summaryrefslogtreecommitdiff
path: root/nsswitch/wb_common.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-03-01 11:43:01 +0000
committerRalph Böhme <slow@samba.org>2015-06-08 19:48:18 +0200
commitb1e718f101fe6788b64b2deab09d2001bf8e0b2f (patch)
tree8d00d663d78811e9f5399ec7e298ac483809f6f4 /nsswitch/wb_common.c
parenta84e982bebbd1c21eba70f2d4873a4a1f3b0f58e (diff)
downloadsamba-b1e718f101fe6788b64b2deab09d2001bf8e0b2f.tar.gz
nsswitch: Simplify winbind_named_pipe_sock()
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Mon Jun 8 19:48:18 CEST 2015 on sn-devel-104
Diffstat (limited to 'nsswitch/wb_common.c')
-rw-r--r--nsswitch/wb_common.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c
index 036557a2d6d..3194df197b7 100644
--- a/nsswitch/wb_common.c
+++ b/nsswitch/wb_common.c
@@ -220,10 +220,10 @@ static int winbind_named_pipe_sock(const char *dir)
{
struct sockaddr_un sunaddr;
struct stat st;
- char *path = NULL;
int fd;
int wait_time;
int slept;
+ int ret;
/* Check permissions on unix socket directory */
@@ -244,25 +244,24 @@ static int winbind_named_pipe_sock(const char *dir)
/* Connect to socket */
- if (asprintf(&path, "%s/%s", dir, WINBINDD_SOCKET_NAME) < 0) {
+ sunaddr = (struct sockaddr_un) { .sun_family = AF_UNIX };
+
+ ret = snprintf(sunaddr.sun_path, sizeof(sunaddr.sun_path),
+ "%s/%s", dir, WINBINDD_SOCKET_NAME);
+ if ((ret == -1) || (ret >= sizeof(sunaddr.sun_path))) {
+ errno = ENAMETOOLONG;
return -1;
}
- ZERO_STRUCT(sunaddr);
- sunaddr.sun_family = AF_UNIX;
- strncpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path) - 1);
-
/* If socket file doesn't exist, don't bother trying to connect
with retry. This is an attempt to make the system usable when
the winbindd daemon is not running. */
- if (lstat(path, &st) == -1) {
+ if (lstat(sunaddr.sun_path, &st) == -1) {
errno = ENOENT;
- SAFE_FREE(path);
return -1;
}
- SAFE_FREE(path);
/* Check permissions on unix socket file */
/*
@@ -290,7 +289,6 @@ static int winbind_named_pipe_sock(const char *dir)
for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1;
wait_time += slept) {
struct pollfd pfd;
- int ret;
int connect_errno = 0;
socklen_t errnosize;