Hi,

i'm tinkering with ldapd and writing regress tests for it, and to
allow running independent instances (with separate port/control
socket/etc) i needed to add the possibility to specify an alternative
datadir, which was so far #defined in the code.
Patch is pretty simple and works fine, i'm open to suggestions of course
on a better wording for the manpage and option choose (i went for -r..)
okays welcome too !

Landry

Index: ldapd.8
===================================================================
RCS file: /cvs/src/usr.sbin/ldapd/ldapd.8,v
retrieving revision 1.12
diff -u -r1.12 ldapd.8
--- ldapd.8     11 Aug 2014 08:21:55 -0000      1.12
+++ ldapd.8     23 Jan 2016 10:11:48 -0000
@@ -57,6 +57,11 @@
 .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.
Index: ldapd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldapd/ldapd.c,v
retrieving revision 1.16
diff -u -r1.16 ldapd.c
--- ldapd.c     17 Jan 2016 08:13:34 -0000      1.16
+++ ldapd.c     23 Jan 2016 10:11:48 -0000
@@ -50,6 +50,7 @@
 
 struct ldapd_stats      stats;
 pid_t                   ldape_pid;
+char *                  datadir;
 
 void
 usage(void)
@@ -57,7 +58,7 @@
        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 @@
        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 @@
                case 'n':
                        configtest = 1;
                        break;
+               case 'r':
+                       datadir = optarg;
+                       break;
                case 's':
                        csockpath = optarg;
                        break;
@@ -366,7 +371,7 @@
        /* 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");
        }
Index: namespace.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldapd/namespace.c,v
retrieving revision 1.14
diff -u -r1.14 namespace.c
--- namespace.c 24 Dec 2015 17:47:57 -0000      1.14
+++ namespace.c 23 Jan 2016 10:11:48 -0000
@@ -38,6 +38,7 @@
 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 @@
        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 @@
 
        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)

Reply via email to