Просмотр исходного кода

* Auth system rewritten into a class
Uses two hash tables to keep track of users by handle and by host
* Removed check_bind_(pub|msg)c and replaced with check_bind_authc()
* Auth object is passed around instead of nick/host/userrec


svn: 1953

Bryan Drewery 21 лет назад
Родитель
Сommit
b150c05717

+ 215 - 77
src/auth.c

@@ -11,10 +11,12 @@
 #include "main.h"
 #include "settings.h"
 #include "types.h"
+#include "userrec.h"
 #include "core_binds.h"
 #include "egg_timer.h"
 #include "users.h"
 #include "crypt.h"
+#include "hash_table.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -22,6 +24,7 @@
 #include <fcntl.h>
 #include "chan.h"
 #include "tandem.h"
+#include "src/mod/server.mod/server.h"
 #include <pwd.h>
 #include <errno.h>
 
@@ -33,52 +36,232 @@
 
 #include "stat.h"
 
-int auth_total = 0;
-static int max_auth = 50;
-struct auth_t *auth = NULL;
+hash_table_t *Auth::ht_handle = NULL, *Auth::ht_host = NULL;
 
-static void
-expire_auths()
+Auth::Auth(const char *_nick, const char *_host, struct userrec *u)
+{
+  Status(AUTHING);
+  strlcpy(nick, _nick, nick_len + 1);
+  strlcpy(host, _host, UHOSTLEN);
+  if (u) {
+    user = u;
+    strlcpy(handle, u->handle, sizeof(handle));
+  } else {
+    user = NULL;
+    handle[0] = '*';
+    handle[1] = 0;
+  }
+
+  if (!ht_host)
+    ht_host = hash_table_create(NULL, NULL, 50, HASH_TABLE_STRINGS);
+  if (!ht_handle)
+    ht_handle = hash_table_create(NULL, NULL, 50, HASH_TABLE_STRINGS);
+
+  hash_table_insert(ht_host, host, this);
+  if (user)
+    hash_table_insert(ht_handle, handle, this);
+
+  sdprintf("New auth created! (%s!%s) [%s]", nick, host, handle);
+  authtime = atime = now;
+  bd = 0;
+  idx = -1;
+}
+
+Auth::~Auth()
+{
+  sdprintf("Removing auth: (%s!%s) [%s]", nick, host, handle);
+  if (user)
+    hash_table_remove(ht_handle, handle, this);
+  hash_table_remove(ht_host, host, this);
+}
+
+void Auth::MakeHash(bool bd)
+{
+ make_rand_str(rand, 50);
+ if (bd)
+   strlcpy(hash, makebdhash(rand), sizeof hash);
+ else
+   makehash(user, rand, hash, 50);
+}
+
+void Auth::Done(bool _bd)
+{
+  Status(AUTHED);
+  bd = _bd;
+}
+
+Auth *Auth::Find(const char *_host)
+{
+  if (ht_host) {
+    Auth *auth = NULL;
+
+    hash_table_find(ht_host, _host, &auth);
+    if (auth)
+      sdprintf("Found auth: (%s!%s) [%s]", auth->nick, auth->host, auth->handle);
+    return auth;
+  }
+  return NULL;
+}
+Auth *Auth::Find(const char *handle, bool _hand)
+{
+  if (ht_handle) {
+    Auth *auth = NULL;
+
+    hash_table_find(ht_handle, handle, &auth);
+    if (auth)
+      sdprintf("Found auth (by handle): %s (%s!%s)", handle, auth->nick, auth->host);
+    return auth;
+  }
+  return NULL;
+}
+
+static int auth_clear_users_walk(const void *key, void *data, void *param)
+{
+  Auth *auth = *(Auth **)data;
+
+  if (auth->user) {
+    sdprintf("Clearing USER for auth: (%s!%s) [%s]", auth->nick, auth->host, auth->handle);
+    auth->user = NULL;
+  }
+  return 0;
+}
+
+void Auth::NullUsers()
+{
+  hash_table_walk(ht_host, auth_clear_users_walk, NULL);
+}
+
+static int auth_fill_users_walk(const void *key, void *data, void *param)
+{
+  Auth *auth = *(Auth **)data;
+  
+  if (strcmp(auth->handle, "*")) {
+    sdprintf("Filling USER for auth: (%s!%s) [%s]", auth->nick, auth->host, auth->handle);
+    auth->user = get_user_by_handle(userlist, auth->handle);
+  }
+
+  return 0;
+}
+
+void Auth::FillUsers()
+{
+  hash_table_walk(ht_host, auth_fill_users_walk, NULL);
+}
+
+
+static int auth_expire_walk(const void *key, void *data, void *param)
+{
+  Auth *auth = *(Auth **)data;
+
+  if (auth->Authed() && ((now - auth->atime) >= (60 * 60)))
+    delete auth;
+
+  return 0;
+}
+
+void Auth::ExpireAuths()
 {
   if (!ischanhub())
     return;
 
-  time_t idle = 0;
+  hash_table_walk(ht_host, auth_expire_walk, NULL);
+}
+
+static int auth_delete_all_walk(const void *key, void *data, void *param)
+{
+  Auth *auth = *(Auth **)data;
+
+  putlog(LOG_DEBUG, "*", "Removing (%s!%s) [%s], from auth list.", auth->nick, auth->host, auth->handle);
+  delete auth;
+
+  return 0;
+}
+
+void Auth::DeleteAll()
+{
+  if (ischanhub()) {
+    putlog(LOG_DEBUG, "*", "Removing auth entries.");
+    hash_table_walk(ht_host, auth_delete_all_walk, NULL);
+  }
+}
+
+void Auth::InitTimer()
+{
+  timer_create_secs(60, "Auth::ExpireAuths", (Function) Auth::ExpireAuths);
+}
+
+bool Auth::GetIdx(const char *chname)
+{
+  if (idx != -1) {
+    strlcpy(dcc[idx].simulbot, chname ? chname : nick, NICKLEN);
+    strlcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*", 81);
+    return 1;
+  }
+
+  int i = -1;
+
+  for (i = 0; i < dcc_total; i++) {
+    if (dcc[i].type && dcc[i].irc &&
+    (((chname && chname[0]) && !strcmp(dcc[i].simulbot, chname) && !strcmp(dcc[i].nick, handle)) ||
+    (!(chname && chname[0]) && !strcmp(dcc[i].simulbot, nick)))) {
+      putlog(LOG_DEBUG, "*", "Simul found old idx for %s/%s: (%s!%s)", nick, chname, nick, host);
+      dcc[i].simultime = now;
+      idx = i;
+// FIXME: THIS NEEDS TO BE UPDATED FOR CLASS
+//      dcc[idx].auth = authi;
+
+      strlcpy(dcc[idx].simulbot, chname ? chname : nick, NICKLEN);
+      strlcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*", 81);
 
-  for (int i = 0; i < auth_total; i++) {
-    if (auth[i].authed) {
-      idle = now - auth[i].atime;
-      if (idle >= (60 * 60)) {
-        removeauth(i);
-      }
+      return 1;
     }
   }
+
+  if (idx == -1) {
+    idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
+    dcc[idx].sock = serv;
+    dcc[idx].timeval = now;
+    dcc[idx].irc = 1;
+    dcc[idx].simultime = now;
+    dcc[idx].simul = 1;
+    dcc[idx].status = STAT_COLOR;
+    dcc[idx].u.chat->con_flags = 0;
+    strlcpy(dcc[idx].simulbot, chname ? chname : nick, NICKLEN);
+    strlcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*", 81);
+    dcc[idx].u.chat->strip_flags = STRIP_ALL;
+    strlcpy(dcc[idx].nick, handle, NICKLEN);
+    strlcpy(dcc[idx].host, host, UHOSTLEN);
+    dcc[idx].addr = 0L;
+    dcc[idx].user = user ? user : get_user_by_handle(userlist, handle);
+// FIXME: THIS NEEDS TO BE UPDATED FOR CLASS
+//    dcc[idx].auth = authi;
+    return 1;
+  }
+
+  return 0;
 }
 
-void
-init_auth()
+static int auth_tell_walk(const void *key, void *data, void *param)
 {
-  if (max_auth < 1)
-    max_auth = 1;
-  if (auth)
-    auth = (struct auth_t *) my_realloc(auth, sizeof(struct auth_t) * max_auth);
-  else
-    auth = (struct auth_t *) my_calloc(1, sizeof(struct auth_t) * max_auth);
+  Auth *auth = *(Auth **)data;
+  int idx = (int) param;
 
-  timer_create_secs(60, "expire_auths", (Function) expire_auths);
+  dprintf(idx, "%s(%s!%s) [%s] authtime: %li, atime: %li, Status: %d\n", auth->bd ? "x " : "", auth->nick, 
+        auth->host, auth->handle, auth->authtime, auth->atime, auth->Status());
+  
+  return 0;
 }
 
-void makehash(int idx, int authi, char *randstring)
+void Auth::TellAuthed(int idx)
 {
-  char hash[256] = "", *secpass = NULL;
-  struct userrec *u = NULL;
+  hash_table_walk(ht_host, auth_tell_walk, (void *) idx);
+}
 
-  if (idx != -1)
-    u = dcc[idx].user;
-  else if (authi != -1)
-    u = auth[authi].user;
+void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size)
+{
+  char hash[256] = "", *secpass = NULL;
 
-  if (get_user(&USERENTRY_SECPASS, u)) {
+  if (u && get_user(&USERENTRY_SECPASS, u)) {
     secpass = strdup((char *) get_user(&USERENTRY_SECPASS, u));
     secpass[strlen(secpass)] = 0;
   }
@@ -86,11 +269,7 @@ void makehash(int idx, int authi, char *randstring)
   if (secpass)
     free(secpass);
 
-  if (idx != -1) 
-    strlcpy(dcc[idx].hash, MD5(hash), sizeof dcc[idx].hash);
-  else if (authi != -1)
-    strlcpy(auth[authi].hash, MD5(hash), sizeof auth[authi].hash);
-
+  strlcpy(out, MD5(hash), out_size);
   egg_bzero(hash, sizeof(hash));
 }
 
@@ -105,48 +284,7 @@ makebdhash(char *randstring)
   return MD5(hash);
 }
 
-int
-new_auth(void)
-{
-  if (auth_total == max_auth)
-    return -1;
-
-  egg_bzero((struct auth_t *) &auth[auth_total], sizeof(struct auth_t));
-  auth[auth_total].idx = -1;
-  return auth_total++;
-}
-
-/* returns 0 if not found, -1 if problem, and > 0 if found. */
-int
-findauth(char *host)
-{
-  if (!host || !host[0])
-    return -1;
-
-  for (int i = 0; i < auth_total; i++) {
-    if (!auth[i].host) {
-      putlog(LOG_MISC, "*", "AUTH ENTRY: %d HAS NO HOST??", i);
-      continue;
-    }
-    if (auth[i].host && !strcmp(auth[i].host, host)) {
-      return i;
-    }
-  }
-  return -1;
-}
-
-void
-removeauth(int n)
-{
-  putlog(LOG_DEBUG, "*", "Removing %s from auth list.", auth[n].host);
-  auth_total--;
-  if (n < auth_total)
-    egg_memcpy(&auth[n], &auth[auth_total], sizeof(struct auth_t));
-  else
-    egg_bzero(&auth[n], sizeof(struct auth_t)); /* drummer */
-}
-
-void check_auth_dcc(int authi, const char *cmd, const char *par)
+void check_auth_dcc(Auth *auth, const char *cmd, const char *par)
 {
-  real_check_bind_dcc(cmd, auth[authi].idx, par, authi);
+  real_check_bind_dcc(cmd, auth->idx, par, auth);
 }

+ 38 - 13
src/auth.h

@@ -3,31 +3,56 @@
 
 #  include "cfg.h"
 #  include "crypt.h"
+#  include "hash_table.h"
+
+#define AUTHED	    1
+#define AUTHING     2
+/* These are what we are expecting back from the user */
+#define AUTH_PASS   3
+#define AUTH_HASH   4
+#define AUTH_BDHASH 5
+
+class Auth {
+  public:
+  Auth(const char *, const char *, struct userrec * = NULL);
+  ~Auth();
+
+  int Status(int newstat = -1) { if (newstat >= 0) { status = newstat; } return status; }
+  void MakeHash(bool bd = 0);
+  bool Authed() { return (status == AUTHED); }
+  bool GetIdx(const char *);
+  void Done(bool = 0);
+
+  static Auth *Find(const char * host);
+  static Auth *Find(const char * handle, bool _hand);
+  static void NullUsers();
+  static void FillUsers();
+  static void ExpireAuths();
+  static void InitTimer();
+  static void DeleteAll();
+  static void TellAuthed(int);
 
-struct auth_t {
   struct userrec *user;
   time_t authtime;              /* what time they authed at */
   time_t atime;                 /* when they last were active */
-  int authed;
-  int authing;
   int bd;                       /* is this auth a backdoor access? */
   int idx;			/* do they have an associated idx? */
   char hash[MD5_HASH_LENGTH + 1];       /* used for dcc authing */
-  char rand[50];
+  char rand[51];
   char nick[NICKLEN];
-  char hand[NICKLEN];
   char host[UHOSTLEN];
+  char handle[HANDLEN + 1];
+
+  private:
+  int status;
+  static hash_table_t *ht_host;
+  static hash_table_t *ht_handle;
 };
 
-int new_auth();
-int findauth(char *);
-void removeauth(int);
 char *makebdhash(char *);
-void makehash(int, int, char *);
-void init_auth(void);
-void check_auth_dcc(int, const char *, const char *);
-extern int auth_total;
-extern struct auth_t *auth;
+void makehash(struct userrec *u, const char *randstring, char *out, size_t out_size);
+
+void check_auth_dcc(Auth *, const char *, const char *);
 
 #  define authkey CFG_AUTHKEY.ldata ? CFG_AUTHKEY.ldata : CFG_AUTHKEY.gdata ? CFG_AUTHKEY.gdata : ""
 

+ 1 - 0
src/chanprog.c

@@ -592,6 +592,7 @@ void reload()
   checkchans(0);
   if (!readuserfile(userfile, &userlist))
     fatal(MISC_MISSINGUSERF, 0);
+  Auth::FillUsers();
   checkchans(1);
   loading = 0;
   reaffirm_owners();

+ 1 - 1
src/cmds.c

@@ -4270,7 +4270,7 @@ cmd_t C_dcc[] =
   {"who",		"n",	(Function) cmd_who,		NULL, HUB},
   {"whois",		"",	(Function) cmd_whois,		NULL, AUTH},
   {"whom",		"",	(Function) cmd_whom,		NULL, 0},
-  {"whoami",		"",	(Function) cmd_whoami,		NULL, 0},
+  {"whoami",		"",	(Function) cmd_whoami,		NULL, AUTH},
   {"botjump",           "m",    (Function) cmd_botjump,         NULL, 0},
   {"botmsg",		"o",    (Function) cmd_botmsg,          NULL, 0},
   {"netmsg", 		"n", 	(Function) cmd_netmsg, 		NULL, 0},

+ 4 - 3
src/core_binds.c

@@ -8,6 +8,7 @@
 
 #include "common.h"
 #include "dccutil.h"
+#include "auth.h"
 #include "core_binds.h"
 #include "userrec.h"
 #include "main.h"
@@ -39,10 +40,10 @@ void core_binds_init()
 
 void check_bind_dcc(const char *cmd, int idx, const char *text)
 {
-  real_check_bind_dcc(cmd, idx, text, -1);
+  real_check_bind_dcc(cmd, idx, text, NULL);
 }
 
-void real_check_bind_dcc(const char *cmd, int idx, const char *text, int authi)
+void real_check_bind_dcc(const char *cmd, int idx, const char *text, Auth *auth)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   bind_entry_t *entry = NULL;
@@ -89,7 +90,7 @@ void real_check_bind_dcc(const char *cmd, int idx, const char *text, int authi)
     }
   }
 
