Add alias support to winbindd_passdb. Sorry, Simo, this does not leave too
[metze/samba/wip.git] / source3 / nsswitch / winbindd.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind daemon for ntdom nss module
5
6    Copyright (C) Tim Potter 2000
7    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
8    
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.
13    
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.
18    
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.   
23 */
24
25 #ifndef _WINBINDD_H
26 #define _WINBINDD_H
27
28 #include "nterr.h"
29
30 #include "winbindd_nss.h"
31
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_WINBIND
34
35 /* Client state structure */
36
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' */
46
47         struct winbindd_request request;          /* Request from client */
48         struct winbindd_response response;        /* Respose to client */
49         struct getent_state *getpwent_state;      /* State for getpwent() */
50         struct getent_state *getgrent_state;      /* State for getgrent() */
51 };
52
53 /* State between get{pw,gr}ent() calls */
54
55 struct getent_state {
56         struct getent_state *prev, *next;
57         void *sam_entries;
58         uint32 sam_entry_index, num_sam_entries;
59         BOOL got_sam_entries;
60         fstring domain_name;
61 };
62
63 /* Storage for cached getpwent() user entries */
64
65 struct getpwent_user {
66         fstring name;                        /* Account name */
67         fstring gecos;                       /* User information */
68         DOM_SID user_sid;                    /* NT user and primary group SIDs */
69         DOM_SID group_sid;
70 };
71
72 /* Server state structure */
73
74 struct winbindd_state {
75
76         /* User and group id pool */
77
78         uid_t uid_low, uid_high;               /* Range of uids to allocate */
79         gid_t gid_low, gid_high;               /* Range of gids to allocate */
80 };
81
82 extern struct winbindd_state server_state;  /* Server information */
83
84 typedef struct {
85         char *acct_name;
86         char *full_name;
87         DOM_SID *user_sid;                    /* NT user and primary group SIDs */
88         DOM_SID *group_sid;
89 } WINBIND_USERINFO;
90
91 /* Structures to hold per domain information */
92
93 struct winbindd_domain {
94         fstring name;                          /* Domain name */        
95         fstring alt_name;                      /* alt Domain name (if any) */
96         DOM_SID sid;                           /* SID for this domain */
97         BOOL native_mode;                      /* is this a win2k domain in native mode ? */
98         BOOL active_directory;                 /* is this a win2k active directory ? */
99         BOOL primary;                          /* is this our primary domain ? */
100         BOOL internal;          /* BUILTIN and member SAM */
101
102         /* Lookup methods for this domain (LDAP or RPC) */
103         struct winbindd_methods *methods;
104
105         /* the backend methods are used by the cache layer to find the right
106            backend */
107         struct winbindd_methods *backend;
108
109         /* Private data for the backends (used for connection cache) */
110
111         void *private; 
112
113         /* Sequence number stuff */
114
115         time_t last_seq_check;
116         uint32 sequence_number;
117         NTSTATUS last_status;
118
119         /* Linked list info */
120
121         struct winbindd_domain *prev, *next;
122 };
123
124 /* per-domain methods. This is how LDAP vs RPC is selected
125  */
126 struct winbindd_methods {
127         /* does this backend provide a consistent view of the data? (ie. is the primary group
128            always correct) */
129         BOOL consistent;
130
131         /* get a list of users, returning a WINBIND_USERINFO for each one */
132         NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
133                                    TALLOC_CTX *mem_ctx,
134                                    uint32 *num_entries, 
135                                    WINBIND_USERINFO **info);
136
137         /* get a list of domain groups */
138         NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
139                                     TALLOC_CTX *mem_ctx,
140                                     uint32 *num_entries, 
141                                     struct acct_info **info);
142
143         /* get a list of domain local groups */
144         NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
145                                     TALLOC_CTX *mem_ctx,
146                                     uint32 *num_entries, 
147                                     struct acct_info **info);
148                                     
149         /* convert one user or group name to a sid */
150         NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
151                                 TALLOC_CTX *mem_ctx,
152                                 const char *name,
153                                 DOM_SID *sid,
154                                 enum SID_NAME_USE *type);
155
156         /* convert a sid to a user or group name */
157         NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
158                                 TALLOC_CTX *mem_ctx,
159                                 const DOM_SID *sid,
160                                 char **name,
161                                 enum SID_NAME_USE *type);
162
163         /* lookup user info for a given SID */
164         NTSTATUS (*query_user)(struct winbindd_domain *domain, 
165                                TALLOC_CTX *mem_ctx, 
166                                const DOM_SID *user_sid,
167                                WINBIND_USERINFO *user_info);
168
169         /* lookup all groups that a user is a member of. The backend
170            can also choose to lookup by username or rid for this
171            function */
172         NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
173                                       TALLOC_CTX *mem_ctx,
174                                       const DOM_SID *user_sid,
175                                       uint32 *num_groups, DOM_SID ***user_gids);
176
177         /* find all members of the group with the specified group_rid */
178         NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
179                                     TALLOC_CTX *mem_ctx,
180                                     const DOM_SID *group_sid,
181                                     uint32 *num_names, 
182                                     DOM_SID ***sid_mem, char ***names, 
183                                     uint32 **name_types);
184
185         /* return the current global sequence number */
186         NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
187
188         /* enumerate trusted domains */
189         NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
190                                     TALLOC_CTX *mem_ctx,
191                                     uint32 *num_domains,
192                                     char ***names,
193                                     char ***alt_names,
194                                     DOM_SID **dom_sids);
195
196         /* find the domain sid */
197         NTSTATUS (*domain_sid)(struct winbindd_domain *domain,
198                                DOM_SID *sid);
199
200         /* setup the list of alternate names for the domain, if any */
201         NTSTATUS (*alternate_name)(struct winbindd_domain *domain);
202 };
203
204 /* Used to glue a policy handle and cli_state together */
205
206 typedef struct {
207         struct cli_state *cli;
208         POLICY_HND pol;
209 } CLI_POLICY_HND;
210
211 /* Filled out by IDMAP backends */
212 struct winbindd_idmap_methods {
213   /* Called when backend is first loaded */
214   BOOL (*init)(void);
215
216   BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid);
217   BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid);
218
219   BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid);
220   BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid);
221
222   /* Called when backend is unloaded */
223   BOOL (*close)(void);
224   /* Called to dump backend status */
225   void (*status)(void);
226 };
227
228 #include "../nsswitch/winbindd_proto.h"
229
230 #include "rpc_parse.h"
231 #include "rpc_client.h"
232
233 #define WINBINDD_ESTABLISH_LOOP 30
234 #define WINBINDD_RESCAN_FREQ 300
235
236 #define DOM_SEQUENCE_NONE ((uint32)-1)
237
238 #endif /* _WINBINDD_H */