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); }
/* called when we get a new connection */ static void kdc_tcp_accept(struct stream_connection *conn) { struct kdc_socket *kdc_socket; struct kdc_tcp_connection *kdc_conn; struct tevent_req *subreq; int rc; kdc_conn = talloc_zero(conn, struct kdc_tcp_connection); if (kdc_conn == NULL) { stream_terminate_connection(conn, "kdc_tcp_accept: out of memory"); return; } kdc_conn->send_queue = tevent_queue_create(conn, "kdc_tcp_accept"); if (kdc_conn->send_queue == NULL) { stream_terminate_connection(conn, "kdc_tcp_accept: out of memory"); return; } kdc_socket = talloc_get_type(conn->private_data, struct kdc_socket); TALLOC_FREE(conn->event.fde); rc = tstream_bsd_existing_socket(kdc_conn, socket_get_fd(conn->socket), &kdc_conn->tstream); if (rc < 0) { stream_terminate_connection(conn, "kdc_tcp_accept: out of memory"); return; } kdc_conn->conn = conn; kdc_conn->kdc_socket = kdc_socket; conn->private_data = kdc_conn; /* * The krb5 tcp pdu's has the length as 4 byte (initial_read_size), * packet_full_request_u32 provides the pdu length then. */ subreq = tstream_read_pdu_blob_send(kdc_conn, kdc_conn->conn->event.ctx, kdc_conn->tstream, 4, /* initial_read_size */ packet_full_request_u32, kdc_conn); if (subreq == NULL) { kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_accept: " "no memory for tstream_read_pdu_blob_send"); return; } tevent_req_set_callback(subreq, kdc_tcp_call_loop, kdc_conn); }
static void wbsrv_accept(struct stream_connection *conn) { struct wbsrv_listen_socket *wbsrv_socket = talloc_get_type(conn->private_data, struct wbsrv_listen_socket); struct wbsrv_connection *wbsrv_conn; struct tevent_req *subreq; int rc; wbsrv_conn = talloc_zero(conn, struct wbsrv_connection); if (wbsrv_conn == NULL) { stream_terminate_connection(conn, "wbsrv_accept: out of memory"); return; } wbsrv_conn->send_queue = tevent_queue_create(conn, "wbsrv_accept"); if (wbsrv_conn->send_queue == NULL) { stream_terminate_connection(conn, "wbsrv_accept: out of memory"); return; } TALLOC_FREE(conn->event.fde); rc = tstream_bsd_existing_socket(wbsrv_conn, socket_get_fd(conn->socket), &wbsrv_conn->tstream); if (rc < 0) { stream_terminate_connection(conn, "wbsrv_accept: out of memory"); return; } wbsrv_conn->conn = conn; wbsrv_conn->listen_socket = wbsrv_socket; wbsrv_conn->lp_ctx = wbsrv_socket->service->task->lp_ctx; conn->private_data = wbsrv_conn; /* * The winbind pdu's has the length as 4 byte (initial_read_size), * wbsrv_samba3_packet_full_request provides the pdu length then. */ subreq = tstream_read_pdu_blob_send(wbsrv_conn, wbsrv_conn->conn->event.ctx, wbsrv_conn->tstream, 4, /* initial_read_size */ wbsrv_samba3_packet_full_request, wbsrv_conn); if (subreq == NULL) { wbsrv_terminate_connection(wbsrv_conn, "wbsrv_accept: " "no memory for tstream_read_pdu_blob_send"); return; } tevent_req_set_callback(subreq, wbsrv_call_loop, wbsrv_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); }
/* called when we get a new connection */ static void wreplsrv_accept(struct stream_connection *conn) { struct wreplsrv_service *service = talloc_get_type(conn->private_data, struct wreplsrv_service); struct wreplsrv_in_connection *wrepl_conn; struct tsocket_address *peer_addr; char *peer_ip; struct tevent_req *subreq; int rc; wrepl_conn = talloc_zero(conn, struct wreplsrv_in_connection); if (wrepl_conn == NULL) { stream_terminate_connection(conn, "wreplsrv_accept: out of memory"); return; } wrepl_conn->send_queue = tevent_queue_create(conn, "wrepl_accept"); if (wrepl_conn->send_queue == NULL) { stream_terminate_connection(conn, "wrepl_accept: out of memory"); return; } TALLOC_FREE(conn->event.fde); rc = tstream_bsd_existing_socket(wrepl_conn, socket_get_fd(conn->socket), &wrepl_conn->tstream); if (rc < 0) { stream_terminate_connection(conn, "wrepl_accept: out of memory"); return; } socket_set_flags(conn->socket, SOCKET_FLAG_NOCLOSE); wrepl_conn->conn = conn; wrepl_conn->service = service; peer_addr = conn->remote_address; if (!tsocket_address_is_inet(peer_addr, "ipv4")) { DEBUG(0,("wreplsrv_accept: non ipv4 peer addr '%s'\n", tsocket_address_string(peer_addr, wrepl_conn))); wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_accept: " "invalid peer IP"); return; } peer_ip = tsocket_address_inet_addr_string(peer_addr, wrepl_conn); if (peer_ip == NULL) { wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_accept: " "could not convert peer IP into a string"); return; } wrepl_conn->partner = wreplsrv_find_partner(service, peer_ip); irpc_add_name(conn->msg_ctx, "wreplsrv_connection"); /* * The wrepl pdu's has the length as 4 byte (initial_read_size), * packet_full_request_u32 provides the pdu length then. */ subreq = tstream_read_pdu_blob_send(wrepl_conn, wrepl_conn->conn->event.ctx, wrepl_conn->tstream, 4, /* initial_read_size */ packet_full_request_u32, wrepl_conn); if (subreq == NULL) { wreplsrv_terminate_in_connection(wrepl_conn, "wrepl_accept: " "no memory for tstream_read_pdu_blob_send"); return; } tevent_req_set_callback(subreq, wreplsrv_call_loop, wrepl_conn); }
/* initialise a server_context from a open socket and register a event handler for reading from that socket */ static void ldapsrv_accept(struct stream_connection *c, struct auth_session_info *session_info, bool is_privileged) { struct ldapsrv_service *ldapsrv_service = talloc_get_type(c->private_data, struct ldapsrv_service); struct ldapsrv_connection *conn; struct cli_credentials *server_credentials; struct socket_address *socket_address; NTSTATUS status; int port; int ret; struct tevent_req *subreq; struct timeval endtime; conn = talloc_zero(c, struct ldapsrv_connection); if (!conn) { stream_terminate_connection(c, "ldapsrv_accept: out of memory"); return; } conn->is_privileged = is_privileged; conn->sockets.send_queue = tevent_queue_create(conn, "ldapsev send queue"); if (conn->sockets.send_queue == NULL) { stream_terminate_connection(c, "ldapsrv_accept: tevent_queue_create failed"); return; } TALLOC_FREE(c->event.fde); ret = tstream_bsd_existing_socket(conn, socket_get_fd(c->socket), &conn->sockets.raw); if (ret == -1) { stream_terminate_connection(c, "ldapsrv_accept: out of memory"); return; } socket_set_flags(c->socket, SOCKET_FLAG_NOCLOSE); conn->connection = c; conn->service = ldapsrv_service; conn->lp_ctx = ldapsrv_service->task->lp_ctx; c->private_data = conn; socket_address = socket_get_my_addr(c->socket, conn); if (!socket_address) { ldapsrv_terminate_connection(conn, "ldapsrv_accept: failed to obtain local socket address!"); return; } port = socket_address->port; talloc_free(socket_address); if (port == 3268 || port == 3269) /* Global catalog */ { conn->global_catalog = true; } server_credentials = cli_credentials_init(conn); if (!server_credentials) { stream_terminate_connection(c, "Failed to init server credentials\n"); return; } cli_credentials_set_conf(server_credentials, conn->lp_ctx); status = cli_credentials_set_machine_account(server_credentials, conn->lp_ctx); if (!NT_STATUS_IS_OK(status)) { stream_terminate_connection(c, talloc_asprintf(conn, "Failed to obtain server credentials, perhaps a standalone server?: %s\n", nt_errstr(status))); return; } conn->server_credentials = server_credentials; conn->session_info = session_info; if (!NT_STATUS_IS_OK(ldapsrv_backend_Init(conn))) { ldapsrv_terminate_connection(conn, "backend Init failed"); return; } /* load limits from the conf partition */ ldapsrv_load_limits(conn); /* should we fail on error ? */ /* register the server */ irpc_add_name(c->msg_ctx, "ldap_server"); conn->sockets.active = conn->sockets.raw; if (port != 636 && port != 3269) { ldapsrv_call_read_next(conn); return; } endtime = timeval_current_ofs(conn->limits.conn_idle_time, 0); subreq = tstream_tls_accept_send(conn, conn->connection->event.ctx, conn->sockets.raw, conn->service->tls_params); if (subreq == NULL) { ldapsrv_terminate_connection(conn, "ldapsrv_accept: " "no memory for tstream_tls_accept_send"); return; } tevent_req_set_endtime(subreq, conn->connection->event.ctx, endtime); tevent_req_set_callback(subreq, ldapsrv_accept_tls_done, conn); }