Avoid crashing when a user is killed by an on-auth callback.
[srvx.git] / src / nickserv.c
index 024364f25f70880c7d4ad5edd49c53316425214e..0ba125e5bfd8658657383b308111f0ef880e2556 100644 (file)
@@ -917,11 +917,14 @@ set_user_handle_info(struct userNode *user, struct handle_info *hi, int stamp)
         /* remove from next_authed linked list */
         if (user->handle_info->users == user) {
             user->handle_info->users = user->next_authed;
-        } else {
+        } else if (user->handle_info->users != NULL) {
             for (other = user->handle_info->users;
                  other->next_authed != user;
                  other = other->next_authed) ;
             other->next_authed = user->next_authed;
+        } else {
+            /* No users authed to the account - can happen if they get
+             * killed for authing. */
         }
         /* if nobody left on old handle, and they're not an oper, remove !god */
         if (!user->handle_info->users && !user->handle_info->opserv_level)
@@ -935,8 +938,11 @@ set_user_handle_info(struct userNode *user, struct handle_info *hi, int stamp)
     user->handle_info = hi;
     if (hi && !hi->users && !hi->opserv_level)
         HANDLE_CLEAR_FLAG(hi, HELPING);
-    for (n=0; (n<auth_func_used) && !user->dead; n++)
+    for (n=0; n<auth_func_used; n++) {
         auth_func_list[n](user, old_info);
+        if (user->dead)
+            return;
+    }
     if (hi) {
         struct nick_info *ni;
 
@@ -957,9 +963,9 @@ set_user_handle_info(struct userNode *user, struct handle_info *hi, int stamp)
 
         if (stamp) {
             if (!nickserv_conf.disable_nicks) {
-                struct nick_info *ni;
-                for (ni = hi->nicks; ni; ni = ni->next) {
-                    if (!irccasecmp(user->nick, ni->nick)) {
+                struct nick_info *ni2;
+                for (ni2 = hi->nicks; ni2; ni2 = ni2->next) {
+                    if (!irccasecmp(user->nick, ni2->nick)) {
                         user->modes |= FLAGS_REGNICK;
                         break;
                     }
@@ -1458,20 +1464,20 @@ static NICKSERV_FUNC(cmd_handleinfo)
     }
 
     if (hi->channels) {
-        struct userData *channel, *next;
+        struct userData *chan, *next;
         char *name;
 
-        for (channel = hi->channels; channel; channel = next) {
-            next = channel->u_next;
-            name = channel->channel->channel->name;
+        for (chan = hi->channels; chan; chan = next) {
+            next = chan->u_next;
+            name = chan->channel->channel->name;
             herelen = strlen(name);
             if (pos + herelen + 7 > ArrayLength(buff)) {
-                next = channel;
+                next = chan;
                 goto print_chans_buff;
             }
-            if (IsUserSuspended(channel))
+            if (IsUserSuspended(chan))
                 buff[pos++] = '-';
-            pos += sprintf(buff+pos, "%d:%s ", channel->access, name);
+            pos += sprintf(buff+pos, "%d:%s ", chan->access, name);
             if (next == NULL) {
               print_chans_buff:
                 buff[pos-1] = 0;
@@ -2171,14 +2177,10 @@ nickserv_apply_flags(struct userNode *user, struct handle_info *hi, const char *
         struct channelList *schannels;
         unsigned int ii;
         schannels = chanserv_support_channels();
-        for (uNode = hi->users; uNode; uNode = uNode->next_authed) {
-            for (ii = 0; ii < schannels->used; ++ii)
-                if (GetUserMode(schannels->list[ii], uNode))
-                    break;
-            if (ii < schannels->used)
+        for (ii = 0; ii < schannels->used; ++ii)
+            if (find_handle_in_channel(schannels->list[ii], hi, NULL))
                 break;
-        }
-        if (!uNode)
+        if (ii == schannels->used)
             HANDLE_CLEAR_FLAG(hi, HELPING);
     }
 
@@ -3470,7 +3472,6 @@ static MODCMD_FUNC(cmd_checkemail)
 
     NICKSERV_MIN_PARMS(3);
     if (!(hi = modcmd_get_handle_info(user, argv[1]))) {
-        reply("MSG_HANDLE_UNKNOWN", argv[1]);
         return 0;
     }
     if (!hi->email_addr)
@@ -3490,7 +3491,7 @@ nickserv_db_read_handle(const char *handle, dict_t obj)
     struct string_list *masks, *slist;
     struct handle_info *hi;
     struct userNode *authed_users;
-    struct userData *channels;
+    struct userData *channel_list;
     unsigned long id;
     unsigned int ii;
     dict_t subdb;
@@ -3504,13 +3505,13 @@ nickserv_db_read_handle(const char *handle, dict_t obj)
     }
     if ((hi = get_handle_info(handle))) {
         authed_users = hi->users;
-        channels = hi->channels;
+        channel_list = hi->channels;
         hi->users = NULL;
         hi->channels = NULL;
         dict_remove(nickserv_handle_dict, hi->handle);
     } else {
         authed_users = NULL;
-        channels = NULL;
+        channel_list = NULL;
     }
     hi = register_handle(handle, str, id);
     if (authed_users) {
@@ -3520,7 +3521,7 @@ nickserv_db_read_handle(const char *handle, dict_t obj)
             authed_users = authed_users->next_authed;
         }
     }
-    hi->channels = channels;
+    hi->channels = channel_list;
     masks = database_get_data(obj, KEY_MASKS, RECDB_STRING_LIST);
     hi->masks = masks ? string_list_copy(masks) : alloc_string_list(1);
     str = database_get_data(obj, KEY_MAXLOGINS, RECDB_QSTRING);
@@ -3623,13 +3624,13 @@ nickserv_db_read_handle(const char *handle, dict_t obj)
             const char *setter;
             const char *text;
             const char *set;
-            const char *id;
+            const char *note_id;
             dict_t notedb;
 
-            id = iter_key(it);
+            note_id = iter_key(it);
             notedb = GET_RECORD_OBJECT((struct record_data*)iter_data(it));
             if (!notedb) {
-                log_module(NS_LOG, LOG_ERROR, "Malformed note %s for account %s; ignoring note.", id, hi->handle);
+                log_module(NS_LOG, LOG_ERROR, "Malformed note %s for account %s; ignoring note.", note_id, hi->handle);
                 continue;
             }
             expires = database_get_data(notedb, KEY_NOTE_EXPIRES, RECDB_QSTRING);
@@ -3637,14 +3638,14 @@ nickserv_db_read_handle(const char *handle, dict_t obj)
             text = database_get_data(notedb, KEY_NOTE_NOTE, RECDB_QSTRING);
             set = database_get_data(notedb, KEY_NOTE_SET, RECDB_QSTRING);
             if (!setter || !text || !set) {
-                log_module(NS_LOG, LOG_ERROR, "Missing field(s) from note %s for account %s; ignoring note.", id, hi->handle);
+                log_module(NS_LOG, LOG_ERROR, "Missing field(s) from note %s for account %s; ignoring note.", note_id, hi->handle);
                 continue;
             }
             note = calloc(1, sizeof(*note) + strlen(text));
             note->next = NULL;
             note->expires = expires ? strtoul(expires, NULL, 10) : 0;
             note->set = strtoul(set, NULL, 10);
-            note->id = strtoul(id, NULL, 10);
+            note->id = strtoul(note_id, NULL, 10);
             safestrncpy(note->setter, setter, sizeof(note->setter));
             strcpy(note->note, text);
             if (last_note)