tinc/src/fsck.c

616 lines
14 KiB
C
Raw Permalink Normal View History

2019-08-26 11:44:52 +00:00
/*
fsck.c -- Check the configuration files for problems
2022-04-22 18:24:15 +00:00
Copyright (C) 2014-2021 Guus Sliepen <guus@tinc-vpn.org>
2019-08-26 11:44:52 +00:00
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "system.h"
#include "crypto.h"
#include "ecdsa.h"
#include "ecdsagen.h"
#include "fsck.h"
#include "names.h"
#ifndef DISABLE_LEGACY
#include "rsa.h"
#include "rsagen.h"
#endif
#include "tincctl.h"
#include "utils.h"
static bool ask_fix(void) {
2019-08-26 11:44:53 +00:00
if(force) {
2019-08-26 11:44:52 +00:00
return true;
2019-08-26 11:44:53 +00:00
}
if(!tty) {
2019-08-26 11:44:52 +00:00
return false;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
again:
fprintf(stderr, "Fix y/n? ");
char buf[1024];
2019-08-26 11:44:53 +00:00
if(!fgets(buf, sizeof(buf), stdin)) {
2019-08-26 11:44:52 +00:00
tty = false;
return false;
}
2019-08-26 11:44:53 +00:00
if(buf[0] == 'y' || buf[0] == 'Y') {
2019-08-26 11:44:52 +00:00
return true;
2019-08-26 11:44:53 +00:00
}
if(buf[0] == 'n' || buf[0] == 'N') {
2019-08-26 11:44:52 +00:00
return false;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
goto again;
}
static void print_tinc_cmd(const char *argv0, const char *format, ...) {
2019-08-26 11:44:53 +00:00
if(confbasegiven) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "%s -c %s ", argv0, confbase);
2019-08-26 11:44:53 +00:00
} else if(netname) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "%s -n %s ", argv0, netname);
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "%s ", argv0);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
va_list va;
va_start(va, format);
vfprintf(stderr, format, va);
va_end(va);
fputc('\n', stderr);
}
static int strtailcmp(const char *str, const char *tail) {
size_t slen = strlen(str);
size_t tlen = strlen(tail);
2019-08-26 11:44:53 +00:00
if(tlen > slen) {
2019-08-26 11:44:52 +00:00
return -1;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
return memcmp(str + slen - tlen, tail, tlen);
}
static void check_conffile(const char *fname, bool server) {
2019-08-26 11:44:53 +00:00
(void)server;
2019-08-26 11:44:52 +00:00
FILE *f = fopen(fname, "r");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!f) {
fprintf(stderr, "ERROR: cannot read %s: %s\n", fname, strerror(errno));
return;
}
char line[2048];
int lineno = 0;
bool skip = false;
const int maxvariables = 50;
int count[maxvariables];
2019-08-26 11:44:53 +00:00
memset(count, 0, sizeof(count));
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
while(fgets(line, sizeof(line), f)) {
2019-08-26 11:44:52 +00:00
if(skip) {
2019-08-26 11:44:53 +00:00
if(!strncmp(line, "-----END", 8)) {
2019-08-26 11:44:52 +00:00
skip = false;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
continue;
} else {
if(!strncmp(line, "-----BEGIN", 10)) {
skip = true;
continue;
}
}
int len;
char *variable, *value, *eol;
variable = value = line;
lineno++;
eol = line + strlen(line);
2019-08-26 11:44:53 +00:00
while(strchr("\t \r\n", *--eol)) {
2019-08-26 11:44:52 +00:00
*eol = '\0';
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
if(!line[0] || line[0] == '#') {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
len = strcspn(value, "\t =");
value += len;
value += strspn(value, "\t ");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(*value == '=') {
value++;
value += strspn(value, "\t ");
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
variable[len] = '\0';
bool found = false;
for(int i = 0; variables[i].name; i++) {
2019-08-26 11:44:53 +00:00
if(strcasecmp(variables[i].name, variable)) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
found = true;
if(variables[i].type & VAR_OBSOLETE) {
fprintf(stderr, "WARNING: obsolete variable %s in %s line %d\n", variable, fname, lineno);
}
2019-08-26 11:44:53 +00:00
if(i < maxvariables) {
2019-08-26 11:44:52 +00:00
count[i]++;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
2019-08-26 11:44:53 +00:00
if(!found) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: unknown variable %s in %s line %d\n", variable, fname, lineno);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
if(!*value) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: no value for variable %s in %s line %d\n", variable, fname, lineno);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
for(int i = 0; variables[i].name && i < maxvariables; i++) {
2019-08-26 11:44:53 +00:00
if(count[i] > 1 && !(variables[i].type & VAR_MULTIPLE)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: multiple instances of variable %s in %s\n", variables[i].name, fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
2019-08-26 11:44:53 +00:00
if(ferror(f)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: while reading %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
fclose(f);
}
int fsck(const char *argv0) {
#ifdef HAVE_MINGW
int uid = 0;
#else
uid_t uid = getuid();
#endif
// Check that tinc.conf is readable.
if(access(tinc_conf, R_OK)) {
fprintf(stderr, "ERROR: cannot read %s: %s\n", tinc_conf, strerror(errno));
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(errno == ENOENT) {
fprintf(stderr, "No tinc configuration found. Create a new one with:\n\n");
print_tinc_cmd(argv0, "init");
} else if(errno == EACCES) {
2019-08-26 11:44:53 +00:00
if(uid != 0) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "You are currently not running tinc as root. Use sudo?\n");
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "Check the permissions of each component of the path %s.\n", tinc_conf);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
return 1;
}
char *name = get_my_name(true);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!name) {
fprintf(stderr, "ERROR: tinc cannot run without a valid Name.\n");
return 1;
}
// Check for private keys.
// TODO: use RSAPrivateKeyFile and Ed25519PrivateKeyFile variables if present.
struct stat st;
char fname[PATH_MAX];
char dname[PATH_MAX];
#ifndef DISABLE_LEGACY
rsa_t *rsa_priv = NULL;
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s/rsa_key.priv", confbase);
2019-08-26 11:44:52 +00:00
if(stat(fname, &st)) {
if(errno != ENOENT) {
// Something is seriously wrong here. If we can access the directory with tinc.conf in it, we should certainly be able to stat() an existing file.
fprintf(stderr, "ERROR: cannot read %s: %s\n", fname, strerror(errno));
fprintf(stderr, "Please correct this error.\n");
return 1;
}
} else {
FILE *f = fopen(fname, "r");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!f) {
fprintf(stderr, "ERROR: could not open %s: %s\n", fname, strerror(errno));
return 1;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
rsa_priv = rsa_read_pem_private_key(f);
fclose(f);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!rsa_priv) {
fprintf(stderr, "ERROR: No key or unusable key found in %s.\n", fname);
fprintf(stderr, "You can generate a new RSA key with:\n\n");
print_tinc_cmd(argv0, "generate-rsa-keys");
return 1;
}
2022-04-22 18:24:15 +00:00
#ifndef HAVE_MINGW
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(st.st_mode & 077) {
fprintf(stderr, "WARNING: unsafe file permissions on %s.\n", fname);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(st.st_uid != uid) {
fprintf(stderr, "You are not running %s as the same uid as %s.\n", argv0, fname);
} else if(ask_fix()) {
2019-08-26 11:44:53 +00:00
if(chmod(fname, st.st_mode & ~077)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: could not change permissions of %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "Fixed permissions of %s.\n", fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
#endif
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
#endif
ecdsa_t *ecdsa_priv = NULL;
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s/ed25519_key.priv", confbase);
2019-08-26 11:44:52 +00:00
if(stat(fname, &st)) {
if(errno != ENOENT) {
// Something is seriously wrong here. If we can access the directory with tinc.conf in it, we should certainly be able to stat() an existing file.
fprintf(stderr, "ERROR: cannot read %s: %s\n", fname, strerror(errno));
fprintf(stderr, "Please correct this error.\n");
return 1;
}
} else {
FILE *f = fopen(fname, "r");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!f) {
fprintf(stderr, "ERROR: could not open %s: %s\n", fname, strerror(errno));
return 1;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
ecdsa_priv = ecdsa_read_pem_private_key(f);
fclose(f);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!ecdsa_priv) {
fprintf(stderr, "ERROR: No key or unusable key found in %s.\n", fname);
fprintf(stderr, "You can generate a new Ed25519 key with:\n\n");
print_tinc_cmd(argv0, "generate-ed25519-keys");
return 1;
}
2022-04-22 18:24:15 +00:00
#ifndef HAVE_MINGW
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(st.st_mode & 077) {
fprintf(stderr, "WARNING: unsafe file permissions on %s.\n", fname);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(st.st_uid != uid) {
fprintf(stderr, "You are not running %s as the same uid as %s.\n", argv0, fname);
} else if(ask_fix()) {
2019-08-26 11:44:53 +00:00
if(chmod(fname, st.st_mode & ~077)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: could not change permissions of %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "Fixed permissions of %s.\n", fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
#endif
}
#ifdef DISABLE_LEGACY
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!ecdsa_priv) {
fprintf(stderr, "ERROR: No Ed25519 private key found.\n");
#else
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!rsa_priv && !ecdsa_priv) {
fprintf(stderr, "ERROR: Neither RSA or Ed25519 private key found.\n");
#endif
fprintf(stderr, "You can generate new keys with:\n\n");
print_tinc_cmd(argv0, "generate-keys");
return 1;
}
// Check for public keys.
// TODO: use RSAPublicKeyFile variable if present.
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, name);
if(access(fname, R_OK)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: cannot read %s\n", fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
FILE *f;
#ifndef DISABLE_LEGACY
rsa_t *rsa_pub = NULL;
f = fopen(fname, "r");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(f) {
2019-08-26 11:44:52 +00:00
rsa_pub = rsa_read_pem_public_key(f);
2019-08-26 11:44:52 +00:00
fclose(f);
}
2019-08-26 11:44:52 +00:00
if(rsa_priv) {
if(!rsa_pub) {
fprintf(stderr, "WARNING: No (usable) public RSA key found.\n");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(ask_fix()) {
FILE *f = fopen(fname, "a");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(f) {
2019-08-26 11:44:53 +00:00
if(rsa_write_pem_public_key(rsa_priv, f)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "Wrote RSA public key to %s.\n", fname);
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: could not write RSA public key to %s.\n", fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
fclose(f);
} else {
fprintf(stderr, "ERROR: could not append to %s: %s\n", fname, strerror(errno));
}
}
} else {
// TODO: suggest remedies
size_t len = rsa_size(rsa_priv);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(len != rsa_size(rsa_pub)) {
fprintf(stderr, "ERROR: public and private RSA keys do not match.\n");
return 1;
}
2019-08-26 11:44:53 +00:00
2022-04-22 18:24:15 +00:00
char *buf1 = malloc(len);
char *buf2 = malloc(len);
char *buf3 = malloc(len);
2019-08-26 11:44:53 +00:00
2022-04-22 18:24:15 +00:00
randomize(buf1, len);
buf1[0] &= 0x7f;
memset(buf2, 0, len);
memset(buf3, 0, len);
bool result = false;
if(rsa_public_encrypt(rsa_pub, buf1, len, buf2)) {
if(rsa_private_decrypt(rsa_priv, buf2, len, buf3)) {
if(memcmp(buf1, buf3, len)) {
result = true;
} else {
fprintf(stderr, "ERROR: public and private RSA keys do not match.\n");
}
} else {
fprintf(stderr, "ERROR: private RSA key does not work.\n");
}
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: public RSA key does not work.\n");
}
2019-08-26 11:44:53 +00:00
2022-04-22 18:24:15 +00:00
free(buf3);
free(buf2);
free(buf1);
2019-08-26 11:44:53 +00:00
2022-04-22 18:24:15 +00:00
if(!result) {
2019-08-26 11:44:52 +00:00
return 1;
}
2022-04-22 18:24:15 +00:00
2019-08-26 11:44:52 +00:00
}
} else {
2019-08-26 11:44:53 +00:00
if(rsa_pub) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: A public RSA key was found but no private key is known.\n");
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
#endif
ecdsa_t *ecdsa_pub = NULL;
f = fopen(fname, "r");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(f) {
ecdsa_pub = get_pubkey(f);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!ecdsa_pub) {
2019-08-26 11:44:52 +00:00
rewind(f);
ecdsa_pub = ecdsa_read_pem_public_key(f);
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
fclose(f);
2019-08-26 11:44:52 +00:00
}
if(ecdsa_priv) {
if(!ecdsa_pub) {
fprintf(stderr, "WARNING: No (usable) public Ed25519 key found.\n");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(ask_fix()) {
FILE *f = fopen(fname, "a");
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(f) {
2019-08-26 11:44:53 +00:00
if(ecdsa_write_pem_public_key(ecdsa_priv, f)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "Wrote Ed25519 public key to %s.\n", fname);
2019-08-26 11:44:53 +00:00
} else {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: could not write Ed25519 public key to %s.\n", fname);
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
fclose(f);
} else {
fprintf(stderr, "ERROR: could not append to %s: %s\n", fname, strerror(errno));
}
}
} else {
// TODO: suggest remedies
char *key1 = ecdsa_get_base64_public_key(ecdsa_pub);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!key1) {
fprintf(stderr, "ERROR: public Ed25519 key does not work.\n");
return 1;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
char *key2 = ecdsa_get_base64_public_key(ecdsa_priv);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!key2) {
free(key1);
fprintf(stderr, "ERROR: private Ed25519 key does not work.\n");
return 1;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
int result = strcmp(key1, key2);
free(key1);
free(key2);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(result) {
fprintf(stderr, "ERROR: public and private Ed25519 keys do not match.\n");
return 1;
}
}
} else {
2019-08-26 11:44:53 +00:00
if(ecdsa_pub) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: A public Ed25519 key was found but no private key is known.\n");
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
// Check whether scripts are executable
struct dirent *ent;
DIR *dir = opendir(confbase);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!dir) {
fprintf(stderr, "ERROR: cannot read directory %s: %s\n", confbase, strerror(errno));
return 1;
}
while((ent = readdir(dir))) {
2019-08-26 11:44:53 +00:00
if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down")) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
strncpy(fname, ent->d_name, sizeof(fname));
2019-08-26 11:44:52 +00:00
char *dash = strrchr(fname, '-');
2019-08-26 11:44:53 +00:00
if(!dash) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
*dash = 0;
if(strcmp(fname, "tinc") && strcmp(fname, "host") && strcmp(fname, "subnet")) {
static bool explained = false;
fprintf(stderr, "WARNING: Unknown script %s" SLASH "%s found.\n", confbase, ent->d_name);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!explained) {
fprintf(stderr, "The only scripts in %s executed by tinc are:\n", confbase);
fprintf(stderr, "tinc-up, tinc-down, host-up, host-down, subnet-up and subnet-down.\n");
explained = true;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
continue;
}
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s" SLASH "%s", confbase, ent->d_name);
2019-08-26 11:44:52 +00:00
if(access(fname, R_OK | X_OK)) {
if(errno != EACCES) {
fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno));
continue;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: cannot read and execute %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(ask_fix()) {
2019-08-26 11:44:53 +00:00
if(chmod(fname, 0755)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: cannot change permissions on %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
}
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
closedir(dir);
2019-08-26 11:44:53 +00:00
snprintf(dname, sizeof(dname), "%s" SLASH "hosts", confbase);
2019-08-26 11:44:52 +00:00
dir = opendir(dname);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(!dir) {
fprintf(stderr, "ERROR: cannot read directory %s: %s\n", dname, strerror(errno));
return 1;
}
while((ent = readdir(dir))) {
2019-08-26 11:44:53 +00:00
if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down")) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
strncpy(fname, ent->d_name, sizeof(fname));
2019-08-26 11:44:52 +00:00
char *dash = strrchr(fname, '-');
2019-08-26 11:44:53 +00:00
if(!dash) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
*dash = 0;
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
2019-08-26 11:44:52 +00:00
if(access(fname, R_OK | X_OK)) {
if(errno != EACCES) {
fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno));
continue;
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
fprintf(stderr, "WARNING: cannot read and execute %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(ask_fix()) {
2019-08-26 11:44:53 +00:00
if(chmod(fname, 0755)) {
2019-08-26 11:44:52 +00:00
fprintf(stderr, "ERROR: cannot change permissions on %s: %s\n", fname, strerror(errno));
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
}
}
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
closedir(dir);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
// Check for obsolete / unsafe / unknown configuration variables.
check_conffile(tinc_conf, true);
dir = opendir(dname);
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
if(dir) {
while((ent = readdir(dir))) {
2019-08-26 11:44:53 +00:00
if(!check_id(ent->d_name)) {
2019-08-26 11:44:52 +00:00
continue;
2019-08-26 11:44:53 +00:00
}
2019-08-26 11:44:52 +00:00
2019-08-26 11:44:53 +00:00
snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
2019-08-26 11:44:52 +00:00
check_conffile(fname, false);
}
2019-08-26 11:44:53 +00:00
2019-08-26 11:44:52 +00:00
closedir(dir);
}
return 0;
}