diff --git a/.gitattributes b/.gitattributes index c9bc8e44..1a4dbd33 100644 --- a/.gitattributes +++ b/.gitattributes @@ -63,6 +63,8 @@ src/adns/setup.c -text src/adns/transmit.c -text src/adns/tvarith.h -text src/adns/types.c -text +src/auth.c -text +src/auth.h -text src/bans.c -text src/bans.h -text src/bots.c -text diff --git a/ChangeLog b/ChangeLog index 255c7ae4..bb07866f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ NeoStats ChangeLog Anything we add/remove/fix/change is in here (even our rants) =============================================================================== * NeoStats * Fish (F) & Mark (M) * Version 3.0.genesis + - seperate auth system from main core so we can add new auth hooks (M) - send_sjoin bug fix where user has no modes (M) - Segfault reports are now directed to segfault.log rather than the main log files for easier submission (M) diff --git a/src/Makefile.in b/src/Makefile.in index d6e6e373..b1df7472 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -15,14 +15,14 @@ OBJS = ${SRCS:.c=.o} SRCS = dns.c chans.c dotconf.c services.c main.c sock.c conf.c ircd.c timer.c \ users.c ns_help.c dl.c list.c hash.c server.c keeper.c log.c misc.c \ support.c ircstring.c commands.c transfer.c exclude.c match.c bans.c \ - bots.c modules.c + bots.c modules.c auth.c INCLUDES = config.h dl.h dotconf.h hash.h list.h neostats.h \ conf.h log.h support.h ircstring.h events.h numeric.h pcre.h \ transfer.h COREINCS = dns.h services.h sock.h ircd.h exclude.h \ ns_help.h timer.h users.h chans.h server.h bans.h \ - bots.h modules.h commands.h + bots.h modules.h commands.h auth.h BUILDFILES = *.in modules/Makefile modules/Makefile.inc.in DISTFILES = $(INCLUDES) $(COREINCS) $(SRCS) $(BUILDFILES) diff --git a/src/auth.c b/src/auth.c new file mode 100644 index 00000000..d4f60dbf --- /dev/null +++ b/src/auth.c @@ -0,0 +1,117 @@ +/* NeoStats - IRC Statistical Services +** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond, Mark Hetherington +** http://www.neostats.net/ +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +** USA +** +** NeoStats CVS Identification +** $Id$ +*/ + +#include "neostats.h" +#include "ircd.h" + +Module* extauth_modptr; + +/* Do dl lookups in advance to speed up UserLevel processing + * + */ +#ifdef EXTAUTH +int (*getauth) (User *, int curlvl); +int InitExtAuth(void) +{ + getauth = ns_dlsym (extauth_modptr->dl_handle , "__do_auth"); + return NS_SUCCESS; +} +#endif + +int UmodeAuth(User * u) +{ + int i, tmplvl = 0; + /* Note, tables have been reordered highest to lowest so the + * first hit will give the highest level for a given umode + * combination so we can just set it without checking against + * the current level + * we can also quit on the first occurrence of 0 + * should be a lot faster! + */ + for (i = 0; i < ircd_umodecount; i++) { + if(user_umodes[i].level == 0) + break; + if (u->Umode & user_umodes[i].umode) { + tmplvl = user_umodes[i].level; + break; + } + } + nlog (LOG_DEBUG1, "UmodeAuth: umode level for %s is %d", u->nick, tmplvl); + +/* I hate SMODEs damn it */ +#ifdef GOTUSERSMODES + /* hey, smode can equal 0 as well you know */ + /* see umode comments above */ + for (i = 0; i < ircd_smodecount; i++) { + if(user_smodes[i].level == 0) + break; + if (u->Smode & user_smodes[i].umode) { + /* only if the smode level is higher than standard, do we alter tmplvl */ + if (user_smodes[i].level > tmplvl) + tmplvl = user_smodes[i].level; + break; + } + } + nlog (LOG_DEBUG1, "UmodeAuth: smode level for %s is %d", u->nick, tmplvl); +#endif + return tmplvl; +} + +int UserAuth(User * u) +{ + int i = 0; + int tmplvl = 0; + tmplvl = UmodeAuth(u); +#ifdef EXTAUTH + if (getauth) + i = (*getauth) (u, tmplvl); + /* if tmplvl is greater than 1000, then extauth is authoritive */ + if (i > tmplvl) + tmplvl = i; +#endif + return; +} + +int InitAuth(void) +{ +#ifdef EXTAUTH + /* load extauth if we need to */ + extauth_modptr = load_module ("extauth", NULL); + InitExtAuth(); +#endif + return 0; +} + +int ListAuth(User *u) +{ +#ifdef EXTAUTH + int (*listauth) (User * u); + + listauth = ns_dlsym (extauth_modptr->dl_handle, "__list_auth"); + if (listauth) { + (*listauth) (u); + return NS_SUCCESS; + } +#endif + return NS_FAILURE; +} \ No newline at end of file diff --git a/src/auth.h b/src/auth.h new file mode 100644 index 00000000..039b3b82 --- /dev/null +++ b/src/auth.h @@ -0,0 +1,31 @@ +/* NeoStats - IRC Statistical Services +** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond, Mark Hetherington +** http://www.neostats.net/ +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +** USA +** +** NeoStats CVS Identification +** $Id$ +*/ + +#ifndef _AUTH_H_ +#define _AUTH_H_ + +int InitAuth(void); +int UserAuth(User *u); +int ListAuth(User *u); + +#endif /* _AUTH_H_ */ diff --git a/src/conf.c b/src/conf.c index 7f5333a3..b4833d23 100644 --- a/src/conf.c +++ b/src/conf.c @@ -204,7 +204,6 @@ int ConfLoadModules () { int i; - int rval; SET_SEGV_LOCATION(); if(load_mods[1] == 0) { @@ -214,8 +213,7 @@ ConfLoadModules () nlog (LOG_NORMAL, "Loading configured modules"); for (i = 1; (i < NUM_MODULES) && (load_mods[i] != 0); i++) { nlog (LOG_DEBUG1, "ConfLoadModules: Loading Module %s", (char *)load_mods[i]); - rval = load_module (load_mods[i], NULL); - if (rval == NS_SUCCESS) { + if (load_module (load_mods[i], NULL)) { nlog (LOG_NORMAL, "Successfully Loaded Module %s", (char *)load_mods[i]); } else { nlog (LOG_WARNING, "Could Not Load Module %s, Please check above error Messages", (char *)load_mods[i]); diff --git a/src/ircd.c b/src/ircd.c index 36a51404..d8a4f874 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -741,10 +741,6 @@ do_stats (const char* nick, const char *what) time_t tmp; time_t tmp2; int i; -#ifdef EXTAUTH - int dl; - int (*listauth) (User * u); -#endif User *u; SET_SEGV_LOCATION(); @@ -763,15 +759,7 @@ do_stats (const char* nick, const char *what) numeric (RPL_STATSCLINE, u->nick, "C *@%s * * %d 50", me.uplink, me.port); } else if (!ircstrcasecmp (what, "o")) { /* Operators */ -#ifdef EXTAUTH - dl = get_dl_handle ("extauth"); - if (dl > 0) { - listauth = ns_dlsym ((int *) dl, "__list_auth"); - if (listauth) - (*listauth) (u); - } else -#endif - numeric (RPL_STATSOLINE, u->nick, "Operators think they are God, but you and I know they are not!"); + ListAuth(u); } else if (!ircstrcasecmp (what, "l")) { /* Port Lists */ tmp = me.now - me.lastmsg; diff --git a/src/main.c b/src/main.c index 3c205c24..714a88e1 100644 --- a/src/main.c +++ b/src/main.c @@ -119,6 +119,9 @@ int InitCore(void) /* initilze our Module subsystem */ if(InitModules () != NS_SUCCESS) return NS_FAILURE; + + InitAuth(); + if(InitTimers() != NS_SUCCESS) return NS_FAILURE; if(InitBots() != NS_SUCCESS) diff --git a/src/modules.c b/src/modules.c index d3b8efdf..6f827952 100644 --- a/src/modules.c +++ b/src/modules.c @@ -254,7 +254,7 @@ ModulesVersion (const char* nick, const char *remoteserver) * * @return */ -int +Module * load_module (char *modfilename, User * u) { #ifndef HAVE_LIBDL @@ -291,7 +291,7 @@ load_module (char *modfilename, User * u) prefmsg (u->nick, ns_botptr->nick, "Unable to load module: %s %s", dl_error, path); } nlog (LOG_WARNING, "Unable to load module: %s %s", dl_error, path); - return NS_FAILURE; + return NULL; } info_ptr = ns_dlsym (dl_handle, "module_info"); @@ -306,13 +306,13 @@ load_module (char *modfilename, User * u) } nlog (LOG_WARNING, "Unable to load module: %s %s", dl_error, path); ns_dlclose (dl_handle); - return NS_FAILURE; + return NULL; } /* Check module was built for this version of NeoStats */ if( ircstrncasecmp (NEOSTATS_VERSION, info_ptr->neostats_version, VERSIONSIZE) !=0 ) { nlog (LOG_WARNING, "Unable to load module: %s was built with an old version of NeoStats and must be rebuilt.", mod_ptr->info->name); ns_dlclose (dl_handle); - return NS_FAILURE; + return NULL; } /* Check that the Module hasn't already been loaded */ if (hash_lookup (mh, info_ptr->name)) { @@ -321,7 +321,7 @@ load_module (char *modfilename, User * u) prefmsg (u->nick, ns_botptr->nick, "Unable to load module: %s already loaded", info_ptr->name); } nlog (LOG_WARNING, "Unable to load module: %s already loaded", info_ptr->name); - return NS_FAILURE; + return NULL; } /* Extract pointer to event list */ event_ptr = ns_dlsym (dl_handle, "module_events"); @@ -336,7 +336,7 @@ load_module (char *modfilename, User * u) } ns_dlclose (dl_handle); free (mod_ptr); - return NS_FAILURE; + return NULL; } hash_insert (mh, mn, info_ptr->name); nlog (LOG_DEBUG1, "Module Internal name: %s", info_ptr->name); @@ -363,7 +363,7 @@ load_module (char *modfilename, User * u) } ns_dlclose (dl_handle); free (mod_ptr); - return NS_FAILURE; + return NULL; } else { int err; SET_SEGV_LOCATION(); @@ -372,7 +372,7 @@ load_module (char *modfilename, User * u) if (err < 1) { nlog (LOG_NORMAL, "Unable to load module: %s. See %s.log for further information.", mod_ptr->info->name, mod_ptr->info->name); unload_module(mod_ptr->info->name, NULL); - return NS_FAILURE; + return NULL; } CLEAR_SEGV_INMODULE(); SET_SEGV_LOCATION(); @@ -398,7 +398,7 @@ load_module (char *modfilename, User * u) prefmsg (u->nick, ns_botptr->nick, "Module %s loaded, %s", info_ptr->name, info_ptr->description); globops (me.name, "Module %s loaded", info_ptr->name); } - return NS_SUCCESS; + return mod_ptr; } /** @brief diff --git a/src/modules.h b/src/modules.h index e1e1266c..0c601876 100644 --- a/src/modules.h +++ b/src/modules.h @@ -27,7 +27,7 @@ int InitModules (void); int FiniModules (void); void SendModuleEvent (char * event, char **av, int ac); -int load_module (char *path, User * u); +Module *load_module (char *path, User * u); int unload_module (const char *module_name, User * u); int list_modules (User * u, char **av, int ac); int get_dl_handle (const char *mod_name); diff --git a/src/modules/extauth/serviceroots.c b/src/modules/extauth/serviceroots.c index 94e9bacf..cbd5d8fd 100644 --- a/src/modules/extauth/serviceroots.c +++ b/src/modules/extauth/serviceroots.c @@ -76,6 +76,18 @@ typedef struct users { int lvl; } users; +static int Online(char **av, int ac) +{ + add_services_cmd_list(extauth_commands); + return 1; +}; + +ModuleEvent module_events[] = { + {EVENT_ONLINE, Online}, + {NULL, NULL} +}; + + int __ModInit(int modnum, int apiver) { srconf.auth = 0; @@ -85,7 +97,6 @@ int __ModInit(int modnum, int apiver) nlog(LOG_WARNING, "ServiceRoots: config failed"); /* we can't unload the extauth module so don't return -1 */ } - add_services_cmd_list(extauth_commands); return 1; } diff --git a/src/services.c b/src/services.c index 477e37fe..43c52d74 100644 --- a/src/services.c +++ b/src/services.c @@ -116,11 +116,6 @@ init_services_bot (void) flags = me.onlyopers ? BOT_FLAG_ONLY_OPERS : 0; flags |= BOT_FLAG_DEAF; ns_botptr = init_bot (NULL, &ns_botinfo, services_bot_modes, flags, ns_commands, NULL); -#ifdef EXTAUTH - /* load extauth if we need to */ - load_module ("extauth", NULL); - InitExtAuth(); -#endif me.onchan = 1; AddStringToList (&av, me.uplink, &ac); SendModuleEvent (EVENT_ONLINE, av, ac); @@ -464,7 +459,7 @@ static int ns_load (User * u, char **av, int ac) { SET_SEGV_LOCATION(); - if (load_module (av[1], u) == NS_SUCCESS) { + if (load_module (av[1], u)) { chanalert (ns_botptr->nick, "%s loaded module %s", u->nick, av[1]); } else { chanalert (ns_botptr->nick, "%s tried to load module %s, but load failed", u->nick, av[1]); diff --git a/src/users.c b/src/users.c index 06292bf1..0870949c 100644 --- a/src/users.c +++ b/src/users.c @@ -676,89 +676,22 @@ UserDump (const char *nick) } } -/* Do dl lookups in advance to speed up UserLevel processing - * - */ -#ifdef EXTAUTH -int (*getauth) (User *, int curlvl); -int InitExtAuth(void) -{ - int i; - i = get_dl_handle ("extauth"); - if (i > 0) { - getauth = ns_dlsym ((int *) i, "__do_auth"); - return NS_SUCCESS; - } - return NS_FAILURE; -} -#endif - -int UmodeAuth(User * u) -{ - int i, tmplvl = 0; - /* Note, tables have been reordered highest to lowest so the - * first hit will give the highest level for a given umode - * combination so we can just set it without checking against - * the current level - * we can also quit on the first occurrence of 0 - * should be a lot faster! - */ - for (i = 0; i < ircd_umodecount; i++) { - if(user_umodes[i].level == 0) - break; - if (u->Umode & user_umodes[i].umode) { - tmplvl = user_umodes[i].level; - break; - } - } - nlog (LOG_DEBUG1, "UmodeAuth: umode level for %s is %d", u->nick, tmplvl); - -/* I hate SMODEs damn it */ -#ifdef GOTUSERSMODES - /* hey, smode can equal 0 as well you know */ - /* see umode comments above */ - for (i = 0; i < ircd_smodecount; i++) { - if(user_smodes[i].level == 0) - break; - if (u->Smode & user_smodes[i].umode) { - /* only if the smode level is higher than standard, do we alter tmplvl */ - if (user_smodes[i].level > tmplvl) - tmplvl = user_smodes[i].level; - break; - } - } - nlog (LOG_DEBUG1, "UmodeAuth: smode level for %s is %d", u->nick, tmplvl); -#endif - return tmplvl; -} - int UserLevel (User * u) { - int i = 0; - int tmplvl = 0; - tmplvl = UmodeAuth(u); - -#ifdef EXTAUTH - if (getauth) - i = (*getauth) (u, tmplvl); - /* if tmplvl is greater than 1000, then extauth is authoritive */ - if (i > tmplvl) - tmplvl = i; -#endif - + int ulevel = 0; + ulevel = UserAuth(u); #ifdef DEBUG #ifdef CODERHACK /* this is only cause I dun have the right O lines on some of my "Beta" Networks, so I need to hack this in :) */ if (!ircstrcasecmp (u->nick, "FISH")) - tmplvl = NS_ULEVEL_ROOT; + ulevel = NS_ULEVEL_ROOT; if (!ircstrcasecmp (u->nick, "SHMAD")) - tmplvl = NS_ULEVEL_ROOT; + ulevel = NS_ULEVEL_ROOT; #endif #endif - - nlog (LOG_DEBUG1, "UserLevel for %s is %d (%d)", u->nick, tmplvl, i); - return tmplvl; + nlog (LOG_DEBUG1, "UserLevel for %s is %d", u->nick, ulevel); + return ulevel; } void diff --git a/src/users.h b/src/users.h index 67f91a3d..10a00066 100644 --- a/src/users.h +++ b/src/users.h @@ -37,7 +37,6 @@ void UserSMode (const char *nick, const char *modes); int InitUsers (void); void UserAway (const char *nick, const char *awaymsg); void DelUser (const char *nick, int killflag, const char *reason); -int InitExtAuth(void); void FreeUsers(); #ifdef BASE64NICKNAME User *finduserbase64 (const char *num);