]> code.citadel.org Git - citadel.git/blobdiff - citadel/room_ops.c
Implemented "access level required to create rooms" (client & server)
[citadel.git] / citadel / room_ops.c
index 7c9ee502c5c95096c60c1437c22e663271ebc94f..5efcdc72435c6d479cf0708824955147b3ed84a9 100644 (file)
@@ -1,12 +1,16 @@
 /* $Id$ */
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <string.h>
+#ifdef HAVE_PTHREAD_H
 #include <pthread.h>
+#endif
 #include <time.h>
 #include <limits.h>
+#include <errno.h>
 #include "citadel.h"
 #include "server.h"
 #include "database.h"
@@ -117,6 +121,22 @@ NEWMSG:    /* By the way, we also check for the presence of new messages */
        return(retval);
        }
 
+/*
+ * Self-checking stuff for a room record read into memory
+ */
+void room_sanity_check(struct quickroom *qrbuf) {
+       /* Mailbox rooms are always on the lowest floor */
+       if (qrbuf->QRflags & QR_MAILBOX) {
+               qrbuf->QRfloor = 0;
+               }
+
+       /* Listing order of 0 is illegal except for base rooms */
+       if (qrbuf->QRorder == 0)
+               if (!is_noneditable(qrbuf))
+                       qrbuf->QRorder = 64;
+       }
+
+
 /*
  * getroom()  -  retrieve room data from disk
  */
@@ -140,10 +160,7 @@ int getroom(struct quickroom *qrbuf, char *room_name)
                        sizeof(struct quickroom) : cdbqr->len) );
                cdb_free(cdbqr);
 
-               /* Mailbox rooms are always on the lowest floor */
-               if (qrbuf->QRflags & QR_MAILBOX) {
-                       qrbuf->QRfloor = 0;
-                       }
+               room_sanity_check(qrbuf);
 
                return(0);
                }
@@ -274,6 +291,7 @@ void ForEachRoom(void (*CallBack)(struct quickroom *EachRoom)) {
                        ( (cdbqr->len > sizeof(struct quickroom)) ?
                        sizeof(struct quickroom) : cdbqr->len) );
                cdb_free(cdbqr);
+               room_sanity_check(&qrbuf);
                if (qrbuf.QRflags & QR_INUSE) (*CallBack)(&qrbuf);
                }
        }
@@ -377,7 +395,7 @@ long AddMessageToRoom(struct quickroom *whichroom, long newmsgid) {
                msglist, num_msgs * sizeof(long));
 
        /* And finally, free up the memory we used. */
-       free(msglist);
+       phree(msglist);
        return(highest_msg);
        }
 
@@ -478,8 +496,10 @@ void list_roomname(struct quickroom *qrbuf) {
                }
 
        /* ...and now the other parameters */
-       cprintf("|%u|%d\n",
-               qrbuf->QRflags,qrbuf->QRfloor);
+       cprintf("|%u|%d|%d\n",
+               qrbuf->QRflags,
+               (int)qrbuf->QRfloor,
+               (int)qrbuf->QRorder);
        }
 
 
@@ -676,11 +696,15 @@ void usergoto(char *where, int display_result)
 
        strcpy(CC->quickroom.QRname, where);
        getroom(&CC->quickroom, where);
+
        lgetuser(&CC->usersupp,CC->curr_user);
        CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
 
-       vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
-       vbuf.v_flags = vbuf.v_flags | V_ACCESS;
+       /* Know the room ... but not if it's the page log room */
+       if (strcasecmp(where, config.c_logpages)) {
+               vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
+               vbuf.v_flags = vbuf.v_flags | V_ACCESS;
+               }
 
        CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
        lputuser(&CC->usersupp,CC->curr_user);
@@ -931,13 +955,14 @@ void cmd_getr(void) {
                }
 
        getroom(&CC->quickroom, CC->quickroom.QRname);
-       cprintf("%d%c%s|%s|%s|%d|%d\n",
+       cprintf("%d%c%s|%s|%s|%d|%d|%d\n",
                OK,check_express(),
                CC->quickroom.QRname,
                ((CC->quickroom.QRflags & QR_PASSWORDED) ? CC->quickroom.QRpasswd : ""),
                ((CC->quickroom.QRflags & QR_DIRECTORY) ? CC->quickroom.QRdirname : ""),
                CC->quickroom.QRflags,
-               (int)CC->quickroom.QRfloor);
+               (int)CC->quickroom.QRfloor,
+               (int)CC->quickroom.QRorder);
        }
 
 
@@ -949,6 +974,7 @@ void cmd_setr(char *args) {
        struct floor flbuf;
        char old_name[ROOMNAMELEN];
        int old_floor;
+       int new_order = 0;
 
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
@@ -975,6 +1001,12 @@ void cmd_setr(char *args) {
                        }
                }
 
+       if (num_parms(args)>=7) {
+               new_order = extract_int(args, 6);
+               if (new_order < 1) new_order = 1;
+               if (new_order > 127) new_order = 127;
+               }
+
        lgetroom(&CC->quickroom, CC->quickroom.QRname);
        strcpy(old_name, CC->quickroom.QRname);
        extract(buf,args,0); buf[ROOMNAMELEN]=0;
@@ -984,6 +1016,8 @@ void cmd_setr(char *args) {
        extract(buf,args,2); buf[15]=0;
        strncpy(CC->quickroom.QRdirname,buf,19);
        CC->quickroom.QRflags = ( extract_int(args,3) | QR_INUSE);
+       if (num_parms(args)>=7)
+               CC->quickroom.QRorder = (char)new_order;
 
        /* Clean up a client boo-boo: if the client set the room to
         * guess-name or passworded, ensure that the private flag is
@@ -1345,7 +1379,7 @@ void cmd_cre8(char *args)
                return;
                }
 
-       if (CC->usersupp.axlevel<3) {
+       if (CC->usersupp.axlevel < config.c_createax) {
                cprintf("%d You need higher access to create rooms.\n",
                        ERROR+HIGHER_ACCESS_REQUIRED);
                return;