3a7728e4a2c82fb3fff2f037ddb99d13820aed71
[vlendec/samba-autobuild/.git] / source3 / nsswitch / winbindd.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind daemon for ntdom nss module
5
6    Copyright (C) Tim Potter 2000
7    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
8    
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.
13    
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.
18    
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.   
23 */
24
25 #ifndef _WINBINDD_H
26 #define _WINBINDD_H
27
28 #include "nterr.h"
29
30 #include "winbindd_nss.h"
31
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_WINBIND
34
35 /* bits for fd_event.flags */
36 #define EVENT_FD_READ 1
37 #define EVENT_FD_WRITE 2
38
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_data, BOOL success);
47         void *private_data;
48 };
49
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' */
60
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() */
70 };
71
72 /* State between get{pw,gr}ent() calls */
73
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;
80 };
81
82 /* Storage for cached getpwent() user entries */
83
84 struct getpwent_user {
85         fstring name;                        /* Account name */
86         fstring gecos;                       /* User information */
87         fstring homedir;                     /* User Home Directory */
88         fstring shell;                       /* User Login Shell */
89         DOM_SID user_sid;                    /* NT user and primary group SIDs */
90         DOM_SID group_sid;
91 };
92
93 /* Server state structure */
94
95 struct winbindd_state {
96
97         /* User and group id pool */
98
99         uid_t uid_low, uid_high;               /* Range of uids to allocate */
100         gid_t gid_low, gid_high;               /* Range of gids to allocate */
101 };
102
103 extern struct winbindd_state server_state;  /* Server information */
104
105 typedef struct {
106         char *acct_name;
107         char *full_name;
108         char *homedir;
109         char *shell;
110         DOM_SID user_sid;                    /* NT user and primary group SIDs */
111         DOM_SID group_sid;
112 } WINBIND_USERINFO;
113
114 /* Our connection to the DC */
115
116 struct winbindd_cm_conn {
117         struct cli_state *cli;
118
119         struct rpc_pipe_client *samr_pipe;
120         POLICY_HND sam_connect_handle, sam_domain_handle;
121
122         struct rpc_pipe_client *lsa_pipe;
123         POLICY_HND lsa_policy;
124
125         /* Auth2 pipe is the pipe used to setup the netlogon schannel key
126          * using rpccli_net_auth2. It needs to be kept open. */
127
128         struct rpc_pipe_client *netlogon_auth2_pipe;
129         unsigned char sess_key[16];        /* Current session key. */
130         DOM_CRED clnt_cred;                /* Client NETLOGON credential. */
131         struct rpc_pipe_client *netlogon_pipe;
132 };
133
134 struct winbindd_async_request;
135
136 /* Async child */
137
138 struct winbindd_child {
139         struct winbindd_child *next, *prev;
140
141         pid_t pid;
142         struct winbindd_domain *domain;
143         pstring logfilename;
144
145         struct fd_event event;
146         struct winbindd_async_request *requests;
147 };
148
149 /* Structures to hold per domain information */
150
151 struct winbindd_domain {
152         fstring name;                          /* Domain name */        
153         fstring alt_name;                      /* alt Domain name (if any) */
154         DOM_SID sid;                           /* SID for this domain */
155         BOOL initialized;                      /* Did we already ask for the domain mode? */
156         BOOL native_mode;                      /* is this a win2k domain in native mode ? */
157         BOOL active_directory;                 /* is this a win2k active directory ? */
158         BOOL primary;                          /* is this our primary domain ? */
159         BOOL internal;          /* BUILTIN and member SAM */
160
161         /* Lookup methods for this domain (LDAP or RPC) */
162         struct winbindd_methods *methods;
163
164         /* the backend methods are used by the cache layer to find the right
165            backend */
166         struct winbindd_methods *backend;
167
168         /* Private data for the backends (used for connection cache) */
169
170         void *private_data; 
171
172         /* A working DC */
173         fstring dcname;
174         struct sockaddr_in dcaddr;
175
176         /* Sequence number stuff */
177
178         time_t last_seq_check;
179         uint32 sequence_number;
180         NTSTATUS last_status;
181
182         /* The smb connection */
183
184         struct winbindd_cm_conn conn;
185
186         /* The child pid we're talking to */
187
188         struct winbindd_child child;
189
190         /* Linked list info */
191
192         struct winbindd_domain *prev, *next;
193 };
194
195 /* per-domain methods. This is how LDAP vs RPC is selected
196  */
197 struct winbindd_methods {
198         /* does this backend provide a consistent view of the data? (ie. is the primary group
199            always correct) */
200         BOOL consistent;
201
202         /* get a list of users, returning a WINBIND_USERINFO for each one */
203         NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
204                                    TALLOC_CTX *mem_ctx,
205                                    uint32 *num_entries, 
206                                    WINBIND_USERINFO **info);
207
208         /* get a list of domain groups */
209         NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
210                                     TALLOC_CTX *mem_ctx,
211                                     uint32 *num_entries, 
212                                     struct acct_info **info);
213
214         /* get a list of domain local groups */
215         NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
216                                     TALLOC_CTX *mem_ctx,
217                                     uint32 *num_entries, 
218                                     struct acct_info **info);
219                                     
220         /* convert one user or group name to a sid */
221         NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
222                                 TALLOC_CTX *mem_ctx,
223                                 const char *domain_name,
224                                 const char *name,
225                                 DOM_SID *sid,
226                                 enum SID_NAME_USE *type);
227
228         /* convert a sid to a user or group name */
229         NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
230                                 TALLOC_CTX *mem_ctx,
231                                 const DOM_SID *sid,
232                                 char **domain_name,
233                                 char **name,
234                                 enum SID_NAME_USE *type);
235
236         /* lookup user info for a given SID */
237         NTSTATUS (*query_user)(struct winbindd_domain *domain, 
238                                TALLOC_CTX *mem_ctx, 
239                                const DOM_SID *user_sid,
240                                WINBIND_USERINFO *user_info);
241
242         /* lookup all groups that a user is a member of. The backend
243            can also choose to lookup by username or rid for this
244            function */
245         NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
246                                       TALLOC_CTX *mem_ctx,
247                                       const DOM_SID *user_sid,
248                                       uint32 *num_groups, DOM_SID **user_gids);
249
250         /* Lookup all aliases that the sids delivered are member of. This is
251          * to implement 'domain local groups' correctly */
252         NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
253                                        TALLOC_CTX *mem_ctx,
254                                        uint32 num_sids,
255                                        const DOM_SID *sids,
256                                        uint32 *num_aliases,
257                                        uint32 **alias_rids);
258
259         /* find all members of the group with the specified group_rid */
260         NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
261                                     TALLOC_CTX *mem_ctx,
262                                     const DOM_SID *group_sid,
263                                     uint32 *num_names, 
264                                     DOM_SID **sid_mem, char ***names, 
265                                     uint32 **name_types);
266
267         /* return the current global sequence number */
268         NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
269
270         /* enumerate trusted domains */
271         NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
272                                     TALLOC_CTX *mem_ctx,
273                                     uint32 *num_domains,
274                                     char ***names,
275                                     char ***alt_names,
276                                     DOM_SID **dom_sids);
277
278         /* setup the list of alternate names for the domain, if any */
279         NTSTATUS (*alternate_name)(struct winbindd_domain *domain);
280 };
281
282 /* Used to glue a policy handle and cli_state together */
283
284 typedef struct {
285         struct cli_state *cli;
286         POLICY_HND pol;
287 } CLI_POLICY_HND;
288
289 /* Filled out by IDMAP backends */
290 struct winbindd_idmap_methods {
291   /* Called when backend is first loaded */
292   BOOL (*init)(void);
293
294   BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
295   BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
296
297   BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
298   BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
299
300   /* Called when backend is unloaded */
301   BOOL (*close)(void);
302   /* Called to dump backend status */
303   void (*status)(void);
304 };
305
306 #include "nsswitch/winbindd_proto.h"
307
308 #include "rpc_parse.h"
309
310 #define WINBINDD_ESTABLISH_LOOP 30
311 #define WINBINDD_RESCAN_FREQ 300
312
313 #define DOM_SEQUENCE_NONE ((uint32)-1)
314
315 #endif /* _WINBINDD_H */