Remove autotools configs
[tinc] / src / invitation.c
index 2163d6f..e71a488 100644 (file)
@@ -1,6 +1,6 @@
 /*
     invitation.c -- Create and accept invitations
-    Copyright (C) 2013-2017 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2013-2022 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -97,7 +97,7 @@ static void scan_for_hostname(const char *filename, char **hostname, char **port
        fclose(f);
 }
 
-char *get_my_hostname() {
+static char *get_my_hostname(void) {
        char *hostname = NULL;
        char *port = NULL;
        char *hostport = NULL;
@@ -448,7 +448,7 @@ int cmd_invite(int argc, char *argv[]) {
        char hash[64];
        char *fingerprint = ecdsa_get_base64_public_key(key);
        sha512(fingerprint, strlen(fingerprint), hash);
-       b64encode_urlsafe(hash, hash, 18);
+       b64encode_tinc_urlsafe(hash, hash, 18);
 
        ecdsa_free(key);
 
@@ -462,11 +462,11 @@ int cmd_invite(int argc, char *argv[]) {
        memcpy(buf, cookie, 18);
        memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
        sha512(buf, sizeof(buf), cookiehash);
-       b64encode_urlsafe(cookiehash, cookiehash, 18);
+       b64encode_tinc_urlsafe(cookiehash, cookiehash, 18);
 
        free(fingerprint);
 
-       b64encode_urlsafe(cookie, cookie, 18);
+       b64encode_tinc_urlsafe(cookie, cookie, 18);
 
        // Create a file containing the details of the invitation.
        snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
@@ -545,14 +545,12 @@ int cmd_invite(int argc, char *argv[]) {
 }
 
 static int sock;
-static char cookie[18];
+static char cookie[18], hash[18];
 static sptps_t sptps;
 static char *data;
 static size_t datalen;
 static bool success = false;
 
-static char cookie[18], hash[18];
-
 static char *get_line(const char **data) {
        if(!data || !*data) {
                return NULL;
@@ -709,7 +707,7 @@ make_names:
 
                // Generate a random netname, ask for a better one later.
                ask_netname = true;
-               snprintf(temp_netname, sizeof(temp_netname), "join_%x", rand());
+               snprintf(temp_netname, sizeof(temp_netname), "join_%x", prng(UINT32_MAX));
                netname = temp_netname;
                goto make_names;
        }
@@ -1087,7 +1085,7 @@ ask_netname:
 static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
        (void)handle;
        (void)type;
-       const uint8_t *data = vdata;
+       const char *data = vdata;
 
        while(len) {
                ssize_t result = send(sock, data, len, 0);
@@ -1227,10 +1225,11 @@ int cmd_join(int argc, char *argv[]) {
        }
 
        if(!port || !*port) {
-               port = "655";
+               static char default_port[] = "655";
+               port = default_port;
        }
 
-       if(!b64decode(slash, hash, 24) || !b64decode(slash + 24, cookie, 24)) {
+       if(!b64decode_tinc(slash, hash, 24) || !b64decode_tinc(slash + 24, cookie, 24)) {
                goto invalid;
        }