From 10e478f17277533099f56dadcd49bc8769c713c1 Mon Sep 17 00:00:00 2001 From: Landry Breuil Date: Sun, 17 Jan 2016 08:13:35 +0000 Subject: Properly remove unix sockets (control & listening) upon exit of the parent process. Child process was killed by pledge because it tried to remove the control socket and didnt have cpath - anyway it couldnt remove it since it had chrooted.. ok jmatthew@ deraadt@ --- usr.sbin/ldapd/control.c | 3 +-- usr.sbin/ldapd/ldapd.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/ldapd/control.c b/usr.sbin/ldapd/control.c index 545fde6a08e..ce25b20f400 100644 --- a/usr.sbin/ldapd/control.c +++ b/usr.sbin/ldapd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.12 2015/12/24 17:47:57 mmcc Exp $ */ +/* $OpenBSD: control.c,v 1.13 2016/01/17 08:13:34 landry Exp $ */ /* * Copyright (c) 2010 Martin Hedenfalk @@ -114,7 +114,6 @@ control_cleanup(struct control_sock *cs) return; event_del(&cs->cs_ev); event_del(&cs->cs_evt); - (void)unlink(cs->cs_name); } /* ARGSUSED */ diff --git a/usr.sbin/ldapd/ldapd.c b/usr.sbin/ldapd/ldapd.c index 3ec54514bd2..fb45ebcef89 100644 --- a/usr.sbin/ldapd/ldapd.c +++ b/usr.sbin/ldapd/ldapd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldapd.c,v 1.15 2015/12/24 17:47:57 mmcc Exp $ */ +/* $OpenBSD: ldapd.c,v 1.16 2016/01/17 08:13:34 landry Exp $ */ /* * Copyright (c) 2009, 2010 Martin Hedenfalk @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -45,6 +46,7 @@ static void ldapd_needfd(struct imsgev *iev); static void ldapd_auth_request(struct imsgev *iev, struct imsg *imsg); static void ldapd_open_request(struct imsgev *iev, struct imsg *imsg); static void ldapd_log_verbose(struct imsg *imsg); +static void ldapd_cleanup(char *); struct ldapd_stats stats; pid_t ldape_pid; @@ -213,11 +215,32 @@ main(int argc, char *argv[]) err(1, "pledge"); event_dispatch(); + + ldapd_cleanup(csockpath); log_debug("ldapd: exiting"); return 0; } +static void +ldapd_cleanup(char * csockpath) +{ + struct listener *l; + struct sockaddr_un *sun = NULL; + + /* Remove control socket. */ + (void)unlink(csockpath); + + /* Remove unix listening sockets. */ + TAILQ_FOREACH(l, &conf->listeners, entry) { + if (l->ss.ss_family == AF_UNIX) { + sun = (struct sockaddr_un *)&l->ss; + log_info("ldapd: removing unix socket %s", sun->sun_path); + (void)unlink(sun->sun_path); + } + } +} + static void ldapd_imsgev(struct imsgev *iev, int code, struct imsg *imsg) { -- cgit v1.2.3