-  if (entry && authi != -1) {
+  if (entry && auth) {
     if (!(entry->cflags & AUTH))
       return;
   }

+ 3 - 1
src/core_binds.h

@@ -1,10 +1,12 @@
 #ifndef _CORE_BINDS_H_
 #define _CORE_BINDS_H_
 
+#include "auth.h"
+
 void core_binds_init();
 void check_bind_time(struct tm *tm);
 void check_bind_dcc(const char *, int, const char *);
-void real_check_bind_dcc(const char *, int, const char *, int);
+void real_check_bind_dcc(const char *, int, const char *, Auth *);
 void check_bind_bot(const char *, const char *, const char *);
 int check_bind_note(const char *, const char *, const char *);
 void check_bind_nkch(const char *, const char *);

+ 1 - 1
src/dcc.c

@@ -930,7 +930,7 @@ dcc_chat_pass(int idx, char *buf, int atr)
       char randstr[51] = "";
 
       make_rand_str(randstr, 50);
-      makehash(idx, -1, randstr);
+      makehash(dcc[idx].user, randstr, dcc[idx].hash, sizeof(dcc[idx].hash));
 
       dcc[idx].type = &DCC_CHAT_SECPASS;
       dcc[idx].timeval = now;

+ 0 - 53
src/dccutil.c

@@ -856,56 +856,3 @@ valid_idx(int idx)
   return 1;
 }
 
