c8c8aaa2dfae9899332d774cf58b56410a3926b4
[citadel.git] / citadel / modules / ctdlproto / serv_user.c
1 /* 
2  * Server functions which perform operations on user objects.
3  *
4  * Copyright (c) 1987-2011 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include "sysdep.h"
16 #include <errno.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <fcntl.h>
21 #include <signal.h>
22 #include <pwd.h>
23 #include <ctype.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <syslog.h>
27 #ifdef HAVE_SYS_STAT_H
28 #include <sys/stat.h>
29 #endif
30
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
33 # include <time.h>
34 #else
35 # if HAVE_SYS_TIME_H
36 #  include <sys/time.h>
37 # else
38 #  include <time.h>
39 # endif
40 #endif
41
42 #include <string.h>
43 #include <limits.h>
44 #include <libcitadel.h>
45 #include "auth.h"
46 #include "citadel.h"
47 #include "server.h"
48 #include "database.h"
49 #include "sysdep_decls.h"
50 #include "support.h"
51 #include "room_ops.h"
52 #include "file_ops.h"
53 #include "control.h"
54 #include "msgbase.h"
55 #include "config.h"
56 #include "citserver.h"
57 #include "citadel_dirs.h"
58 #include "genstamp.h"
59 #include "threads.h"
60 #include "citadel_ldap.h"
61 #include "context.h"
62 #include "ctdl_module.h"
63 #include "user_ops.h"
64 #include "internet_addressing.h"
65
66
67
68 /*
69  * USER cmd
70  */
71 void cmd_user(char *cmdbuf)
72 {
73         char username[256];
74         int a;
75
76         CON_syslog(LOG_DEBUG, "cmd_user(%s)\n", cmdbuf);
77         extract_token(username, cmdbuf, 0, '|', sizeof username);
78         CON_syslog(LOG_DEBUG, "username: %s\n", username);
79         striplt(username);
80         CON_syslog(LOG_DEBUG, "username: %s\n", username);
81
82         a = CtdlLoginExistingUser(NULL, username);
83         switch (a) {
84         case login_already_logged_in:
85                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
86                 return;
87         case login_too_many_users:
88                 cprintf("%d %s: "
89                         "Too many users are already online "
90                         "(maximum is %d)\n",
91                         ERROR + MAX_SESSIONS_EXCEEDED,
92                         config.c_nodename, config.c_maxsessions);
93                 return;
94         case login_ok:
95                 cprintf("%d Password required for %s\n",
96                         MORE_DATA, CC->curr_user);
97                 return;
98         case login_not_found:
99                 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
100                 return;
101         default:
102                 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
103         }
104 }
105
106
107 void cmd_pass(char *buf)
108 {
109         char password[SIZ];
110         int a;
111         long len;
112
113         memset(password, 0, sizeof(password));
114         len = extract_token(password, buf, 0, '|', sizeof password);
115         a = CtdlTryPassword(password, len);
116
117         switch (a) {
118         case pass_already_logged_in:
119                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
120                 return;
121         case pass_no_user:
122                 cprintf("%d You must send a name with USER first.\n",
123                         ERROR + USERNAME_REQUIRED);
124                 return;
125         case pass_wrong_password:
126                 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
127                 return;
128         case pass_ok:
129                 logged_in_response();
130                 return;
131         }
132 }
133
134
135 /*
136  * cmd_newu()  -  create a new user account and log in as that user
137  */
138 void cmd_newu(char *cmdbuf)
139 {
140         int a;
141         long len;
142         char username[SIZ];
143
144         if (config.c_auth_mode != AUTHMODE_NATIVE) {
145                 cprintf("%d This system does not use native mode authentication.\n",
146                         ERROR + NOT_HERE);
147                 return;
148         }
149
150         if (config.c_disable_newu) {
151                 cprintf("%d Self-service user account creation "
152                         "is disabled on this system.\n", ERROR + NOT_HERE);
153                 return;
154         }
155
156         if (CC->logged_in) {
157                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
158                 return;
159         }
160         if (CC->nologin) {
161                 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
162                         ERROR + MAX_SESSIONS_EXCEEDED,
163                         config.c_nodename, config.c_maxsessions);
164         }
165         extract_token(username, cmdbuf, 0, '|', sizeof username);
166         strproc(username);
167         len = cutuserkey(username);
168
169         if (IsEmptyStr(username)) {
170                 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
171                 return;
172         }
173
174         if ((!strcasecmp(username, "bbs")) ||
175             (!strcasecmp(username, "new")) ||
176             (!strcasecmp(username, "."))) {
177                 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
178                 return;
179         }
180
181         a = create_user(username, len, 1);
182
183         if (a == 0) {
184                 logged_in_response();
185         } else if (a == ERROR + ALREADY_EXISTS) {
186                 cprintf("%d '%s' already exists.\n",
187                         ERROR + ALREADY_EXISTS, username);
188                 return;
189         } else if (a == ERROR + INTERNAL_ERROR) {
190                 cprintf("%d Internal error - user record disappeared?\n",
191                         ERROR + INTERNAL_ERROR);
192                 return;
193         } else {
194                 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
195         }
196 }
197
198 /*
199  * set password - citadel protocol implementation
200  */
201 void cmd_setp(char *new_pw)
202 {
203         if (CtdlAccessCheck(ac_logged_in)) {
204                 return;
205         }
206         if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
207                 cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR + NOT_HERE);
208                 return;
209         }
210         if (CC->is_master) {
211                 cprintf("%d The master prefix password cannot be changed with this command.\n",
212                         ERROR + NOT_HERE);
213                 return;
214         }
215
216         if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
217                 char random_password[17];
218                 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
219                 CtdlSetPassword(random_password);
220                 cprintf("%d %s\n", CIT_OK, random_password);
221         }
222         else {
223                 strproc(new_pw);
224                 if (IsEmptyStr(new_pw)) {
225                         cprintf("%d Password unchanged.\n", CIT_OK);
226                         return;
227                 }
228                 CtdlSetPassword(new_pw);
229                 cprintf("%d Password changed.\n", CIT_OK);
230         }
231 }
232
233
234 /*
235  * cmd_creu() - administratively create a new user account (do not log in to it)
236  */
237 void cmd_creu(char *cmdbuf)
238 {
239         int a;
240         long len;
241         char username[SIZ];
242         char password[SIZ];
243         struct ctdluser tmp;
244
245         if (CtdlAccessCheck(ac_aide)) {
246                 return;
247         }
248
249         extract_token(username, cmdbuf, 0, '|', sizeof username);
250         strproc(username);
251         strproc(password);
252         if (IsEmptyStr(username)) {
253                 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
254                 return;
255         }
256         len = cutuserkey(username);
257
258
259         extract_token(password, cmdbuf, 1, '|', sizeof password);
260
261         a = create_user(username, len, 0);
262
263         if (a == 0) {
264                 if (!IsEmptyStr(password)) {
265                         CtdlGetUserLock(&tmp, username);
266                         safestrncpy(tmp.password, password, sizeof(tmp.password));
267                         CtdlPutUserLock(&tmp);
268                 }
269                 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
270                                 (!IsEmptyStr(password)) ? "and password set" :
271                                 "with no password");
272                 return;
273         } else if (a == ERROR + ALREADY_EXISTS) {
274                 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
275                 return;
276         } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
277                 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
278                         ERROR + NO_SUCH_USER);
279                 return;
280         } else {
281                 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
282         }
283 }
284
285
286
287 /*
288  * get user parameters
289  */
290 void cmd_getu(char *cmdbuf)
291 {
292
293         if (CtdlAccessCheck(ac_logged_in))
294                 return;
295
296         CtdlGetUser(&CC->user, CC->curr_user);
297         cprintf("%d 80|24|%d|\n",
298                 CIT_OK,
299                 (CC->user.flags & US_USER_SET)
300         );
301 }
302
303 /*
304  * set user parameters
305  */
306 void cmd_setu(char *new_parms)
307 {
308         if (CtdlAccessCheck(ac_logged_in))
309                 return;
310
311         if (num_parms(new_parms) < 3) {
312                 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
313                 return;
314         }
315         CtdlGetUserLock(&CC->user, CC->curr_user);
316         CC->user.flags = CC->user.flags & (~US_USER_SET);
317         CC->user.flags = CC->user.flags | (extract_int(new_parms, 2) & US_USER_SET);
318         CtdlPutUserLock(&CC->user);
319         cprintf("%d Ok\n", CIT_OK);
320 }
321
322 /*
323  * set last read pointer
324  */
325 void cmd_slrp(char *new_ptr)
326 {
327         long newlr;
328         visit vbuf;
329         visit original_vbuf;
330
331         if (CtdlAccessCheck(ac_logged_in)) {
332                 return;
333         }
334
335         if (!strncasecmp(new_ptr, "highest", 7)) {
336                 newlr = CC->room.QRhighest;
337         } else {
338                 newlr = atol(new_ptr);
339         }
340
341         CtdlGetUserLock(&CC->user, CC->curr_user);
342
343         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
344         memcpy(&original_vbuf, &vbuf, sizeof(visit));
345         vbuf.v_lastseen = newlr;
346         snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
347
348         /* Only rewrite the record if it changed */
349         if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
350            || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
351                 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
352         }
353
354         CtdlPutUserLock(&CC->user);
355         cprintf("%d %ld\n", CIT_OK, newlr);
356 }
357
358
359 void cmd_seen(char *argbuf) {
360         long target_msgnum = 0L;
361         int target_setting = 0;
362
363         if (CtdlAccessCheck(ac_logged_in)) {
364                 return;
365         }
366
367         if (num_parms(argbuf) != 2) {
368                 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
369                 return;
370         }
371
372         target_msgnum = extract_long(argbuf, 0);
373         target_setting = extract_int(argbuf, 1);
374
375         CtdlSetSeen(&target_msgnum, 1, target_setting,
376                         ctdlsetseen_seen, NULL, NULL);
377         cprintf("%d OK\n", CIT_OK);
378 }
379
380
381 void cmd_gtsn(char *argbuf) {
382         visit vbuf;
383
384         if (CtdlAccessCheck(ac_logged_in)) {
385                 return;
386         }
387
388         /* Learn about the user and room in question */
389         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
390
391         cprintf("%d ", CIT_OK);
392         client_write(vbuf.v_seen, strlen(vbuf.v_seen));
393         client_write(HKEY("\n"));
394 }
395
396 /*
397  * INVT and KICK commands
398  */
399 void cmd_invt_kick(char *iuser, int op) {
400
401         /*
402          * These commands are only allowed by admins, room admins,
403          * and room namespace owners
404          */
405         if (is_room_aide()) {
406                 /* access granted */
407         } else if ( ((atol(CC->room.QRname) == CC->user.usernum) ) && (CC->user.usernum != 0) ) {
408                 /* access granted */
409         } else {
410                 /* access denied */
411                 cprintf("%d Higher access or room ownership required.\n",
412                         ERROR + HIGHER_ACCESS_REQUIRED);
413                 return;
414         }
415
416         if (!strncasecmp(CC->room.QRname, config.c_baseroom,
417                          ROOMNAMELEN)) {
418                 cprintf("%d Can't add/remove users from this room.\n",
419                         ERROR + NOT_HERE);
420                 return;
421         }
422
423         if (CtdlInvtKick(iuser, op) != 0) {
424                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
425                 return;
426         }
427
428         cprintf("%d %s %s %s.\n",
429                 CIT_OK, iuser,
430                 ((op == 1) ? "invited to" : "kicked out of"),
431                 CC->room.QRname);
432         return;
433 }
434
435 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
436 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
437
438
439 /*
440  * forget (Zap) the current room
441  */
442 void cmd_forg(char *argbuf)
443 {
444
445         if (CtdlAccessCheck(ac_logged_in)) {
446                 return;
447         }
448
449         if (CtdlForgetThisRoom() == 0) {
450                 cprintf("%d Ok\n", CIT_OK);
451         }
452         else {
453                 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
454         }
455 }
456
457 /*
458  * Get Next Unregistered User
459  */
460 void cmd_gnur(char *argbuf)
461 {
462         struct cdbdata *cdbus;
463         struct ctdluser usbuf;
464
465         if (CtdlAccessCheck(ac_aide)) {
466                 return;
467         }
468
469         if ((CitControl.MMflags & MM_VALID) == 0) {
470                 cprintf("%d There are no unvalidated users.\n", CIT_OK);
471                 return;
472         }
473
474         /* There are unvalidated users.  Traverse the user database,
475          * and return the first user we find that needs validation.
476          */
477         cdb_rewind(CDB_USERS);
478         while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
479                 memset(&usbuf, 0, sizeof(struct ctdluser));
480                 memcpy(&usbuf, cdbus->ptr,
481                        ((cdbus->len > sizeof(struct ctdluser)) ?
482                         sizeof(struct ctdluser) : cdbus->len));
483                 cdb_free(cdbus);
484                 if ((usbuf.flags & US_NEEDVALID)
485                     && (usbuf.axlevel > AxDeleted)) {
486                         cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
487                         cdb_close_cursor(CDB_USERS);
488                         return;
489                 }
490         }
491
492         /* If we get to this point, there are no more unvalidated users.
493          * Therefore we clear the "users need validation" flag.
494          */
495
496         begin_critical_section(S_CONTROL);
497         get_control();
498         CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
499         put_control();
500         end_critical_section(S_CONTROL);
501         cprintf("%d *** End of registration.\n", CIT_OK);
502
503
504 }
505
506
507 /*
508  * validate a user
509  */
510 void cmd_vali(char *v_args)
511 {
512         char user[128];
513         int newax;
514         struct ctdluser userbuf;
515
516         extract_token(user, v_args, 0, '|', sizeof user);
517         newax = extract_int(v_args, 1);
518
519         if (CtdlAccessCheck(ac_aide) || 
520             (newax > AxAideU) ||
521             (newax < AxDeleted)) {
522                 return;
523         }
524
525         if (CtdlGetUserLock(&userbuf, user) != 0) {
526                 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
527                 return;
528         }
529
530         userbuf.axlevel = newax;
531         userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
532
533         CtdlPutUserLock(&userbuf);
534
535         /* If the access level was set to zero, delete the user */
536         if (newax == 0) {
537                 if (purge_user(user) == 0) {
538                         cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
539                         return;
540                 }
541         }
542         cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
543 }
544
545 /* 
546  *  List users (searchstring may be empty to list all users)
547  */
548 void cmd_list(char *cmdbuf)
549 {
550         char searchstring[256];
551         extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
552         striplt(searchstring);
553         cprintf("%d \n", LISTING_FOLLOWS);
554         ForEachUser(ListThisUser, (void *)searchstring );
555         cprintf("000\n");
556 }
557
558
559
560
561 /*
562  * assorted info we need to check at login
563  */
564 void cmd_chek(char *argbuf)
565 {
566         int mail = 0;
567         int regis = 0;
568         int vali = 0;
569
570         if (CtdlAccessCheck(ac_logged_in)) {
571                 return;
572         }
573
574         CtdlGetUser(&CC->user, CC->curr_user);  /* no lock is needed here */
575         if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
576                 regis = 1;
577
578         if (CC->user.axlevel >= AxAideU) {
579                 get_control();
580                 if (CitControl.MMflags & MM_VALID)
581                         vali = 1;
582         }
583
584         /* check for mail */
585         mail = InitialMailCheck();
586
587         cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
588 }
589
590
591 /*
592  * check to see if a user exists
593  */
594 void cmd_qusr(char *who)
595 {
596         struct ctdluser usbuf;
597
598         if (CtdlGetUser(&usbuf, who) == 0) {
599                 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
600         } else {
601                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
602         }
603 }
604
605
606 /*
607  * Administrative Get User Parameters
608  */
609 void cmd_agup(char *cmdbuf)
610 {
611         struct ctdluser usbuf;
612         char requested_user[128];
613
614         if (CtdlAccessCheck(ac_aide)) {
615                 return;
616         }
617
618         extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
619         if (CtdlGetUser(&usbuf, requested_user) != 0) {
620                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
621                 return;
622         }
623         cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
624                 CIT_OK,
625                 usbuf.fullname,
626                 usbuf.password,
627                 usbuf.flags,
628                 usbuf.timescalled,
629                 usbuf.posted,
630                 (int) usbuf.axlevel,
631                 usbuf.usernum,
632                 (long)usbuf.lastcall,
633                 usbuf.USuserpurge);
634 }
635
636
637
638 /*
639  * Administrative Set User Parameters
640  */
641 void cmd_asup(char *cmdbuf)
642 {
643         struct ctdluser usbuf;
644         char requested_user[128];
645         char notify[SIZ];
646         int np;
647         int newax;
648         int deleted = 0;
649
650         if (CtdlAccessCheck(ac_aide))
651                 return;
652
653         extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
654         if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
655                 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
656                 return;
657         }
658         np = num_parms(cmdbuf);
659         if (np > 1)
660                 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
661         if (np > 2)
662                 usbuf.flags = extract_int(cmdbuf, 2);
663         if (np > 3)
664                 usbuf.timescalled = extract_int(cmdbuf, 3);
665         if (np > 4)
666                 usbuf.posted = extract_int(cmdbuf, 4);
667         if (np > 5) {
668                 newax = extract_int(cmdbuf, 5);
669                 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
670                         usbuf.axlevel = newax;
671                 }
672         }
673         if (np > 7) {
674                 usbuf.lastcall = extract_long(cmdbuf, 7);
675         }
676         if (np > 8) {
677                 usbuf.USuserpurge = extract_int(cmdbuf, 8);
678         }
679         CtdlPutUserLock(&usbuf);
680         if (usbuf.axlevel == AxDeleted) {
681                 if (purge_user(requested_user) == 0) {
682                         deleted = 1;
683                 }
684         }
685
686         if (deleted) {
687                 snprintf(notify, SIZ, 
688                          "User \"%s\" has been deleted by %s.\n",
689                          usbuf.fullname,
690                         (CC->logged_in ? CC->user.fullname : "an administrator")
691                 );
692                 CtdlAideMessage(notify, "User Deletion Message");
693         }
694
695         cprintf("%d Ok", CIT_OK);
696         if (deleted)
697                 cprintf(" (%s deleted)", requested_user);
698         cprintf("\n");
699 }
700
701
702 /*
703  * Set the preferred view for the current user/room combination
704  */
705 void cmd_view(char *cmdbuf) {
706         int requested_view;
707         visit vbuf;
708
709         if (CtdlAccessCheck(ac_logged_in)) {
710                 return;
711         }
712
713         requested_view = extract_int(cmdbuf, 0);
714
715         CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
716         vbuf.v_view = requested_view;
717         CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
718         
719         cprintf("%d ok\n", CIT_OK);
720 }
721
722
723 /*
724  * Rename a user
725  */
726 void cmd_renu(char *cmdbuf)
727 {
728         int retcode;
729         char oldname[USERNAME_SIZE];
730         char newname[USERNAME_SIZE];
731
732         if (CtdlAccessCheck(ac_aide)) {
733                 return;
734         }
735
736         extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
737         extract_token(newname, cmdbuf, 1, '|', sizeof newname);
738
739         retcode = rename_user(oldname, newname);
740         switch(retcode) {
741                 case RENAMEUSER_OK:
742                         cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
743                         return;
744                 case RENAMEUSER_LOGGED_IN:
745                         cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
746                                 ERROR + ALREADY_LOGGED_IN , oldname);
747                         return;
748                 case RENAMEUSER_NOT_FOUND:
749                         cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
750                         return;
751                 case RENAMEUSER_ALREADY_EXISTS:
752                         cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
753                         return;
754         }
755
756         cprintf("%d An unknown error occurred.\n", ERROR);
757 }
758
759
760
761 void cmd_quit(char *argbuf)
762 {
763         cprintf("%d Goodbye.\n", CIT_OK);
764         CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
765 }
766
767
768 void cmd_lout(char *argbuf)
769 {
770         if (CC->logged_in) 
771                 CtdlUserLogout();
772         cprintf("%d logged out.\n", CIT_OK);
773 }
774
775
776 /*****************************************************************************/
777 /*                      MODULE INITIALIZATION STUFF                          */
778 /*****************************************************************************/
779
780
781 CTDL_MODULE_INIT(serv_user)
782 {
783         if (!threading) {
784                 CtdlRegisterProtoHook(cmd_user, "USER", "Submit username for login");
785                 CtdlRegisterProtoHook(cmd_pass, "PASS", "Complete login by submitting a password");
786                 CtdlRegisterProtoHook(cmd_quit, "QUIT", "log out and disconnect from server");
787                 CtdlRegisterProtoHook(cmd_lout, "LOUT", "log out but do not disconnect from server");
788                 CtdlRegisterProtoHook(cmd_creu, "CREU", "Create User");
789                 CtdlRegisterProtoHook(cmd_setp, "SETP", "Set the password for an account");
790                 CtdlRegisterProtoHook(cmd_getu, "GETU", "Get User parameters");
791                 CtdlRegisterProtoHook(cmd_setu, "SETU", "Set User parameters");
792                 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Set Last Read Pointer");
793                 CtdlRegisterProtoHook(cmd_invt, "INVT", "Invite a user to a room");
794                 CtdlRegisterProtoHook(cmd_kick, "KICK", "Kick a user out of a room");
795                 CtdlRegisterProtoHook(cmd_forg, "FORG", "Forget a room");
796                 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Get Next Unregistered User");
797                 CtdlRegisterProtoHook(cmd_vali, "VALI", "Validate new users");
798                 CtdlRegisterProtoHook(cmd_list, "LIST", "List users");
799                 CtdlRegisterProtoHook(cmd_chek, "CHEK", "assorted info we need to check at login");
800                 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "check to see if a user exists");
801                 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Administratively Get User Parameters");
802                 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Administratively Set User Parameters");
803                 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Manipulate seen/unread message flags");
804                 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Fetch seen/unread message flags");
805                 CtdlRegisterProtoHook(cmd_view, "VIEW", "Set preferred view for user/room combination");
806                 CtdlRegisterProtoHook(cmd_renu, "RENU", "Rename a user");
807                 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Log in as a new user");
808         }
809         /* return our Subversion id for the Log */
810         return "user";
811 }