s3-passdb: use tevent_context in passdb.
[Samba.git] / source3 / include / passdb.h
blob37d35cfee3d5adb9e369773ed0bc8624280d14a5
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
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 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef _PASSDB_H
24 #define _PASSDB_H
26 #ifndef NT_HASH_LEN
27 #define NT_HASH_LEN 16
28 #endif
30 #ifndef LM_HASH_LEN
31 #define LM_HASH_LEN 16
32 #endif
34 #include "../librpc/gen_ndr/lsa.h"
35 #include <tevent.h>
37 /* group mapping headers */
39 #define ENUM_ONLY_MAPPED True
40 #define ENUM_ALL_MAPPED False
42 typedef struct _GROUP_MAP {
43 struct pdb_methods *methods;
44 gid_t gid;
45 struct dom_sid sid;
46 enum lsa_SidType sid_name_use;
47 char *nt_name;
48 char *comment;
49 } GROUP_MAP;
51 /* The following definitions come from groupdb/mapping.c */
53 NTSTATUS add_initial_entry(gid_t gid, const char *sid, enum lsa_SidType sid_name_use, const char *nt_name, const char *comment);
54 bool get_domain_group_from_sid(struct dom_sid sid, GROUP_MAP *map);
55 int smb_create_group(const char *unix_group, gid_t *new_gid);
56 int smb_delete_group(const char *unix_group);
57 int smb_set_primary_group(const char *unix_group, const char* unix_user);
58 int smb_add_user_group(const char *unix_group, const char *unix_user);
59 int smb_delete_user_group(const char *unix_group, const char *unix_user);
60 NTSTATUS pdb_default_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
61 struct dom_sid sid);
62 NTSTATUS pdb_default_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
63 gid_t gid);
64 NTSTATUS pdb_default_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
65 const char *name);
66 NTSTATUS pdb_default_add_group_mapping_entry(struct pdb_methods *methods,
67 GROUP_MAP *map);
68 NTSTATUS pdb_default_update_group_mapping_entry(struct pdb_methods *methods,
69 GROUP_MAP *map);
70 NTSTATUS pdb_default_delete_group_mapping_entry(struct pdb_methods *methods,
71 struct dom_sid sid);
72 NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods,
73 const struct dom_sid *sid,
74 enum lsa_SidType sid_name_use,
75 GROUP_MAP ***pp_rmap,
76 size_t *p_num_entries,
77 bool unix_only);
78 NTSTATUS pdb_default_create_alias(struct pdb_methods *methods,
79 const char *name, uint32_t *rid);
80 NTSTATUS pdb_default_delete_alias(struct pdb_methods *methods,
81 const struct dom_sid *sid);
82 struct acct_info;
83 NTSTATUS pdb_default_get_aliasinfo(struct pdb_methods *methods,
84 const struct dom_sid *sid,
85 struct acct_info *info);
86 NTSTATUS pdb_default_set_aliasinfo(struct pdb_methods *methods,
87 const struct dom_sid *sid,
88 struct acct_info *info);
89 NTSTATUS pdb_default_add_aliasmem(struct pdb_methods *methods,
90 const struct dom_sid *alias, const struct dom_sid *member);
91 NTSTATUS pdb_default_del_aliasmem(struct pdb_methods *methods,
92 const struct dom_sid *alias, const struct dom_sid *member);
93 NTSTATUS pdb_default_enum_aliasmem(struct pdb_methods *methods,
94 const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
95 struct dom_sid **pp_members,
96 size_t *p_num_members);
97 NTSTATUS pdb_default_alias_memberships(struct pdb_methods *methods,
98 TALLOC_CTX *mem_ctx,
99 const struct dom_sid *domain_sid,
100 const struct dom_sid *members,
101 size_t num_members,
102 uint32_t **pp_alias_rids,
103 size_t *p_num_alias_rids);
104 NTSTATUS pdb_nop_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
105 struct dom_sid sid);
106 NTSTATUS pdb_nop_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
107 gid_t gid);
108 NTSTATUS pdb_nop_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
109 const char *name);
110 NTSTATUS pdb_nop_add_group_mapping_entry(struct pdb_methods *methods,
111 GROUP_MAP *map);
112 NTSTATUS pdb_nop_update_group_mapping_entry(struct pdb_methods *methods,
113 GROUP_MAP *map);
114 NTSTATUS pdb_nop_delete_group_mapping_entry(struct pdb_methods *methods,
115 struct dom_sid sid);
116 NTSTATUS pdb_nop_enum_group_mapping(struct pdb_methods *methods,
117 enum lsa_SidType sid_name_use,
118 GROUP_MAP **rmap, size_t *num_entries,
119 bool unix_only);
120 NTSTATUS pdb_create_builtin_alias(uint32_t rid);
123 /* passdb headers */
125 /**********************************************************************
126 * Masks for mappings between unix uid and gid types and
127 * NT RIDS.
128 **********************************************************************/
130 /* Take the bottom bit. */
131 #define RID_TYPE_MASK 1
132 #define RID_MULTIPLIER 2
134 /* The two common types. */
135 #define USER_RID_TYPE 0
136 #define GROUP_RID_TYPE 1
139 * Flags for local user manipulation.
142 #define LOCAL_ADD_USER 0x1
143 #define LOCAL_DELETE_USER 0x2
144 #define LOCAL_DISABLE_USER 0x4
145 #define LOCAL_ENABLE_USER 0x8
146 #define LOCAL_TRUST_ACCOUNT 0x10
147 #define LOCAL_SET_NO_PASSWORD 0x20
148 #define LOCAL_SET_PASSWORD 0x40
149 #define LOCAL_SET_LDAP_ADMIN_PW 0x80
150 #define LOCAL_INTERDOM_ACCOUNT 0x100
151 #define LOCAL_AM_ROOT 0x200 /* Act as root */
154 * Size of new password account encoding string. This is enough space to
155 * hold 11 ACB characters, plus the surrounding [] and a terminating null.
156 * Do not change unless you are adding new ACB bits!
159 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
161 /* Password history contants. */
162 #define PW_HISTORY_SALT_LEN 16
163 #define SALTED_MD5_HASH_LEN 16
164 #define PW_HISTORY_ENTRY_LEN (PW_HISTORY_SALT_LEN+SALTED_MD5_HASH_LEN)
165 #define MAX_PW_HISTORY_LEN 24
168 * bit flags representing initialized fields in struct samu
170 enum pdb_elements {
171 PDB_UNINIT,
172 PDB_SMBHOME,
173 PDB_PROFILE,
174 PDB_DRIVE,
175 PDB_LOGONSCRIPT,
176 PDB_LOGONTIME,
177 PDB_LOGOFFTIME,
178 PDB_KICKOFFTIME,
179 PDB_BAD_PASSWORD_TIME,
180 PDB_CANCHANGETIME,
181 PDB_MUSTCHANGETIME,
182 PDB_PLAINTEXT_PW,
183 PDB_USERNAME,
184 PDB_FULLNAME,
185 PDB_DOMAIN,
186 PDB_NTUSERNAME,
187 PDB_HOURSLEN,
188 PDB_LOGONDIVS,
189 PDB_USERSID,
190 PDB_GROUPSID,
191 PDB_ACCTCTRL,
192 PDB_PASSLASTSET,
193 PDB_ACCTDESC,
194 PDB_WORKSTATIONS,
195 PDB_COMMENT,
196 PDB_MUNGEDDIAL,
197 PDB_HOURS,
198 PDB_FIELDS_PRESENT,
199 PDB_BAD_PASSWORD_COUNT,
200 PDB_LOGON_COUNT,
201 PDB_COUNTRY_CODE,
202 PDB_CODE_PAGE,
203 PDB_UNKNOWN6,
204 PDB_LMPASSWD,
205 PDB_NTPASSWD,
206 PDB_PWHISTORY,
207 PDB_BACKEND_PRIVATE_DATA,
209 /* this must be the last element */
210 PDB_COUNT
213 enum pdb_group_elements {
214 PDB_GROUP_NAME,
215 PDB_GROUP_SID,
216 PDB_GROUP_SID_NAME_USE,
217 PDB_GROUP_MEMBERS,
219 /* this must be the last element */
220 PDB_GROUP_COUNT
224 enum pdb_value_state {
225 PDB_DEFAULT=0,
226 PDB_SET,
227 PDB_CHANGED
230 #define IS_SAM_SET(x, flag) (pdb_get_init_flags(x, flag) == PDB_SET)
231 #define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
232 #define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
234 /* cache for bad password lockout data, to be used on replicated SAMs */
235 struct login_cache {
236 time_t entry_timestamp;
237 uint32_t acct_ctrl;
238 uint16_t bad_password_count;
239 time_t bad_password_time;
242 #define SAMU_BUFFER_V0 0
243 #define SAMU_BUFFER_V1 1
244 #define SAMU_BUFFER_V2 2
245 #define SAMU_BUFFER_V3 3
246 /* nothing changed from V3 to V4 */
247 #define SAMU_BUFFER_V4 4
248 #define SAMU_BUFFER_LATEST SAMU_BUFFER_V4
250 #define MAX_HOURS_LEN 32
252 struct samu {
253 struct pdb_methods *methods;
255 /* initialization flags */
256 struct bitmap *change_flags;
257 struct bitmap *set_flags;
259 time_t logon_time; /* logon time */
260 time_t logoff_time; /* logoff time */
261 time_t kickoff_time; /* kickoff time */
262 time_t bad_password_time; /* last bad password entered */
263 time_t pass_last_set_time; /* password last set time */
264 time_t pass_can_change_time; /* password can change time */
265 time_t pass_must_change_time; /* password must change time */
267 const char *username; /* UNIX username string */
268 const char *domain; /* Windows Domain name */
269 const char *nt_username; /* Windows username string */
270 const char *full_name; /* user's full name string */
271 const char *home_dir; /* home directory string */
272 const char *dir_drive; /* home directory drive string */
273 const char *logon_script; /* logon script string */
274 const char *profile_path; /* profile path string */
275 const char *acct_desc; /* user description string */
276 const char *workstations; /* login from workstations string */
277 const char *comment;
278 const char *munged_dial; /* munged path name and dial-back tel number */
280 struct dom_sid user_sid;
281 struct dom_sid *group_sid;
283 DATA_BLOB lm_pw; /* .data is Null if no password */
284 DATA_BLOB nt_pw; /* .data is Null if no password */
285 DATA_BLOB nt_pw_his; /* nt hashed password history .data is Null if not available */
286 char* plaintext_pw; /* is Null if not available */
288 uint32_t acct_ctrl; /* account info (ACB_xxxx bit-mask) */
289 uint32_t fields_present; /* 0x00ff ffff */
291 uint16_t logon_divs; /* 168 - number of hours in a week */
292 uint32_t hours_len; /* normally 21 bytes */
293 uint8_t hours[MAX_HOURS_LEN];
295 /* Was unknown_5. */
296 uint16_t bad_password_count;
297 uint16_t logon_count;
299 uint16_t country_code;
300 uint16_t code_page;
302 uint32_t unknown_6; /* 0x0000 04ec */
304 /* a tag for who added the private methods */
306 const struct pdb_methods *backend_private_methods;
307 void *backend_private_data;
308 void (*backend_private_data_free_fn)(void **);
310 /* maintain a copy of the user's struct passwd */
312 struct passwd *unix_pw;
315 struct acct_info {
316 char *acct_name; /* account name */
317 char *acct_desc; /* account name */
318 uint32_t rid; /* domain-relative RID */
321 struct samr_displayentry {
322 uint32_t idx;
323 uint32_t rid;
324 uint32_t acct_flags;
325 const char *account_name;
326 const char *fullname;
327 const char *description;
330 enum pdb_search_type {
331 PDB_USER_SEARCH,
332 PDB_GROUP_SEARCH,
333 PDB_ALIAS_SEARCH
336 struct pdb_search {
337 enum pdb_search_type type;
338 struct samr_displayentry *cache;
339 uint32_t num_entries;
340 ssize_t cache_size;
341 bool search_ended;
342 void *private_data;
343 bool (*next_entry)(struct pdb_search *search,
344 struct samr_displayentry *entry);
345 void (*search_end)(struct pdb_search *search);
348 struct pdb_domain_info {
349 char *name;
350 char *dns_domain;
351 char *dns_forest;
352 struct dom_sid sid;
353 struct GUID guid;
356 struct pdb_trusted_domain {
357 char *domain_name;
358 char *netbios_name;
359 struct dom_sid security_identifier;
360 DATA_BLOB trust_auth_incoming;
361 DATA_BLOB trust_auth_outgoing;
362 uint32_t trust_direction;
363 uint32_t trust_type;
364 uint32_t trust_attributes;
365 uint32_t *trust_posix_offset;
366 uint32_t *supported_enc_type;
367 DATA_BLOB trust_forest_trust_info;
371 * trusted domain entry/entries returned by secrets_get_trusted_domains
372 * (used in _lsa_enum_trust_dom call)
374 struct trustdom_info {
375 char *name;
376 struct dom_sid sid;
380 * Types of account policy.
382 enum pdb_policy_type {
383 PDB_POLICY_MIN_PASSWORD_LEN = 1,
384 PDB_POLICY_PASSWORD_HISTORY = 2,
385 PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS = 3,
386 PDB_POLICY_MAX_PASSWORD_AGE = 4,
387 PDB_POLICY_MIN_PASSWORD_AGE = 5,
388 PDB_POLICY_LOCK_ACCOUNT_DURATION = 6,
389 PDB_POLICY_RESET_COUNT_TIME = 7,
390 PDB_POLICY_BAD_ATTEMPT_LOCKOUT = 8,
391 PDB_POLICY_TIME_TO_LOGOUT = 9,
392 PDB_POLICY_REFUSE_MACHINE_PW_CHANGE = 10
395 #define PDB_CAP_STORE_RIDS 0x0001
396 #define PDB_CAP_ADS 0x0002
397 #define PDB_CAP_TRUSTED_DOMAINS_EX 0x0004
399 /*****************************************************************
400 Functions to be implemented by the new (v2) passdb API
401 ****************************************************************/
404 * This next constant specifies the version number of the PASSDB interface
405 * this SAMBA will load. Increment this if *ANY* changes are made to the interface.
406 * Changed interface to fix int -> size_t problems. JRA.
407 * There's no point in allocating arrays in
408 * samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in
409 * the pdb module. Remove the latter, this might happen more often. VL.
410 * changed to version 14 to move lookup_rids and lookup_names to return
411 * enum lsa_SidType rather than uint32_t.
412 * Changed to 16 for access to the trusted domain passwords (obnox).
413 * Changed to 17, the sampwent interface is gone.
414 * Changed to 18, pdb_rid_algorithm -> pdb_capabilities
415 * Changed to 19, removed uid_to_rid
416 * Changed to 20, pdb_secret calls
419 #define PASSDB_INTERFACE_VERSION 20
421 struct pdb_methods
423 const char *name; /* What name got this module */
425 struct pdb_domain_info *(*get_domain_info)(struct pdb_methods *,
426 TALLOC_CTX *mem_ctx);
428 NTSTATUS (*getsampwnam)(struct pdb_methods *, struct samu *sam_acct, const char *username);
430 NTSTATUS (*getsampwsid)(struct pdb_methods *, struct samu *sam_acct, const struct dom_sid *sid);
432 NTSTATUS (*create_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
433 const char *name, uint32_t acct_flags,
434 uint32_t *rid);
436 NTSTATUS (*delete_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
437 struct samu *sam_acct);
439 NTSTATUS (*add_sam_account)(struct pdb_methods *, struct samu *sampass);
441 NTSTATUS (*update_sam_account)(struct pdb_methods *, struct samu *sampass);
443 NTSTATUS (*delete_sam_account)(struct pdb_methods *, struct samu *username);
445 NTSTATUS (*rename_sam_account)(struct pdb_methods *, struct samu *oldname, const char *newname);
447 NTSTATUS (*update_login_attempts)(struct pdb_methods *methods, struct samu *sam_acct, bool success);
449 NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, struct dom_sid sid);
451 NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid);
453 NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name);
455 NTSTATUS (*create_dom_group)(struct pdb_methods *methods,
456 TALLOC_CTX *mem_ctx, const char *name,
457 uint32_t *rid);
459 NTSTATUS (*delete_dom_group)(struct pdb_methods *methods,
460 TALLOC_CTX *mem_ctx, uint32_t rid);
462 NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods,
463 GROUP_MAP *map);
465 NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods,
466 GROUP_MAP *map);
468 NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods,
469 struct dom_sid sid);
471 NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods,
472 const struct dom_sid *sid, enum lsa_SidType sid_name_use,
473 GROUP_MAP ***pp_rmap, size_t *p_num_entries,
474 bool unix_only);
476 NTSTATUS (*enum_group_members)(struct pdb_methods *methods,
477 TALLOC_CTX *mem_ctx,
478 const struct dom_sid *group,
479 uint32_t **pp_member_rids,
480 size_t *p_num_members);
482 NTSTATUS (*enum_group_memberships)(struct pdb_methods *methods,
483 TALLOC_CTX *mem_ctx,
484 struct samu *user,
485 struct dom_sid **pp_sids, gid_t **pp_gids,
486 uint32_t *p_num_groups);
488 NTSTATUS (*set_unix_primary_group)(struct pdb_methods *methods,
489 TALLOC_CTX *mem_ctx,
490 struct samu *user);
492 NTSTATUS (*add_groupmem)(struct pdb_methods *methods,
493 TALLOC_CTX *mem_ctx,
494 uint32_t group_rid, uint32_t member_rid);
496 NTSTATUS (*del_groupmem)(struct pdb_methods *methods,
497 TALLOC_CTX *mem_ctx,
498 uint32_t group_rid, uint32_t member_rid);
500 NTSTATUS (*create_alias)(struct pdb_methods *methods,
501 const char *name, uint32_t *rid);
503 NTSTATUS (*delete_alias)(struct pdb_methods *methods,
504 const struct dom_sid *sid);
506 NTSTATUS (*get_aliasinfo)(struct pdb_methods *methods,
507 const struct dom_sid *sid,
508 struct acct_info *info);
510 NTSTATUS (*set_aliasinfo)(struct pdb_methods *methods,
511 const struct dom_sid *sid,
512 struct acct_info *info);
514 NTSTATUS (*add_aliasmem)(struct pdb_methods *methods,
515 const struct dom_sid *alias, const struct dom_sid *member);
516 NTSTATUS (*del_aliasmem)(struct pdb_methods *methods,
517 const struct dom_sid *alias, const struct dom_sid *member);
518 NTSTATUS (*enum_aliasmem)(struct pdb_methods *methods,
519 const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
520 struct dom_sid **members, size_t *p_num_members);
521 NTSTATUS (*enum_alias_memberships)(struct pdb_methods *methods,
522 TALLOC_CTX *mem_ctx,
523 const struct dom_sid *domain_sid,
524 const struct dom_sid *members,
525 size_t num_members,
526 uint32_t **pp_alias_rids,
527 size_t *p_num_alias_rids);
529 NTSTATUS (*lookup_rids)(struct pdb_methods *methods,
530 const struct dom_sid *domain_sid,
531 int num_rids,
532 uint32_t *rids,
533 const char **pp_names,
534 enum lsa_SidType *attrs);
536 NTSTATUS (*lookup_names)(struct pdb_methods *methods,
537 const struct dom_sid *domain_sid,
538 int num_names,
539 const char **pp_names,
540 uint32_t *rids,
541 enum lsa_SidType *attrs);
543 NTSTATUS (*get_account_policy)(struct pdb_methods *methods,
544 enum pdb_policy_type type,
545 uint32_t *value);
547 NTSTATUS (*set_account_policy)(struct pdb_methods *methods,
548 enum pdb_policy_type type,
549 uint32_t value);
551 NTSTATUS (*get_seq_num)(struct pdb_methods *methods, time_t *seq_num);
553 bool (*search_users)(struct pdb_methods *methods,
554 struct pdb_search *search,
555 uint32_t acct_flags);
556 bool (*search_groups)(struct pdb_methods *methods,
557 struct pdb_search *search);
558 bool (*search_aliases)(struct pdb_methods *methods,
559 struct pdb_search *search,
560 const struct dom_sid *sid);
562 bool (*uid_to_sid)(struct pdb_methods *methods, uid_t uid,
563 struct dom_sid *sid);
564 bool (*gid_to_sid)(struct pdb_methods *methods, gid_t gid,
565 struct dom_sid *sid);
566 bool (*sid_to_id)(struct pdb_methods *methods, const struct dom_sid *sid,
567 uid_t *uid, gid_t *gid, enum lsa_SidType *type);
569 uint32_t (*capabilities)(struct pdb_methods *methods);
570 bool (*new_rid)(struct pdb_methods *methods, uint32_t *rid);
573 bool (*get_trusteddom_pw)(struct pdb_methods *methods,
574 const char *domain, char** pwd,
575 struct dom_sid *sid, time_t *pass_last_set_time);
576 bool (*set_trusteddom_pw)(struct pdb_methods *methods,
577 const char* domain, const char* pwd,
578 const struct dom_sid *sid);
579 bool (*del_trusteddom_pw)(struct pdb_methods *methods,
580 const char *domain);
581 NTSTATUS (*enum_trusteddoms)(struct pdb_methods *methods,
582 TALLOC_CTX *mem_ctx, uint32_t *num_domains,
583 struct trustdom_info ***domains);
585 NTSTATUS (*get_trusted_domain)(struct pdb_methods *methods,
586 TALLOC_CTX *mem_ctx,
587 const char *domain,
588 struct pdb_trusted_domain **td);
589 NTSTATUS (*get_trusted_domain_by_sid)(struct pdb_methods *methods,
590 TALLOC_CTX *mem_ctx,
591 struct dom_sid *sid,
592 struct pdb_trusted_domain **td);
593 NTSTATUS (*set_trusted_domain)(struct pdb_methods *methods,
594 const char* domain,
595 const struct pdb_trusted_domain *td);
596 NTSTATUS (*del_trusted_domain)(struct pdb_methods *methods,
597 const char *domain);
598 NTSTATUS (*enum_trusted_domains)(struct pdb_methods *methods,
599 TALLOC_CTX *mem_ctx,
600 uint32_t *num_domains,
601 struct pdb_trusted_domain ***domains);
603 NTSTATUS (*get_secret)(struct pdb_methods *methods,
604 TALLOC_CTX *mem_ctx,
605 const char *secret_name,
606 DATA_BLOB *secret_current,
607 NTTIME *secret_current_lastchange,
608 DATA_BLOB *secret_old,
609 NTTIME *secret_old_lastchange,
610 struct security_descriptor **sd);
611 NTSTATUS (*set_secret)(struct pdb_methods *methods,
612 const char *secret_name,
613 DATA_BLOB *secret_current,
614 DATA_BLOB *secret_old,
615 struct security_descriptor *sd);
616 NTSTATUS (*delete_secret)(struct pdb_methods *methods,
617 const char *secret_name);
619 void *private_data; /* Private data of some kind */
621 void (*free_private_data)(void **);
624 typedef NTSTATUS (*pdb_init_function)(struct pdb_methods **, const char *);
626 struct pdb_init_function_entry {
627 const char *name;
629 /* Function to create a member of the pdb_methods list */
630 pdb_init_function init;
632 struct pdb_init_function_entry *prev, *next;
635 /* The following definitions come from passdb/account_pol.c */
637 void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int *num_names);
638 const char *decode_account_policy_name(enum pdb_policy_type type);
639 const char *get_account_policy_attr(enum pdb_policy_type type);
640 const char *account_policy_get_desc(enum pdb_policy_type type);
641 enum pdb_policy_type account_policy_name_to_typenum(const char *name);
642 bool account_policy_get_default(enum pdb_policy_type type, uint32_t *val);
643 bool init_account_policy(void);
644 bool account_policy_get(enum pdb_policy_type type, uint32_t *value);
645 bool account_policy_set(enum pdb_policy_type type, uint32_t value);
646 bool cache_account_policy_set(enum pdb_policy_type type, uint32_t value);
647 bool cache_account_policy_get(enum pdb_policy_type type, uint32_t *value);
648 struct db_context *get_account_pol_db( void );
650 /* The following definitions come from passdb/login_cache.c */
652 bool login_cache_init(void);
653 bool login_cache_shutdown(void);
654 bool login_cache_read(struct samu *sampass, struct login_cache *entry);
655 bool login_cache_write(const struct samu *sampass,
656 const struct login_cache *entry);
657 bool login_cache_delentry(const struct samu *sampass);
659 /* The following definitions come from passdb/passdb.c */
661 const char *my_sam_name(void);
662 struct samu *samu_new( TALLOC_CTX *ctx );
663 NTSTATUS samu_set_unix(struct samu *user, const struct passwd *pwd);
664 NTSTATUS samu_alloc_rid_unix(struct pdb_methods *methods,
665 struct samu *user, const struct passwd *pwd);
666 char *pdb_encode_acct_ctrl(uint32_t acct_ctrl, size_t length);
667 uint32_t pdb_decode_acct_ctrl(const char *p);
668 void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32_t acct_ctrl);
669 bool pdb_gethexpwd(const char *p, unsigned char *pwd);
670 void pdb_sethexhours(char *p, const unsigned char *hours);
671 bool pdb_gethexhours(const char *p, unsigned char *hours);
672 int algorithmic_rid_base(void);
673 uid_t algorithmic_pdb_user_rid_to_uid(uint32_t user_rid);
674 uid_t max_algorithmic_uid(void);
675 uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid);
676 gid_t pdb_group_rid_to_gid(uint32_t group_rid);
677 gid_t max_algorithmic_gid(void);
678 uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid);
679 bool algorithmic_pdb_rid_is_user(uint32_t rid);
680 bool lookup_global_sam_name(const char *name, int flags, uint32_t *rid,
681 enum lsa_SidType *type);
682 NTSTATUS local_password_change(const char *user_name,
683 int local_flags,
684 const char *new_passwd,
685 char **pp_err_str,
686 char **pp_msg_str);
687 bool init_samu_from_buffer(struct samu *sampass, uint32_t level,
688 uint8_t *buf, uint32_t buflen);
689 uint32_t init_buffer_from_samu (uint8_t **buf, struct samu *sampass, bool size_only);
690 bool pdb_copy_sam_account(struct samu *dst, struct samu *src );
691 bool pdb_update_bad_password_count(struct samu *sampass, bool *updated);
692 bool pdb_update_autolock_flag(struct samu *sampass, bool *updated);
693 bool pdb_increment_bad_password_count(struct samu *sampass);
694 bool is_dc_trusted_domain_situation(const char *domain_name);
695 bool get_trust_pw_clear(const char *domain, char **ret_pwd,
696 const char **account_name,
697 enum netr_SchannelType *channel);
698 bool get_trust_pw_hash(const char *domain, uint8_t ret_pwd[16],
699 const char **account_name,
700 enum netr_SchannelType *channel);
702 /* The following definitions come from passdb/pdb_compat.c */
704 uint32_t pdb_get_user_rid (const struct samu *sampass);
705 uint32_t pdb_get_group_rid (struct samu *sampass);
706 bool pdb_set_user_sid_from_rid (struct samu *sampass, uint32_t rid, enum pdb_value_state flag);
707 bool pdb_set_group_sid_from_rid (struct samu *sampass, uint32_t grid, enum pdb_value_state flag);
709 /* The following definitions come from passdb/pdb_get_set.c */
711 uint32_t pdb_get_acct_ctrl(const struct samu *sampass);
712 time_t pdb_get_logon_time(const struct samu *sampass);
713 time_t pdb_get_logoff_time(const struct samu *sampass);
714 time_t pdb_get_kickoff_time(const struct samu *sampass);
715 time_t pdb_get_bad_password_time(const struct samu *sampass);
716 time_t pdb_get_pass_last_set_time(const struct samu *sampass);
717 time_t pdb_get_pass_can_change_time(const struct samu *sampass);
718 time_t pdb_get_pass_can_change_time_noncalc(const struct samu *sampass);
719 time_t pdb_get_pass_must_change_time(const struct samu *sampass);
720 bool pdb_get_pass_can_change(const struct samu *sampass);
721 uint16_t pdb_get_logon_divs(const struct samu *sampass);
722 uint32_t pdb_get_hours_len(const struct samu *sampass);
723 const uint8_t *pdb_get_hours(const struct samu *sampass);
724 const uint8_t *pdb_get_nt_passwd(const struct samu *sampass);
725 const uint8_t *pdb_get_lanman_passwd(const struct samu *sampass);
726 const uint8_t *pdb_get_pw_history(const struct samu *sampass, uint32_t *current_hist_len);
727 const char *pdb_get_plaintext_passwd(const struct samu *sampass);
728 const struct dom_sid *pdb_get_user_sid(const struct samu *sampass);
729 const struct dom_sid *pdb_get_group_sid(struct samu *sampass);
730 enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element);
731 const char *pdb_get_username(const struct samu *sampass);
732 const char *pdb_get_domain(const struct samu *sampass);
733 const char *pdb_get_nt_username(const struct samu *sampass);
734 const char *pdb_get_fullname(const struct samu *sampass);
735 const char *pdb_get_homedir(const struct samu *sampass);
736 const char *pdb_get_dir_drive(const struct samu *sampass);
737 const char *pdb_get_logon_script(const struct samu *sampass);
738 const char *pdb_get_profile_path(const struct samu *sampass);
739 const char *pdb_get_acct_desc(const struct samu *sampass);
740 const char *pdb_get_workstations(const struct samu *sampass);
741 const char *pdb_get_comment(const struct samu *sampass);
742 const char *pdb_get_munged_dial(const struct samu *sampass);
743 uint16_t pdb_get_bad_password_count(const struct samu *sampass);
744 uint16_t pdb_get_logon_count(const struct samu *sampass);
745 uint16_t pdb_get_country_code(const struct samu *sampass);
746 uint16_t pdb_get_code_page(const struct samu *sampass);
747 uint32_t pdb_get_unknown_6(const struct samu *sampass);
748 void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_methods *my_methods);
749 bool pdb_set_acct_ctrl(struct samu *sampass, uint32_t acct_ctrl, enum pdb_value_state flag);
750 bool pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
751 bool pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
752 bool pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
753 bool pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
754 bool pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
755 bool pdb_set_pass_must_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
756 bool pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
757 bool pdb_set_hours_len(struct samu *sampass, uint32_t len, enum pdb_value_state flag);
758 bool pdb_set_logon_divs(struct samu *sampass, uint16_t hours, enum pdb_value_state flag);
759 bool pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag);
760 bool pdb_set_user_sid(struct samu *sampass, const struct dom_sid *u_sid, enum pdb_value_state flag);
761 bool pdb_set_user_sid_from_string(struct samu *sampass, const char *u_sid, enum pdb_value_state flag);
762 bool pdb_set_group_sid(struct samu *sampass, const struct dom_sid *g_sid, enum pdb_value_state flag);
763 bool pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag);
764 bool pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag);
765 bool pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag);
766 bool pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag);
767 bool pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag);
768 bool pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag);
769 bool pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag);
770 bool pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag);
771 bool pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag);
772 bool pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag);
773 bool pdb_set_comment(struct samu *sampass, const char *comment, enum pdb_value_state flag);
774 bool pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag);
775 bool pdb_set_nt_passwd(struct samu *sampass, const uint8_t pwd[NT_HASH_LEN], enum pdb_value_state flag);
776 bool pdb_set_lanman_passwd(struct samu *sampass, const uint8_t pwd[LM_HASH_LEN], enum pdb_value_state flag);
777 bool pdb_set_pw_history(struct samu *sampass, const uint8_t *pwd, uint32_t historyLen, enum pdb_value_state flag);
778 bool pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag);
779 bool pdb_set_bad_password_count(struct samu *sampass, uint16_t bad_password_count, enum pdb_value_state flag);
780 bool pdb_set_logon_count(struct samu *sampass, uint16_t logon_count, enum pdb_value_state flag);
781 bool pdb_set_country_code(struct samu *sampass, uint16_t country_code,
782 enum pdb_value_state flag);
783 bool pdb_set_code_page(struct samu *sampass, uint16_t code_page,
784 enum pdb_value_state flag);
785 bool pdb_set_unknown_6(struct samu *sampass, uint32_t unkn, enum pdb_value_state flag);
786 bool pdb_set_hours(struct samu *sampass, const uint8_t *hours, int hours_len,
787 enum pdb_value_state flag);
788 bool pdb_set_backend_private_data(struct samu *sampass, void *private_data,
789 void (*free_fn)(void **),
790 const struct pdb_methods *my_methods,
791 enum pdb_value_state flag);
792 bool pdb_set_pass_can_change(struct samu *sampass, bool canchange);
793 bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext);
794 uint32_t pdb_build_fields_present(struct samu *sampass);
795 bool pdb_element_is_changed(const struct samu *sampass,
796 enum pdb_elements element);
797 bool pdb_element_is_set_or_changed(const struct samu *sampass,
798 enum pdb_elements element);
800 /* The following definitions come from passdb/pdb_interface.c */
802 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) ;
803 struct pdb_init_function_entry *pdb_find_backend_entry(const char *name);
804 const struct pdb_init_function_entry *pdb_get_backends(void);
805 struct tevent_context *pdb_get_tevent_context(void);
806 NTSTATUS make_pdb_method_name(struct pdb_methods **methods, const char *selected);
807 struct pdb_domain_info *pdb_get_domain_info(TALLOC_CTX *mem_ctx);
808 bool pdb_getsampwnam(struct samu *sam_acct, const char *username) ;
809 bool pdb_getsampwsid(struct samu *sam_acct, const struct dom_sid *sid) ;
810 NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32_t flags,
811 uint32_t *rid);
812 NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct);
813 NTSTATUS pdb_add_sam_account(struct samu *sam_acct) ;
814 NTSTATUS pdb_update_sam_account(struct samu *sam_acct) ;
815 NTSTATUS pdb_delete_sam_account(struct samu *sam_acct) ;
816 NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname);
817 NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, bool success);
818 bool pdb_getgrsid(GROUP_MAP *map, struct dom_sid sid);
819 bool pdb_getgrgid(GROUP_MAP *map, gid_t gid);
820 bool pdb_getgrnam(GROUP_MAP *map, const char *name);
821 NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name,
822 uint32_t *rid);
823 NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32_t rid);
824 NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map);
825 NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map);
826 NTSTATUS pdb_delete_group_mapping_entry(struct dom_sid sid);
827 bool pdb_enum_group_mapping(const struct dom_sid *sid,
828 enum lsa_SidType sid_name_use,
829 GROUP_MAP ***pp_rmap,
830 size_t *p_num_entries,
831 bool unix_only);
832 NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
833 const struct dom_sid *sid,
834 uint32_t **pp_member_rids,
835 size_t *p_num_members);
836 NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user,
837 struct dom_sid **pp_sids, gid_t **pp_gids,
838 uint32_t *p_num_groups);
839 NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user);
840 NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
841 uint32_t member_rid);
842 NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
843 uint32_t member_rid);
844 NTSTATUS pdb_create_alias(const char *name, uint32_t *rid);
845 NTSTATUS pdb_delete_alias(const struct dom_sid *sid);
846 NTSTATUS pdb_get_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
847 NTSTATUS pdb_set_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
848 NTSTATUS pdb_add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
849 NTSTATUS pdb_del_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
850 NTSTATUS pdb_enum_aliasmem(const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
851 struct dom_sid **pp_members, size_t *p_num_members);
852 NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
853 const struct dom_sid *domain_sid,
854 const struct dom_sid *members, size_t num_members,
855 uint32_t **pp_alias_rids,
856 size_t *p_num_alias_rids);
857 NTSTATUS pdb_lookup_rids(const struct dom_sid *domain_sid,
858 int num_rids,
859 uint32_t *rids,
860 const char **names,
861 enum lsa_SidType *attrs);
862 NTSTATUS pdb_lookup_names(const struct dom_sid *domain_sid,
863 int num_names,
864 const char **names,
865 uint32_t *rids,
866 enum lsa_SidType *attrs);
867 bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value);
868 bool pdb_set_account_policy(enum pdb_policy_type type, uint32_t value);
869 bool pdb_get_seq_num(time_t *seq_num);
870 bool pdb_uid_to_sid(uid_t uid, struct dom_sid *sid);
871 bool pdb_gid_to_sid(gid_t gid, struct dom_sid *sid);
872 bool pdb_sid_to_id(const struct dom_sid *sid, uid_t *uid, gid_t *gid,
873 enum lsa_SidType *type);
874 uint32_t pdb_capabilities(void);
875 bool pdb_new_rid(uint32_t *rid);
876 bool initialize_password_db(bool reload, struct tevent_context *tevent_ctx);
877 struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx,
878 enum pdb_search_type type);
879 struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32_t acct_flags);
880 struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx);
881 struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
882 uint32_t pdb_search_entries(struct pdb_search *search,
883 uint32_t start_idx, uint32_t max_entries,
884 struct samr_displayentry **result);
885 bool pdb_get_trusteddom_pw(const char *domain, char** pwd, struct dom_sid *sid,
886 time_t *pass_last_set_time);
887 bool pdb_set_trusteddom_pw(const char* domain, const char* pwd,
888 const struct dom_sid *sid);
889 bool pdb_del_trusteddom_pw(const char *domain);
890 NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
891 struct trustdom_info ***domains);
892 NTSTATUS pdb_get_trusted_domain(TALLOC_CTX *mem_ctx, const char *domain,
893 struct pdb_trusted_domain **td);
894 NTSTATUS pdb_get_trusted_domain_by_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid,
895 struct pdb_trusted_domain **td);
896 NTSTATUS pdb_set_trusted_domain(const char* domain,
897 const struct pdb_trusted_domain *td);
898 NTSTATUS pdb_del_trusted_domain(const char *domain);
899 NTSTATUS pdb_enum_trusted_domains(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
900 struct pdb_trusted_domain ***domains);
901 NTSTATUS make_pdb_method( struct pdb_methods **methods ) ;
902 NTSTATUS pdb_get_secret(TALLOC_CTX *mem_ctx,
903 const char *secret_name,
904 DATA_BLOB *secret_current,
905 NTTIME *secret_current_lastchange,
906 DATA_BLOB *secret_old,
907 NTTIME *secret_old_lastchange,
908 struct security_descriptor **sd);
909 NTSTATUS pdb_set_secret(const char *secret_name,
910 DATA_BLOB *secret_current,
911 DATA_BLOB *secret_old,
912 struct security_descriptor *sd);
913 NTSTATUS pdb_delete_secret(const char *secret_name);
915 /* The following definitions come from passdb/pdb_util.c */
917 NTSTATUS create_builtin_users(const struct dom_sid *sid);
918 NTSTATUS create_builtin_administrators(const struct dom_sid *sid);
920 #include "passdb/machine_sid.h"
921 #include "passdb/lookup_sid.h"
923 #endif /* _PASSDB_H */