r10834: Work in progress on winbind. With some helper routines the composite functions
[samba.git] / source4 / winbind / wb_server.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Main winbindd server routines
4
5    Copyright (C) Stefan Metzmacher      2005
6    Copyright (C) Andrew Tridgell        2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WINBINDD_DIR "/tmp/.winbindd/"
24 #define WINBINDD_SOCKET WINBINDD_DIR"socket"
25 /* the privileged socket is in smbd_tmp_dir() */
26 #define WINBINDD_PRIVILEGED_SOCKET "winbind_socket"
27
28 #define WINBINDD_SAMBA3_SOCKET WINBINDD_DIR"pipe"
29 /* the privileged socket is in smbd_tmp_dir() */
30 #define WINBINDD_SAMBA3_PRIVILEGED_SOCKET "winbind_pipe"
31
32 /* this struct stores global data for the winbind task */
33 struct wbsrv_service {
34         struct task_server *task;
35         struct dcerpc_pipe *netlogon_pipe;
36         struct dcerpc_pipe *lsa_pipe;
37 };
38
39 /* 
40   this is an abstraction for the actual protocol being used,
41   so that we can listen on different sockets with different protocols
42   e.g. the old samba3 protocol on one socket and a new protocol on another socket
43 */
44 struct wbsrv_protocol_ops {
45         const char *name;
46         BOOL allow_pending_calls;
47         uint32_t (*packet_length)(DATA_BLOB blob);
48         NTSTATUS (*pull_request)(DATA_BLOB blob, TALLOC_CTX *mem_ctx, struct wbsrv_call **call);
49         NTSTATUS (*handle_call)(struct wbsrv_call *call);
50         NTSTATUS (*push_reply)(struct wbsrv_call *call, TALLOC_CTX *mem_ctx, DATA_BLOB *blob);
51 };
52
53 /*
54   state of a listen socket and it's protocol information
55 */
56 struct wbsrv_listen_socket {
57         const char *socket_path;
58         struct wbsrv_service *service;
59         BOOL privileged;
60         const struct wbsrv_protocol_ops *ops;
61 };
62
63 /*
64   state of an open winbind connection
65 */
66 struct wbsrv_connection {
67         /* stream connection we belong to */
68         struct stream_connection *conn;
69
70         /* the listening socket we belong to, it holds protocol hooks */
71         struct wbsrv_listen_socket *listen_socket;
72
73         /* storage for protocol specific data */
74         void *protocol_private_data;
75
76         /* the partial data we've receiced yet */
77         DATA_BLOB partial;
78
79         /* the amount that we used yet from the partial buffer */
80         uint32_t partial_read;
81
82         /* prevent loops when we use half async code, while processing a requuest */
83         BOOL processing;
84
85         /* how many calls are pending */
86         uint32_t pending_calls;
87
88         struct data_blob_list_item *send_queue;
89 };
90
91 /*
92   state of one request
93
94   NOTE about async replies:
95    if the backend wants to reply later:
96
97    - it should set the WBSRV_CALL_FLAGS_REPLY_ASYNC flag, and may set a 
98      talloc_destructor on the this structure or on the private_data (if it's a
99      talloc child of this structure), so that wbsrv_terminate_connection
100      called by another call clean up the whole connection correct.
101    - When the backend is ready to reply it should call wbsrv_send_reply(call),
102      wbsrv_send_reply implies talloc_free(call), so the backend should use 
103      talloc_reference(call), if it needs it later. 
104    - If wbsrv_send_reply doesn't return NT_STATUS_OK, the backend function 
105      should call, wbsrv_terminate_connection(call->wbconn, nt_errstr(status));
106      return;
107
108 */
109 struct wbsrv_call {
110 #define WBSRV_CALL_FLAGS_REPLY_ASYNC 0x00000001
111         uint32_t flags;
112
113         /* the backend should use this event context */
114         struct event_context *event_ctx;
115
116         /* the connection the call belongs to */
117         struct wbsrv_connection *wbconn;
118
119         /* storage for protocol specific data */
120         void *private_data;
121 };