]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/ctdlproto/serv_user.c
Merge branch 'configdb' of ssh://git.citadel.org/appl/gitroot/citadel
[citadel.git] / citadel / modules / ctdlproto / serv_user.c
index c8c8aaa2dfae9899332d774cf58b56410a3926b4..51ea437b7241951c9c7fb7bffe77c8178ddbe421 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * Server functions which perform operations on user objects.
  *
- * Copyright (c) 1987-2011 by the citadel.org team
+ * Copyright (c) 1987-2015 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.
  * GNU General Public License for more details.
  */
 
-#include "sysdep.h"
-#include <errno.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <syslog.h>
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-
-#include <string.h>
-#include <limits.h>
-#include <libcitadel.h>
-#include "auth.h"
-#include "citadel.h"
-#include "server.h"
-#include "database.h"
-#include "sysdep_decls.h"
 #include "support.h"
-#include "room_ops.h"
-#include "file_ops.h"
 #include "control.h"
-#include "msgbase.h"
-#include "config.h"
-#include "citserver.h"
-#include "citadel_dirs.h"
-#include "genstamp.h"
-#include "threads.h"
-#include "citadel_ldap.h"
-#include "context.h"
 #include "ctdl_module.h"
+#include "citserver.h"
+#include "config.h"
 #include "user_ops.h"
 #include "internet_addressing.h"
 
 
-
 /*
  * USER cmd
  */
@@ -89,7 +45,7 @@ void cmd_user(char *cmdbuf)
                        "Too many users are already online "
                        "(maximum is %d)\n",
                        ERROR + MAX_SESSIONS_EXCEEDED,
-                       config.c_nodename, config.c_maxsessions);
+                       CtdlGetConfigStr("c_nodename"), CtdlGetConfigInt("c_maxsessions"));
                return;
        case login_ok:
                cprintf("%d Password required for %s\n",
@@ -141,13 +97,13 @@ void cmd_newu(char *cmdbuf)
        long len;
        char username[SIZ];
 
-       if (config.c_auth_mode != AUTHMODE_NATIVE) {
+       if (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) {
                cprintf("%d This system does not use native mode authentication.\n",
                        ERROR + NOT_HERE);
                return;
        }
 
-       if (config.c_disable_newu) {
+       if (CtdlGetConfigInt("c_disable_newu")) {
                cprintf("%d Self-service user account creation "
                        "is disabled on this system.\n", ERROR + NOT_HERE);
                return;
@@ -160,7 +116,8 @@ void cmd_newu(char *cmdbuf)
        if (CC->nologin) {
                cprintf("%d %s: Too many users are already online (maximum is %d)\n",
                        ERROR + MAX_SESSIONS_EXCEEDED,
-                       config.c_nodename, config.c_maxsessions);
+                       CtdlGetConfigStr("c_nodename"), CtdlGetConfigInt("c_maxsessions"));
+               return;
        }
        extract_token(username, cmdbuf, 0, '|', sizeof username);
        strproc(username);
@@ -273,7 +230,7 @@ void cmd_creu(char *cmdbuf)
        } else if (a == ERROR + ALREADY_EXISTS) {
                cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
                return;
-       } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
+       } else if ( (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
                cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
                        ERROR + NO_SUCH_USER);
                return;
@@ -283,23 +240,19 @@ void cmd_creu(char *cmdbuf)
 }
 
 
-
 /*
  * get user parameters
  */
 void cmd_getu(char *cmdbuf)
 {
-
        if (CtdlAccessCheck(ac_logged_in))
                return;
 
        CtdlGetUser(&CC->user, CC->curr_user);
-       cprintf("%d 80|24|%d|\n",
-               CIT_OK,
-               (CC->user.flags & US_USER_SET)
-       );
+       cprintf("%d 80|24|%d|\n", CIT_OK, (CC->user.flags & US_USER_SET));
 }
 
+
 /*
  * set user parameters
  */
@@ -312,10 +265,10 @@ void cmd_setu(char *new_parms)
                cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
                return;
        }
