static void named_pipe_accept(struct stream_connection *conn) { struct tstream_context *plain_tstream; int fd; struct tevent_req *subreq; int ret; /* Let tstream take over fd operations */ fd = socket_get_fd(conn->socket); socket_set_flags(conn->socket, SOCKET_FLAG_NOCLOSE); TALLOC_FREE(conn->event.fde); TALLOC_FREE(conn->socket); ret = tstream_bsd_existing_socket(conn, fd, &plain_tstream); if (ret != 0) { stream_terminate_connection(conn, "named_pipe_accept: out of memory"); return; } subreq = tstream_npa_accept_existing_send(conn, conn->event.ctx, plain_tstream, FILE_TYPE_MESSAGE_MODE_PIPE, 0xff | 0x0400 | 0x0100, 4096); if (subreq == NULL) { stream_terminate_connection(conn, "named_pipe_accept: " "no memory for tstream_npa_accept_existing_send"); return; } tevent_req_set_callback(subreq, named_pipe_accept_done, conn); }
void named_pipe_accept_function(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, const char *pipe_name, int fd, named_pipe_termination_fn *term_fn, void *private_data) { struct named_pipe_client *npc; struct tstream_context *plain; struct tevent_req *subreq; int ret; npc = talloc_zero(ev_ctx, struct named_pipe_client); if (!npc) { DEBUG(0, ("Out of memory!\n")); close(fd); return; } npc->pipe_name = talloc_strdup(npc, pipe_name); if (npc->pipe_name == NULL) { DEBUG(0, ("Out of memory!\n")); TALLOC_FREE(npc); close(fd); return; } npc->ev = ev_ctx; npc->msg_ctx = msg_ctx; npc->term_fn = term_fn; npc->private_data = private_data; talloc_set_destructor(npc, named_pipe_destructor); /* make sure socket is in NON blocking state */ ret = set_blocking(fd, false); if (ret != 0) { DEBUG(2, ("Failed to make socket non-blocking\n")); TALLOC_FREE(npc); close(fd); return; } ret = tstream_bsd_existing_socket(npc, fd, &plain); if (ret != 0) { DEBUG(2, ("Failed to create tstream socket\n")); TALLOC_FREE(npc); close(fd); return; } npc->file_type = FILE_TYPE_MESSAGE_MODE_PIPE; npc->device_state = 0xff | 0x0400 | 0x0100; npc->allocation_size = 4096; subreq = tstream_npa_accept_existing_send(npc, npc->ev, plain, npc->file_type, npc->device_state, npc->allocation_size); if (!subreq) { DEBUG(2, ("Failed to start async accept procedure\n")); TALLOC_FREE(npc); close(fd); return; } tevent_req_set_callback(subreq, named_pipe_accept_done, npc); }