1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
/*
Unix SMB/CIFS implementation.
passdb structures and parameters
Copyright (C) Gerald Carter 2001
Copyright (C) Luke Kenneth Casson Leighton 1998 - 2000
Copyright (C) Andrew Bartlett 2002
Copyright (C) Simo Sorce 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _PASSDB_H
#define _PASSDB_H
/*
* fields_present flags meanings
* same names as found in samba4 idl files
*/
#define ACCT_USERNAME 0x00000001
#define ACCT_FULL_NAME 0x00000002
#define ACCT_RID 0x00000004
#define ACCT_PRIMARY_GID 0x00000008
#define ACCT_ADMIN_DESC 0x00000010
#define ACCT_DESCRIPTION 0x00000020
#define ACCT_HOME_DIR 0x00000040
#define ACCT_HOME_DRIVE 0x00000080
#define ACCT_LOGON_SCRIPT 0x00000100
#define ACCT_PROFILE 0x00000200
#define ACCT_WORKSTATIONS 0x00000400
#define ACCT_LAST_LOGON 0x00000800
#define ACCT_LAST_LOGOFF 0x00001000
#define ACCT_LOGON_HOURS 0x00002000
#define ACCT_BAD_PWD_COUNT 0x00004000
#define ACCT_NUM_LOGONS 0x00008000
#define ACCT_ALLOW_PWD_CHANGE 0x00010000
#define ACCT_FORCE_PWD_CHANGE 0x00020000
#define ACCT_LAST_PWD_CHANGE 0x00040000
#define ACCT_EXPIRY 0x00080000
#define ACCT_FLAGS 0x00100000
#define ACCT_CALLBACK 0x00200000
#define ACCT_COUNTRY_CODE 0x00400000
#define ACCT_CODE_PAGE 0x00800000
#define ACCT_NT_PWD_SET 0x01000000
#define ACCT_LM_PWD_SET 0x02000000
#define ACCT_PRIVATEDATA 0x04000000
#define ACCT_EXPIRED_FLAG 0x08000000
#define ACCT_SEC_DESC 0x10000000
#define ACCT_OWF_PWD 0x20000000
/*
* bit flags representing initialized fields in SAM_ACCOUNT
*/
enum pdb_elements {
PDB_UNINIT,
PDB_SMBHOME,
PDB_PROFILE,
PDB_DRIVE,
PDB_LOGONSCRIPT,
PDB_LOGONTIME,
PDB_LOGOFFTIME,
PDB_KICKOFFTIME,
PDB_BAD_PASSWORD_TIME,
PDB_CANCHANGETIME,
PDB_MUSTCHANGETIME,
PDB_PLAINTEXT_PW,
PDB_USERNAME,
PDB_FULLNAME,
PDB_DOMAIN,
PDB_NTUSERNAME,
PDB_HOURSLEN,
PDB_LOGONDIVS,
PDB_USERSID,
PDB_GROUPSID,
PDB_ACCTCTRL,
PDB_PASSLASTSET,
PDB_UNIXHOMEDIR,
PDB_ACCTDESC,
PDB_WORKSTATIONS,
PDB_UNKNOWNSTR,
PDB_MUNGEDDIAL,
PDB_HOURS,
PDB_FIELDS_PRESENT,
PDB_BAD_PASSWORD_COUNT,
PDB_LOGON_COUNT,
PDB_UNKNOWN6,
PDB_LMPASSWD,
PDB_NTPASSWD,
PDB_BACKEND_PRIVATE_DATA,
/* this must be the last element */
PDB_COUNT
};
enum pdb_group_elements {
PDB_GROUP_NAME,
PDB_GROUP_SID,
PDB_GROUP_SID_NAME_USE,
PDB_GROUP_MEMBERS,
/* this must be the last element */
PDB_GROUP_COUNT
};
enum pdb_trust_passwd_elements {
PDB_TRUST_PASS,
PDB_TRUST_SID,
PDB_TRUST_NAME,
PDB_TRUST_MODTIME,
PDB_TRUST_FLAGS,
PDB_TRUST_COUNT
};
enum pdb_value_state {
PDB_DEFAULT=0,
PDB_SET,
PDB_CHANGED
};
#define IS_SAM_SET(x, flag) (pdb_get_init_flags(x, flag) == PDB_SET)
#define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
#define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
typedef struct sam_passwd
{
TALLOC_CTX *mem_ctx;
void (*free_fn)(struct sam_passwd **);
struct pdb_methods *methods;
struct user_data {
/* initialization flags */
struct bitmap *change_flags;
struct bitmap *set_flags;
time_t logon_time; /* logon time */
time_t logoff_time; /* logoff time */
time_t kickoff_time; /* kickoff time */
time_t bad_password_time; /* last bad password entered */
time_t pass_last_set_time; /* password last set time */
time_t pass_can_change_time; /* password can change time */
time_t pass_must_change_time; /* password must change time */
const char * username; /* UNIX username string */
const char * domain; /* Windows Domain name */
const char * nt_username; /* Windows username string */
const char * full_name; /* user's full name string */
const char * unix_home_dir; /* UNIX home directory string */
const char * home_dir; /* home directory string */
const char * dir_drive; /* home directory drive string */
const char * logon_script; /* logon script string */
const char * profile_path; /* profile path string */
const char * acct_desc ; /* user description string */
const char * workstations; /* login from workstations string */
const char * unknown_str ; /* don't know what this is, yet. */
const char * munged_dial ; /* munged path name and dial-back tel number */
DOM_SID user_sid; /* Primary User SID */
DOM_SID group_sid; /* Primary Group SID */
DATA_BLOB lm_pw; /* .data is Null if no password */
DATA_BLOB nt_pw; /* .data is Null if no password */
char* plaintext_pw; /* is Null if not available */
uint16 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
uint32 fields_present; /* 0x00ff ffff */
uint16 logon_divs; /* 168 - number of hours in a week */
uint32 hours_len; /* normally 21 bytes */
uint8 hours[MAX_HOURS_LEN];
/* Was unknown_5. */
uint16 bad_password_count;
uint16 logon_count;
uint32 unknown_6; /* 0x0000 04ec */
/* a tag for who added the private methods */
const struct pdb_methods *backend_private_methods;
void *backend_private_data;
void (*backend_private_data_free_fn)(void **);
} private;
/* Lets see if the remaining code can get the hint that you
are meant to use the pdb_...() functions. */
} SAM_ACCOUNT;
typedef struct sam_group {
TALLOC_CTX *mem_ctx;
void (*free_fn)(struct sam_group **);
struct pdb_methods *methods;
struct group_data {
/* initialization flags */
struct bitmap *change_flags;
struct bitmap *set_flags;
const char *name; /* Windows group name string */
DOM_SID sid; /* Group SID */
enum SID_NAME_USE sid_name_use; /* Group type */
uint32 mem_num; /* Number of member SIDs */
DOM_SID *members; /* SID array */
} private;
} SAM_GROUP;
typedef struct _GROUP_INFO {
struct pdb_methods *methods;
DOM_SID sid;
enum SID_NAME_USE sid_name_use;
fstring nt_name;
fstring comment;
} GROUP_INFO;
typedef struct sam_trust_passwd {
TALLOC_CTX *mem_ctx;
void (*free_fn)(struct sam_trust_passwd **);
struct pdb_methods *methods;
struct trust_passwd_data {
uint16 flags; /* flags */
size_t uni_name_len; /* unicode name length */
smb_ucs2_t uni_name[32]; /* unicode domain name */
fstring pass; /* trust password */
time_t mod_time; /* last change time */
DOM_SID domain_sid; /* trusted domain sid */
} private;
} SAM_TRUST_PASSWD;
/*****************************************************************
Functions to be implemented by the new (v2) passdb API
****************************************************************/
/*
* This next constant specifies the version number of the PASSDB interface
* this SAMBA will load. Increment this if *ANY* changes are made to the interface.
*/
#define PASSDB_INTERFACE_VERSION 5
typedef struct pdb_context
{
struct pdb_methods *pdb_methods;
struct pdb_methods *pwent_methods;
/* These functions are wrappers for the functions listed above.
They may do extra things like re-reading a SAM_ACCOUNT on update */
NTSTATUS (*pdb_setsampwent)(struct pdb_context *, BOOL update);
void (*pdb_endsampwent)(struct pdb_context *);
NTSTATUS (*pdb_getsampwent)(struct pdb_context *, SAM_ACCOUNT *user);
NTSTATUS (*pdb_getsampwnam)(struct pdb_context *, SAM_ACCOUNT *sam_acct, const char *username);
NTSTATUS (*pdb_getsampwsid)(struct pdb_context *, SAM_ACCOUNT *sam_acct, const DOM_SID *sid);
NTSTATUS (*pdb_add_sam_account)(struct pdb_context *, SAM_ACCOUNT *sampass);
NTSTATUS (*pdb_update_sam_account)(struct pdb_context *, SAM_ACCOUNT *sampass);
NTSTATUS (*pdb_delete_sam_account)(struct pdb_context *, SAM_ACCOUNT *username);
/* group mapping functions: to be removed */
NTSTATUS (*pdb_getgrsid)(struct pdb_context *context, GROUP_MAP *map, DOM_SID sid);
NTSTATUS (*pdb_getgrgid)(struct pdb_context *context, GROUP_MAP *map, gid_t gid);
NTSTATUS (*pdb_getgrnam)(struct pdb_context *context, GROUP_MAP *map, const char *name);
NTSTATUS (*pdb_add_group_mapping_entry)(struct pdb_context *context,
GROUP_MAP *map);
NTSTATUS (*pdb_update_group_mapping_entry)(struct pdb_context *context,
GROUP_MAP *map);
NTSTATUS (*pdb_delete_group_mapping_entry)(struct pdb_context *context,
DOM_SID sid);
NTSTATUS (*pdb_enum_group_mapping)(struct pdb_context *context,
enum SID_NAME_USE sid_name_use,
GROUP_MAP **rmap, int *num_entries,
BOOL unix_only);
NTSTATUS (*pdb_add_aliasmem)(struct pdb_context *context,
const DOM_SID *alias,
const DOM_SID *member);
NTSTATUS (*pdb_del_aliasmem)(struct pdb_context *context,
const DOM_SID *alias,
const DOM_SID *member);
NTSTATUS (*pdb_enum_aliasmem)(struct pdb_context *context,
const DOM_SID *alias,
DOM_SID **members, int *num_members);
NTSTATUS (*pdb_enum_alias_memberships)(struct pdb_context *context,
const DOM_SID *alias,
DOM_SID **aliases,
int *num);
/* group functions */
NTSTATUS (*pdb_get_group_info_by_sid)(struct pdb_context *context, GROUP_INFO *info, const DOM_SID *group);
NTSTATUS (*pdb_get_group_list)(struct pdb_context *context, GROUP_INFO **info, const enum SID_NAME_USE sid_name_use, int *num_groups);
NTSTATUS (*pdb_get_group_sids)(struct pdb_context *context, const DOM_SID *group, DOM_SID **members, int *num_members);
NTSTATUS (*pdb_add_group)(struct pdb_context *context, const SAM_GROUP *group);
NTSTATUS (*pdb_update_group)(struct pdb_context *context, const SAM_GROUP *group);
NTSTATUS (*pdb_delete_group)(struct pdb_context *context, const DOM_SID *group);
NTSTATUS (*pdb_add_sid_to_group)(struct pdb_context *context, const DOM_SID *group, const DOM_SID *member);
NTSTATUS (*pdb_remove_sid_from_group)(struct pdb_context *context, const DOM_SID *group, const DOM_SID *member);
NTSTATUS (*pdb_get_group_info_by_name)(struct pdb_context *context, GROUP_INFO *info, const char *name);
NTSTATUS (*pdb_get_group_info_by_nt_name)(struct pdb_context *context, GROUP_INFO *info, const char *nt_name);
NTSTATUS (*pdb_get_group_uids)(struct pdb_context *context, const DOM_SID *group, uid_t **members, int *num_members);
/* trust password functions */
NTSTATUS (*pdb_gettrustpwent)(struct pdb_context *context, SAM_TRUST_PASSWD *trust);
NTSTATUS (*pdb_gettrustpwsid)(struct pdb_context *context, SAM_TRUST_PASSWD *trust, const DOM_SID *sid);
NTSTATUS (*pdb_add_trust_passwd)(struct pdb_context *context, SAM_TRUST_PASSWD* trust);
NTSTATUS (*pdb_update_trust_passwd)(struct pdb_context *context, SAM_TRUST_PASSWD* trust);
NTSTATUS (*pdb_delete_trust_passwd)(struct pdb_context *context, SAM_TRUST_PASSWD* trust);
/* privileges functions */
NTSTATUS (*pdb_add_sid_to_privilege)(struct pdb_context *context, const char *priv_name, const DOM_SID *sid);
NTSTATUS (*pdb_remove_sid_from_privilege)(struct pdb_context *context, const char *priv_name, const DOM_SID *sid);
NTSTATUS (*pdb_get_privilege_set)(struct pdb_context *context, NT_USER_TOKEN *token, PRIVILEGE_SET *privs);
NTSTATUS (*pdb_get_privilege_entry)(struct pdb_context *context, const char *privname, char **sid_list);
void (*free_fn)(struct pdb_context **);
TALLOC_CTX *mem_ctx;
} PDB_CONTEXT;
typedef struct pdb_methods
{
const char *name; /* What name got this module */
struct pdb_context *parent;
/* Use macros from dlinklist.h on these two */
struct pdb_methods *next;
struct pdb_methods *prev;
NTSTATUS (*setsampwent)(struct pdb_methods *, BOOL update);
void (*endsampwent)(struct pdb_methods *);
NTSTATUS (*getsampwent)(struct pdb_methods *, SAM_ACCOUNT *user);
NTSTATUS (*getsampwnam)(struct pdb_methods *, SAM_ACCOUNT *sam_acct, const char *username);
NTSTATUS (*getsampwsid)(struct pdb_methods *, SAM_ACCOUNT *sam_acct, const DOM_SID *sid);
NTSTATUS (*add_sam_account)(struct pdb_methods *, SAM_ACCOUNT *sampass);
NTSTATUS (*update_sam_account)(struct pdb_methods *, SAM_ACCOUNT *sampass);
NTSTATUS (*delete_sam_account)(struct pdb_methods *, SAM_ACCOUNT *username);
/* group mapping functions: to be removed */
NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, DOM_SID sid);
NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid);
NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name);
NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods,
GROUP_MAP *map);
NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods,
GROUP_MAP *map);
NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods,
DOM_SID sid);
NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods,
enum SID_NAME_USE sid_name_use,
GROUP_MAP **rmap, int *num_entries,
BOOL unix_only);
NTSTATUS (*add_aliasmem)(struct pdb_methods *methods,
const DOM_SID *alias, const DOM_SID *member);
NTSTATUS (*del_aliasmem)(struct pdb_methods *methods,
const DOM_SID *alias, const DOM_SID *member);
NTSTATUS (*enum_aliasmem)(struct pdb_methods *methods,
const DOM_SID *alias, DOM_SID **members,
int *num_members);
NTSTATUS (*enum_alias_memberships)(struct pdb_methods *methods,
const DOM_SID *sid,
DOM_SID **aliases, int *num);
/* group functions */
NTSTATUS (*get_group_info_by_sid)(struct pdb_methods *methods, GROUP_INFO *info, const DOM_SID *group);
NTSTATUS (*get_group_list)(struct pdb_methods *methods, GROUP_INFO **info, const enum SID_NAME_USE sid_name_use, int *num_groups);
NTSTATUS (*get_group_sids)(struct pdb_methods *methods, const DOM_SID *group, DOM_SID **members, int *num_members);
NTSTATUS (*add_group)(struct pdb_methods *methods, const SAM_GROUP *group);
NTSTATUS (*update_group)(struct pdb_methods *methods, const SAM_GROUP *group);
NTSTATUS (*delete_group)(struct pdb_methods *methods, const DOM_SID *group);
NTSTATUS (*add_sid_to_group)(struct pdb_methods *methods, const DOM_SID *group, const DOM_SID *member);
NTSTATUS (*remove_sid_from_group)(struct pdb_methods *methods, const DOM_SID *group, const DOM_SID *member);
NTSTATUS (*get_group_info_by_name)(struct pdb_methods *methods, GROUP_INFO *info, const char *name);
NTSTATUS (*get_group_info_by_nt_name)(struct pdb_methods *methods, GROUP_INFO *info, const char *nt_name);
NTSTATUS (*get_group_uids)(struct pdb_methods *methods, const DOM_SID *group, uid_t **members, int *num_members);
void *private_data; /* Private data of some kind */
void (*free_private_data)(void **);
/* trust password functions */
NTSTATUS (*gettrustpwent)(struct pdb_methods *methods, SAM_TRUST_PASSWD *trust);
NTSTATUS (*gettrustpwsid)(struct pdb_methods *methods, SAM_TRUST_PASSWD *trust, const DOM_SID *sid);
NTSTATUS (*add_trust_passwd)(struct pdb_methods *methods, const SAM_TRUST_PASSWD* trust);
NTSTATUS (*update_trust_passwd)(struct pdb_methods *methods, const SAM_TRUST_PASSWD* trust);
NTSTATUS (*delete_trust_passwd)(struct pdb_methods *methods, const SAM_TRUST_PASSWD* trust);
/* privileges functions */
NTSTATUS (*add_sid_to_privilege)(struct pdb_methods *methods, const char *priv_name, const DOM_SID *sid);
NTSTATUS (*remove_sid_from_privilege)(struct pdb_methods *methods, const char *priv_name, const DOM_SID *sid);
NTSTATUS (*get_privilege_set)(struct pdb_methods *methods, NT_USER_TOKEN *token, PRIVILEGE_SET *privs);
NTSTATUS (*get_privilege_entry)(struct pdb_methods *methods, const char *privname, char **sid_list);
} PDB_METHODS;
typedef NTSTATUS (*pdb_init_function)(struct pdb_context *,
struct pdb_methods **,
const char *);
struct pdb_init_function_entry {
const char *name;
/* Function to create a member of the pdb_methods list */
pdb_init_function init;
struct pdb_init_function_entry *prev, *next;
};
enum sql_search_field { SQL_SEARCH_NONE = 0, SQL_SEARCH_USER_SID = 1, SQL_SEARCH_USER_NAME = 2};
#endif /* _PASSDB_H */
|