2 Unix SMB/Netbios implementation.
3 Generic infrstructure for RPC Daemons
4 Copyright (C) Simo Sorce 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "rpc_server/rpc_server.h"
23 struct named_pipe_listen_state {
27 static void named_pipe_listener(struct tevent_context *ev,
28 struct tevent_fd *fde,
35 bool setup_named_pipe_socket(const char *pipe_name,
36 struct tevent_context *ev_ctx)
38 struct named_pipe_listen_state *state;
39 struct tevent_fd *fde;
42 state = talloc(ev_ctx, struct named_pipe_listen_state);
44 DEBUG(0, ("Out of memory\n"));
49 np_dir = talloc_asprintf(state, "%s/np", lp_ncalrpc_dir());
51 DEBUG(0, ("Out of memory\n"));
55 if (!directory_create_or_exist(np_dir, geteuid(), 0700)) {
56 DEBUG(0, ("Failed to create pipe directory %s - %s\n",
57 np_dir, strerror(errno)));
61 state->fd = create_pipe_sock(np_dir, pipe_name, 0700);
62 if (state->fd == -1) {
63 DEBUG(0, ("Failed to create pipe socket! [%s/%s]\n",
68 DEBUG(10, ("Openened pipe socket fd %d for %s\n",
69 state->fd, pipe_name));
71 fde = tevent_add_fd(ev_ctx,
72 state, state->fd, TEVENT_FD_READ,
73 named_pipe_listener, state);
75 DEBUG(0, ("Failed to add event handler!\n"));
79 tevent_fd_set_auto_close(fde);
83 if (state->fd != -1) {