From 2fc6c313c63f098ca1119d4cac6db620c3005bfc Mon Sep 17 00:00:00 2001 From: Giovanni Giacobbi Date: Mon, 8 Apr 2002 18:39:27 +0000 Subject: [PATCH] fixed some output config text, added macro SILC_SERVER_CONFIG_ALLOCTMP, drop root privs when in foreground but NOT debugging. --- CHANGES | 18 +++ apps/silcd/serverconfig.c | 225 ++++++++++++++++---------------------- apps/silcd/silcd.c | 10 +- lib/silcutil/silcconfig.c | 1 + lib/silcutil/silcconfig.h | 1 + 5 files changed, 121 insertions(+), 134 deletions(-) diff --git a/CHANGES b/CHANGES index 2dc369cd..baec17fa 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +Mon Apr 8 19:57:40 CEST 2002 Johnny Mnemonic + + * Added config parse status SILC_CONFIG_EPRINTLINE, this status + must be handled by the application and should tell the application + that an error message was already printed, and it should print the + config coords (line, filename, ...). Affected files are + silcd/serverconfig.c, lib/silcutil/silcconfig.[ch]. + + * Added local macro SILC_SERVER_CONFIG_ALLOCTMP to make the + server config parsing code more readable. + + Fixed a bug in the fetch_logging() config callback. + + Affected files is silcd/serverconfig.c. + + * Drop root privileges when started in foreground. Don't drop them + if debugging also. Affected file is silcd/silcd.c. + Wed Apr 3 12:36:05 CEST 2002 Pekka Riikonen * Added better error logging in rekey protocol. Affected file diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index b5dbc04c..88a6b4cb 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -34,6 +34,13 @@ __type__ *findtmp, *tmp = (__type__ *) config->tmp; \ int got_errno = 0 +/* allocate the tmp field for fetching data */ +#define SILC_SERVER_CONFIG_ALLOCTMP(__type__) \ + if (!tmp) { \ + config->tmp = silc_calloc(1, sizeof(*findtmp)); \ + tmp = (__type__ *) config->tmp; \ + } + /* append the tmp field to the specified list */ #define SILC_SERVER_CONFIG_LIST_APPENDTMP(__list__) \ if (!__list__) { \ @@ -78,7 +85,7 @@ my_set_param_defaults(SilcServerConfigConnParams *params, (params->p ? params->p : (defaults && defaults->p ? defaults->p : d)) SET_PARAM_DEFAULT(connections_max, SILC_SERVER_MAX_CONNECTIONS); - SET_PARAM_DEFAULT(connections_max_per_host, + SET_PARAM_DEFAULT(connections_max_per_host, SILC_SERVER_MAX_CONNECTIONS_SINGLE); SET_PARAM_DEFAULT(keepalive_secs, SILC_SERVER_KEEPALIVE); SET_PARAM_DEFAULT(reconnect_count, SILC_SERVER_RETRY_COUNT); @@ -91,7 +98,7 @@ my_set_param_defaults(SilcServerConfigConnParams *params, /* Find connection parameters by the parameter block name. */ static SilcServerConfigConnParams * -my_find_param(SilcServerConfig config, const char *name, SilcUInt32 line) +my_find_param(SilcServerConfig config, const char *name) { SilcServerConfigConnParams *param; @@ -100,15 +107,15 @@ my_find_param(SilcServerConfig config, const char *name, SilcUInt32 line) return param; } - SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line %lu: " - "Cannot find Param \"%s\".\n", line, name)); + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Cannot find Params \"%s\".\n", name)); return NULL; } /* parse an authdata according to its auth method */ -static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, - SilcUInt32 line, void **auth_data, +static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, + SilcUInt32 line, void **auth_data, SilcUInt32 *auth_data_len) { if (auth_meth == SILC_AUTH_PASSWORD) { @@ -123,8 +130,9 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_PEM)) if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_BIN)) { - SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line %lu: " - "Could not load public key file!\n", line)); + SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line " + "%lu: Could not load public key file!\n", + line)); return FALSE; } @@ -200,17 +208,17 @@ SILC_CONFIG_CALLBACK(fetch_generic) } else if (!strcmp(name, "version_protocol")) { CONFIG_IS_DOUBLE(config->param.version_protocol); - config->param.version_protocol = + config->param.version_protocol = (*(char *)val ? strdup((char *) val) : NULL); } else if (!strcmp(name, "version_software")) { CONFIG_IS_DOUBLE(config->param.version_software); - config->param.version_software = + config->param.version_software = (*(char *)val ? strdup((char *) val) : NULL); } else if (!strcmp(name, "version_software_vendor")) { CONFIG_IS_DOUBLE(config->param.version_software_vendor);; - config->param.version_software_vendor = + config->param.version_software_vendor = (*(char *)val ? strdup((char *) val) : NULL); } else @@ -230,22 +238,18 @@ SILC_CONFIG_CALLBACK(fetch_cipher) type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; if (!tmp->name) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } - /* the temporary struct is ok, append it to the list */ + SILC_SERVER_CONFIG_LIST_APPENDTMP(config->cipher); config->tmp = NULL; return SILC_CONFIG_OK; } - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigCipher *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigCipher); /* Identify and save this value */ if (!strcmp(name, "name")) { @@ -282,23 +286,18 @@ SILC_CONFIG_CALLBACK(fetch_hash) type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; if (!tmp->name || (tmp->block_length == 0) || (tmp->digest_length == 0)) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } - /* the temporary struct in tmp is ok */ + SILC_SERVER_CONFIG_LIST_APPENDTMP(config->hash); config->tmp = NULL; return SILC_CONFIG_OK; } - - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigHash *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigHash); /* Identify and save this value */ if (!strcmp(name, "name")) { @@ -335,22 +334,18 @@ SILC_CONFIG_CALLBACK(fetch_hmac) type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; if (!tmp->name || !tmp->hash || (tmp->mac_length == 0)) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } - /* the temporary struct is ok, append it to the list */ + SILC_SERVER_CONFIG_LIST_APPENDTMP(config->hmac); config->tmp = NULL; return SILC_CONFIG_OK; } - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigHmac *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigHmac); /* Identify and save this value */ if (!strcmp(name, "name")) { @@ -384,22 +379,18 @@ SILC_CONFIG_CALLBACK(fetch_pkcs) type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; if (!tmp->name) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } - /* the temporary struct is ok, append it to the list */ + SILC_SERVER_CONFIG_LIST_APPENDTMP(config->pkcs); config->tmp = NULL; return SILC_CONFIG_OK; } - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigPkcs *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigPkcs); /* Identify and save this value */ if (!strcmp(name, "name")) { @@ -447,8 +438,10 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) else if (!strcmp(name, "port")) { int port = *(int *)val; if ((port <= 0) || (port > 65535)) { - SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line)); - return SILC_CONFIG_ESILENT; + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Invalid port number!\n")); + got_errno = SILC_CONFIG_EPRINTLINE; + goto got_err; } server_info->port = (SilcUInt16) port; } @@ -493,7 +486,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) if (!silc_pkcs_load_public_key(file_tmp, &server_info->public_key, SILC_PKCS_FILE_BIN)) { SILC_SERVER_LOG_ERROR(("Error: Could not load public key file.\n")); - SILC_SERVER_LOG_ERROR((" line %lu: file \"%s\"\n", line, file_tmp)); + SILC_SERVER_LOG_ERROR((" line %lu, file \"%s\"\n", line, file_tmp)); return SILC_CONFIG_ESILENT; } } @@ -506,7 +499,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) if (!silc_pkcs_load_private_key(file_tmp, &server_info->private_key, SILC_PKCS_FILE_PEM)) { SILC_SERVER_LOG_ERROR(("Error: Could not load private key file.\n")); - SILC_SERVER_LOG_ERROR((" line %lu: file \"%s\"\n", line, file_tmp)); + SILC_SERVER_LOG_ERROR((" line %lu, file \"%s\"\n", line, file_tmp)); return SILC_CONFIG_ESILENT; } } @@ -520,10 +513,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo) SILC_CONFIG_CALLBACK(fetch_logging) { - SilcServerConfig config = (SilcServerConfig) context; - SilcServerConfigLogging *tmp = - (SilcServerConfigLogging *) config->tmp; - int got_errno; + SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigLogging); if (!strcmp(name, "quicklogs")) { config->logging_quick = *(bool *)val; @@ -531,12 +521,19 @@ SILC_CONFIG_CALLBACK(fetch_logging) else if (!strcmp(name, "flushdelay")) { int flushdelay = *(int *)val; if (flushdelay < 2) { /* this value was taken from silclog.h (min delay) */ - SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid flushdelay value, use " - "quicklogs if you want real-time logging.\n", line)); - return SILC_CONFIG_ESILENT; + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Invalid flushdelay value, use quicklogs if you " + "want real-time logging.\n")); + return SILC_CONFIG_EPRINTLINE; } config->logging_flushdelay = (long) flushdelay; } + + /* The following istances happens only in Logging's sub-blocks, a match + for the sub-block name means that you should store the filename/maxsize + temporary struct to the proper logging channel. + If we get a match for "file" or "maxsize" this means that we are inside + a sub-sub-block and it is safe to alloc a new tmp. */ #define FETCH_LOGGING_CHAN(__chan__, __member__) \ else if (!strcmp(name, __chan__)) { \ if (!tmp) return SILC_CONFIG_OK; \ @@ -552,13 +549,8 @@ SILC_CONFIG_CALLBACK(fetch_logging) FETCH_LOGGING_CHAN("fatals", logging_fatals) #undef FETCH_LOGGING_CHAN else if (!strcmp(name, "file")) { - if (!tmp) { /* FIXME: what the fuck is this? */ - config->tmp = silc_calloc(1, sizeof(*tmp)); - tmp = (SilcServerConfigLogging *) config->tmp; - } - if (tmp->file) { - got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigLogging); + CONFIG_IS_DOUBLE(tmp->file); tmp->file = strdup((char *) val); } else if (!strcmp(name, "size")) { @@ -583,18 +575,16 @@ SILC_CONFIG_CALLBACK(fetch_connparam) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigConnParams); - SERVER_CONFIG_DEBUG(("Received CONNPARAM type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received CONNPARAM type=%d name=\"%s\" (val=%x)", type, name, context)); - if (type == SILC_CONFIG_ARG_BLOCK) { - if (!tmp) + /* check the temporary struct's fields */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; - if (!tmp->name) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } - /* Set defaults */ my_set_param_defaults(tmp, &config->param); @@ -602,12 +592,7 @@ SILC_CONFIG_CALLBACK(fetch_connparam) config->tmp = NULL; return SILC_CONFIG_OK; } - - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigConnParams *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigConnParams); if (!strcmp(name, "name")) { CONFIG_IS_DOUBLE(tmp->name); @@ -650,7 +635,7 @@ SILC_CONFIG_CALLBACK(fetch_connparam) } else if (!strcmp(name, "version_software_vendor")) { CONFIG_IS_DOUBLE(tmp->version_software_vendor);; - tmp->version_software_vendor = + tmp->version_software_vendor = (*(char *)val ? strdup((char *) val) : NULL); } else @@ -672,14 +657,11 @@ SILC_CONFIG_CALLBACK(fetch_client) SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", type, name, context)); - /* alloc tmp before block checking (empty sub-blocks are welcome here) */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigClient *) config->tmp; - } + /* Alloc before block checking, because empty sub-blocks are welcome here */ + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigClient); if (type == SILC_CONFIG_ARG_BLOCK) { - /* closing the block */ + /* empty sub-blocks are welcome */ SILC_SERVER_CONFIG_LIST_APPENDTMP(config->clients); config->tmp = NULL; return SILC_CONFIG_OK; @@ -708,9 +690,9 @@ SILC_CONFIG_CALLBACK(fetch_client) } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); - tmp->param = my_find_param(config, (char *) val, line); - if (!tmp->param) { /* error already output */ - got_errno = SILC_CONFIG_ESILENT; + tmp->param = my_find_param(config, (char *) val); + if (!tmp->param) { /* error message already output */ + got_errno = SILC_CONFIG_EPRINTLINE; goto got_err; } } @@ -732,22 +714,16 @@ SILC_CONFIG_CALLBACK(fetch_admin) SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", type, name, context)); - if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; SILC_SERVER_CONFIG_LIST_APPENDTMP(config->admins); config->tmp = NULL; return SILC_CONFIG_OK; } - - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigAdmin *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigAdmin); /* Identify and save this value */ if (!strcmp(name, "host")) { @@ -801,21 +777,18 @@ SILC_CONFIG_CALLBACK(fetch_deny) type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; if (!tmp->reason) { got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err; } + SILC_SERVER_CONFIG_LIST_APPENDTMP(config->denied); config->tmp = NULL; return SILC_CONFIG_OK; } - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigDeny *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigDeny); /* Identify and save this value */ if (!strcmp(name, "host")) { @@ -844,10 +817,9 @@ SILC_CONFIG_CALLBACK(fetch_server) SERVER_CONFIG_DEBUG(("Received SERVER type=%d name=\"%s\" (val=%x)", type, name, context)); - if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; /* the temporary struct is ok, append it to the list */ @@ -855,12 +827,7 @@ SILC_CONFIG_CALLBACK(fetch_server) config->tmp = NULL; return SILC_CONFIG_OK; } - - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigServer *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigServer); /* Identify and save this value */ if (!strcmp(name, "host")) { @@ -886,9 +853,9 @@ SILC_CONFIG_CALLBACK(fetch_server) } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); - tmp->param = my_find_param(config, (char *) val, line); - if (!tmp->param) { /* error already output */ - got_errno = SILC_CONFIG_ESILENT; + tmp->param = my_find_param(config, (char *) val); + if (!tmp->param) { /* error message already output */ + got_errno = SILC_CONFIG_EPRINTLINE; goto got_err; } } @@ -914,22 +881,15 @@ SILC_CONFIG_CALLBACK(fetch_router) SERVER_CONFIG_DEBUG(("Received ROUTER type=%d name=\"%s\" (val=%x)", type, name, context)); - if (type == SILC_CONFIG_ARG_BLOCK) { - if (!tmp) /* empty sub-block? */ + if (!tmp) /* discard empty sub-blocks */ return SILC_CONFIG_OK; - /* the temporary struct is ok, append it to the list */ SILC_SERVER_CONFIG_LIST_APPENDTMP(config->routers); config->tmp = NULL; return SILC_CONFIG_OK; } - - /* if there isn't a temporary struct alloc one */ - if (!tmp) { - config->tmp = silc_calloc(1, sizeof(*findtmp)); - tmp = (SilcServerConfigRouter *) config->tmp; - } + SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigRouter); /* Identify and save this value */ if (!strcmp(name, "host")) { @@ -939,8 +899,10 @@ SILC_CONFIG_CALLBACK(fetch_router) else if (!strcmp(name, "port")) { int port = *(int *)val; if ((port <= 0) || (port > 65535)) { - SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line)); - return SILC_CONFIG_ESILENT; + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Invalid port number!\n")); + got_errno = SILC_CONFIG_EPRINTLINE; + goto got_err; } tmp->port = (SilcUInt16) port; } @@ -963,9 +925,9 @@ SILC_CONFIG_CALLBACK(fetch_router) } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); - tmp->param = my_find_param(config, (char *) val, line); - if (!tmp->param) { /* error already output */ - got_errno = SILC_CONFIG_ESILENT; + tmp->param = my_find_param(config, (char *) val); + if (!tmp->param) { /* error message already output */ + got_errno = SILC_CONFIG_EPRINTLINE; goto got_err; } } @@ -980,8 +942,10 @@ SILC_CONFIG_CALLBACK(fetch_router) else if (!strcmp(name, "backupport")) { int port = *(int *)val; if ((port <= 0) || (port > 65535)) { - SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line)); - return SILC_CONFIG_ESILENT; + SILC_SERVER_LOG_ERROR(("Error while parsing config file: " + "Invalid port number!\n")); + got_errno = SILC_CONFIG_EPRINTLINE; + goto got_err; } tmp->backup_replace_port = (SilcUInt16) port; } @@ -1019,9 +983,9 @@ static const SilcConfigTable table_general[] = { { "channel_rekey_secs", SILC_CONFIG_ARG_INT, fetch_generic, NULL }, { "key_exchange_timeout", SILC_CONFIG_ARG_INT, fetch_generic, NULL }, { "conn_auth_timeout", SILC_CONFIG_ARG_INT, fetch_generic, NULL }, - { "version_protocol", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, - { "version_software", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, - { "version_software_vendor", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, + { "version_protocol", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, + { "version_software", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, + { "version_software_vendor", SILC_CONFIG_ARG_STR, fetch_generic, NULL }, { 0, 0, 0, 0 } }; @@ -1101,7 +1065,7 @@ static const SilcConfigTable table_connparam[] = { { "key_exchange_pfs", SILC_CONFIG_ARG_TOGGLE, fetch_connparam, NULL }, { "version_protocol", SILC_CONFIG_ARG_STR, fetch_connparam, NULL }, { "version_software", SILC_CONFIG_ARG_STR, fetch_connparam, NULL }, - { "version_software_vendor", SILC_CONFIG_ARG_STR, fetch_connparam, NULL }, + { "version_software_vendor", SILC_CONFIG_ARG_STR, fetch_connparam, NULL }, { 0, 0, 0, 0 } }; @@ -1231,10 +1195,11 @@ SilcServerConfig silc_server_config_alloc(const char *filename) if (ret != SILC_CONFIG_ESILENT) { char *linebuf, *filename = silc_config_get_filename(file); SilcUInt32 line = silc_config_get_line(file); - SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.\n", - silc_config_strerror(ret))); + if (ret != SILC_CONFIG_EPRINTLINE) + SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.\n", + silc_config_strerror(ret))); linebuf = silc_config_read_line(file, line); - SILC_SERVER_LOG_ERROR((" file %s line %lu: %s\n", filename, + SILC_SERVER_LOG_ERROR((" file %s line %lu: %s\n\n", filename, line, linebuf)); silc_free(linebuf); } @@ -1452,7 +1417,7 @@ bool silc_server_config_register_ciphers(SilcServer server) SILC_CIPHER_SIM_SET_KEY)); SILC_LOG_DEBUG(("set_key=%p", cipher_obj.set_key)); cipher_obj.set_key_with_string = - silc_sim_getsym(sim, + silc_sim_getsym(sim, silc_sim_symname(alg_name, SILC_CIPHER_SIM_SET_KEY_WITH_STRING)); SILC_LOG_DEBUG(("set_key_with_string=%p", @@ -1651,7 +1616,7 @@ void silc_server_config_setlogfiles(SilcServer server) SILC_LOG_DEBUG(("Setting configured log file names and options")); silc_log_quick = config->logging_quick; - silc_log_flushdelay = (config->logging_flushdelay ? + silc_log_flushdelay = (config->logging_flushdelay ? config->logging_flushdelay : SILC_SERVER_LOG_FLUSH_DELAY); @@ -1695,7 +1660,7 @@ silc_server_config_find_client(SilcServer server, char *host) nickname. */ SilcServerConfigAdmin * -silc_server_config_find_admin(SilcServer server, char *host, char *user, +silc_server_config_find_admin(SilcServer server, char *host, char *user, char *nick) { SilcServerConfig config = server->config; diff --git a/apps/silcd/silcd.c b/apps/silcd/silcd.c index 095a5c3f..35693a71 100644 --- a/apps/silcd/silcd.c +++ b/apps/silcd/silcd.c @@ -131,7 +131,7 @@ static void silc_server_checkpid(SilcServer silcd) /* Drop root privileges. If some system call fails, die. */ -static void silc_server_drop(SilcServer server) +static void silc_server_drop_privs(SilcServer server) { /* Are we executing silcd as root or a regular user? */ if (geteuid()) { @@ -402,10 +402,12 @@ int main(int argc, char **argv) silc_schedule_signal_register(silcd->schedule, SIGTERM, stop_server, NULL); silc_schedule_signal_register(silcd->schedule, SIGINT, stop_server, NULL); - if (!foreground) { - /* Drop root. */ - silc_server_drop(silcd); + /* Drop root if we are not in debug mode, so you don't need to bother about + file writing permissions and so on */ + if (!silc_debug) + silc_server_drop_privs(silcd); + if (!foreground) { /* Before running the server, fork to background. */ silc_server_daemonise(silcd); diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index de73159a..c2f6c1b8 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -60,6 +60,7 @@ struct SilcConfigEntityObject { static char *errorstrs[] = { "-OK", /* SILC_CONFIG_OK */ "-SILENT", /* SILC_CONFIG_ESILENT */ + "-PRINTLINE", /* SILC_CONFIG_EPRINTLINE */ "Invalid syntax", /* SILC_CONFIG_EGENERIC */ "Internal error! Please report this bug", /* SILC_CONFIG_EINTERNAL */ "Can't open specified file", /* SILC_CONFIG_ECANTOPEN */ diff --git a/lib/silcutil/silcconfig.h b/lib/silcutil/silcconfig.h index a6a20756..5138dc24 100644 --- a/lib/silcutil/silcconfig.h +++ b/lib/silcutil/silcconfig.h @@ -94,6 +94,7 @@ enum { SILC_CONFIG_OK, /* OK */ SILC_CONFIG_ESILENT, /* Error defined by callback function */ + SILC_CONFIG_EPRINTLINE, /* Error defined by callback function */ SILC_CONFIG_EGENERIC, /* Invalid syntax */ SILC_CONFIG_EINTERNAL, /* Internal Error (caused by developer) */ SILC_CONFIG_ECANTOPEN, /* Can't open specified file */ -- 2.24.0