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