]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
These are the changes to eliminate most of the arbitrary limits in the
[citadel.git] / citadel / user_ops.c
index 9a71c3778fb8f8f0bd22e12bb8df3abcef01b1db..8c7b0d00a6d3f043a2973b5e84718c0f18c3034c 100644 (file)
@@ -1,4 +1,5 @@
-#define _XOPEN_SOURCE  /* needed to properly enable crypt() stuff on some systems */
+/* needed to properly enable crypt() stuff on some systems */
+#define _XOPEN_SOURCE
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -210,13 +211,11 @@ void session_startup(void) {
        hook_user_login(CC->cs_pid, CC->curr_user);
        lgetuser(&CC->usersupp,CC->curr_user);
        ++(CC->usersupp.timescalled);
-       /* <bc> */
        CC->fake_username[0] = '\0';
        CC->fake_postname[0] = '\0';
        CC->fake_hostname[0] = '\0';
        CC->fake_roomname[0] = '\0';
        CC->last_pager[0] = '\0';
-       /* <bc> */
        time(&CC->usersupp.lastcall);
 
        /* If this user's name is the name of the system administrator
@@ -324,16 +323,42 @@ void cmd_pass(char *buf)
 /*
  * purge related files when removing or overwriting a user record
  */
-void purge_user(pnum)
-long pnum; {
+void purge_user(char *pname) {
        char filename[64];
+       struct usersupp usbuf;
+       int a;
+       struct cdbdata *cdbmb;
+       long *mailbox;
+       int num_mails;
+
+       if (getuser(&usbuf, pname) != 0) {
+               lprintf(5, "Cannot purge user <%s> - not found\n", pname);
+               return;
+               }
+
+       /* delete any messages in the user's mailbox */
+       cdbmb = cdb_fetch(CDB_MAILBOXES, &usbuf.usernum, sizeof(long));
+       if (cdbmb != NULL) {
+               num_mails = cdbmb->len / sizeof(long);
+               mailbox = (long *) cdbmb->ptr;
+               if (num_mails > 0) for (a=0; a<num_mails; ++a) {
+                       cdb_delete(CDB_MSGMAIN, &mailbox[a], sizeof(long));
+                       }
+               cdb_free(cdbmb);
+               /* now delete the mailbox itself */
+               cdb_delete(CDB_MAILBOXES, &usbuf.usernum, sizeof(long));
+               }
+
+
+       /* delete the userlog entry */
+       cdb_delete(CDB_USERSUPP, pname, strlen(pname));
 
        /* remove the user's bio file */        
-       sprintf(filename, "./bio/%ld", pnum);
+       sprintf(filename, "./bio/%ld", usbuf.usernum);
        unlink(filename);
 
        /* remove the user's picture */
-       sprintf(filename, "./userpics/%ld.gif", pnum);
+       sprintf(filename, "./userpics/%ld.gif", usbuf.usernum);
        unlink(filename);
        
        }
@@ -345,8 +370,7 @@ long pnum; {
 int create_user(char *newusername)
 {
        struct usersupp usbuf;
-       int a,file;
-       long aa;
+       int a;
        struct passwd *p = NULL;
        char username[64];
 
@@ -380,9 +404,6 @@ int create_user(char *newusername)
                CC->usersupp.generation[a]=(-1);
                CC->usersupp.forget[a]=(-1);
                }
-       for (a=0; a<MAILSLOTS; ++a) {
-               CC->usersupp.mailnum[a]=0L;
-               }
        strcpy(CC->usersupp.password,"");
 
        /* These are the default flags on new accounts */
@@ -675,7 +696,6 @@ void cmd_forg(void) {
 void cmd_gnur(void) {
        struct cdbdata *cdbus;
        struct usersupp usbuf;
-       FILE *fp;
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
@@ -817,6 +837,14 @@ void cmd_vali(char *v_args)
        userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
 
        lputuser(&userbuf,user);
+
+       /* If the access level was set to zero, delete the user */
+       if (newax == 0) {
+               purge_user(user);
+               cprintf("%d %s Deleted.\n", OK, userbuf.fullname);
+               return;
+               }
+
        cprintf("%d ok\n",OK);
        }
 
@@ -862,7 +890,6 @@ void cmd_list(void) {
  */
 void cmd_regi(void) {
        int a,b,c;
-       FILE *fp;
        char buf[256];
 
        char tmpname[256];
@@ -951,7 +978,11 @@ void cmd_chek(void) {
        int mail = 0;
        int regis = 0;
        int vali = 0;
-       int a,file;
+       int a;
+       struct cdbdata *cdbmb;
+       long *mailbox;
+       int num_mails;
+       
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
@@ -966,10 +997,19 @@ void cmd_chek(void) {
                if (CitControl.MMflags&MM_VALID) vali = 1;
                }
 
-       mail=0;                         /* check for mail */
-       for (a=0; a<MAILSLOTS; ++a)
-               if ((CC->usersupp.mailnum[a])>(CC->usersupp.lastseen[1]))
-                       ++mail;
+
+       /* check for mail */
+       mail = 0;
+       cdbmb = cdb_fetch(CDB_MAILBOXES, &CC->usersupp.usernum, sizeof(long));
+       if (cdbmb != NULL) {
+               num_mails = cdbmb->len / sizeof(long);
+               mailbox = (long *) cdbmb->ptr;
+               if (num_mails > 0) for (a=0; a<num_mails; ++a) {
+                       if (mailbox[a] > (CC->usersupp.lastseen[1])) ++mail;
+                       }
+               cdb_free(cdbmb);
+               }
+
 
        cprintf("%d %d|%d|%d\n",OK,mail,regis,vali);
        }