diff options
author | Stefan Metzmacher <metze@samba.org> | 2004-07-13 21:04:56 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:57:35 -0500 |
commit | 45a85bdd353418828df8017a9d7eb7c14f6f0cd3 (patch) | |
tree | 14ec6ac1262f9a0a1974b6725a7f26afddb38f61 /source4/smbd/process_standard.c | |
parent | 9b4ac4d81ecf9786d2a3f96914af4a2895046676 (diff) | |
download | samba-45a85bdd353418828df8017a9d7eb7c14f6f0cd3.tar.gz samba-45a85bdd353418828df8017a9d7eb7c14f6f0cd3.tar.bz2 samba-45a85bdd353418828df8017a9d7eb7c14f6f0cd3.zip |
r1486: commit the start of the generic server infastructure
the idea is to have services as modules (smb, dcerpc, swat, ...)
the process_model don't know about the service it self anymore.
TODO:
- the smbsrv should use the smbsrv_send function
- the service subsystem init should be done like for other modules
- we need to have a generic socket subsystem, which handle stream, datagram,
and virtuell other sockets( e.g. for the ntvfs_ipc module to connect to the dcerpc server
, or for smb or dcerpc or whatever to connect to a server wide auth service)
- and other fixes...
NOTE: process model pthread seems to be broken( but also before this patch!)
metze
(This used to be commit bbe5e00715ca4013ff0dbc345aa97adc6b5c2458)
Diffstat (limited to 'source4/smbd/process_standard.c')
-rw-r--r-- | source4/smbd/process_standard.c | 138 |
1 files changed, 76 insertions, 62 deletions
diff --git a/source4/smbd/process_standard.c b/source4/smbd/process_standard.c index 2ee486e1d2..cc02e84d57 100644 --- a/source4/smbd/process_standard.c +++ b/source4/smbd/process_standard.c @@ -3,6 +3,7 @@ process model: standard (1 process per client connection) Copyright (C) Andrew Tridgell 1992-2003 Copyright (C) James J Myers 2003 <myersjj@samba.org> + Copyright (C) Stefan (metze) Metzmacher 2004 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 @@ -24,25 +25,31 @@ /* called when the process model is selected */ -static void model_startup(void) +static void standard_model_startup(void) { signal(SIGCHLD, SIG_IGN); + smbd_process_init(); } /* called when a listening socket becomes readable */ -static void accept_connection(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags) +static void standard_accept_connection(struct event_context *ev, struct fd_event *srv_fde, time_t t, uint16_t flags) { int accepted_fd; struct sockaddr addr; socklen_t in_addrlen = sizeof(addr); pid_t pid; - struct model_ops *model_ops = fde->private; - - accepted_fd = accept(fde->fd,&addr,&in_addrlen); + struct fd_event fde; + struct timed_event idle; + struct server_socket *server_socket = srv_fde->private; + struct server_connection *conn; + TALLOC_CTX *mem_ctx; + + /* accept an incoming connection. */ + accepted_fd = accept(srv_fde->fd,&addr,&in_addrlen); if (accepted_fd == -1) { - DEBUG(0,("accept_connection_standard: accept: %s\n", + DEBUG(0,("standard_accept_connection: accept: %s\n", strerror(errno))); return; } @@ -60,82 +67,91 @@ static void accept_connection(struct event_context *ev, struct fd_event *fde, ti /* Child code ... */ /* close all the listening sockets */ - event_remove_fd_all_handler(ev, model_ops->accept_connection); - event_remove_fd_all_handler(ev, model_ops->accept_rpc_connection); + event_remove_fd_all_handler(ev, standard_accept_connection); /* tdb needs special fork handling */ if (tdb_reopen_all() == -1) { - DEBUG(0,("accept_connection_standard: tdb_reopen_all failed.\n")); + DEBUG(0,("standard_accept_connection: tdb_reopen_all failed.\n")); } - /* Load DSO's */ - init_modules(); - - /* initialize new process */ - smbd_process_init(); - - init_smbsession(ev, model_ops, accepted_fd, smbd_read_handler); - - /* return to the event loop */ -} - -/* - called when a rpc listening socket becomes readable -*/ -static void accept_rpc_connection(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags) -{ - int accepted_fd; - struct sockaddr addr; - socklen_t in_addrlen = sizeof(addr); - pid_t pid; + mem_ctx = talloc_init("server_service_connection"); + if (!mem_ctx) { + DEBUG(0,("talloc_init(server_service_connection) failed\n")); + return; + } - accepted_fd = accept(fde->fd,&addr,&in_addrlen); - if (accepted_fd == -1) { - DEBUG(0,("accept_connection_standard: accept: %s\n", - strerror(errno))); + conn = talloc_p(mem_ctx, struct server_connection); + if (!conn) { + DEBUG(0,("talloc_p(mem_ctx, struct server_service_connection) failed\n")); + talloc_destroy(mem_ctx); return; } - pid = fork(); + ZERO_STRUCTP(conn); + conn->mem_ctx = mem_ctx; - if (pid != 0) { - /* parent or error code ... */ - close(accepted_fd); - /* go back to the event loop */ + fde.private = conn; + fde.fd = accepted_fd; + fde.flags = EVENT_FD_READ; + fde.handler = server_io_handler; + + idle.private = conn; + idle.next_event = t + 300; + idle.handler = server_idle_handler; + + + conn->event.ctx = ev; + conn->event.fde = &fde; + conn->event.idle = &idle; + conn->event.idle_time = 300; + + conn->server_socket = server_socket; + conn->service = server_socket->service; + + /* TODO: we need a generic socket subsystem */ + conn->socket = talloc_p(conn->mem_ctx, struct socket_context); + if (!conn->socket) { + DEBUG(0,("talloc_p(conn->mem_ctx, struct socket_context) failed\n")); + talloc_destroy(mem_ctx); return; } + conn->socket->private_data = NULL; + conn->socket->ops = NULL; + conn->socket->client_addr = NULL; + conn->socket->pkt_count = 0; + conn->socket->fde = conn->event.fde; - /* Child code ... */ + /* create a smb server context and add it to out event + handling */ + server_socket->service->ops->accept_connection(conn); - /* close all the listening sockets */ - event_remove_fd_all_handler(ev, accept_connection); - event_remove_fd_all_handler(ev, accept_rpc_connection); - - init_rpc_session(ev, fde->private, accepted_fd); -} + /* accpect_connection() of the service may changed idle.next_event */ + conn->event.fde = event_add_fd(ev,&fde); + conn->event.idle = event_add_timed(ev,&idle); -/* called when a SMB connection goes down */ -static void terminate_connection(struct smbsrv_connection *server, const char *reason) -{ - server_terminate(server); - /* terminate this process */ - exit(0); + conn->socket->fde = conn->event.fde; + + DLIST_ADD(server_socket->connection_list,conn); + + /* return to the event loop */ } -/* called when a rpc connection goes down */ -static void terminate_rpc_connection(void *r, const char *reason) + +/* called when a SMB connection goes down */ +static void standard_terminate_connection(struct server_connection *conn, const char *reason) { - rpc_server_terminate(r); + DEBUG(0,("single_terminate_connection: reason[%s]\n",reason)); + conn->service->ops->close_connection(conn,reason); /* terminate this process */ exit(0); } -static int get_id(struct smbsrv_request *req) +static int standard_get_id(struct smbsrv_request *req) { return (int)req->smb_conn->pid; } -static void standard_exit_server(struct smbsrv_connection *smb, const char *reason) +static void standard_exit_server(struct server_context *srv_ctx, const char *reason) { DEBUG(1,("standard_exit_server: reason[%s]\n",reason)); } @@ -154,13 +170,11 @@ NTSTATUS process_model_standard_init(void) ops.name = "standard"; /* fill in all the operations */ - ops.model_startup = model_startup; - ops.accept_connection = accept_connection; - ops.accept_rpc_connection = accept_rpc_connection; - ops.terminate_connection = terminate_connection; - ops.terminate_rpc_connection = terminate_rpc_connection; + ops.model_startup = standard_model_startup; + ops.accept_connection = standard_accept_connection; + ops.terminate_connection = standard_terminate_connection; ops.exit_server = standard_exit_server; - ops.get_id = get_id; + ops.get_id = standard_get_id; /* register ourselves with the PROCESS_MODEL subsystem. */ ret = register_backend("process_model", &ops); |