diff --git a/client/ipa-join.c b/client/ipa-join.c index 54dba2c99..4deb7d932 100644 --- a/client/ipa-join.c +++ b/client/ipa-join.c @@ -810,6 +810,40 @@ cleanup: 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 jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) { 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_t *j_root = NULL; + json_t *j_error_obj = NULL; j_root = json_loads(payload, 0, &j_error); if (!j_root) { @@ -827,6 +862,13 @@ jsonrpc_parse_response(const char *payload, json_t** j_result_obj, bool quiet) { 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"); if (!*j_result_obj) { if (debug)