Move user privileges functions to user_ops.c, room access check functions to room_ops.c
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 1 Sep 2013 16:12:25 +0000 (18:12 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 1 Sep 2013 16:12:25 +0000 (18:12 +0200)
citadel/modules/imap/imap_misc.c
citadel/modules/imap/imap_store.c
citadel/modules/smtp/serv_smtp.c
citadel/modules/vcard/serv_vcard.c
citadel/modules/wiki/serv_wiki.c
citadel/msgbase.c
citadel/msgbase.h
citadel/room_ops.c
citadel/room_ops.h
citadel/user_ops.c
citadel/user_ops.h

index 14d2396c7e54480329f006906ca78abb620f0fa2..5485836a9666de4984d61fcc90905be3e732a3e9 100644 (file)
@@ -52,6 +52,7 @@
 #include "user_ops.h"
 #include "database.h"
 #include "msgbase.h"
+#include "room_ops.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
index 5685e239225f39a05c5ec8a73cc2e18721e32619..8c4188bdbb93118c01f8b881662f4342ff3457f1 100644 (file)
@@ -53,6 +53,7 @@
 #include "config.h"
 #include "user_ops.h"
 #include "database.h"
+#include "room_ops.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
index f21e9d16ecd55c82de1a2a4f9c414314b393c12e..d96cda9bd84eb8b1d3870b75bea230b32df0960d 100644 (file)
@@ -69,6 +69,7 @@
 #include "config.h"
 #include "control.h"
 #include "user_ops.h"
+#include "room_ops.h"
 #include "database.h"
 #include "msgbase.h"
 #include "internet_addressing.h"
index 9b49782bfcc69c051991844808ba8580cc5d2859..393cf72101fbfd3fc1d1ebc58810234b6b7df84c 100644 (file)
@@ -63,6 +63,7 @@
 #include "user_ops.h"
 #include "database.h"
 #include "msgbase.h"
+#include "room_ops.h"
 #include "internet_addressing.h"
 #include "serv_vcard.h"
 #include "citadel_ldap.h"
index e9db40985e506b7650d3ff87add358e6f5657963..79a961f451ed1ae289435db0586cbb8dcef6f107 100644 (file)
@@ -45,6 +45,7 @@
 #include "config.h"
 #include "control.h"
 #include "user_ops.h"
+#include "room_ops.h"
 #include "database.h"
 #include "msgbase.h"
 #include "euidindex.h"
index 405790cb43ded6e5b56871264ae5f2931eec99be..052f06fcaf78ef88d830e5530cc742f020aaacda 100644 (file)
@@ -1795,20 +1795,6 @@ int check_cached_msglist(long msgnum) {
 }
 
 
-/* 
- * 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))
-               && (!config.c_guest_logins)
-       ) {
-               return(om_not_logged_in);
-       }
-       return(om_ok);
-}
-
 
 /*
  * Get a message off disk.  (returns om_* values found in msgbase.h)
@@ -4182,102 +4168,6 @@ struct CtdlMessage *CtdlMakeMessage(
        return(msg);
 }
 
-/*
- * 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, 
-       const char* RemoteIdentifier,
-       int PostPublic,
-       int is_reply
-       ) {
-       int ra;
-
-       if (!(CC->logged_in) && 
-           (PostPublic == POST_LOGGED_IN)) {
-               snprintf(errmsgbuf, n, "Not logged in.");
-               return (ERROR + NOT_LOGGED_IN);
-       }
-       else if (PostPublic == CHECK_EXISTANCE) {
-               return (0); // We're Evaling whether a recipient exists
-       }
-       else if (!(CC->logged_in)) {
-               
-               if ((CC->room.QRflags & QR_READONLY)) {
-                       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);
-               }
-               if ((PostPublic!=POST_LMTP) &&(CC->room.QRflags2 & QR2_SMTP_PUBLIC) == 0) {
-
-                       return CtdlNetconfigCheckRoomaccess(errmsgbuf, n, RemoteIdentifier);
-               }
-               return (0);
-
-       }
-
-       if ((CC->user.axlevel < AxProbU)
-           && ((CC->room.QRflags & QR_MAILBOX) == 0)) {
-               snprintf(errmsgbuf, n, "Need to be validated to enter (except in %s> to sysop)", MAILROOM);
-               return (ERROR + HIGHER_ACCESS_REQUIRED);
-       }
-
-       CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
-
-       if (ra & UA_POSTALLOWED) {
-               strcpy(errmsgbuf, "OK to post or reply here");
-               return(0);
-       }
-
-       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.
-                */
-               strcpy(errmsgbuf, "OK to reply here");
-               return(0);
-       }
-
-       if ( (ra & UA_REPLYALLOWED) && (!is_reply) ) {
-               /* Clarify what happened with a better error message */
-               snprintf(errmsgbuf, n, "You may only reply to existing messages here.");
-               return (ERROR + HIGHER_ACCESS_REQUIRED);
-       }
-
-       snprintf(errmsgbuf, n, "Higher access is required to post in this room.");
-       return (ERROR + HIGHER_ACCESS_REQUIRED);
-
-}
-
-
-/*
- * Check to see if the specified user has Internet mail permission
- * (returns nonzero if permission is granted)
- */
-int CtdlCheckInternetMailPermission(struct ctdluser *who) {
-
-       /* Do not allow twits to send Internet mail */
-       if (who->axlevel <= AxProbU) return(0);
-
-       /* Globally enabled? */
-       if (config.c_restrict == 0) return(1);
-
-       /* User flagged ok? */
-       if (who->flags & US_INTERNET) return(2);
-
-       /* Admin level access? */
-       if (who->axlevel >= AxAideU) return(3);
-
-       /* No mail for you! */
-       return(0);
-}
 
 
 /*
@@ -5046,22 +4936,6 @@ int CtdlDeleteMessages(char *room_name,          /* which room */
        return (num_deleted);
 }
 