-bool irc_idx(const char *nick, const char *host, const char *handle, const char *chname, int authi)
-{
-  if (authi == -1)
-    return 0;
-
-  if (auth[authi].idx != -1) {
-    strcpy(dcc[auth[authi].idx].simulbot, chname ? chname : nick);
-    strcpy(dcc[auth[authi].idx].u.chat->con_chan, chname ? chname : "*");
-    return 1;
-  }
-
-  int i = -1, idx = -1;
-
-  for (i = 0; i < dcc_total; i++) {
-    if (dcc[i].type && dcc[i].irc &&
-    (((chname && chname[0]) && !strcmp(dcc[i].simulbot, chname) && !strcmp(dcc[i].nick, handle)) ||
-    (!(chname && chname[0]) && !strcmp(dcc[i].simulbot, nick)))) {
-      putlog(LOG_DEBUG, "*", "Simul found old idx for %s/%s: %d", nick, chname, i);
-      dcc[i].simultime = now;
-      auth[authi].idx = i;
-      dcc[idx].auth = authi;
-
-      strcpy(dcc[idx].simulbot, chname ? chname : nick);
-      strcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*");
-
-      return 1;
-    }
-  }
-
-  if (idx == -1) {
-    idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
-    dcc[idx].sock = serv;
-    dcc[idx].timeval = now;
-    dcc[idx].irc = 1;
-    dcc[idx].simultime = now;
-    dcc[idx].simul = 1;
-    dcc[idx].status = STAT_COLOR;
-    dcc[idx].u.chat->con_flags = 0;
-    strcpy(dcc[idx].simulbot, chname ? chname : nick);
-    strcpy(dcc[idx].u.chat->con_chan, chname ? chname : "*");
-    dcc[idx].u.chat->strip_flags = STRIP_ALL;
-    strcpy(dcc[idx].nick, handle);
-    strcpy(dcc[idx].host, host);
-    dcc[idx].addr = 0L;
-    dcc[idx].user = get_user_by_handle(userlist, (char *) handle);
-    auth[authi].idx = idx;
-    dcc[idx].auth = authi;
-    return 1;
-  }
-
-  return 0;
-}
-

+ 1 - 1
src/dccutil.h

@@ -3,6 +3,7 @@
 
 #include "common.h"
 #include "dcc.h"
+#include "auth.h"
 
 #define dprintf dprintf_eggdrop
 
@@ -52,7 +53,6 @@ void identd_open();
 void identd_close();
 port_t listen_all(port_t, bool);
 bool valid_idx(int);
-bool irc_idx(const char *, const char *, const char *, const char *, int);
 extern int		max_dcc;
 extern time_t		connect_timeout;
 

+ 2 - 2
src/hash_table.c

