Stricter checks for node names.
This commit is contained in:
parent
03f72c6173
commit
cedfeccb24
1 changed files with 27 additions and 5 deletions
|
@ -832,6 +832,11 @@ static int cmd_connect(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!check_id(argv[2])) {
|
||||||
|
fprintf(stderr, "Invalid name for node.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(!connect_tincd())
|
if(!connect_tincd())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -850,6 +855,11 @@ static int cmd_disconnect(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!check_id(argv[2])) {
|
||||||
|
fprintf(stderr, "Invalid name for node.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(!connect_tincd())
|
if(!connect_tincd())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -1018,6 +1028,11 @@ static int cmd_config(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(node && !check_id(node)) {
|
||||||
|
fprintf(stderr, "Invalid name for node.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Open the right configuration file.
|
// Open the right configuration file.
|
||||||
char *filename;
|
char *filename;
|
||||||
if(node)
|
if(node)
|
||||||
|
@ -1151,6 +1166,15 @@ static int cmd_config(int argc, char *argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool check_id(const char *name) {
|
||||||
|
for(int i = 0; i < strlen(name); i++) {
|
||||||
|
if(!isalnum(name[i]) && name[i] != '_')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int cmd_init(int argc, char *argv[]) {
|
static int cmd_init(int argc, char *argv[]) {
|
||||||
if(!access(tinc_conf, F_OK)) {
|
if(!access(tinc_conf, F_OK)) {
|
||||||
fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
|
fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
|
||||||
|
@ -1184,12 +1208,10 @@ static int cmd_init(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < strlen(name); i++) {
|
if(!check_id(name)) {
|
||||||
if(!isalnum(name[i]) && name[i] != '_') {
|
|
||||||
fprintf(stderr, "Invalid Name! Only a-z, A-Z, 0-9 and _ are allowed characters.\n");
|
fprintf(stderr, "Invalid Name! Only a-z, A-Z, 0-9 and _ are allowed characters.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(mkdir(CONFDIR, 0755) && errno != EEXIST) {
|
if(mkdir(CONFDIR, 0755) && errno != EEXIST) {
|
||||||
fprintf(stderr, "Could not create directory %s: %s\n", CONFDIR, strerror(errno));
|
fprintf(stderr, "Could not create directory %s: %s\n", CONFDIR, strerror(errno));
|
||||||
|
|
Loading…
Reference in a new issue