Merge branch 'master' into release/4

This commit is contained in:
William Pitcock 2016-06-18 01:06:52 -05:00
commit 16e64bb554
8 changed files with 102 additions and 117 deletions

View file

@ -197,7 +197,7 @@
#define NUMERIC_STR_501 ":%s 501 %s :Unknown MODE flag"
#define NUMERIC_STR_502 ":%s 502 %s :Can't change mode for other users"
#define NUMERIC_STR_504 ":%s 504 %s %s :User is not on this server"
#define NUMERIC_STR_513 ":%s 513 %s :To connect type /QUOTE PONG %08lX"
#define NUMERIC_STR_513 ":%s 513 %s :To connect type /QUOTE PONG %08X"
#define NUMERIC_STR_517 "%s :This command has been administratively disabled"
#define NUMERIC_STR_524 ":%s 524 %s %s :Help not found"
#define NUMERIC_STR_670 ":STARTTLS successful, proceed with TLS handshake"

View file

@ -46,6 +46,7 @@ struct module
int origin; /* Ditto */
int mapi_version;
void *mapi_header; /* actually struct mapi_mheader_av<mapi_version> */
rb_dlink_node node;
};
#define MAPI_MAGIC_HDR 0x4D410000
@ -133,12 +134,10 @@ extern void load_core_modules(bool);
extern bool unload_one_module(const char *, bool);
extern bool load_one_module(const char *, int, bool);
extern bool load_a_module(const char *, bool, int, bool);
extern int findmodule_byname(const char *);
extern void modules_init(void);
extern struct module *findmodule_byname(const char *);
extern void init_modules(void);
/* Misc externs */
extern struct module **modlist;
extern int num_mods;
extern int max_mods;
extern rb_dlink_list module_list;
extern rb_dlink_list mod_paths;
#endif /* INCLUDED_modules_h */

View file

@ -136,6 +136,25 @@ const char *ircd_paths[IRCD_PATH_COUNT] = {
[IRCD_PATH_LIBEXEC] = PKGLIBEXECDIR,
};
const char *ircd_pathnames[IRCD_PATH_COUNT] = {
[IRCD_PATH_PREFIX] = "prefix",
[IRCD_PATH_MODULES] = "modules",
[IRCD_PATH_AUTOLOAD_MODULES] = "autoload modules",
[IRCD_PATH_ETC] = "config",
[IRCD_PATH_LOG] = "log",
[IRCD_PATH_USERHELP] = "user help",
[IRCD_PATH_OPERHELP] = "oper help",
[IRCD_PATH_IRCD_EXEC] = "ircd binary",
[IRCD_PATH_IRCD_CONF] = "ircd.conf",
[IRCD_PATH_IRCD_MOTD] = "ircd.motd",
[IRCD_PATH_IRCD_LOG] = "ircd.log",
[IRCD_PATH_IRCD_PID] = "ircd.pid",
[IRCD_PATH_IRCD_OMOTD] = "oper motd",
[IRCD_PATH_BANDB] = "bandb",
[IRCD_PATH_BIN] = "binary dir",
[IRCD_PATH_LIBEXEC] = "libexec dir",
};
const char *logFileName = NULL;
const char *pidFileName = NULL;
@ -188,7 +207,6 @@ print_startup(int pid)
if (fd != 1)
abort();
#endif
inotice("runtime path: %s", rb_path_to_self());
inotice("now running in %s mode from %s as pid %d ...",
!server_state_foreground ? "background" : "foreground",
ConfigFileEntry.dpath, pid);
@ -391,6 +409,7 @@ initialize_server_capabs(void)
default_server_capabs &= ~CAP_ZIP;
}
#ifdef _WIN32
/*
* relocate_paths
*
@ -398,7 +417,6 @@ initialize_server_capabs(void)
* output - none
* side effects - items in ircd_paths[] array are relocated
*/
#ifdef _WIN32
static void
relocate_paths(void)
{
@ -468,6 +486,12 @@ relocate_paths(void)
snprintf(workbuf, sizeof workbuf, "%s%cbin", prefix, RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_BIN] = rb_strdup(workbuf);
ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(workbuf);
inotice("runtime paths:");
for (int i = 0; i < IRCD_PATH_COUNT; i++)
{
inotice(" %s: %s", ircd_pathnames[i], ircd_paths[i]);
}
}
#endif
@ -783,6 +807,7 @@ charybdis_main(int argc, char * const argv[])
init_authd(); /* Start up authd. */
init_dns(); /* Start up DNS query system */
init_modules(); /* Start up modules system */
privilegeset_set_new("default", "", 0);
@ -790,8 +815,6 @@ charybdis_main(int argc, char * const argv[])
fprintf(stderr, "\nBeginning config test\n");
read_conf_files(true); /* cold start init conf files */
mod_add_path(MODULE_DIR);
mod_add_path(MODULE_DIR "/autoload");
load_all_modules(1);
load_core_modules(1);

