Newer
Older
/**
* Callback function that uses the password passed in the request to open the
* luks volume.
* @param[in] request incoming HTTP request
* @param[out] response HTTP response to the request
* @param[in] user_data extra data to pass between main thread and callbacks
* @return internal status code
int callback_encryption_unlock(const struct _u_request * request,
struct _u_response * response, void * user_data)
{
json_t * json_input = ulfius_get_json_body_request(request, NULL);
const char * password;
password = json_string_value(json_object_get(json_input, "password"));
if (password == NULL)
{
return send_simple_response(response, 400, "error", "missing password");
}
int unlock_status = encryption_unlock(DATA_PARTITION_DEVICE,
MAPPED_DEVICE_NAME, password);
if (unlock_status == -1)
{
// Experience learns that -1 is returned when the password is wrong.
return send_simple_response(response, 403, "error",
"incorrect password");
}
if (unlock_status != 0)
{
// Something else went wrong with unlocking.
printf("encryption_unlock failed with status %d\n", unlock_status);
return send_simple_response(response, 500, "error",
"error during unlocking");
}
// If we reach this point, apparently everything went well.
int r = send_simple_response(response, 200, "status", "ok");
stop_server();
return r;
}