smbd: Factor out unlocking from smbd_do_locking
[Samba.git] / source3 / include / passdb.h
blobf9918085da85247986b22bf82a7d6b62a45f3831
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>
36 struct unixid;
38 /* group mapping headers */
40 #define ENUM_ONLY_MAPPED True
41 #define ENUM_ALL_MAPPED False
43 typedef struct _GROUP_MAP {
44 struct pdb_methods *methods;
45 gid_t gid;
46 struct dom_sid sid;
47 enum lsa_SidType sid_name_use;
48 char *nt_name;
49 char *comment;
50 } GROUP_MAP;
52 struct acct_info {
53 char *acct_name; /* account name */
54 char *acct_desc; /* account name */
55 uint32_t rid; /* domain-relative RID */
58 /* The following definitions come from groupdb/mapping.c */
60 NTSTATUS add_initial_entry(gid_t gid, const char *sid, enum lsa_SidType sid_name_use, const char *nt_name, const char *comment);
61 bool get_domain_group_from_sid(struct dom_sid sid, GROUP_MAP *map);
62 int smb_create_group(const char *unix_group, gid_t *new_gid);
63 int smb_delete_group(const char *unix_group);
64 int smb_set_primary_group(const char *unix_group, const char* unix_user);
65 int smb_add_user_group(const char *unix_group, const char *unix_user);
66 int smb_delete_user_group(const char *unix_group, const char *unix_user);
67 NTSTATUS pdb_default_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
68 struct dom_sid sid);
69 NTSTATUS pdb_default_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
70 gid_t gid);
71 NTSTATUS pdb_default_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
72 const char *name);
73 NTSTATUS pdb_default_add_group_mapping_entry(struct pdb_methods *methods,
74 GROUP_MAP *map);
75 NTSTATUS pdb_default_update_group_mapping_entry(struct pdb_methods *methods,
76 GROUP_MAP *map);
77 NTSTATUS pdb_default_delete_group_mapping_entry(struct pdb_methods *methods,
78 struct dom_sid sid);
79 NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods,
80 const struct dom_sid *sid,
81 enum lsa_SidType sid_name_use,
82 GROUP_MAP ***pp_rmap,
83 size_t *p_num_entries,
84 bool unix_only);
85 NTSTATUS pdb_default_create_alias(struct pdb_methods *methods,
86 const char *name, uint32_t *rid);
87 NTSTATUS pdb_default_delete_alias(struct pdb_methods *methods,
88 const struct dom_sid *sid);
89 NTSTATUS pdb_default_get_aliasinfo(struct pdb_methods *methods,
90 const struct dom_sid *sid,
91 struct acct_info *info);
92 NTSTATUS pdb_default_set_aliasinfo(struct pdb_methods *methods,
93 const struct dom_sid *sid,
94 struct acct_info *info);
95 NTSTATUS pdb_default_add_aliasmem(struct pdb_methods *methods,
96 const struct dom_sid *alias, const struct dom_sid *member);
97 NTSTATUS pdb_default_del_aliasmem(struct pdb_methods *methods,
98 const struct dom_sid *alias, const struct dom_sid *member);
99 NTSTATUS pdb_default_enum_aliasmem(struct pdb_methods *methods,
100 const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
101 struct dom_sid **pp_members,
102 size_t *p_num_members);
103 NTSTATUS pdb_default_alias_memberships(struct pdb_methods *methods,
104 TALLOC_CTX *mem_ctx,
105 const struct dom_sid *domain_sid,
106 const struct dom_sid *members,
107 size_t num_members,
108 uint32_t **pp_alias_rids,
109 size_t *p_num_alias_rids);
110 NTSTATUS pdb_nop_getgrsid(struct pdb_methods *methods, GROUP_MAP *map,
111 struct dom_sid sid);
112 NTSTATUS pdb_nop_getgrgid(struct pdb_methods *methods, GROUP_MAP *map,
113 gid_t gid);
114 NTSTATUS pdb_nop_getgrnam(struct pdb_methods *methods, GROUP_MAP *map,
115 const char *name);
116 NTSTATUS pdb_nop_add_group_mapping_entry(struct pdb_methods *methods,
117 GROUP_MAP *map);
118 NTSTATUS pdb_nop_update_group_mapping_entry(struct pdb_methods *methods,
119 GROUP_MAP *map);
120 NTSTATUS pdb_nop_delete_group_mapping_entry(struct pdb_methods *methods,
121 struct dom_sid sid);
122 NTSTATUS pdb_nop_enum_group_mapping(struct pdb_methods *methods,
123 enum lsa_SidType sid_name_use,
124 GROUP_MAP **rmap, size_t *num_entries,
125 bool unix_only);
126 NTSTATUS pdb_create_builtin_alias(uint32_t rid, gid_t gid);
129 /* passdb headers */
131 /**********************************************************************
132 * Masks for mappings between unix uid and gid types and
133 * NT RIDS.
134 **********************************************************************/
136 /* Take the bottom bit. */
137 #define RID_TYPE_MASK 1
138 #define RID_MULTIPLIER 2
140 /* The two common types. */
141 #define USER_RID_TYPE 0
142 #define GROUP_RID_TYPE 1
145 * Flags for local user manipulation.
148 #define LOCAL_ADD_USER 0x1
149 #define LOCAL_DELETE_USER 0x2
150 #define LOCAL_DISABLE_USER 0x4
151 #define LOCAL_ENABLE_USER 0x8
152 #define LOCAL_TRUST_ACCOUNT 0x10
153 #define LOCAL_SET_NO_PASSWORD 0x20
154 #define LOCAL_SET_PASSWORD 0x40
155 #define LOCAL_SET_LDAP_ADMIN_PW 0x80
156 #define LOCAL_INTERDOM_ACCOUNT 0x100
157 #define LOCAL_AM_ROOT 0x200 /* Act as root */
160 * Size of new password account encoding string. This is enough space to
161 * hold 11 ACB characters, plus the surrounding [] and a terminating null.
162 * Do not change unless you are adding new ACB bits!
165 #define NEW_PW_FORMAT_SPACE_PADDED_LEN 14
167 /* Password history contants. */
168 #define PW_HISTORY_SALT_LEN 16
169 #define SALTED_MD5_HASH_LEN 16
170 #define PW_HISTORY_ENTRY_LEN (PW_HISTORY_SALT_LEN+SALTED_MD5_HASH_LEN)
171 #define MAX_PW_HISTORY_LEN 24
174 * bit flags representing initialized fields in struct samu
176 enum pdb_elements {
177 PDB_UNINIT,
178 PDB_SMBHOME,
179 PDB_PROFILE,
180 PDB_DRIVE,
181 PDB_LOGONSCRIPT,
182 PDB_LOGONTIME,
183 PDB_LOGOFFTIME,
184 PDB_KICKOFFTIME,
185 PDB_BAD_PASSWORD_TIME,
186 PDB_CANCHANGETIME,
187 PDB_PLAINTEXT_PW,
188 PDB_USERNAME,
189 PDB_FULLNAME,
190 PDB_DOMAIN,
191 PDB_NTUSERNAME,
192 PDB_HOURSLEN,
193 PDB_LOGONDIVS,
194 PDB_USERSID,
195 PDB_GROUPSID,
196 PDB_ACCTCTRL,
197 PDB_PASSLASTSET,
198 PDB_ACCTDESC,
199 PDB_WORKSTATIONS,
200 PDB_COMMENT,
201 PDB_MUNGEDDIAL,
202 PDB_HOURS,
203 PDB_FIELDS_PRESENT,
204 PDB_BAD_PASSWORD_COUNT,
205 PDB_LOGON_COUNT,
206 PDB_COUNTRY_CODE,
207 PDB_CODE_PAGE,
208 PDB_UNKNOWN6,
209 PDB_LMPASSWD,
210 PDB_NTPASSWD,
211 PDB_PWHISTORY,
212 PDB_BACKEND_PRIVATE_DATA,
214 /* this must be the last element */
215 PDB_COUNT
218 enum pdb_group_elements {
219 PDB_GROUP_NAME,
220 PDB_GROUP_SID,
221 PDB_GROUP_SID_NAME_USE,
222 PDB_GROUP_MEMBERS,
224 /* this must be the last element */
225 PDB_GROUP_COUNT
229 enum pdb_value_state {
230 PDB_DEFAULT=0,
231 PDB_SET,
232 PDB_CHANGED
235 #define IS_SAM_SET(x, flag) (pdb_get_init_flags(x, flag) == PDB_SET)
236 #define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
237 #define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
239 /* cache for bad password lockout data, to be used on replicated SAMs */
240 struct login_cache {
241 time_t entry_timestamp;
242 uint32_t acct_ctrl;
243 uint16_t bad_password_count;
244 time_t bad_password_time;
247 #define SAMU_BUFFER_V0 0
248 #define SAMU_BUFFER_V1 1
249 #define SAMU_BUFFER_V2 2
250 #define SAMU_BUFFER_V3 3
251 /* nothing changed from V3 to V4 */
252 #define SAMU_BUFFER_V4 4
253 #define SAMU_BUFFER_LATEST SAMU_BUFFER_V4
255 #define MAX_HOURS_LEN 32
257 struct samu {
258 struct pdb_methods *methods;
260 /* initialization flags */
261 struct bitmap *change_flags;
262 struct bitmap *set_flags;
264 time_t logon_time; /* logon time */
265 time_t logoff_time; /* logoff time */
266 time_t kickoff_time; /* kickoff time */
267 time_t bad_password_time; /* last bad password entered */
268 time_t pass_last_set_time; /* password last set time */
269 time_t pass_can_change_time; /* password can change time */
271 const char *username; /* UNIX username string */
272 const char *domain; /* Windows Domain name */
273 const char *nt_username; /* Windows username string */
274 const char *full_name; /* user's full name string */
275 const char *home_dir; /* home directory string */
276 const char *dir_drive; /* home directory drive string */
277 const char *logon_script; /* logon script string */
278 const char *profile_path; /* profile path string */
279 const char *acct_desc; /* user description string */
280 const char *workstations; /* login from workstations string */
281 const char *comment;
282 const char *munged_dial; /* munged path name and dial-back tel number */
284 struct dom_sid user_sid;
285 struct dom_sid *group_sid;
287 DATA_BLOB lm_pw; /* .data is Null if no password */
288 DATA_BLOB nt_pw; /* .data is Null if no password */
289 DATA_BLOB nt_pw_his; /* nt hashed password history .data is Null if not available */
290 char* plaintext_pw; /* is Null if not available */
292 uint32_t acct_ctrl; /* account info (ACB_xxxx bit-mask) */
293 uint32_t fields_present; /* 0x00ff ffff */
295 uint16_t logon_divs; /* 168 - number of hours in a week */
296 uint32_t hours_len; /* normally 21 bytes */
297 uint8_t hours[MAX_HOURS_LEN];
299 /* Was unknown_5. */
300 uint16_t bad_password_count;
301 uint16_t logon_count;
303 uint16_t country_code;
304 uint16_t code_page;
306 uint32_t unknown_6; /* 0x0000 04ec */
308 /* a tag for who added the private methods */
310 const struct pdb_methods *backend_private_methods;
311 void *backend_private_data;
312 void (*backend_private_data_free_fn)(void **);
314 /* maintain a copy of the user's struct passwd */
316 struct passwd *unix_pw;
319 struct samr_displayentry {
320 uint32_t idx;
321 uint32_t rid;
322 uint32_t acct_flags;
323 const char *account_name;
324 const char *fullname;
325 const char *description;
328 enum pdb_search_type {
329 PDB_USER_SEARCH,
330 PDB_GROUP_SEARCH,
331 PDB_ALIAS_SEARCH
334 struct pdb_search {
335 enum pdb_search_type type;
336 struct samr_displayentry *cache;
337 uint32_t num_entries;
338 ssize_t cache_size;
339 bool search_ended;
340 void *private_data;
341 bool (*next_entry)(struct pdb_search *search,
342 struct samr_displayentry *entry);
343 void (*search_end)(struct pdb_search *search);
346 struct pdb_domain_info {
347 char *name;
348 char *dns_domain;
349 char *dns_forest;
350 struct dom_sid sid;
351 struct GUID guid;
354 struct pdb_trusted_domain {
355 char *domain_name;
356 char *netbios_name;
357 struct dom_sid security_identifier;
358 DATA_BLOB trust_auth_incoming;
359 DATA_BLOB trust_auth_outgoing;
360 uint32_t trust_direction;
361 uint32_t trust_type;
362 uint32_t trust_attributes;
363 uint32_t *trust_posix_offset;
364 uint32_t *supported_enc_type;
365 DATA_BLOB trust_forest_trust_info;
369 * trusted domain entry/entries returned by secrets_get_trusted_domains
370 * (used in _lsa_enum_trust_dom call)
372 struct trustdom_info {
373 char *name;
374 struct dom_sid sid;
378 * Types of account policy.
380 enum pdb_policy_type {
381 PDB_POLICY_MIN_PASSWORD_LEN = 1,
382 PDB_POLICY_PASSWORD_HISTORY = 2,
383 PDB_POLICY_USER_MUST_LOGON_TO_CHG_PASS = 3,
384 PDB_POLICY_MAX_PASSWORD_AGE = 4,
385 PDB_POLICY_MIN_PASSWORD_AGE = 5,
386 PDB_POLICY_LOCK_ACCOUNT_DURATION = 6,
387 PDB_POLICY_RESET_COUNT_TIME = 7,
388 PDB_POLICY_BAD_ATTEMPT_LOCKOUT = 8,
389 PDB_POLICY_TIME_TO_LOGOUT = 9,
390 PDB_POLICY_REFUSE_MACHINE_PW_CHANGE = 10
393 #define PDB_CAP_STORE_RIDS 0x0001
394 #define PDB_CAP_ADS 0x0002
395 #define PDB_CAP_TRUSTED_DOMAINS_EX 0x0004
397 /*****************************************************************
398 Functions to be implemented by the new (v2) passdb API
399 ****************************************************************/
402 * This next constant specifies the version number of the PASSDB interface
403 * this SAMBA will load. Increment this if *ANY* changes are made to the interface.
404 * Changed interface to fix int -> size_t problems. JRA.
405 * There's no point in allocating arrays in
406 * samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in
407 * the pdb module. Remove the latter, this might happen more often. VL.
408 * changed to version 14 to move lookup_rids and lookup_names to return
409 * enum lsa_SidType rather than uint32_t.
410 * Changed to 16 for access to the trusted domain passwords (obnox).
411 * Changed to 17, the sampwent interface is gone.
412 * Changed to 18, pdb_rid_algorithm -> pdb_capabilities
413 * Changed to 19, removed uid_to_rid
414 * Changed to 20, pdb_secret calls
415 * Changed to 21, set/enum_upn_suffixes. AB.
416 * Changed to 22, idmap control functions
417 * Changed to 23, new idmap control functions
420 #define PASSDB_INTERFACE_VERSION 23
422 struct pdb_methods
424 const char *name; /* What name got this module */
426 struct pdb_domain_info *(*get_domain_info)(struct pdb_methods *,
427 TALLOC_CTX *mem_ctx);
429 NTSTATUS (*getsampwnam)(struct pdb_methods *, struct samu *sam_acct, const char *username);
431 NTSTATUS (*getsampwsid)(struct pdb_methods *, struct samu *sam_acct, const struct dom_sid *sid);
433 NTSTATUS (*create_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
434 const char *name, uint32_t acct_flags,
435 uint32_t *rid);
437 NTSTATUS (*delete_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
438 struct samu *sam_acct);
440 NTSTATUS (*add_sam_account)(struct pdb_methods *, struct samu *sampass);
442 NTSTATUS (*update_sam_account)(struct pdb_methods *, struct samu *sampass);
444 NTSTATUS (*delete_sam_account)(struct pdb_methods *, struct samu *username);
446 NTSTATUS (*rename_sam_account)(struct pdb_methods *, struct samu *oldname, const char *newname);
448 NTSTATUS (*update_login_attempts)(struct pdb_methods *methods, struct samu *sam_acct, bool success);
450 NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, struct dom_sid sid);
452 NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid);
454 NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name);
456 NTSTATUS (*create_dom_group)(struct pdb_methods *methods,
457 TALLOC_CTX *mem_ctx, const char *name,
458 uint32_t *rid);
460 NTSTATUS (*delete_dom_group)(struct pdb_methods *methods,
461 TALLOC_CTX *mem_ctx, uint32_t rid);
463 NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods,
464 GROUP_MAP *map);
466 NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods,
467 GROUP_MAP *map);
469 NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods,
470 struct dom_sid sid);
472 NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods,
473 const struct dom_sid *sid, enum lsa_SidType sid_name_use,
474 GROUP_MAP ***pp_rmap, size_t *p_num_entries,
475 bool unix_only);
477 NTSTATUS (*enum_group_members)(struct pdb_methods *methods,
478 TALLOC_CTX *mem_ctx,
479 const struct dom_sid *group,
480 uint32_t **pp_member_rids,
481 size_t *p_num_members);
483 NTSTATUS (*enum_group_memberships)(struct pdb_methods *methods,
484 TALLOC_CTX *mem_ctx,
485 struct samu *user,
486 struct dom_sid **pp_sids, gid_t **pp_gids,
487 uint32_t *p_num_groups);
489 NTSTATUS (*set_unix_primary_group)(struct pdb_methods *methods,
490 TALLOC_CTX *mem_ctx,
491 struct samu *user);
493 NTSTATUS (*add_groupmem)(struct pdb_methods *methods,
494 TALLOC_CTX *mem_ctx,
495 uint32_t group_rid, uint32_t member_rid);
497 NTSTATUS (*del_groupmem)(struct pdb_methods *methods,
498 TALLOC_CTX *mem_ctx,
499 uint32_t group_rid, uint32_t member_rid);
501 NTSTATUS (*create_alias)(struct pdb_methods *methods,
502 const char *name, uint32_t *rid);
504 NTSTATUS (*delete_alias)(struct pdb_methods *methods,
505 const struct dom_sid *sid);
507 NTSTATUS (*get_aliasinfo)(struct pdb_methods *methods,
508 const struct dom_sid *sid,
509 struct acct_info *info);
511 NTSTATUS (*set_aliasinfo)(struct pdb_methods *methods,
512 const struct dom_sid *sid,
513 struct acct_info *info);
515 NTSTATUS (*add_aliasmem)(struct pdb_methods *methods,
516 const struct dom_sid *alias, const struct dom_sid *member);
517 NTSTATUS (*del_aliasmem)(struct pdb_methods *methods,
518 const struct dom_sid *alias, const struct dom_sid *member);
519 NTSTATUS (*enum_aliasmem)(struct pdb_methods *methods,
520 const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
521 struct dom_sid **members, size_t *p_num_members);
522 NTSTATUS (*enum_alias_memberships)(struct pdb_methods *methods,
523 TALLOC_CTX *mem_ctx,
524 const struct dom_sid *domain_sid,
525 const struct dom_sid *members,
526 size_t num_members,
527 uint32_t **pp_alias_rids,
528 size_t *p_num_alias_rids);
530 NTSTATUS (*lookup_rids)(struct pdb_methods *methods,
531 const struct dom_sid *domain_sid,
532 int num_rids,
533 uint32_t *rids,
534 const char **pp_names,
535 enum lsa_SidType *attrs);
537 NTSTATUS (*lookup_names)(struct pdb_methods *methods,
538 const struct dom_sid *domain_sid,
539 int num_names,
540 const char **pp_names,
541 uint32_t *rids,
542 enum lsa_SidType *attrs);
544 NTSTATUS (*get_account_policy)(struct pdb_methods *methods,
545 enum pdb_policy_type type,
546 uint32_t *value);
548 NTSTATUS (*set_account_policy)(struct pdb_methods *methods,
549 enum pdb_policy_type type,
550 uint32_t value);
552 NTSTATUS (*get_seq_num)(struct pdb_methods *methods, time_t *seq_num);
554 bool (*search_users)(struct pdb_methods *methods,
555 struct pdb_search *search,
556 uint32_t acct_flags);
557 bool (*search_groups)(struct pdb_methods *methods,
558 struct pdb_search *search);
559 bool (*search_aliases)(struct pdb_methods *methods,
560 struct pdb_search *search,
561 const struct dom_sid *sid);
563 bool (*uid_to_sid)(struct pdb_methods *methods, uid_t uid,
564 struct dom_sid *sid);
565 bool (*gid_to_sid)(struct pdb_methods *methods, gid_t gid,
566 struct dom_sid *sid);
567 bool (*sid_to_id)(struct pdb_methods *methods, const struct dom_sid *sid,
568 struct unixid *id);
570 uint32_t (*capabilities)(struct pdb_methods *methods);
571 bool (*new_rid)(struct pdb_methods *methods, uint32_t *rid);
574 bool (*get_trusteddom_pw)(struct pdb_methods *methods,
575 const char *domain, char** pwd,
576 struct dom_sid *sid, time_t *pass_last_set_time);
577 bool (*set_trusteddom_pw)(struct pdb_methods *methods,
578 const char* domain, const char* pwd,
579 const struct dom_sid *sid);
580 bool (*del_trusteddom_pw)(struct pdb_methods *methods,
581 const char *domain);
582 NTSTATUS (*enum_trusteddoms)(struct pdb_methods *methods,
583 TALLOC_CTX *mem_ctx, uint32_t *num_domains,
584 struct trustdom_info ***domains);
586 NTSTATUS (*get_trusted_domain)(struct pdb_methods *methods,
587 TALLOC_CTX *mem_ctx,
588 const char *domain,
589 struct pdb_trusted_domain **td);
590 NTSTATUS (*get_trusted_domain_by_sid)(struct pdb_methods *methods,
591 TALLOC_CTX *mem_ctx,
592 struct dom_sid *sid,
593 struct pdb_trusted_domain **td);
594 NTSTATUS (*set_trusted_domain)(struct pdb_methods *methods,
595 const char* domain,
596 const struct pdb_trusted_domain *td);
597 NTSTATUS (*del_trusted_domain)(struct pdb_methods *methods,
598 const char *domain);
599 NTSTATUS (*enum_trusted_domains)(struct pdb_methods *methods,
600 TALLOC_CTX *mem_ctx,
601 uint32_t *num_domains,
602 struct pdb_trusted_domain ***domains);
604 NTSTATUS (*get_secret)(struct pdb_methods *methods,
605 TALLOC_CTX *mem_ctx,
606 const char *secret_name,
607 DATA_BLOB *secret_current,
608 NTTIME *secret_current_lastchange,
609 DATA_BLOB *secret_old,
610 NTTIME *secret_old_lastchange,
611 struct security_descriptor **sd);
612 NTSTATUS (*set_secret)(struct pdb_methods *methods,
613 const char *secret_name,
614 DATA_BLOB *secret_current,
615 DATA_BLOB *secret_old,
616 struct security_descriptor *sd);
617 NTSTATUS (*delete_secret)(struct pdb_methods *methods,
618 const char *secret_name);
620 NTSTATUS (*enum_upn_suffixes)(struct pdb_methods *methods,
621 TALLOC_CTX *mem_ctx,
622 uint32_t *num_suffixes,
623 char ***suffixes);
625 NTSTATUS (*set_upn_suffixes)(struct pdb_methods *methods,
626 uint32_t num_suffixes,
627 const char **suffixes);
629 bool (*is_responsible_for_our_sam)(struct pdb_methods *methods);
630 bool (*is_responsible_for_builtin)(struct pdb_methods *methods);
631 bool (*is_responsible_for_wellknown)(struct pdb_methods *methods);
632 bool (*is_responsible_for_unix_users)(struct pdb_methods *methods);
633 bool (*is_responsible_for_unix_groups)(struct pdb_methods *methods);
634 bool (*is_responsible_for_everything_else)(struct pdb_methods *methods);
636 void *private_data; /* Private data of some kind */
638 void (*free_private_data)(void **);
641 typedef NTSTATUS (*pdb_init_function)(struct pdb_methods **, const char *);
643 struct pdb_init_function_entry {
644 const char *name;
646 /* Function to create a member of the pdb_methods list */
647 pdb_init_function init;
649 struct pdb_init_function_entry *prev, *next;
652 /* The following definitions come from passdb/account_pol.c */
654 void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int *num_names);
655 const char *decode_account_policy_name(enum pdb_policy_type type);
656 const char *get_account_policy_attr(enum pdb_policy_type type);
657 const char *account_policy_get_desc(enum pdb_policy_type type);
658 enum pdb_policy_type account_policy_name_to_typenum(const char *name);
659 bool account_policy_get_default(enum pdb_policy_type type, uint32_t *val);
660 bool init_account_policy(void);
661 bool account_policy_get(enum pdb_policy_type type, uint32_t *value);
662 bool account_policy_set(enum pdb_policy_type type, uint32_t value);
663 bool cache_account_policy_set(enum pdb_policy_type type, uint32_t value);
664 bool cache_account_policy_get(enum pdb_policy_type type, uint32_t *value);
665 struct db_context *get_account_pol_db( void );
667 /* The following definitions come from passdb/login_cache.c */
669 bool login_cache_init(void);
670 bool login_cache_shutdown(void);
671 bool login_cache_read(struct samu *sampass, struct login_cache *entry);
672 bool login_cache_write(const struct samu *sampass,
673 const struct login_cache *entry);
674 bool login_cache_delentry(const struct samu *sampass);
676 /* The following definitions come from passdb/passdb.c */
678 const char *my_sam_name(void);
679 struct samu *samu_new( TALLOC_CTX *ctx );
680 NTSTATUS samu_set_unix(struct samu *user, const struct passwd *pwd);
681 NTSTATUS samu_alloc_rid_unix(struct pdb_methods *methods,
682 struct samu *user, const struct passwd *pwd);
683 char *pdb_encode_acct_ctrl(uint32_t acct_ctrl, size_t length);
684 uint32_t pdb_decode_acct_ctrl(const char *p);
685 void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32_t acct_ctrl);
686 bool pdb_gethexpwd(const char *p, unsigned char *pwd);
687 void pdb_sethexhours(char *p, const unsigned char *hours);
688 bool pdb_gethexhours(const char *p, unsigned char *hours);
689 int algorithmic_rid_base(void);
690 uid_t algorithmic_pdb_user_rid_to_uid(uint32_t user_rid);
691 uid_t max_algorithmic_uid(void);
692 uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid);
693 gid_t pdb_group_rid_to_gid(uint32_t group_rid);
694 gid_t max_algorithmic_gid(void);
695 uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid);
696 bool algorithmic_pdb_rid_is_user(uint32_t rid);
697 bool lookup_global_sam_name(const char *name, int flags, uint32_t *rid,
698 enum lsa_SidType *type);
699 NTSTATUS local_password_change(const char *user_name,
700 int local_flags,
701 const char *new_passwd,
702 char **pp_err_str,
703 char **pp_msg_str);
704 bool init_samu_from_buffer(struct samu *sampass, uint32_t level,
705 uint8_t *buf, uint32_t buflen);
706 uint32_t init_buffer_from_samu (uint8_t **buf, struct samu *sampass, bool size_only);
707 bool pdb_copy_sam_account(struct samu *dst, struct samu *src );
708 bool pdb_update_bad_password_count(struct samu *sampass, bool *updated);
709 bool pdb_update_autolock_flag(struct samu *sampass, bool *updated);
710 bool pdb_increment_bad_password_count(struct samu *sampass);
711 bool is_dc_trusted_domain_situation(const char *domain_name);
712 bool get_trust_pw_clear(const char *domain, char **ret_pwd,
713 const char **account_name,
714 enum netr_SchannelType *channel);
715 bool get_trust_pw_hash(const char *domain, uint8_t ret_pwd[16],
716 const char **account_name,
717 enum netr_SchannelType *channel);
719 /* The following definitions come from passdb/pdb_compat.c */
721 uint32_t pdb_get_user_rid (const struct samu *sampass);
722 uint32_t pdb_get_group_rid (struct samu *sampass);
723 bool pdb_set_user_sid_from_rid (struct samu *sampass, uint32_t rid, enum pdb_value_state flag);
724 bool pdb_set_group_sid_from_rid (struct samu *sampass, uint32_t grid, enum pdb_value_state flag);
726 /* The following definitions come from passdb/pdb_get_set.c */
728 bool pdb_is_password_change_time_max(time_t test_time);
729 uint32_t pdb_get_acct_ctrl(const struct samu *sampass);
730 time_t pdb_get_logon_time(const struct samu *sampass);
731 time_t pdb_get_logoff_time(const struct samu *sampass);
732 time_t pdb_get_kickoff_time(const struct samu *sampass);
733 time_t pdb_get_bad_password_time(const struct samu *sampass);
734 time_t pdb_get_pass_last_set_time(const struct samu *sampass);
735 time_t pdb_get_pass_can_change_time(const struct samu *sampass);
736 time_t pdb_get_pass_can_change_time_noncalc(const struct samu *sampass);
737 time_t pdb_get_pass_must_change_time(const struct samu *sampass);
738 bool pdb_get_pass_can_change(const struct samu *sampass);
739 uint16_t pdb_get_logon_divs(const struct samu *sampass);
740 uint32_t pdb_get_hours_len(const struct samu *sampass);
741 const uint8_t *pdb_get_hours(const struct samu *sampass);
742 const uint8_t *pdb_get_nt_passwd(const struct samu *sampass);
743 const uint8_t *pdb_get_lanman_passwd(const struct samu *sampass);
744 const uint8_t *pdb_get_pw_history(const struct samu *sampass, uint32_t *current_hist_len);
745 const char *pdb_get_plaintext_passwd(const struct samu *sampass);
746 const struct dom_sid *pdb_get_user_sid(const struct samu *sampass);
747 const struct dom_sid *pdb_get_group_sid(struct samu *sampass);
748 enum pdb_value_state pdb_get_init_flags(const struct samu *sampass, enum pdb_elements element);
749 const char *pdb_get_username(const struct samu *sampass);
750 const char *pdb_get_domain(const struct samu *sampass);
751 const char *pdb_get_nt_username(const struct samu *sampass);
752 const char *pdb_get_fullname(const struct samu *sampass);
753 const char *pdb_get_homedir(const struct samu *sampass);
754 const char *pdb_get_dir_drive(const struct samu *sampass);
755 const char *pdb_get_logon_script(const struct samu *sampass);
756 const char *pdb_get_profile_path(const struct samu *sampass);
757 const char *pdb_get_acct_desc(const struct samu *sampass);
758 const char *pdb_get_workstations(const struct samu *sampass);
759 const char *pdb_get_comment(const struct samu *sampass);
760 const char *pdb_get_munged_dial(const struct samu *sampass);
761 uint16_t pdb_get_bad_password_count(const struct samu *sampass);
762 uint16_t pdb_get_logon_count(const struct samu *sampass);
763 uint16_t pdb_get_country_code(const struct samu *sampass);
764 uint16_t pdb_get_code_page(const struct samu *sampass);
765 uint32_t pdb_get_unknown_6(const struct samu *sampass);
766 void *pdb_get_backend_private_data(const struct samu *sampass, const struct pdb_methods *my_methods);
767 bool pdb_set_acct_ctrl(struct samu *sampass, uint32_t acct_ctrl, enum pdb_value_state flag);
768 bool pdb_set_logon_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
769 bool pdb_set_logoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
770 bool pdb_set_kickoff_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
771 bool pdb_set_bad_password_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
772 bool pdb_set_pass_can_change_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
773 bool pdb_set_pass_last_set_time(struct samu *sampass, time_t mytime, enum pdb_value_state flag);
774 bool pdb_set_hours_len(struct samu *sampass, uint32_t len, enum pdb_value_state flag);
775 bool pdb_set_logon_divs(struct samu *sampass, uint16_t hours, enum pdb_value_state flag);
776 bool pdb_set_init_flags(struct samu *sampass, enum pdb_elements element, enum pdb_value_state value_flag);
777 bool pdb_set_user_sid(struct samu *sampass, const struct dom_sid *u_sid, enum pdb_value_state flag);
778 bool pdb_set_user_sid_from_string(struct samu *sampass, const char *u_sid, enum pdb_value_state flag);
779 bool pdb_set_group_sid(struct samu *sampass, const struct dom_sid *g_sid, enum pdb_value_state flag);
780 bool pdb_set_username(struct samu *sampass, const char *username, enum pdb_value_state flag);
781 bool pdb_set_domain(struct samu *sampass, const char *domain, enum pdb_value_state flag);
782 bool pdb_set_nt_username(struct samu *sampass, const char *nt_username, enum pdb_value_state flag);
783 bool pdb_set_fullname(struct samu *sampass, const char *full_name, enum pdb_value_state flag);
784 bool pdb_set_logon_script(struct samu *sampass, const char *logon_script, enum pdb_value_state flag);
785 bool pdb_set_profile_path(struct samu *sampass, const char *profile_path, enum pdb_value_state flag);
786 bool pdb_set_dir_drive(struct samu *sampass, const char *dir_drive, enum pdb_value_state flag);
787 bool pdb_set_homedir(struct samu *sampass, const char *home_dir, enum pdb_value_state flag);
788 bool pdb_set_acct_desc(struct samu *sampass, const char *acct_desc, enum pdb_value_state flag);
789 bool pdb_set_workstations(struct samu *sampass, const char *workstations, enum pdb_value_state flag);
790 bool pdb_set_comment(struct samu *sampass, const char *comment, enum pdb_value_state flag);
791 bool pdb_set_munged_dial(struct samu *sampass, const char *munged_dial, enum pdb_value_state flag);
792 bool pdb_set_nt_passwd(struct samu *sampass, const uint8_t pwd[NT_HASH_LEN], enum pdb_value_state flag);
793 bool pdb_set_lanman_passwd(struct samu *sampass, const uint8_t pwd[LM_HASH_LEN], enum pdb_value_state flag);
794 bool pdb_set_pw_history(struct samu *sampass, const uint8_t *pwd, uint32_t historyLen, enum pdb_value_state flag);
795 bool pdb_set_plaintext_pw_only(struct samu *sampass, const char *password, enum pdb_value_state flag);
796 bool pdb_set_bad_password_count(struct samu *sampass, uint16_t bad_password_count, enum pdb_value_state flag);
797 bool pdb_set_logon_count(struct samu *sampass, uint16_t logon_count, enum pdb_value_state flag);
798 bool pdb_set_country_code(struct samu *sampass, uint16_t country_code,
799 enum pdb_value_state flag);
800 bool pdb_set_code_page(struct samu *sampass, uint16_t code_page,
801 enum pdb_value_state flag);
802 bool pdb_set_unknown_6(struct samu *sampass, uint32_t unkn, enum pdb_value_state flag);
803 bool pdb_set_hours(struct samu *sampass, const uint8_t *hours, int hours_len,
804 enum pdb_value_state flag);
805 bool pdb_set_backend_private_data(struct samu *sampass, void *private_data,
806 void (*free_fn)(void **),
807 const struct pdb_methods *my_methods,
808 enum pdb_value_state flag);
809 bool pdb_set_pass_can_change(struct samu *sampass, bool canchange);
810 bool pdb_set_plaintext_passwd(struct samu *sampass, const char *plaintext);
811 uint32_t pdb_build_fields_present(struct samu *sampass);
812 bool pdb_element_is_changed(const struct samu *sampass,
813 enum pdb_elements element);
814 bool pdb_element_is_set_or_changed(const struct samu *sampass,
815 enum pdb_elements element);
817 /* The following definitions come from passdb/pdb_interface.c */
819 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) ;
820 struct pdb_init_function_entry *pdb_find_backend_entry(const char *name);
821 const struct pdb_init_function_entry *pdb_get_backends(void);
822 struct tevent_context *pdb_get_tevent_context(void);
823 NTSTATUS make_pdb_method_name(struct pdb_methods **methods, const char *selected);
824 struct pdb_domain_info *pdb_get_domain_info(TALLOC_CTX *mem_ctx);
825 bool pdb_getsampwnam(struct samu *sam_acct, const char *username) ;
826 bool pdb_getsampwsid(struct samu *sam_acct, const struct dom_sid *sid) ;
827 NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32_t flags,
828 uint32_t *rid);
829 NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct);
830 NTSTATUS pdb_add_sam_account(struct samu *sam_acct) ;
831 NTSTATUS pdb_update_sam_account(struct samu *sam_acct) ;
832 NTSTATUS pdb_delete_sam_account(struct samu *sam_acct) ;
833 NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname);
834 NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, bool success);
835 bool pdb_getgrsid(GROUP_MAP *map, struct dom_sid sid);
836 bool pdb_getgrgid(GROUP_MAP *map, gid_t gid);
837 bool pdb_getgrnam(GROUP_MAP *map, const char *name);
838 NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name,
839 uint32_t *rid);
840 NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32_t rid);
841 NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map);
842 NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map);
843 NTSTATUS pdb_delete_group_mapping_entry(struct dom_sid sid);
844 bool pdb_enum_group_mapping(const struct dom_sid *sid,
845 enum lsa_SidType sid_name_use,
846 GROUP_MAP ***pp_rmap,
847 size_t *p_num_entries,
848 bool unix_only);
849 NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
850 const struct dom_sid *sid,
851 uint32_t **pp_member_rids,
852 size_t *p_num_members);
853 NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user,
854 struct dom_sid **pp_sids, gid_t **pp_gids,
855 uint32_t *p_num_groups);
856 NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user);
857 NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
858 uint32_t member_rid);
859 NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
860 uint32_t member_rid);
861 NTSTATUS pdb_create_alias(const char *name, uint32_t *rid);
862 NTSTATUS pdb_delete_alias(const struct dom_sid *sid);
863 NTSTATUS pdb_get_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
864 NTSTATUS pdb_set_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
865 NTSTATUS pdb_add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
866 NTSTATUS pdb_del_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
867 NTSTATUS pdb_enum_aliasmem(const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
868 struct dom_sid **pp_members, size_t *p_num_members);
869 NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
870 const struct dom_sid *domain_sid,
871 const struct dom_sid *members, size_t num_members,
872 uint32_t **pp_alias_rids,
873 size_t *p_num_alias_rids);
874 NTSTATUS pdb_lookup_rids(const struct dom_sid *domain_sid,
875 int num_rids,
876 uint32_t *rids,
877 const char **names,
878 enum lsa_SidType *attrs);
879 NTSTATUS pdb_lookup_names(const struct dom_sid *domain_sid,
880 int num_names,
881 const char **names,
882 uint32_t *rids,
883 enum lsa_SidType *attrs);
884 bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value);
885 bool pdb_set_account_policy(enum pdb_policy_type type, uint32_t value);
886 bool pdb_get_seq_num(time_t *seq_num);
887 bool pdb_uid_to_sid(uid_t uid, struct dom_sid *sid);
888 bool pdb_gid_to_sid(gid_t gid, struct dom_sid *sid);
889 bool pdb_sid_to_id(const struct dom_sid *sid, struct unixid *id);
890 uint32_t pdb_capabilities(void);
891 bool pdb_new_rid(uint32_t *rid);
892 bool initialize_password_db(bool reload, struct tevent_context *tevent_ctx);
893 struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx,
894 enum pdb_search_type type);
895 struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32_t acct_flags);
896 struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx);
897 struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
898 uint32_t pdb_search_entries(struct pdb_search *search,
899 uint32_t start_idx, uint32_t max_entries,
900 struct samr_displayentry **result);
901 bool pdb_get_trusteddom_pw(const char *domain, char** pwd, struct dom_sid *sid,
902 time_t *pass_last_set_time);
903 bool pdb_set_trusteddom_pw(const char* domain, const char* pwd,
904 const struct dom_sid *sid);
905 bool pdb_del_trusteddom_pw(const char *domain);
906 NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
907 struct trustdom_info ***domains);
908 NTSTATUS pdb_get_trusted_domain(TALLOC_CTX *mem_ctx, const char *domain,
909 struct pdb_trusted_domain **td);
910 NTSTATUS pdb_get_trusted_domain_by_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid,
911 struct pdb_trusted_domain **td);
912 NTSTATUS pdb_set_trusted_domain(const char* domain,
913 const struct pdb_trusted_domain *td);
914 NTSTATUS pdb_del_trusted_domain(const char *domain);
915 NTSTATUS pdb_enum_trusted_domains(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
916 struct pdb_trusted_domain ***domains);
917 NTSTATUS make_pdb_method( struct pdb_methods **methods ) ;
918 NTSTATUS pdb_get_secret(TALLOC_CTX *mem_ctx,
919 const char *secret_name,
920 DATA_BLOB *secret_current,
921 NTTIME *secret_current_lastchange,
922 DATA_BLOB *secret_old,
923 NTTIME *secret_old_lastchange,
924 struct security_descriptor **sd);
925 NTSTATUS pdb_set_secret(const char *secret_name,
926 DATA_BLOB *secret_current,
927 DATA_BLOB *secret_old,
928 struct security_descriptor *sd);
929 NTSTATUS pdb_delete_secret(const char *secret_name);
930 bool pdb_sid_to_id_unix_users_and_groups(const struct dom_sid *sid,
931 struct unixid *id);
933 NTSTATUS pdb_enum_upn_suffixes(TALLOC_CTX *mem_ctx,
934 uint32_t *num_suffixes,
935 char ***suffixes);
937 NTSTATUS pdb_set_upn_suffixes(uint32_t num_suffixes,
938 const char **suffixes);
939 bool pdb_is_responsible_for_our_sam(void);
940 bool pdb_is_responsible_for_builtin(void);
941 bool pdb_is_responsible_for_wellknown(void);
942 bool pdb_is_responsible_for_unix_users(void);
943 bool pdb_is_responsible_for_unix_groups(void);
944 bool pdb_is_responsible_for_everything_else(void);
946 /* The following definitions come from passdb/pdb_util.c */
948 NTSTATUS pdb_create_builtin(uint32_t rid);
949 NTSTATUS create_builtin_users(const struct dom_sid *sid);
950 NTSTATUS create_builtin_administrators(const struct dom_sid *sid);
952 #include "passdb/machine_sid.h"
953 #include "passdb/lookup_sid.h"
955 /* The following definitions come from passdb/pdb_unixid.c */
956 void unixid_from_uid(struct unixid *id, uint32_t some_uid);
957 void unixid_from_gid(struct unixid *id, uint32_t some_gid);
958 void unixid_from_both(struct unixid *id, uint32_t some_id);
960 /* The following definitions come from passdb/pdb_secrets.c
961 * and should be used by PDB modules if they need to store
962 * sid/guid information for the domain in secrets database
964 bool PDB_secrets_mark_domain_protected(const char *domain);
965 bool PDB_secrets_clear_domain_protection(const char *domain);
966 bool PDB_secrets_store_domain_sid(const char *domain, const struct dom_sid *sid);
967 bool PDB_secrets_fetch_domain_sid(const char *domain, struct dom_sid *sid);
968 bool PDB_secrets_store_domain_guid(const char *domain, struct GUID *guid);
969 bool PDB_secrets_fetch_domain_guid(const char *domain, struct GUID *guid);
971 #endif /* _PASSDB_H */