View file

@ -291,7 +291,7 @@ loadmodule:
char *m_bn;
m_bn = rb_basename((char *) $2);
if (findmodule_byname(m_bn) == -1)
if (findmodule_byname(m_bn) == NULL)
{
load_one_module($2, MAPI_ORIGIN_EXTENSION, 0);
}

View file

@ -43,7 +43,8 @@
# error "Charybdis requires loadable module support."
#endif
struct module **modlist = NULL;
rb_dlink_list module_list;
rb_dlink_list mod_paths;
static const char *core_module_table[] = {
"m_ban",
@ -65,14 +66,8 @@ static const char *core_module_table[] = {
#define MOD_WARN_DELTA (90 * 86400) /* time in seconds, 86400 seconds in a day */
#define MODS_INCREMENT 10
int num_mods = 0;
int max_mods = MODS_INCREMENT;
static rb_dlink_list mod_paths;
void
modules_init(void)
init_modules(void)
{
if(lt_dlinit())
{
@ -153,25 +148,27 @@ mod_clear_paths(void)
* output - index of module on success, -1 on failure
* side effects - none
*/
int
struct module *
findmodule_byname(const char *name)
{
int i;
rb_dlink_node *ptr;
char name_ext[PATH_MAX + 1];
rb_strlcpy(name_ext, name, sizeof name_ext);
rb_strlcat(name_ext, LT_MODULE_EXT, sizeof name_ext);
for (i = 0; i < num_mods; i++)
RB_DLINK_FOREACH(ptr, module_list.head)
{
if(!irccmp(modlist[i]->name, name))
return i;
struct module *mod = ptr->data;
if(!irccmp(modlist[i]->name, name_ext))
return i;
if(!irccmp(mod->name, name))
return mod;
if(!irccmp(mod->name, name_ext))
return mod;
}
return -1;
return NULL;
}
/* load_all_modules()
@ -188,12 +185,6 @@ load_all_modules(bool warn)
char module_fq_name[PATH_MAX + 1];
size_t module_ext_len = strlen(LT_MODULE_EXT);
modules_init();
modlist = (struct module **) rb_malloc(sizeof(struct module *) * (MODS_INCREMENT));
max_mods = MODS_INCREMENT;
system_module_dir = opendir(ircd_paths[IRCD_PATH_AUTOLOAD_MODULES]);
if(system_module_dir == NULL)
@ -285,8 +276,6 @@ load_one_module(const char *path, int origin, bool coremodule)
return false;
}
static void increase_modlist(void);
static char unknown_ver[] = "<unknown>";
static char unknown_description[] = "<none>";
@ -300,9 +289,9 @@ static char unknown_description[] = "<none>";
bool
unload_one_module(const char *name, bool warn)
{
int modindex;
struct module *mod;
if((modindex = findmodule_byname(name)) == -1)
if((mod = findmodule_byname(name)) == NULL)
return false;
/*
@ -316,11 +305,11 @@ unload_one_module(const char *name, bool warn)
** -jmallett
*/
/* Left the comment in but the code isn't here any more -larne */
switch (modlist[modindex]->mapi_version)
switch (mod->mapi_version)
{
case 1:
{
struct mapi_mheader_av1 *mheader = modlist[modindex]->mapi_header;
struct mapi_mheader_av1 *mheader = mod->mapi_header;
if(mheader->mapi_command_list)
{
struct Message **m;
@ -344,7 +333,7 @@ unload_one_module(const char *name, bool warn)
}
case 2:
{
struct mapi_mheader_av2 *mheader = modlist[modindex]->mapi_header;
struct mapi_mheader_av2 *mheader = mod->mapi_header;
/* XXX duplicate code :( */
if(mheader->mapi_command_list)
@ -385,10 +374,10 @@ unload_one_module(const char *name, bool warn)
default:
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
m->cap_index, m->cap_name, modlist[modindex]->name);
m->cap_index, m->cap_name, mod->name);
ilog(L_MAIN,
"Unknown/unsupported CAP index found of type %d on capability %s when unloading %s",
m->cap_index, m->cap_name, modlist[modindex]->name);
m->cap_index, m->cap_name, mod->name);
continue;
}
@ -404,21 +393,17 @@ unload_one_module(const char *name, bool warn)
default:
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"Unknown/unsupported MAPI version %d when unloading %s!",
modlist[modindex]->mapi_version, modlist[modindex]->name);
mod->mapi_version, mod->name);
ilog(L_MAIN, "Unknown/unsupported MAPI version %d when unloading %s!",
modlist[modindex]->mapi_version, modlist[modindex]->name);
mod->mapi_version, mod->name);
break;
}
lt_dlclose(modlist[modindex]->address);
lt_dlclose(mod->address);
rb_free(modlist[modindex]->name);
rb_free(modlist[modindex]);
memmove(&modlist[modindex], &modlist[modindex + 1],
sizeof(struct module *) * ((num_mods - 1) - modindex));
if(num_mods != 0)
num_mods--;
rb_dlinkDelete(&mod->node, &module_list);
rb_free(mod->name);
rb_free(mod);
if(warn)
{
@ -439,6 +424,7 @@ unload_one_module(const char *name, bool warn)
bool
load_a_module(const char *path, bool warn, int origin, bool core)
{
struct module *mod;
lt_dlhandle tmpptr;
char *mod_displayname, *c;
const char *ver, *description = NULL;
@ -641,18 +627,16 @@ load_a_module(const char *path, bool warn, int origin, bool core)
if(description == NULL)
description = unknown_description;
increase_modlist();
modlist[num_mods] = rb_malloc(sizeof(struct module));
modlist[num_mods]->address = tmpptr;
modlist[num_mods]->version = ver;
modlist[num_mods]->description = description;
modlist[num_mods]->core = core;
modlist[num_mods]->name = rb_strdup(mod_displayname);
modlist[num_mods]->mapi_header = mapi_version;
modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version);
modlist[num_mods]->origin = origin;
num_mods++;
mod = rb_malloc(sizeof(struct module));
mod->address = tmpptr;
mod->version = ver;
mod->description = description;
mod->core = core;
mod->name = rb_strdup(mod_displayname);
mod->mapi_header = mapi_version;
mod->mapi_version = MAPI_VERSION(*mapi_version);
mod->origin = origin;
rb_dlinkAdd(mod, &mod->node, &module_list);
if(warn)
{
@ -681,27 +665,3 @@ load_a_module(const char *path, bool warn, int origin, bool core)
rb_free(mod_displayname);
return true;
}
/*
* increase_modlist
*
* inputs - NONE
* output - NONE
* side effects - expand the size of modlist if necessary
*/
static void
increase_modlist(void)
{
struct module **new_modlist = NULL;
if((num_mods + 1) < max_mods)
return;
new_modlist = (struct module **) rb_malloc(sizeof(struct module *) *
(max_mods + MODS_INCREMENT));
memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module *) * num_mods);
rb_free(modlist);
modlist = new_modlist;
max_mods += MODS_INCREMENT;
}

