seperate auth system from main core

This commit is contained in:
Mark 2004-03-26 22:45:56 +00:00
parent d9bde09e10
commit 96d483f13a
14 changed files with 187 additions and 109 deletions

2
.gitattributes vendored
View file

@ -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

View file

@ -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)

View file

@ -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)

117
src/auth.c Normal file
View file

@ -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;
}

31
src/auth.h Normal file
View file

@ -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_ */

View file

@ -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]);

View file

@ -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;

View file

@ -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)

View file

@ -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

View file

@ -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);

View file

@ -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;
}

View file

@ -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]);

View file

@ -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

View file

@ -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);