summaryrefslogtreecommitdiffstats
path: root/src/lib/mkdir-parents.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib/mkdir-parents.h
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/mkdir-parents.h')
-rw-r--r--src/lib/mkdir-parents.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/mkdir-parents.h b/src/lib/mkdir-parents.h
new file mode 100644
index 0000000..9b5ddf0
--- /dev/null
+++ b/src/lib/mkdir-parents.h
@@ -0,0 +1,33 @@
+#ifndef MKDIR_PARENTS_H
+#define MKDIR_PARENTS_H
+
+#include <sys/stat.h>
+
+/* Create path and all the directories under it if needed. Permissions for
+ existing directories isn't changed. Returns 0 if ok. If directory already
+ exists, returns -1 with errno=EEXIST. */
+int mkdir_parents(const char *path, mode_t mode);
+
+/* Like mkdir_parents(), but use the given uid/gid for newly created
+ directories. (uid_t)-1 or (gid_t)-1 can be used to indicate that it
+ doesn't need to be changed. If gid isn't (gid_t)-1 and the parent directory
+ had setgid-bit enabled, it's removed unless explicitly included in the
+ mode. */
+int mkdir_parents_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
+/* Like mkdir_parents_chown(), but change only group. If chown() fails with
+ EACCES, use gid_origin in the error message. */
+int mkdir_parents_chgrp(const char *path, mode_t mode,
+ gid_t gid, const char *gid_origin);
+
+/* Like mkdir_parents_chown(), but don't actually create any parents. */
+int mkdir_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
+int mkdir_chgrp(const char *path, mode_t mode,
+ gid_t gid, const char *gid_origin);
+
+/* stat() the path or its first parent that exists. Returns 0 if ok, -1 if
+ failed. root_dir is set to the last stat()ed directory (on success and
+ on failure). */
+int stat_first_parent(const char *path, const char **root_dir_r,
+ struct stat *st_r);
+
+#endif