X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcd%2Fserverconfig.h;h=2104976ed3e87275c5c485ab67a941d792cd930f;hb=413da0f8686910f5e627393157566ae729ca99c4;hp=afab2c9bdef570b1f8ae34be3047f13519950f94;hpb=c49f7330c61ba13940fadef90377ec4012145e37;p=silc.git diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index afab2c9b..2104976e 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -2,15 +2,15 @@ serverconfig.h - Author: Pekka Riikonen + Author: Giovanni Giacobbi - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -21,249 +21,219 @@ #ifndef SERVERCONFIG_H #define SERVERCONFIG_H -/* Holds information of configured algorithms */ -typedef struct SilcServerConfigSectionAlgStruct { - char *alg_name; - char *sim_name; - unsigned int block_len; - unsigned int key_len; - struct SilcServerConfigSectionAlgStruct *next; - struct SilcServerConfigSectionAlgStruct *prev; -#define SILC_CONFIG_SERVER_MODNAME "builtin" -} SilcServerConfigSectionAlg; - -/* Holds server information from config file */ -typedef struct { - char *server_name; +typedef struct SilcServerConfigCipherStruct { + char *name; + char *module; + SilcUInt32 key_length; + SilcUInt32 block_length; + struct SilcServerConfigCipherStruct *next; +} SilcServerConfigCipher; + +typedef struct SilcServerConfigHashStruct { + char *name; + char *module; + SilcUInt32 block_length; + SilcUInt32 digest_length; + struct SilcServerConfigHashStruct *next; +} SilcServerConfigHash; + +typedef struct SilcServerConfigHmacStruct { + char *name; + char *hash; + SilcUInt32 mac_length; + struct SilcServerConfigHmacStruct *next; +} SilcServerConfigHmac; + +typedef struct SilcServerConfigPkcsStruct { + char *name; + struct SilcServerConfigPkcsStruct *next; +} SilcServerConfigPkcs; + +typedef struct SilcServerConfigServerInfoInterfaceStruct { char *server_ip; - char *location; - unsigned short port; -} SilcServerConfigSectionServerInfo; + SilcUInt16 port; + struct SilcServerConfigServerInfoInterfaceStruct *next; +} SilcServerConfigServerInfoInterface; -/* Holds server's administrative information from config file */ -typedef struct { - char *location; - char *server_type; - char *admin_name; - char *admin_email; -} SilcServerConfigSectionAdminInfo; - -/* Holds all the ports the server is listenning on */ -typedef struct SilcServerConfigSectionListenPortStruct { - char *host; - char *remote_ip; - unsigned short port; - struct SilcServerConfigSectionListenPortStruct *next; - struct SilcServerConfigSectionListenPortStruct *prev; -} SilcServerConfigSectionListenPort; - -/* Holds server's execution identity, or the user and group which - to change from root when server starts */ -typedef struct { - char *user; - char *group; -} SilcServerConfigSectionIdentity; - -/* Holds all the configured log files. */ -typedef struct SilcServerConfigSectionLoggingStruct { - char *logtype; - char *filename; - unsigned int maxsize; - struct SilcServerConfigSectionLoggingStruct *next; - struct SilcServerConfigSectionLoggingStruct *prev; - -/* Allowed section types */ -#define SILC_CONFIG_SERVER_LF_INFO "infologfile" -#define SILC_CONFIG_SERVER_LF_WARNING "warninglogfile" -#define SILC_CONFIG_SERVER_LF_ERROR "errorlogfile" -#define SILC_CONFIG_SERVER_LF_FATAL "fatalogfile" -} SilcServerConfigSectionLogging; - -/* Holds all configured connection classes */ -typedef struct SilcServerConfigSectionConnectionClassStruct { - unsigned int class; - unsigned int ping_freq; - unsigned int connect_freq; - unsigned int max_links; - struct SilcServerConfigSectionConnectionClassStruct *next; - struct SilcServerConfigSectionConnectionClassStruct *prev; -} SilcServerConfigSectionConnectionClass; - -#define SILC_CONFIG_SERVER_AUTH_METH_PASSWD "passwd" -#define SILC_CONFIG_SERVER_AUTH_METH_PUBKEY "pubkey" +typedef struct SilcServerConfigServerInfoStruct { + char *server_name; + SilcServerConfigServerInfoInterface *primary; + SilcServerConfigServerInfoInterface *secondary; + char *server_type; /* E.g. "Test Server" */ + char *location; /* geographic location */ + char *admin; /* admin full name */ + char *email; /* admin's email address */ + char *user; /* userid the server should be runned at */ + char *group; /* ditto, but about groupid */ + SilcPublicKey public_key; + SilcPrivateKey private_key; + char *motd_file; /* path to text motd file (reading only) */ + char *pid_file; /* path to the pid file (for reading and writing) */ +} SilcServerConfigServerInfo; + +typedef struct SilcServerConfigLoggingStruct { + char *file; + SilcUInt32 maxsize; +} SilcServerConfigLogging; + +/* Connection parameters */ +typedef struct SilcServerConfigConnParams { + struct SilcServerConfigConnParams *next; + char *name; + char *version_protocol; + char *version_software; + char *version_software_vendor; + SilcUInt32 connections_max; + SilcUInt32 connections_max_per_host; + SilcUInt32 keepalive_secs; + SilcUInt32 reconnect_count; + SilcUInt32 reconnect_interval; + SilcUInt32 reconnect_interval_max; + SilcUInt32 key_exchange_rekey; + SilcUInt32 qos_rate_limit; + SilcUInt32 qos_bytes_limit; + SilcUInt32 qos_limit_sec; + SilcUInt32 qos_limit_usec; + unsigned int key_exchange_pfs : 1; + unsigned int reconnect_keep_trying : 1; + unsigned int anonymous : 1; + unsigned int qos : 1; +} SilcServerConfigConnParams; /* Holds all client authentication data from config file */ -typedef struct SilcServerConfigSectionClientConnectionStruct { - char *host; - SilcAuthMethod auth_meth; - void *auth_data; - unsigned int auth_data_len; - unsigned short port; - unsigned int class; - struct SilcServerConfigSectionClientConnectionStruct *next; - struct SilcServerConfigSectionClientConnectionStruct *prev; -} SilcServerConfigSectionClientConnection; - -/* Hols all server's administrators authentication data from config file */ -typedef struct SilcServerConfigSectionAdminConnectionStruct { +typedef struct SilcServerConfigClientStruct { char *host; - char *username; - char *nickname; - SilcAuthMethod auth_meth; - void *auth_data; - unsigned int auth_data_len; - struct SilcServerConfigSectionAdminConnectionStruct *next; - struct SilcServerConfigSectionAdminConnectionStruct *prev; -} SilcServerConfigSectionAdminConnection; - -/* Holds all configured server/router connections from config file */ -typedef struct SilcServerConfigSectionServerConnectionStruct { + unsigned char *passphrase; + SilcUInt32 passphrase_len; + SilcHashTable publickeys; + SilcServerConfigConnParams *param; + struct SilcServerConfigClientStruct *next; +} SilcServerConfigClient; + +/* Holds all server's administrators authentication data from config file */ +typedef struct SilcServerConfigAdminStruct { char *host; - SilcAuthMethod auth_meth; - void *auth_data; - unsigned int auth_data_len; - unsigned short port; - char *version; - unsigned int class; - int initiator; - struct SilcServerConfigSectionServerConnectionStruct *next; - struct SilcServerConfigSectionServerConnectionStruct *prev; -} SilcServerConfigSectionServerConnection; + char *user; + char *nick; + unsigned char *passphrase; + SilcUInt32 passphrase_len; + SilcHashTable publickeys; + struct SilcServerConfigAdminStruct *next; +} SilcServerConfigAdmin; /* Holds all configured denied connections from config file */ -typedef struct { +typedef struct SilcServerConfigDenyStruct { char *host; - char *time; - char *comment; - unsigned short port; -} SilcServerConfigSectionDenyConnection; - -/* Holds motd file */ -typedef struct { - char *motd_file; -} SilcServerConfigSectionMotd; - -/* - SILC Server Config object. + char *reason; + struct SilcServerConfigDenyStruct *next; +} SilcServerConfigDeny; - This object holds all the data parsed from the SILC server configuration - file. This is mainly used at the initialization of the server. - -*/ +/* Holds all configured server connections from config file */ +typedef struct SilcServerConfigServerStruct { + char *host; + unsigned char *passphrase; + SilcUInt32 passphrase_len; + SilcHashTable publickeys; + SilcServerConfigConnParams *param; + bool backup_router; + struct SilcServerConfigServerStruct *next; +} SilcServerConfigServer; + +/* Holds all configured router connections from config file */ +typedef struct SilcServerConfigRouterStruct { + char *host; + unsigned char *passphrase; + SilcUInt32 passphrase_len; + SilcHashTable publickeys; + SilcUInt16 port; + SilcServerConfigConnParams *param; + bool initiator; + bool backup_router; + char *backup_replace_ip; + SilcUInt16 backup_replace_port; + bool backup_local; + struct SilcServerConfigRouterStruct *next; +} SilcServerConfigRouter; + +/* define the SilcServerConfig object */ typedef struct { - /* Pointer back to the server */ - void *server; + void *tmp; + + /* Reference count (when this reaches zero, config object is destroyed) */ + SilcInt32 refcount; + + /* The General section */ + char *module_path; + bool prefer_passphrase_auth; + bool require_reverse_lookup; + SilcUInt32 channel_rekey_secs; + SilcUInt32 key_exchange_timeout; + SilcUInt32 conn_auth_timeout; + SilcServerConfigConnParams param; + bool detach_disabled; + SilcUInt32 detach_timeout; + bool logging_timestamp; + bool logging_quick; + long logging_flushdelay; + char *debug_string; + + /* Other configuration sections */ + SilcServerConfigCipher *cipher; + SilcServerConfigHash *hash; + SilcServerConfigHmac *hmac; + SilcServerConfigPkcs *pkcs; + SilcServerConfigLogging *logging_info; + SilcServerConfigLogging *logging_warnings; + SilcServerConfigLogging *logging_errors; + SilcServerConfigLogging *logging_fatals; + SilcServerConfigServerInfo *server_info; + SilcServerConfigConnParams *conn_params; + SilcServerConfigClient *clients; + SilcServerConfigAdmin *admins; + SilcServerConfigDeny *denied; + SilcServerConfigServer *servers; + SilcServerConfigRouter *routers; +} *SilcServerConfig; - /* Filename of the configuration file */ - char *filename; - - /* Configuration sections */ - SilcServerConfigSectionAlg *cipher; - SilcServerConfigSectionAlg *pkcs; - SilcServerConfigSectionAlg *hash_func; - SilcServerConfigSectionAlg *hmac; - SilcServerConfigSectionServerInfo *server_info; - SilcServerConfigSectionAdminInfo *admin_info; - SilcServerConfigSectionListenPort *listen_port; - SilcServerConfigSectionIdentity *identity; - SilcServerConfigSectionLogging *logging; - SilcServerConfigSectionConnectionClass *conn_class; - SilcServerConfigSectionClientConnection *clients; - SilcServerConfigSectionServerConnection *servers; - SilcServerConfigSectionServerConnection *routers; - SilcServerConfigSectionAdminConnection *admins; - SilcServerConfigSectionDenyConnection *denied; - SilcServerConfigSectionMotd *motd; -} SilcServerConfigObject; - -typedef SilcServerConfigObject *SilcServerConfig; - -/* Configuration section type enumerations. */ -typedef enum { - SILC_CONFIG_SERVER_SECTION_TYPE_NONE = 0, - SILC_CONFIG_SERVER_SECTION_TYPE_CIPHER, - SILC_CONFIG_SERVER_SECTION_TYPE_PKCS, - SILC_CONFIG_SERVER_SECTION_TYPE_HASH_FUNCTION, - SILC_CONFIG_SERVER_SECTION_TYPE_HMAC, - SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_INFO, - SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_INFO, - SILC_CONFIG_SERVER_SECTION_TYPE_LISTEN_PORT, - SILC_CONFIG_SERVER_SECTION_TYPE_IDENTITY, - SILC_CONFIG_SERVER_SECTION_TYPE_LOGGING, - SILC_CONFIG_SERVER_SECTION_TYPE_CONNECTION_CLASS, - SILC_CONFIG_SERVER_SECTION_TYPE_CLIENT_CONNECTION, - SILC_CONFIG_SERVER_SECTION_TYPE_SERVER_CONNECTION, - SILC_CONFIG_SERVER_SECTION_TYPE_ROUTER_CONNECTION, - SILC_CONFIG_SERVER_SECTION_TYPE_ADMIN_CONNECTION, - SILC_CONFIG_SERVER_SECTION_TYPE_DENY_CONNECTION, - SILC_CONFIG_SERVER_SECTION_TYPE_MOTD, -} SilcServerConfigSectionType; - -/* SILC Configuration Section structure. */ typedef struct { - const char *section; - SilcServerConfigSectionType type; - unsigned int maxfields; -} SilcServerConfigSection; - -/* LIst of all possible config sections in SILC server. */ -extern SilcServerConfigSection silc_server_config_sections[]; - -/* Structure used in parsing the configuration lines. The line is read - from a file to this structure before parsing it further. */ -typedef struct SilcServerConfigParseStruct { - SilcBuffer line; - unsigned int linenum; - SilcServerConfigSection *section; - struct SilcServerConfigParseStruct *next; - struct SilcServerConfigParseStruct *prev; -} *SilcServerConfigParse; - -/* Macros */ - -/* Allocates list entries for configuration sections. Used by all - config sections as this is common. */ -#define SILC_SERVER_CONFIG_LIST_ALLOC(x) \ -do { \ - if (!(x)) { \ - (x) = silc_calloc(1, sizeof(*(x))); \ - (x)->next = NULL; \ - (x)->prev = NULL; \ - } else { \ - if (!(x)->next) { \ - (x)->next = silc_calloc(1, sizeof(*(x)->next)); \ - (x)->next->next = NULL; \ - (x)->next->prev = (x); \ - (x) = (x)->next; \ - } \ - } \ -} while(0) + SilcServerConfig config; + void *ref_ptr; +} SilcServerConfigRef; /* Prototypes */ -SilcServerConfig silc_server_config_alloc(char *filename); -void silc_server_config_free(SilcServerConfig config); -int silc_server_config_parse(SilcServerConfig config, SilcBuffer buffer, - SilcServerConfigParse *return_config); -int silc_server_config_parse_lines(SilcServerConfig config, - SilcServerConfigParse parse_config); -int silc_server_config_check_sections(unsigned int checkmask); -void silc_server_config_setlogfiles(SilcServerConfig config); -void silc_server_config_register_ciphers(SilcServerConfig config); -void silc_server_config_register_pkcs(SilcServerConfig config); -void silc_server_config_register_hashfuncs(SilcServerConfig config); -void silc_server_config_register_hmacs(SilcServerConfig config); -SilcServerConfigSectionClientConnection * -silc_server_config_find_client_conn(SilcServerConfig config, - char *host, int port); -SilcServerConfigSectionServerConnection * -silc_server_config_find_server_conn(SilcServerConfig config, - char *host, int port); -SilcServerConfigSectionServerConnection * -silc_server_config_find_router_conn(SilcServerConfig config, - char *host, int port); -SilcServerConfigSectionAdminConnection * -silc_server_config_find_admin(SilcServerConfig config, - char *host, char *username, char *nickname); -void silc_server_config_print(); -#endif +/* Basic config operations */ +SilcServerConfig silc_server_config_alloc(const char *filename); +void silc_server_config_destroy(SilcServerConfig config); +void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config, + void *ref_ptr); +void silc_server_config_unref(SilcServerConfigRef *ref); + +/* Algorithm registering and reset functions */ +bool silc_server_config_register_ciphers(SilcServer server); +bool silc_server_config_register_hashfuncs(SilcServer server); +bool silc_server_config_register_hmacs(SilcServer server); +bool silc_server_config_register_pkcs(SilcServer server); +void silc_server_config_setlogfiles(SilcServer server); + +/* Run-time config access functions */ +SilcServerConfigClient * +silc_server_config_find_client(SilcServer server, char *host); +SilcServerConfigAdmin * +silc_server_config_find_admin(SilcServer server, char *host, char *user, + char *nick); +SilcServerConfigDeny * +silc_server_config_find_denied(SilcServer server, char *host); +SilcServerConfigServer * +silc_server_config_find_server_conn(SilcServer server, char *host); +SilcServerConfigRouter * +silc_server_config_find_router_conn(SilcServer server, char *host, int port); +SilcServerConfigRouter * +silc_server_config_find_backup_conn(SilcServer server, char *host); +bool silc_server_config_is_primary_route(SilcServer server); +SilcServerConfigRouter * +silc_server_config_get_primary_router(SilcServer server); +SilcServerConfigRouter * +silc_server_config_get_backup_router(SilcServer server); + +#endif /* !SERVERCONFIG_H */