summaryrefslogtreecommitdiff
path: root/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
diff options
context:
space:
mode:
authorJoseph Quadrino <jquadrin@gmail.com>2013-07-31 03:07:51 -0400
committerJoseph Quadrino <jquadrin@gmail.com>2013-07-31 03:07:51 -0400
commit9f6be0ce4b895eb0941e4c7063520a7d95fb7de9 (patch)
tree7851ec495451e843322deb5ace06f1e21259b452 /other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c
parent52a77cc997e5c91fe2ed9244bfcfd9e379226091 (diff)
stat file before attempting to open
Diffstat (limited to 'other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c')
-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");