summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleydson Soares <gsoares@cvs.openbsd.org>2016-02-02 14:59:21 +0000
committerGleydson Soares <gsoares@cvs.openbsd.org>2016-02-02 14:59:21 +0000
commit804600b9ea8701bf9604a56b311b54970a97753d (patch)
treeddce23fd366cd01e500d50341b074004d329b978
parent7f8d774131c5fc667eca66af5dc17d0e8ef38f92 (diff)
use stat(2) instead of chdir(2) to check if given the directory is valid.
OK landry@ jca@
-rw-r--r--usr.sbin/ldapd/ldapd.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/ldapd/ldapd.c b/usr.sbin/ldapd/ldapd.c
index 28004efd12a..49baa296bf4 100644
--- a/usr.sbin/ldapd/ldapd.c
+++ b/usr.sbin/ldapd/ldapd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapd.c,v 1.17 2016/02/01 20:00:18 landry Exp $ */
+/* $OpenBSD: ldapd.c,v 1.18 2016/02/02 14:59:20 gsoares Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -17,6 +17,7 @@
*/
#include <sys/queue.h>
+#include <sys/stat.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -117,6 +118,7 @@ main(int argc, char *argv[])
struct event ev_sigterm;
struct event ev_sigchld;
struct event ev_sighup;
+ struct stat sb;
datadir = DATADIR;
log_init(1); /* log to stderr until daemonized */
@@ -178,8 +180,10 @@ main(int argc, char *argv[])
skip_chroot = 1;
}
- if (datadir && chdir(datadir))
- err(1, "chdir");
+ if (stat(datadir, &sb) == -1)
+ err(1, "%s", datadir);
+ if (!S_ISDIR(sb.st_mode))
+ errx(1, "%s is not a directory", datadir);
if (!skip_chroot && (pw = getpwnam(LDAPD_USER)) == NULL)
err(1, "%s", LDAPD_USER);