diff options
author | Landry Breuil <landry@cvs.openbsd.org> | 2016-02-01 20:00:19 +0000 |
---|---|---|
committer | Landry Breuil <landry@cvs.openbsd.org> | 2016-02-01 20:00:19 +0000 |
commit | d5be4ddc012390f5bb4c587a2987421acf353393 (patch) | |
tree | 879c2f303c9d3d1008596b12303c352d95c99244 | |
parent | 9397e24ce503c6dcfd0504847127ac48de6caa40 (diff) |
Add -r argument to ldapd, to specify an alternative directory to
store/read the database, still defaulting to /var/db/ldap.
This will allow running totally separate instances, to be used by an
upcoming regress suite for example.
With a tweak from gsoares@ to check that the directory exists.
ok dlg@ semarie@ jca@
-rw-r--r-- | usr.sbin/ldapd/ldapd.8 | 9 | ||||
-rw-r--r-- | usr.sbin/ldapd/ldapd.c | 16 | ||||
-rw-r--r-- | usr.sbin/ldapd/namespace.c | 7 |
3 files changed, 23 insertions, 9 deletions
diff --git a/usr.sbin/ldapd/ldapd.8 b/usr.sbin/ldapd/ldapd.8 index 9b9bdd71659..ce85632d4f1 100644 --- a/usr.sbin/ldapd/ldapd.8 +++ b/usr.sbin/ldapd/ldapd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ldapd.8,v 1.12 2014/08/11 08:21:55 jmc Exp $ +.\" $OpenBSD: ldapd.8,v 1.13 2016/02/01 20:00:18 landry Exp $ .\" .\" Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 11 2014 $ +.Dd $Mdocdate: February 1 2016 $ .Dt LDAPD 8 .Os .Sh NAME @@ -57,6 +57,11 @@ Use .Ar file as the configuration file, instead of the default .Pa /etc/ldapd.conf . +.It Fl r Ar directory +Store and read database files in +.Ar directory +, instead of the default +.Pa /var/db/ldap . .It Fl n Configtest mode. Only check the configuration file for validity. diff --git a/usr.sbin/ldapd/ldapd.c b/usr.sbin/ldapd/ldapd.c index fb45ebcef89..28004efd12a 100644 --- a/usr.sbin/ldapd/ldapd.c +++ b/usr.sbin/ldapd/ldapd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapd.c,v 1.16 2016/01/17 08:13:34 landry Exp $ */ +/* $OpenBSD: ldapd.c,v 1.17 2016/02/01 20:00:18 landry Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se> @@ -50,6 +50,7 @@ static void ldapd_cleanup(char *); struct ldapd_stats stats; pid_t ldape_pid; +char * datadir; void usage(void) @@ -57,7 +58,7 @@ usage(void) extern char *__progname; fprintf(stderr, "usage: %s [-dnv] [-D macro=value] " - "[-f file] [-s file]\n", __progname); + "[-f file] [-r directory] [-s file]\n", __progname); exit(1); } @@ -117,9 +118,10 @@ main(int argc, char *argv[]) struct event ev_sigchld; struct event ev_sighup; + datadir = DATADIR; log_init(1); /* log to stderr until daemonized */ - while ((c = getopt(argc, argv, "dhvD:f:ns:")) != -1) { + while ((c = getopt(argc, argv, "dhvD:f:nr:s:")) != -1) { switch (c) { case 'd': debug = 1; @@ -139,6 +141,9 @@ main(int argc, char *argv[]) case 'n': configtest = 1; break; + case 'r': + datadir = optarg; + break; case 's': csockpath = optarg; break; @@ -173,6 +178,9 @@ main(int argc, char *argv[]) skip_chroot = 1; } + if (datadir && chdir(datadir)) + err(1, "chdir"); + if (!skip_chroot && (pw = getpwnam(LDAPD_USER)) == NULL) err(1, "%s", LDAPD_USER); @@ -366,7 +374,7 @@ ldapd_open_request(struct imsgev *iev, struct imsg *imsg) /* make sure path is null-terminated */ oreq->path[PATH_MAX] = '\0'; - if (strncmp(oreq->path, DATADIR, strlen(DATADIR)) != 0) { + if (strncmp(oreq->path, datadir, strlen(datadir)) != 0) { log_warnx("refusing to open file %s", oreq->path); fatal("ldape sent invalid open request"); } diff --git a/usr.sbin/ldapd/namespace.c b/usr.sbin/ldapd/namespace.c index de1a1a6ec5f..e400509b501 100644 --- a/usr.sbin/ldapd/namespace.c +++ b/usr.sbin/ldapd/namespace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: namespace.c,v 1.14 2015/12/24 17:47:57 mmcc Exp $ */ +/* $OpenBSD: namespace.c,v 1.15 2016/02/01 20:00:18 landry Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se> @@ -38,6 +38,7 @@ static void namespace_queue_replay(int fd, short event, void *arg); static int namespace_set_fd(struct namespace *ns, struct btree **bt, int fd, unsigned int flags); +extern char *datadir; int namespace_begin_txn(struct namespace *ns, struct btree_txn **data_txn, struct btree_txn **indx_txn, int rdonly) @@ -115,7 +116,7 @@ namespace_open(struct namespace *ns) if (ns->sync == 0) db_flags |= BT_NOSYNC; - if (asprintf(&ns->data_path, "%s/%s_data.db", DATADIR, ns->suffix) < 0) + if (asprintf(&ns->data_path, "%s/%s_data.db", datadir, ns->suffix) < 0) return -1; log_info("opening namespace %s", ns->suffix); ns->data_db = btree_open(ns->data_path, db_flags | BT_REVERSEKEY, 0644); @@ -124,7 +125,7 @@ namespace_open(struct namespace *ns) btree_set_cache_size(ns->data_db, ns->cache_size); - if (asprintf(&ns->indx_path, "%s/%s_indx.db", DATADIR, ns->suffix) < 0) + if (asprintf(&ns->indx_path, "%s/%s_indx.db", datadir, ns->suffix) < 0) return -1; ns->indx_db = btree_open(ns->indx_path, db_flags, 0644); if (ns->indx_db == NULL) |