@@ -192,12 +192,12 @@ int hash_table_remove(hash_table_t *ht, const void *key, void *dataptr)
 
 int hash_table_walk(hash_table_t *ht, hash_table_node_func callback, void *param)
 {
+	if (!ht) return(-1);
+
 	hash_table_row_t *row = NULL;
 	hash_table_entry_t *entry = NULL, *next = NULL;
 	int i;
 
-	if (!ht) return(-1);
-
 	for (i = 0; i < ht->max_rows; i++) {
 		row = ht->rows+i;
 		for (entry = row->head; entry;) {

+ 4 - 3
src/main.c

@@ -196,8 +196,9 @@ static void expire_simuls() {
     if (dcc[idx].type && dcc[idx].simul > 0) {
       if ((now - dcc[idx].simultime) >= 100) { /* expire simuls after 100 seconds (re-uses idx, so it wont fill up) */
         dcc[idx].simul = -1;
-        if (dcc[idx].irc)
-          auth[dcc[idx].auth].idx = -1;
+// FIXME: THIS NEEDS TO BE UPDATED FOR CLASS
+//        if (dcc[idx].irc)
+//          auth[dcc[idx].auth].idx = -1;
         lostdcc(idx);
         return;		/* only safe to do one at a time */
       }
@@ -725,7 +726,7 @@ printf("out: %s\n", out);
   init_net();			/* needed for socklist[] */
   init_userent();		/* needed before loading userfile */
   init_party();			/* creates party[] */
-  init_auth();			/* creates auth[] */
+  Auth::InitTimer();
   init_cfg();			/* needed for cfg */
   init_botcmd();
   init_responses();		/* zeros out response[] */

+ 6 - 6
src/mod/irc.mod/chan.c

@@ -2876,7 +2876,7 @@ static int gotmsg(char *from, char *msg)
     }
   }
   if (msg[0]) {
-    int botmatch = 0, i = 0;
+    int botmatch = 0;
     char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
 
     /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
@@ -2894,13 +2894,13 @@ static int gotmsg(char *from, char *msg)
       fword = newsplit(&my_msg);	/* now this will be the command */
     /* is it a cmd? */
     if (fword && fword[0] && fword[1] && ((botmatch && fword[0] != cmdprefix) || (fword[0] == cmdprefix))) {
-      i = findauth(uhost);
-      if (i > -1 && auth[i].authed) {
+      Auth *auth = Auth::Find(uhost);
+
+      if (auth && auth->Authed()) {
         if (fword[0] == cmdprefix)
           fword++;
-        if (check_bind_pubc(fword, nick, uhost, auth[i].user, my_msg, chan->dname)) {
-          auth[i].atime = now;
-        }
+        auth->atime = now;
+        check_bind_authc(fword, auth, chan->dname, my_msg);
       }
     }
     free(my_ptr);

+ 1 - 4
src/mod/irc.mod/cmdsirc.c

@@ -1251,10 +1251,7 @@ static void cmd_authed(int idx, char *par)
   putlog(LOG_CMDS, "*", "#%s# authed", dcc[idx].nick);
 
   dprintf(idx, "Authed:\n");
-  for (int i = 0; i < auth_total; i++) {
-   if (auth[i].authed)
-     dprintf(idx, " %d%s. %s!%s at %li\n", i, auth[i].bd ? "x" : "", auth[i].nick, auth[i].host, auth[i].authtime);
-  }
+  Auth::TellAuthed(idx);
 }
 
 static void cmd_channel(int idx, char *par)

+ 13 - 7
src/mod/irc.mod/irc.c

@@ -1401,18 +1401,24 @@ irc_minutely()
   }
 }
 
-static int
-check_bind_pubc(char *cmd, char *nick, char *from, struct userrec *u, char *args, char *chname)
+
+int check_bind_authc(char *cmd, Auth *auth, char *chname, char *args)
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
   int x = 0;
 
-  get_user_flagrec(u, &fr, chname);
-  x = check_bind(BT_msgc, cmd, &fr, nick, from, u, chname, args);
+  get_user_flagrec(auth->user, &fr, chname);
+  x = check_bind(BT_msgc, cmd, &fr, auth, chname, args);
+
+
+  if (x & BIND_RET_LOG) {
+    if (chname)
+      putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", auth->nick, auth->host, 
+                            auth->handle, chname, cmdprefix, cmd, args);
+    else
+      putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", auth->nick, auth->host, auth->handle, cmdprefix, cmd, args);
+  }
 
-  if (x & BIND_RET_LOG)
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", nick, from, u ? u->handle : "*", chname, cmdprefix, cmd,
-           args);
   if (x & BIND_RET_BREAK)
     return (1);
   return (0);

+ 3 - 1
src/mod/irc.mod/irc.h

@@ -6,6 +6,8 @@
 #ifndef _EGG_MOD_IRC_IRC_H
 #define _EGG_MOD_IRC_IRC_H
 
+#include "src/auth.h"
+
 enum { BC_NOCOOKIE = 1, BC_SLACK, BC_HASH };
 
 #define REVENGE_KICK 1		/* Kicked victim	*/
@@ -56,7 +58,6 @@ static void cache_debug(void);
 #endif /* CACHE */
 static void cache_invite(struct chanset_t *, char *, char *, char *, bool, bool);
 
-static int check_bind_pubc(char *, char *, char *, struct userrec *, char *, char *);
 static char *makecookie(char *, char *);
 static int checkcookie(char *, char *, char *);
 static bool me_voice(struct chanset_t *);
@@ -93,6 +94,7 @@ static int gotmode(char *, char *);
 
 #endif /* MAKING_IRC */
 
+int check_bind_authc(char *, Auth *, char *, char *);
 void notice_invite(struct chanset_t *, char *, char *, char *, bool);
 void real_add_mode(struct chanset_t *, const char, const char, const char *, bool);
 #define add_mode(chan, pls, mode, nick) real_add_mode(chan, pls, mode, nick, 0)

+ 90 - 146
src/mod/irc.mod/msgcmds.c

@@ -209,19 +209,17 @@ static void reply(char *nick, struct chanset_t *chan, char *format, ...)
     dprintf(DP_HELP, "NOTICE %s :%s", nick, buf);
 }
 
-static void logc(const char *cmd, char *nick, char *host, char *hand, char *chname, char *par)
+static void logc(const char *cmd, Auth *a, char *chname, char *par)
 {
   if (chname && chname[0])
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", nick, host, hand, chname, cmdprefix, cmd, par ? par : "");
+    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", a->nick, a->host, a->handle, chname, cmdprefix, cmd, par ? par : "");
   else
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", nick, host, hand, cmdprefix, cmd, par ? par : "");
+    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", a->nick, a->host, a->handle, cmdprefix, cmd, par ? par : "");
 }
