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 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.
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 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.
30 #include "winbindd_nss.h"
37 #define DBGC_CLASS DBGC_WINBIND
39 /* bits for fd_event.flags */
40 #define EVENT_FD_READ 1
41 #define EVENT_FD_WRITE 2
44 struct fd_event *next, *prev;
46 int flags; /* see EVENT_FD_* flags */
47 void (*handler)(struct fd_event *fde, int flags);
50 void (*finished)(void *private_data, BOOL success);
59 enum SID_NAME_USE type;
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' */
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
77 BOOL getgrent_initialized; /* Has getgrent_state been
79 struct getent_state *getpwent_state; /* State for getpwent() */
80 struct getent_state *getgrent_state; /* State for getgrent() */
83 /* State between get{pw,gr}ent() calls */
86 struct getent_state *prev, *next;
88 uint32 sam_entry_index, num_sam_entries;
93 /* Storage for cached getpwent() user entries */
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 */
104 /* Server state structure */
106 struct winbindd_state {
108 /* User and group id pool */
110 uid_t uid_low, uid_high; /* Range of uids to allocate */
111 gid_t gid_low, gid_high; /* Range of gids to allocate */
114 extern struct winbindd_state server_state; /* Server information */
121 DOM_SID user_sid; /* NT user and primary group SIDs */
125 /* Our connection to the DC */
127 struct winbindd_cm_conn {
128 struct cli_state *cli;
130 struct rpc_pipe_client *samr_pipe;
131 POLICY_HND sam_connect_handle, sam_domain_handle;
133 struct rpc_pipe_client *lsa_pipe;
134 POLICY_HND lsa_policy;
136 struct rpc_pipe_client *netlogon_pipe;
139 struct winbindd_async_request;
143 struct winbindd_child {
144 struct winbindd_child *next, *prev;
147 struct winbindd_domain *domain;
151 struct fd_event event;
152 struct timed_event *timed_event;
153 struct winbindd_async_request *requests;
156 /* Structures to hold per domain information */
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 ? */
169 /* Lookup methods for this domain (LDAP or RPC) */
170 struct winbindd_methods *methods;
172 /* the backend methods are used by the cache layer to find the right
174 struct winbindd_methods *backend;
176 /* Private data for the backends (used for connection cache) */
182 struct sockaddr_in dcaddr;
184 /* Sequence number stuff */
186 time_t last_seq_check;
187 uint32 sequence_number;
188 NTSTATUS last_status;
190 /* The smb connection */
192 struct winbindd_cm_conn conn;
194 /* The child pid we're talking to */
196 struct winbindd_child child;
198 /* Linked list info */
200 struct winbindd_domain *prev, *next;
203 /* per-domain methods. This is how LDAP vs RPC is selected
205 struct winbindd_methods {
206 /* does this backend provide a consistent view of the data? (ie. is the primary group
210 /* get a list of users, returning a WINBIND_USERINFO for each one */
211 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
214 WINBIND_USERINFO **info);
216 /* get a list of domain groups */
217 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
220 struct acct_info **info);
222 /* get a list of domain local groups */
223 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
226 struct acct_info **info);
228 /* convert one user or group name to a sid */
229 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
231 const char *domain_name,
234 enum SID_NAME_USE *type);
236 /* convert a sid to a user or group name */
237 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
242 enum SID_NAME_USE *type);
244 /* lookup user info for a given SID */
245 NTSTATUS (*query_user)(struct winbindd_domain *domain,
247 const DOM_SID *user_sid,
248 WINBIND_USERINFO *user_info);
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
253 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
255 const DOM_SID *user_sid,
256 uint32 *num_groups, DOM_SID **user_gids);
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,
265 uint32 **alias_rids);
267 /* find all members of the group with the specified group_rid */
268 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
270 const DOM_SID *group_sid,
272 DOM_SID **sid_mem, char ***names,
273 uint32 **name_types);
275 /* return the current global sequence number */
276 NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
278 /* return the lockout policy */
279 NTSTATUS (*lockout_policy)(struct winbindd_domain *domain,
281 SAM_UNK_INFO_12 *lockout_policy);
283 /* return the lockout policy */
284 NTSTATUS (*password_policy)(struct winbindd_domain *domain,
286 SAM_UNK_INFO_1 *password_policy);
288 /* enumerate trusted domains */
289 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
297 /* Used to glue a policy handle and cli_state together */
300 struct cli_state *cli;
304 /* Filled out by IDMAP backends */
305 struct winbindd_idmap_methods {
306 /* Called when backend is first loaded */
309 BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
310 BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
312 BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
313 BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
315 /* Called when backend is unloaded */
317 /* Called to dump backend status */
318 void (*status)(void);
321 #include "nsswitch/winbindd_proto.h"
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)
328 #endif /* _WINBINDD_H */