projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Simplify signal handling.
[tinc]
/
src
/
invitation.c
diff --git
a/src/invitation.c
b/src/invitation.c
index
30d100d
..
3c23a17
100644
(file)
--- a/
src/invitation.c
+++ b/
src/invitation.c
@@
-111,6
+111,9
@@
char *get_my_hostname() {
scan_for_hostname(tinc_conf, &hostname, &port);
}
scan_for_hostname(tinc_conf, &hostname, &port);
}
+ free(name);
+ name = NULL;
+
if(hostname) {
goto done;
}
if(hostname) {
goto done;
}
@@
-133,7
+136,7
@@
char *get_my_hostname() {
if(s >= 0) {
send(s, request, sizeof(request) - 1, 0);
if(s >= 0) {
send(s, request, sizeof(request) - 1, 0);
-
in
t len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
+
ssize_
t len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
if(len > 0) {
line[len] = 0;
if(len > 0) {
line[len] = 0;
@@
-167,7
+170,7
@@
char *get_my_hostname() {
// Check that the hostname is reasonable
if(hostname) {
for(char *p = hostname; *p; p++) {
// Check that the hostname is reasonable
if(hostname) {
for(char *p = hostname; *p; p++) {
- if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':') {
+ if(isalnum(
(uint8_t)
*p) || *p == '-' || *p == '.' || *p == ':') {
continue;
}
continue;
}
@@
-213,7
+216,7
@@
again:
}
for(char *p = line; *p; p++) {
}
for(char *p = line; *p; p++) {
- if(isalnum(*p) || *p == '-' || *p == '.') {
+ if(isalnum(
(uint8_t)
*p) || *p == '-' || *p == '.') {
continue;
}
continue;
}
@@
-289,6
+292,7
@@
int cmd_invite(int argc, char *argv[]) {
return 1;
}
return 1;
}
+ free(myname);
myname = get_my_name(true);
if(!myname) {
myname = get_my_name(true);
if(!myname) {
@@
-407,6
+411,7
@@
int cmd_invite(int argc, char *argv[]) {
if(!f) {
fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno));
if(!f) {
fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno));
+ free(key);
return 1;
}
return 1;
}
@@
-415,6
+420,7
@@
int cmd_invite(int argc, char *argv[]) {
if(!ecdsa_write_pem_private_key(key, f)) {
fprintf(stderr, "Could not write ECDSA private key\n");
fclose(f);
if(!ecdsa_write_pem_private_key(key, f)) {
fprintf(stderr, "Could not write ECDSA private key\n");
fclose(f);
+ free(key);
return 1;
}
return 1;
}
@@
-444,18
+450,22
@@
int cmd_invite(int argc, char *argv[]) {
sha512(fingerprint, strlen(fingerprint), hash);
b64encode_urlsafe(hash, hash, 18);
sha512(fingerprint, strlen(fingerprint), hash);
b64encode_urlsafe(hash, hash, 18);
+ free(key);
+
// Create a random cookie for this invitation.
char cookie[25];
randomize(cookie, 18);
// Create a filename that doesn't reveal the cookie itself
// Create a random cookie for this invitation.
char cookie[25];
randomize(cookie, 18);
// Create a filename that doesn't reveal the cookie itself
-
char
buf[18 + strlen(fingerprint)];
+
uint8_t
buf[18 + strlen(fingerprint)];
char cookiehash[64];
memcpy(buf, cookie, 18);
memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
sha512(buf, sizeof(buf), cookiehash);
b64encode_urlsafe(cookiehash, cookiehash, 18);
char cookiehash[64];
memcpy(buf, cookie, 18);
memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
sha512(buf, sizeof(buf), cookiehash);
b64encode_urlsafe(cookiehash, cookiehash, 18);
+ free(fingerprint);
+
b64encode_urlsafe(cookie, cookie, 18);
// Create a file containing the details of the invitation.
b64encode_urlsafe(cookie, cookie, 18);
// Create a file containing the details of the invitation.
@@
-562,7
+572,7
@@
static char *get_line(const char **data) {
return NULL;
}
return NULL;
}
- if(len && !isprint(**data)) {
+ if(len && !isprint(
(uint8_t)
**data)) {
abort();
}
abort();
}
@@
-605,7
+615,7
@@
static char *grep(const char *data, const char *var) {
static char value[1024];
const char *p = data;
static char value[1024];
const char *p = data;
-
in
t varlen = strlen(var);
+
size_
t varlen = strlen(var);
// Skip all lines not starting with var
while(strncasecmp(p, var, varlen) || !strchr(" \t=", p[varlen])) {
// Skip all lines not starting with var
while(strncasecmp(p, var, varlen) || !strchr(" \t=", p[varlen])) {
@@
-771,7
+781,7
@@
make_names:
}
// Split line into variable and value
}
// Split line into variable and value
-
in
t len = strcspn(l, "\t =");
+
size_
t len = strcspn(l, "\t =");
value = l + len;
value += strspn(value, "\t ");
value = l + len;
value += strspn(value, "\t ");
@@
-876,7
+886,7
@@
make_names:
continue;
}
continue;
}
-
in
t len = strcspn(l, "\t =");
+
size_
t len = strcspn(l, "\t =");
if(len == 4 && !strncasecmp(l, "Name", 4)) {
value = l + len;
if(len == 4 && !strncasecmp(l, "Name", 4)) {
value = l + len;
@@
-1054,7
+1064,13
@@
ask_netname:
}
}
} else {
}
}
} else {
- fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n");
+ if(force) {
+ rename(filename, filename2);
+ chmod(filename2, 0755);
+ fprintf(stderr, "tinc-up enabled.\n");
+ } else {
+ fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n");
+ }
}
} else {
// A placeholder was generated.
}
} else {
// A placeholder was generated.
@@
-1071,10
+1087,10
@@
ask_netname:
static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
(void)handle;
(void)type;
static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
(void)handle;
(void)type;
- const
char
*data = vdata;
+ const
uint8_t
*data = vdata;
while(len) {
while(len) {
-
in
t result = send(sock, data, len, 0);
+
ssize_
t result = send(sock, data, len, 0);
if(result == -1 && sockwouldblock(sockerrno)) {
continue;
if(result == -1 && sockwouldblock(sockerrno)) {
continue;
@@
-1231,6
+1247,7
@@
int cmd_join(int argc, char *argv[]) {
struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
if(!ai) {
struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
if(!ai) {
+ free(b64key);
return 1;
}
return 1;
}
@@
-1244,6
+1261,7
@@
next:
if(!aip) {
freeaddrinfo(ai);
if(!aip) {
freeaddrinfo(ai);
+ free(b64key);
return 1;
}
}
return 1;
}
}
@@
-1268,7
+1286,7
@@
next:
fprintf(stderr, "Connected to %s port %s...\n", address, port);
// Tell him we have an invitation, and give him our throw-away key.
fprintf(stderr, "Connected to %s port %s...\n", address, port);
// Tell him we have an invitation, and give him our throw-away key.
-
in
t len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
+
ssize_
t len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
if(len <= 0 || (size_t)len >= sizeof(line)) {
abort();
if(len <= 0 || (size_t)len >= sizeof(line)) {
abort();
@@
-1290,6
+1308,11
@@
next:
}
freeaddrinfo(ai);
}
freeaddrinfo(ai);
+ ai = NULL;
+ aip = NULL;
+
+ free(b64key);
+ b64key = NULL;
// Check if the hash of the key he gave us matches the hash in the URL.
char *fingerprint = line + 2;
// Check if the hash of the key he gave us matches the hash in the URL.
char *fingerprint = line + 2;
@@
-1345,13
+1368,13
@@
next:
char *p = line;
while(len) {
char *p = line;
while(len) {
-
in
t done = sptps_receive_data(&sptps, p, len);
+
size_
t done = sptps_receive_data(&sptps, p, len);
if(!done) {
return 1;
}
if(!done) {
return 1;
}
- len -= done;
+ len -=
(ssize_t)
done;
p += done;
}
}
p += done;
}
}