r14505: Rename the timed_event to lockout_policy_event.
[samba.git] / source / 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 #ifdef HAVE_LIBNSCD
33 #include "libnscd.h"
34 #endif
35
36 #undef DBGC_CLASS
37 #define DBGC_CLASS DBGC_WINBIND
38
39 /* bits for fd_event.flags */
40 #define EVENT_FD_READ 1
41 #define EVENT_FD_WRITE 2
42
43 struct fd_event {
44         struct fd_event *next, *prev;
45         int fd;
46         int flags; /* see EVENT_FD_* flags */
47         void (*handler)(struct fd_event *fde, int flags);
48         void *data;
49         size_t length, done;
50         void (*finished)(void *private_data, BOOL success);
51         void *private_data;
52 };
53
54 struct sid_ctr {
55         DOM_SID *sid;
56         BOOL finished;
57         const char *domain;
58         const char *name;
59         enum SID_NAME_USE type;
60 };
61
62 struct winbindd_cli_state {
63         struct winbindd_cli_state *prev, *next;   /* Linked list pointers */
64         int sock;                                 /* Open socket from client */
65         struct fd_event fd_event;
66         pid_t pid;                                /* pid of client */
67         BOOL finished;                            /* Can delete from list */
68         BOOL write_extra_data;                    /* Write extra_data field */
69         time_t last_access;                       /* Time of last access (read or write) */
70         BOOL privileged;                           /* Is the client 'privileged' */
71
72         TALLOC_CTX *mem_ctx;                      /* memory per request */
73         struct winbindd_request request;          /* Request from client */
74         struct winbindd_response response;        /* Respose to client */
75         BOOL getpwent_initialized;                /* Has getpwent_state been
76                                                    * initialized? */
77         BOOL getgrent_initialized;                /* Has getgrent_state been
78                                                    * initialized? */
79         struct getent_state *getpwent_state;      /* State for getpwent() */
80         struct getent_state *getgrent_state;      /* State for getgrent() */
81 };
82
83 /* State between get{pw,gr}ent() calls */
84
85 struct getent_state {
86         struct getent_state *prev, *next;
87         void *sam_entries;
88         uint32 sam_entry_index, num_sam_entries;
89         BOOL got_sam_entries;
90         fstring domain_name;
91 };
92
93 /* Storage for cached getpwent() user entries */
94
95 struct getpwent_user {
96         fstring name;                        /* Account name */
97         fstring gecos;                       /* User information */
98         fstring homedir;                     /* User Home Directory */
99         fstring shell;                       /* User Login Shell */
100         DOM_SID user_sid;                    /* NT user and primary group SIDs */
101         DOM_SID group_sid;
102 };
103
104 /* Server state structure */
105
106 struct winbindd_state {
107
108         /* User and group id pool */
109
110         uid_t uid_low, uid_high;               /* Range of uids to allocate */
111         gid_t gid_low, gid_high;               /* Range of gids to allocate */
112 };
113
114 extern struct winbindd_state server_state;  /* Server information */
115
116 typedef struct {
117         char *acct_name;
118         char *full_name;
119         char *homedir;
120         char *shell;
121         DOM_SID user_sid;                    /* NT user and primary group SIDs */
122         DOM_SID group_sid;
123 } WINBIND_USERINFO;
124
125 /* Our connection to the DC */
126
127 struct winbindd_cm_conn {
128         struct cli_state *cli;
129
130         struct rpc_pipe_client *samr_pipe;
131         POLICY_HND sam_connect_handle, sam_domain_handle;
132
133         struct rpc_pipe_client *lsa_pipe;
134         POLICY_HND lsa_policy;
135
136         struct rpc_pipe_client *netlogon_pipe;
137 };
138
139 struct winbindd_async_request;
140
141 /* Async child */
142
143 struct winbindd_child {
144         struct winbindd_child *next, *prev;
145
146         pid_t pid;
147         struct winbindd_domain *domain;
148         pstring logfilename;
149
150         TALLOC_CTX *mem_ctx;
151         struct fd_event event;
152         struct timed_event *lockout_policy_event;
153         struct winbindd_async_request *requests;
154 };
155
156 /* Structures to hold per domain information */
157
158 struct winbindd_domain {
159         fstring name;                          /* Domain name */        
160         fstring alt_name;                      /* alt Domain name (if any) */
161         DOM_SID sid;                           /* SID for this domain */
162         BOOL initialized;                      /* Did we already ask for the domain mode? */
163         BOOL native_mode;                      /* is this a win2k domain in native mode ? */
164         BOOL active_directory;                 /* is this a win2k active directory ? */
165         BOOL primary;                          /* is this our primary domain ? */
166         BOOL internal;                         /* BUILTIN and member SAM */
167         BOOL online;                           /* is this domain available ? */
168
169         /* Lookup methods for this domain (LDAP or RPC) */
170         struct winbindd_methods *methods;
171
172         /* the backend methods are used by the cache layer to find the right
173            backend */
174         struct winbindd_methods *backend;
175
176         /* Private data for the backends (used for connection cache) */
177
178         void *private_data; 
179
180         /* A working DC */
181         fstring dcname;
182         struct sockaddr_in dcaddr;
183
184         /* Sequence number stuff */
185
186         time_t last_seq_check;
187         uint32 sequence_number;
188         NTSTATUS last_status;
189
190         /* The smb connection */
191
192         struct winbindd_cm_conn conn;
193
194         /* The child pid we're talking to */
195
196         struct winbindd_child child;
197
198         /* Linked list info */
199
200         struct winbindd_domain *prev, *next;
201 };
202
203 /* per-domain methods. This is how LDAP vs RPC is selected
204  */
205 struct winbindd_methods {
206         /* does this backend provide a consistent view of the data? (ie. is the primary group
207            always correct) */
208         BOOL consistent;
209
210         /* get a list of users, returning a WINBIND_USERINFO for each one */
211         NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
212                                    TALLOC_CTX *mem_ctx,
213                                    uint32 *num_entries, 
214                                    WINBIND_USERINFO **info);
215
216         /* get a list of domain groups */
217         NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
218                                     TALLOC_CTX *mem_ctx,
219                                     uint32 *num_entries, 
220                                     struct acct_info **info);
221
222         /* get a list of domain local groups */
223         NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
224                                     TALLOC_CTX *mem_ctx,
225                                     uint32 *num_entries, 
226                                     struct acct_info **info);
227                                     
228         /* convert one user or group name to a sid */
229         NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
230                                 TALLOC_CTX *mem_ctx,
231                                 const char *domain_name,
232                                 const char *name,
233                                 DOM_SID *sid,
234                                 enum SID_NAME_USE *type);
235
236         /* convert a sid to a user or group name */
237         NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
238                                 TALLOC_CTX *mem_ctx,
239                                 const DOM_SID *sid,
240                                 char **domain_name,
241                                 char **name,
242                                 enum SID_NAME_USE *type);
243
244         /* lookup user info for a given SID */
245         NTSTATUS (*query_user)(struct winbindd_domain *domain, 
246                                TALLOC_CTX *mem_ctx, 
247                                const DOM_SID *user_sid,
248                                WINBIND_USERINFO *user_info);
249
250         /* lookup all groups that a user is a member of. The backend
251            can also choose to lookup by username or rid for this
252            function */
253         NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
254                                       TALLOC_CTX *mem_ctx,
255                                       const DOM_SID *user_sid,
256                                       uint32 *num_groups, DOM_SID **user_gids);
257
258         /* Lookup all aliases that the sids delivered are member of. This is
259          * to implement 'domain local groups' correctly */
260         NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
261                                        TALLOC_CTX *mem_ctx,
262                                        uint32 num_sids,
263                                        const DOM_SID *sids,
264                                        uint32 *num_aliases,
265                                        uint32 **alias_rids);
266
267         /* find all members of the group with the specified group_rid */
268         NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
269                                     TALLOC_CTX *mem_ctx,
270                                     const DOM_SID *group_sid,
271                                     uint32 *num_names, 
272                                     DOM_SID **sid_mem, char ***names, 
273                                     uint32 **name_types);
274
275         /* return the current global sequence number */
276         NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
277
278         /* return the lockout policy */
279         NTSTATUS (*lockout_policy)(struct winbindd_domain *domain, 
280                                    TALLOC_CTX *mem_ctx,
281                                    SAM_UNK_INFO_12 *lockout_policy);
282  
283         /* return the lockout policy */
284         NTSTATUS (*password_policy)(struct winbindd_domain *domain, 
285                                     TALLOC_CTX *mem_ctx,
286                                     SAM_UNK_INFO_1 *password_policy);
287  
288         /* enumerate trusted domains */
289         NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
290                                     TALLOC_CTX *mem_ctx,
291                                     uint32 *num_domains,
292                                     char ***names,
293                                     char ***alt_names,
294                                     DOM_SID **dom_sids);
295 };
296
297 /* Used to glue a policy handle and cli_state together */
298
299 typedef struct {
300         struct cli_state *cli;
301         POLICY_HND pol;
302 } CLI_POLICY_HND;
303
304 /* Filled out by IDMAP backends */
305 struct winbindd_idmap_methods {
306   /* Called when backend is first loaded */
307   BOOL (*init)(void);
308
309   BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
310   BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
311
312   BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
313   BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
314
315   /* Called when backend is unloaded */
316   BOOL (*close)(void);
317   /* Called to dump backend status */
318   void (*status)(void);
319 };
320
321 #include "nsswitch/winbindd_proto.h"
322
323 #define WINBINDD_ESTABLISH_LOOP 30
324 #define WINBINDD_RESCAN_FREQ 300
325 #define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
326 #define DOM_SEQUENCE_NONE ((uint32)-1)
327
328 #endif /* _WINBINDD_H */