summaryrefslogtreecommitdiff
path: root/usr.sbin/ldapd
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2017-01-20 11:55:09 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2017-01-20 11:55:09 +0000
commited67e665e663bedff1c44076973d19135a2c7821 (patch)
tree6d735ab7139e1e591d4c47eefb7aa90c7fd9b526 /usr.sbin/ldapd
parent2a4396317124823d511608dce9ffa899d054ad46 (diff)
work on making log.c similar in all daemons:
move daemon-local functions into new logmsg.c, and reduce the (mostly whitespace) differences so that log.c's can be diffed easily. ok krw@ jmatthew@
Diffstat (limited to 'usr.sbin/ldapd')
-rw-r--r--usr.sbin/ldapd/Makefile4
-rw-r--r--usr.sbin/ldapd/attributes.c3
-rw-r--r--usr.sbin/ldapd/auth.c3
-rw-r--r--usr.sbin/ldapd/conn.c3
-rw-r--r--usr.sbin/ldapd/control.c3
-rw-r--r--usr.sbin/ldapd/filter.c3
-rw-r--r--usr.sbin/ldapd/index.c3
-rw-r--r--usr.sbin/ldapd/ldapd.c3
-rw-r--r--usr.sbin/ldapd/ldapd.h15
-rw-r--r--usr.sbin/ldapd/ldape.c3
-rw-r--r--usr.sbin/ldapd/log.c307
-rw-r--r--usr.sbin/ldapd/log.h31
-rw-r--r--usr.sbin/ldapd/logmsg.c325
-rw-r--r--usr.sbin/ldapd/modify.c3
-rw-r--r--usr.sbin/ldapd/namespace.c3
-rw-r--r--usr.sbin/ldapd/parse.y3
-rw-r--r--usr.sbin/ldapd/schema.c3
-rw-r--r--usr.sbin/ldapd/search.c3
-rw-r--r--usr.sbin/ldapd/util.c3
-rw-r--r--usr.sbin/ldapd/validate.c3
20 files changed, 397 insertions, 330 deletions
diff --git a/usr.sbin/ldapd/Makefile b/usr.sbin/ldapd/Makefile
index 37eda13dcda..cc0816908fe 100644
--- a/usr.sbin/ldapd/Makefile
+++ b/usr.sbin/ldapd/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.14 2017/01/20 09:54:44 deraadt Exp $
+# $OpenBSD: Makefile,v 1.15 2017/01/20 11:55:08 benno Exp $
PROG= ldapd
MAN= ldapd.8 ldapd.conf.5
-SRCS= ber.c log.c control.c \
+SRCS= ber.c log.c logmsg.c control.c \
util.c ldapd.c ldape.c conn.c attributes.c namespace.c \
btree.c filter.c search.c parse.y \
auth.c modify.c index.c evbuffer_tls.c \
diff --git a/usr.sbin/ldapd/attributes.c b/usr.sbin/ldapd/attributes.c
index b89c75f8d43..6fafef28d27 100644
--- a/usr.sbin/ldapd/attributes.c
+++ b/usr.sbin/ldapd/attributes.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: attributes.c,v 1.3 2010/10/19 09:34:41 martinh Exp $ */
+/* $OpenBSD: attributes.c,v 1.4 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009 Martin Hedenfalk <martin@bzero.se>
@@ -24,6 +24,7 @@
#include <time.h>
#include "ldapd.h"
+#include "log.h"
struct ber_element *
ldap_get_attribute(struct ber_element *entry, const char *attr)
diff --git a/usr.sbin/ldapd/auth.c b/usr.sbin/ldapd/auth.c
index dfbdfe11fcf..45f9ef81ddd 100644
--- a/usr.sbin/ldapd/auth.c
+++ b/usr.sbin/ldapd/auth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.c,v 1.11 2015/12/24 17:47:57 mmcc Exp $ */
+/* $OpenBSD: auth.c,v 1.12 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -29,6 +29,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
static int
aci_matches(struct aci *aci, struct conn *conn, struct namespace *ns,
diff --git a/usr.sbin/ldapd/conn.c b/usr.sbin/ldapd/conn.c
index 728c75d69f1..4e8306c58fb 100644
--- a/usr.sbin/ldapd/conn.c
+++ b/usr.sbin/ldapd/conn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conn.c,v 1.13 2016/05/01 00:32:37 jmatthew Exp $ */
+/* $OpenBSD: conn.c,v 1.14 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -24,6 +24,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
int conn_dispatch(struct conn *conn);
int conn_tls_init(struct conn *);
diff --git a/usr.sbin/ldapd/control.c b/usr.sbin/ldapd/control.c
index 05c13b5c609..2d49e300024 100644
--- a/usr.sbin/ldapd/control.c
+++ b/usr.sbin/ldapd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2017/01/09 14:04:31 krw Exp $ */
+/* $OpenBSD: control.c,v 1.15 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2010 Martin Hedenfalk <martin@bzero.se>
@@ -35,6 +35,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
#define CONTROL_BACKLOG 5
diff --git a/usr.sbin/ldapd/filter.c b/usr.sbin/ldapd/filter.c
index 3e7954f32b0..b70297c0b71 100644
--- a/usr.sbin/ldapd/filter.c
+++ b/usr.sbin/ldapd/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.3 2014/09/21 05:33:49 daniel Exp $ */
+/* $OpenBSD: filter.c,v 1.4 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martinh@openbsd.org>
@@ -23,6 +23,7 @@
#include <stdint.h>
#include "ldapd.h"
+#include "log.h"
static int ldap_filt_eq(struct ber_element *root, struct plan *plan);
static int ldap_filt_subs(struct ber_element *root, struct plan *plan);
diff --git a/usr.sbin/ldapd/index.c b/usr.sbin/ldapd/index.c
index 8e35261827f..2f9f4db7127 100644
--- a/usr.sbin/ldapd/index.c
+++ b/usr.sbin/ldapd/index.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: index.c,v 1.10 2015/12/24 17:47:57 mmcc Exp $ */
+/* $OpenBSD: index.c,v 1.11 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009 Martin Hedenfalk <martin@bzero.se>
@@ -79,6 +79,7 @@
#include <string.h>
#include "ldapd.h"
+#include "log.h"
static int
index_attribute(struct namespace *ns, char *attr, struct btval *dn,
diff --git a/usr.sbin/ldapd/ldapd.c b/usr.sbin/ldapd/ldapd.c
index b41eb2dac2f..b5b819b1b97 100644
--- a/usr.sbin/ldapd/ldapd.c
+++ b/usr.sbin/ldapd/ldapd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapd.c,v 1.20 2016/05/01 00:32:37 jmatthew Exp $ */
+/* $OpenBSD: ldapd.c,v 1.21 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -38,6 +38,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
void usage(void);
void ldapd_sig_handler(int fd, short why, void *data);
diff --git a/usr.sbin/ldapd/ldapd.h b/usr.sbin/ldapd/ldapd.h
index 2cb4050f4dc..590c39c2dc9 100644
--- a/usr.sbin/ldapd/ldapd.h
+++ b/usr.sbin/ldapd/ldapd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldapd.h,v 1.26 2016/05/01 00:32:37 jmatthew Exp $ */
+/* $OpenBSD: ldapd.h,v 1.27 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -464,23 +464,12 @@ int ssl_cmp(struct ssl *, struct ssl *);
SPLAY_PROTOTYPE(ssltree, ssl, ssl_nodes, ssl_cmp);
-/* log.c */
-void log_init(int);
-void log_verbose(int v);
-void vlog(int, const char *, va_list);
-void logit(int pri, const char *fmt, ...);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-__dead void fatal(const char *);
-__dead void fatalx(const char *);
+/* logmsg.c */
const char *print_host(struct sockaddr_storage *ss, char *buf,
size_t len);
void hexdump(void *data, size_t len, const char *fmt, ...);
void ldap_debug_elements(struct ber_element *root,
int context, const char *fmt, ...);
-
/* util.c */
int bsnprintf(char *str, size_t size,
const char *format, ...);
diff --git a/usr.sbin/ldapd/ldape.c b/usr.sbin/ldapd/ldape.c
index 36559e1954b..1d88c38c1af 100644
--- a/usr.sbin/ldapd/ldape.c
+++ b/usr.sbin/ldapd/ldape.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldape.c,v 1.24 2016/05/01 00:32:37 jmatthew Exp $ */
+/* $OpenBSD: ldape.c,v 1.25 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -31,6 +31,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
void ldape_sig_handler(int fd, short why, void *data);
static void ldape_auth_result(struct imsg *imsg);
diff --git a/usr.sbin/ldapd/log.c b/usr.sbin/ldapd/log.c
index b2d2c7a0a46..c1c185a4f5d 100644
--- a/usr.sbin/ldapd/log.c
+++ b/usr.sbin/ldapd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.5 2017/01/17 22:10:55 krw Exp $ */
+/* $OpenBSD: log.c,v 1.6 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -11,18 +11,12 @@
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-
#include <errno.h>
-#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -30,12 +24,11 @@
#include <syslog.h>
#include <time.h>
#include <unistd.h>
-#include <vis.h>
-#include "ldapd.h"
+#include "log.h"
-int debug;
-int verbose;
+int debug;
+int verbose;
void
log_init(int n_debug)
@@ -176,289 +169,3 @@ fatalx(const char *emsg)
errno = 0;
fatal(emsg);
}
-
-const char *
-print_host(struct sockaddr_storage *ss, char *buf, size_t len)
-{
- if (getnameinfo((struct sockaddr *)ss, ss->ss_len,
- buf, len, NULL, 0, NI_NUMERICHOST) != 0) {
- buf[0] = '\0';
- return (NULL);
- }
- return (buf);
-}
-
-void
-hexdump(void *data, size_t len, const char *fmt, ...)
-{
- uint8_t *p = data;
- va_list ap;
-
- if (verbose < 2 || !debug)
- return;
-
- va_start(ap, fmt);
- vlog(LOG_DEBUG, fmt, ap);
- va_end(ap);
-
- while (len--) {
- size_t ofs = p - (uint8_t *)data;
- if (ofs % 16 == 0)
- fprintf(stderr, "%s%04lx:", ofs == 0 ? "" : "\n", ofs);
- else if (ofs % 8 == 0)
- fprintf(stderr, " ");
- fprintf(stderr, " %02x", *p++);
- }
- fprintf(stderr, "\n");
-}
-
-/*
- * Display a list of ber elements.
- *
- */
-void
-ldap_debug_elements(struct ber_element *root, int context, const char *fmt, ...)
-{
- va_list ap;
- static int indent = 0;
- long long v;
- int d;
- char *buf, *visbuf;
- size_t len;
- u_int i;
- int constructed;
- struct ber_oid o;
-
- if (verbose < 2 || !debug)
- return;
-
- if (fmt != NULL) {
- va_start(ap, fmt);
- vlog(LOG_DEBUG, fmt, ap);
- va_end(ap);
- }
-
- /* calculate lengths */
- ber_calc_len(root);
-
- switch (root->be_encoding) {
- case BER_TYPE_SEQUENCE:
- case BER_TYPE_SET:
- constructed = root->be_encoding;
- break;
- default:
- constructed = 0;
- break;
- }
-
- fprintf(stderr, "%*slen %lu ", indent, "", root->be_len);
- switch (root->be_class) {
- case BER_CLASS_UNIVERSAL:
- fprintf(stderr, "class: universal(%u) type: ", root->be_class);
- switch (root->be_type) {
- case BER_TYPE_EOC:
- fprintf(stderr, "end-of-content");
- break;
- case BER_TYPE_BOOLEAN:
- fprintf(stderr, "boolean");
- break;
- case BER_TYPE_INTEGER:
- fprintf(stderr, "integer");
- break;
- case BER_TYPE_BITSTRING:
- fprintf(stderr, "bit-string");
- break;
- case BER_TYPE_OCTETSTRING:
- fprintf(stderr, "octet-string");
- break;
- case BER_TYPE_NULL:
- fprintf(stderr, "null");
- break;
- case BER_TYPE_OBJECT:
- fprintf(stderr, "object");
- break;
- case BER_TYPE_ENUMERATED:
- fprintf(stderr, "enumerated");
- break;
- case BER_TYPE_SEQUENCE:
- fprintf(stderr, "sequence");
- break;
- case BER_TYPE_SET:
- fprintf(stderr, "set");
- break;
- }
- break;
- case BER_CLASS_APPLICATION:
- fprintf(stderr, "class: application(%u) type: ",
- root->be_class);
- switch (root->be_type) {
- case LDAP_REQ_BIND:
- case LDAP_RES_BIND:
- fprintf(stderr, "bind");
- break;
- case LDAP_REQ_UNBIND_30:
- fprintf(stderr, "unbind");
- break;
- case LDAP_REQ_SEARCH:
- fprintf(stderr, "search");
- break;
- case LDAP_RES_SEARCH_ENTRY:
- fprintf(stderr, "search entry");
- break;
- case LDAP_RES_SEARCH_RESULT:
- fprintf(stderr, "search result");
- break;
- case LDAP_REQ_MODIFY:
- case LDAP_RES_MODIFY:
- fprintf(stderr, "modify");
- break;
- case LDAP_REQ_ADD:
- case LDAP_RES_ADD:
- fprintf(stderr, "add");
- break;
- case LDAP_REQ_DELETE_30:
- case LDAP_RES_DELETE:
- fprintf(stderr, "delete");
- break;
- case LDAP_REQ_MODRDN:
- case LDAP_RES_MODRDN:
- fprintf(stderr, "modrdn");
- break;
- case LDAP_REQ_COMPARE:
- case LDAP_RES_COMPARE:
- fprintf(stderr, "compare");
- break;
- case LDAP_REQ_ABANDON_30:
- fprintf(stderr, "abandon");
- break;
- case LDAP_REQ_EXTENDED:
- case LDAP_RES_EXTENDED:
- fprintf(stderr, "extended");
- break;
- }
- break;
- case BER_CLASS_PRIVATE:
- fprintf(stderr, "class: private(%u) type: ", root->be_class);
- fprintf(stderr, "encoding (%lu) type: ", root->be_encoding);
- break;
- case BER_CLASS_CONTEXT:
- fprintf(stderr, "class: context(%u) type: ", root->be_class);
- switch (context) {
- case LDAP_REQ_BIND:
- switch(root->be_type) {
- case LDAP_AUTH_SIMPLE:
- fprintf(stderr, "auth simple");
- break;
- }
- break;
- case LDAP_REQ_SEARCH:
- switch(root->be_type) {
- case LDAP_FILT_AND:
- fprintf(stderr, "and");
- break;
- case LDAP_FILT_OR:
- fprintf(stderr, "or");
- break;
- case LDAP_FILT_NOT:
- fprintf(stderr, "not");
- break;
- case LDAP_FILT_EQ:
- fprintf(stderr, "equal");
- break;
- case LDAP_FILT_SUBS:
- fprintf(stderr, "substring");
- break;
- case LDAP_FILT_GE:
- fprintf(stderr, "greater-or-equal");
- break;
- case LDAP_FILT_LE:
- fprintf(stderr, "less-or-equal");
- break;
- case LDAP_FILT_PRES:
- fprintf(stderr, "presence");
- break;
- case LDAP_FILT_APPR:
- fprintf(stderr, "approximate");
- break;
- }
- break;
- }
- break;
- default:
- fprintf(stderr, "class: <INVALID>(%u) type: ", root->be_class);
- break;
- }
- fprintf(stderr, "(%lu) encoding %lu ",
- root->be_type, root->be_encoding);
-
- if (constructed)
- root->be_encoding = constructed;
-
- switch (root->be_encoding) {
- case BER_TYPE_BOOLEAN:
- if (ber_get_boolean(root, &d) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- fprintf(stderr, "%s(%d)\n", d ? "true" : "false", d);
- break;
- case BER_TYPE_INTEGER:
- if (ber_get_integer(root, &v) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- fprintf(stderr, "value %lld\n", v);
- break;
- case BER_TYPE_ENUMERATED:
- if (ber_get_enumerated(root, &v) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- fprintf(stderr, "value %lld\n", v);
- break;
- case BER_TYPE_BITSTRING:
- if (ber_get_bitstring(root, (void *)&buf, &len) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- fprintf(stderr, "hexdump ");
- for (i = 0; i < len; i++)
- fprintf(stderr, "%02x", buf[i]);
- fprintf(stderr, "\n");
- break;
- case BER_TYPE_OBJECT:
- if (ber_get_oid(root, &o) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- fprintf(stderr, "\n");
- break;
- case BER_TYPE_OCTETSTRING:
- if (ber_get_nstring(root, (void *)&buf, &len) == -1) {
- fprintf(stderr, "<INVALID>\n");
- break;
- }
- if ((visbuf = malloc(len * 4 + 1)) != NULL) {
- strvisx(visbuf, buf, len, 0);
- fprintf(stderr, "string \"%s\"\n", visbuf);
- free(visbuf);
- }
- break;
- case BER_TYPE_NULL: /* no payload */
- case BER_TYPE_EOC:
- case BER_TYPE_SEQUENCE:
- case BER_TYPE_SET:
- default:
- fprintf(stderr, "\n");
- break;
- }
-
- if (constructed && root->be_sub) {
- indent += 2;
- ldap_debug_elements(root->be_sub, context, NULL);
- indent -= 2;
- }
- if (root->be_next)
- ldap_debug_elements(root->be_next, context, NULL);
-}
-
diff --git a/usr.sbin/ldapd/log.h b/usr.sbin/ldapd/log.h
new file mode 100644
index 00000000000..a7f77554566
--- /dev/null
+++ b/usr.sbin/ldapd/log.h
@@ -0,0 +1,31 @@
+/* $OpenBSD: log.h,v 1.1 2017/01/20 11:55:08 benno Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdarg.h>
+#include <sys/cdefs.h>
+
+void log_init(int);
+void log_verbose(int);
+void logit(int, const char *, ...);
+void vlog(int, const char *, va_list);
+void log_warn(const char *, ...);
+void log_warnx(const char *, ...);
+void log_info(const char *, ...);
+void log_debug(const char *, ...);
+void fatal(const char *) __dead;
+void fatalx(const char *) __dead;
diff --git a/usr.sbin/ldapd/logmsg.c b/usr.sbin/ldapd/logmsg.c
new file mode 100644
index 00000000000..2dbbbc90421
--- /dev/null
+++ b/usr.sbin/ldapd/logmsg.c
@@ -0,0 +1,325 @@
+/* $OpenBSD: logmsg.c,v 1.1 2017/01/20 11:55:08 benno Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+
+#include <errno.h>
+#include <netdb.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <time.h>
+#include <unistd.h>
+#include <vis.h>
+
+#include "ldapd.h"
+#include "log.h"
+
+extern int debug;
+extern int verbose;
+
+const char *
+print_host(struct sockaddr_storage *ss, char *buf, size_t len)
+{
+ if (getnameinfo((struct sockaddr *)ss, ss->ss_len,
+ buf, len, NULL, 0, NI_NUMERICHOST) != 0) {
+ buf[0] = '\0';
+ return (NULL);
+ }
+ return (buf);
+}
+
+void
+hexdump(void *data, size_t len, const char *fmt, ...)
+{
+ uint8_t *p = data;
+ va_list ap;
+
+ if (verbose < 2 || !debug)
+ return;
+
+ va_start(ap, fmt);
+ vlog(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+
+ while (len--) {
+ size_t ofs = p - (uint8_t *)data;
+ if (ofs % 16 == 0)
+ fprintf(stderr, "%s%04lx:", ofs == 0 ? "" : "\n", ofs);
+ else if (ofs % 8 == 0)
+ fprintf(stderr, " ");
+ fprintf(stderr, " %02x", *p++);
+ }
+ fprintf(stderr, "\n");
+}
+
+/*
+ * Display a list of ber elements.
+ *
+ */
+void
+ldap_debug_elements(struct ber_element *root, int context, const char *fmt, ...)
+{
+ va_list ap;
+ static int indent = 0;
+ long long v;
+ int d;
+ char *buf, *visbuf;
+ size_t len;
+ u_int i;
+ int constructed;
+ struct ber_oid o;
+
+ if (verbose < 2 || !debug)
+ return;
+
+ if (fmt != NULL) {
+ va_start(ap, fmt);
+ vlog(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+ }
+
+ /* calculate lengths */
+ ber_calc_len(root);
+
+ switch (root->be_encoding) {
+ case BER_TYPE_SEQUENCE:
+ case BER_TYPE_SET:
+ constructed = root->be_encoding;
+ break;
+ default:
+ constructed = 0;
+ break;
+ }
+
+ fprintf(stderr, "%*slen %lu ", indent, "", root->be_len);
+ switch (root->be_class) {
+ case BER_CLASS_UNIVERSAL:
+ fprintf(stderr, "class: universal(%u) type: ", root->be_class);
+ switch (root->be_type) {
+ case BER_TYPE_EOC:
+ fprintf(stderr, "end-of-content");
+ break;
+ case BER_TYPE_BOOLEAN:
+ fprintf(stderr, "boolean");
+ break;
+ case BER_TYPE_INTEGER:
+ fprintf(stderr, "integer");
+ break;
+ case BER_TYPE_BITSTRING:
+ fprintf(stderr, "bit-string");
+ break;
+ case BER_TYPE_OCTETSTRING:
+ fprintf(stderr, "octet-string");
+ break;
+ case BER_TYPE_NULL:
+ fprintf(stderr, "null");
+ break;
+ case BER_TYPE_OBJECT:
+ fprintf(stderr, "object");
+ break;
+ case BER_TYPE_ENUMERATED:
+ fprintf(stderr, "enumerated");
+ break;
+ case BER_TYPE_SEQUENCE:
+ fprintf(stderr, "sequence");
+ break;
+ case BER_TYPE_SET:
+ fprintf(stderr, "set");
+ break;
+ }
+ break;
+ case BER_CLASS_APPLICATION:
+ fprintf(stderr, "class: application(%u) type: ",
+ root->be_class);
+ switch (root->be_type) {
+ case LDAP_REQ_BIND:
+ case LDAP_RES_BIND:
+ fprintf(stderr, "bind");
+ break;
+ case LDAP_REQ_UNBIND_30:
+ fprintf(stderr, "unbind");
+ break;
+ case LDAP_REQ_SEARCH:
+ fprintf(stderr, "search");
+ break;
+ case LDAP_RES_SEARCH_ENTRY:
+ fprintf(stderr, "search entry");
+ break;
+ case LDAP_RES_SEARCH_RESULT:
+ fprintf(stderr, "search result");
+ break;
+ case LDAP_REQ_MODIFY:
+ case LDAP_RES_MODIFY:
+ fprintf(stderr, "modify");
+ break;
+ case LDAP_REQ_ADD:
+ case LDAP_RES_ADD:
+ fprintf(stderr, "add");
+ break;
+ case LDAP_REQ_DELETE_30:
+ case LDAP_RES_DELETE:
+ fprintf(stderr, "delete");
+ break;
+ case LDAP_REQ_MODRDN:
+ case LDAP_RES_MODRDN:
+ fprintf(stderr, "modrdn");
+ break;
+ case LDAP_REQ_COMPARE:
+ case LDAP_RES_COMPARE:
+ fprintf(stderr, "compare");
+ break;
+ case LDAP_REQ_ABANDON_30:
+ fprintf(stderr, "abandon");
+ break;
+ case LDAP_REQ_EXTENDED:
+ case LDAP_RES_EXTENDED:
+ fprintf(stderr, "extended");
+ break;
+ }
+ break;
+ case BER_CLASS_PRIVATE:
+ fprintf(stderr, "class: private(%u) type: ", root->be_class);
+ fprintf(stderr, "encoding (%lu) type: ", root->be_encoding);
+ break;
+ case BER_CLASS_CONTEXT:
+ fprintf(stderr, "class: context(%u) type: ", root->be_class);
+ switch (context) {
+ case LDAP_REQ_BIND:
+ switch(root->be_type) {
+ case LDAP_AUTH_SIMPLE:
+ fprintf(stderr, "auth simple");
+ break;
+ }
+ break;
+ case LDAP_REQ_SEARCH:
+ switch(root->be_type) {
+ case LDAP_FILT_AND:
+ fprintf(stderr, "and");
+ break;
+ case LDAP_FILT_OR:
+ fprintf(stderr, "or");
+ break;
+ case LDAP_FILT_NOT:
+ fprintf(stderr, "not");
+ break;
+ case LDAP_FILT_EQ:
+ fprintf(stderr, "equal");
+ break;
+ case LDAP_FILT_SUBS:
+ fprintf(stderr, "substring");
+ break;
+ case LDAP_FILT_GE:
+ fprintf(stderr, "greater-or-equal");
+ break;
+ case LDAP_FILT_LE:
+ fprintf(stderr, "less-or-equal");
+ break;
+ case LDAP_FILT_PRES:
+ fprintf(stderr, "presence");
+ break;
+ case LDAP_FILT_APPR:
+ fprintf(stderr, "approximate");
+ break;
+ }
+ break;
+ }
+ break;
+ default:
+ fprintf(stderr, "class: <INVALID>(%u) type: ", root->be_class);
+ break;
+ }
+ fprintf(stderr, "(%lu) encoding %lu ",
+ root->be_type, root->be_encoding);
+
+ if (constructed)
+ root->be_encoding = constructed;
+
+ switch (root->be_encoding) {
+ case BER_TYPE_BOOLEAN:
+ if (ber_get_boolean(root, &d) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ fprintf(stderr, "%s(%d)\n", d ? "true" : "false", d);
+ break;
+ case BER_TYPE_INTEGER:
+ if (ber_get_integer(root, &v) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ fprintf(stderr, "value %lld\n", v);
+ break;
+ case BER_TYPE_ENUMERATED:
+ if (ber_get_enumerated(root, &v) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ fprintf(stderr, "value %lld\n", v);
+ break;
+ case BER_TYPE_BITSTRING:
+ if (ber_get_bitstring(root, (void *)&buf, &len) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ fprintf(stderr, "hexdump ");
+ for (i = 0; i < len; i++)
+ fprintf(stderr, "%02x", buf[i]);
+ fprintf(stderr, "\n");
+ break;
+ case BER_TYPE_OBJECT:
+ if (ber_get_oid(root, &o) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ fprintf(stderr, "\n");
+ break;
+ case BER_TYPE_OCTETSTRING:
+ if (ber_get_nstring(root, (void *)&buf, &len) == -1) {
+ fprintf(stderr, "<INVALID>\n");
+ break;
+ }
+ if ((visbuf = malloc(len * 4 + 1)) != NULL) {
+ strvisx(visbuf, buf, len, 0);
+ fprintf(stderr, "string \"%s\"\n", visbuf);
+ free(visbuf);
+ }
+ break;
+ case BER_TYPE_NULL: /* no payload */
+ case BER_TYPE_EOC:
+ case BER_TYPE_SEQUENCE:
+ case BER_TYPE_SET:
+ default:
+ fprintf(stderr, "\n");
+ break;
+ }
+
+ if (constructed && root->be_sub) {
+ indent += 2;
+ ldap_debug_elements(root->be_sub, context, NULL);
+ indent -= 2;
+ }
+ if (root->be_next)
+ ldap_debug_elements(root->be_next, context, NULL);
+}
+
diff --git a/usr.sbin/ldapd/modify.c b/usr.sbin/ldapd/modify.c
index a24bdd19a92..1fbc5f4ee79 100644
--- a/usr.sbin/ldapd/modify.c
+++ b/usr.sbin/ldapd/modify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: modify.c,v 1.17 2015/12/24 17:47:57 mmcc Exp $ */
+/* $OpenBSD: modify.c,v 1.18 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -25,6 +25,7 @@
#include <string.h>
#include "ldapd.h"
+#include "log.h"
#include "uuid.h"
int
diff --git a/usr.sbin/ldapd/namespace.c b/usr.sbin/ldapd/namespace.c
index 052e24de257..88f50fceac2 100644
--- a/usr.sbin/ldapd/namespace.c
+++ b/usr.sbin/ldapd/namespace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: namespace.c,v 1.16 2016/02/04 12:48:06 jca Exp $ */
+/* $OpenBSD: namespace.c,v 1.17 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -27,6 +27,7 @@
#include <zlib.h>
#include "ldapd.h"
+#include "log.h"
extern const char *datadir;
diff --git a/usr.sbin/ldapd/parse.y b/usr.sbin/ldapd/parse.y
index 82e7fbfc19d..11e250276bf 100644
--- a/usr.sbin/ldapd/parse.y
+++ b/usr.sbin/ldapd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.22 2017/01/05 13:53:09 krw Exp $ */
+/* $OpenBSD: parse.y,v 1.23 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martinh@openbsd.org>
@@ -45,6 +45,7 @@
#include <unistd.h>
#include "ldapd.h"
+#include "log.h"
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
static struct file {
diff --git a/usr.sbin/ldapd/schema.c b/usr.sbin/ldapd/schema.c
index c5f25f70c7f..1bf275ffd02 100644
--- a/usr.sbin/ldapd/schema.c
+++ b/usr.sbin/ldapd/schema.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: schema.c,v 1.16 2014/11/16 19:04:40 bluhm Exp $ */
+/* $OpenBSD: schema.c,v 1.17 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2010 Martin Hedenfalk <martinh@openbsd.org>
@@ -24,6 +24,7 @@
#include <syslog.h>
#include "ldapd.h"
+#include "log.h"
#define ERROR -1
#define STRING 1
diff --git a/usr.sbin/ldapd/search.c b/usr.sbin/ldapd/search.c
index c480a259f4d..715aa92b94d 100644
--- a/usr.sbin/ldapd/search.c
+++ b/usr.sbin/ldapd/search.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: search.c,v 1.17 2015/12/24 17:47:57 mmcc Exp $ */
+/* $OpenBSD: search.c,v 1.18 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
@@ -27,6 +27,7 @@
#include <time.h>
#include "ldapd.h"
+#include "log.h"
#define MAX_SEARCHES 200
diff --git a/usr.sbin/ldapd/util.c b/usr.sbin/ldapd/util.c
index a4c26825832..7cf38a18b90 100644
--- a/usr.sbin/ldapd/util.c
+++ b/usr.sbin/ldapd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.7 2015/12/24 17:47:57 mmcc Exp $ */
+/* $OpenBSD: util.c,v 1.8 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2009 Martin Hedenfalk <martin@bzero.se>
@@ -32,6 +32,7 @@
#include <errno.h>
#include "ldapd.h"
+#include "log.h"
int
bsnprintf(char *str, size_t size, const char *format, ...)
diff --git a/usr.sbin/ldapd/validate.c b/usr.sbin/ldapd/validate.c
index ab4b15d8714..49c710928dc 100644
--- a/usr.sbin/ldapd/validate.c
+++ b/usr.sbin/ldapd/validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: validate.c,v 1.9 2010/09/03 09:53:24 martinh Exp $ */
+/* $OpenBSD: validate.c,v 1.10 2017/01/20 11:55:08 benno Exp $ */
/*
* Copyright (c) 2010 Martin Hedenfalk <martin@bzero.se>
@@ -23,6 +23,7 @@
#include <string.h>
#include "ldapd.h"
+#include "log.h"
static int
validate_required_attributes(struct ber_element *entry, struct object *obj)