From 4d8cfacd95530550b075c38efa447d5673cb822e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 24 Mar 2016 18:45:28 -0500 Subject: [PATCH] ircd: start staging for relocatable paths --- include/defaults.h | 21 +++++++++++++++++++++ ircd/authd.c | 14 +++++++------- ircd/bandbi.c | 10 +++++----- ircd/cache.c | 16 ++++++++-------- ircd/ircd.c | 29 ++++++++++++++++++++++++----- ircd/ircd_lexer.l | 4 ++-- ircd/modules.c | 12 ++++++------ ircd/restart.c | 4 ++-- ircd/sslproc.c | 8 ++++---- modules/m_rehash.c | 2 +- 10 files changed, 80 insertions(+), 40 deletions(-) diff --git a/include/defaults.h b/include/defaults.h index 29b05cfb..599b2611 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -36,6 +36,27 @@ * First, set other fd limits based on values from user */ +typedef enum { + IRCD_PATH_PREFIX, + IRCD_PATH_MODULES, + IRCD_PATH_AUTOLOAD_MODULES, + IRCD_PATH_ETC, + IRCD_PATH_LOG, + IRCD_PATH_USERHELP, + IRCD_PATH_OPERHELP, + IRCD_PATH_IRCD_EXEC, + IRCD_PATH_IRCD_CONF, + IRCD_PATH_IRCD_MOTD, + IRCD_PATH_IRCD_LOG, + IRCD_PATH_IRCD_PID, + IRCD_PATH_IRCD_OMOTD, + IRCD_PATH_BANDB, + IRCD_PATH_BIN, + IRCD_PATH_LIBEXEC, + IRCD_PATH_COUNT +} ircd_path_t; + +extern const char *ircd_paths[IRCD_PATH_COUNT]; #define MAXCONNECTIONS 65535 /* default max connections if getrlimit doesn't work */ /* class {} default values */ diff --git a/ircd/authd.c b/ircd/authd.c index 491d0237..30dd30cb 100644 --- a/ircd/authd.c +++ b/ircd/authd.c @@ -55,20 +55,20 @@ start_authd(void) #endif if(authd_path == NULL) { - snprintf(fullpath, sizeof(fullpath), "%s/authd%s", PKGLIBEXECDIR, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cauthd%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { - snprintf(fullpath, sizeof(fullpath), "%s/libexec/charybdis/authd%s", - ConfigFileEntry.dpath, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cbin%cauthd%s", + ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { ilog(L_MAIN, - "Unable to execute authd in %s or %s/libexec/charybdis", - PKGLIBEXECDIR, ConfigFileEntry.dpath); + "Unable to execute authd in %s or %s/bin", + ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath); sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Unable to execute authd in %s or %s/libexec/charybdis", - PKGLIBEXECDIR, ConfigFileEntry.dpath); + "Unable to execute authd in %s or %s/bin", + ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath); return 1; } diff --git a/ircd/bandbi.c b/ircd/bandbi.c index aa9410d2..15171b64 100644 --- a/ircd/bandbi.c +++ b/ircd/bandbi.c @@ -80,21 +80,21 @@ start_bandb(void) const char *suffix = ""; #endif - rb_setenv("BANDB_DBPATH", PKGLOCALSTATEDIR "/ban.db", 1); + rb_setenv("BANDB_DBPATH", ircd_paths[IRCD_PATH_BANDB], 1); if(bandb_path == NULL) { - snprintf(fullpath, sizeof(fullpath), "%s/bandb%s", PKGLIBEXECDIR, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cbandb%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { - snprintf(fullpath, sizeof(fullpath), "%s/bin/bandb%s", - ConfigFileEntry.dpath, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cbin%cbandb%s", + ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { ilog(L_MAIN, "Unable to execute bandb%s in %s or %s/bin", - suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); + suffix, ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath); return 0; } } diff --git a/ircd/cache.c b/ircd/cache.c index 1a2cb14f..3e40eb36 100644 --- a/ircd/cache.c +++ b/ircd/cache.c @@ -64,8 +64,8 @@ init_cache(void) user_motd_changed[0] = '\0'; - user_motd = cache_file(MPATH, "ircd.motd", 0); - oper_motd = cache_file(OPATH, "opers.motd", 0); + user_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_MOTD], "ircd.motd", 0); + oper_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_OMOTD], "opers.motd", 0); memset(&links_cache_list, 0, sizeof(links_cache_list)); help_dict_oper = rb_dictionary_create("oper help", strcasecmp); @@ -253,7 +253,7 @@ load_help(void) free_cachefile(cacheptr); } - helpfile_dir = opendir(HPATH); + helpfile_dir = opendir(ircd_paths[IRCD_PATH_OPERHELP]); if(helpfile_dir == NULL) return; @@ -262,13 +262,13 @@ load_help(void) { if(ldirent->d_name[0] == '.') continue; - snprintf(filename, sizeof(filename), "%s/%s", HPATH, ldirent->d_name); + snprintf(filename, sizeof(filename), "%s%c%s", ircd_paths[IRCD_PATH_OPERHELP], RB_PATH_SEPARATOR, ldirent->d_name); cacheptr = cache_file(filename, ldirent->d_name, HELP_OPER); rb_dictionary_add(help_dict_oper, cacheptr->name, cacheptr); } closedir(helpfile_dir); - helpfile_dir = opendir(UHPATH); + helpfile_dir = opendir(ircd_path[IRCD_PATH_USERHELP]); if(helpfile_dir == NULL) return; @@ -277,7 +277,7 @@ load_help(void) { if(ldirent->d_name[0] == '.') continue; - snprintf(filename, sizeof(filename), "%s/%s", UHPATH, ldirent->d_name); + snprintf(filename, sizeof(filename), "%s%c%s", ircd_paths[IRCD_PATH_USERHELP], RB_PATH_SEPARATOR, ldirent->d_name); #if defined(S_ISLNK) && defined(HAVE_LSTAT) if(lstat(filename, &sb) < 0) @@ -341,7 +341,7 @@ cache_user_motd(void) struct stat sb; struct tm *local_tm; - if(stat(MPATH, &sb) == 0) + if(stat(ircd_paths[IRCD_PATH_IRCD_MOTD], &sb) == 0) { local_tm = localtime(&sb.st_mtime); @@ -355,7 +355,7 @@ cache_user_motd(void) } } free_cachefile(user_motd); - user_motd = cache_file(MPATH, "ircd.motd", 0); + user_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_MOTD], "ircd.motd", 0); } diff --git a/ircd/ircd.c b/ircd/ircd.c index b3f1b5d0..2012ad37 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -94,9 +94,6 @@ rb_dlink_list global_serv_list; /* global servers on the network */ rb_dlink_list local_oper_list; /* our opers, duplicated in lclient_list */ rb_dlink_list oper_list; /* network opers */ -const char *logFileName = LPATH; -const char *pidFileName = PPATH; - char **myargv; bool dorehash = false; bool dorehashbans = false; @@ -118,6 +115,28 @@ int split_users; int split_servers; int eob_count; +const char *ircd_paths[IRCD_PATH_COUNT] = { + [IRCD_PATH_PREFIX] = DPATH, + [IRCD_PATH_MODULES] = MODPATH, + [IRCD_PATH_AUTOLOAD_MODULES] = AUTOMODPATH, + [IRCD_PATH_ETC] = ETCPATH, + [IRCD_PATH_LOG] = LOGPATH, + [IRCD_PATH_USERHELP] = UHPATH, + [IRCD_PATH_OPERHELP] = HPATH, + [IRCD_PATH_IRCD_EXEC] = SPATH, + [IRCD_PATH_IRCD_CONF] = CPATH, + [IRCD_PATH_IRCD_MOTD] = MPATH, + [IRCD_PATH_IRCD_LOG] = LPATH, + [IRCD_PATH_IRCD_PID] = PPATH, + [IRCD_PATH_IRCD_OMOTD] = OPATH, + [IRCD_PATH_BANDB] = DBPATH, + [IRCD_PATH_BIN] = BINPATH, + [IRCD_PATH_LIBEXEC] = PKGLIBEXECDIR, +}; + +const char *logFileName = LPATH; +const char *pidFileName = PPATH; + void ircd_shutdown(const char *reason) { @@ -562,8 +581,8 @@ charybdis_main(int argc, char *argv[]) init_sys(); - ConfigFileEntry.dpath = DPATH; - ConfigFileEntry.configfile = CPATH; /* Server configuration file */ + ConfigFileEntry.dpath = ircd_paths[IRCD_PATH_PREFIX]; + ConfigFileEntry.configfile = ircd_paths[IRCD_PATH_IRCD_CONF]; /* Server configuration file */ ConfigFileEntry.connect_timeout = 30; /* Default to 30 */ umask(077); /* better safe than sorry --SRB */ diff --git a/ircd/ircd_lexer.l b/ircd/ircd_lexer.l index 4ccee128..ae96b407 100644 --- a/ircd/ircd_lexer.l +++ b/ircd/ircd_lexer.l @@ -193,10 +193,10 @@ void cinclude(void) if (tmp_fbfile_in == NULL) { - /* if its not found in PREFIX, look in ETCPATH */ + /* if its not found in PREFIX, look in IRCD_PATH_ETC */ char fnamebuf[BUFSIZE]; - snprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", ETCPATH, c); + snprintf(fnamebuf, sizeof(fnamebuf), "%s%c%s", IRCD_PATH_ETC, RB_PATH_SEPARATOR, c); tmp_fbfile_in = fopen(fnamebuf, "r"); /* wasnt found there either.. error. */ diff --git a/ircd/modules.c b/ircd/modules.c index da3da947..2173dd69 100644 --- a/ircd/modules.c +++ b/ircd/modules.c @@ -129,8 +129,8 @@ modules_init(void) mod_add_cmd(&modrestart_msgtab); /* Add the default paths we look in to the module system --nenolod */ - mod_add_path(MODPATH); - mod_add_path(AUTOMODPATH); + mod_add_path(ircd_paths[IRCD_PATH_MODULES]); + mod_add_path(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]); } /* mod_find_path() @@ -243,11 +243,11 @@ load_all_modules(int warn) max_mods = MODS_INCREMENT; - system_module_dir = opendir(AUTOMODPATH); + system_module_dir = opendir(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]); if(system_module_dir == NULL) { - ilog(L_MAIN, "Could not load modules from %s: %s", AUTOMODPATH, strerror(errno)); + ilog(L_MAIN, "Could not load modules from %s: %s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], strerror(errno)); return; } @@ -258,7 +258,7 @@ load_all_modules(int warn) len = strlen(ldirent->d_name); if(len > module_ext_len && !strcasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT)) { - (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name); + (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s%c%s", ircd_paths[IRCD_PATH_AUTOLOAD_MODULES], RB_PATH_SEPARATOR, ldirent->d_name); (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0); } @@ -281,7 +281,7 @@ load_core_modules(int warn) for (i = 0; core_module_table[i]; i++) { - snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH, + snprintf(module_name, sizeof(module_name), "%s%c%s%s", ircd_paths[IRCD_PATH_MODULES], RB_PATH_SEPARATOR, core_module_table[i], LT_MODULE_EXT); if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1) diff --git a/ircd/restart.c b/ircd/restart.c index 1a63b572..f91f9293 100644 --- a/ircd/restart.c +++ b/ircd/restart.c @@ -72,10 +72,10 @@ server_reboot(void) close(i); unlink(pidFileName); - execv(SPATH, (void *)myargv); + execv(ircd_paths[IRCD_PATH_IRCD_EXEC], (void *)myargv); /* use this if execv of SPATH fails */ - snprintf(path, sizeof(path), "%s/bin/ircd", ConfigFileEntry.dpath); + snprintf(path, sizeof(path), "%s%cbin%circd", ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR); execv(path, (void *)myargv); exit(-1); diff --git a/ircd/sslproc.c b/ircd/sslproc.c index 6d53caf3..2edd091e 100644 --- a/ircd/sslproc.c +++ b/ircd/sslproc.c @@ -278,17 +278,17 @@ start_ssldaemon(int count, const char *ssl_cert, const char *ssl_private_key, co if(ssld_path == NULL) { - snprintf(fullpath, sizeof(fullpath), "%s/ssld%s", PKGLIBEXECDIR, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cssld%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { - snprintf(fullpath, sizeof(fullpath), "%s/bin/ssld%s", - ConfigFileEntry.dpath, suffix); + snprintf(fullpath, sizeof(fullpath), "%s%cbin%cssld%s", + ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix); if(access(fullpath, X_OK) == -1) { ilog(L_MAIN, "Unable to execute ssld%s in %s or %s/bin", - suffix, PKGLIBEXECDIR, ConfigFileEntry.dpath); + suffix, ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath); return 0; } } diff --git a/modules/m_rehash.c b/modules/m_rehash.c index bd6670aa..3151abfa 100644 --- a/modules/m_rehash.c +++ b/modules/m_rehash.c @@ -117,7 +117,7 @@ rehash_omotd(struct Client *source_p) remote_rehash_oper_p = source_p; free_cachefile(oper_motd); - oper_motd = cache_file(OPATH, "opers.motd", 0); + oper_motd = cache_file(ircd_paths[IRCD_PATH_IRCD_OMOTD], "opers.motd", 0); } static void