mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipa-join: handle JSON-RPC error codes
Error code 2100 (ACIError) is handled explicitly to match XML-RPC behaviour. Fixes: https://pagure.io/freeipa/issue/8408 Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
This commit is contained in:
parent
4696644f3f
commit
6dfefc9745
@ -810,6 +810,40 @@ cleanup:
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
jsonrpc_parse_error(json_t *j_error_obj) {
|
||||||
|
int rval = 0;
|
||||||
|
|
||||||
|
json_error_t j_error;
|
||||||
|
|
||||||
|
int error_code = 0;
|
||||||
|
char *error_message = NULL;
|
||||||
|
if (json_unpack_ex(j_error_obj, &j_error, 0, "{s:i, s:s}",
|
||||||
|
"code", &error_code,
|
||||||
|
"message", &error_message) != 0) {
|
||||||
|
if (debug)
|
||||||
|
fprintf(stderr, _("Extracting the error from the JSON-RPC response failed: %s\n"), j_error.text);
|
||||||
|
|
||||||
|
rval = 17;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (error_code) {
|
||||||
|
case 2100:
|
||||||
|
fprintf(stderr, _("No permission to join this host to the IPA domain.\n"));
|
||||||
|
rval = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (error_message)
|
||||||
|
fprintf(stderr, "%s\n", error_message);
|
||||||
|
rval = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) {
|
jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) {
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
@ -817,6 +851,7 @@ jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) {
|
|||||||
json_error_t j_error;
|
json_error_t j_error;
|
||||||
|
|
||||||
json_t *j_root = NULL;
|
json_t *j_root = NULL;
|
||||||
|
json_t *j_error_obj = NULL;
|
||||||
|
|
||||||
j_root = json_loads(payload, 0, &j_error);
|
j_root = json_loads(payload, 0, &j_error);
|
||||||
if (!j_root) {
|
if (!j_root) {
|
||||||
@ -827,6 +862,13 @@ jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j_error_obj = json_object_get(j_root, "error");
|
||||||
|
if (j_error_obj && !json_is_null(j_error_obj))
|
||||||
|
{
|
||||||
|
rval = jsonrpc_parse_error(j_error_obj);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
*j_result_obj = json_object_get(j_root, "result");
|
*j_result_obj = json_object_get(j_root, "result");
|
||||||
if (!*j_result_obj) {
|
if (!*j_result_obj) {
|
||||||
if (debug)
|
if (debug)
|
||||||
|
Loading…
Reference in New Issue
Block a user