--- /dev/null
+
+.PHONY: all
+all: authext.so
+
+authext.so: authext.o
+ ld -shared -Bdynamic -o $@ $^
--- /dev/null
+#include "authext.h"
+#include "../core/nsmalloc.h"
+#include "../core/error.h"
+#include "../lib/sstring.h"
+#include "../lib/irc_string.h"
+
+#include <string.h>
+
+#define ALLOCUNIT 100
+
+#define authnamehash(x) ((x)%AUTHNAMEHASHSIZE)
+
+authname *freeauthnames;
+authname *authnametable[AUTHNAMEHASHSIZE];
+
+sstring *authnameextnames[MAXAUTHNAMEEXTS];
+
+void _init() {
+ freeauthnames=NULL;
+ memset(authnametable,0,sizeof(authnametable));
+}
+
+void _fini() {
+ nsfreeall(POOL_AUTHEXT);
+}
+
+authname *newauthname() {
+ authname *anp;
+ int i;
+
+ if (freeauthnames==NULL) {
+ freeauthnames=(authname *)nsmalloc(POOL_AUTHEXT, ALLOCUNIT*sizeof(authname));
+ for (i=0;i<(ALLOCUNIT-1);i++) {
+ freeauthnames[i].next=&(freeauthnames[i+1]);
+ }
+ freeauthnames[ALLOCUNIT-1].next=NULL;
+ }
+
+ anp=freeauthnames;
+ freeauthnames=anp->next;
+
+ return anp;
+}
+
+void freeauthname (authname *anp) {
+ anp->next=freeauthnames;
+ freeauthnames=anp;
+}
+
+int registerauthnameext(const char *name) {
+ int i;
+
+ if (findauthnameext(name)!=-1) {
+ Error("nick",ERR_WARNING,"Tried to register duplicate authname extension %s",name);
+ return -1;
+ }
+
+ for (i=0;i<MAXAUTHNAMEEXTS;i++) {
+ if (authnameextnames[i]==NULL) {
+ authnameextnames[i]=getsstring(name,100);
+ return i;
+ }
+ }
+
+ Error("nick",ERR_WARNING,"Tried to register too many authname extensions: %s",name);
+ return -1;
+}
+
+int findauthnameext(const char *name) {
+ int i;
+
+ for (i=0;i<MAXAUTHNAMEEXTS;i++) {
+ if (authnameextnames[i]!=NULL && !ircd_strcmp(name,authnameextnames[i]->content)) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+void releaseauthnameext(int index) {
+ int i;
+ authname *anp;
+
+ freesstring(authnameextnames[index]);
+ authnameextnames[index]=NULL;
+
+ for (i=0;i<AUTHNAMEHASHSIZE;i++) {
+ for (anp=authnametable[i];anp;anp=anp->next) {
+ anp->exts[index]=NULL;
+ }
+ }
+}
+
+authname *findauthname(unsigned long userid) {
+ authname *anp;
+
+ if(!userid)
+ return NULL;
+
+ for (anp=authnametable[authnamehash(userid)];anp;anp=(authname *)anp->next)
+ if (userid==anp->userid)
+ return anp;
+
+ return NULL;
+}
+
+authname *findorcreateauthname(unsigned long userid) {
+ authname *anp;
+ unsigned int thehash=authnamehash(userid);
+
+ if(!userid)
+ return NULL;
+
+ for (anp=authnametable[thehash];anp;anp=(authname *)anp->next)
+ if (userid==anp->userid)
+ return anp;
+
+ anp=newauthname();
+ anp->userid=userid;
+ anp->usercount=0;
+ anp->marker=0;
+ anp->nicks=NULL;
+ memset(anp->exts, 0, MAXAUTHNAMEEXTS * sizeof(void *));
+ anp->next=(struct authname *)authnametable[thehash];
+ authnametable[thehash]=anp;
+
+ return anp;
+}
+
+void releaseauthname(authname *anp) {
+ authname **manp;
+ int i;
+ if (anp->usercount==0) {
+ for(i=0;i<MAXAUTHNAMEEXTS;i++)
+ if(anp->exts[i]!=NULL)
+ return;
+
+ for(manp=&(authnametable[authnamehash(anp->userid)]);*manp;manp=(authname **)&((*manp)->next)) {
+ if ((*manp)==anp) {
+ (*manp)=(authname *)anp->next;
+ freeauthname(anp);
+ return;
+ }
+ }
+ Error("nick",ERR_ERROR,"Unable to remove authname %lu from hashtable",anp->userid);
+ }
+}
+
+unsigned int nextauthnamemarker() {
+ int i;
+ authname *anp;
+ static unsigned int authnamemarker=0;
+
+ authnamemarker++;
+ if (!authnamemarker) {
+ /* If we wrapped to zero, zap the marker on all records */
+ for (i=0;i<AUTHNAMEHASHSIZE;i++)
+ for (anp=authnametable[i];anp;anp=anp->next)
+ anp->marker=0;
+ authnamemarker++;
+ }
+
+ return authnamemarker;
+}
--- /dev/null
+#ifndef __AUTHEXT_H
+#define __AUTHEXT_H
+
+#define MAXAUTHNAMEEXTS 5
+
+struct nick;
+
+typedef struct authname {
+ unsigned long userid;
+ int usercount;
+ unsigned int marker;
+ struct nick *nicks;
+ struct authname *next;
+ /* These are extensions only used by other modules */
+ void *exts[MAXAUTHNAMEEXTS];
+} authname;
+
+#define AUTHNAMEHASHSIZE 60000
+
+extern authname *authnametable[AUTHNAMEHASHSIZE];
+
+/* Allocators */
+authname *newauthname();
+void freeauthname (authname *hp);
+
+/* EXT management */
+int registerauthnameext(const char *name);
+int findauthnameext(const char *name);
+void releaseauthnameext(int index);
+
+/* Actual user commands */
+authname *findauthname(unsigned long userid);
+authname *findorcreateauthname(unsigned long userid);
+void releaseauthname(authname *anp);
+
+/* Marker */
+unsigned int nextauthnamemarker();
+
+#endif
sstring *nickextnames[MAXNICKEXTS];
sstring *nodeextnames[PATRICIA_MAXSLOTS];
patricia_tree_t *iptree;
-sstring *authnameextnames[MAXAUTHNAMEEXTS];
void nickstats(int hooknum, void *arg);
}
}
-int registerauthnameext(const char *name) {
- int i;
-
- if (findauthnameext(name)!=-1) {
- Error("nick",ERR_WARNING,"Tried to register duplicate authname extension %s",name);
- return -1;
- }
-
- for (i=0;i<MAXAUTHNAMEEXTS;i++) {
- if (authnameextnames[i]==NULL) {
- authnameextnames[i]=getsstring(name,100);
- return i;
- }
- }
-
- Error("nick",ERR_WARNING,"Tried to register too many authname extensions: %s",name);
- return -1;
-}
-
-int findauthnameext(const char *name) {
- int i;
-
- for (i=0;i<MAXAUTHNAMEEXTS;i++) {
- if (authnameextnames[i]!=NULL && !ircd_strcmp(name,authnameextnames[i]->content)) {
- return i;
- }
- }
-
- return -1;
-}
-
-void releaseauthnameext(int index) {
- int i;
- authname *anp;
-
- freesstring(authnameextnames[index]);
- authnameextnames[index]=NULL;
-
- for (i=0;i<AUTHNAMEHASHSIZE;i++) {
- for (anp=authnametable[i];anp;anp=anp->next) {
- anp->exts[index]=NULL;
- }
- }
-}
-
/* visiblehostmask
* Produces the "apparent" hostmask as seen by network users.
*/
#include "../lib/base64.h"
#include "../lib/irc_ipv6.h"
#include "../lib/patricia.h"
+
+#include "../authext/authext.h"
+
#include <time.h>
#define MAXNICKEXTS 6
-#define MAXAUTHNAMEEXTS 5
#define UMODE_INV 0x0001
#define UMODE_WALLOPS 0x0002
struct realname *next;
} realname;
-typedef struct authname {
- unsigned long userid;
- int usercount;
- unsigned int marker;
- struct nick *nicks;
- struct authname *next;
- /* These are extensions only used by other modules */
- void *exts[MAXAUTHNAMEEXTS];
-} authname;
-
typedef struct nick {
char nick[NICKLEN+1];
long numeric;
#define NICKHASHSIZE 60000
#define HOSTHASHSIZE 40000
#define REALNAMEHASHSIZE 40000
-#define AUTHNAMEHASHSIZE 60000
extern nick *nicktable[NICKHASHSIZE];
extern nick **servernicks[MAXSERVERS];
extern host *hosttable[HOSTHASHSIZE];
extern realname *realnametable[REALNAMEHASHSIZE];
-extern authname *authnametable[AUTHNAMEHASHSIZE];
extern const flag umodeflags[];
extern patricia_tree_t *iptree;
void freenick (nick *np);
host *newhost();
void freehost (host *hp);
-authname *newauthname();
-void freeauthname (authname *hp);
/* nick.c functions */
void handleserverchange(int hooknum, void *arg);
int registernickext(const char *name);
int findnickext(const char *name);
void releasenickext(int index);
-int registerauthnameext(const char *name);
-int findauthnameext(const char *name);
-void releaseauthnameext(int index);
char *visiblehostmask(nick *np, char *buf);
int registernodeext(const char *name);
int findnodeext(const char *name);
realname *findrealname(const char *name);
realname *findorcreaterealname(const char *name);
void releaserealname(realname *rnp);
-authname *findauthname(unsigned long userid);
-authname *findorcreateauthname(unsigned long userid);
-void releaseauthname(authname *anp);
unsigned int nexthostmarker();
unsigned int nextrealnamemarker();
-unsigned int nextauthnamemarker();
unsigned int nextnickmarker();
#endif
nick *freenicks;
host *freehosts;
-authname *freeauthnames;
void initnickalloc() {
freenicks=NULL;
freehosts=NULL;
- freeauthnames=NULL;
assert(sizeof(host)==sizeof(realname));
}
freehosts=hp;
}
-authname *newauthname() {
- authname *anp;
- int i;
-
- if (freeauthnames==NULL) {
- freeauthnames=(authname *)malloc(ALLOCUNIT*sizeof(authname));
- for (i=0;i<(ALLOCUNIT-1);i++) {
- freeauthnames[i].next=&(freeauthnames[i+1]);
- }
- freeauthnames[ALLOCUNIT-1].next=NULL;
- }
-
- anp=freeauthnames;
- freeauthnames=anp->next;
-
- return anp;
-}
-
-void freeauthname (authname *anp) {
- anp->next=freeauthnames;
- freeauthnames=anp;
-}
#define hosthash(x) ((crc32i(x))%HOSTHASHSIZE)
#define realnamehash(x) ((crc32(x))%REALNAMEHASHSIZE)
-#define authnamehash(x) ((x)%AUTHNAMEHASHSIZE)
host *hosttable[HOSTHASHSIZE];
realname *realnametable[REALNAMEHASHSIZE];
-authname *authnametable[AUTHNAMEHASHSIZE];
void initnickhelpers() {
memset(hosttable,0,sizeof(hosttable));
memset(realnametable,0,sizeof(realnametable));
- memset(authnametable,0,sizeof(authnametable));
}
host *findhost(const char *hostname) {
}
}
-authname *findauthname(unsigned long userid) {
- authname *anp;
-
- if(!userid)
- return NULL;
-
- for (anp=authnametable[authnamehash(userid)];anp;anp=(authname *)anp->next)
- if (userid==anp->userid)
- return anp;
-
- return NULL;
-}
-
-authname *findorcreateauthname(unsigned long userid) {
- authname *anp;
- unsigned int thehash=authnamehash(userid);
-
- if(!userid)
- return NULL;
-
- for (anp=authnametable[thehash];anp;anp=(authname *)anp->next)
- if (userid==anp->userid)
- return anp;
-
- anp=newauthname();
- anp->userid=userid;
- anp->usercount=0;
- anp->marker=0;
- anp->nicks=NULL;
- memset(anp->exts, 0, MAXAUTHNAMEEXTS * sizeof(void *));
- anp->next=(struct authname *)authnametable[thehash];
- authnametable[thehash]=anp;
-
- return anp;
-}
-
-void releaseauthname(authname *anp) {
- authname **manp;
- int i;
- if (anp->usercount==0) {
- for(i=0;i<MAXAUTHNAMEEXTS;i++)
- if(anp->exts[i]!=NULL)
- return;
-
- for(manp=&(authnametable[authnamehash(anp->userid)]);*manp;manp=(authname **)&((*manp)->next)) {
- if ((*manp)==anp) {
- (*manp)=(authname *)anp->next;
- freeauthname(anp);
- return;
- }
- }
- Error("nick",ERR_ERROR,"Unable to remove authname %lu from hashtable",anp->userid);
- }
-}
-
unsigned int nexthostmarker() {
int i;
host *hp;
return realnamemarker;
}
-unsigned int nextauthnamemarker() {
- int i;
- authname *anp;
- static unsigned int authnamemarker=0;
-
- authnamemarker++;
- if (!authnamemarker) {
- /* If we wrapped to zero, zap the marker on all records */
- for (i=0;i<AUTHNAMEHASHSIZE;i++)
- for (anp=authnametable[i];anp;anp=anp->next)
- anp->marker=0;
- authnamemarker++;
- }
-
- return authnamemarker;
-}
-
unsigned int nextnickmarker() {
int i;
nick *np;