Suppress warnings about parsing Ed25519 keys when they are not present.
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 16 Feb 2015 07:42:30 +0000 (08:42 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 16 Feb 2015 07:42:30 +0000 (08:42 +0100)
src/ed25519/ecdsa.c
src/net_setup.c

index bfdabc19e681eb57bf4607b5a8f345ded0d6a45e..f8aafe460b128868f9f63dd36c0ad47b0ebeead4 100644 (file)
@@ -84,11 +84,13 @@ static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) {
                size_t len = b64decode(line, line, linelen);
                if(!len) {
                        logger(DEBUG_ALWAYS, LOG_ERR, "Invalid base64 data in PEM file\n");
+                       errno = EINVAL;
                        return false;
                }
 
                if(len > size) {
                        logger(DEBUG_ALWAYS, LOG_ERR, "Too much base64 data in PEM file\n");
+                       errno = EINVAL;
                        return false;
                }
 
@@ -98,7 +100,12 @@ static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) {
        }
 
        if(size) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "Too little base64 data in PEM file\n");
+               if(data) {
+                       errno = EINVAL;
+                       logger(DEBUG_ALWAYS, LOG_ERR, "Too little base64 data in PEM file\n");
+               } else {
+                       errno = ENOENT;
+               }
                return false;
        }
 
index 7f51fe4b46c938e1b9ef552c75d4e3831e9c1681..d1d5c04be36ff5bfbbe002b106551a789a1635f2 100644 (file)
@@ -137,10 +137,11 @@ bool read_ecdsa_public_key(connection_t *c) {
        }
 
        c->ecdsa = ecdsa_read_pem_public_key(fp);
-       fclose(fp);
 
-       if(!c->ecdsa)
+       if(!c->ecdsa && errno != ENOENT)
                logger(DEBUG_ALWAYS, LOG_ERR, "Parsing Ed25519 public key file `%s' failed.", fname);
+
+       fclose(fp);
        free(fname);
        return c->ecdsa;
 }