From: Andrew Tridgell Date: Sat, 12 May 2007 23:20:16 +0000 (+1000) Subject: make sure the ctdb control socket is secure X-Git-Tag: tevent-0.9.20~348^2~2737 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5839eb1e80f3ab7c750b97e162658b58fa7fcbab;p=thirdparty%2Fsamba.git make sure the ctdb control socket is secure (This used to be ctdb commit 2954f2e501a418af578e75e8705b0b39a77c1861) --- diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index 8bbb07ec591..69c5005952b 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -600,10 +600,15 @@ static int ux_socket_bind(struct ctdb_context *ctdb) ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0); if (ctdb->daemon.sd == -1) { - ctdb->daemon.sd = -1; return -1; } + if (fchown(ctdb->daemon.sd, geteuid(), getegid()) != 0 || + fchmod(ctdb->daemon.sd, 0700) != 0) { + DEBUG(0,("Unable to secure ctdb socket '%s', ctdb->daemon.name\n")); + goto failed; + } + set_non_blocking(ctdb->daemon.sd); memset(&addr, 0, sizeof(addr)); @@ -611,13 +616,20 @@ static int ux_socket_bind(struct ctdb_context *ctdb) strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)); if (bind(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { - close(ctdb->daemon.sd); - ctdb->daemon.sd = -1; - return -1; + DEBUG(0,("Unable to bind on ctdb socket '%s', ctdb->daemon.name\n")); + goto failed; } - listen(ctdb->daemon.sd, 1); + if (listen(ctdb->daemon.sd, 10) != 0) { + DEBUG(0,("Unable to listen on ctdb socket '%s', ctdb->daemon.name\n")); + goto failed; + } return 0; + +failed: + close(ctdb->daemon.sd); + ctdb->daemon.sd = -1; + return -1; } /*