-
-
-/*
- * Check whether the current user has permission to delete messages from
- * the current room (returns 1 for yes, 0 for no)
- */
-int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void) {
-       int ra;
-       CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
-       if (ra & UA_DELETEALLOWED) return(1);
-       return(0);
-}
-
-
-
-
 /*
  * Delete message from current room
  */
index 645e5f7442ee1db5aadecbfe81cf037be9441d37..11a46d6ea544afab8b3432ee00b78e953ad37c8c 100644 (file)
@@ -218,22 +218,6 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
                           int crlf,            /* 0=LF, 1=CRLF */
                           int flags            /* should the bessage be exported clean? */
 );
-int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
-int CtdlDoIHavePermissionToReadMessagesInThisRoom(void);
-
-enum {
-       POST_LOGGED_IN,
-       POST_EXTERNAL,
-       CHECK_EXISTANCE,
-       POST_LMTP
-};
-
-int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, 
-       size_t n, 
-       const char* RemoteIdentifier,
-       int PostPublic,
-       int is_reply
-);
 
 
 /* values for which_set */
@@ -266,7 +250,6 @@ struct CtdlMessage *CtdlMakeMessage(
         char *preformatted_text,        /* ...or NULL to read text from client */
        char *references                /* Thread references */
 );
-int CtdlCheckInternetMailPermission(struct ctdluser *who);
 int CtdlIsMe(char *addr, int addr_buf_len);
 
 /* 
index 010fa12766a3e617e9adbe6df7de2395e9d1bb20..29fa36971788043db962f3cb47ccec23928e701c 100644 (file)
 
 struct floor *floorcache[MAXFLOORS];
 
+/* 
+ * 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))
+               && (!config.c_guest_logins)
+       ) {
+               return(om_not_logged_in);
+       }
+       return(om_ok);
+}
+
+/*
+ * 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, 
+       const char* RemoteIdentifier,
+       PostType PostPublic,
+       int is_reply
+       ) {
+       int ra;
+
+       if (!(CC->logged_in) && 
+           (PostPublic == POST_LOGGED_IN)) {
+               snprintf(errmsgbuf, n, "Not logged in.");
+               return (ERROR + NOT_LOGGED_IN);
+       }
+       else if (PostPublic == CHECK_EXISTANCE) {
+               return (0); // We're Evaling whether a recipient exists
+       }
+       else if (!(CC->logged_in)) {
+               
+               if ((CC->room.QRflags & QR_READONLY)) {
+                       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);
+               }
+               if ((PostPublic!=POST_LMTP) &&(CC->room.QRflags2 & QR2_SMTP_PUBLIC) == 0) {
+
+                       return CtdlNetconfigCheckRoomaccess(errmsgbuf, n, RemoteIdentifier);
+               }
+               return (0);
+
+       }
+
+       if ((CC->user.axlevel < AxProbU)
+           && ((CC->room.QRflags & QR_MAILBOX) == 0)) {
+               snprintf(errmsgbuf, n, "Need to be validated to enter (except in %s> to sysop)", MAILROOM);
+               return (ERROR + HIGHER_ACCESS_REQUIRED);
+       }
+
+       CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
+
+       if (ra & UA_POSTALLOWED) {
+               strcpy(errmsgbuf, "OK to post or reply here");
+               return(0);
+       }
+
+       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.
+                */
+               strcpy(errmsgbuf, "OK to reply here");
+               return(0);
+       }
+
+       if ( (ra & UA_REPLYALLOWED) && (!is_reply) ) {
+               /* Clarify what happened with a better error message */
+               snprintf(errmsgbuf, n, "You may only reply to existing messages here.");
+               return (ERROR + HIGHER_ACCESS_REQUIRED);
+       }
+
+       snprintf(errmsgbuf, n, "Higher access is required to post in this room.");
+       return (ERROR + HIGHER_ACCESS_REQUIRED);
+
+}
+
+/*
+ * Check whether the current user has permission to delete messages from
+ * the current room (returns 1 for yes, 0 for no)
+ */
+int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void) {
+       int ra;
+       CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
+       if (ra & UA_DELETEALLOWED) return(1);
+       return(0);
+}
+
 /*
  * Retrieve access control information for any user/room pair
  */
