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/>.
26 #include "nsswitch/winbind_struct_protocol.h"
27 #include "nsswitch/libwbclient/wbclient.h"
33 #ifdef HAVE_SYS_MMAN_H
38 #define DBGC_CLASS DBGC_WINBIND
40 #define WB_REPLACE_CHAR '_'
42 struct winbindd_fd_event {
43 struct winbindd_fd_event *next, *prev;
45 int flags; /* see EVENT_FD_* flags */
46 void (*handler)(struct winbindd_fd_event *fde, int flags);
49 void (*finished)(void *private_data, bool success);
58 enum lsa_SidType type;
61 struct winbindd_cli_state {
62 struct winbindd_cli_state *prev, *next; /* Linked list pointers */
63 int sock; /* Open socket from client */
64 struct winbindd_fd_event fd_event;
65 pid_t pid; /* pid of client */
66 bool finished; /* Can delete from list */
67 bool write_extra_data; /* Write extra_data field */
68 time_t last_access; /* Time of last access (read or write) */
69 bool privileged; /* Is the client 'privileged' */
71 TALLOC_CTX *mem_ctx; /* memory per request */
72 struct winbindd_request request; /* Request from client */
73 struct winbindd_response response; /* Respose to client */
74 bool getpwent_initialized; /* Has getpwent_state been
76 bool getgrent_initialized; /* Has getgrent_state been
78 struct getent_state *getpwent_state; /* State for getpwent() */
79 struct getent_state *getgrent_state; /* State for getgrent() */
82 /* State between get{pw,gr}ent() calls */
85 struct getent_state *prev, *next;
87 uint32 sam_entry_index, num_sam_entries;
92 /* Storage for cached getpwent() user entries */
94 struct getpwent_user {
95 fstring name; /* Account name */
96 fstring gecos; /* User information */
97 fstring homedir; /* User Home Directory */
98 fstring shell; /* User Login Shell */
99 DOM_SID user_sid; /* NT user and primary group SIDs */
103 /* Server state structure */
110 gid_t primary_gid; /* allow the nss_info
111 backend to set the primary group */
112 DOM_SID user_sid; /* NT user and primary group SIDs */
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 struct rpc_pipe_client *netlogon_pipe;
130 struct winbindd_async_request;
134 struct winbindd_domain;
136 struct winbindd_child_dispatch_table {
138 enum winbindd_cmd struct_cmd;
139 enum winbindd_result (*struct_fn)(struct winbindd_domain *domain,
140 struct winbindd_cli_state *state);
143 struct winbindd_child {
144 struct winbindd_child *next, *prev;
147 struct winbindd_domain *domain;
150 struct winbindd_fd_event event;
151 struct timed_event *lockout_policy_event;
152 struct timed_event *machine_password_change_event;
153 struct winbindd_async_request *requests;
155 const struct winbindd_child_dispatch_table *table;
158 /* Structures to hold per domain information */
160 struct winbindd_domain {
161 fstring name; /* Domain name (NetBIOS) */
162 fstring alt_name; /* alt Domain name, if any (FQDN for ADS) */
163 fstring forest_name; /* Name of the AD forest we're in */
164 DOM_SID sid; /* SID for this domain */
165 uint32 domain_flags; /* Domain flags from netlogon.h */
166 uint32 domain_type; /* Domain type from netlogon.h */
167 uint32 domain_trust_attribs; /* Trust attribs from netlogon.h */
168 bool initialized; /* Did we already ask for the domain mode? */
169 bool native_mode; /* is this a win2k domain in native mode ? */
170 bool active_directory; /* is this a win2k active directory ? */
171 bool primary; /* is this our primary domain ? */
172 bool internal; /* BUILTIN and member SAM */
173 bool online; /* is this domain available ? */
174 time_t startup_time; /* When we set "startup" true. */
175 bool startup; /* are we in the first 30 seconds after startup_time ? */
177 bool can_do_samlogon_ex; /* Due to the lack of finer control what type
178 * of DC we have, let us try to do a
179 * credential-chain less samlogon_ex call
180 * with AD and schannel. If this fails with
181 * DCERPC_FAULT_OP_RNG_ERROR, then set this
182 * to False. This variable is around so that
183 * we don't have to try _ex every time. */
185 /* Lookup methods for this domain (LDAP or RPC) */
186 struct winbindd_methods *methods;
188 /* the backend methods are used by the cache layer to find the right
190 struct winbindd_methods *backend;
192 /* Private data for the backends (used for connection cache) */
197 * idmap config settings, used to tell the idmap child which
198 * special domain config to use for a mapping
200 bool have_idmap_config;
201 uint32_t id_range_low, id_range_high;
204 pid_t dc_probe_pid; /* Child we're using to detect the DC. */
206 struct sockaddr_storage dcaddr;
208 /* Sequence number stuff */
210 time_t last_seq_check;
211 uint32 sequence_number;
212 NTSTATUS last_status;
214 /* The smb connection */
216 struct winbindd_cm_conn conn;
218 /* The child pid we're talking to */
220 struct winbindd_child child;
222 /* Callback we use to try put us back online. */
224 uint32 check_online_timeout;
225 struct timed_event *check_online_event;
227 /* Linked list info */
229 struct winbindd_domain *prev, *next;
232 /* per-domain methods. This is how LDAP vs RPC is selected
234 struct winbindd_methods {
235 /* does this backend provide a consistent view of the data? (ie. is the primary group
239 /* get a list of users, returning a WINBIND_USERINFO for each one */
240 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
243 WINBIND_USERINFO **info);
245 /* get a list of domain groups */
246 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
249 struct acct_info **info);
251 /* get a list of domain local groups */
252 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
255 struct acct_info **info);
257 /* convert one user or group name to a sid */
258 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
260 enum winbindd_cmd orig_cmd,
261 const char *domain_name,
264 enum lsa_SidType *type);
266 /* convert a sid to a user or group name */
267 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
272 enum lsa_SidType *type);
274 NTSTATUS (*rids_to_names)(struct winbindd_domain *domain,
276 const DOM_SID *domain_sid,
281 enum lsa_SidType **types);
283 /* lookup user info for a given SID */
284 NTSTATUS (*query_user)(struct winbindd_domain *domain,
286 const DOM_SID *user_sid,
287 WINBIND_USERINFO *user_info);
289 /* lookup all groups that a user is a member of. The backend
290 can also choose to lookup by username or rid for this
292 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
294 const DOM_SID *user_sid,
295 uint32 *num_groups, DOM_SID **user_gids);
297 /* Lookup all aliases that the sids delivered are member of. This is
298 * to implement 'domain local groups' correctly */
299 NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
304 uint32 **alias_rids);
306 /* find all members of the group with the specified group_rid */
307 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
309 const DOM_SID *group_sid,
311 DOM_SID **sid_mem, char ***names,
312 uint32 **name_types);
314 /* return the current global sequence number */
315 NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
317 /* return the lockout policy */
318 NTSTATUS (*lockout_policy)(struct winbindd_domain *domain,
320 struct samr_DomInfo12 *lockout_policy);
322 /* return the lockout policy */
323 NTSTATUS (*password_policy)(struct winbindd_domain *domain,
325 struct samr_DomInfo1 *password_policy);
327 /* enumerate trusted domains */
328 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
336 /* Filled out by IDMAP backends */
337 struct winbindd_idmap_methods {
338 /* Called when backend is first loaded */
341 bool (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
342 bool (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
344 bool (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
345 bool (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
347 /* Called when backend is unloaded */
349 /* Called to dump backend status */
350 void (*status)(void);
353 /* Data structures for dealing with the trusted domain cache */
355 struct winbindd_tdc_domain {
356 const char *domain_name;
357 const char *dns_name;
360 uint32 trust_attribs;
364 /* Switch for listing users or groups */
370 struct WINBINDD_MEMORY_CREDS {
371 struct WINBINDD_MEMORY_CREDS *next, *prev;
372 const char *username; /* lookup key. */
376 uint8_t *nt_hash; /* Base pointer for the following 2 */
381 struct WINBINDD_CCACHE_ENTRY {
382 struct WINBINDD_CCACHE_ENTRY *next, *prev;
383 const char *principal_name;
386 const char *username;
388 struct WINBINDD_MEMORY_CREDS *cred_ptr;
394 struct timed_event *event;
397 #include "winbindd/winbindd_proto.h"
399 #define WINBINDD_ESTABLISH_LOOP 30
400 #define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
401 #define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
402 #define DOM_SEQUENCE_NONE ((uint32)-1)
404 #define IS_DOMAIN_OFFLINE(x) ( lp_winbind_offline_logon() && \
405 ( get_global_winbindd_state_offline() \
407 #define IS_DOMAIN_ONLINE(x) (!IS_DOMAIN_OFFLINE(x))
409 #endif /* _WINBINDD_H */