Lots and lots of whitespace and code style fixes
This commit is contained in:
154
confparser.c
154
confparser.c
@@ -8,8 +8,8 @@
|
||||
#include "confparser.h"
|
||||
#include "enum_functions.h"
|
||||
|
||||
static int test_conf_perms();
|
||||
static int test_conf_syntax();
|
||||
static int test_conf_perms(void);
|
||||
static int test_conf_syntax(void);
|
||||
|
||||
struct conf_table conf = {
|
||||
0, /* isvalid initial state */
|
||||
@@ -39,7 +39,7 @@ struct conf_table conf = {
|
||||
},
|
||||
{
|
||||
0 /* nfs -> TODO */
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const char* conf_db_pass(void)
|
||||
@@ -54,7 +54,7 @@ const char* conf_db_hostname(void)
|
||||
|
||||
void confexport(void)
|
||||
{
|
||||
printf( "db.type=%s\n"
|
||||
printf("db.type=%s\n"
|
||||
"db.hostname=%s\n"
|
||||
"db.port=%s\n"
|
||||
"db.pass=%s\n"
|
||||
@@ -75,17 +75,17 @@ void confexport(void)
|
||||
"rmps.client_tls_key=%s\n"
|
||||
"rmps.client_poolsize=%d\n",
|
||||
conf.db.type,
|
||||
conf.db.hostname,
|
||||
conf.db.port,
|
||||
conf.db.hostname,
|
||||
conf.db.port,
|
||||
conf.db.pass,
|
||||
conf.rmps.agent_ip,
|
||||
conf.rmps.agent_port,
|
||||
conf.rmps.client_ip,
|
||||
conf.rmps.client_port,
|
||||
conf.rmps.logfile,
|
||||
conf.rmps.errlog,
|
||||
conf.rmps.loglevel,
|
||||
conf.rmps.pidfile,
|
||||
conf.rmps.agent_ip,
|
||||
conf.rmps.agent_port,
|
||||
conf.rmps.client_ip,
|
||||
conf.rmps.client_port,
|
||||
conf.rmps.logfile,
|
||||
conf.rmps.errlog,
|
||||
conf.rmps.loglevel,
|
||||
conf.rmps.pidfile,
|
||||
conf.rmps.agent_tls_crt,
|
||||
conf.rmps.agent_tls_key,
|
||||
conf.rmps.cafile,
|
||||
@@ -97,33 +97,34 @@ void confexport(void)
|
||||
);
|
||||
}
|
||||
|
||||
static int fopen_and_mkdir(const char *dir) {
|
||||
static int fopen_and_mkdir(const char *dir)
|
||||
{
|
||||
char tmp[256];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
FILE *fp;
|
||||
|
||||
snprintf(tmp, sizeof(tmp),"%s",dir);
|
||||
snprintf(tmp, sizeof(tmp), "%s", dir);
|
||||
len = strlen(tmp);
|
||||
if(tmp[len - 1] == '/')
|
||||
if (tmp[len - 1] == '/')
|
||||
tmp[len - 1] = 0;
|
||||
for (p = tmp + 1; *p; p++)
|
||||
if(*p == '/') {
|
||||
if (*p == '/') {
|
||||
*p = 0;
|
||||
if (mkdir(tmp, S_IRWXU) == -1 && errno != EEXIST) {
|
||||
log( ERROR,
|
||||
log(ERROR,
|
||||
"Permission denied to create directory: %s",
|
||||
tmp );
|
||||
tmp);
|
||||
return 1;
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
fp = fopen(dir, "a");
|
||||
if (!fp) {
|
||||
log(ERROR, "Permission denied to write into: %s", dir);
|
||||
}
|
||||
fp = fopen(dir, "a");
|
||||
if (!fp) {
|
||||
log(ERROR, "Permission denied to write into: %s", dir);
|
||||
return 1;
|
||||
}
|
||||
fclose(fp);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,8 +147,8 @@ static int test_conf_perms(void)
|
||||
log(ERROR, confresult);
|
||||
return 1;
|
||||
}
|
||||
if ( !(S_IRUSR & s.st_mode) ||
|
||||
!(S_IXUSR & s.st_mode) ) {
|
||||
if (!(S_IRUSR & s.st_mode) ||
|
||||
!(S_IXUSR & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM);
|
||||
log(ERROR, confresult);
|
||||
return 1;
|
||||
@@ -155,13 +156,11 @@ static int test_conf_perms(void)
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_UID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
else if (s.st_gid != 0) {
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_GID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
else if ( (S_IROTH & s.st_mode) ||
|
||||
(S_IWOTH & s.st_mode) ) {
|
||||
} else if ((S_IROTH & s.st_mode) ||
|
||||
(S_IWOTH & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
@@ -189,16 +188,14 @@ static int test_conf_perms(void)
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_UID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
else if (s.st_gid != 0) {
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_GID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
else if ( (S_IROTH & s.st_mode) ||
|
||||
(S_IWOTH & s.st_mode) ) {
|
||||
} else if ((S_IROTH & s.st_mode) ||
|
||||
(S_IWOTH & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_FILE_PERM_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; /* conf is readable */
|
||||
}
|
||||
@@ -226,9 +223,9 @@ static int test_conf_syntax(void)
|
||||
if ((tmp = strstr(buf, "=")))
|
||||
*tmp = '\0';
|
||||
else {
|
||||
log( ERROR,
|
||||
"Bad entry in /etc/rmps/rmps.conf, line %d: %s",
|
||||
j, buf );
|
||||
log(ERROR,
|
||||
"Bad entry in /etc/rmps/rmps.conf, line %d: %s",
|
||||
j, buf);
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
continue;
|
||||
@@ -238,9 +235,9 @@ static int test_conf_syntax(void)
|
||||
if (tmp[i] == '\n')
|
||||
tmp[i] = '\0';
|
||||
if (tmp[strspn(tmp + 1, " \t\v\r\n") + 1] == '\0') {
|
||||
log( ERROR,
|
||||
"Specified entry without value, line %d: %s",
|
||||
j, buf );
|
||||
log(ERROR,
|
||||
"Specified entry without value, line %d: %s",
|
||||
j, buf);
|
||||
failed = 1;
|
||||
continue;
|
||||
}
|
||||
@@ -278,28 +275,30 @@ static int test_conf_syntax(void)
|
||||
/* TODO */
|
||||
} else if (!strcmp(buf, "rmps.agent_port")) {
|
||||
if ((i = strlen(tmp + 1)) < 6) {
|
||||
if ((signed int)strspn(tmp + 1, "1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if (i > 0 && i < 65536) {
|
||||
strcpy(conf.rmps.agent_port, tmp + 1);
|
||||
if ((signed int)strspn(tmp + 1, "1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if (i > 0 && i < 65536) {
|
||||
strcpy(conf.rmps.agent_port,
|
||||
tmp + 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "rmps.client_ip")) {
|
||||
/* TODO */
|
||||
} else if (!strcmp(buf, "rmps.client_port")) {
|
||||
if ((i = strlen(tmp + 1)) < 6) {
|
||||
if ((signed int)strspn(tmp + 1, "1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if (i > 0 && i < 65536) {
|
||||
strcpy(conf.rmps.client_port, tmp + 1);
|
||||
if ((signed int)strspn(tmp + 1, "1234567890") == i) {
|
||||
i = atoi(tmp + 1);
|
||||
if (i > 0 && i < 65536) {
|
||||
strcpy(conf.rmps.client_port,
|
||||
tmp + 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ok = 0;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "rmps.logfile")) {
|
||||
@@ -309,13 +308,15 @@ static int test_conf_syntax(void)
|
||||
} else if (!strcmp(buf, "rmps.errlog")) {
|
||||
strcpy(conf.rmps.errlog, tmp + 1);
|
||||
if (fopen_and_mkdir(conf.rmps.errlog) != 0)
|
||||
failed = 1;
|
||||
failed = 1;
|
||||
} else if (!strcmp(buf, "rmps.pidfile")) {
|
||||
strcpy(conf.rmps.pidfile, tmp + 1);
|
||||
/*if (fopen_and_mkdir(conf.rmps.pidfile) != 0)
|
||||
failed = 1;*/
|
||||
* failed = 1;
|
||||
*/
|
||||
} else if (!strcmp(buf, "rmps.loglevel")) {
|
||||
if (strlen(tmp + 1) == 1 && (tmp[1] > '0' && tmp[1] < '5'))
|
||||
if (strlen(tmp + 1) == 1 &&
|
||||
(tmp[1] > '0' && tmp[1] < '5'))
|
||||
conf.rmps.loglevel = tmp[1] - '0';
|
||||
else
|
||||
failed = 1;
|
||||
@@ -323,21 +324,18 @@ static int test_conf_syntax(void)
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
}
|
||||
else if (access(tmp + 1, R_OK) == -1) {
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
} else
|
||||
strncpy(conf.rmps.agent_tls_crt,
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.agent_tls_crt));
|
||||
}
|
||||
else if (!strcmp(buf, "rmps.agent_tls_key")) {
|
||||
} else if (!strcmp(buf, "rmps.agent_tls_key")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
}
|
||||
else if (access(tmp + 1, R_OK) == -1) {
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
} else
|
||||
@@ -345,23 +343,23 @@ static int test_conf_syntax(void)
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.agent_tls_key));
|
||||
} else if (!strcmp(buf, "rmps.cipherlist")) {
|
||||
strncpy(conf.rmps.cipherlist, tmp + 1, sizeof(conf.rmps.cipherlist));
|
||||
strncpy(conf.rmps.cipherlist,
|
||||
tmp + 1, sizeof(conf.rmps.cipherlist));
|
||||
} else if (!strcmp(buf, "rmps.cafile")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
}
|
||||
else if (access(tmp + 1, R_OK) == -1) {
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable\n", tmp + 1);
|
||||
failed = 1;
|
||||
} else
|
||||
strncpy(conf.rmps.cafile, tmp + 1, sizeof(conf.rmps.cafile));
|
||||
strncpy(conf.rmps.cafile,
|
||||
tmp + 1, sizeof(conf.rmps.cafile));
|
||||
} else if (!strcmp(buf, "rmps.client_tls_crt")) {
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
}
|
||||
else if (access(tmp + 1, R_OK) == -1) {
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
} else
|
||||
@@ -372,8 +370,7 @@ static int test_conf_syntax(void)
|
||||
if (access(tmp + 1, F_OK) == -1) {
|
||||
log(ERROR, "%s is missing", tmp + 1);
|
||||
failed = 1;
|
||||
}
|
||||
else if (access(tmp + 1, R_OK) == -1) {
|
||||
} else if (access(tmp + 1, R_OK) == -1) {
|
||||
log(ERROR, "%s is not readable", tmp + 1);
|
||||
failed = 1;
|
||||
} else
|
||||
@@ -381,11 +378,12 @@ static int test_conf_syntax(void)
|
||||
tmp + 1,
|
||||
sizeof(conf.rmps.client_tls_key));
|
||||
} else
|
||||
log(ERROR, "Unknown config entry on line %d: %s", j, buf);
|
||||
log(ERROR, "Unknown config entry on line %d: %s",
|
||||
j, buf);
|
||||
if (!ok) {
|
||||
log( ERROR,
|
||||
"Invalid value for \"%s\", line %d: \"%s\"",
|
||||
buf, j, tmp + 1 );
|
||||
log(ERROR,
|
||||
"Invalid value for \"%s\", line %d: \"%s\"",
|
||||
buf, j, tmp + 1);
|
||||
ok = !ok;
|
||||
}
|
||||
}
|
||||
@@ -404,7 +402,7 @@ int confparse(void)
|
||||
result = test_conf_perms();
|
||||
if (result)
|
||||
return 1; /* Bad conf perms */
|
||||
|
||||
|
||||
result = test_conf_syntax();
|
||||
if (result != 0)
|
||||
return 1; /* Bad conf syntax */
|
||||
|
||||
Reference in New Issue
Block a user