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