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 '_'
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 bool write_extra_data; /* Write extra_data field */
55 time_t last_access; /* Time of last access (read or write) */
56 bool privileged; /* Is the client 'privileged' */
58 TALLOC_CTX *mem_ctx; /* memory per request */
59 NTSTATUS (*recv_fn)(struct tevent_req *req, TALLOC_CTX *mem_ctx,
60 struct winbindd_response **presp);
61 struct winbindd_request *request; /* Request from client */
62 struct winbindd_request _request;
63 struct tevent_queue *out_queue;
64 struct winbindd_response response; /* Respose to client */
65 bool getpwent_initialized; /* Has getpwent_state been
67 bool getgrent_initialized; /* Has getgrent_state been
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 */
76 struct getent_state *prev, *next;
78 uint32 sam_entry_index, num_sam_entries;
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 */
94 /* Server state structure */
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 */
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;
125 struct winbindd_domain;
127 struct winbindd_child_dispatch_table {
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;
138 struct winbindd_domain *domain;
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
182 struct winbindd_methods *backend;
184 /* Private data for the backends (used for connection cache) */
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;
196 pid_t dc_probe_pid; /* Child we're using to detect the DC. */
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
231 /* get a list of users, returning a WINBIND_USERINFO for each one */
232 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
235 WINBIND_USERINFO **info);
237 /* get a list of domain groups */
238 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
241 struct acct_info **info);
243 /* get a list of domain local groups */
244 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
247 struct acct_info **info);
249 /* convert one user or group name to a sid */
250 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
252 enum winbindd_cmd orig_cmd,
253 const char *domain_name,
256 enum lsa_SidType *type);
258 /* convert a sid to a user or group name */
259 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
264 enum lsa_SidType *type);
266 NTSTATUS (*rids_to_names)(struct winbindd_domain *domain,
268 const DOM_SID *domain_sid,
273 enum lsa_SidType **types);
275 /* lookup user info for a given SID */
276 NTSTATUS (*query_user)(struct winbindd_domain *domain,
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
284 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
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,
296 uint32 **alias_rids);
298 /* find all members of the group with the specified group_rid */
299 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
301 const DOM_SID *group_sid,
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,
312 struct samr_DomInfo12 *lockout_policy);
314 /* return the lockout policy */
315 NTSTATUS (*password_policy)(struct winbindd_domain *domain,
317 struct samr_DomInfo1 *password_policy);
319 /* enumerate trusted domains */
320 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
328 /* Filled out by IDMAP backends */
329 struct winbindd_idmap_methods {
330 /* Called when backend is first loaded */
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 */
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;
352 uint32 trust_attribs;
356 /* Switch for listing users or groups */
362 struct WINBINDD_MEMORY_CREDS {
363 struct WINBINDD_MEMORY_CREDS *next, *prev;
364 const char *username; /* lookup key. */
368 uint8_t *nt_hash; /* Base pointer for the following 2 */
373 struct WINBINDD_CCACHE_ENTRY {
374 struct WINBINDD_CCACHE_ENTRY *next, *prev;
375 const char *principal_name;
378 const char *username;
380 struct WINBINDD_MEMORY_CREDS *cred_ptr;
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() \
399 #define IS_DOMAIN_ONLINE(x) (!IS_DOMAIN_OFFLINE(x))
401 #endif /* _WINBINDD_H */