diff options
author | Simo Sorce <idra@samba.org> | 2010-06-18 11:00:38 -0400 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2010-09-15 12:53:41 +0200 |
commit | 3c26e95840454f8a311df037d90663abbda5854c (patch) | |
tree | eb25d9ad71a5e1a60f45aaa7f1cf03540afdd398 | |
parent | 11721874c3bc47fe7612cae611fbe321f683df6f (diff) | |
download | samba-3c26e95840454f8a311df037d90663abbda5854c.tar.gz samba-3c26e95840454f8a311df037d90663abbda5854c.tar.bz2 samba-3c26e95840454f8a311df037d90663abbda5854c.zip |
s3-rpc_server: Added initial generic RPC server infrastructure.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
-rw-r--r-- | source3/Makefile.in | 4 | ||||
-rw-r--r-- | source3/rpc_server/rpc_server.c | 88 | ||||
-rw-r--r-- | source3/rpc_server/rpc_server.h | 4 |
3 files changed, 94 insertions, 2 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 337045b88d..b3136db4e9 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -708,8 +708,10 @@ NPA_TSTREAM_OBJ = ../libcli/named_pipe_auth/npa_tstream.o \ RPC_NCACN_NP_INTERNAL = rpc_server/srv_pipe_register.o rpc_server/rpc_ncacn_np_internal.o \ rpc_server/rpc_handles.o +RPC_SERVICE = rpc_server/rpc_server.o + RPC_PIPE_OBJ = rpc_server/srv_pipe.o rpc_server/srv_pipe_hnd.o \ - $(RPC_NCACN_NP_INTERNAL) + $(RPC_NCACN_NP_INTERNAL) $(RPC_SERVICE) RPC_RPCECHO_OBJ = rpc_server/srv_echo_nt.o librpc/gen_ndr/srv_echo.o diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c new file mode 100644 index 0000000000..047f128217 --- /dev/null +++ b/source3/rpc_server/rpc_server.c @@ -0,0 +1,88 @@ +/* + Unix SMB/Netbios implementation. + Generic infrstructure for RPC Daemons + Copyright (C) Simo Sorce 2010 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "rpc_server/rpc_server.h" + +struct named_pipe_listen_state { + int fd; +}; + +static void named_pipe_listener(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, + void *private_data) +{ + return; +} + +bool setup_named_pipe_socket(const char *pipe_name, + struct tevent_context *ev_ctx) +{ + struct named_pipe_listen_state *state; + struct tevent_fd *fde; + char *np_dir; + + state = talloc(ev_ctx, struct named_pipe_listen_state); + if (!state) { + DEBUG(0, ("Out of memory\n")); + return false; + } + state->fd = -1; + + np_dir = talloc_asprintf(state, "%s/np", lp_ncalrpc_dir()); + if (!np_dir) { + DEBUG(0, ("Out of memory\n")); + goto out; + } + + if (!directory_create_or_exist(np_dir, geteuid(), 0700)) { + DEBUG(0, ("Failed to create pipe directory %s - %s\n", + np_dir, strerror(errno))); + goto out; + } + + state->fd = create_pipe_sock(np_dir, pipe_name, 0700); + if (state->fd == -1) { + DEBUG(0, ("Failed to create pipe socket! [%s/%s]\n", + np_dir, pipe_name)); + goto out; + } + + DEBUG(10, ("Openened pipe socket fd %d for %s\n", + state->fd, pipe_name)); + + fde = tevent_add_fd(ev_ctx, + state, state->fd, TEVENT_FD_READ, + named_pipe_listener, state); + if (!fde) { + DEBUG(0, ("Failed to add event handler!\n")); + goto out; + } + + tevent_fd_set_auto_close(fde); + return true; + +out: + if (state->fd != -1) { + close(state->fd); + } + TALLOC_FREE(state); + return false; +} diff --git a/source3/rpc_server/rpc_server.h b/source3/rpc_server/rpc_server.h index c9e5ac0901..c1573bb6c8 100644 --- a/source3/rpc_server/rpc_server.h +++ b/source3/rpc_server/rpc_server.h @@ -1,5 +1,5 @@ /* - * RPC Pipe server helper headers + * RPC Server helper headers * Almost completely rewritten by (C) Jeremy Allison 2005 - 2010 * Copyright (C) Simo Sorce <idra@samba.org> - 2010 * @@ -22,5 +22,7 @@ void set_incoming_fault(struct pipes_struct *p); void process_complete_pdu(struct pipes_struct *p); +bool setup_named_pipe_socket(const char *pipe_name, + struct tevent_context *ev_ctx); #endif /* _PRC_SERVER_H_ */ |