Whitespace syncup with 3.0
[ira/wip.git] / source3 / include / passdb.h
1 /* 
2    Unix SMB/CIFS implementation.
3    passdb structures and parameters
4    Copyright (C) Gerald Carter 2001
5    Copyright (C) Luke Kenneth Casson Leighton 1998 - 2000
6    Copyright (C) Andrew Bartlett 2002
7    Copyright (C) Simo Sorce 2003
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program 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
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef _PASSDB_H
25 #define _PASSDB_H
26
27
28 /*
29  * bit flags representing initialized fields in SAM_ACCOUNT
30  */
31 enum pdb_elements {
32         PDB_UNINIT,
33         PDB_SMBHOME,
34         PDB_PROFILE,
35         PDB_DRIVE,
36         PDB_LOGONSCRIPT,
37         PDB_LOGONTIME,
38         PDB_LOGOFFTIME,
39         PDB_KICKOFFTIME,
40         PDB_CANCHANGETIME,
41         PDB_MUSTCHANGETIME,
42         PDB_PLAINTEXT_PW,
43         PDB_USERNAME,
44         PDB_FULLNAME,
45         PDB_DOMAIN,
46         PDB_NTUSERNAME,
47         PDB_HOURSLEN,
48         PDB_LOGONDIVS,
49         PDB_USERSID,
50         PDB_GROUPSID,
51         PDB_ACCTCTRL,
52         PDB_PASSLASTSET,
53         PDB_UNIXHOMEDIR,
54         PDB_ACCTDESC,
55         PDB_WORKSTATIONS,
56         PDB_UNKNOWNSTR,
57         PDB_MUNGEDDIAL,
58         PDB_HOURS,
59         PDB_UNKNOWN3,
60         PDB_BAD_PASSWORD_COUNT,
61         PDB_LOGON_COUNT,
62         PDB_UNKNOWN6,
63         PDB_LMPASSWD,
64         PDB_NTPASSWD,
65         PDB_BACKEND_PRIVATE_DATA,
66
67         /* this must be the last element */
68         PDB_COUNT
69 };
70
71 enum pdb_group_elements {
72         PDB_GROUP_NAME,
73         PDB_GROUP_SID,
74         PDB_GROUP_SID_NAME_USE,
75         PDB_GROUP_MEMBERS,
76
77         /* this must be the last element */
78         PDB_GROUP_COUNT
79 };
80
81
82 enum pdb_value_state {
83         PDB_DEFAULT=0,
84         PDB_SET,
85         PDB_CHANGED
86 };
87
88 #define IS_SAM_SET(x, flag)     (pdb_get_init_flags(x, flag) == PDB_SET)
89 #define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
90 #define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
91                 
92 typedef struct sam_passwd
93 {
94         TALLOC_CTX *mem_ctx;
95         
96         void (*free_fn)(struct sam_passwd **);
97
98         struct pdb_methods *methods;
99
100         struct user_data {
101                 /* initiailization flags */
102                 struct bitmap *change_flags;
103                 struct bitmap *set_flags;
104
105                 time_t logon_time;            /* logon time */
106                 time_t logoff_time;           /* logoff time */
107                 time_t kickoff_time;          /* kickoff time */
108                 time_t pass_last_set_time;    /* password last set time */
109                 time_t pass_can_change_time;  /* password can change time */
110                 time_t pass_must_change_time; /* password must change time */
111                 
112                 const char * username;     /* UNIX username string */
113                 const char * domain;       /* Windows Domain name */
114                 const char * nt_username;  /* Windows username string */
115                 const char * full_name;    /* user's full name string */
116                 const char * unix_home_dir;     /* UNIX home directory string */
117                 const char * home_dir;     /* home directory string */
118                 const char * dir_drive;    /* home directory drive string */
119                 const char * logon_script; /* logon script string */
120                 const char * profile_path; /* profile path string */
121                 const char * acct_desc  ;  /* user description string */
122                 const char * workstations; /* login from workstations string */
123                 const char * unknown_str ; /* don't know what this is, yet. */
124                 const char * munged_dial ; /* munged path name and dial-back tel number */
125                 
126                 DOM_SID user_sid;    /* Primary User SID */
127                 DOM_SID group_sid;   /* Primary Group SID */
128                 
129                 DATA_BLOB lm_pw; /* .data is Null if no password */
130                 DATA_BLOB nt_pw; /* .data is Null if no password */
131                 char* plaintext_pw; /* is Null if not available */
132                 
133                 uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
134                 uint32 unknown_3; /* 0x00ff ffff */
135                 
136                 uint16 logon_divs; /* 168 - number of hours in a week */
137                 uint32 hours_len; /* normally 21 bytes */
138                 uint8 hours[MAX_HOURS_LEN];
139                 
140                 /* Was unknown_5. */
141                 uint16 bad_password_count;
142                 uint16 logon_count;
143
144                 uint32 unknown_6; /* 0x0000 04ec */
145                 /* a tag for who added the private methods */
146                 const struct pdb_methods *backend_private_methods;
147                 void *backend_private_data; 
148                 void (*backend_private_data_free_fn)(void **);
149         } private;
150
151         /* Lets see if the remaining code can get the hint that you
152            are meant to use the pdb_...() functions. */
153         
154 } SAM_ACCOUNT;
155
156 typedef struct sam_group {
157         TALLOC_CTX *mem_ctx;
158         
159         void (*free_fn)(struct sam_group **);
160
161         struct pdb_methods *methods;
162
163         struct group_data {
164                 /* initiailization flags */
165                 struct bitmap *change_flags;
166                 struct bitmap *set_flags;
167
168                 const char *name;               /* Windows group name string */
169
170                 DOM_SID sid;                    /* Group SID */
171                 enum SID_NAME_USE sid_name_use; /* Group type */
172
173                 uint32 mem_num;                 /* Number of member SIDs */
174                 DOM_SID *members;               /* SID array */
175         } private;
176
177 } SAM_GROUP;
178
179
180 typedef struct _GROUP_INFO {
181         struct pdb_methods *methods;
182         DOM_SID sid;
183         enum SID_NAME_USE sid_name_use;
184         fstring nt_name;
185         fstring comment;
186 } GROUP_INFO;
187
188
189 /*****************************************************************
190  Functions to be implemented by the new (v2) passdb API 
191 ****************************************************************/
192
193 /*
194  * This next constant specifies the version number of the PASSDB interface
195  * this SAMBA will load. Increment this if *ANY* changes are made to the interface. 
196  */
197
198 #define PASSDB_INTERFACE_VERSION 4
199
200 typedef struct pdb_context 
201 {
202         struct pdb_methods *pdb_methods;
203         struct pdb_methods *pwent_methods;
204         
205         /* These functions are wrappers for the functions listed above.
206            They may do extra things like re-reading a SAM_ACCOUNT on update */
207
208         NTSTATUS (*pdb_setsampwent)(struct pdb_context *, BOOL update);
209         
210         void (*pdb_endsampwent)(struct pdb_context *);
211         
212         NTSTATUS (*pdb_getsampwent)(struct pdb_context *, SAM_ACCOUNT *user);
213         
214         NTSTATUS (*pdb_getsampwnam)(struct pdb_context *, SAM_ACCOUNT *sam_acct, const char *username);
215         
216         NTSTATUS (*pdb_getsampwsid)(struct pdb_context *, SAM_ACCOUNT *sam_acct, const DOM_SID *sid);
217
218         NTSTATUS (*pdb_add_sam_account)(struct pdb_context *, SAM_ACCOUNT *sampass);
219         
220         NTSTATUS (*pdb_update_sam_account)(struct pdb_context *, SAM_ACCOUNT *sampass);
221         
222         NTSTATUS (*pdb_delete_sam_account)(struct pdb_context *, SAM_ACCOUNT *username);
223
224         /* group mapping functions: to be removed */
225         
226         NTSTATUS (*pdb_getgrsid)(struct pdb_context *context, GROUP_MAP *map, DOM_SID sid);
227         
228         NTSTATUS (*pdb_getgrgid)(struct pdb_context *context, GROUP_MAP *map, gid_t gid);
229         
230         NTSTATUS (*pdb_getgrnam)(struct pdb_context *context, GROUP_MAP *map, const char *name);
231         
232         NTSTATUS (*pdb_add_group_mapping_entry)(struct pdb_context *context,
233                                                 GROUP_MAP *map);
234         
235         NTSTATUS (*pdb_update_group_mapping_entry)(struct pdb_context *context,
236                                                    GROUP_MAP *map);
237         
238         NTSTATUS (*pdb_delete_group_mapping_entry)(struct pdb_context *context,
239                                                    DOM_SID sid);
240         
241         NTSTATUS (*pdb_enum_group_mapping)(struct pdb_context *context,
242                                            enum SID_NAME_USE sid_name_use,
243                                            GROUP_MAP **rmap, int *num_entries,
244                                            BOOL unix_only);
245
246         /* group functions */
247
248         NTSTATUS (*pdb_get_group_info_by_sid)(struct pdb_context *context, GROUP_INFO *info, const DOM_SID *group);
249
250         NTSTATUS (*pdb_get_group_list)(struct pdb_context *context, GROUP_INFO **info, const enum SID_NAME_USE sid_name_use, int *num_groups);
251
252         NTSTATUS (*pdb_get_group_sids)(struct pdb_context *context, const DOM_SID *group, DOM_SID **members, int *num_members);
253
254         NTSTATUS (*pdb_add_group)(struct pdb_context *context, const SAM_GROUP *group);
255
256         NTSTATUS (*pdb_update_group)(struct pdb_context *context, const SAM_GROUP *group);
257
258         NTSTATUS (*pdb_delete_group)(struct pdb_context *context, const DOM_SID *group);
259
260         NTSTATUS (*pdb_add_sid_to_group)(struct pdb_context *context, const DOM_SID *group, const DOM_SID *member);
261
262         NTSTATUS (*pdb_remove_sid_from_group)(struct pdb_context *context, const DOM_SID *group, const DOM_SID *member);
263
264         NTSTATUS (*pdb_get_group_info_by_name)(struct pdb_context *context, GROUP_INFO *info, const char *name);
265
266         NTSTATUS (*pdb_get_group_info_by_nt_name)(struct pdb_context *context, GROUP_INFO *info, const char *nt_name);
267
268         NTSTATUS (*pdb_get_group_uids)(struct pdb_context *context, const DOM_SID *group, uid_t **members, int *num_members);
269
270         void (*free_fn)(struct pdb_context **);
271         
272         TALLOC_CTX *mem_ctx;
273         
274 } PDB_CONTEXT;
275
276 typedef struct pdb_methods 
277 {
278         const char *name; /* What name got this module */
279         struct pdb_context *parent;
280
281         /* Use macros from dlinklist.h on these two */
282         struct pdb_methods *next;
283         struct pdb_methods *prev;
284
285         NTSTATUS (*setsampwent)(struct pdb_methods *, BOOL update);
286         
287         void (*endsampwent)(struct pdb_methods *);
288         
289         NTSTATUS (*getsampwent)(struct pdb_methods *, SAM_ACCOUNT *user);
290         
291         NTSTATUS (*getsampwnam)(struct pdb_methods *, SAM_ACCOUNT *sam_acct, const char *username);
292         
293         NTSTATUS (*getsampwsid)(struct pdb_methods *, SAM_ACCOUNT *sam_acct, const DOM_SID *sid);
294         
295         NTSTATUS (*add_sam_account)(struct pdb_methods *, SAM_ACCOUNT *sampass);
296         
297         NTSTATUS (*update_sam_account)(struct pdb_methods *, SAM_ACCOUNT *sampass);
298         
299         NTSTATUS (*delete_sam_account)(struct pdb_methods *, SAM_ACCOUNT *username);
300
301         /* group mapping functions: to be removed */
302
303         NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, DOM_SID sid);
304
305         NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid);
306
307         NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name);
308
309         NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods,
310                                             GROUP_MAP *map);
311
312         NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods,
313                                                GROUP_MAP *map);
314
315         NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods,
316                                                DOM_SID sid);
317
318         NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods,
319                                        enum SID_NAME_USE sid_name_use,
320                                        GROUP_MAP **rmap, int *num_entries,
321                                        BOOL unix_only);
322
323         /* group functions */
324
325         NTSTATUS (*get_group_info_by_sid)(struct pdb_methods *methods, GROUP_INFO *info, const DOM_SID *group);
326
327         NTSTATUS (*get_group_list)(struct pdb_methods *methods, GROUP_INFO **info, const enum SID_NAME_USE sid_name_use, int *num_groups);
328
329         NTSTATUS (*get_group_sids)(struct pdb_methods *methods, const DOM_SID *group, DOM_SID **members, int *num_members);
330
331         NTSTATUS (*add_group)(struct pdb_methods *methods, const SAM_GROUP *group);
332
333         NTSTATUS (*update_group)(struct pdb_methods *methods, const SAM_GROUP *group);
334
335         NTSTATUS (*delete_group)(struct pdb_methods *methods, const DOM_SID *group);
336
337         NTSTATUS (*add_sid_to_group)(struct pdb_methods *methods, const DOM_SID *group, const DOM_SID *member);
338
339         NTSTATUS (*remove_sid_from_group)(struct pdb_methods *methods, const DOM_SID *group, const DOM_SID *member);
340
341         NTSTATUS (*get_group_info_by_name)(struct pdb_methods *methods, GROUP_INFO *info, const char *name);
342
343         NTSTATUS (*get_group_info_by_nt_name)(struct pdb_methods *methods, GROUP_INFO *info, const char *nt_name);
344
345         NTSTATUS (*get_group_uids)(struct pdb_methods *methods, const DOM_SID *group, uid_t **members, int *num_members);
346
347         void *private_data;  /* Private data of some kind */
348         
349         void (*free_private_data)(void **);
350
351 } PDB_METHODS;
352
353 typedef NTSTATUS (*pdb_init_function)(struct pdb_context *, 
354                          struct pdb_methods **, 
355                          const char *);
356
357 struct pdb_init_function_entry {
358         const char *name;
359         /* Function to create a member of the pdb_methods list */
360         pdb_init_function init;
361         struct pdb_init_function_entry *prev, *next;
362 };
363
364 #endif /* _PASSDB_H */