Use actual port in tincd logs / tinc get Port / invitations
[tinc] / src / protocol_auth.c
index 19859b7..16abc05 100644 (file)
@@ -25,7 +25,6 @@
 #include "control.h"
 #include "control_common.h"
 #include "cipher.h"
-#include "crypto.h"
 #include "digest.h"
 #include "ecdsa.h"
 #include "edge.h"
@@ -42,6 +41,7 @@
 #include "sptps.h"
 #include "utils.h"
 #include "xalloc.h"
+#include "random.h"
 
 #include "ed25519/sha512.h"
 #include "keys.h"
@@ -296,6 +296,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
 
        if(!fgets(buf, sizeof(buf), f)) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Could not read invitation file %s\n", cookie);
+               fclose(f);
                return false;
        }
 
@@ -336,6 +337,12 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
                sptps_send_record(&c->sptps, 0, buf, result);
        }
 
+       if(!feof(f)) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Could not read invitation file %s\n", cookie);
+               fclose(f);
+               return false;
+       }
+
        sptps_send_record(&c->sptps, 1, buf, 0);
        fclose(f);
        unlink(usedname);
@@ -887,7 +894,7 @@ bool send_ack(connection_t *c) {
                get_config_int(lookup_config(&config_tree, "Weight"), &c->estimated_weight);
        }
 
-       return send_request(c, "%d %s %d %x", ACK, myport, c->estimated_weight, (c->options & 0xffffff) | (experimental ? (PROT_MINOR << 24) : 0));
+       return send_request(c, "%d %s %d %x", ACK, myport.udp, c->estimated_weight, (c->options & 0xffffff) | (experimental ? (PROT_MINOR << 24) : 0));
 }
 
 static void send_everything(connection_t *c) {
@@ -1060,7 +1067,7 @@ bool ack_h(connection_t *c, const char *request) {
        if(getsockname(c->socket, &local_sa.sa, &local_salen) < 0) {
                logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name);
        } else {
-               sockaddr_setport(&local_sa, myport);
+               sockaddr_setport(&local_sa, myport.udp);
                c->edge->local_address = local_sa;
        }