From 45849f53944896cfb5d4894a18872f5f1026c5e0 Mon Sep 17 00:00:00 2001
From: Maarten de Waard <maarten@greenhost.nl>
Date: Thu, 13 Jul 2017 17:47:40 +0200
Subject: [PATCH] resolve most discussions

---
 src/api/ssh_keys_post.c |  4 ++--
 src/auxiliary.c         | 28 +++++++++++++++++-----------
 src/cryptops-api.c      |  2 +-
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/api/ssh_keys_post.c b/src/api/ssh_keys_post.c
index 90725ea..58c2f93 100644
--- a/src/api/ssh_keys_post.c
+++ b/src/api/ssh_keys_post.c
@@ -27,7 +27,7 @@ int callback_ssh_keys_post(const struct _u_request * request,
     {
         printf("Could not open authorized_keys file for writing\n");
         return send_simple_response(response, 500, "error",
-            "error reading authorized_keys");
+            "error opening authorized_keys");
     }
 
     // Read in json request body.
@@ -41,7 +41,7 @@ int callback_ssh_keys_post(const struct _u_request * request,
         return send_simple_response(response, 400, "error", "missing ssh-key");
     }
 
-    // Call cat to append the command correctly:
+    // Call sed to append the command correctly:
     char * command = NULL;
     asprintf(&command, "echo '%s' | sed -rf '%s'", ssh_key, RESTRICT_COMMAND_PATH);
     FILE * sed_output = popen(command, "r");
diff --git a/src/auxiliary.c b/src/auxiliary.c
index c7dddab..c05da34 100644
--- a/src/auxiliary.c
+++ b/src/auxiliary.c
@@ -19,26 +19,32 @@ void stop_server()
 char * read_from_file(FILE * file)
 {
     char buf[100];
-    char *str = NULL;
-    char *temp = NULL;
-    unsigned int size = 1;  // start with size of 1 to make room for null terminator
+    char * str = NULL;
+    char * temp = NULL;
+    // start with size of 1 to make room for null terminator
+    unsigned int size = 1;
     unsigned int strlength;
     if (file)
     {
-        while (fgets(buf, sizeof(buf), file) != NULL) {
+        while (fgets(buf, sizeof(buf), file) != NULL)
+        {
             strlength = strlen(buf);
-            temp = realloc(str, size + strlength);  // allocate room for the buf that gets appended
-            if (temp == NULL) {
-                // allocation error
-            } else {
+            // allocate room for the buf that gets appended
+            temp = realloc(str, size + strlength);
+            if (temp == NULL)
+            {
+                printf("Could not allocate memory for file reading\n");
+                return NULL;
+            }
+            else
+            {
                 str = temp;
             }
-            strcpy(str + size - 1, buf);     // append buffer to str
+            // append buffer to str
+            strcpy(str + size - 1, buf);
             size += strlength;
         }
         pclose(file);
-        temp = realloc(str, size + 1);
-        str[size] = '\0';
     }
     return str;
 }
diff --git a/src/cryptops-api.c b/src/cryptops-api.c
index 1b2a867..faaf253 100644
--- a/src/cryptops-api.c
+++ b/src/cryptops-api.c
@@ -25,7 +25,7 @@ int main(int argc, char ** argv)
     inet_pton(AF_INET, BIND_ADDRESS, &address.sin_addr);
 
     struct _u_instance instance;
-    if (ulfius_init_instance(&instance, PORT, NULL, NULL) != U_OK)
+    if (ulfius_init_instance(&instance, PORT, &address, NULL) != U_OK)
     {
         y_log_message(Y_LOG_LEVEL_ERROR, "Error ulfius_init_instance, abort");
         return(1);
-- 
GitLab