static int winbind_open_pipe_sock(int recursing) { #ifdef HAVE_UNIXSOCKET static pid_t our_pid; struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); if (our_pid != getpid()) { close_sock(); our_pid = getpid(); } if (winbindd_fd != -1) { return winbindd_fd; } if (recursing) { return -1; } if ((winbindd_fd = winbind_named_pipe_sock(WINBINDD_SOCKET_DIR)) == -1) { return -1; } /* version-check the socket */ request.flags = WBFLAG_RECURSE; if ((winbindd_request_response(WINBINDD_INTERFACE_VERSION, &request, &response) != NSS_STATUS_SUCCESS) || (response.data.interface_version != WINBIND_INTERFACE_VERSION)) { close_sock(); return -1; } /* try and get priv pipe */ request.flags = WBFLAG_RECURSE; if (winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request, &response) == NSS_STATUS_SUCCESS) { int fd; if ((fd = winbind_named_pipe_sock(response.extra_data.data)) != -1) { close(winbindd_fd); winbindd_fd = fd; } } SAFE_FREE(response.extra_data.data); return winbindd_fd; #else return -1; #endif /* HAVE_UNIXSOCKET */ }
static int winbind_open_pipe_sock(int recursing, int need_priv) { #ifdef HAVE_UNIXSOCKET static pid_t our_pid; struct winbindd_request request; struct winbindd_response response; ZERO_STRUCT(request); ZERO_STRUCT(response); if (our_pid != getpid()) { winbind_close_sock(); our_pid = getpid(); } if ((need_priv != 0) && (is_privileged == 0)) { winbind_close_sock(); } if (winbindd_fd != -1) { return winbindd_fd; } if (recursing) { return -1; } if ((winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir())) == -1) { return -1; } is_privileged = 0; /* version-check the socket */ request.wb_flags = WBFLAG_RECURSE; if ((winbindd_request_response(WINBINDD_INTERFACE_VERSION, &request, &response) != NSS_STATUS_SUCCESS) || (response.data.interface_version != WINBIND_INTERFACE_VERSION)) { winbind_close_sock(); return -1; } /* try and get priv pipe */ request.wb_flags = WBFLAG_RECURSE; /* Note that response needs to be initialized to avoid * crashing on clean up after WINBINDD_PRIV_PIPE_DIR call failed * as interface version (from the first request) returned as a fstring, * thus response.extra_data.data will not be NULL even though * winbindd response did not write over it due to a failure */ ZERO_STRUCT(response); 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; } } if ((need_priv != 0) && (is_privileged == 0)) { return -1; } SAFE_FREE(response.extra_data.data); return winbindd_fd; #else return -1; #endif /* HAVE_UNIXSOCKET */ }