[email protected] (Jérémie Courrèges-Anglas) writes:
> Sebastien Marie <[email protected]> writes:
>
>> On Sun, Jan 31, 2016 at 09:39:52AM +0100, Landry Breuil wrote:
>>> 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 !
>>>
>>
>> the diff looks good and it would permit to make regress tests, so OK
>> semarie@ :)
>
> I have smallish tweaks to propose but nothing that prevents this diff to
> go in as is. ok jca@
Since both ldapd and ldapctl may access the db, ldapctl should be
modified similarly.
Comments/ok?
Index: ldapctl.8
===================================================================
RCS file: /cvs/src/usr.sbin/ldapctl/ldapctl.8,v
retrieving revision 1.4
diff -u -p -r1.4 ldapctl.8
--- ldapctl.8 21 Jul 2010 06:32:14 -0000 1.4
+++ ldapctl.8 1 Feb 2016 17:57:55 -0000
@@ -24,6 +24,7 @@
.Nm ldapctl
.Op Fl v
.Op Fl f Ar file
+.Op Fl r Ar datadir
.Op Fl s Ar socket
.Ar command
.Op Ar argument ...
@@ -41,6 +42,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 s Ar socket
Use
.Ar socket
Index: ldapctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldapctl/ldapctl.c,v
retrieving revision 1.7
diff -u -p -r1.7 ldapctl.c
--- ldapctl.c 5 Dec 2015 13:19:13 -0000 1.7
+++ ldapctl.c 1 Feb 2016 17:57:55 -0000
@@ -56,10 +56,10 @@ void show_stats(struct imsg *imsg);
void show_dbstats(const char *prefix, struct btree_stat *st);
void show_nsstats(struct imsg *imsg);
int compact_db(const char *path);
-int compact_namespace(struct namespace *ns);
-int compact_namespaces(void);
-int index_namespace(struct namespace *ns);
-int index_namespaces(void);
+int compact_namespace(struct namespace *ns, const char *datadir);
+int compact_namespaces(const char *datadir);
+int index_namespace(struct namespace *ns, const char *datadir);
+int index_namespaces(const char *datadir);
__dead void
usage(void)
@@ -67,7 +67,8 @@ usage(void)
extern char *__progname;
fprintf(stderr,
- "usage: %s [-v] [-f file] [-s socket] command [argument ...]\n",
+ "usage: %s [-v] [-f file] [-r directory] [-s socket] "
+ "command [argument ...]\n",
__progname);
exit(1);
}
@@ -93,11 +94,11 @@ compact_db(const char *path)
}
int
-compact_namespace(struct namespace *ns)
+compact_namespace(struct namespace *ns, const char *datadir)
{
char *path;
- if (asprintf(&path, "%s/%s_data.db", DATADIR, ns->suffix) < 0)
+ if (asprintf(&path, "%s/%s_data.db", datadir, ns->suffix) < 0)
return -1;
if (compact_db(path) != 0) {
log_warn("%s", path);
@@ -106,7 +107,7 @@ compact_namespace(struct namespace *ns)
}
free(path);
- if (asprintf(&path, "%s/%s_indx.db", DATADIR, ns->suffix) < 0)
+ if (asprintf(&path, "%s/%s_indx.db", datadir, ns->suffix) < 0)
return -1;
if (compact_db(path) != 0) {
log_warn("%s", path);
@@ -119,19 +120,22 @@ compact_namespace(struct namespace *ns)
}
int
-compact_namespaces(void)
+compact_namespaces(const char *datadir)
{
struct namespace *ns;
- TAILQ_FOREACH(ns, &conf->namespaces, next)
- if (SLIST_EMPTY(&ns->referrals) && compact_namespace(ns) != 0)
+ TAILQ_FOREACH(ns, &conf->namespaces, next) {
+ if (SLIST_EMPTY(&ns->referrals))
+ continue;
+ if (compact_namespace(ns, datadir) != 0)
return -1;
+ }
return 0;
}
int
-index_namespace(struct namespace *ns)
+index_namespace(struct namespace *ns, const char *datadir)
{
struct btval key, val;
struct btree *data_db, *indx_db;
@@ -150,7 +154,7 @@ index_namespace(struct namespace *ns)
if (data_db == NULL)
return -1;
- if (asprintf(&path, "%s/%s_indx.db", DATADIR, ns->suffix) < 0)
+ if (asprintf(&path, "%s/%s_indx.db", datadir, ns->suffix) < 0)
return -1;
indx_db = btree_open(path, BT_NOSYNC, 0644);
free(path);
@@ -212,13 +216,16 @@ index_namespace(struct namespace *ns)
}
int
-index_namespaces(void)
+index_namespaces(const char *datadir)
{
struct namespace *ns;
- TAILQ_FOREACH(ns, &conf->namespaces, next)
- if (SLIST_EMPTY(&ns->referrals) && index_namespace(ns) != 0)
+ TAILQ_FOREACH(ns, &conf->namespaces, next) {
+ if (SLIST_EMPTY(&ns->referrals))
+ continue;
+ if (index_namespace(ns, datadir) != 0)
return -1;
+ }
return 0;
}
@@ -237,6 +244,7 @@ main(int argc, char *argv[])
ssize_t n;
int ch;
enum action action = NONE;
+ const char *datadir = DATADIR;
const char *sock = LDAPD_SOCKET;
char *conffile = CONFFILE;
struct sockaddr_un sun;
@@ -245,11 +253,14 @@ main(int argc, char *argv[])
log_init(1);
- while ((ch = getopt(argc, argv, "f:s:v")) != -1) {
+ while ((ch = getopt(argc, argv, "f:r:s:v")) != -1) {
switch (ch) {
case 'f':
conffile = optarg;
break;
+ case 'r':
+ datadir = optarg;
+ break;
case 's':
sock = optarg;
break;
@@ -295,9 +306,9 @@ main(int argc, char *argv[])
err(1, "pledge");
if (action == COMPACT_DB)
- return compact_namespaces();
+ return compact_namespaces(datadir);
else
- return index_namespaces();
+ return index_namespaces(datadir);
}
/* connect to ldapd control socket */
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE