static JsonObject * parse_login_data (const gchar *json_str) { JsonObject *results = NULL; JsonObject *login_data = NULL; GError *error = NULL; results = cockpit_json_parse_object (json_str, strlen(json_str), &error); if (!results) { g_warning ("received bad json data: %s", error->message); g_error_free (error); goto out; } if (!cockpit_json_get_object (results, "login-data", NULL, &login_data)) { g_warning ("received bad login-data: %s", json_str); login_data = NULL; goto out; } if (login_data) login_data = json_object_ref (login_data); out: if (results) json_object_unref (results); return login_data; }
static CockpitCreds * parse_ssh_spawn_results (CockpitAuth *self, AuthData *ad, GHashTable *headers, JsonObject **prompt_data, GError **error) { CockpitCreds *creds = NULL; JsonObject *results = NULL; JsonObject *auth_results = NULL; const gchar *pw_result = NULL; const gchar *user; const gchar *error_str; results = cockpit_auth_process_parse_result (ad->auth_process, ad->response_data, error); if (results) { user = cockpit_auth_process_get_authenticated_user (ad->auth_process, results, prompt_data, error); if (user) { creds = create_creds_for_spawn_authenticated (self, user, ad, results, ad->response_data); } else if (cockpit_json_get_string (results, "error", NULL, &error_str)) { if (g_strcmp0 (error_str, "authentication-failed") == 0) { cockpit_json_get_object (results, "auth-method-results", NULL, &auth_results); if (auth_results) cockpit_json_get_string (auth_results, "password", NULL, &pw_result); if (!pw_result || g_strcmp0 (pw_result, "no-server-support") == 0) { g_clear_error (error); g_set_error (error, COCKPIT_ERROR, COCKPIT_ERROR_AUTHENTICATION_FAILED, "Authentication failed: authentication-not-supported"); } } else if (g_strcmp0 (error_str, "terminated") == 0) { g_clear_error (error); g_set_error (error, COCKPIT_ERROR, COCKPIT_ERROR_AUTHENTICATION_FAILED, "Authentication failed: terminated"); } } json_object_unref (results); } return creds; }