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