]> code.citadel.org Git - citadel.git/blobdiff - citadel/room_ops.c
More of me not being able to look at code without poking around changing everything...
[citadel.git] / citadel / room_ops.c
index 1e3f787fe33dc955203edc2443fad89bcc53dd0f..078dc4ab533d41b6660a76d01d5e565511af87f0 100644 (file)
@@ -1,16 +1,14 @@
-/* 
- * Server functions which perform operations on room objects.
- *
- * Copyright (c) 1987-2021 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
+// Server functions which perform operations on room objects.
+//
+// Copyright (c) 1987-2022 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.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 
 #include <stdio.h>
 #include <libcitadel.h>
 
 struct floor *floorcache[MAXFLOORS];
 
-/* 
- * Determine whether the currently logged in session has permission to read
- * messages in the current room.
- */
+// Determine whether the currently logged in session has permission to read
+// messages in the current room.
 int CtdlDoIHavePermissionToReadMessagesInThisRoom(void) {
        if (    (!(CC->logged_in))
                && (!(CC->internal_pgm))
@@ -39,11 +35,9 @@ int CtdlDoIHavePermissionToReadMessagesInThisRoom(void) {
 }
 
 
-/*
- * Check to see whether we have permission to post a message in the current
- * room.  Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or
- * returns 0 on success.
- */
+// Check to see whether we have permission to post a message in the current
+// room.  Returns a *CITADEL ERROR CODE* and puts a message in errmsgbuf, or
+// returns 0 on success.
 int CtdlDoIHavePermissionToPostInThisRoom(
        char *errmsgbuf, 
        size_t n, 
@@ -57,7 +51,7 @@ int CtdlDoIHavePermissionToPostInThisRoom(
                snprintf(errmsgbuf, n, "Not logged in.");
                return (ERROR + NOT_LOGGED_IN);
        }
-       else if (PostPublic == CHECK_EXISTANCE) {
+       else if (PostPublic == CHECK_EXIST) {
                return (0);                                     // evaluate whether a recipient exists
        }
        else if (!(CC->logged_in)) {
@@ -65,14 +59,6 @@ int CtdlDoIHavePermissionToPostInThisRoom(
                        snprintf(errmsgbuf, n, "Not logged in.");
                        return (ERROR + NOT_LOGGED_IN);
                }
-               if (CC->room.QRflags2 & QR2_MODERATED) {
-                       snprintf(errmsgbuf, n, "Not logged in Moderation feature not yet implemented!");
-                       return (ERROR + NOT_LOGGED_IN);
-               }
-               // FIXME what was this?  AJC 2021
-               //if ((PostPublic != POST_LMTP) && (CC->room.QRflags2 & QR2_SMTP_PUBLIC) == 0) {
-                       //return CtdlNetconfigCheckRoomaccess(errmsgbuf, n, RemoteIdentifier);
-               //}
                return (0);
        }
 
@@ -89,17 +75,15 @@ int CtdlDoIHavePermissionToPostInThisRoom(
        }
 
        if ( (ra & UA_REPLYALLOWED) && (is_reply) ) {
-               /*
-                * To be thorough, we ought to check to see if the message they are
-                * replying to is actually a valid one in this room, but unless this
-                * actually becomes a problem we'll go with high performance instead.
-                */
+               // To be thorough, we ought to check to see if the message they are
+               // replying to is actually a valid one in this room, but unless this
+               // actually becomes a problem we'll go with high performance instead.
                strcpy(errmsgbuf, "OK to reply here");
                return(0);
        }
 
        if ( (ra & UA_REPLYALLOWED) && (!is_reply) ) {
-               /* Clarify what happened with a better error message */
+               // Clarify what happened with a better error message
                snprintf(errmsgbuf, n, "You may only reply to existing messages here.");
                return (ERROR + HIGHER_ACCESS_REQUIRED);
        }
@@ -220,13 +204,11 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *res
 
        /* For non-mailbox rooms... */
        else {
-
-               /* User is allowed to post in the room unless:
-                * - User is not validated
-                * - User has no net privileges and it is a shared network room
-                * - It is a read-only room
-                * - It is a blog room (in which case we only allow replies to existing messages)
-                */
+               // User is allowed to post in the room unless:
+               // - User is not validated
+               // - User has no net privileges and it is a shared network room
+               // - It is a read-only room
+               // - It is a blog room (in which case we only allow replies to existing messages)
                int post_allowed = 1;
                int reply_allowed = 1;
                if (userbuf->axlevel < AxProbU) {
@@ -251,9 +233,8 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *res
                        retval = retval | UA_REPLYALLOWED;
                }
 
-               /* If "collaborative deletion" is active for this room, any user who can post
-                * is also allowed to delete
-                */
+               // If "collaborative deletion" is active for this room, any user who can post
+               // is also allowed to delete
                if (roombuf->QRflags2 & QR2_COLLABDEL) {
                        if (retval & UA_POSTALLOWED) {
                                retval = retval | UA_DELETEALLOWED;
@@ -291,16 +272,14 @@ void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *res
                }
        }
 
-       /* Aides can gain access to mailboxes as well, but they don't show
-        * by default.
-        */
+       // Aides can gain access to mailboxes as well, but they don't show by default.
        if (    (userbuf->axlevel >= AxAideU)
                && (roombuf->QRflags & QR_MAILBOX)
        ) {
                retval = retval | UA_GOTOALLOWED | UA_POSTALLOWED | UA_REPLYALLOWED;
        }
 
-       /* Aides and Room Aides have admin privileges */
+       // Aides and Room Aides have admin privileges
        if (    (userbuf->axlevel >= AxAideU)
                || (userbuf->usernum == roombuf->QRroomaide)
        ) {
@@ -333,13 +312,14 @@ void room_sanity_check(struct ctdlroom *qrbuf) {
                qrbuf->QRfloor = 0;
        }
        /* Listing order of 0 is illegal except for base rooms */
-       if (qrbuf->QRorder == 0)
+       if (qrbuf->QRorder == 0) {
                if (    !(qrbuf->QRflags & QR_MAILBOX)
                        && strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_baseroom"), ROOMNAMELEN)
                        && strncasecmp(qrbuf->QRname, CtdlGetConfigStr("c_aideroom"), ROOMNAMELEN)
                ) {
                        qrbuf->QRorder = 64;
                }
+       }
 }
 
 
@@ -364,6 +344,10 @@ int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name) {
 
        memset(qrbuf, 0, sizeof(struct ctdlroom));
 
+       if (IsEmptyStr(lowercase_name)) {
+               return(1);                      // empty room name , not valid
+       }
+
        /* First, try the public namespace */
        cdbqr = cdb_fetch(CDB_ROOMS, lowercase_name, strlen(lowercase_name));
 
@@ -603,6 +587,7 @@ void lputfloor(struct floor *flbuf, int floor_num) {
        CtdlPutFloorLock(flbuf, floor_num);
 }
 
+
 /* 
  * Iterate through the room table, performing a callback for each room.
  */
@@ -696,7 +681,6 @@ int CtdlIsNonEditable(struct ctdlroom *qrbuf) {
 }
 
 
-
 /*
  * Make the specified room the current room for this session.  No validation
  * or access control is done here -- the caller should make sure that the
@@ -1068,26 +1052,25 @@ void CtdlDeleteRoom(struct ctdlroom *qrbuf) {
 
        syslog(LOG_NOTICE, "room_ops: deleting room <%s>", qrbuf->QRname);
 
-       /* Delete the room's network configdb entry */
+       // Delete the room's network configdb entry
        netcfg_keyname(configdbkeyname, qrbuf->QRnumber);
        CtdlDelConfig(configdbkeyname);
 
-       /* Delete the messages in the room
-        * (Careful: this opens an S_ROOMS critical section!)
-        */
+       // Delete the messages in the room
+       // (Careful: this opens an S_ROOMS critical section!)
        CtdlDeleteMessages(qrbuf->QRname, NULL, 0, "");
 
-       /* Flag the room record as not in use */
+       // Flag the room record as not in use
        CtdlGetRoomLock(qrbuf, qrbuf->QRname);
        qrbuf->QRflags = 0;
        CtdlPutRoomLock(qrbuf);
 
-       /* then decrement the reference count for the floor */
+       // then decrement the reference count for the floor
        lgetfloor(&flbuf, (int) (qrbuf->QRfloor));
        flbuf.f_ref_count = flbuf.f_ref_count - 1;
        lputfloor(&flbuf, (int) (qrbuf->QRfloor));
 
-       /* Delete the room record from the database! */
+       // Delete the room record from the database!
        b_deleteroom(qrbuf->QRname);
 }