From 0d1ecbbb73e958707612f9c9308c1d20e9b84909 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 13 Jan 2002 11:13:54 +0000 Subject: I'm doing some things towards the NamedPipes game with lckl and he has asked me to move this from being a static to matching its mate in lib/util_sock.c. In any case, this should discorage anybody from using the 'wrong' version of this function. (ie the one from TNG, which needs a bit more error checking depending on use). Andrew Bartlett (This used to be commit e6a3a01f795a85d908180ff19469ce09a2803512) --- source3/nsswitch/winbindd.c | 88 ++------------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) (limited to 'source3/nsswitch') diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index 1a9eae7afa..25b69cee6d 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -187,92 +187,8 @@ static void sighup_handler(int signum) static int create_sock(void) { - struct sockaddr_un sunaddr; - struct stat st; - int sock; - mode_t old_umask; - pstring path; - - /* Create the socket directory or reuse the existing one */ - - if (lstat(WINBINDD_SOCKET_DIR, &st) == -1) { - - if (errno == ENOENT) { - - /* Create directory */ - - if (mkdir(WINBINDD_SOCKET_DIR, 0755) == -1) { - DEBUG(0, ("error creating socket directory " - "%s: %s\n", WINBINDD_SOCKET_DIR, - strerror(errno))); - return -1; - } - - } else { - - DEBUG(0, ("lstat failed on socket directory %s: %s\n", - WINBINDD_SOCKET_DIR, strerror(errno))); - return -1; - } - - } else { - - /* Check ownership and permission on existing directory */ - - if (!S_ISDIR(st.st_mode)) { - DEBUG(0, ("socket directory %s isn't a directory\n", - WINBINDD_SOCKET_DIR)); - return -1; - } - - if ((st.st_uid != sec_initial_uid()) || - ((st.st_mode & 0777) != 0755)) { - DEBUG(0, ("invalid permissions on socket directory " - "%s\n", WINBINDD_SOCKET_DIR)); - return -1; - } - } - - /* Create the socket file */ - - old_umask = umask(0); - - sock = socket(AF_UNIX, SOCK_STREAM, 0); - - if (sock == -1) { - perror("socket"); - return -1; - } - - snprintf(path, sizeof(path), "%s/%s", - WINBINDD_SOCKET_DIR, WINBINDD_SOCKET_NAME); - - unlink(path); - memset(&sunaddr, 0, sizeof(sunaddr)); - sunaddr.sun_family = AF_UNIX; - safe_strcpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path)-1); - - if (bind(sock, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1) { - DEBUG(0, ("bind failed on winbind socket %s: %s\n", - path, - strerror(errno))); - close(sock); - return -1; - } - - if (listen(sock, 5) == -1) { - DEBUG(0, ("listen failed on winbind socket %s: %s\n", - path, - strerror(errno))); - close(sock); - return -1; - } - - umask(old_umask); - - /* Success! */ - - return sock; + return create_pipe_sock( WINBINDD_SOCKET_DIR, + WINBINDD_SOCKET_NAME, 0755); } struct dispatch_table { -- cgit