/*
tincctl.c -- Controlling a running tincd
- Copyright (C) 2007-2015 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2007-2016 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
static void version(void) {
printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
- printf("Copyright (C) 1998-2015 Ivo Timmermans, Guus Sliepen and others.\n"
+ printf("Copyright (C) 1998-2016 Ivo Timmermans, Guus Sliepen and others.\n"
"See the AUTHORS file for a complete list.\n\n"
"tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions;\n"
va_start(ap, format);
blen = vsnprintf(buffer, sizeof buffer, format, ap);
+ buffer[sizeof buffer - 1] = 0;
va_end(ap);
if(blen < 1 || blen >= sizeof buffer)
}
fclose(f);
+ if ((pid == 0) || (kill(pid, 0) && (errno == ESRCH))) {
+ fprintf(stderr, "Could not find tincd running at pid %d\n", pid);
+ /* clean up the stale socket and pid file */
+ unlink(pidfilename);
+ unlink(unixsocketname);
+ return false;
+ }
#ifndef HAVE_MINGW
struct sockaddr_un sa;
if(!pid) {
close(pfd[0]);
- char buf[100] = "";
+ char buf[100];
snprintf(buf, sizeof buf, "%d", pfd[1]);
setenv("TINC_UMBILICAL", buf, true);
exit(execvp(c, nargv));
return 1;
}
- if(!connect_tincd(true) && !pid)
+ if(!connect_tincd(true) || !pid)
return 1;
printf("%d\n", pid);
return NULL;
}
-static ecdsa_t *get_pubkey(FILE *f) {
+ecdsa_t *get_pubkey(FILE *f) {
char buf[4096];
char *value;
while(fgets(buf, sizeof buf, f)) {
char *newline = memchr(data, '\n', len);
if(!newline || (newline - data > MAX_STRING_SIZE - 1)) {
fprintf(stderr, "Invalid input\n");
+ free(data);
return 1;
}
*newline++ = '\0';
+ size_t skip = newline - data;
char signer[MAX_STRING_SIZE] = "";
char sig[MAX_STRING_SIZE] = "";
if(sscanf(data, "Signature = %s %ld %s", signer, &t, sig) != 3 || strlen(sig) != 86 || !t || !check_id(signer)) {
fprintf(stderr, "Invalid input\n");
+ free(data);
return 1;
}
if(node && strcmp(node, signer)) {
fprintf(stderr, "Signature is not made by %s\n", node);
+ free(data);
return 1;
}
memcpy(data + len, trailer, trailer_len);
free(trailer);
+ newline = data + skip;
+
char fname[PATH_MAX];
snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, node);
FILE *fp = fopen(fname, "r");
if(nargc == argc)
continue;
- if(!strcasecmp(nargv[argc], "exit") || !strcasecmp(nargv[argc], "quit"))
+ if(!strcasecmp(nargv[argc], "exit") || !strcasecmp(nargv[argc], "quit")) {
+ free(nargv);
return result;
+ }
bool found = false;