index f4c7cf527c0e35f2261d83b580eb96b58cd84c41..20a8436541e6b2a752466ad86126cd0a1b02a145 100644 (file)
@@ -14,3 +14,18 @@ void list_roomname(struct ctdlroom *qrbuf, int ra, int current_view, int default
 void convert_room_name_macros(char *towhere, size_t maxlen);
 
 
+typedef enum _POST_TYPE{
+       POST_LOGGED_IN,
+       POST_EXTERNAL,
+       CHECK_EXISTANCE,
+       POST_LMTP
+}PostType;
+
+int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, 
+       size_t n, 
+       const char* RemoteIdentifier,
+       PostType PostPublic,
+       int is_reply
+);
+int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
+int CtdlDoIHavePermissionToReadMessagesInThisRoom(void);
index fd8056559c4ba479eaec5eb8570c63ebf11ca47c..7c7e226a779bb26b9198ce11b030ca97df025d1d 100644 (file)
@@ -368,6 +368,29 @@ void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *pr
 }
 
 
+/*
+ * Check to see if the specified user has Internet mail permission
+ * (returns nonzero if permission is granted)
+ */
+int CtdlCheckInternetMailPermission(struct ctdluser *who) {
+
+       /* Do not allow twits to send Internet mail */
+       if (who->axlevel <= AxProbU) return(0);
+
+       /* Globally enabled? */
+       if (config.c_restrict == 0) return(1);
+
+       /* User flagged ok? */
+       if (who->flags & US_INTERNET) return(2);
+
+       /* Admin level access? */
+       if (who->axlevel >= AxAideU) return(3);
+
+       /* No mail for you! */
+       return(0);
+}
+
+
 /*
  * Is the user currently logged in an Admin?
  */
index 3afe55013250e39fcaf495079f9db904e453661e..03133c2a384674796f6b59ffe6b58780dc680c5b 100644 (file)
@@ -14,6 +14,7 @@ void putuser (struct ctdluser *) __attribute__ ((deprecated));
 void lputuser (struct ctdluser *) __attribute__ ((deprecated));
 int is_aide (void);
 int is_room_aide (void);
+int CtdlCheckInternetMailPermission(struct ctdluser *who);
 /* getuserbynumber is deprecated, use CtdlGetUserByNumber instead */
 int getuserbynumber (struct ctdluser *usbuf, long int number) __attribute__ ((deprecated));
 void rebuild_usersbynumber(void);