r23995: Work to allow mimir's libnet code to be called from winbind.
[kai/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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "nsswitch/winbind_nss_config.h"
23 #include "nsswitch/winbindd_nss.h"
24 #include "libnet/libnet.h"
25
26
27 #define WINBINDD_SAMBA3_SOCKET "pipe"
28 /* the privileged socket is in smbd_tmp_dir() */
29 #define WINBINDD_SAMBA3_PRIVILEGED_SOCKET "winbind_pipe"
30
31 /* this struct stores global data for the winbind task */
32 struct wbsrv_service {
33         struct task_server *task;
34
35         const struct dom_sid *primary_sid;
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 wb_dom_info {
48         const char *name;
49         const char *dns_name;
50         const struct dom_sid *sid;
51
52         int num_dcs;
53         struct nbt_dc_name *dcs;
54 };
55
56 struct wbsrv_domain {
57         struct wbsrv_domain *next, *prev;
58
59         struct wb_dom_info *info;
60
61         /* Details for the server we are currently talking to */
62         const char *dc_address;
63         const char *dc_name;
64
65         struct libnet_context *libnet_ctx;
66
67         struct dcerpc_binding *lsa_binding;
68
69         struct dcerpc_binding *samr_binding;
70
71         struct ldap_connection *ldap_conn;
72
73         struct dcerpc_pipe *netlogon_pipe;
74         struct dcerpc_binding *netlogon_binding;
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 };
85
86 /*
87   state of an open winbind connection
88 */
89 struct wbsrv_connection {
90         /* stream connection we belong to */
91         struct stream_connection *conn;
92
93         /* the listening socket we belong to, it holds protocol hooks */
94         struct wbsrv_listen_socket *listen_socket;
95
96         /* storage for protocol specific data */
97         void *protocol_private_data;
98
99         /* how many calls are pending */
100         uint32_t pending_calls;
101
102         struct packet_context *packet;
103 };
104
105 #define WBSRV_SAMBA3_SET_STRING(dest, src) do { \
106         strncpy(dest, src, sizeof(dest)-1);\
107 } while(0)
108
109 /*
110   state of one request
111
112   NOTE about async replies:
113    if the backend wants to reply later:
114
115    - it should set the WBSRV_CALL_FLAGS_REPLY_ASYNC flag, and may set a 
116      talloc_destructor on the this structure or on the private_data (if it's a
117      talloc child of this structure), so that wbsrv_terminate_connection
118      called by another call clean up the whole connection correct.
119    - When the backend is ready to reply it should call wbsrv_send_reply(call),
120      wbsrv_send_reply implies talloc_free(call), so the backend should use 
121      talloc_reference(call), if it needs it later. 
122    - If wbsrv_send_reply doesn't return NT_STATUS_OK, the backend function 
123      should call, wbsrv_terminate_connection(call->wbconn, nt_errstr(status));
124      return;
125
126 */
127 struct wbsrv_samba3_call {
128 #define WBSRV_CALL_FLAGS_REPLY_ASYNC 0x00000001
129         uint32_t flags;
130
131         /* the connection the call belongs to */
132         struct wbsrv_connection *wbconn;
133
134         /* the backend should use this event context */
135         struct event_context *event_ctx;
136
137         /* here the backend can store stuff like composite_context's ... */
138         void *private_data;
139
140         /* the request structure of the samba3 protocol */
141         struct winbindd_request request;
142         
143         /* the response structure of the samba3 protocol*/
144         struct winbindd_response response;
145 };
146
147 struct netr_LMSessionKey;
148 struct netr_UserSessionKey;
149 struct winbind_SamLogon;
150
151 #include "winbind/wb_async_helpers.h"
152 #include "winbind/wb_proto.h"