summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2012-09-16 11:53:57 +0000
committergilles <gilles@openbsd.org>2012-09-16 11:53:57 +0000
commitfc240c156ad9ef53f858535168362db4724cde70 (patch)
tree513fb4e96d1faa02436e4c64f0ac527cdb0a32a1
parentremove the thread_private hack. (diff)
downloadwireguard-openbsd-fc240c156ad9ef53f858535168362db4724cde70.tar.xz
wireguard-openbsd-fc240c156ad9ef53f858535168362db4724cde70.zip
replace BSD-licensed mkdir_p() with ISC-licensed mkdirs(), this allows us
to avoid a dual-licensed util.c for no reason ok chl@
-rw-r--r--usr.sbin/smtpd/delivery_maildir.c4
-rw-r--r--usr.sbin/smtpd/smtpd.h4
-rw-r--r--usr.sbin/smtpd/util.c123
3 files changed, 54 insertions, 77 deletions
diff --git a/usr.sbin/smtpd/delivery_maildir.c b/usr.sbin/smtpd/delivery_maildir.c
index 946b3636ad4..f576772c771 100644
--- a/usr.sbin/smtpd/delivery_maildir.c
+++ b/usr.sbin/smtpd/delivery_maildir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: delivery_maildir.c,v 1.7 2012/07/12 08:51:43 chl Exp $ */
+/* $OpenBSD: delivery_maildir.c,v 1.8 2012/09/16 11:53:57 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -62,7 +62,7 @@ delivery_maildir_open(struct deliver *deliver)
#define error2(m) { msg = m; goto err2; }
setproctitle("maildir delivery");
- if (mkdir_p(deliver->to, 0700) < 0 && errno != EEXIST)
+ if (mkdirs(deliver->to, 0700) < 0 && errno != EEXIST)
error("cannot mkdir maildir");
if (chdir(deliver->to) < 0)
error("cannot cd to maildir");
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 696b69af45c..b1e8716e450 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.348 2012/09/14 19:22:04 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.349 2012/09/16 11:53:57 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1186,7 +1186,7 @@ void addargs(arglist *, char *, ...)
__attribute__((format(printf, 2, 3)));
int bsnprintf(char *, size_t, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
-int mkdir_p(char *, mode_t);
+int mkdirs(char *, mode_t);
int safe_fclose(FILE *);
int hostname_match(char *, char *);
int email_to_mailaddr(struct mailaddr *, char *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 4da4dcba48e..3458a54599f 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.76 2012/09/15 15:12:11 eric Exp $ */
+/* $OpenBSD: util.c,v 1.77 2012/09/16 11:53:57 gilles Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -19,37 +19,6 @@
* 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>
@@ -134,59 +103,67 @@ 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)
+
+static int
+mkdirs_component(char *path, mode_t mode)
{
- struct stat sb;
- char *slash;
- int done, exists;
- mode_t dir_mode;
+ struct stat sb;
- dir_mode = mode | S_IWUSR | S_IXUSR;
+ if (stat(path, &sb) == -1) {
+ if (errno != ENOENT)
+ return 0;
+ if (mkdir(path, mode | S_IWUSR | S_IXUSR) == -1)
+ return 0;
+ }
+ else if (! S_ISDIR(sb.st_mode))
+ return 0;
- slash = path;
+ return 1;
+}
- for (;;) {
- slash += strspn(slash, "/");
- slash += strcspn(slash, "/");
+int
+mkdirs(char *path, mode_t mode)
+{
+ char buf[MAXPATHLEN];
+ int i = 0;
+ int done = 0;
+ char *p;
- done = (*slash == '\0');
- *slash = '\0';
+ /* absolute path required */
+ if (*path != '/')
+ return 0;
- /* skip existing path components */
- exists = !stat(path, &sb);
- if (!done && exists && S_ISDIR(sb.st_mode)) {
- *slash = '/';
- continue;
- }
+ /* make sure we don't exceed MAXPATHLEN */
+ if (strlen(path) >= sizeof buf)
+ return 0;
- 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);
- }
+ bzero(buf, sizeof buf);
+ for (p = path; *p; p++) {
+ if (*p == '/') {
+ if (buf[0] != '\0')
+ if (! mkdirs_component(buf, mode))
+ return 0;
+ while (*p == '/')
+ p++;
+ buf[i++] = '/';
+ buf[i++] = *p;
+ if (*p == '\0' && ++done)
+ break;
+ continue;
}
-
- if (done)
- break;
-
- *slash = '/';
+ buf[i++] = *p;
}
+ if (! done)
+ if (! mkdirs_component(buf, mode))
+ return 0;
+
+ if (chmod(path, mode) == -1)
+ return 0;
- return (0);
+ return 1;
}
+
int
ckdir(const char *path, mode_t mode, uid_t owner, gid_t group, int create)
{