Modified the behavior of ForEachUser() to do the two phase load/perform cycle
[citadel.git] / citadel / modules / ctdlproto / serv_user.c
index a3238a522c9663e36cc5f074ae1ba8edf8058f3f..73465ab2647708275fcd3f45c3ab7ba039f2e67c 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * Server functions which perform operations on user objects.
  *
- * Copyright (c) 1987-2017 by the citadel.org team
+ * Copyright (c) 1987-2019 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.
@@ -34,7 +34,7 @@ void cmd_user(char *cmdbuf)
        striplt(username);
        syslog(LOG_DEBUG, "user_ops: cmd_user(%s)", username);
 
-       a = CtdlLoginExistingUser(NULL, username);
+       a = CtdlLoginExistingUser(username);
        switch (a) {
        case login_already_logged_in:
                cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
@@ -132,7 +132,7 @@ void cmd_newu(char *cmdbuf)
                return;
        }
 
-       a = create_user(username, CREATE_USER_BECOME_USER);
+       a = create_user(username, CREATE_USER_BECOME_USER, NATIVE_AUTH_UID);
 
        if (a == 0) {
                logged_in_response();
@@ -162,11 +162,6 @@ void cmd_setp(char *new_pw)
                cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR + NOT_HERE);
                return;
        }
-       if (CC->is_master) {
-               cprintf("%d The master prefix password cannot be changed with this command.\n",
-                       ERROR + NOT_HERE);
-               return;
-       }
 
        if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
                char random_password[17];
@@ -210,7 +205,7 @@ void cmd_creu(char *cmdbuf)
 
        extract_token(password, cmdbuf, 1, '|', sizeof password);
 
-       a = create_user(username, CREATE_USER_DO_NOT_BECOME_USER);
+       a = create_user(username, CREATE_USER_DO_NOT_BECOME_USER, NATIVE_AUTH_UID);
 
        if (a == 0) {
                if (!IsEmptyStr(password)) {
@@ -489,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)
  */
@@ -701,7 +730,6 @@ void cmd_asea(char *cmdbuf)
        char buf[SIZ];
        char whodat[64];
        char new_emailaddrs[512] = { 0 } ;
-       int i;
 
        if (CtdlAccessCheck(ac_aide)) return;
 
@@ -729,25 +757,8 @@ void cmd_asea(char *cmdbuf)
                }
        }
 
-       if (CtdlGetUserLock(&usbuf, requested_user) != 0) {     // We are relying on the fact that the DirectoryIndex functions don't lock.
-               return;                                         // Silently fail here if we can't acquire a lock on the user record.
-       }
 
-       /* Delete all of the existing directory index records for the user (easier this way) */
-       for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
-               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
-               CtdlDirectoryDelUser(buf, requested_user);
-       }
-
-       strcpy(usbuf.emailaddrs, new_emailaddrs);               // make it official.
-
-       /* Index all of the new email addresses (they've already been sanitized) */
-       for (i=0; i<num_tokens(usbuf.emailaddrs, '|'); ++i) {
-               extract_token(buf, usbuf.emailaddrs, i, '|', sizeof buf);
-               CtdlDirectoryAddUser(buf, requested_user);
-       }
-
-       CtdlPutUserLock(&usbuf);
+       CtdlSetEmailAddressesForUser(requested_user, new_emailaddrs);
 }