summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/util.c
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2012-07-12 08:51:44 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2012-07-12 08:51:44 +0000
commit9f54542debb76e221205d8e0c355fb8f04cff66d (patch)
treea4255a3cca2c9c3fd47e41e5321f22121855da0a /usr.sbin/smtpd/util.c
parent9f028027b87696fcb7ebed94f66e6c23c36ccf0d (diff)
add support for maildir tagging/folders.
ok gilles@ ok eric@ on previous versions of this patch
Diffstat (limited to 'usr.sbin/smtpd/util.c')
-rw-r--r--usr.sbin/smtpd/util.c86
1 files changed, 85 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index e53a2d8d0f9..96e8350264e 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.65 2012/07/11 22:16:45 chl Exp $ */
+/* $OpenBSD: util.c,v 1.66 2012/07/12 08:51:43 chl Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -18,6 +18,37 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+/* the mkdir_p() function is based on bin/mkdir/mkdir.c that is covered
+ * by the following license: */
+/*
+ * Copyright (c) 1983, 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/queue.h>
@@ -69,6 +100,59 @@ bsnprintf(char *str, size_t size, const char *format, ...)
return 1;
}
+/*
+ * mkdir -p. Based on bin/mkdir/mkdir.c:mkpath()
+ */
+int
+mkdir_p(char *path, mode_t mode)
+{
+ struct stat sb;
+ char *slash;
+ int done, exists;
+ mode_t dir_mode;
+
+ dir_mode = mode | S_IWUSR | S_IXUSR;
+
+ slash = path;
+
+ for (;;) {
+ slash += strspn(slash, "/");
+ slash += strcspn(slash, "/");
+
+ done = (*slash == '\0');
+ *slash = '\0';
+
+ /* skip existing path components */
+ exists = !stat(path, &sb);
+ if (!done && exists && S_ISDIR(sb.st_mode)) {
+ *slash = '/';
+ continue;
+ }
+
+ if (mkdir(path, done ? mode : dir_mode) == 0) {
+ if (mode > 0777 && chmod(path, mode) < 0)
+ return (-1);
+ } else {
+ if (!exists) {
+ /* Not there */
+ return (-1);
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ /* Is there, but isn't a directory */
+ errno = ENOTDIR;
+ return (-1);
+ }
+ }
+
+ if (done)
+ break;
+
+ *slash = '/';
+ }
+
+ return (0);
+}
+
int
ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
{