df871f4c254008766b57d2a3bd37c3b0ab76e30f
[jelmer/samba4-debian.git] / source / 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
36         struct wbsrv_domain *domains;
37 };
38
39 struct wbsrv_samconn {
40         struct wbsrv_domain *domain;
41         void *private_data;
42
43         struct composite_context (*seqnum_send)(struct wbsrv_samconn *);
44         NTSTATUS (*seqnum_recv)(struct composite_context *, uint64_t *);
45 };
46
47 struct wbsrv_domain {
48         struct wbsrv_domain *next, *prev;
49
50         BOOL initialized;
51
52         const char *name;
53         const struct dom_sid *sid;
54
55         struct dcerpc_pipe *lsa_pipe;
56         struct policy_handle *lsa_policy;
57
58         struct dcerpc_pipe *netlogon_auth2_pipe;
59         struct dcerpc_pipe *netlogon_pipe;
60         struct cli_credentials *schannel_creds;
61 };
62
63 /* 
64   this is an abstraction for the actual protocol being used,
65   so that we can listen on different sockets with different protocols
66   e.g. the old samba3 protocol on one socket and a new protocol on another socket
67 */
68 struct wbsrv_protocol_ops {
69         const char *name;
70         BOOL allow_pending_calls;
71         uint32_t (*packet_length)(DATA_BLOB blob);
72         NTSTATUS (*pull_request)(DATA_BLOB blob, TALLOC_CTX *mem_ctx, struct wbsrv_call **call);
73         NTSTATUS (*handle_call)(struct wbsrv_call *call);
74         NTSTATUS (*push_reply)(struct wbsrv_call *call, TALLOC_CTX *mem_ctx, DATA_BLOB *blob);
75 };
76
77 /*
78   state of a listen socket and it's protocol information
79 */
80 struct wbsrv_listen_socket {
81         const char *socket_path;
82         struct wbsrv_service *service;
83         BOOL privileged;
84         const struct wbsrv_protocol_ops *ops;
85 };
86
87 /*
88   state of an open winbind connection
89 */
90 struct wbsrv_connection {
91         /* stream connection we belong to */
92         struct stream_connection *conn;
93
94         /* the listening socket we belong to, it holds protocol hooks */
95         struct wbsrv_listen_socket *listen_socket;
96
97         /* storage for protocol specific data */
98         void *protocol_private_data;
99
100         /* the partial data we've receiced yet */
101         DATA_BLOB partial;
102
103         /* the amount that we used yet from the partial buffer */
104         uint32_t partial_read;
105
106         /* prevent loops when we use half async code, while processing a requuest */
107         BOOL processing;
108
109         /* how many calls are pending */
110         uint32_t pending_calls;
111
112         struct data_blob_list_item *send_queue;
113 };
114
115 /*
116   state of one request
117
118   NOTE about async replies:
119    if the backend wants to reply later:
120
121    - it should set the WBSRV_CALL_FLAGS_REPLY_ASYNC flag, and may set a 
122      talloc_destructor on the this structure or on the private_data (if it's a
123      talloc child of this structure), so that wbsrv_terminate_connection
124      called by another call clean up the whole connection correct.
125    - When the backend is ready to reply it should call wbsrv_send_reply(call),
126      wbsrv_send_reply implies talloc_free(call), so the backend should use 
127      talloc_reference(call), if it needs it later. 
128    - If wbsrv_send_reply doesn't return NT_STATUS_OK, the backend function 
129      should call, wbsrv_terminate_connection(call->wbconn, nt_errstr(status));
130      return;
131
132 */
133 struct wbsrv_call {
134 #define WBSRV_CALL_FLAGS_REPLY_ASYNC 0x00000001
135         uint32_t flags;
136
137         /* the backend should use this event context */
138         struct event_context *event_ctx;
139
140         /* the connection the call belongs to */
141         struct wbsrv_connection *wbconn;
142
143         /* storage for protocol specific data */
144         void *private_data;
145 };