hide password in log files in opt_password (oset password)
[srvx.git] / src / nickserv.c
index 31ee22f2e29b4273d52c526076e4d2900395afac..581d9b47d57ca0c881d6e6d3dca5af0eda1edcce 100644 (file)
@@ -417,7 +417,7 @@ static struct {
 } nickserv_conf;
 
 struct pendingLOCUser {
-    char numeric[COMBO_NUMERIC_LEN+1];
+    struct handle_info *handle_info;
     unsigned long time;
     struct authlogEntry *authlog;
     struct pendingLOCUser *next;
@@ -1974,9 +1974,7 @@ struct handle_info *checklogin(const char *user, const char *pass, const char *n
     struct authlogEntry *authlog = authlog_add(hi, NULL, ptr);
     struct pendingLOCUser *pending;
     if(authlog && (pending = malloc(sizeof(*pending)))) {
-        for(ii = 0; ii < COMBO_NUMERIC_LEN; ii++)
-            pending->numeric[ii] = numeric[ii];
-        pending->numeric[COMBO_NUMERIC_LEN] = '\0';
+        pending->handle_info = hi;
         pending->time = now;
         pending->authlog = authlog;
         pending->next = pendingLOCUsers;
@@ -2012,9 +2010,25 @@ reg_allowauth_func(allowauth_func_t func)
     allowauth_func_list[allowauth_func_used++] = func;
 }
 
+static int cmd_authlog_func(struct userNode *user, struct svccmd *cmd, struct handle_info *hi);
+
 static MODCMD_FUNC(cmd_authlog)
 {
-    struct handle_info *hi = user->handle_info;
+    return cmd_authlog_func(user, cmd, user->handle_info);
+}
+
+static MODCMD_FUNC(cmd_oauthlog) {
+    struct handle_info *hi;
+    
+    NICKSERV_MIN_PARMS(1);
+    
+    if (!(hi = get_victim_oper(user, argv[1])))
+        return 0;
+    
+    return cmd_authlog_func(user, cmd, hi);
+}
+
+static int cmd_authlog_func(struct userNode *user, struct svccmd *cmd, struct handle_info *hi) {
     struct helpfile_table tbl;
     struct authlogEntry *authlog;
     int i = 0;
@@ -2054,8 +2068,12 @@ static MODCMD_FUNC(cmd_authlog)
         tbl.contents[i][1] = ptr;
         if(authlog->logout_time)
             str = intervalString(intervalBuf, now - authlog->logout_time, hi);
-        else
-            str = (authlog->user ? "Never" : "Unknown");
+        else if(!authlog->user)
+            str = "Unknown";
+        else {
+            sprintf(intervalBuf, "Never (%s)", authlog->user->nick);
+            str = intervalBuf;
+        }
         ptr = malloc(strlen(str)+1);
         strcpy(ptr, str);
         tbl.contents[i][2] = ptr;
@@ -2795,6 +2813,8 @@ static OPTION_FUNC(opt_password)
         cryptpass(argv[1], hi->passwd);
 
     send_message(user, nickserv, "NSMSG_SET_PASSWORD", "***");
+    argv[1] = "****";
+    
     return 1;
 }
 
@@ -4174,6 +4194,8 @@ nickserv_db_read_authlog(UNUSED_ARG(const char *key), void *data, void *extra)
     str = database_get_data(rd->d.object, KEY_AUTHLOG_QUIT_REASON, RECDB_QSTRING);
     authlog->quit_reason = str ? strdup(str) : NULL;
     
+    authlog->user = NULL;
+    
     authlog->next = NULL;
     
     //append it to the end of the list...
@@ -4680,23 +4702,27 @@ nickserv_reclaim_p(void *data) {
 static void
 check_user_nick(struct userNode *user) {
     //check if this user is a pending LOC user
-    struct pendingLOCUser *pending, *next, *prev = NULL;
-    for(pending = pendingLOCUsers; pending; pending = next) {
-        next = pending->next;
-        if(!strcmp(user->numeric, pending->numeric)) {
-            pending->authlog->user = user;
-            if(prev)
-                prev->next = next;
-            else
-                pendingLOCUsers = next;
-            free(pending);
-        }
-        if(now - pending->time > 10) {
-            if(prev)
-                prev->next = next;
-            else
-                pendingLOCUsers = next;
-            free(pending);
+    if(pendingLOCUsers) {
+        struct pendingLOCUser *pending, *next, *prev = NULL;
+        for(pending = pendingLOCUsers; pending; pending = next) {
+            next = pending->next;
+            if(user->handle_info == pending->handle_info) {
+                pending->authlog->user = user;
+                free((char*) pending->authlog->hostmask);
+                pending->authlog->hostmask = generate_hostmask(user, GENMASK_USENICK|GENMASK_STRICT_IDENT|GENMASK_NO_HIDING|GENMASK_STRICT_HOST);
+                if(prev)
+                    prev->next = next;
+                else
+                    pendingLOCUsers = next;
+                free(pending);
+            }
+            if(now - pending->time > 10) {
+                if(prev)
+                    prev->next = next;
+                else
+                    pendingLOCUsers = next;
+                free(pending);
+            }
         }
     }
     struct nick_info *ni;
@@ -4905,7 +4931,8 @@ init_nickserv(const char *nick)
     nickserv_define_func("MERGEDB", cmd_mergedb, 999, 1, 0);
     nickserv_define_func("CHECKPASS", cmd_checkpass, 601, 1, 0);
     nickserv_define_func("CHECKEMAIL", cmd_checkemail, 0, 1, 0);
-    nickserv_define_func("AUTHLOG", cmd_authlog, 0, 1, 0);
+    nickserv_define_func("AUTHLOG", cmd_authlog, -1, 1, 0);
+    nickserv_define_func("OAUTHLOG", cmd_oauthlog, 0, 1, 0);
     /* other options */
     dict_insert(nickserv_opt_dict, "INFO", opt_info);
     dict_insert(nickserv_opt_dict, "WIDTH", opt_width);