Skip to content
Snippets Groups Projects
Commit 1d9be6ba authored by Arie Peterson's avatar Arie Peterson
Browse files

Include line number as id when listing ssh keys

parent 39e5cf07
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ int callback_ssh_keys_get(const struct _u_request * request,
size_t line_length = 0;
ssize_t read;
json_t * keys = json_array();
json_t * keys = json_object();
// Open file.
authorized_keys = fopen("/root/.ssh/authorized_keys", "r");
......@@ -27,11 +27,15 @@ int callback_ssh_keys_get(const struct _u_request * request,
}
// Read file line by line.
int index = 0;
char * field;
while ((read = getline(&line, &line_length, authorized_keys)) != -1)
{
// Remove trailing newline.
asprintf(&field, "%d", index);
line[strcspn(line, "\n")] = 0;
json_array_append(keys, json_string(line));
json_object_set(keys, field, json_string(line));
++index;
}
// Close file and clean up.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment