summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ldapctl/ldapctl.c
diff options
context:
space:
mode:
authorjca <jca@openbsd.org>2016-02-02 12:47:10 +0000
committerjca <jca@openbsd.org>2016-02-02 12:47:10 +0000
commite923bb1786e252643d45b68ef8405ac9d4a8130e (patch)
treeeb474adf247391e15daa09dd9ae94b809460796e /usr.sbin/ldapctl/ldapctl.c
parentUppecase. (diff)
downloadwireguard-openbsd-e923bb1786e252643d45b68ef8405ac9d4a8130e.tar.xz
wireguard-openbsd-e923bb1786e252643d45b68ef8405ac9d4a8130e.zip
Implement ldapctl -r datadir; ok sthen@ landry@
Diffstat (limited to 'usr.sbin/ldapctl/ldapctl.c')
-rw-r--r--usr.sbin/ldapctl/ldapctl.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/usr.sbin/ldapctl/ldapctl.c b/usr.sbin/ldapctl/ldapctl.c
index db429978340..ce11b5b551f 100644
--- a/usr.sbin/ldapctl/ldapctl.c
+++ b/usr.sbin/ldapctl/ldapctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapctl.c,v 1.7 2015/12/05 13:19:13 claudio Exp $ */
+/* $OpenBSD: ldapctl.c,v 1.8 2016/02/02 12:47:10 jca Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -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 */