Fixed a bug in username key usage that was causing email aliases to disappear
[citadel.git] / citadel / modules / ctdlproto / serv_user.c
index 48799de77d955c73e92bae7599d2c4affd8f1c0b..437f59633514c36f80e206537745fdb66a132726 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * Server functions which perform operations on user objects.
  *
- * Copyright (c) 1987-2018 by the citadel.org team
+ * Copyright (c) 1987-2020 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License, version 3.
@@ -484,6 +484,40 @@ void cmd_vali(char *v_args)
        cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
 }
 
+
+/*
+ * List one user (this works with cmd_list)
+ */
+void ListThisUser(char *username, void *data)
+{
+       char *searchstring;
+       struct ctdluser usbuf;
+
+       if (CtdlGetUser(&usbuf, username) != 0) {
+               return;
+       }
+
+       searchstring = (char *)data;
+       if (bmstrcasestr(usbuf.fullname, searchstring) == NULL) {
+               return;
+       }
+
+       if (usbuf.axlevel > AxDeleted) {
+               if ((CC->user.axlevel >= AxAideU)
+                   || ((usbuf.flags & US_UNLISTED) == 0)
+                   || ((CC->internal_pgm))) {
+                       cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
+                               usbuf.fullname,
+                               usbuf.axlevel,
+                               usbuf.usernum,
+                               (long)usbuf.lastcall,
+                               usbuf.timescalled,
+                               usbuf.posted);
+               }
+       }
+}
+
+
 /* 
  *  List users (searchstring may be empty to list all users)
  */
@@ -707,15 +741,20 @@ void cmd_asea(char *cmdbuf)
 
        cprintf("%d Ok\n", SEND_LISTING);
        while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000")) {
-               if (                                                                                    // addresses must be:
-                       (!IsEmptyStr(buf))                                                              // non-empty
-                       && ((strlen(new_emailaddrs) + strlen(buf) + 2) < sizeof(new_emailaddrs))        // fit in the remaining buffer
-                       && (IsDirectory(buf, 0))                                                        // in one of our own domains
-                       && (                                                                            // not belong to someone else
-                               (CtdlDirectoryLookup(whodat, buf, sizeof whodat) != 0)
-                               || (!strcasecmp(whodat, requested_user))
-                       )
-               ) {
+               if (IsEmptyStr(buf)) {
+                       syslog(LOG_ERR, "user_ops: address <%s> is empty - not using", buf);
+               }
+               else if ((strlen(new_emailaddrs) + strlen(buf) + 2) > sizeof(new_emailaddrs)) {
+                       syslog(LOG_ERR, "user_ops: address <%s> does not fit in buffer - not using", buf);
+               }
+               else if (!IsDirectory(buf, 0)) {
+                       syslog(LOG_ERR, "user_ops: address <%s> is not in one of our domains - not using", buf);
+               }
+               else if ( (CtdlDirectoryLookup(whodat, buf, sizeof whodat) == 0) && (CtdlUserCmp(whodat, requested_user)) ) {
+                       syslog(LOG_ERR, "user_ops: address <%s> already belongs to <%s> - not using", buf, whodat);
+               }
+               else {
+                       syslog(LOG_DEBUG, "user_ops: address <%s> validated", buf);
                        if (!IsEmptyStr(new_emailaddrs)) {
                                strcat(new_emailaddrs, "|");
                        }
@@ -723,7 +762,6 @@ void cmd_asea(char *cmdbuf)
                }
        }
 
-
        CtdlSetEmailAddressesForUser(requested_user, new_emailaddrs);
 }