r4879: Fix rewinddir -> rewind_dir. Noticed by James Peach.
[Samba/gebeck_regimport.git] / source3 / nsswitch / winbindd.h
blobcd1d16e34411349ac7aa6a26518fb0b38ea575ac
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 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.
25 #ifndef _WINBINDD_H
26 #define _WINBINDD_H
28 #include "nterr.h"
30 #include "winbindd_nss.h"
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_WINBIND
35 /* Client state structure */
37 struct winbindd_cli_state {
38 struct winbindd_cli_state *prev, *next; /* Linked list pointers */
39 int sock; /* Open socket from client */
40 pid_t pid; /* pid of client */
41 int read_buf_len, write_buf_len; /* Indexes in request/response */
42 BOOL finished; /* Can delete from list */
43 BOOL write_extra_data; /* Write extra_data field */
44 time_t last_access; /* Time of last access (read or write) */
45 BOOL privileged; /* Is the client 'privileged' */
47 struct winbindd_request request; /* Request from client */
48 struct winbindd_response response; /* Respose to client */
49 BOOL getpwent_initialized; /* Has getpwent_state been initialized? */
50 BOOL getgrent_initialized; /* Has getgrent_state been initialized? */
51 struct getent_state *getpwent_state; /* State for getpwent() */
52 struct getent_state *getgrent_state; /* State for getgrent() */
55 /* State between get{pw,gr}ent() calls */
57 struct getent_state {
58 struct getent_state *prev, *next;
59 void *sam_entries;
60 uint32 sam_entry_index, num_sam_entries;
61 BOOL got_sam_entries;
62 fstring domain_name;
65 /* Storage for cached getpwent() user entries */
67 struct getpwent_user {
68 fstring name; /* Account name */
69 fstring gecos; /* User information */
70 DOM_SID user_sid; /* NT user and primary group SIDs */
71 DOM_SID group_sid;
74 /* Server state structure */
76 struct winbindd_state {
78 /* User and group id pool */
80 uid_t uid_low, uid_high; /* Range of uids to allocate */
81 gid_t gid_low, gid_high; /* Range of gids to allocate */
84 extern struct winbindd_state server_state; /* Server information */
86 typedef struct {
87 char *acct_name;
88 char *full_name;
89 DOM_SID *user_sid; /* NT user and primary group SIDs */
90 DOM_SID *group_sid;
91 } WINBIND_USERINFO;
93 /* Structures to hold per domain information */
95 struct winbindd_domain {
96 fstring name; /* Domain name */
97 fstring alt_name; /* alt Domain name (if any) */
98 DOM_SID sid; /* SID for this domain */
99 BOOL initialized; /* Did we already ask for the domain mode? */
100 BOOL native_mode; /* is this a win2k domain in native mode ? */
101 BOOL active_directory; /* is this a win2k active directory ? */
102 BOOL primary; /* is this our primary domain ? */
103 BOOL internal; /* BUILTIN and member SAM */
105 /* Lookup methods for this domain (LDAP or RPC) */
106 struct winbindd_methods *methods;
108 /* the backend methods are used by the cache layer to find the right
109 backend */
110 struct winbindd_methods *backend;
112 /* Private data for the backends (used for connection cache) */
114 void *private;
116 /* A working DC */
117 fstring dcname;
118 struct sockaddr_in dcaddr;
120 /* Sequence number stuff */
122 time_t last_seq_check;
123 uint32 sequence_number;
124 NTSTATUS last_status;
126 /* Linked list info */
128 struct winbindd_domain *prev, *next;
131 /* per-domain methods. This is how LDAP vs RPC is selected
133 struct winbindd_methods {
134 /* does this backend provide a consistent view of the data? (ie. is the primary group
135 always correct) */
136 BOOL consistent;
138 /* get a list of users, returning a WINBIND_USERINFO for each one */
139 NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
140 TALLOC_CTX *mem_ctx,
141 uint32 *num_entries,
142 WINBIND_USERINFO **info);
144 /* get a list of domain groups */
145 NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
146 TALLOC_CTX *mem_ctx,
147 uint32 *num_entries,
148 struct acct_info **info);
150 /* get a list of domain local groups */
151 NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
152 TALLOC_CTX *mem_ctx,
153 uint32 *num_entries,
154 struct acct_info **info);
156 /* convert one user or group name to a sid */
157 NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
158 TALLOC_CTX *mem_ctx,
159 const char *domain_name,
160 const char *name,
161 DOM_SID *sid,
162 enum SID_NAME_USE *type);
164 /* convert a sid to a user or group name */
165 NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
166 TALLOC_CTX *mem_ctx,
167 const DOM_SID *sid,
168 char **domain_name,
169 char **name,
170 enum SID_NAME_USE *type);
172 /* lookup user info for a given SID */
173 NTSTATUS (*query_user)(struct winbindd_domain *domain,
174 TALLOC_CTX *mem_ctx,
175 const DOM_SID *user_sid,
176 WINBIND_USERINFO *user_info);
178 /* lookup all groups that a user is a member of. The backend
179 can also choose to lookup by username or rid for this
180 function */
181 NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
182 TALLOC_CTX *mem_ctx,
183 const DOM_SID *user_sid,
184 uint32 *num_groups, DOM_SID ***user_gids);
186 /* Lookup all aliases that the sids delivered are member of. This is
187 * to implement 'domain local groups' correctly */
188 NTSTATUS (*lookup_useraliases)(struct winbindd_domain *domain,
189 TALLOC_CTX *mem_ctx,
190 uint32 num_sids, DOM_SID **sids,
191 uint32 *num_aliases,
192 uint32 **alias_rids);
194 /* find all members of the group with the specified group_rid */
195 NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
196 TALLOC_CTX *mem_ctx,
197 const DOM_SID *group_sid,
198 uint32 *num_names,
199 DOM_SID ***sid_mem, char ***names,
200 uint32 **name_types);
202 /* return the current global sequence number */
203 NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
205 /* enumerate trusted domains */
206 NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
207 TALLOC_CTX *mem_ctx,
208 uint32 *num_domains,
209 char ***names,
210 char ***alt_names,
211 DOM_SID **dom_sids);
213 /* find the domain sid */
214 NTSTATUS (*domain_sid)(struct winbindd_domain *domain,
215 DOM_SID *sid);
217 /* setup the list of alternate names for the domain, if any */
218 NTSTATUS (*alternate_name)(struct winbindd_domain *domain);
221 /* Used to glue a policy handle and cli_state together */
223 typedef struct {
224 struct cli_state *cli;
225 POLICY_HND pol;
226 } CLI_POLICY_HND;
228 /* Filled out by IDMAP backends */
229 struct winbindd_idmap_methods {
230 /* Called when backend is first loaded */
231 BOOL (*init)(void);
233 BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
234 BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
236 BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
237 BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
239 /* Called when backend is unloaded */
240 BOOL (*close)(void);
241 /* Called to dump backend status */
242 void (*status)(void);
245 #include "nsswitch/winbindd_proto.h"
247 #include "rpc_parse.h"
248 #include "rpc_client.h"
250 #define WINBINDD_ESTABLISH_LOOP 30
251 #define WINBINDD_RESCAN_FREQ 300
253 #define DOM_SEQUENCE_NONE ((uint32)-1)
255 #endif /* _WINBINDD_H */