mkdir-parents.c revision b710c5119d3b66572eb87a15ac6d8dcd192f7cc5
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Copyright (c) 2003-2010 Dovecot authors, see the included COPYING file */
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschmkdir_chown_full(const char *path, mode_t mode, uid_t uid,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* EISDIR check is for BSD/OS which returns it if path
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch contains '/' at the end and it exists.
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch ENOSYS check is for NFS mount points. */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_error("%s", eperm_error_get_chgrp("chown", path, gid,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint mkdir_chown(const char *path, mode_t mode, uid_t uid, gid_t gid)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return mkdir_chown_full(path, mode, uid, gid, NULL);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen return mkdir_chown_full(path, mode, (uid_t)-1, gid, gid_origin);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschmkdir_parents_chown_full(const char *path, mode_t mode, uid_t uid, gid_t gid,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch const char *p;
dc05b1fb4b7a2b4d91248078311458cb4cbad9a1Stephan Bosch if (mkdir_chown_full(path, mode, uid, gid, gid_origin) < 0) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* doesn't exist, try recursively creating our parent dir */
201c3b9375760bafbc180629b4c6ad71ed554aecStephan Bosch ret = mkdir_parents_chown_full(t_strdup_until(path, p),
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* should work now */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (mkdir_chown_full(path, mode, uid, gid, gid_origin) < 0)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint mkdir_parents_chown(const char *path, mode_t mode, uid_t uid, gid_t gid)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return mkdir_parents_chown_full(path, mode, uid, gid, NULL);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint mkdir_parents_chgrp(const char *path, mode_t mode,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return mkdir_parents_chown_full(path, mode, (uid_t)-1, gid, gid_origin);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint mkdir_parents(const char *path, mode_t mode)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch return mkdir_parents_chown(path, mode, (uid_t)-1, (gid_t)-1);