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