From 1d9be6ba35ed37e9510bfee8ceb3fa10772f2394 Mon Sep 17 00:00:00 2001 From: Arie Peterson <arie@greenhost.nl> Date: Wed, 21 Jun 2017 17:55:32 +0200 Subject: [PATCH] Include line number as id when listing ssh keys --- src/api/ssh_keys_get.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api/ssh_keys_get.c b/src/api/ssh_keys_get.c index 04b1a08..4674f47 100644 --- a/src/api/ssh_keys_get.c +++ b/src/api/ssh_keys_get.c @@ -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. -- GitLab