projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Silence clang-tidy warnings about atoi(getenv())
[tinc]
/
src
/
fsck.c
diff --git
a/src/fsck.c
b/src/fsck.c
index
7b18c19
..
b44b775
100644
(file)
--- a/
src/fsck.c
+++ b/
src/fsck.c
@@
-1,6
+1,6
@@
/*
fsck.c -- Check the configuration files for problems
/*
fsck.c -- Check the configuration files for problems
- Copyright (C) 2014-202
1
Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2014-202
2
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
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
@@
-64,6
+64,7
@@
again:
goto again;
}
goto again;
}
+static void print_tinc_cmd(const char *format, ...) ATTR_FORMAT(printf, 1, 2);
static void print_tinc_cmd(const char *format, ...) {
if(confbasegiven) {
fprintf(stderr, "%s -c %s ", exe_name, confbase);
static void print_tinc_cmd(const char *format, ...) {
if(confbasegiven) {
fprintf(stderr, "%s -c %s ", exe_name, confbase);
@@
-119,19
+120,19
@@
static int strtailcmp(const char *str, const char *tail) {
}
static void check_conffile(const char *nodename, bool server) {
}
static void check_conffile(const char *nodename, bool server) {
- splay_tree_t
*config = NULL
;
+ splay_tree_t
config
;
init_configuration(&config);
bool read;
if(server) {
init_configuration(&config);
bool read;
if(server) {
- read = read_server_config(config);
+ read = read_server_config(
&
config);
} else {
} else {
- read = read_host_config(config, nodename, true);
+ read = read_host_config(
&
config, nodename, true);
}
if(!read) {
}
if(!read) {
-
exit_configuration
(&config);
+
splay_empty_tree
(&config);
return;
}
return;
}
@@
-141,10
+142,16
@@
static void check_conffile(const char *nodename, bool server) {
++total_vars;
}
++total_vars;
}
- int count[total_vars];
- memset(count, 0, sizeof(count));
+ if(!total_vars) {
+ splay_empty_tree(&config);
+ return;
+ }
- for splay_each(config_t, conf, config) {
+ const size_t countlen = total_vars * sizeof(int);
+ int *count = alloca(countlen);
+ memset(count, 0, countlen);
+
+ for splay_each(config_t, conf, &config) {
int var_type = 0;
for(size_t i = 0; variables[i].name; ++i) {
int var_type = 0;
for(size_t i = 0; variables[i].name; ++i) {
@@
-181,13
+188,13
@@
static void check_conffile(const char *nodename, bool server) {
}
}
}
}
-
exit_configuration
(&config);
+
splay_empty_tree
(&config);
}
}
-#ifdef HAVE_
MINGW
+#ifdef HAVE_
WINDOWS
typedef int uid_t;
typedef int uid_t;
-static uid_t getuid() {
+static uid_t getuid(
void
) {
return 0;
}
return 0;
}
@@
-218,9
+225,9
@@
static void check_key_file_mode(const char *fname) {
}
}
}
}
}
}
-#endif // HAVE_
MINGW
+#endif // HAVE_
WINDOWS
-static char *read_node_name() {
+static char *read_node_name(
void
) {
if(access(tinc_conf, R_OK) == 0) {
return get_my_name(true);
}
if(access(tinc_conf, R_OK) == 0) {
return get_my_name(true);
}
@@
-329,7
+336,7
@@
static bool test_rsa_keypair(rsa_t *rsa_priv, rsa_t *rsa_pub, const char *host_f
uint8_t *encrypted = xzalloc(len);
uint8_t *decrypted = xzalloc(len);
uint8_t *encrypted = xzalloc(len);
uint8_t *decrypted = xzalloc(len);
- randomize(plaintext, len);
+
prng_
randomize(plaintext, len);
plaintext[0] &= 0x7f;
if(rsa_public_encrypt(rsa_pub, plaintext, len, encrypted)) {
plaintext[0] &= 0x7f;
if(rsa_public_encrypt(rsa_pub, plaintext, len, encrypted)) {
@@
-438,7
+445,7
@@
static bool check_config_mode(const char *fname) {
return true;
}
return true;
}
-static bool check_script_confdir() {
+static bool check_script_confdir(
void
) {
char fname[PATH_MAX];
DIR *dir = opendir(confbase);
char fname[PATH_MAX];
DIR *dir = opendir(confbase);
@@
-535,14
+542,11
@@
static bool check_public_keys(splay_tree_t *config, const char *name, rsa_t *rsa
fprintf(stderr, "WARNING: cannot read %s\n", host_file);
}
fprintf(stderr, "WARNING: cannot read %s\n", host_file);
}
- ecdsa_t *ec_pub = NULL;
- read_ecdsa_public_key(&ec_pub, &config, name);
+ ecdsa_t *ec_pub = read_ecdsa_public_key(&config, name);
bool success = true;
#ifndef DISABLE_LEGACY
bool success = true;
#ifndef DISABLE_LEGACY
- rsa_t *rsa_pub = NULL;
- read_rsa_public_key(&rsa_pub, config, name);
-
+ rsa_t *rsa_pub = read_rsa_public_key(config, name);
success = check_rsa_pubkey(rsa_priv, rsa_pub, host_file);
rsa_free(rsa_pub);
#endif
success = check_rsa_pubkey(rsa_priv, rsa_pub, host_file);
rsa_free(rsa_pub);
#endif
@@
-616,7
+620,7
@@
static void check_config_variables(const char *host_dir) {
}
}
}
}
-static bool check_scripts_and_configs() {
+static bool check_scripts_and_configs(
void
) {
// Check whether scripts are executable.
if(!check_script_confdir()) {
return false;
// Check whether scripts are executable.
if(!check_script_confdir()) {
return false;
@@
-649,17
+653,17
@@
int fsck(const char *argv0) {
// Avoid touching global configuration here. Read the config files into
// a temporary configuration tree, then throw it away after fsck is done.
// Avoid touching global configuration here. Read the config files into
// a temporary configuration tree, then throw it away after fsck is done.
- splay_tree_t
*config = NULL
;
+ splay_tree_t
config
;
init_configuration(&config);
// Read the server configuration file and append host configuration for our node.
init_configuration(&config);
// Read the server configuration file and append host configuration for our node.
- bool success = read_server_config(config) &&
- read_host_config(config, name, true);
+ bool success = read_server_config(
&
config) &&
+ read_host_config(
&
config, name, true);
// Check both RSA and EC key pairs.
// We need working configuration to run this check.
if(success) {
// Check both RSA and EC key pairs.
// We need working configuration to run this check.
if(success) {
- success = check_keypairs(config, name);
+ success = check_keypairs(
&
config, name);
}
// Check that scripts are executable and check the config for invalid variables.
}
// Check that scripts are executable and check the config for invalid variables.
@@
-667,7
+671,7
@@
int fsck(const char *argv0) {
// This way, we can diagnose more issues on the first run.
success = success & check_scripts_and_configs();
// This way, we can diagnose more issues on the first run.
success = success & check_scripts_and_configs();
-
exit_configuration
(&config);
+
splay_empty_tree
(&config);
free(name);
exe_name = NULL;
free(name);
exe_name = NULL;