Skip to content
Snippets Groups Projects
Commit 45849f53 authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

resolve most discussions

parent d8a616a1
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ int callback_ssh_keys_post(const struct _u_request * request, ...@@ -27,7 +27,7 @@ int callback_ssh_keys_post(const struct _u_request * request,
{ {
printf("Could not open authorized_keys file for writing\n"); printf("Could not open authorized_keys file for writing\n");
return send_simple_response(response, 500, "error", return send_simple_response(response, 500, "error",
"error reading authorized_keys"); "error opening authorized_keys");
} }
// Read in json request body. // Read in json request body.
...@@ -41,7 +41,7 @@ int callback_ssh_keys_post(const struct _u_request * request, ...@@ -41,7 +41,7 @@ int callback_ssh_keys_post(const struct _u_request * request,
return send_simple_response(response, 400, "error", "missing ssh-key"); 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; char * command = NULL;
asprintf(&command, "echo '%s' | sed -rf '%s'", ssh_key, RESTRICT_COMMAND_PATH); asprintf(&command, "echo '%s' | sed -rf '%s'", ssh_key, RESTRICT_COMMAND_PATH);
FILE * sed_output = popen(command, "r"); FILE * sed_output = popen(command, "r");
......
...@@ -19,26 +19,32 @@ void stop_server() ...@@ -19,26 +19,32 @@ void stop_server()
char * read_from_file(FILE * file) char * read_from_file(FILE * file)
{ {
char buf[100]; char buf[100];
char *str = NULL; char * str = NULL;
char *temp = NULL; char * temp = NULL;
unsigned int size = 1; // start with size of 1 to make room for null terminator // start with size of 1 to make room for null terminator
unsigned int size = 1;
unsigned int strlength; unsigned int strlength;
if (file) if (file)
{ {
while (fgets(buf, sizeof(buf), file) != NULL) { while (fgets(buf, sizeof(buf), file) != NULL)
{
strlength = strlen(buf); strlength = strlen(buf);
temp = realloc(str, size + strlength); // allocate room for the buf that gets appended // allocate room for the buf that gets appended
if (temp == NULL) { temp = realloc(str, size + strlength);
// allocation error if (temp == NULL)
} else { {
printf("Could not allocate memory for file reading\n");
return NULL;
}
else
{
str = temp; str = temp;
} }
strcpy(str + size - 1, buf); // append buffer to str // append buffer to str
strcpy(str + size - 1, buf);
size += strlength; size += strlength;
} }
pclose(file); pclose(file);
temp = realloc(str, size + 1);
str[size] = '\0';
} }
return str; return str;
} }
......
...@@ -25,7 +25,7 @@ int main(int argc, char ** argv) ...@@ -25,7 +25,7 @@ int main(int argc, char ** argv)
inet_pton(AF_INET, BIND_ADDRESS, &address.sin_addr); inet_pton(AF_INET, BIND_ADDRESS, &address.sin_addr);
struct _u_instance instance; 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"); y_log_message(Y_LOG_LEVEL_ERROR, "Error ulfius_init_instance, abort");
return(1); return(1);
......
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