Make winbindd_cli_state->response a pointer instead of a struct member
[Samba.git] / source3 / winbindd / winbindd.h
blob4b4fc04d6d5593e4cd13a936bc026a9ddb115415
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 Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 3 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 Lesser General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _WINBINDD_H
24 #define _WINBINDD_H
26 #include "nsswitch/winbind_struct_protocol.h"
27 #include "nsswitch/libwbclient/wbclient.h"
29 #ifdef HAVE_LIBNSCD
30 #include <libnscd.h>
31 #endif
33 #ifdef HAVE_SYS_MMAN_H
34 #include <sys/mman.h>
35 #endif
37 #undef DBGC_CLASS
38 #define DBGC_CLASS DBGC_WINBIND
40 #define WB_REPLACE_CHAR '_'
42 struct sid_ctr {
43 DOM_SID *sid;
44 bool finished;
45 const char *domain;
46 const char *name;
47 enum lsa_SidType type;
50 struct winbindd_cli_state {
51 struct winbindd_cli_state *prev, *next; /* Linked list pointers */
52 int sock; /* Open socket from client */
53 pid_t pid; /* pid of client */
54 time_t last_access; /* Time of last access (read or write) */
55 bool privileged; /* Is the client 'privileged' */
57 TALLOC_CTX *mem_ctx; /* memory per request */
58 NTSTATUS (*recv_fn)(struct tevent_req *req, TALLOC_CTX *mem_ctx,
59 struct winbindd_response **presp);
60 struct winbindd_request *request; /* Request from client */
61 struct winbindd_request _request;
62 struct tevent_queue *out_queue;
63 struct winbindd_response *response;
64 struct winbindd_response _response; /* Respose to client */
65 bool getpwent_initialized; /* Has getpwent_state been
66 * initialized? */
67 bool getgrent_initialized; /* Has getgrent_state been
68 * initialized? */
69 struct getent_state *getpwent_state; /* State for getpwent() */
70 struct getent_state *getgrent_state; /* State for getgrent() */
73 /* State between get{pw,gr}ent() calls */
75 struct getent_state {
76 struct getent_state *prev, *next;
77 void *sam_entries;
78 uint32 sam_entry_index, num_sam_entries;
79 bool got_sam_entries;
80 fstring domain_name;
83 /* Storage for cached getpwent() user entries */
85 struct getpwent_user {
86 fstring name; /* Account name */
87 fstring gecos; /* User information */
88 fstring homedir; /* User Home Directory */
89 fstring shell; /* User Login Shell */
90 DOM_SID user_sid; /* NT user and primary group SIDs */
91 DOM_SID group_sid;
94 /* Server state structure */
96 typedef struct {
97 char *acct_name;
98 char *full_name;
99 char *homedir;
100 char *shell;
101 gid_t primary_gid; /* allow the nss_info
102 backend to set the primary group */
103 DOM_SID user_sid; /* NT user and primary group SIDs */
104 DOM_SID group_sid;
105 } WINBIND_USERINFO;
107 /* Our connection to the DC */
109 struct winbindd_cm_conn {
110 struct cli_state *cli;
112 struct rpc_pipe_client *samr_pipe;
113 struct policy_handle sam_connect_handle, sam_domain_handle;
115 struct rpc_pipe_client *lsa_pipe;
116 struct policy_handle lsa_policy;
118 struct rpc_pipe_client *netlogon_pipe;
121 struct winbindd_async_request;
123 /* Async child */
125 struct winbindd_domain;
127 struct winbindd_child_dispatch_table {
128 const char *name;
129 enum winbindd_cmd struct_cmd;
130 enum winbindd_result (*struct_fn)(struct winbindd_domain *domain,
131 struct winbindd_cli_state *state);
134 struct winbindd_child {
135 struct winbindd_child *next, *prev;
137 pid_t pid;
138 struct winbindd_domain *domain;
139 char *logfilename;
141 int sock;
142 struct tevent_queue *queue;
144 struct timed_event *lockout_policy_event;
145 struct timed_event *machine_password_change_event;
147 const struct winbindd_child_dispatch_table *table;
150 /* Structures to hold per domain information */
152 struct winbindd_domain {
153 fstring name; /* Domain name (NetBIOS) */
154 fstring alt_name; /* alt Domain name, if any (FQDN for ADS) */
155 fstring forest_name; /* Name of the AD forest we're in */
156 DOM_SID sid; /* SID for this domain */
157 uint32 domain_flags; /* Domain flags from netlogon.h */
158 uint32 domain_type; /* Domain type from netlogon.h */
159 uint32 domain_trust_attribs; /* Trust attribs from netlogon.h */
160 bool initialized; /* Did we already ask for the domain mode? */
161 bool native_mode; /* is this a win2k domain in native mode ? */
162 bool active_directory; /* is this a win2k active directory ? */
163 bool primary; /* is this our primary domain ? */
164 bool internal; /* BUILTIN and member SAM */
165 bool online; /* is this domain available ? */
166 time_t startup_time; /* When we set "startup" true. */
167 bool startup; /* are we in the first 30 seconds after startup_time ? */
169 bool can_do_samlogon_ex; /* Due to the lack of finer control what type
170 * of DC we have, let us try to do a
171 * credential-chain less samlogon_ex call
172 * with AD and schannel. If this fails with
173 * DCERPC_FAULT_OP_RNG_ERROR, then set this
174 * to False. This variable is around so that
175 * we don't have to try _ex every time. */
177 /* Lookup methods for this domain (LDAP or RPC) */
178 struct winbindd_methods *methods;
180 /* the backend methods are used by the cache layer to find the right
181 backend */
182 struct winbindd_methods *backend;
184 /* Private data for the backends (used for connection cache) */
186 void *private_data;
189 * idmap config settings, used to tell the idmap child which
190 * special domain config to use for a mapping
192 bool have_idmap_config;
193 uint32_t id_range_low, id_range_high;
195 /* A working DC */
196 pid_t dc_probe_pid; /* Child we're using to detect the DC. */
197 fstring dcname;
198 struct sockaddr_storage dcaddr;
200 /* Sequence number stuff */
202 time_t last_seq_check;
203 uint32 sequence_number;
204 NTSTATUS last_status;
206 /* The smb connection */
208 struct winbindd_cm_conn conn;
210 /* The child pid we're talking to */
212 struct winbindd_child child;
214 /* Callback we use to try put us back online. */
216 uint32 check_online_timeout;
217 struct timed_event *check_online_event;
219 /* Linked list info */
221 struct winbindd_domain *prev, *next;
224 /* per-domain methods. This is how LDAP vs RPC is selected
226 struct winbindd_methods {
227 /* does this backend provide a consistent view of the data? (ie. is the primary group
228 always correct) */
229 bool consistent;
231 /* get a list of users, returning a WINBIND_USERINFO for each one */
232 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
233 TALLOC_CTX *mem_ctx,
234 uint32 *num_entries,
235 WINBIND_USERINFO **info);
237 /* get a list of domain groups */
238 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
239 TALLOC_CTX *mem_ctx,
240 uint32 *num_entries,
241 struct acct_info **info);
243 /* get a list of domain local groups */
244 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
245 TALLOC_CTX *mem_ctx,
246 uint32 *num_entries,
247 struct acct_info **info);
249 /* convert one user or group name to a sid */
250 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
251 TALLOC_CTX *mem_ctx,
252 enum winbindd_cmd orig_cmd,
253 const char *domain_name,
254 const char *name,
255 DOM_SID *sid,
256 enum lsa_SidType *type);
258 /* convert a sid to a user or group name */
259 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
260 TALLOC_CTX *mem_ctx,
261 const DOM_SID *sid,
262 char **domain_name,
263 char **name,
264 enum lsa_SidType *type);
266 NTSTATUS (*rids_to_names)(struct winbindd_domain *domain,
267 TALLOC_CTX *mem_ctx,
268 const DOM_SID *domain_sid,
269 uint32 *rids,
270 size_t num_rids,
271 char **domain_name,
272 char ***names,
273 enum lsa_SidType **types);
275 /* lookup user info for a given SID */
276 NTSTATUS (*query_user)(struct winbindd_domain *domain,
277 TALLOC_CTX *mem_ctx,
278 const DOM_SID *user_sid,
279 WINBIND_USERINFO *user_info);
281 /* lookup all groups that a user is a member of. The backend
282 can also choose to lookup by username or rid for this
283 function */
284 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
285 TALLOC_CTX *mem_ctx,
286 const DOM_SID *user_sid,
287 uint32 *num_groups, DOM_SID **user_gids);
289 /* Lookup all aliases that the sids delivered are member of. This is
290 * to implement 'domain local groups' correctly */
291 NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
292 TALLOC_CTX *mem_ctx,
293 uint32 num_sids,
294 const DOM_SID *sids,
295 uint32 *num_aliases,
296 uint32 **alias_rids);
298 /* find all members of the group with the specified group_rid */
299 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
300 TALLOC_CTX *mem_ctx,
301 const DOM_SID *group_sid,
302 uint32 *num_names,
303 DOM_SID **sid_mem, char ***names,
304 uint32 **name_types);
306 /* return the current global sequence number */
307 NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
309 /* return the lockout policy */
310 NTSTATUS (*lockout_policy)(struct winbindd_domain *domain,
311 TALLOC_CTX *mem_ctx,
312 struct samr_DomInfo12 *lockout_policy);
314 /* return the lockout policy */
315 NTSTATUS (*password_policy)(struct winbindd_domain *domain,
316 TALLOC_CTX *mem_ctx,
317 struct samr_DomInfo1 *password_policy);
319 /* enumerate trusted domains */
320 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
321 TALLOC_CTX *mem_ctx,
322 uint32 *num_domains,
323 char ***names,
324 char ***alt_names,
325 DOM_SID **dom_sids);
328 /* Filled out by IDMAP backends */
329 struct winbindd_idmap_methods {
330 /* Called when backend is first loaded */
331 bool (*init)(void);
333 bool (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
334 bool (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
336 bool (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
337 bool (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
339 /* Called when backend is unloaded */
340 bool (*close)(void);
341 /* Called to dump backend status */
342 void (*status)(void);
345 /* Data structures for dealing with the trusted domain cache */
347 struct winbindd_tdc_domain {
348 const char *domain_name;
349 const char *dns_name;
350 DOM_SID sid;
351 uint32 trust_flags;
352 uint32 trust_attribs;
353 uint32 trust_type;
356 /* Switch for listing users or groups */
357 enum ent_type {
358 LIST_USERS = 0,
359 LIST_GROUPS,
362 struct WINBINDD_MEMORY_CREDS {
363 struct WINBINDD_MEMORY_CREDS *next, *prev;
364 const char *username; /* lookup key. */
365 uid_t uid;
366 int ref_count;
367 size_t len;
368 uint8_t *nt_hash; /* Base pointer for the following 2 */
369 uint8_t *lm_hash;
370 char *pass;
373 struct WINBINDD_CCACHE_ENTRY {
374 struct WINBINDD_CCACHE_ENTRY *next, *prev;
375 const char *principal_name;
376 const char *ccname;
377 const char *service;
378 const char *username;
379 const char *realm;
380 struct WINBINDD_MEMORY_CREDS *cred_ptr;
381 int ref_count;
382 uid_t uid;
383 time_t create_time;
384 time_t renew_until;
385 time_t refresh_time;
386 struct timed_event *event;
389 #include "winbindd/winbindd_proto.h"
391 #define WINBINDD_ESTABLISH_LOOP 30
392 #define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
393 #define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
394 #define DOM_SEQUENCE_NONE ((uint32)-1)
396 #define IS_DOMAIN_OFFLINE(x) ( lp_winbind_offline_logon() && \
397 ( get_global_winbindd_state_offline() \
398 || !(x)->online ) )
399 #define IS_DOMAIN_ONLINE(x) (!IS_DOMAIN_OFFLINE(x))
401 #endif /* _WINBINDD_H */