View file

@ -300,7 +300,7 @@ conf_set_modules_module(void *data)
m_bn = rb_basename((char *) data);
if(findmodule_byname(m_bn) == -1)
if(findmodule_byname(m_bn) == NULL)
load_one_module((char *) data, MAPI_ORIGIN_EXTENSION, false);
rb_free(m_bn);

View file

@ -138,7 +138,6 @@ rb_dictionary_get_linear_index(rb_dictionary *dict, const void *key)
rb_dictionary_element *elem;
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
elem = rb_dictionary_find(dict, key);
if (elem == NULL)
@ -648,7 +647,6 @@ void rb_dictionary_foreach_next(rb_dictionary *dtree,
rb_dictionary_element *rb_dictionary_find(rb_dictionary *dict, const void *key)
{
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
/* retune for key, key will be the tree's root if it's available */
rb_dictionary_retune(dict, key);
@ -681,7 +679,6 @@ rb_dictionary_element *rb_dictionary_add(rb_dictionary *dict, const void *key, v
rb_dictionary_element *delem;
lrb_assert(dict != NULL);
lrb_assert(key != NULL);
lrb_assert(data != NULL);
lrb_assert(rb_dictionary_find(dict, key) == NULL);

View file

@ -265,7 +265,7 @@ do_modload(struct Client *source_p, const char *module)
char *m_bn = rb_basename(module);
int origin;
if(findmodule_byname(m_bn) != -1)
if(findmodule_byname(m_bn) != NULL)
{
sendto_one_notice(source_p, ":Module %s is already loaded", m_bn);
rb_free(m_bn);
@ -281,17 +281,17 @@ do_modload(struct Client *source_p, const char *module)
static void
do_modunload(struct Client *source_p, const char *module)
{
int modindex;
struct module *mod;
char *m_bn = rb_basename(module);
if((modindex = findmodule_byname(m_bn)) == -1)
if((mod = findmodule_byname(m_bn)) == NULL)
{
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
rb_free(m_bn);
return;
}
if(modlist[modindex]->core)
if(mod->core)
{
sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn);
rb_free(m_bn);
@ -307,18 +307,18 @@ do_modunload(struct Client *source_p, const char *module)
static void
do_modreload(struct Client *source_p, const char *module)
{
int modindex;
struct module *mod;
int check_core;
char *m_bn = rb_basename(module);
if((modindex = findmodule_byname(m_bn)) == -1)
if((mod = findmodule_byname(m_bn)) == NULL)
{
sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
rb_free(m_bn);
return;
}
check_core = modlist[modindex]->core;
check_core = mod->core;
if(unload_one_module(m_bn, true) == false)
{
@ -327,7 +327,7 @@ do_modreload(struct Client *source_p, const char *module)
return;
}
if((load_one_module(m_bn, modlist[modindex]->origin, check_core) == false) && check_core)
if((load_one_module(m_bn, mod->origin, check_core) == false) && check_core)
{
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Error reloading core module: %s: terminating ircd", m_bn);
@ -341,33 +341,39 @@ do_modreload(struct Client *source_p, const char *module)
static void
do_modrestart(struct Client *source_p)
{
int modnum;
unsigned int modnum = 0;
rb_dlink_node *ptr, *nptr;
sendto_one_notice(source_p, ":Reloading all modules");
modnum = num_mods;
while (num_mods)
unload_one_module(modlist[0]->name, false);
RB_DLINK_FOREACH_SAFE(ptr, nptr, module_list.head)
{
struct module *mod = ptr->data;
unload_one_module(mod->name, false);
modnum++;
}
load_all_modules(false);
load_core_modules(false);
rehash(false);
sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
"Module Restart: %d modules unloaded, %d modules loaded",
modnum, num_mods);
ilog(L_MAIN, "Module Restart: %d modules unloaded, %d modules loaded", modnum, num_mods);
"Module Restart: %u modules unloaded, %lu modules loaded",
modnum, rb_dlink_list_length(&module_list));
ilog(L_MAIN, "Module Restart: %u modules unloaded, %lu modules loaded", modnum, rb_dlink_list_length(&module_list));
}
static void
do_modlist(struct Client *source_p, const char *pattern)
{
rb_dlink_node *ptr;
int i;
for (i = 0; i < num_mods; i++)
RB_DLINK_FOREACH(ptr, module_list.head)
{
struct module *mod = ptr->data;
const char *origin;
switch (modlist[i]->origin)
switch (mod->origin)
{
case MAPI_ORIGIN_EXTENSION:
origin = "extension";
@ -382,21 +388,21 @@ do_modlist(struct Client *source_p, const char *pattern)
if(pattern)
{
if(match(pattern, modlist[i]->name))
if(match(pattern, mod->name))
{
sendto_one(source_p, form_str(RPL_MODLIST),
me.name, source_p->name,
modlist[i]->name,
(unsigned long)(uintptr_t)modlist[i]->address, origin,
modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
mod->name,
(unsigned long)(uintptr_t)mod->address, origin,
mod->core ? " (core)" : "", mod->version, mod->description);
}
}
else
{
sendto_one(source_p, form_str(RPL_MODLIST),
me.name, source_p->name, modlist[i]->name,
(unsigned long)(uintptr_t)modlist[i]->address, origin,
modlist[i]->core ? " (core)" : "", modlist[i]->version, modlist[i]->description);
me.name, source_p->name, mod->name,
(unsigned long)(uintptr_t)mod->address, origin,
mod->core ? " (core)" : "", mod->version, mod->description);
}
}