Improve conf and conf testing
This commit is contained in:
@@ -166,30 +166,35 @@ static int test_conf_perms(char *config)
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_MISSING);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISREG(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_NOTFILE);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config);
|
||||
return 1;
|
||||
}
|
||||
if (!(0400 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_PERM);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config);
|
||||
return 1;
|
||||
}
|
||||
if (access(config, R_OK) != 0) {
|
||||
enumtostr(confresult, CONF_NOT_READABLE);
|
||||
log(ERROR, confresult, config);
|
||||
return 1;
|
||||
}
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_UID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config);
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_FILE_GID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config);
|
||||
} else if ((0004 & s.st_mode) ||
|
||||
(0002 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_FILE_PERM_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,31 +203,31 @@ static int test_conf_perms(char *config)
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_DIR_MISSING);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config_copy);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_NOTDIR);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config_copy);
|
||||
return 1;
|
||||
}
|
||||
if (!(0400 & s.st_mode) ||
|
||||
!(0100 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM);
|
||||
log(ERROR, confresult);
|
||||
log(ERROR, confresult, config_copy);
|
||||
return 1;
|
||||
}
|
||||
if (s.st_uid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_UID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config_copy);
|
||||
} else if (s.st_gid != 0) {
|
||||
enumtostr(confresult, CONF_DIR_GID_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config_copy);
|
||||
} else if ((0004 & s.st_mode) ||
|
||||
(0002 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM_INSECURE);
|
||||
log(WARNING, confresult);
|
||||
log(WARNING, confresult, config_copy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,18 +352,18 @@ static int test_conf_syntax(char *config)
|
||||
} else if (!strcmp(buf, "rmps.logfile")) {
|
||||
strncpy(conf.rmps.logfile, tmp + 1,
|
||||
sizeof(conf.rmps.logfile) - 1);
|
||||
if (fopen_and_mkdir(conf.rmps.logfile) != 0)
|
||||
failed = 1;
|
||||
/*if (fopen_and_mkdir(conf.rmps.logfile) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.errlog")) {
|
||||
strncpy(conf.rmps.errlog, tmp + 1,
|
||||
sizeof(conf.rmps.errlog) - 1);
|
||||
if (fopen_and_mkdir(conf.rmps.errlog) != 0)
|
||||
failed = 1;
|
||||
/*if (fopen_and_mkdir(conf.rmps.errlog) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.pidfile")) {
|
||||
strncpy(conf.rmps.pidfile, tmp + 1,
|
||||
sizeof(conf.rmps.pidfile) - 1);
|
||||
if (fopen_and_mkdir(conf.rmps.pidfile) != 0)
|
||||
failed = 1;
|
||||
/*if (fopen_and_mkdir(conf.rmps.pidfile) != 0)
|
||||
failed = 1;*/
|
||||
} else if (!strcmp(buf, "rmps.loglevel")) {
|
||||
if (strlen(tmp + 1) == 1 &&
|
||||
(tmp[1] > '0' && tmp[1] < '5'))
|
||||
|
||||
@@ -29,6 +29,7 @@ enum ERROR_CODES {
|
||||
CONF_MISSING, /* 103 */
|
||||
CONF_PERM, /* 104 */
|
||||
CONF_NOTFILE, /* 105 */
|
||||
CONF_NOT_READABLE, /* 106 */
|
||||
};
|
||||
|
||||
enum WARN_CODES {
|
||||
|
||||
18
src/main.c
18
src/main.c
@@ -34,9 +34,11 @@ static void usage(char *argv)
|
||||
{
|
||||
fprintf(stderr, "Usage:\n%s TASK [-c CONFIG] [-d]\n\n"
|
||||
"Tasks:\n"
|
||||
"\t--start\t\tStart the RMPS server.\n"
|
||||
"\t--start\t\tStart the RMPS server. This is by default. \n"
|
||||
"\t--stop\t\tStop the RMPS server.\n"
|
||||
"\t--restart\tRestart the RMPS server.\n\n"
|
||||
"\t--restart\tRestart the RMPS server.\n"
|
||||
"\t-t, --test\tTest the configuration file and exit,\n"
|
||||
"\t-T\t\tTest the configuration file, dump it to stdout and exit.\n"
|
||||
"Options:\n"
|
||||
"\t-c, --config\n"
|
||||
"\t\tSpecify the configuration file path. Default is set "
|
||||
@@ -53,10 +55,12 @@ int main(int argc, char *argv[])
|
||||
enum tasks {
|
||||
START = 1,
|
||||
STOP,
|
||||
RESTART
|
||||
RESTART,
|
||||
TEST,
|
||||
TEST_AND_EXPORT
|
||||
};
|
||||
static int task;
|
||||
const char opts_short[] = "dc:h";
|
||||
static int task = START;
|
||||
const char opts_short[] = "dc:htT";
|
||||
static struct option opts_long[] =
|
||||
{
|
||||
{"start", no_argument, &task, START},
|
||||
@@ -112,14 +116,14 @@ int main(int argc, char *argv[])
|
||||
log(VERBOSE, "Conf parser finished successfully");
|
||||
//confexport();
|
||||
|
||||
if (task == STOP|| task == RESTART) {
|
||||
if (task == STOP || task == RESTART) {
|
||||
char buf[10];
|
||||
int pid;
|
||||
FILE *fp;
|
||||
|
||||
if (task == STOP)
|
||||
log(VERBOSE, "We got a stop signal!");
|
||||
else if (task == RESTART)
|
||||
else /* RESTART */
|
||||
log(VERBOSE, "We got a restart signal!");
|
||||
|
||||
fp = fopen(conf.rmps.pidfile, "r");
|
||||
|
||||
Reference in New Issue
Block a user