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"
28 #include "librpc/gen_ndr/wbint.h"
34 #ifdef HAVE_SYS_MMAN_H
39 #define DBGC_CLASS DBGC_WINBIND
41 #define WB_REPLACE_CHAR '_'
48 enum lsa_SidType type
;
51 struct winbindd_cli_state
{
52 struct winbindd_cli_state
*prev
, *next
; /* Linked list pointers */
53 int sock
; /* Open socket from client */
54 pid_t pid
; /* pid of client */
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
,
60 struct winbindd_response
*presp
);
61 struct winbindd_request
*request
; /* Request from client */
62 struct tevent_queue
*out_queue
;
63 struct winbindd_response
*response
; /* Respose to client */
64 bool getpwent_initialized
; /* Has getpwent_state been
66 bool getgrent_initialized
; /* Has getgrent_state been
68 struct getent_state
*getgrent_state
; /* State for getgrent() */
70 struct getpwent_state
*pwent_state
; /* State for getpwent() */
71 struct getgrent_state
*grent_state
; /* State for getgrent() */
74 /* State between get{pw,gr}ent() calls */
77 struct getent_state
*prev
, *next
;
79 uint32 sam_entry_index
, num_sam_entries
;
84 struct getpwent_state
{
85 struct winbindd_domain
*domain
;
88 struct wbint_userinfo
*users
;
91 struct getgrent_state
{
92 struct winbindd_domain
*domain
;
95 struct wbint_Principal
*groups
;
98 /* Storage for cached getpwent() user entries */
100 struct getpwent_user
{
101 fstring name
; /* Account name */
102 fstring gecos
; /* User information */
103 fstring homedir
; /* User Home Directory */
104 fstring shell
; /* User Login Shell */
105 DOM_SID user_sid
; /* NT user and primary group SIDs */
109 /* Our connection to the DC */
111 struct winbindd_cm_conn
{
112 struct cli_state
*cli
;
114 struct rpc_pipe_client
*samr_pipe
;
115 struct policy_handle sam_connect_handle
, sam_domain_handle
;
117 struct rpc_pipe_client
*lsa_pipe
;
118 struct policy_handle lsa_policy
;
120 struct rpc_pipe_client
*netlogon_pipe
;
123 struct winbindd_async_request
;
127 struct winbindd_domain
;
129 struct winbindd_child_dispatch_table
{
131 enum winbindd_cmd struct_cmd
;
132 enum winbindd_result (*struct_fn
)(struct winbindd_domain
*domain
,
133 struct winbindd_cli_state
*state
);
136 struct winbindd_child
{
137 struct winbindd_child
*next
, *prev
;
140 struct winbindd_domain
*domain
;
144 struct tevent_queue
*queue
;
145 struct rpc_pipe_client
*rpccli
;
147 struct timed_event
*lockout_policy_event
;
148 struct timed_event
*machine_password_change_event
;
150 const struct winbindd_child_dispatch_table
*table
;
153 /* Structures to hold per domain information */
155 struct winbindd_domain
{
156 fstring name
; /* Domain name (NetBIOS) */
157 fstring alt_name
; /* alt Domain name, if any (FQDN for ADS) */
158 fstring forest_name
; /* Name of the AD forest we're in */
159 DOM_SID sid
; /* SID for this domain */
160 uint32 domain_flags
; /* Domain flags from netlogon.h */
161 uint32 domain_type
; /* Domain type from netlogon.h */
162 uint32 domain_trust_attribs
; /* Trust attribs from netlogon.h */
163 bool initialized
; /* Did we already ask for the domain mode? */
164 bool native_mode
; /* is this a win2k domain in native mode ? */
165 bool active_directory
; /* is this a win2k active directory ? */
166 bool primary
; /* is this our primary domain ? */
167 bool internal
; /* BUILTIN and member SAM */
168 bool online
; /* is this domain available ? */
169 time_t startup_time
; /* When we set "startup" true. */
170 bool startup
; /* are we in the first 30 seconds after startup_time ? */
172 bool can_do_samlogon_ex
; /* Due to the lack of finer control what type
173 * of DC we have, let us try to do a
174 * credential-chain less samlogon_ex call
175 * with AD and schannel. If this fails with
176 * DCERPC_FAULT_OP_RNG_ERROR, then set this
177 * to False. This variable is around so that
178 * we don't have to try _ex every time. */
180 /* Lookup methods for this domain (LDAP or RPC) */
181 struct winbindd_methods
*methods
;
183 /* the backend methods are used by the cache layer to find the right
185 struct winbindd_methods
*backend
;
187 /* Private data for the backends (used for connection cache) */
192 * idmap config settings, used to tell the idmap child which
193 * special domain config to use for a mapping
195 bool have_idmap_config
;
196 uint32_t id_range_low
, id_range_high
;
199 pid_t dc_probe_pid
; /* Child we're using to detect the DC. */
201 struct sockaddr_storage dcaddr
;
203 /* Sequence number stuff */
205 time_t last_seq_check
;
206 uint32 sequence_number
;
207 NTSTATUS last_status
;
209 /* The smb connection */
211 struct winbindd_cm_conn conn
;
213 /* The child pid we're talking to */
215 struct winbindd_child child
;
217 /* Callback we use to try put us back online. */
219 uint32 check_online_timeout
;
220 struct timed_event
*check_online_event
;
222 /* Linked list info */
224 struct winbindd_domain
*prev
, *next
;
227 /* per-domain methods. This is how LDAP vs RPC is selected
229 struct winbindd_methods
{
230 /* does this backend provide a consistent view of the data? (ie. is the primary group
234 /* get a list of users, returning a wbint_userinfo for each one */
235 NTSTATUS (*query_user_list
)(struct winbindd_domain
*domain
,
238 struct wbint_userinfo
**info
);
240 /* get a list of domain groups */
241 NTSTATUS (*enum_dom_groups
)(struct winbindd_domain
*domain
,
244 struct acct_info
**info
);
246 /* get a list of domain local groups */
247 NTSTATUS (*enum_local_groups
)(struct winbindd_domain
*domain
,
250 struct acct_info
**info
);
252 /* convert one user or group name to a sid */
253 NTSTATUS (*name_to_sid
)(struct winbindd_domain
*domain
,
255 const char *domain_name
,
259 enum lsa_SidType
*type
);
261 /* convert a sid to a user or group name */
262 NTSTATUS (*sid_to_name
)(struct winbindd_domain
*domain
,
267 enum lsa_SidType
*type
);
269 NTSTATUS (*rids_to_names
)(struct winbindd_domain
*domain
,
271 const DOM_SID
*domain_sid
,
276 enum lsa_SidType
**types
);
278 /* lookup user info for a given SID */
279 NTSTATUS (*query_user
)(struct winbindd_domain
*domain
,
281 const DOM_SID
*user_sid
,
282 struct wbint_userinfo
*user_info
);
284 /* lookup all groups that a user is a member of. The backend
285 can also choose to lookup by username or rid for this
287 NTSTATUS (*lookup_usergroups
)(struct winbindd_domain
*domain
,
289 const DOM_SID
*user_sid
,
290 uint32
*num_groups
, DOM_SID
**user_gids
);
292 /* Lookup all aliases that the sids delivered are member of. This is
293 * to implement 'domain local groups' correctly */
294 NTSTATUS (*lookup_useraliases
)(struct winbindd_domain
*domain
,
299 uint32
**alias_rids
);
301 /* find all members of the group with the specified group_rid */
302 NTSTATUS (*lookup_groupmem
)(struct winbindd_domain
*domain
,
304 const DOM_SID
*group_sid
,
305 enum lsa_SidType type
,
307 DOM_SID
**sid_mem
, char ***names
,
308 uint32
**name_types
);
310 /* return the current global sequence number */
311 NTSTATUS (*sequence_number
)(struct winbindd_domain
*domain
, uint32
*seq
);
313 /* return the lockout policy */
314 NTSTATUS (*lockout_policy
)(struct winbindd_domain
*domain
,
316 struct samr_DomInfo12
*lockout_policy
);
318 /* return the lockout policy */
319 NTSTATUS (*password_policy
)(struct winbindd_domain
*domain
,
321 struct samr_DomInfo1
*password_policy
);
323 /* enumerate trusted domains */
324 NTSTATUS (*trusted_domains
)(struct winbindd_domain
*domain
,
332 /* Filled out by IDMAP backends */
333 struct winbindd_idmap_methods
{
334 /* Called when backend is first loaded */
337 bool (*get_sid_from_uid
)(uid_t uid
, DOM_SID
*sid
);
338 bool (*get_sid_from_gid
)(gid_t gid
, DOM_SID
*sid
);
340 bool (*get_uid_from_sid
)(DOM_SID
*sid
, uid_t
*uid
);
341 bool (*get_gid_from_sid
)(DOM_SID
*sid
, gid_t
*gid
);
343 /* Called when backend is unloaded */
345 /* Called to dump backend status */
346 void (*status
)(void);
349 /* Data structures for dealing with the trusted domain cache */
351 struct winbindd_tdc_domain
{
352 const char *domain_name
;
353 const char *dns_name
;
356 uint32 trust_attribs
;
360 /* Switch for listing users or groups */
366 struct WINBINDD_MEMORY_CREDS
{
367 struct WINBINDD_MEMORY_CREDS
*next
, *prev
;
368 const char *username
; /* lookup key. */
372 uint8_t *nt_hash
; /* Base pointer for the following 2 */
377 struct WINBINDD_CCACHE_ENTRY
{
378 struct WINBINDD_CCACHE_ENTRY
*next
, *prev
;
379 const char *principal_name
;
382 const char *username
;
384 struct WINBINDD_MEMORY_CREDS
*cred_ptr
;
390 struct timed_event
*event
;
393 #include "winbindd/winbindd_proto.h"
395 #define WINBINDD_ESTABLISH_LOOP 30
396 #define WINBINDD_RESCAN_FREQ lp_winbind_cache_time()
397 #define WINBINDD_PAM_AUTH_KRB5_RENEW_TIME 2592000 /* one month */
398 #define DOM_SEQUENCE_NONE ((uint32)-1)
400 #define IS_DOMAIN_OFFLINE(x) ( lp_winbind_offline_logon() && \
401 ( get_global_winbindd_state_offline() \
403 #define IS_DOMAIN_ONLINE(x) (!IS_DOMAIN_OFFLINE(x))
405 #endif /* _WINBINDD_H */