2 * Unix SMB/CIFS implementation.
3 * passdb - password and authentication handling
5 * Copyright (C) Andrew Tridgell 1992-1998
6 * Copyright (C) Jeremy Allison 1995-2009
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998
8 * Copyright (C) Jean François Micouleau 1998-2001
9 * Copyright (C) Gerald (Jerry) Carter 2000-2006
10 * Copyright (C) Simo Sorce 2000-2003,2006
11 * Copyright (C) Andrew Bartlett 2001-2002
12 * Copyright (C) Shahms King 2001
13 * Copyright (C) Jelmer Vernooij 2002
14 * Copyright (C) Rafal Szczesniak 2002
15 * Copyright (C) Stefan (metze) Metzmacher 2002-2003
16 * Copyright (C) Guenther Deschner 2004-2005
17 * Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2004-2005
18 * Copyright (C) Vince Brimhall 2004-2005
19 * Copyright (C) Volker Lendecke 2006
20 * Copyright (C) Michael Adam 2007
21 * Copyright (C) Dan Sledz 2009
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, see <http://www.gnu.org/licenses/>.
37 #ifndef _PASSDB_PROTO_H_
38 #define _PASSDB_PROTO_H_
40 /* The following definitions come from passdb/account_pol.c */
42 void account_policy_names_list(const char ***names
, int *num_names
);
43 const char *decode_account_policy_name(enum pdb_policy_type type
);
44 const char *get_account_policy_attr(enum pdb_policy_type type
);
45 const char *account_policy_get_desc(enum pdb_policy_type type
);
46 enum pdb_policy_type
account_policy_name_to_typenum(const char *name
);
47 bool account_policy_get_default(enum pdb_policy_type type
, uint32_t *val
);
48 bool init_account_policy(void);
49 bool account_policy_get(enum pdb_policy_type type
, uint32_t *value
);
50 bool account_policy_set(enum pdb_policy_type type
, uint32_t value
);
51 bool cache_account_policy_set(enum pdb_policy_type type
, uint32_t value
);
52 bool cache_account_policy_get(enum pdb_policy_type type
, uint32_t *value
);
53 struct db_context
*get_account_pol_db( void );
55 /* The following definitions come from passdb/login_cache.c */
57 bool login_cache_init(void);
58 bool login_cache_shutdown(void);
59 bool login_cache_read(struct samu
*sampass
, struct login_cache
*entry
);
60 bool login_cache_write(const struct samu
*sampass
,
61 const struct login_cache
*entry
);
62 bool login_cache_delentry(const struct samu
*sampass
);
64 /* The following definitions come from passdb/passdb.c */
66 const char *my_sam_name(void);
67 struct samu
*samu_new( TALLOC_CTX
*ctx
);
68 NTSTATUS
samu_set_unix(struct samu
*user
, const struct passwd
*pwd
);
69 NTSTATUS
samu_alloc_rid_unix(struct samu
*user
, const struct passwd
*pwd
);
70 char *pdb_encode_acct_ctrl(uint32_t acct_ctrl
, size_t length
);
71 uint32_t pdb_decode_acct_ctrl(const char *p
);
72 void pdb_sethexpwd(char p
[33], const unsigned char *pwd
, uint32_t acct_ctrl
);
73 bool pdb_gethexpwd(const char *p
, unsigned char *pwd
);
74 void pdb_sethexhours(char *p
, const unsigned char *hours
);
75 bool pdb_gethexhours(const char *p
, unsigned char *hours
);
76 int algorithmic_rid_base(void);
77 uid_t
algorithmic_pdb_user_rid_to_uid(uint32_t user_rid
);
78 uid_t
max_algorithmic_uid(void);
79 uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid
);
80 gid_t
pdb_group_rid_to_gid(uint32_t group_rid
);
81 gid_t
max_algorithmic_gid(void);
82 uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid
);
83 bool algorithmic_pdb_rid_is_user(uint32_t rid
);
84 bool lookup_global_sam_name(const char *name
, int flags
, uint32_t *rid
,
85 enum lsa_SidType
*type
);
86 NTSTATUS
local_password_change(const char *user_name
,
88 const char *new_passwd
,
91 bool init_samu_from_buffer(struct samu
*sampass
, uint32_t level
,
92 uint8_t *buf
, uint32_t buflen
);
93 uint32_t init_buffer_from_samu (uint8_t **buf
, struct samu
*sampass
, bool size_only
);
94 bool pdb_copy_sam_account(struct samu
*dst
, struct samu
*src
);
95 bool pdb_update_bad_password_count(struct samu
*sampass
, bool *updated
);
96 bool pdb_update_autolock_flag(struct samu
*sampass
, bool *updated
);
97 bool pdb_increment_bad_password_count(struct samu
*sampass
);
98 bool is_dc_trusted_domain_situation(const char *domain_name
);
99 bool get_trust_pw_clear(const char *domain
, char **ret_pwd
,
100 const char **account_name
,
101 enum netr_SchannelType
*channel
);
102 bool get_trust_pw_hash(const char *domain
, uint8_t ret_pwd
[16],
103 const char **account_name
,
104 enum netr_SchannelType
*channel
);
106 /* The following definitions come from passdb/pdb_compat.c */
108 uint32_t pdb_get_user_rid (const struct samu
*sampass
);
109 uint32_t pdb_get_group_rid (struct samu
*sampass
);
110 bool pdb_set_user_sid_from_rid (struct samu
*sampass
, uint32_t rid
, enum pdb_value_state flag
);
111 bool pdb_set_group_sid_from_rid (struct samu
*sampass
, uint32_t grid
, enum pdb_value_state flag
);
113 /* The following definitions come from passdb/pdb_get_set.c */
115 bool pdb_is_password_change_time_max(time_t test_time
);
116 uint32_t pdb_get_acct_ctrl(const struct samu
*sampass
);
117 time_t pdb_get_logon_time(const struct samu
*sampass
);
118 time_t pdb_get_logoff_time(const struct samu
*sampass
);
119 time_t pdb_get_kickoff_time(const struct samu
*sampass
);
120 time_t pdb_get_bad_password_time(const struct samu
*sampass
);
121 time_t pdb_get_pass_last_set_time(const struct samu
*sampass
);
122 time_t pdb_get_pass_can_change_time(const struct samu
*sampass
);
123 time_t pdb_get_pass_can_change_time_noncalc(const struct samu
*sampass
);
124 time_t pdb_get_pass_must_change_time(const struct samu
*sampass
);
125 bool pdb_get_pass_can_change(const struct samu
*sampass
);
126 uint16_t pdb_get_logon_divs(const struct samu
*sampass
);
127 uint32_t pdb_get_hours_len(const struct samu
*sampass
);
128 const uint8_t *pdb_get_hours(const struct samu
*sampass
);
129 const uint8_t *pdb_get_nt_passwd(const struct samu
*sampass
);
130 const uint8_t *pdb_get_lanman_passwd(const struct samu
*sampass
);
131 const uint8_t *pdb_get_pw_history(const struct samu
*sampass
, uint32_t *current_hist_len
);
132 const char *pdb_get_plaintext_passwd(const struct samu
*sampass
);
133 const struct dom_sid
*pdb_get_user_sid(const struct samu
*sampass
);
134 const struct dom_sid
*pdb_get_group_sid(struct samu
*sampass
);
135 enum pdb_value_state
pdb_get_init_flags(const struct samu
*sampass
, enum pdb_elements element
);
136 const char *pdb_get_username(const struct samu
*sampass
);
137 const char *pdb_get_domain(const struct samu
*sampass
);
138 const char *pdb_get_nt_username(const struct samu
*sampass
);
139 const char *pdb_get_fullname(const struct samu
*sampass
);
140 const char *pdb_get_homedir(const struct samu
*sampass
);
141 const char *pdb_get_dir_drive(const struct samu
*sampass
);
142 const char *pdb_get_logon_script(const struct samu
*sampass
);
143 const char *pdb_get_profile_path(const struct samu
*sampass
);
144 const char *pdb_get_acct_desc(const struct samu
*sampass
);
145 const char *pdb_get_workstations(const struct samu
*sampass
);
146 const char *pdb_get_comment(const struct samu
*sampass
);
147 const char *pdb_get_munged_dial(const struct samu
*sampass
);
148 uint16_t pdb_get_bad_password_count(const struct samu
*sampass
);
149 uint16_t pdb_get_logon_count(const struct samu
*sampass
);
150 uint16_t pdb_get_country_code(const struct samu
*sampass
);
151 uint16_t pdb_get_code_page(const struct samu
*sampass
);
152 uint32_t pdb_get_unknown_6(const struct samu
*sampass
);
153 void *pdb_get_backend_private_data(const struct samu
*sampass
, const struct pdb_methods
*my_methods
);
154 bool pdb_set_acct_ctrl(struct samu
*sampass
, uint32_t acct_ctrl
, enum pdb_value_state flag
);
155 bool pdb_set_logon_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
156 bool pdb_set_logoff_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
157 bool pdb_set_kickoff_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
158 bool pdb_set_bad_password_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
159 bool pdb_set_pass_can_change_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
160 bool pdb_set_pass_must_change_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
161 bool pdb_set_pass_last_set_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
162 bool pdb_set_hours_len(struct samu
*sampass
, uint32_t len
, enum pdb_value_state flag
);
163 bool pdb_set_logon_divs(struct samu
*sampass
, uint16_t hours
, enum pdb_value_state flag
);
164 bool pdb_set_init_flags(struct samu
*sampass
, enum pdb_elements element
, enum pdb_value_state value_flag
);
165 bool pdb_set_user_sid(struct samu
*sampass
, const struct dom_sid
*u_sid
, enum pdb_value_state flag
);
166 bool pdb_set_user_sid_from_string(struct samu
*sampass
, fstring u_sid
, enum pdb_value_state flag
);
167 bool pdb_set_group_sid(struct samu
*sampass
, const struct dom_sid
*g_sid
, enum pdb_value_state flag
);
168 bool pdb_set_username(struct samu
*sampass
, const char *username
, enum pdb_value_state flag
);
169 bool pdb_set_domain(struct samu
*sampass
, const char *domain
, enum pdb_value_state flag
);
170 bool pdb_set_nt_username(struct samu
*sampass
, const char *nt_username
, enum pdb_value_state flag
);
171 bool pdb_set_fullname(struct samu
*sampass
, const char *full_name
, enum pdb_value_state flag
);
172 bool pdb_set_logon_script(struct samu
*sampass
, const char *logon_script
, enum pdb_value_state flag
);
173 bool pdb_set_profile_path(struct samu
*sampass
, const char *profile_path
, enum pdb_value_state flag
);
174 bool pdb_set_dir_drive(struct samu
*sampass
, const char *dir_drive
, enum pdb_value_state flag
);
175 bool pdb_set_homedir(struct samu
*sampass
, const char *home_dir
, enum pdb_value_state flag
);
176 bool pdb_set_acct_desc(struct samu
*sampass
, const char *acct_desc
, enum pdb_value_state flag
);
177 bool pdb_set_workstations(struct samu
*sampass
, const char *workstations
, enum pdb_value_state flag
);
178 bool pdb_set_comment(struct samu
*sampass
, const char *comment
, enum pdb_value_state flag
);
179 bool pdb_set_munged_dial(struct samu
*sampass
, const char *munged_dial
, enum pdb_value_state flag
);
180 bool pdb_set_nt_passwd(struct samu
*sampass
, const uint8_t pwd
[NT_HASH_LEN
], enum pdb_value_state flag
);
181 bool pdb_set_lanman_passwd(struct samu
*sampass
, const uint8_t pwd
[LM_HASH_LEN
], enum pdb_value_state flag
);
182 bool pdb_set_pw_history(struct samu
*sampass
, const uint8_t *pwd
, uint32_t historyLen
, enum pdb_value_state flag
);
183 bool pdb_set_plaintext_pw_only(struct samu
*sampass
, const char *password
, enum pdb_value_state flag
);
184 bool pdb_set_bad_password_count(struct samu
*sampass
, uint16_t bad_password_count
, enum pdb_value_state flag
);
185 bool pdb_set_logon_count(struct samu
*sampass
, uint16_t logon_count
, enum pdb_value_state flag
);
186 bool pdb_set_country_code(struct samu
*sampass
, uint16_t country_code
,
187 enum pdb_value_state flag
);
188 bool pdb_set_code_page(struct samu
*sampass
, uint16_t code_page
,
189 enum pdb_value_state flag
);
190 bool pdb_set_unknown_6(struct samu
*sampass
, uint32_t unkn
, enum pdb_value_state flag
);
191 bool pdb_set_hours(struct samu
*sampass
, const uint8
*hours
, int hours_len
,
192 enum pdb_value_state flag
);
193 bool pdb_set_backend_private_data(struct samu
*sampass
, void *private_data
,
194 void (*free_fn
)(void **),
195 const struct pdb_methods
*my_methods
,
196 enum pdb_value_state flag
);
197 bool pdb_set_pass_can_change(struct samu
*sampass
, bool canchange
);
198 bool pdb_set_plaintext_passwd(struct samu
*sampass
, const char *plaintext
);
199 uint32_t pdb_build_fields_present(struct samu
*sampass
);
201 /* The following definitions come from passdb/pdb_interface.c */
203 NTSTATUS
smb_register_passdb(int version
, const char *name
, pdb_init_function init
) ;
204 struct pdb_init_function_entry
*pdb_find_backend_entry(const char *name
);
205 struct event_context
*pdb_get_event_context(void);
206 NTSTATUS
make_pdb_method_name(struct pdb_methods
**methods
, const char *selected
);
207 struct pdb_domain_info
*pdb_get_domain_info(TALLOC_CTX
*mem_ctx
);
208 bool pdb_getsampwnam(struct samu
*sam_acct
, const char *username
) ;
209 bool pdb_getsampwsid(struct samu
*sam_acct
, const struct dom_sid
*sid
) ;
210 NTSTATUS
pdb_create_user(TALLOC_CTX
*mem_ctx
, const char *name
, uint32_t flags
,
212 NTSTATUS
pdb_delete_user(TALLOC_CTX
*mem_ctx
, struct samu
*sam_acct
);
213 NTSTATUS
pdb_add_sam_account(struct samu
*sam_acct
) ;
214 NTSTATUS
pdb_update_sam_account(struct samu
*sam_acct
) ;
215 NTSTATUS
pdb_delete_sam_account(struct samu
*sam_acct
) ;
216 NTSTATUS
pdb_rename_sam_account(struct samu
*oldname
, const char *newname
);
217 NTSTATUS
pdb_update_login_attempts(struct samu
*sam_acct
, bool success
);
218 bool pdb_getgrsid(GROUP_MAP
*map
, struct dom_sid sid
);
219 bool pdb_getgrgid(GROUP_MAP
*map
, gid_t gid
);
220 bool pdb_getgrnam(GROUP_MAP
*map
, const char *name
);
221 NTSTATUS
pdb_create_dom_group(TALLOC_CTX
*mem_ctx
, const char *name
,
223 NTSTATUS
pdb_delete_dom_group(TALLOC_CTX
*mem_ctx
, uint32_t rid
);
224 NTSTATUS
pdb_add_group_mapping_entry(GROUP_MAP
*map
);
225 NTSTATUS
pdb_update_group_mapping_entry(GROUP_MAP
*map
);
226 NTSTATUS
pdb_delete_group_mapping_entry(struct dom_sid sid
);
227 bool pdb_enum_group_mapping(const struct dom_sid
*sid
, enum lsa_SidType sid_name_use
, GROUP_MAP
**pp_rmap
,
228 size_t *p_num_entries
, bool unix_only
);
229 NTSTATUS
pdb_enum_group_members(TALLOC_CTX
*mem_ctx
,
230 const struct dom_sid
*sid
,
231 uint32_t **pp_member_rids
,
232 size_t *p_num_members
);
233 NTSTATUS
pdb_enum_group_memberships(TALLOC_CTX
*mem_ctx
, struct samu
*user
,
234 struct dom_sid
**pp_sids
, gid_t
**pp_gids
,
235 uint32_t *p_num_groups
);
236 NTSTATUS
pdb_set_unix_primary_group(TALLOC_CTX
*mem_ctx
, struct samu
*user
);
237 NTSTATUS
pdb_add_groupmem(TALLOC_CTX
*mem_ctx
, uint32_t group_rid
,
238 uint32_t member_rid
);
239 NTSTATUS
pdb_del_groupmem(TALLOC_CTX
*mem_ctx
, uint32_t group_rid
,
240 uint32_t member_rid
);
241 NTSTATUS
pdb_create_alias(const char *name
, uint32_t *rid
);
242 NTSTATUS
pdb_delete_alias(const struct dom_sid
*sid
);
243 NTSTATUS
pdb_get_aliasinfo(const struct dom_sid
*sid
, struct acct_info
*info
);
244 NTSTATUS
pdb_set_aliasinfo(const struct dom_sid
*sid
, struct acct_info
*info
);
245 NTSTATUS
pdb_add_aliasmem(const struct dom_sid
*alias
, const struct dom_sid
*member
);
246 NTSTATUS
pdb_del_aliasmem(const struct dom_sid
*alias
, const struct dom_sid
*member
);
247 NTSTATUS
pdb_enum_aliasmem(const struct dom_sid
*alias
, TALLOC_CTX
*mem_ctx
,
248 struct dom_sid
**pp_members
, size_t *p_num_members
);
249 NTSTATUS
pdb_enum_alias_memberships(TALLOC_CTX
*mem_ctx
,
250 const struct dom_sid
*domain_sid
,
251 const struct dom_sid
*members
, size_t num_members
,
252 uint32_t **pp_alias_rids
,
253 size_t *p_num_alias_rids
);
254 NTSTATUS
pdb_lookup_rids(const struct dom_sid
*domain_sid
,
258 enum lsa_SidType
*attrs
);
259 NTSTATUS
pdb_lookup_names(const struct dom_sid
*domain_sid
,
263 enum lsa_SidType
*attrs
);
264 bool pdb_get_account_policy(enum pdb_policy_type type
, uint32_t *value
);
265 bool pdb_set_account_policy(enum pdb_policy_type type
, uint32_t value
);
266 bool pdb_get_seq_num(time_t *seq_num
);
267 bool pdb_uid_to_sid(uid_t uid
, struct dom_sid
*sid
);
268 bool pdb_gid_to_sid(gid_t gid
, struct dom_sid
*sid
);
269 bool pdb_sid_to_id(const struct dom_sid
*sid
, union unid_t
*id
,
270 enum lsa_SidType
*type
);
271 uint32_t pdb_capabilities(void);
272 bool pdb_new_rid(uint32_t *rid
);
273 bool initialize_password_db(bool reload
, struct event_context
*event_ctx
);
274 struct pdb_search
*pdb_search_init(TALLOC_CTX
*mem_ctx
,
275 enum pdb_search_type type
);
276 struct pdb_search
*pdb_search_users(TALLOC_CTX
*mem_ctx
, uint32_t acct_flags
);
277 struct pdb_search
*pdb_search_groups(TALLOC_CTX
*mem_ctx
);
278 struct pdb_search
*pdb_search_aliases(TALLOC_CTX
*mem_ctx
, const struct dom_sid
*sid
);
279 uint32_t pdb_search_entries(struct pdb_search
*search
,
280 uint32_t start_idx
, uint32_t max_entries
,
281 struct samr_displayentry
**result
);
282 bool pdb_get_trusteddom_pw(const char *domain
, char** pwd
, struct dom_sid
*sid
,
283 time_t *pass_last_set_time
);
284 bool pdb_set_trusteddom_pw(const char* domain
, const char* pwd
,
285 const struct dom_sid
*sid
);
286 bool pdb_del_trusteddom_pw(const char *domain
);
287 NTSTATUS
pdb_enum_trusteddoms(TALLOC_CTX
*mem_ctx
, uint32_t *num_domains
,
288 struct trustdom_info
***domains
);
289 NTSTATUS
pdb_get_trusted_domain(TALLOC_CTX
*mem_ctx
, const char *domain
,
290 struct pdb_trusted_domain
**td
);
291 NTSTATUS
pdb_get_trusted_domain_by_sid(TALLOC_CTX
*mem_ctx
, struct dom_sid
*sid
,
292 struct pdb_trusted_domain
**td
);
293 NTSTATUS
pdb_set_trusted_domain(const char* domain
,
294 const struct pdb_trusted_domain
*td
);
295 NTSTATUS
pdb_del_trusted_domain(const char *domain
);
296 NTSTATUS
pdb_enum_trusted_domains(TALLOC_CTX
*mem_ctx
, uint32_t *num_domains
,
297 struct pdb_trusted_domain
***domains
);
298 NTSTATUS
make_pdb_method( struct pdb_methods
**methods
) ;
300 /* The following definitions come from passdb/pdb_ldap.c */
302 const char** get_userattr_list( TALLOC_CTX
*mem_ctx
, int schema_ver
);
303 NTSTATUS
pdb_init_ldapsam_compat(struct pdb_methods
**pdb_method
, const char *location
);
304 NTSTATUS
pdb_init_ldapsam(struct pdb_methods
**pdb_method
, const char *location
);
305 NTSTATUS
pdb_ldap_init(void);
307 /* The following definitions come from passdb/pdb_nds.c */
309 struct smbldap_state
;
311 int pdb_nds_get_password(
312 struct smbldap_state
*ldap_state
,
316 int pdb_nds_set_password(
317 struct smbldap_state
*ldap_state
,
320 NTSTATUS
pdb_nds_init(void);
322 /* The following definitions come from passdb/pdb_nds.c */
324 NTSTATUS
pdb_ipa_init(void);
326 /* The following definitions come from passdb/pdb_smbpasswd.c */
328 NTSTATUS
pdb_smbpasswd_init(void) ;
330 /* The following definitions come from passdb/pdb_wbc_sam.c */
332 NTSTATUS
pdb_wbc_sam_init(void);
334 /* The following definitions come from passdb/pdb_tdb.c */
336 NTSTATUS
pdb_tdbsam_init(void);
338 /* The following definitions come from passdb/pdb_util.c */
340 NTSTATUS
create_builtin_users(const struct dom_sid
*sid
);
341 NTSTATUS
create_builtin_administrators(const struct dom_sid
*sid
);
343 #endif /* _PASSDB_PROTO_H_ */