RMPS: improve enumtostr() and confparser
This commit is contained in:
@@ -154,37 +154,41 @@ static void init_conf(void)
|
||||
//conf.nfs = {0}; /* TODO */
|
||||
}
|
||||
|
||||
static void log_and_free(char **msg, const char *config, char *mem)
|
||||
{
|
||||
log(ERROR, *msg, config);
|
||||
if (*msg) /* in case enumtostr() fails */
|
||||
free(*msg);
|
||||
free(mem);
|
||||
}
|
||||
|
||||
static bool test_conf_perms(char *config)
|
||||
{
|
||||
struct stat s;
|
||||
char confresult[128];
|
||||
char *confresult;
|
||||
char *config_copy = strdup(config);
|
||||
int err = stat(config, &s);
|
||||
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_MISSING);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_MISSING);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISREG(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_NOTFILE);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_NOTFILE);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (!(0400 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_PERM);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_PERM);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (access(config, R_OK) != 0) {
|
||||
enumtostr(confresult, CONF_NOT_READABLE);
|
||||
log(ERROR, confresult, config);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_NOT_READABLE);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -193,23 +197,20 @@ static bool test_conf_perms(char *config)
|
||||
|
||||
if (err == -1) {
|
||||
if (errno == ENOENT) {
|
||||
enumtostr(confresult, CONF_DIR_MISSING);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_DIR_MISSING);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_NOTDIR);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_DIR_NOTDIR);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
if (!(0400 & s.st_mode) ||
|
||||
!(0100 & s.st_mode)) {
|
||||
enumtostr(confresult, CONF_DIR_PERM);
|
||||
log(ERROR, confresult, config_copy);
|
||||
free(config_copy);
|
||||
enumtostr(&confresult, CONF_DIR_PERM);
|
||||
log_and_free(&confresult, config, config_copy);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user