diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-02-05 16:39:28 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-02-05 16:39:28 +0100 |
commit | 6d139ca4680abcbda5110f2f0886aa038ff62088 (patch) | |
tree | 7d61db40fb058bcbf08ccd8e0dadc365b819371b /source3/rpc_server/srv_pipe_hnd.c | |
parent | 4a9b3052caeb8bb144803b49dcfae82395172bc3 (diff) | |
parent | afa960cbbcd609123d710c301e7a9a070c1fed70 (diff) | |
download | samba-6d139ca4680abcbda5110f2f0886aa038ff62088.tar.gz samba-6d139ca4680abcbda5110f2f0886aa038ff62088.tar.bz2 samba-6d139ca4680abcbda5110f2f0886aa038ff62088.zip |
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Conflicts:
librpc/ndr.pc.in
Diffstat (limited to 'source3/rpc_server/srv_pipe_hnd.c')
-rw-r--r-- | source3/rpc_server/srv_pipe_hnd.c | 321 |
1 files changed, 254 insertions, 67 deletions
diff --git a/source3/rpc_server/srv_pipe_hnd.c b/source3/rpc_server/srv_pipe_hnd.c index 0753476230..4cbe8d67a3 100644 --- a/source3/rpc_server/srv_pipe_hnd.c +++ b/source3/rpc_server/srv_pipe_hnd.c @@ -90,13 +90,14 @@ static bool pipe_init_outgoing_data(pipes_struct *p) ****************************************************************************/ static struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, - const char *pipe_name, + const struct ndr_syntax_id *syntax, const char *client_address, struct auth_serversupplied_info *server_info) { pipes_struct *p; - DEBUG(4,("Create pipe requested %s\n", pipe_name)); + DEBUG(4,("Create pipe requested %s\n", + get_pipe_name_from_iface(syntax))); p = TALLOC_ZERO_P(mem_ctx, struct pipes_struct); @@ -105,13 +106,15 @@ static struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, return NULL; } - if ((p->mem_ctx = talloc_init("pipe %s %p", pipe_name, p)) == NULL) { + if ((p->mem_ctx = talloc_init("pipe %s %p", + get_pipe_name_from_iface(syntax), + p)) == NULL) { DEBUG(0,("open_rpc_pipe_p: talloc_init failed.\n")); TALLOC_FREE(p); return NULL; } - if (!init_pipe_handle_list(p, pipe_name)) { + if (!init_pipe_handle_list(p, syntax)) { DEBUG(0,("open_rpc_pipe_p: init_pipe_handles failed.\n")); talloc_destroy(p->mem_ctx); TALLOC_FREE(p); @@ -152,11 +155,11 @@ static struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx, * Initialize the outgoing RPC data buffer with no memory. */ prs_init_empty(&p->out_data.rdata, p->mem_ctx, MARSHALL); - - fstrcpy(p->name, pipe_name); - + + p->syntax = *syntax; + DEBUG(4,("Created internal pipe %s (pipes_open=%d)\n", - pipe_name, pipes_open)); + get_pipe_name_from_iface(syntax), pipes_open)); talloc_set_destructor(p, close_internal_rpc_pipe_hnd); @@ -174,7 +177,7 @@ static void set_incoming_fault(pipes_struct *p) p->in_data.pdu_received_len = 0; p->fault_state = True; DEBUG(10, ("set_incoming_fault: Setting fault state on pipe %s\n", - p->name)); + get_pipe_name_from_iface(&p->syntax))); } /**************************************************************************** @@ -324,7 +327,8 @@ static void free_pipe_context(pipes_struct *p) "%lu\n", (unsigned long)talloc_total_size(p->mem_ctx) )); talloc_free_children(p->mem_ctx); } else { - p->mem_ctx = talloc_init("pipe %s %p", p->name, p); + p->mem_ctx = talloc_init( + "pipe %s %p", get_pipe_name_from_iface(&p->syntax), p); if (p->mem_ctx == NULL) { p->fault_state = True; } @@ -492,7 +496,7 @@ static void process_complete_pdu(pipes_struct *p) if(p->fault_state) { DEBUG(10,("process_complete_pdu: pipe %s in fault state.\n", - p->name )); + get_pipe_name_from_iface(&p->syntax))); set_incoming_fault(p); setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR)); return; @@ -520,12 +524,13 @@ static void process_complete_pdu(pipes_struct *p) case RPC_PING: /* CL request - ignore... */ DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n", - (unsigned int)p->hdr.pkt_type, p->name)); + (unsigned int)p->hdr.pkt_type, + get_pipe_name_from_iface(&p->syntax))); break; case RPC_RESPONSE: /* No responses here. */ DEBUG(0,("process_complete_pdu: Error. RPC_RESPONSE received from client on pipe %s.\n", - p->name )); + get_pipe_name_from_iface(&p->syntax))); break; case RPC_FAULT: @@ -537,7 +542,8 @@ static void process_complete_pdu(pipes_struct *p) case RPC_FACK: case RPC_CANCEL_ACK: DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n", - (unsigned int)p->hdr.pkt_type, p->name)); + (unsigned int)p->hdr.pkt_type, + get_pipe_name_from_iface(&p->syntax))); break; case RPC_BIND: @@ -552,7 +558,8 @@ static void process_complete_pdu(pipes_struct *p) case RPC_BINDACK: case RPC_BINDNACK: DEBUG(0,("process_complete_pdu: Error. RPC_BINDACK/RPC_BINDNACK packet type %u received on pipe %s.\n", - (unsigned int)p->hdr.pkt_type, p->name)); + (unsigned int)p->hdr.pkt_type, + get_pipe_name_from_iface(&p->syntax))); break; @@ -567,7 +574,7 @@ static void process_complete_pdu(pipes_struct *p) case RPC_ALTCONTRESP: DEBUG(0,("process_complete_pdu: Error. RPC_ALTCONTRESP on pipe %s: Should only be server -> client.\n", - p->name)); + get_pipe_name_from_iface(&p->syntax))); break; case RPC_AUTH3: @@ -581,7 +588,7 @@ static void process_complete_pdu(pipes_struct *p) case RPC_SHUTDOWN: DEBUG(0,("process_complete_pdu: Error. RPC_SHUTDOWN on pipe %s: Should only be server -> client.\n", - p->name)); + get_pipe_name_from_iface(&p->syntax))); break; case RPC_CO_CANCEL: @@ -619,7 +626,8 @@ static void process_complete_pdu(pipes_struct *p) prs_set_endian_data( &p->in_data.data, RPC_LITTLE_ENDIAN); if (!reply) { - DEBUG(3,("process_complete_pdu: DCE/RPC fault sent on pipe %s\n", p->pipe_srv_name)); + DEBUG(3,("process_complete_pdu: DCE/RPC fault sent on " + "pipe %s\n", get_pipe_name_from_iface(&p->syntax))); set_incoming_fault(p); setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR)); prs_mem_free(&rpc_in); @@ -773,7 +781,8 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data, size_ return -1; } - DEBUG(6,(" name: %s len: %u\n", p->name, (unsigned int)n)); + DEBUG(6,(" name: %s len: %u\n", get_pipe_name_from_iface(&p->syntax), + (unsigned int)n)); /* * We cannot return more than one PDU length per @@ -787,8 +796,10 @@ static ssize_t read_from_internal_pipe(struct pipes_struct *p, char *data, size_ */ if(n > RPC_MAX_PDU_FRAG_LEN) { - DEBUG(5,("read_from_pipe: too large read (%u) requested on \ -pipe %s. We can only service %d sized reads.\n", (unsigned int)n, p->name, RPC_MAX_PDU_FRAG_LEN )); + DEBUG(5,("read_from_pipe: too large read (%u) requested on " + "pipe %s. We can only service %d sized reads.\n", + (unsigned int)n, get_pipe_name_from_iface(&p->syntax), + RPC_MAX_PDU_FRAG_LEN )); n = RPC_MAX_PDU_FRAG_LEN; } @@ -803,9 +814,12 @@ pipe %s. We can only service %d sized reads.\n", (unsigned int)n, p->name, RPC_M if((pdu_remaining = p->out_data.current_pdu_len - p->out_data.current_pdu_sent) > 0) { data_returned = (ssize_t)MIN(n, pdu_remaining); - DEBUG(10,("read_from_pipe: %s: current_pdu_len = %u, current_pdu_sent = %u \ -returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len, - (unsigned int)p->out_data.current_pdu_sent, (int)data_returned)); + DEBUG(10,("read_from_pipe: %s: current_pdu_len = %u, " + "current_pdu_sent = %u returning %d bytes.\n", + get_pipe_name_from_iface(&p->syntax), + (unsigned int)p->out_data.current_pdu_len, + (unsigned int)p->out_data.current_pdu_sent, + (int)data_returned)); memcpy( data, &p->out_data.current_pdu[p->out_data.current_pdu_sent], (size_t)data_returned); p->out_data.current_pdu_sent += (uint32)data_returned; @@ -817,9 +831,11 @@ returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len, * may of course be zero if this is the first return fragment. */ - DEBUG(10,("read_from_pipe: %s: fault_state = %d : data_sent_length \ -= %u, prs_offset(&p->out_data.rdata) = %u.\n", - p->name, (int)p->fault_state, (unsigned int)p->out_data.data_sent_length, (unsigned int)prs_offset(&p->out_data.rdata) )); + DEBUG(10,("read_from_pipe: %s: fault_state = %d : data_sent_length " + "= %u, prs_offset(&p->out_data.rdata) = %u.\n", + get_pipe_name_from_iface(&p->syntax), (int)p->fault_state, + (unsigned int)p->out_data.data_sent_length, + (unsigned int)prs_offset(&p->out_data.rdata) )); if(p->out_data.data_sent_length >= prs_offset(&p->out_data.rdata)) { /* @@ -837,7 +853,8 @@ returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len, */ if(!create_next_pdu(p)) { - DEBUG(0,("read_from_pipe: %s: create_next_pdu failed.\n", p->name)); + DEBUG(0,("read_from_pipe: %s: create_next_pdu failed.\n", + get_pipe_name_from_iface(&p->syntax))); return -1; } @@ -1086,13 +1103,14 @@ NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name, handle->private_data = p; } else { struct pipes_struct *p; + struct ndr_syntax_id syntax; - if (!is_known_pipename(name)) { + if (!is_known_pipename(name, &syntax)) { TALLOC_FREE(handle); return NT_STATUS_OBJECT_NAME_NOT_FOUND; } - p = make_internal_rpc_pipe_p(handle, name, client_address, + p = make_internal_rpc_pipe_p(handle, &syntax, client_address, server_info); handle->type = FAKE_FILE_TYPE_NAMED_PIPE; @@ -1109,66 +1127,235 @@ NTSTATUS np_open(TALLOC_CTX *mem_ctx, const char *name, return NT_STATUS_OK; } -NTSTATUS np_write(struct fake_file_handle *handle, const uint8_t *data, - size_t len, ssize_t *nwritten) +struct np_write_state { + ssize_t nwritten; +}; + +static void np_write_done(struct async_req *subreq); + +struct async_req *np_write_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + struct fake_file_handle *handle, + const uint8_t *data, size_t len) { - DEBUG(6, ("np_write: len: %d\n", (int)len)); + struct async_req *result, *subreq; + struct np_write_state *state; + NTSTATUS status; + + DEBUG(6, ("np_write_send: len: %d\n", (int)len)); dump_data(50, data, len); - switch (handle->type) { - case FAKE_FILE_TYPE_NAMED_PIPE: { + if (!async_req_setup(mem_ctx, &result, &state, + struct np_write_state)) { + return NULL; + } + + if (len == 0) { + state->nwritten = 0; + status = NT_STATUS_OK; + goto post_status; + } + + if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE) { struct pipes_struct *p = talloc_get_type_abort( handle->private_data, struct pipes_struct); - *nwritten = write_to_internal_pipe(p, (char *)data, len); - break; + + state->nwritten = write_to_internal_pipe(p, (char *)data, len); + + status = (state->nwritten >= 0) + ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR; + goto post_status; } - case FAKE_FILE_TYPE_NAMED_PIPE_PROXY: { + + if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY) { struct np_proxy_state *p = talloc_get_type_abort( handle->private_data, struct np_proxy_state); - *nwritten = write_data(p->fd, (char *)data, len); - break; + + state->nwritten = len; + + subreq = sendall_send(state, ev, p->fd, data, len, 0); + if (subreq == NULL) { + goto fail; + } + subreq->async.fn = np_write_done; + subreq->async.priv = result; + return result; } - default: - return NT_STATUS_INVALID_HANDLE; - break; + + status = NT_STATUS_INVALID_HANDLE; + post_status: + if (async_post_ntstatus(result, ev, status)) { + return result; } + fail: + TALLOC_FREE(result); + return NULL; +} + +static void np_write_done(struct async_req *subreq) +{ + struct async_req *req = talloc_get_type_abort( + subreq->async.priv, struct async_req); + NTSTATUS status; + + status = sendall_recv(subreq); + if (!NT_STATUS_IS_OK(status)) { + async_req_nterror(req, status); + return; + } + async_req_done(req); +} + +NTSTATUS np_write_recv(struct async_req *req, ssize_t *pnwritten) +{ + struct np_write_state *state = talloc_get_type_abort( + req->private_data, struct np_write_state); + NTSTATUS status; - return ((*nwritten) >= 0) - ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR; + if (async_req_is_nterror(req, &status)) { + return status; + } + *pnwritten = state->nwritten; + return NT_STATUS_OK; } -NTSTATUS np_read(struct fake_file_handle *handle, uint8_t *data, size_t len, - ssize_t *nread, bool *is_data_outstanding) +struct np_read_state { + ssize_t nread; + bool is_data_outstanding; + int fd; +}; + +static void np_read_done(struct async_req *subreq); + +struct async_req *np_read_send(TALLOC_CTX *mem_ctx, struct event_context *ev, + struct fake_file_handle *handle, + uint8_t *data, size_t len) { - switch (handle->type) { - case FAKE_FILE_TYPE_NAMED_PIPE: { + struct async_req *result, *subreq; + struct np_read_state *state; + NTSTATUS status; + + if (!async_req_setup(mem_ctx, &result, &state, + struct np_read_state)) { + return NULL; + } + + if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE) { struct pipes_struct *p = talloc_get_type_abort( handle->private_data, struct pipes_struct); - *nread = read_from_internal_pipe(p, (char *)data, len, - is_data_outstanding); - break; + + state->nread = read_from_internal_pipe( + p, (char *)data, len, &state->is_data_outstanding); + + status = (state->nread >= 0) + ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR; + goto post_status; } - case FAKE_FILE_TYPE_NAMED_PIPE_PROXY: { + + if (handle->type == FAKE_FILE_TYPE_NAMED_PIPE_PROXY) { struct np_proxy_state *p = talloc_get_type_abort( handle->private_data, struct np_proxy_state); - int available = 0; - *nread = sys_read(p->fd, (char *)data, len); + state->fd = p->fd; - /* - * We don't look at the ioctl result. We don't really care - * if there is data available, because this is racy anyway. - */ - ioctl(p->fd, FIONREAD, &available); - *is_data_outstanding = (available > 0); + subreq = async_recv(state, ev, p->fd, data, len, 0); + if (subreq == NULL) { + goto fail; + } + subreq->async.fn = np_read_done; + subreq->async.priv = result; + return result; + } + + status = NT_STATUS_INVALID_HANDLE; + post_status: + if (async_post_ntstatus(result, ev, status)) { + return result; + } + fail: + TALLOC_FREE(result); + return NULL; +} + +static void np_read_done(struct async_req *subreq) +{ + struct async_req *req = talloc_get_type_abort( + subreq->async.priv, struct async_req); + struct np_read_state *state = talloc_get_type_abort( + req->private_data, struct np_read_state); + ssize_t result; + int sys_errno; + int available = 0; + + result = async_syscall_result_ssize_t(subreq, &sys_errno); + if (result == -1) { + async_req_nterror(req, map_nt_error_from_unix(sys_errno)); + return; + } + if (result == 0) { + async_req_nterror(req, NT_STATUS_END_OF_FILE); + return; + } + + state->nread = result; - break; + /* + * We don't look at the ioctl result. We don't really care if there is + * data available, because this is racy anyway. + */ + ioctl(state->fd, FIONREAD, &available); + state->is_data_outstanding = (available > 0); + + async_req_done(req); +} + +NTSTATUS np_read_recv(struct async_req *req, ssize_t *nread, + bool *is_data_outstanding) +{ + struct np_read_state *state = talloc_get_type_abort( + req->private_data, struct np_read_state); + NTSTATUS status; + + if (async_req_is_nterror(req, &status)) { + return status; + } + *nread = state->nread; + *is_data_outstanding = state->is_data_outstanding; + return NT_STATUS_OK; +} + +/** + * Create a new RPC client context which uses a local dispatch function. + */ +NTSTATUS rpc_pipe_open_internal(TALLOC_CTX *mem_ctx, + const struct ndr_syntax_id *abstract_syntax, + NTSTATUS (*dispatch) (struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const struct ndr_interface_table *table, + uint32_t opnum, void *r), + struct auth_serversupplied_info *serversupplied_info, + struct rpc_pipe_client **presult) +{ + struct rpc_pipe_client *result; + + result = TALLOC_ZERO_P(mem_ctx, struct rpc_pipe_client); + if (result == NULL) { + return NT_STATUS_NO_MEMORY; } - default: - return NT_STATUS_INVALID_HANDLE; - break; + + result->abstract_syntax = *abstract_syntax; + result->transfer_syntax = ndr_transfer_syntax; + result->dispatch = dispatch; + + result->pipes_struct = make_internal_rpc_pipe_p( + result, abstract_syntax, "", serversupplied_info); + if (result->pipes_struct == NULL) { + TALLOC_FREE(result); + return NT_STATUS_NO_MEMORY; } - return ((*nread) >= 0) - ? NT_STATUS_OK : NT_STATUS_UNEXPECTED_IO_ERROR; + result->max_xmit_frag = -1; + result->max_recv_frag = -1; + + *presult = result; + return NT_STATUS_OK; } |