r7415: * big change -- volker's new async winbindd from trunk
[Samba/gbeck.git] / source / nsswitch / winbindd.h
blobc8d2ebf686ccf31d5490d2d98f4bb5d6ad0561b2
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind daemon for ntdom nss module
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this library; if not, write to the
21 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
25 #ifndef _WINBINDD_H
26 #define _WINBINDD_H
28 #include "nterr.h"
30 #include "winbindd_nss.h"
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_WINBIND
35 /* bits for fd_event.flags */
36 #define EVENT_FD_READ 1
37 #define EVENT_FD_WRITE 2
39 struct fd_event {
40 struct fd_event *next, *prev;
41 int fd;
42 int flags; /* see EVENT_FD_* flags */
43 void (*handler)(struct fd_event *fde, int flags);
44 void *data;
45 size_t length, done;
46 void (*finished)(void *private, BOOL success);
47 void *private;
50 struct winbindd_cli_state {
51 struct winbindd_cli_state *prev, *next; /* Linked list pointers */
52 int sock; /* Open socket from client */
53 struct fd_event fd_event;
54 pid_t pid; /* pid of client */
55 int read_buf_len, write_buf_len; /* Indexes in request/response */
56 BOOL finished; /* Can delete from list */
57 BOOL write_extra_data; /* Write extra_data field */
58 time_t last_access; /* Time of last access (read or write) */
59 BOOL privileged; /* Is the client 'privileged' */
61 TALLOC_CTX *mem_ctx; /* memory per request */
62 struct winbindd_request request; /* Request from client */
63 struct winbindd_response response; /* Respose to client */
64 BOOL getpwent_initialized; /* Has getpwent_state been
65 * initialized? */
66 BOOL getgrent_initialized; /* Has getgrent_state been
67 * initialized? */
68 struct getent_state *getpwent_state; /* State for getpwent() */
69 struct getent_state *getgrent_state; /* State for getgrent() */
72 /* State between get{pw,gr}ent() calls */
74 struct getent_state {
75 struct getent_state *prev, *next;
76 void *sam_entries;
77 uint32 sam_entry_index, num_sam_entries;
78 BOOL got_sam_entries;
79 fstring domain_name;
82 /* Storage for cached getpwent() user entries */
84 struct getpwent_user {
85 fstring name; /* Account name */
86 fstring gecos; /* User information */
87 DOM_SID user_sid; /* NT user and primary group SIDs */
88 DOM_SID group_sid;
91 /* Server state structure */
93 struct winbindd_state {
95 /* User and group id pool */
97 uid_t uid_low, uid_high; /* Range of uids to allocate */
98 gid_t gid_low, gid_high; /* Range of gids to allocate */
101 struct winbindd_dispatch_table {
102 enum winbindd_cmd cmd;
103 enum winbindd_result (*fn)(struct winbindd_cli_state *state);
104 const char *winbindd_cmd_name;
107 extern struct winbindd_state server_state; /* Server information */
109 typedef struct {
110 char *acct_name;
111 char *full_name;
112 DOM_SID user_sid; /* NT user and primary group SIDs */
113 DOM_SID group_sid;
114 } WINBIND_USERINFO;
116 /* Our connection to the DC */
118 struct winbindd_cm_conn {
119 struct cli_state *cli;
121 struct rpc_pipe_client *samr_pipe;
122 POLICY_HND sam_connect_handle, sam_domain_handle;
124 struct rpc_pipe_client *lsa_pipe;
125 POLICY_HND lsa_policy;
127 /* Auth2 pipe is the pipe used to setup the netlogon schannel key
128 * using rpccli_net_auth2. It needs to be kept open. */
130 struct rpc_pipe_client *netlogon_auth2_pipe;
131 unsigned char sess_key[16]; /* Current session key. */
132 DOM_CRED clnt_cred; /* Client NETLOGON credential. */
133 struct rpc_pipe_client *netlogon_pipe;
136 struct winbindd_async_request;
138 /* Async child */
140 struct winbindd_child {
141 struct winbindd_child *next, *prev;
143 pid_t pid;
144 struct winbindd_domain *domain;
145 pstring logfilename;
147 struct fd_event event;
148 struct winbindd_async_request *requests;
151 /* Structures to hold per domain information */
153 struct winbindd_domain {
154 fstring name; /* Domain name */
155 fstring alt_name; /* alt Domain name (if any) */
156 DOM_SID sid; /* SID for this domain */
157 BOOL initialized; /* Did we already ask for the domain mode? */
158 BOOL native_mode; /* is this a win2k domain in native mode ? */
159 BOOL active_directory; /* is this a win2k active directory ? */
160 BOOL primary; /* is this our primary domain ? */
161 BOOL internal; /* BUILTIN and member SAM */
163 /* Lookup methods for this domain (LDAP or RPC) */
164 struct winbindd_methods *methods;
166 /* the backend methods are used by the cache layer to find the right
167 backend */
168 struct winbindd_methods *backend;
170 /* Private data for the backends (used for connection cache) */
172 void *private;
174 /* A working DC */
175 fstring dcname;
176 struct sockaddr_in dcaddr;
178 /* Sequence number stuff */
180 time_t last_seq_check;
181 uint32 sequence_number;
182 NTSTATUS last_status;
184 /* The smb connection */
186 struct winbindd_cm_conn conn;
188 /* The child pid we're talking to */
190 struct winbindd_child child;
192 /* Linked list info */
194 struct winbindd_domain *prev, *next;
197 /* per-domain methods. This is how LDAP vs RPC is selected
199 struct winbindd_methods {
200 /* does this backend provide a consistent view of the data? (ie. is the primary group
201 always correct) */
202 BOOL consistent;
204 /* get a list of users, returning a WINBIND_USERINFO for each one */
205 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
206 TALLOC_CTX *mem_ctx,
207 uint32 *num_entries,
208 WINBIND_USERINFO **info);
210 /* get a list of domain groups */
211 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
212 TALLOC_CTX *mem_ctx,
213 uint32 *num_entries,
214 struct acct_info **info);
216 /* get a list of domain local groups */
217 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
218 TALLOC_CTX *mem_ctx,
219 uint32 *num_entries,
220 struct acct_info **info);
222 /* convert one user or group name to a sid */
223 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
224 TALLOC_CTX *mem_ctx,
225 const char *domain_name,
226 const char *name,
227 DOM_SID *sid,
228 enum SID_NAME_USE *type);
230 /* convert a sid to a user or group name */
231 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
232 TALLOC_CTX *mem_ctx,
233 const DOM_SID *sid,
234 char **domain_name,
235 char **name,
236 enum SID_NAME_USE *type);
238 /* lookup user info for a given SID */
239 NTSTATUS (*query_user)(struct winbindd_domain *domain,
240 TALLOC_CTX *mem_ctx,
241 const DOM_SID *user_sid,
242 WINBIND_USERINFO *user_info);
244 /* lookup all groups that a user is a member of. The backend
245 can also choose to lookup by username or rid for this
246 function */
247 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
248 TALLOC_CTX *mem_ctx,
249 const DOM_SID *user_sid,
250 uint32 *num_groups, DOM_SID **user_gids);
252 /* Lookup all aliases that the sids delivered are member of. This is
253 * to implement 'domain local groups' correctly */
254 NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
255 TALLOC_CTX *mem_ctx,
256 uint32 num_sids,
257 const DOM_SID *sids,
258 uint32 *num_aliases,
259 uint32 **alias_rids);
261 /* find all members of the group with the specified group_rid */
262 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
263 TALLOC_CTX *mem_ctx,
264 const DOM_SID *group_sid,
265 uint32 *num_names,
266 DOM_SID **sid_mem, char ***names,
267 uint32 **name_types);
269 /* return the current global sequence number */
270 NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
272 /* enumerate trusted domains */
273 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
274 TALLOC_CTX *mem_ctx,
275 uint32 *num_domains,
276 char ***names,
277 char ***alt_names,
278 DOM_SID **dom_sids);
280 /* setup the list of alternate names for the domain, if any */
281 NTSTATUS (*alternate_name)(struct winbindd_domain *domain);
284 /* Used to glue a policy handle and cli_state together */
286 typedef struct {
287 struct cli_state *cli;
288 POLICY_HND pol;
289 } CLI_POLICY_HND;
291 /* Filled out by IDMAP backends */
292 struct winbindd_idmap_methods {
293 /* Called when backend is first loaded */
294 BOOL (*init)(void);
296 BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
297 BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
299 BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
300 BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
302 /* Called when backend is unloaded */
303 BOOL (*close)(void);
304 /* Called to dump backend status */
305 void (*status)(void);
308 #include "nsswitch/winbindd_proto.h"
310 #include "rpc_parse.h"
312 #define WINBINDD_ESTABLISH_LOOP 30
313 #define WINBINDD_RESCAN_FREQ 300
315 #define DOM_SEQUENCE_NONE ((uint32)-1)
317 #endif /* _WINBINDD_H */