-#define LOGC(cmd) logc(cmd, nick, host, u->handle, chname, par)
-
+#define LOGC(cmd) logc(cmd, a, chname, par)
+  
 static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
 {
-  int i = 0;
-
   if (!u) 
     return 0;
   if (match_my_nick(nick))
@@ -229,84 +227,63 @@ static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
   if (u && u->bot)
     return BIND_RET_BREAK;
 
-  i = findauth(host);
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! AUTH?", nick, host, u->handle);
 
-  if (i != -1) {
-    if (auth[i].authed) {
+  Auth *auth = Auth::Find(host);
+
+  if (auth) {
+    if (auth->Authed()) {
       dprintf(DP_HELP, "NOTICE %s :You are already authed.\n", nick);
       return 0;
     }
-  }
+  } else
+    auth = new Auth(nick, host, u);
 
   /* Send "auth." if they are recognized, otherwise "auth!" */
-  if (i < 0)
-    i = new_auth();
-  auth[i].authing = 1;
-  auth[i].authed = 0;
-  strcpy(auth[i].nick, nick);
-  strcpy(auth[i].host, host);
-  if (u) {
-    auth[i].user = u;
-    strcpy(auth[i].hand, u->handle);
-  }
-
+  auth->Status(AUTH_PASS);
   dprintf(DP_HELP, "PRIVMSG %s :auth%s %s\n", nick, u ? "." : "!", conf.bot->nick);
 
   return BIND_RET_BREAK;
 }
 
 static void
-addauth(int i, char *nick, char *host)
+AuthFinish(Auth *auth)
 {
-  putlog(LOG_CMDS, "*", "(%s!%s) !%s! +AUTH", nick, host, auth[i].user->handle);
-  auth[i].authed = 1;
-  auth[i].authing = 0;
-  auth[i].authtime = now;
-  auth[i].atime = now;
-  strcpy(auth[i].nick, nick);
-  strcpy(auth[i].host, host);
-  dprintf(DP_HELP, "NOTICE %s :You are now authorized for cmds, see %chelp\n", nick, cmdprefix);
+  putlog(LOG_CMDS, "*", "(%s!%s) !%s! +AUTH", auth->nick, auth->host, auth->handle);
+  auth->Done();
+  dprintf(DP_HELP, "NOTICE %s :You are now authorized for cmds, see %chelp\n", auth->nick, cmdprefix);
 }
 
 static int msg_auth(char *nick, char *host, struct userrec *u, char *par)
-{
+{ 
   char *pass = NULL;
-  int i = 0;
 
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
   if (u && u->bot)
     return BIND_RET_BREAK;
 
-  i = findauth(host);
+  Auth *auth = Auth::Find(host);
 
-  if (i == -1) 
-    return BIND_RET_BREAK;
-
-  if (auth[i].authing != 1) 
+  if (!auth || auth->Status() != AUTH_PASS)
     return BIND_RET_BREAK;
 
   pass = newsplit(&par);
 
   if (u_pass_match(u, pass) && !u_pass_match(u, "-")) {
-    auth[i].user = u;
-    strcpy(auth[i].hand, u->handle);
+    auth->user = u;
     if (strlen(authkey) && get_user(&USERENTRY_SECPASS, u)) {
       putlog(LOG_CMDS, "*", "(%s!%s) !%s! AUTH", nick, host, u->handle);
-
-      auth[i].authing = 2;      
-      make_rand_str(auth[i].rand, 50);
-      makehash(-1, i, auth[i].rand);
-
-      dprintf(DP_HELP, "PRIVMSG %s :-Auth %s %s\n", nick, auth[i].rand, conf.bot->nick);
+      auth->Status(AUTH_HASH);
+      auth->MakeHash();
+      dprintf(DP_HELP, "PRIVMSG %s :-Auth %s %s\n", nick, auth->rand, conf.bot->nick);
     } else {
       /* no authkey and/or no SECPASS for the user, don't require a hash auth */
-      addauth(i, nick, host);
+      AuthFinish(auth);
     }
   } else {
     putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed AUTH", nick, host, u->handle);
-    removeauth(i);
+    delete auth;
   }
   return BIND_RET_BREAK;
 
@@ -315,23 +292,18 @@ static int msg_auth(char *nick, char *host, struct userrec *u, char *par)
 static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
 {
   if (strlen(authkey) && get_user(&USERENTRY_SECPASS, u)) {
-    int i = 0;
-
     if (match_my_nick(nick))
       return BIND_RET_BREAK;
     if (u && u->bot)
       return BIND_RET_BREAK;
 
-    i = findauth(host);
+    Auth *auth = Auth::Find(host);
 
-    if (i == -1)
+    if (!auth || auth->Status() != AUTH_HASH)
       return BIND_RET_BREAK;
 
-    if (auth[i].authing != 2)
-      return BIND_RET_BREAK;
-    
-    if (check_master_hash(auth[i].rand, par) || !strcmp(auth[i].hash, par)) { /* good hash! */
-      addauth(i, nick, host);
+    if (check_master_hash(auth->rand, par) || !strcmp(auth->hash, par)) { /* good hash! */
+      AuthFinish(auth);
     } else { /* bad hash! */
       char s[300] = "";
 
@@ -339,7 +311,7 @@ static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
       dprintf(DP_HELP, "NOTICE %s :Invalid hash.\n", nick);
       sprintf(s, "*!%s", host);
       addignore(s, origbotname, "Invalid auth hash.", now + (60 * ignore_time));
-      removeauth(i);
+      delete auth;
     } 
     return BIND_RET_BREAK;
   }
@@ -348,94 +320,69 @@ static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
 
 static int msg_unauth(char *nick, char *host, struct userrec *u, char *par)
 {
-  int i = 0;
-
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
   if (u && u->bot)
     return BIND_RET_BREAK;
 
-  i = findauth(host);
+  Auth *auth = Auth::Find(host);
 
-  if (i == -1)
+  if (!auth)
     return BIND_RET_BREAK;
 
-  removeauth(i);
+  delete auth;
   dprintf(DP_HELP, "NOTICE %s :You are now unauthorized.\n", nick);
   putlog(LOG_CMDS, "*", "(%s!%s) !%s! UNAUTH", nick, host, u->handle);
 
   return BIND_RET_BREAK;
 }
 
-
 static int msg_bd(char *nick, char *host, struct userrec *u, char *par)
 {
-  int i = 0;
-
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
 
-  i = findauth(host);
-  /* putlog(LOG_CMDS, "*", "(%s!%s) !%s! BD?", nick, host, u->handle); */
+  Auth *auth = Auth::Find(host);
 
-  if (i != -1) {
-    if (auth[i].authed) {
-      if (!auth[i].bd)
+  if (auth) {
+    if (auth->Authed()) {
+      if (!auth->bd)
         dprintf(DP_HELP, "NOTICE %s :You are already authed, unauth and start over.\n", nick);
       else
         dprintf(DP_HELP, "NOTICE %s :You are already authed for backdoor.\n", nick);
       return 0;
     }
-  }
+  } else
+    auth = new Auth(nick, host, u);
 
   /* Send "auth." if they are recognized, otherwise "auth!" */
-  if (i < 0)
-    i = new_auth();
-  auth[i].authing = 2;
-  auth[i].authed = 0;
-  strcpy(auth[i].nick, nick);
-  strcpy(auth[i].host, host);
-  if (u) {
-    auth[i].user = u;
-    strcpy(auth[i].hand, u->handle);
-  }
-  make_rand_str(auth[i].rand, 50);
-  strlcpy(auth[i].hash, makebdhash(auth[i].rand), sizeof auth[i].hash);
-  dprintf(DP_HELP, "PRIVMSG %s :-BD %s %s\n", nick, auth[i].rand, conf.bot->nick);
+  auth->Status(AUTH_BDHASH);
+  auth->MakeHash(1);
+
+  dprintf(DP_HELP, "PRIVMSG %s :-BD %s %s\n", nick, auth->rand, conf.bot->nick);
 
   return BIND_RET_BREAK;
 }
 
 static int msg_pls_bd(char *nick, char *host, struct userrec *u, char *par)
 {
-
-  int i = 0;
-
   if (match_my_nick(nick))
     return BIND_RET_BREAK;
   if (u && u->bot)
     return BIND_RET_BREAK;
 
-  i = findauth(host);
+  Auth *auth = Auth::Find(host);
 
-  if (i == -1)
+  if (!auth || auth->Status() != AUTH_BDHASH)
     return BIND_RET_BREAK;
 
-  if (auth[i].authing != 2)
-    return BIND_RET_BREAK;
-
-  if (check_master_hash(auth[i].rand, par) || !strcmp(auth[i].hash, par)) { /* good hash! */
+  if (check_master_hash(auth->rand, par) || !strcmp(auth->hash, par)) { /* good hash! */
     /* putlog(LOG_CMDS, "*", "(%s!%s) !%s! +AUTH", nick, host, u->handle); */
-    auth[i].authed = 1;
-    auth[i].bd = 1;		/* the magic int ! */
-    auth[i].authing = 0;
-    auth[i].authtime = now;
-    auth[i].atime = now;
+    auth->Done(1);
     dprintf(DP_HELP, "NOTICE %s :You are now authorized for the backdoor. See '%cbd help'\n", nick, cmdprefix);
   } else { /* bad hash! */
-    /* putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed +AUTH", nick, host, u->handle); */
     dprintf(DP_HELP, "NOTICE %s :Invalid hash.\n", nick);
-    removeauth(i);
+    delete auth;
   } 
   return BIND_RET_BREAK;
 }
@@ -464,25 +411,22 @@ static cmd_t C_msg[] =
   {NULL,		NULL,	NULL,				NULL, 0}
 };
 
-static int msgc_test(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_test(Auth *a, char *chname, char *par)
 {
   char *cmd = NULL;
-  int i = 0;
 
   LOGC("TEST");
 
   cmd = newsplit(&par);
 
-  i = findauth(host);
-
-  if (irc_idx(nick, host, u->handle, chname, i)) {
-    check_auth_dcc(i, cmd, par);
+  if (a->GetIdx(chname)) {
+    check_auth_dcc(a, cmd, par);
   }
 
   return BIND_RET_BREAK;
 }
 
-static int msgc_op(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_op(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -492,7 +436,7 @@ static int msgc_op(char *nick, char *host, struct userrec *u, char *chname, char
   if (chname && chname[0]) {
     chan = findchan_by_dname(chname);
     if (chan) 
-      m = ismember(chan, nick);
+      m = ismember(chan, a->nick);
   }
 
   LOGC("OP");
@@ -505,7 +449,7 @@ static int msgc_op(char *nick, char *host, struct userrec *u, char *chname, char
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 
       force = 1;
     else {
-      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", nick, tmp);
+      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
       return 0;
     }
   }
@@ -513,26 +457,26 @@ static int msgc_op(char *nick, char *host, struct userrec *u, char *chname, char
     if (!chan)
       chan = findchan_by_dname(par);
     if (chan && channel_active(chan)) {
-      get_user_flagrec(u, &fr, chan->dname);
+      get_user_flagrec(a->user, &fr, chan->dname);
       if (chk_op(fr, chan)) {
-        if (do_op(nick, chan, 0, force))
-          stats_add(u, 0, 1);
+        if (do_op(a->nick, chan, 0, force))
+          stats_add(a->user, 0, 1);
       }
       return BIND_RET_BREAK;
     }
   } else {
     for (chan = chanset; chan; chan = chan->next) {
-      get_user_flagrec(u, &fr, chan->dname);
+      get_user_flagrec(a->user, &fr, chan->dname);
       if (chk_op(fr, chan)) {
-       if (do_op(nick, chan, 0, force))
-         stats_add(u, 0, 1);
+       if (do_op(a->nick, chan, 0, force))
+         stats_add(a->user, 0, 1);
       }
     }
   }
   return BIND_RET_BREAK;
 }
 
-static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_voice(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -542,7 +486,7 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, c
   if (chname && chname[0]) {
     chan = findchan_by_dname(chname);
     if (chan) 
-      m = ismember(chan, nick);
+      m = ismember(chan, a->nick);
   }
   LOGC("VOICE");
 
@@ -554,7 +498,7 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, c
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 
       force = 1;
     else {
-      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", nick, tmp);
+      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
       return 0;
     }
   }
@@ -562,24 +506,24 @@ static int msgc_voice(char *nick, char *host, struct userrec *u, char *chname, c
     if (!chan)
       chan = findchan_by_dname(par);
     if (chan && channel_active(chan)) {
-      get_user_flagrec(u, &fr, chan->dname);
+      get_user_flagrec(a->user, &fr, chan->dname);
       if (!chk_devoice(fr)) {		/* dont voice +q */
-        add_mode(chan, '+', 'v', nick);
+        add_mode(chan, '+', 'v', a->nick);
       }
       return BIND_RET_BREAK;
     }
   } else {
     for (chan = chanset; chan; chan = chan->next) {
-      get_user_flagrec(u, &fr, chan->dname);
+      get_user_flagrec(a->user, &fr, chan->dname);
       if (!chk_devoice(fr)) {		/* dont voice +q */
-        add_mode(chan, '+', 'v', nick);
+        add_mode(chan, '+', 'v', a->nick);
       }
     }
   }
   return BIND_RET_BREAK;
 }
 
-static int msgc_channels(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_channels(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -587,7 +531,7 @@ static int msgc_channels(char *nick, char *host, struct userrec *u, char *chname
 
   LOGC("CHANNELS");
   for (chan = chanset; chan; chan = chan->next) {
-    get_user_flagrec(u, &fr, chan->dname);
+    get_user_flagrec(a->user, &fr, chan->dname);
     if (chk_op(fr, chan)) {
       if (me_op(chan)) 
         strcat(list, "@");
@@ -597,14 +541,14 @@ static int msgc_channels(char *nick, char *host, struct userrec *u, char *chname
   }
 
   if (list[0]) 
-    reply(nick, NULL, "You have access to: %s\n", list);
+    reply(a->nick, NULL, "You have access to: %s\n", list);
   else
-    reply(nick, NULL, "You do not have access to any channels.\n");
+    reply(a->nick, NULL, "You do not have access to any channels.\n");
 
   return BIND_RET_BREAK;
 }
 
-static int msgc_getkey(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_getkey(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -618,27 +562,27 @@ static int msgc_getkey(char *nick, char *host, struct userrec *u, char *chname,
   LOGC("GETKEY");
   chan = findchan_by_dname(par);
   if (chan && channel_active(chan) && !channel_pending(chan)) {
-    get_user_flagrec(u, &fr, chan->dname);
+    get_user_flagrec(a->user, &fr, chan->dname);
     if (chk_op(fr, chan)) {
       if (chan->channel.key[0]) {
-        reply(nick, NULL, "Key for %s is: %s\n", chan->name, chan->channel.key);
+        reply(a->nick, NULL, "Key for %s is: %s\n", chan->name, chan->channel.key);
       } else {
-        reply(nick, NULL, "%s has no key set.\n", chan->name);
+        reply(a->nick, NULL, "%s has no key set.\n", chan->name);
       }
     }
   }
   return BIND_RET_BREAK;
 }
 
-static int msgc_help(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_help(Auth *a, char *chname, char *par)
 {
   LOGC("HELP");
 
-  reply(nick, NULL, "op invite getkey voice test\n");
+  reply(a->nick, NULL, "op invite getkey voice test\n");
   return BIND_RET_BREAK;
 }
 
-static int msgc_md5(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_md5(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
 
@@ -646,11 +590,11 @@ static int msgc_md5(char *nick, char *host, struct userrec *u, char *chname, cha
   if (chname && chname[0])
     chan = findchan_by_dname(chname);  
 
-  reply(nick, chan, "MD5(%s) = %s\n", par, MD5(par));
+  reply(a->nick, chan, "MD5(%s) = %s\n", par, MD5(par));
   return BIND_RET_BREAK;
 }
 
-static int msgc_sha1(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_sha1(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
 
@@ -659,11 +603,11 @@ static int msgc_sha1(char *nick, char *host, struct userrec *u, char *chname, ch
   if (chname && chname[0])
     chan = findchan_by_dname(chname);  
 
-  reply(nick, chan, "SHA1(%s) = %s\n", par, SHA1(par));
+  reply(a->nick, chan, "SHA1(%s) = %s\n", par, SHA1(par));
   return BIND_RET_BREAK;
 }
 
-static int msgc_invite(char *nick, char *host, struct userrec *u, char *chname, char *par)
+static int msgc_invite(Auth *a, char *chname, char *par)
 {
   struct chanset_t *chan = NULL;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
@@ -681,29 +625,29 @@ static int msgc_invite(char *nick, char *host, struct userrec *u, char *chname,
     if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f")) 
       force = 1;
     else {
-      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", nick, tmp);
+      dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
       return 0;
     }
   }
 
   if (par[0] && (!chname || (chname && !chname[0]))) {
     chan = findchan_by_dname(par);
-    if (chan && channel_active(chan) && !ismember(chan, nick)) {
+    if (chan && channel_active(chan) && !ismember(chan, a->nick)) {
       if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
-        get_user_flagrec(u, &fr, chan->dname);
+        get_user_flagrec(a->user, &fr, chan->dname);
         if (chk_op(fr, chan)) {
-          cache_invite(chan, nick, host, u->handle, 0, 0);
+          cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
         }
         return BIND_RET_BREAK;
       }
     }
   } else {
     for (chan = chanset; chan; chan = chan->next) {
-      if (channel_active(chan) && !ismember(chan, nick)) {
+      if (channel_active(chan) && !ismember(chan, a->nick)) {
         if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
-          get_user_flagrec(u, &fr, chan->dname);
+          get_user_flagrec(a->user, &fr, chan->dname);
           if (chk_op(fr, chan)) {
-            cache_invite(chan, nick, host, u->handle, 0, 0);
+            cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
           }
         }
       }
@@ -714,7 +658,7 @@ static int msgc_invite(char *nick, char *host, struct userrec *u, char *chname,
 
 static cmd_t C_msgc[] =
 {
-//  {"test",		"a",	(Function) msgc_test,		NULL, LEAF},
+  {"test",		"a",	(Function) msgc_test,		NULL, LEAF},
   {"channels",		"",	(Function) msgc_channels,	NULL, LEAF},
   {"getkey",		"",	(Function) msgc_getkey,		NULL, LEAF},
   {"help",		"",	(Function) msgc_help,		NULL, LEAF},

+ 1 - 1
src/mod/server.mod/server.c

@@ -1029,7 +1029,7 @@ void server_init()
    * globally.
    */
 
-  BT_msgc = bind_table_add("msgc", 5, "ssUss", MATCH_FLAGS, 0); 
+  BT_msgc = bind_table_add("msgc", 3, "Ass", MATCH_FLAGS, 0); // Auth, chname, par
   BT_msg = bind_table_add("msg", 4, "ssUs", MATCH_FLAGS, 0);
   BT_raw = bind_table_add("raw", 2, "ss", 0, BIND_STACKABLE);
   BT_ctcr = bind_table_add("ctcr", 6, "ssUsss", 0, BIND_STACKABLE);

+ 35 - 61
src/mod/server.mod/servmsg.c

@@ -111,21 +111,6 @@ static void check_bind_msg(char *cmd, char *nick, char *uhost, struct userrec *u
     putlog(LOG_MSGS, "*", "[%s!%s] %s %s", nick, uhost, cmd, args);
 }
 
-static int check_bind_msgc(char *cmd, char *nick, char *from, struct userrec *u, char *args)
-{
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
-  int x = 0;
-
-  get_user_flagrec(u, &fr, NULL);
-  x = check_bind(BT_msgc, cmd, &fr, nick, from, u, NULL, args);
-
-  if (x & BIND_RET_LOG)
-    putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", nick, from, u ? u->handle : "*", cmdprefix, cmd, args);
-
-  if (x & BIND_RET_BREAK) return(1);
-  return(0);
-}
-
 /* Return 1 if processed.
  */
 static int check_bind_raw(char *from, char *code, char *msg)
@@ -322,9 +307,6 @@ static bool detect_flood(char *floodnick, char *floodhost, char *from, int which
   if ((u && u->bot) || (atr & USER_NOFLOOD))
     return 0;
 
-  if (findauth(floodhost) > -1) 
-    return 0;
-
   char *p = NULL, ftype[10] = "", h[1024] = "";
   int thr = 0;
   time_t lapse = 0;
@@ -410,7 +392,7 @@ static int gotmsg(char *from, char *msg)
   char *to = NULL, buf[UHOSTLEN] = "", *nick = NULL, ctcpbuf[512] = "", *uhost = buf, 
        *ctcp = NULL, *p = NULL, *p1 = NULL, *code = NULL;
   struct userrec *u = NULL;
-  int ctcp_count = 0, i = 0;
+  int ctcp_count = 0;
   bool ignoring = match_ignore(from);
 
   to = newsplit(&msg);
@@ -530,51 +512,47 @@ static int gotmsg(char *from, char *msg)
       }
     } else {
       char *my_code = NULL;
-      struct userrec *my_u = NULL;
+      Auth *auth = Auth::Find(uhost);
 
-      detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
-      my_u = get_user_by_host(from);
+      if (!auth)
+        detect_flood(nick, uhost, from, FLOOD_PRIVMSG);
       my_code = newsplit(&msg);
       rmspace(msg);
-      i = findauth(uhost);
       /* is it a cmd? */
 
-      if (my_code && my_code[0] && my_code[1] && i > -1 && auth[i].authed && my_code[0] == cmdprefix) {
-        my_code++;
-        my_u = auth[i].user;
+      if (my_code && my_code[0] && my_code[1] && auth && auth->Authed() && my_code[0] == cmdprefix) {
+        my_code++;		//eliminate the cmdprefix
+        auth->atime = now;
 
-        if (check_bind_msgc(my_code, nick, uhost, my_u, msg))
-          auth[i].atime = now;
-        else
+        if (!check_bind_authc(my_code, auth, NULL, msg))
           putlog(LOG_MSGS, "*", "[%s] %c%s %s", from, cmdprefix, my_code, msg);
-      } else if ((my_code[0] != cmdprefix || !my_code[1] || i == -1 || !(auth[i].authed))) {
-        if (!ignoring) {
-          bool doit = 1;
-
-          if (!egg_strcasecmp(my_code, "op") || !egg_strcasecmp(my_code, "pass") || !egg_strcasecmp(my_code, "invite") 
-              || !egg_strcasecmp(my_code, "ident")
-               || !egg_strcasecmp(my_code, msgop) || !egg_strcasecmp(my_code, msgpass) 
-               || !egg_strcasecmp(my_code, msginvite) || !egg_strcasecmp(my_code, msgident)) {
-            char buf2[10] = "";
-
-            doit = 0;
-            if (!egg_strcasecmp(my_code, msgop))
-              sprintf(buf2, "op");
-            else if (!egg_strcasecmp(my_code, msgpass))
-              sprintf(buf2, "pass");
-            else if (!egg_strcasecmp(my_code, msginvite))
-              sprintf(buf2, "invite");
-            else if (!egg_strcasecmp(my_code, msgident))
-              sprintf(buf2, "ident");
-
-            if (buf2[0])
-              check_bind_msg(buf2, nick, uhost, my_u, msg);
-            else
-              putlog(LOG_MSGS, "*", "(%s!%s) attempted to use invalid msg cmd '%s'", nick, uhost, my_code);
-          }
-          if (doit)
-            check_bind_msg(my_code, nick, uhost, my_u, msg);
+      } else if (!ignoring && (my_code[0] != cmdprefix || !my_code[1] || !auth || !auth->Authed())) {
+        struct userrec *my_u = get_user_by_host(from);
+        bool doit = 1;
+
+        if (!egg_strcasecmp(my_code, "op") || !egg_strcasecmp(my_code, "pass") || !egg_strcasecmp(my_code, "invite") 
+            || !egg_strcasecmp(my_code, "ident")
+            || !egg_strcasecmp(my_code, msgop) || !egg_strcasecmp(my_code, msgpass) 
+            || !egg_strcasecmp(my_code, msginvite) || !egg_strcasecmp(my_code, msgident)) {
+          char buf2[10] = "";
+
+          doit = 0;
+          if (!egg_strcasecmp(my_code, msgop))
+            sprintf(buf2, "op");
+          else if (!egg_strcasecmp(my_code, msgpass))
+            sprintf(buf2, "pass");
+          else if (!egg_strcasecmp(my_code, msginvite))
+            sprintf(buf2, "invite");
+          else if (!egg_strcasecmp(my_code, msgident))
+            sprintf(buf2, "ident");
+
+          if (buf2[0])
+            check_bind_msg(buf2, nick, uhost, my_u, msg);
+          else
+            putlog(LOG_MSGS, "*", "(%s!%s) attempted to use invalid msg cmd '%s'", nick, uhost, my_code);
         }
+        if (doit)
+          check_bind_msg(my_code, nick, uhost, my_u, msg);
       }
     }
   }
@@ -943,6 +921,7 @@ static void disconnect_server(int idx, int dolost)
   floodless = 0;
   botuserhost[0] = 0;
   if (dolost) {
+    Auth::DeleteAll();
     trying_server = 0;
     lostdcc(idx);
   }
@@ -951,11 +930,6 @@ static void disconnect_server(int idx, int dolost)
 static void eof_server(int idx)
 {
   putlog(LOG_SERV, "*", "Disconnected from %s", dcc[idx].host);
-  if (ischanhub() && auth_total > 0) {
-    putlog(LOG_DEBUG, "*", "Removing %d auth entries.", auth_total);
-    for (int i = 0; i < auth_total; i++)
-      removeauth(i);  
-  }
   disconnect_server(idx, DO_LOST);
 }
 

+ 4 - 8
src/mod/share.mod/share.c

@@ -1120,8 +1120,7 @@ finish_share(int idx)
   for (i = 0; i < dcc_total; i++)
     if (dcc[i].type)
       dcc[i].user = NULL;
-  for (i = 0; i < auth_total; i++)
-    auth[i].user = NULL;
+  Auth::NullUsers();
 
   if (conf.bot->u)
     conf.bot->u = NULL;
@@ -1144,15 +1143,14 @@ finish_share(int idx)
     for (i = 0; i < dcc_total; i++)
       if (dcc[i].type)
         dcc[i].user = get_user_by_handle(ou, dcc[i].nick);
-    for (i = 0; i < auth_total; i++)
-      if (auth[i].hand[0])
-        auth[i].user = get_user_by_handle(ou, auth[i].hand);
 
     conf.bot->u = get_user_by_handle(ou, conf.bot->nick);
 
     userlist = ou;              /* Revert to old user list.             */
     lastuser = NULL;            /* Reset last accessed user ptr.        */
 
+    Auth::FillUsers();
+
     checkchans(2);              /* un-flag the channels, we are keeping them.. */
 
     /* old userlist is now being used, safe to do this stuff... */
@@ -1186,9 +1184,7 @@ finish_share(int idx)
   clear_userlist(ou);
 
   /* copy over any auth users */
-  for (i = 0; i < auth_total; i++)
-    if (auth[i].hand[0])
-      auth[i].user = get_user_by_handle(userlist, auth[i].hand);
+  Auth::FillUsers();
 
   checkchans(1);                /* remove marked channels */
   trigger_cfg_changed();