From 804600b9ea8701bf9604a56b311b54970a97753d Mon Sep 17 00:00:00 2001 From: Gleydson Soares Date: Tue, 2 Feb 2016 14:59:21 +0000 Subject: use stat(2) instead of chdir(2) to check if given the directory is valid. OK landry@ jca@ --- usr.sbin/ldapd/ldapd.c | 10 +++++++--- 1 file 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 @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -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); -- cgit v1.2.3