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