-       CtdlGetUserLock(&CC->user, CC->curr_user);
+       CtdlLockGetCurrentUser();
        CC->user.flags = CC->user.flags & (~US_USER_SET);
        CC->user.flags = CC->user.flags | (extract_int(new_parms, 2) & US_USER_SET);
-       CtdlPutUserLock(&CC->user);
+       CtdlPutCurrentUserLock();
        cprintf("%d Ok\n", CIT_OK);
 }
 
@@ -338,7 +291,7 @@ void cmd_slrp(char *new_ptr)
                newlr = atol(new_ptr);
        }
 
-       CtdlGetUserLock(&CC->user, CC->curr_user);
+       CtdlLockGetCurrentUser();
 
        CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
        memcpy(&original_vbuf, &vbuf, sizeof(visit));
@@ -351,7 +304,7 @@ void cmd_slrp(char *new_ptr)
                CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
        }
 
-       CtdlPutUserLock(&CC->user);
+       CtdlPutCurrentUserLock();
        cprintf("%d %ld\n", CIT_OK, newlr);
 }
 
@@ -413,7 +366,7 @@ void cmd_invt_kick(char *iuser, int op) {
                return;
        }
 
-       if (!strncasecmp(CC->room.QRname, config.c_baseroom,
+       if (!strncasecmp(CC->room.QRname, CtdlGetConfigStr("c_baseroom"),
                         ROOMNAMELEN)) {
                cprintf("%d Can't add/remove users from this room.\n",
                        ERROR + NOT_HERE);
@@ -466,7 +419,7 @@ void cmd_gnur(char *argbuf)
                return;
        }
 
-       if ((CitControl.MMflags & MM_VALID) == 0) {
+       if ((CtdlGetConfigInt("MMflags") & MM_VALID) == 0) {
                cprintf("%d There are no unvalidated users.\n", CIT_OK);
                return;
        }
@@ -494,13 +447,12 @@ void cmd_gnur(char *argbuf)
         */
 
        begin_critical_section(S_CONTROL);
-       get_control();
-       CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
-       put_control();
+       int flags;
+       flags = CtdlGetConfigInt("MMflags");
+       flags = flags & (~MM_VALID);
+       CtdlSetConfigInt("MMflags", flags);
        end_critical_section(S_CONTROL);
        cprintf("%d *** End of registration.\n", CIT_OK);
-
-
 }
 
 
@@ -576,9 +528,9 @@ void cmd_chek(char *argbuf)
                regis = 1;
 
        if (CC->user.axlevel >= AxAideU) {
-               get_control();
-               if (CitControl.MMflags & MM_VALID)
+               if (CtdlGetConfigInt("MMflags") & MM_VALID) {
                        vali = 1;
+               }
        }
 
        /* check for mail */
@@ -699,6 +651,25 @@ void cmd_asup(char *cmdbuf)
 }
 
 
+/*
+ * Citadel protocol command to do the same
+ */
+void cmd_isme(char *argbuf) {
+       char addr[256];
+
+       if (CtdlAccessCheck(ac_logged_in)) return;
+       extract_token(addr, argbuf, 0, '|', sizeof addr);
+
+       if (CtdlIsMe(addr, sizeof addr)) {
+               cprintf("%d %s\n", CIT_OK, addr);
+       }
+       else {
+               cprintf("%d Not you.\n", ERROR + ILLEGAL_VALUE);
+       }
+
+}
+
+
 /*
  * Set the preferred view for the current user/room combination
  */
@@ -805,6 +776,7 @@ CTDL_MODULE_INIT(serv_user)
                CtdlRegisterProtoHook(cmd_view, "VIEW", "Set preferred view for user/room combination");
                CtdlRegisterProtoHook(cmd_renu, "RENU", "Rename a user");
                CtdlRegisterProtoHook(cmd_newu, "NEWU", "Log in as a new user");
+               CtdlRegisterProtoHook(cmd_isme, "ISME", "Determine whether an email address belongs to a user");
        }
        /* return our Subversion id for the Log */
        return "user";