From 192117806435453b6008edde07261fd41305e059 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 1 Sep 2013 18:12:25 +0200 Subject: [PATCH] Move user privileges functions to user_ops.c, room access check functions to room_ops.c --- citadel/modules/imap/imap_misc.c | 1 + citadel/modules/imap/imap_store.c | 1 + citadel/modules/smtp/serv_smtp.c | 1 + citadel/modules/vcard/serv_vcard.c | 1 + citadel/modules/wiki/serv_wiki.c | 1 + citadel/msgbase.c | 126 ----------------------------- citadel/msgbase.h | 17 ---- citadel/room_ops.c | 99 +++++++++++++++++++++++ citadel/room_ops.h | 15 ++++ citadel/user_ops.c | 23 ++++++ citadel/user_ops.h | 1 + 11 files changed, 143 insertions(+), 143 deletions(-) diff --git a/citadel/modules/imap/imap_misc.c b/citadel/modules/imap/imap_misc.c index 14d2396c7..5485836a9 100644 --- a/citadel/modules/imap/imap_misc.c +++ b/citadel/modules/imap/imap_misc.c @@ -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" diff --git a/citadel/modules/imap/imap_store.c b/citadel/modules/imap/imap_store.c index 5685e2392..8c4188bdb 100644 --- a/citadel/modules/imap/imap_store.c +++ b/citadel/modules/imap/imap_store.c @@ -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" diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index f21e9d16e..d96cda9bd 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -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" diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index 9b49782bf..393cf7210 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -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" diff --git a/citadel/modules/wiki/serv_wiki.c b/citadel/modules/wiki/serv_wiki.c index e9db40985..79a961f45 100644 --- a/citadel/modules/wiki/serv_wiki.c +++ b/citadel/modules/wiki/serv_wiki.c @@ -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" diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 405790cb4..052f06fca 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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 */ diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 645e5f744..11a46d6ea 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -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); /* diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 010fa1276..29fa36971 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -53,6 +53,105 @@ 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 */ diff --git a/citadel/room_ops.h b/citadel/room_ops.h index f4c7cf527..20a843654 100644 --- a/citadel/room_ops.h +++ b/citadel/room_ops.h @@ -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); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index fd8056559..7c7e226a7 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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? */ diff --git a/citadel/user_ops.h b/citadel/user_ops.h index 3afe55013..03133c2a3 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -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); -- 2.30.2