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