[dovecot-cvs] dovecot/src/lib-storage mailbox-list-private.h, 1.5, 1.6 mailbox-list.c, 1.15, 1.16 mailbox-list.h, 1.8, 1.9
tss at dovecot.org
tss at dovecot.org
Wed Apr 11 22:28:25 EEST 2007
Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv4149
Modified Files:
mailbox-list-private.h mailbox-list.c mailbox-list.h
Log Message:
Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Index: mailbox-list-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list-private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- mailbox-list-private.h 11 Apr 2007 10:55:34 -0000 1.5
+++ mailbox-list-private.h 11 Apr 2007 19:28:23 -0000 1.6
@@ -73,6 +73,10 @@
struct mailbox_list_settings set;
enum mailbox_list_flags flags;
+ /* -1 if unset: */
+ uid_t cached_uid;
+ gid_t cached_gid;
+
char *error;
bool temporary_error;
Index: mailbox-list.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- mailbox-list.c 11 Apr 2007 10:55:34 -0000 1.15
+++ mailbox-list.c 11 Apr 2007 19:28:23 -0000 1.16
@@ -8,7 +8,9 @@
#include "mailbox-list-private.h"
#include <time.h>
+#include <unistd.h>
#include <dirent.h>
+#include <sys/stat.h>
/* 20 * (200+1) < 4096 which is the standard PATH_MAX. Having these settings
prevents malicious user from creating eg. "a/a/a/.../a" mailbox name and
@@ -97,6 +99,8 @@
list->ns = ns;
list->flags = flags;
+ list->cached_uid = (uid_t)-1;
+ list->cached_gid = (gid_t)-1;
/* copy settings */
list->set.root_dir = p_strdup(list->pool, set->root_dir);
@@ -200,6 +204,43 @@
return list->v.get_path(list, name, type);
}
+int mailbox_list_get_permissions(struct mailbox_list *list, const char *name,
+ mode_t *mode_r, uid_t *uid_r, gid_t *gid_r)
+{
+ const char *path;
+ struct stat st;
+
+ mailbox_list_clear_error(list);
+
+ path = mailbox_list_get_path(list, name,
+ MAILBOX_LIST_PATH_TYPE_MAILBOX);
+ if (*path == '\0')
+ return -1;
+
+ if (stat(path, &st) < 0) {
+ if (ENOTFOUND(errno))
+ return 0;
+ mailbox_list_set_critical(list, "stat(%s) failed: %m", path);
+ return -1;
+ }
+
+ *mode_r = st.st_mode & 0666;
+
+ if (list->cached_uid == (uid_t)-1)
+ list->cached_uid = geteuid();
+ *uid_r = list->cached_uid == st.st_uid ? (uid_t)-1 : st.st_uid;
+
+ if (S_ISDIR(st.st_mode) && (st.st_mode & S_ISGID) != 0) {
+ /* directory's GID is used automatically for new files */
+ *gid_r = (gid_t)-1;
+ } else {
+ if (list->cached_gid == (gid_t)-1)
+ list->cached_gid = getegid();
+ *gid_r = list->cached_gid == st.st_gid ? (gid_t)-1 : st.st_gid;
+ }
+ return 1;
+}
+
const char *mailbox_list_get_temp_prefix(struct mailbox_list *list)
{
return list->v.get_temp_prefix(list);
Index: mailbox-list.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mailbox-list.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mailbox-list.h 11 Apr 2007 10:55:34 -0000 1.8
+++ mailbox-list.h 11 Apr 2007 19:28:23 -0000 1.9
@@ -39,7 +39,9 @@
/* Don't return any flags unless it can be done without cost */
MAILBOX_LIST_ITER_FAST_FLAGS = 0x02,
/* Return children flags */
- MAILBOX_LIST_ITER_CHILDREN = 0x04
+ MAILBOX_LIST_ITER_CHILDREN = 0x04,
+ /* Ignore index file and ACLs (used by ACL plugin internally) */
+ MAILBOX_LIST_ITER_RAW_LIST = 0x08
};
enum mailbox_list_path_type {
@@ -124,6 +126,13 @@
For INDEX=MEMORY it returns "" as the path. */
const char *mailbox_list_get_path(struct mailbox_list *list, const char *name,
enum mailbox_list_path_type type);
+/* Returns the mode, UID and GID that should be used when creating new files
+ to the given mailbox. (uid_t)-1 and (gid_t)-1 is returned if it's not
+ necessary to change the default UID or GID. The name must be a valid
+ existing mailbox name, or NULL to get global permissions.
+ Returns -1 if error, 0 if mailbox not found, 1 if ok. */
+int mailbox_list_get_permissions(struct mailbox_list *list, const char *name,
+ mode_t *mode_r, uid_t *uid_r, gid_t *gid_r);
/* Returns mailbox name status */
int mailbox_list_get_mailbox_name_status(struct mailbox_list *list,
const char *name,
More information about the dovecot-cvs
mailing list