struct wb_context *wb_context_init(TALLOC_CTX *mem_ctx, const char* dir) { struct wb_context *result; result = talloc_zero(mem_ctx, struct wb_context); if (result == NULL) { return NULL; } result->queue = tevent_queue_create(result, "wb_trans"); if (result->queue == NULL) { TALLOC_FREE(result); return NULL; } result->fd = -1; result->is_priv = false; if (dir != NULL) { result->dir = talloc_strdup(result, dir); } else { result->dir = winbindd_socket_dir(); } if (result->dir == NULL) { TALLOC_FREE(result); return NULL; } return result; }
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 */ }
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; 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 */ }