>From 9ffd1cc77c0f4a026fb0b94986ea2d275288c09b Mon Sep 17 00:00:00 2001 From: Matthew Newton Date: Fri, 16 Jan 2015 23:11:46 +0000 Subject: [PATCH 1/3] Convert wb_common.c global variables into a struct Storing winbindd_fd and is_privileged together makes sense because they are related to each other, and makes code more efficient when using thread local storage. --- nsswitch/wb_common.c | 29 ++++++++++++++--------------- nsswitch/winbind_client.h | 7 +++++++ nsswitch/winbind_nss_irix.c | 8 ++++---- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c index 3b67df0..f432920 100644 --- a/nsswitch/wb_common.c +++ b/nsswitch/wb_common.c @@ -28,8 +28,7 @@ /* Global variables. These are effectively the client state information */ -int winbindd_fd = -1; /* fd for winbindd socket */ -static int is_privileged = 0; +struct fd_info_s fd_info = { .winbindd_fd = -1, .is_privileged = 0 }; /* Free a response structure */ @@ -69,9 +68,9 @@ __attribute__((destructor)) #endif static void winbind_close_sock(void) { - if (winbindd_fd != -1) { - close(winbindd_fd); - winbindd_fd = -1; + if (fd_info.winbindd_fd != -1) { + close(fd_info.winbindd_fd); + fd_info.winbindd_fd = -1; } } @@ -347,23 +346,23 @@ static int winbind_open_pipe_sock(int recursing, int need_priv) our_pid = getpid(); } - if ((need_priv != 0) && (is_privileged == 0)) { + if ((need_priv != 0) && (fd_info.is_privileged == 0)) { winbind_close_sock(); } - if (winbindd_fd != -1) { - return winbindd_fd; + if (fd_info.winbindd_fd != -1) { + return fd_info.winbindd_fd; } if (recursing) { return -1; } - if ((winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir())) == -1) { + if ((fd_info.winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir())) == -1) { return -1; } - is_privileged = 0; + fd_info.is_privileged = 0; /* version-check the socket */ @@ -386,19 +385,19 @@ static int winbind_open_pipe_sock(int recursing, int need_priv) if (winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request, &response) == NSS_STATUS_SUCCESS) { int fd; if ((fd = winbind_named_pipe_sock((char *)response.extra_data.data)) != -1) { - close(winbindd_fd); - winbindd_fd = fd; - is_privileged = 1; + close(fd_info.winbindd_fd); + fd_info.winbindd_fd = fd; + fd_info.is_privileged = 1; } } - if ((need_priv != 0) && (is_privileged == 0)) { + if ((need_priv != 0) && (fd_info.is_privileged == 0)) { return -1; } SAFE_FREE(response.extra_data.data); - return winbindd_fd; + return fd_info.winbindd_fd; #else return -1; #endif /* HAVE_UNIXSOCKET */ diff --git a/nsswitch/winbind_client.h b/nsswitch/winbind_client.h index 905a189..cb9a08c 100644 --- a/nsswitch/winbind_client.h +++ b/nsswitch/winbind_client.h @@ -47,4 +47,11 @@ NSS_STATUS winbindd_priv_request_response(int req_type, #define winbind_on() \ (setenv(WINBINDD_DONT_ENV, "0", 1) == 0) +/* winbind file descriptor and privileged flag */ + +struct fd_info_s { + int winbindd_fd; + int is_privileged; +}; + #endif /* _NSSWITCH_WINBIND_CLIENT_H_ */ diff --git a/nsswitch/winbind_nss_irix.c b/nsswitch/winbind_nss_irix.c index 66fa4b5..6ed9d20 100644 --- a/nsswitch/winbind_nss_irix.c +++ b/nsswitch/winbind_nss_irix.c @@ -46,7 +46,7 @@ int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3); /* Prototypes from wb_common.c */ -extern int winbindd_fd; +extern struct fd_info_s fd_info; #ifdef HAVE_NS_API_H @@ -418,7 +418,7 @@ winbind_timeout(nsd_file_t **rqp, nsd_times_t *to) *rqp = rq; /* Remove the callback and timeout */ - nsd_callback_remove(winbindd_fd); + nsd_callback_remove(fd_info.winbindd_fd); nsd_timeout_remove(rq); rq->f_status = NS_NOTFOUND; @@ -468,9 +468,9 @@ send_next_request(nsd_file_t *rq, struct winbindd_request *request) * Set up callback and timeouts */ nsd_logprintf(NSD_LOG_MIN, "send_next_request (winbind) fd = %d\n", - winbindd_fd); + fd_info.winbindd_fd); - nsd_callback_new(winbindd_fd, winbind_callback, NSD_READ); + nsd_callback_new(fd_info.winbindd_fd, winbind_callback, NSD_READ); nsd_timeout_new(rq, timeout * 1000, winbind_timeout, NULL); return NSD_CONTINUE; } -- 1.7.10.4