From: Giovanni Giacobbi Date: Fri, 15 Feb 2002 12:25:59 +0000 (+0000) Subject: updates. X-Git-Tag: silc.client.0.8.1~59 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=dc8285f973aac7fed9c8cca730418ed11b0119a3 updates. --- diff --git a/CHANGES b/CHANGES index 18f6e516..a6dbbe12 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,18 @@ +Fri Feb 15 13:23:03 CET 2002 Johnny Mnemonic + + * Fixes to the silcd config template. Affected file is + doc/example_silcd.conf.in. + + * Removed type casts from silc_calloc(), conforming to the + CodingStyle. Affected file is lib/silcutil/silcconfig.c. + + * Removed param_name member from client, server, and router + section structs, now identifying the param directly. + + Added CONFIG_FREE_AUTH macro in config file parsing. + + Affected files are silcd/serverconfig.[ch]. + Fri Feb 15 12:24:08 EET 2002 Timo Sirainen * Fixed command line parameter handling. All SILC initialization diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 16866fd2..6ee3ebc6 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -51,35 +51,33 @@ tmp = (void *) di->next; /* Set EDOUBLE error value and bail out if necessary */ -#define CONFIG_IS_DOUBLE(x) \ - if ((x)) { \ - got_errno = SILC_CONFIG_EDOUBLE; \ - goto got_err; \ - } +#define CONFIG_IS_DOUBLE(__x__) \ + if ((__x__)) { \ + got_errno = SILC_CONFIG_EDOUBLE; \ + goto got_err; \ + } + +/* Free the authentication fields in the specified struct + * Expands to two instructions */ +#define CONFIG_FREE_AUTH(__section__) \ + silc_free(__section__->passphrase); \ + silc_pkcs_public_key_free(__section__->publickey) /* Find connection parameters by the parameter block name. */ static SilcServerConfigSectionConnectionParam * -my_find_param(SilcServerConfig config, const char *name) +my_find_param(SilcServerConfig config, const char *name, uint32 line) { SilcServerConfigSectionConnectionParam *param; - if (!name) - return NULL; - for (param = config->conn_params; param; param = param->next) { if (!strcasecmp(param->name, name)) return param; } - return NULL; -} + fprintf(stderr, "\nError while parsing config file at line %lu: " + "Cannot find Param \"%s\".\n", line, name); -/* free an authdata according to its auth method */ -static void my_free_authdata(char *passphrase, void *public_key) -{ - silc_free(passphrase); - if (public_key) - silc_pkcs_public_key_free((SilcPublicKey) public_key); + return NULL; } /* parse an authdata according to its auth method */ @@ -108,7 +106,7 @@ static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, uint32 line, *auth_data_len = 0; } else { fprintf(stderr, "\nError while parsing config file at line %lu: " - "Unkonwn authentication method\n", line); + "Unknown authentication method.\n", line); return FALSE; } return TRUE; @@ -132,16 +130,16 @@ SILC_CONFIG_CALLBACK(fetch_generic) config->require_reverse_lookup = *(bool *)val; } else if (!strcmp(name, "keepalive_secs")) { - config->param.keepalive_secs = *(uint32 *)val; + config->param.keepalive_secs = (uint32) *(int *)val; } else if (!strcmp(name, "reconnect_count")) { - config->param.reconnect_count = *(uint32 *)val; + config->param.reconnect_count = (uint32) *(int *)val; } else if (!strcmp(name, "reconnect_interval")) { - config->param.reconnect_interval = *(uint32 *)val; + config->param.reconnect_interval = (uint32) *(int *)val; } else if (!strcmp(name, "reconnect_interval_max")) { - config->param.reconnect_interval_max = *(uint32 *)val; + config->param.reconnect_interval_max = (uint32) *(int *)val; } else if (!strcmp(name, "reconnect_keep_trying")) { config->param.reconnect_keep_trying = *(bool *)val; @@ -159,7 +157,7 @@ SILC_CONFIG_CALLBACK(fetch_cipher) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionCipher); - SERVER_CONFIG_DEBUG(("Received CIPHER type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received CIPHER type=%d name=\"%s\" (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ @@ -211,7 +209,7 @@ SILC_CONFIG_CALLBACK(fetch_hash) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionHash); - SERVER_CONFIG_DEBUG(("Received HASH type=%d name=%s (val=%x)", + SERVER_CONFIG_DEBUG(("Received HASH type=%d name=%s (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ @@ -264,7 +262,7 @@ SILC_CONFIG_CALLBACK(fetch_hmac) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionHmac); - SERVER_CONFIG_DEBUG(("Received HMAC type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received HMAC type=%d name=\"%s\" (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ @@ -565,36 +563,22 @@ SILC_CONFIG_CALLBACK(fetch_client) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionClient); - SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", type, name, context)); - if (type == SILC_CONFIG_ARG_BLOCK) { - if (!tmp) /* empty sub-block? */ - return SILC_CONFIG_OK; - - /* Find connection parameter block */ - if (tmp->param_name) { - tmp->param = my_find_param(config, tmp->param_name); - if (!tmp->param) { - fprintf(stderr, "Unknown ConnectionParam: %s\n", tmp->param_name); - silc_free(tmp->param_name); - got_errno = SILC_CONFIG_ESILENT; - goto got_err; - } - silc_free(tmp->param_name); - } + /* alloc tmp before block checking (empty sub-blocks are welcome here) */ + if (!tmp) { + config->tmp = silc_calloc(1, sizeof(*findtmp)); + tmp = (SilcServerConfigSectionClient *) config->tmp; + } + if (type == SILC_CONFIG_ARG_BLOCK) { + /* closing the block */ SILC_SERVER_CONFIG_LIST_APPENDTMP(config->clients); 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 = (SilcServerConfigSectionClient *) config->tmp; - } - /* Identify and save this value */ if (!strcmp(name, "host")) { CONFIG_IS_DOUBLE(tmp->host); @@ -602,7 +586,7 @@ SILC_CONFIG_CALLBACK(fetch_client) } else if (!strcmp(name, "passphrase")) { if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line, - (void **)&tmp->passphrase, + (void **)&tmp->passphrase, &tmp->passphrase_len)) { got_errno = SILC_CONFIG_ESILENT; goto got_err; @@ -619,14 +603,18 @@ SILC_CONFIG_CALLBACK(fetch_client) int port = *(int *)val; if ((port <= 0) || (port > 65535)) { fprintf(stderr, "Invalid port number!\n"); - got_errno = SILC_CONFIG_ESILENT; + got_errno = SILC_CONFIG_ESILENT; goto got_err; } tmp->port = (uint16) port; } else if (!strcmp(name, "param")) { - CONFIG_IS_DOUBLE(tmp->param_name); - tmp->param_name = (*(char *)val ? strdup((char *) val) : NULL); + 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; + goto got_err; + } } else return SILC_CONFIG_EINTERNAL; @@ -634,7 +622,7 @@ SILC_CONFIG_CALLBACK(fetch_client) got_err: silc_free(tmp->host); - my_free_authdata(tmp->passphrase, tmp->publickey); + CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; return got_errno; @@ -644,7 +632,7 @@ SILC_CONFIG_CALLBACK(fetch_admin) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionAdmin); - SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { @@ -678,7 +666,7 @@ SILC_CONFIG_CALLBACK(fetch_admin) } else if (!strcmp(name, "passphrase")) { if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line, - (void **)&tmp->passphrase, + (void **)&tmp->passphrase, &tmp->passphrase_len)) { got_errno = SILC_CONFIG_ESILENT; goto got_err; @@ -699,7 +687,7 @@ SILC_CONFIG_CALLBACK(fetch_admin) silc_free(tmp->host); silc_free(tmp->user); silc_free(tmp->nick); - my_free_authdata(tmp->passphrase, tmp->publickey); + CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; return got_errno; @@ -709,7 +697,7 @@ SILC_CONFIG_CALLBACK(fetch_deny) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionDeny); - SERVER_CONFIG_DEBUG(("Received DENY type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received DENY type=%d name=\"%s\" (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { /* check the temporary struct's fields */ @@ -762,7 +750,7 @@ SILC_CONFIG_CALLBACK(fetch_server) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionServer); - SERVER_CONFIG_DEBUG(("Received SERVER type=%d name=\"%s\" (val=%x)", + SERVER_CONFIG_DEBUG(("Received SERVER type=%d name=\"%s\" (val=%x)", type, name, context)); if (type == SILC_CONFIG_ARG_BLOCK) { @@ -770,17 +758,7 @@ SILC_CONFIG_CALLBACK(fetch_server) if (!tmp) /* empty sub-block? */ return SILC_CONFIG_OK; - /* Find connection parameter block */ - if (tmp->param_name) { - tmp->param = my_find_param(config, tmp->param_name); - if (!tmp->param) { - fprintf(stderr, "Unknown ConnectionParam: %s\n", tmp->param_name); - silc_free(tmp->param_name); - got_errno = SILC_CONFIG_ESILENT; - goto got_err; - } - silc_free(tmp->param_name); - } + /* XXX mandatory fields for server? */ /* the temporary struct is ok, append it to the list */ SILC_SERVER_CONFIG_LIST_APPENDTMP(config->servers); @@ -801,7 +779,7 @@ SILC_CONFIG_CALLBACK(fetch_server) } else if (!strcmp(name, "passphrase")) { if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line, - (void **)&tmp->passphrase, + (void **)&tmp->passphrase, &tmp->passphrase_len)) { got_errno = SILC_CONFIG_ESILENT; goto got_err; @@ -819,8 +797,12 @@ SILC_CONFIG_CALLBACK(fetch_server) tmp->version = strdup((char *) val); } else if (!strcmp(name, "param")) { - CONFIG_IS_DOUBLE(tmp->param_name); - tmp->param_name = (*(char *)val ? strdup((char *) val) : NULL); + 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; + goto got_err; + } } else if (!strcmp(name, "backup")) { tmp->backup_router = *(bool *)val; @@ -833,7 +815,7 @@ SILC_CONFIG_CALLBACK(fetch_server) got_err: silc_free(tmp->host); silc_free(tmp->version); - my_free_authdata(tmp->passphrase, tmp->publickey); + CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; return got_errno; @@ -843,24 +825,14 @@ SILC_CONFIG_CALLBACK(fetch_router) { SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigSectionRouter); - SERVER_CONFIG_DEBUG(("Received ROUTER type=%d name=\"%s\" (val=%x)", + 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? */ return SILC_CONFIG_OK; - /* Find connection parameter block */ - if (tmp->param_name) { - tmp->param = my_find_param(config, tmp->param_name); - if (!tmp->param) { - fprintf(stderr, "Unknown ConnectionParam: %s\n", tmp->param_name); - silc_free(tmp->param_name); - got_errno = SILC_CONFIG_ESILENT; - goto got_err; - } - silc_free(tmp->param_name); - } + /* XXX mandatory fields for router? */ /* the temporary struct is ok, append it to the list */ SILC_SERVER_CONFIG_LIST_APPENDTMP(config->routers); @@ -889,7 +861,7 @@ SILC_CONFIG_CALLBACK(fetch_router) } else if (!strcmp(name, "passphrase")) { if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line, - (void **)&tmp->passphrase, + (void **)&tmp->passphrase, &tmp->passphrase_len)) { got_errno = SILC_CONFIG_ESILENT; goto got_err; @@ -907,15 +879,19 @@ SILC_CONFIG_CALLBACK(fetch_router) tmp->version = strdup((char *) val); } else if (!strcmp(name, "param")) { - CONFIG_IS_DOUBLE(tmp->param_name); - tmp->param_name = (*(char *)val ? strdup((char *) val) : NULL); + 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; + goto got_err; + } } else if (!strcmp(name, "initiator")) { tmp->initiator = *(bool *)val; } else if (!strcmp(name, "backuphost")) { CONFIG_IS_DOUBLE(tmp->backup_replace_ip); - tmp->backup_replace_ip = (*(char *)val ? strdup((char *) val) : + tmp->backup_replace_ip = (*(char *)val ? strdup((char *) val) : strdup("*")); } else @@ -927,7 +903,7 @@ SILC_CONFIG_CALLBACK(fetch_router) silc_free(tmp->host); silc_free(tmp->version); silc_free(tmp->backup_replace_ip); - my_free_authdata(tmp->passphrase, tmp->publickey); + CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; return got_errno; @@ -1198,14 +1174,14 @@ void silc_server_config_destroy(SilcServerConfig config) SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigSectionClient, config->clients) silc_free(di->host); - my_free_authdata(di->passphrase, di->publickey); + CONFIG_FREE_AUTH(di); silc_free(di); } SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigSectionAdmin, config->admins) silc_free(di->host); silc_free(di->user); silc_free(di->nick); - my_free_authdata(di->passphrase, di->publickey); + CONFIG_FREE_AUTH(di); silc_free(di); } SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigSectionDeny, config->denied) @@ -1217,7 +1193,7 @@ void silc_server_config_destroy(SilcServerConfig config) config->servers) silc_free(di->host); silc_free(di->version); - my_free_authdata(di->passphrase, di->publickey); + CONFIG_FREE_AUTH(di); silc_free(di); } SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigSectionRouter, @@ -1225,7 +1201,7 @@ void silc_server_config_destroy(SilcServerConfig config) silc_free(di->host); silc_free(di->version); silc_free(di->backup_replace_ip); - my_free_authdata(di->passphrase, di->publickey); + CONFIG_FREE_AUTH(di); silc_free(di); } } @@ -1698,7 +1674,7 @@ bool silc_server_config_set_defaults(SilcServer server) config->param.reconnect_interval = (config->param.reconnect_interval ? config->param.reconnect_interval : SILC_SERVER_RETRY_INTERVAL_MIN); - config->param.reconnect_interval_max = + config->param.reconnect_interval_max = (config->param.reconnect_interval_max ? config->param.reconnect_interval_max : SILC_SERVER_RETRY_INTERVAL_MAX); diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index 2a37bb94..2ec5f8a3 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -78,7 +78,7 @@ typedef struct SilcServerConfigSectionConnectionParam { uint32 reconnect_interval; uint32 reconnect_interval_max; bool reconnect_keep_trying; - /* + /* uint32 connect_freq; uint32 max_links; */ @@ -92,7 +92,6 @@ typedef struct SilcServerConfigSectionClientStruct { uint32 passphrase_len; void *publickey; uint16 port; - char *param_name; SilcServerConfigSectionConnectionParam *param; struct SilcServerConfigSectionClientStruct *next; } SilcServerConfigSectionClient; @@ -123,7 +122,6 @@ typedef struct SilcServerConfigSectionServerStruct { uint32 passphrase_len; void *publickey; char *version; - char *param_name; SilcServerConfigSectionConnectionParam *param; bool backup_router; struct SilcServerConfigSectionServerStruct *next; @@ -137,7 +135,6 @@ typedef struct SilcServerConfigSectionRouterStruct { void *publickey; uint16 port; char *version; - char *param_name; SilcServerConfigSectionConnectionParam *param; bool initiator; bool backup_router; diff --git a/doc/example_silcd.conf.in b/doc/example_silcd.conf.in index da1d6830..2f68295b 100644 --- a/doc/example_silcd.conf.in +++ b/doc/example_silcd.conf.in @@ -95,7 +95,7 @@ ServerInfo { # # Admin's email address # - EMail = "priikone@poseidon.pspt.fi"; + AdminEmail = "priikone@poseidon.pspt.fi"; # # Run SILC server as specific user and group. The server must be @@ -236,11 +236,11 @@ ConnectionParam { # Next example connection will match to all incoming client connections, # and no authentication is required # -Client { - #host = ""; - #passphrase = "secret"; - #publickey = "/path/to/the/public.key"; - param = "normal"; +Client { + #Host = "10.1.*"; + #Passphrase = "secret"; + #PublicKey = "/path/to/the/public.key"; + Param = "normal"; }; # @@ -284,7 +284,7 @@ Admin { ServerConnection { Host = "10.2.1.7"; Passphrase = "verysecret"; - # Publickey = "/path/to/the/public.key"; + #Publickey = "/path/to/the/public.key"; VersionID = 1; Param = "normal"; Backup = false; @@ -319,7 +319,7 @@ RouterConnection { Host = "10.2.1.100"; Port = 706; Passphrase = "verysecret"; - # Publickey = "/path/to/the/public.key"; + #Publickey = "/path/to/the/public.key"; VersionID = 1; Param = "normal"; Initiator = true; diff --git a/lib/silcutil/silcconfig.c b/lib/silcutil/silcconfig.c index 8731aa1d..dcd55b93 100644 --- a/lib/silcutil/silcconfig.c +++ b/lib/silcutil/silcconfig.c @@ -259,7 +259,7 @@ SilcConfigFile *silc_config_open(char *configfile) if (!(buffer = silc_file_readfile(configfile, &filelen))) return NULL; - ret = (SilcConfigFile *) silc_calloc(1, sizeof(*ret)); + ret = silc_calloc(1, sizeof(*ret)); ret->filename = strdup(configfile); ret->base = ret->p = buffer; ret->len = filelen; @@ -293,10 +293,12 @@ void silc_config_close(SilcConfigFile *file) SilcConfigEntity silc_config_init(SilcConfigFile *file) { SilcConfigEntity ret; + if (!file) return NULL; + SILC_CONFIG_DEBUG(("Allocating new config entity")); - ret = (SilcConfigEntity) silc_calloc(1, sizeof(*ret)); + ret = silc_calloc(1, sizeof(*ret)); ret->file = file; return ret; }; @@ -403,7 +405,7 @@ bool silc_config_register(SilcConfigEntity ent, const char *name, } /* allocate and append the new option */ - newopt = (SilcConfigOption *) silc_calloc(1, sizeof(*newopt)); + newopt = silc_calloc(1, sizeof(*newopt)); newopt->name = strdup(name); newopt->type = type; newopt->cb = cb;