This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[vlendec/samba-autobuild/.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    
8    This library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Library General Public
10    License as published by the Free Software Foundation; either
11    version 2 of the License, or (at your option) any later version.
12    
13    This library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Library General Public License for more details.
17    
18    You should have received a copy of the GNU Library General Public
19    License along with this library; if not, write to the
20    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA  02111-1307, USA.   
22 */
23
24 #ifndef _WINBINDD_H
25 #define _WINBINDD_H
26
27 #include "includes.h"
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 privilaged;                           /* Is the client 'privilaged' */
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         uint32 user_rid, group_rid;          /* NT user and group rids */
69 };
70
71 /* Server state structure */
72
73 struct winbindd_state {
74
75         /* User and group id pool */
76
77         uid_t uid_low, uid_high;               /* Range of uids to allocate */
78         gid_t gid_low, gid_high;               /* Range of gids to allocate */
79 };
80
81 extern struct winbindd_state server_state;  /* Server information */
82
83 typedef struct {
84         char *acct_name;
85         char *full_name;
86         uint32 user_rid;
87         uint32 group_rid; /* primary group */
88 } WINBIND_USERINFO;
89
90 /* Structures to hold per domain information */
91
92 struct winbindd_domain {
93         fstring name;                          /* Domain name */        
94         fstring alt_name;                      /* alt Domain name (if any) */
95         DOM_SID sid;                           /* SID for this domain */
96         BOOL native_mode;                      /* is this a win2k domain in native mode ? */
97
98         /* Lookup methods for this domain (LDAP or RPC) */
99
100         struct winbindd_methods *methods;
101
102         /* Private data for the backends (used for connection cache) */
103
104         void *private; 
105
106         /* Sequence number stuff */
107
108         time_t last_seq_check;
109         uint32 sequence_number;
110
111         /* Linked list info */
112
113         struct winbindd_domain *prev, *next;
114 };
115
116 /* per-domain methods. This is how LDAP vs RPC is selected
117  */
118 struct winbindd_methods {
119         /* does this backend provide a consistent view of the data? (ie. is the primary group
120            always correct) */
121         BOOL consistent;
122
123         /* get a list of users, returning a WINBIND_USERINFO for each one */
124         NTSTATUS (*query_user_list)(struct winbindd_domain *domain,
125                                    TALLOC_CTX *mem_ctx,
126                                    uint32 *num_entries, 
127                                    WINBIND_USERINFO **info);
128
129         /* get a list of domain groups */
130         NTSTATUS (*enum_dom_groups)(struct winbindd_domain *domain,
131                                     TALLOC_CTX *mem_ctx,
132                                     uint32 *num_entries, 
133                                     struct acct_info **info);
134
135         /* get a list of domain local groups */
136         NTSTATUS (*enum_local_groups)(struct winbindd_domain *domain,
137                                     TALLOC_CTX *mem_ctx,
138                                     uint32 *num_entries, 
139                                     struct acct_info **info);
140                                     
141         /* convert one user or group name to a sid */
142         NTSTATUS (*name_to_sid)(struct winbindd_domain *domain,
143                                 const char *name,
144                                 DOM_SID *sid,
145                                 enum SID_NAME_USE *type);
146
147         /* convert a sid to a user or group name */
148         NTSTATUS (*sid_to_name)(struct winbindd_domain *domain,
149                                 TALLOC_CTX *mem_ctx,
150                                 DOM_SID *sid,
151                                 char **name,
152                                 enum SID_NAME_USE *type);
153
154         /* lookup user info for a given rid */
155         NTSTATUS (*query_user)(struct winbindd_domain *domain, 
156                                TALLOC_CTX *mem_ctx, 
157                                uint32 user_rid, 
158                                WINBIND_USERINFO *user_info);
159
160         /* lookup all groups that a user is a member of. The backend
161            can also choose to lookup by username or rid for this
162            function */
163         NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain,
164                                       TALLOC_CTX *mem_ctx,
165                                       uint32 user_rid, 
166                                       uint32 *num_groups, uint32 **user_gids);
167
168         /* find all members of the group with the specified group_rid */
169         NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain,
170                                     TALLOC_CTX *mem_ctx,
171                                     uint32 group_rid, uint32 *num_names, 
172                                     uint32 **rid_mem, char ***names, 
173                                     uint32 **name_types);
174
175         /* return the current global sequence number */
176         NTSTATUS (*sequence_number)(struct winbindd_domain *domain, uint32 *seq);
177
178         /* enumerate trusted domains */
179         NTSTATUS (*trusted_domains)(struct winbindd_domain *domain,
180                                     TALLOC_CTX *mem_ctx,
181                                     uint32 *num_domains,
182                                     char ***names,
183                                     char ***alt_names,
184                                     DOM_SID **dom_sids);
185
186         /* find the domain sid */
187         NTSTATUS (*domain_sid)(struct winbindd_domain *domain,
188                                DOM_SID *sid);
189
190         /* setup the list of alternate names for the domain, if any */
191         NTSTATUS (*alternate_name)(struct winbindd_domain *domain);
192 };
193
194 /* Used to glue a policy handle and cli_state together */
195
196 typedef struct {
197         struct cli_state *cli;
198         POLICY_HND pol;
199 } CLI_POLICY_HND;
200
201 #include "winbindd_proto.h"
202
203 #include "rpc_parse.h"
204 #include "rpc_client.h"
205
206 #define WINBINDD_ESTABLISH_LOOP 30
207 #define WINBINDD_RESCAN_FREQ 300
208
209 #define DOM_SEQUENCE_NONE ((uint32)-1)
210
211 #endif /* _WINBINDD_H */