summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-31 04:37:08 -0700
committerirungentoo <irungentoo@gmail.com>2013-07-31 04:37:08 -0700
commitb4eb49eae2235b9f01d98b2beffd7d11bc19123d (patch)
tree419d69c97f95fe31f213fd4222e7b3859c7907c4
parentb2dbefb4c9aa3d6dcad02032f5c51da10b5f56eb (diff)
parent9f6be0ce4b895eb0941e4c7063520a7d95fb7de9 (diff)
Merge pull request #200 from jquadrin/master
stat file before attempting to open
-rw-r--r--other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
index 8e278b28..4f28fb3c 100644
--- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
+++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
@@ -123,11 +123,12 @@ void manage_keys(char *keys_file)
123{ 123{
124 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; 124 const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES;
125 uint8_t keys[KEYS_SIZE]; 125 uint8_t keys[KEYS_SIZE];
126 126 struct stat existence;
127 /* TODO: stat the file before trying to open it. We aren't cave people! */ 127 FILE *keysf;
128 FILE *keysf = fopen(keys_file, "r"); 128
129 if (keysf != NULL) { 129 /* Check if file exits, proceed to open and load keys */
130 /* if file was opened successfully -- load keys */ 130 if(stat(keys_file,&existence) >= 0) {
131 keysf = fopen(keys_file, "r");
131 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keysf); 132 size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keysf);
132 if (read_size != KEYS_SIZE) { 133 if (read_size != KEYS_SIZE) {
133 printf("Error while reading the key file\nExiting.\n"); 134 printf("Error while reading the key file\nExiting.\n");