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 uint32_t pdb_get_acct_ctrl(const struct samu
*sampass
);
116 time_t pdb_get_logon_time(const struct samu
*sampass
);
117 time_t pdb_get_logoff_time(const struct samu
*sampass
);
118 time_t pdb_get_kickoff_time(const struct samu
*sampass
);
119 time_t pdb_get_bad_password_time(const struct samu
*sampass
);
120 time_t pdb_get_pass_last_set_time(const struct samu
*sampass
);
121 time_t pdb_get_pass_can_change_time(const struct samu
*sampass
);
122 time_t pdb_get_pass_can_change_time_noncalc(const struct samu
*sampass
);
123 time_t pdb_get_pass_must_change_time(const struct samu
*sampass
);
124 bool pdb_get_pass_can_change(const struct samu
*sampass
);
125 uint16_t pdb_get_logon_divs(const struct samu
*sampass
);
126 uint32_t pdb_get_hours_len(const struct samu
*sampass
);
127 const uint8_t *pdb_get_hours(const struct samu
*sampass
);
128 const uint8_t *pdb_get_nt_passwd(const struct samu
*sampass
);
129 const uint8_t *pdb_get_lanman_passwd(const struct samu
*sampass
);
130 const uint8_t *pdb_get_pw_history(const struct samu
*sampass
, uint32_t *current_hist_len
);
131 const char *pdb_get_plaintext_passwd(const struct samu
*sampass
);
132 const struct dom_sid
*pdb_get_user_sid(const struct samu
*sampass
);
133 const struct dom_sid
*pdb_get_group_sid(struct samu
*sampass
);
134 enum pdb_value_state
pdb_get_init_flags(const struct samu
*sampass
, enum pdb_elements element
);
135 const char *pdb_get_username(const struct samu
*sampass
);
136 const char *pdb_get_domain(const struct samu
*sampass
);
137 const char *pdb_get_nt_username(const struct samu
*sampass
);
138 const char *pdb_get_fullname(const struct samu
*sampass
);
139 const char *pdb_get_homedir(const struct samu
*sampass
);
140 const char *pdb_get_dir_drive(const struct samu
*sampass
);
141 const char *pdb_get_logon_script(const struct samu
*sampass
);
142 const char *pdb_get_profile_path(const struct samu
*sampass
);
143 const char *pdb_get_acct_desc(const struct samu
*sampass
);
144 const char *pdb_get_workstations(const struct samu
*sampass
);
145 const char *pdb_get_comment(const struct samu
*sampass
);
146 const char *pdb_get_munged_dial(const struct samu
*sampass
);
147 uint16_t pdb_get_bad_password_count(const struct samu
*sampass
);
148 uint16_t pdb_get_logon_count(const struct samu
*sampass
);
149 uint16_t pdb_get_country_code(const struct samu
*sampass
);
150 uint16_t pdb_get_code_page(const struct samu
*sampass
);
151 uint32_t pdb_get_unknown_6(const struct samu
*sampass
);
152 void *pdb_get_backend_private_data(const struct samu
*sampass
, const struct pdb_methods
*my_methods
);
153 bool pdb_set_acct_ctrl(struct samu
*sampass
, uint32_t acct_ctrl
, enum pdb_value_state flag
);
154 bool pdb_set_logon_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
155 bool pdb_set_logoff_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
156 bool pdb_set_kickoff_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
157 bool pdb_set_bad_password_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
158 bool pdb_set_pass_can_change_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
159 bool pdb_set_pass_must_change_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
160 bool pdb_set_pass_last_set_time(struct samu
*sampass
, time_t mytime
, enum pdb_value_state flag
);
161 bool pdb_set_hours_len(struct samu
*sampass
, uint32_t len
, enum pdb_value_state flag
);
162 bool pdb_set_logon_divs(struct samu
*sampass
, uint16_t hours
, enum pdb_value_state flag
);
163 bool pdb_set_init_flags(struct samu
*sampass
, enum pdb_elements element
, enum pdb_value_state value_flag
);
164 bool pdb_set_user_sid(struct samu
*sampass
, const struct dom_sid
*u_sid
, enum pdb_value_state flag
);
165 bool pdb_set_user_sid_from_string(struct samu
*sampass
, fstring u_sid
, enum pdb_value_state flag
);
166 bool pdb_set_group_sid(struct samu
*sampass
, const struct dom_sid
*g_sid
, enum pdb_value_state flag
);
167 bool pdb_set_username(struct samu
*sampass
, const char *username
, enum pdb_value_state flag
);
168 bool pdb_set_domain(struct samu
*sampass
, const char *domain
, enum pdb_value_state flag
);
169 bool pdb_set_nt_username(struct samu
*sampass
, const char *nt_username
, enum pdb_value_state flag
);
170 bool pdb_set_fullname(struct samu
*sampass
, const char *full_name
, enum pdb_value_state flag
);
171 bool pdb_set_logon_script(struct samu
*sampass
, const char *logon_script
, enum pdb_value_state flag
);
172 bool pdb_set_profile_path(struct samu
*sampass
, const char *profile_path
, enum pdb_value_state flag
);
173 bool pdb_set_dir_drive(struct samu
*sampass
, const char *dir_drive
, enum pdb_value_state flag
);
174 bool pdb_set_homedir(struct samu
*sampass
, const char *home_dir
, enum pdb_value_state flag
);
175 bool pdb_set_acct_desc(struct samu
*sampass
, const char *acct_desc
, enum pdb_value_state flag
);
176 bool pdb_set_workstations(struct samu
*sampass
, const char *workstations
, enum pdb_value_state flag
);
177 bool pdb_set_comment(struct samu
*sampass
, const char *comment
, enum pdb_value_state flag
);
178 bool pdb_set_munged_dial(struct samu
*sampass
, const char *munged_dial
, enum pdb_value_state flag
);
179 bool pdb_set_nt_passwd(struct samu
*sampass
, const uint8_t pwd
[NT_HASH_LEN
], enum pdb_value_state flag
);
180 bool pdb_set_lanman_passwd(struct samu
*sampass
, const uint8_t pwd
[LM_HASH_LEN
], enum pdb_value_state flag
);
181 bool pdb_set_pw_history(struct samu
*sampass
, const uint8_t *pwd
, uint32_t historyLen
, enum pdb_value_state flag
);
182 bool pdb_set_plaintext_pw_only(struct samu
*sampass
, const char *password
, enum pdb_value_state flag
);
183 bool pdb_set_bad_password_count(struct samu
*sampass
, uint16_t bad_password_count
, enum pdb_value_state flag
);
184 bool pdb_set_logon_count(struct samu
*sampass
, uint16_t logon_count
, enum pdb_value_state flag
);
185 bool pdb_set_country_code(struct samu
*sampass
, uint16_t country_code
,
186 enum pdb_value_state flag
);
187 bool pdb_set_code_page(struct samu
*sampass
, uint16_t code_page
,
188 enum pdb_value_state flag
);
189 bool pdb_set_unknown_6(struct samu
*sampass
, uint32_t unkn
, enum pdb_value_state flag
);
190 bool pdb_set_hours(struct samu
*sampass
, const uint8
*hours
, int hours_len
,
191 enum pdb_value_state flag
);
192 bool pdb_set_backend_private_data(struct samu
*sampass
, void *private_data
,
193 void (*free_fn
)(void **),
194 const struct pdb_methods
*my_methods
,
195 enum pdb_value_state flag
);
196 bool pdb_set_pass_can_change(struct samu
*sampass
, bool canchange
);
197 bool pdb_set_plaintext_passwd(struct samu
*sampass
, const char *plaintext
);
198 uint32_t pdb_build_fields_present(struct samu
*sampass
);
200 /* The following definitions come from passdb/pdb_interface.c */
202 NTSTATUS
smb_register_passdb(int version
, const char *name
, pdb_init_function init
) ;
203 struct pdb_init_function_entry
*pdb_find_backend_entry(const char *name
);
204 struct event_context
*pdb_get_event_context(void);
205 NTSTATUS
make_pdb_method_name(struct pdb_methods
**methods
, const char *selected
);
206 struct pdb_domain_info
*pdb_get_domain_info(TALLOC_CTX
*mem_ctx
);
207 bool pdb_getsampwnam(struct samu
*sam_acct
, const char *username
) ;
208 bool pdb_getsampwsid(struct samu
*sam_acct
, const struct dom_sid
*sid
) ;
209 NTSTATUS
pdb_create_user(TALLOC_CTX
*mem_ctx
, const char *name
, uint32_t flags
,
211 NTSTATUS
pdb_delete_user(TALLOC_CTX
*mem_ctx
, struct samu
*sam_acct
);
212 NTSTATUS
pdb_add_sam_account(struct samu
*sam_acct
) ;
213 NTSTATUS
pdb_update_sam_account(struct samu
*sam_acct
) ;
214 NTSTATUS
pdb_delete_sam_account(struct samu
*sam_acct
) ;
215 NTSTATUS
pdb_rename_sam_account(struct samu
*oldname
, const char *newname
);
216 NTSTATUS
pdb_update_login_attempts(struct samu
*sam_acct
, bool success
);
217 bool pdb_getgrsid(GROUP_MAP
*map
, struct dom_sid sid
);
218 bool pdb_getgrgid(GROUP_MAP
*map
, gid_t gid
);
219 bool pdb_getgrnam(GROUP_MAP
*map
, const char *name
);
220 NTSTATUS
pdb_create_dom_group(TALLOC_CTX
*mem_ctx
, const char *name
,
222 NTSTATUS
pdb_delete_dom_group(TALLOC_CTX
*mem_ctx
, uint32_t rid
);
223 NTSTATUS
pdb_add_group_mapping_entry(GROUP_MAP
*map
);
224 NTSTATUS
pdb_update_group_mapping_entry(GROUP_MAP
*map
);
225 NTSTATUS
pdb_delete_group_mapping_entry(struct dom_sid sid
);
226 bool pdb_enum_group_mapping(const struct dom_sid
*sid
, enum lsa_SidType sid_name_use
, GROUP_MAP
**pp_rmap
,
227 size_t *p_num_entries
, bool unix_only
);
228 NTSTATUS
pdb_enum_group_members(TALLOC_CTX
*mem_ctx
,
229 const struct dom_sid
*sid
,
230 uint32_t **pp_member_rids
,
231 size_t *p_num_members
);
232 NTSTATUS
pdb_enum_group_memberships(TALLOC_CTX
*mem_ctx
, struct samu
*user
,
233 struct dom_sid
**pp_sids
, gid_t
**pp_gids
,
234 uint32_t *p_num_groups
);
235 NTSTATUS
pdb_set_unix_primary_group(TALLOC_CTX
*mem_ctx
, struct samu
*user
);
236 NTSTATUS
pdb_add_groupmem(TALLOC_CTX
*mem_ctx
, uint32_t group_rid
,
237 uint32_t member_rid
);
238 NTSTATUS
pdb_del_groupmem(TALLOC_CTX
*mem_ctx
, uint32_t group_rid
,
239 uint32_t member_rid
);
240 NTSTATUS
pdb_create_alias(const char *name
, uint32_t *rid
);
241 NTSTATUS
pdb_delete_alias(const struct dom_sid
*sid
);
242 NTSTATUS
pdb_get_aliasinfo(const struct dom_sid
*sid
, struct acct_info
*info
);
243 NTSTATUS
pdb_set_aliasinfo(const struct dom_sid
*sid
, struct acct_info
*info
);
244 NTSTATUS
pdb_add_aliasmem(const struct dom_sid
*alias
, const struct dom_sid
*member
);
245 NTSTATUS
pdb_del_aliasmem(const struct dom_sid
*alias
, const struct dom_sid
*member
);
246 NTSTATUS
pdb_enum_aliasmem(const struct dom_sid
*alias
, TALLOC_CTX
*mem_ctx
,
247 struct dom_sid
**pp_members
, size_t *p_num_members
);
248 NTSTATUS
pdb_enum_alias_memberships(TALLOC_CTX
*mem_ctx
,
249 const struct dom_sid
*domain_sid
,
250 const struct dom_sid
*members
, size_t num_members
,
251 uint32_t **pp_alias_rids
,
252 size_t *p_num_alias_rids
);
253 NTSTATUS
pdb_lookup_rids(const struct dom_sid
*domain_sid
,
257 enum lsa_SidType
*attrs
);
258 NTSTATUS
pdb_lookup_names(const struct dom_sid
*domain_sid
,
262 enum lsa_SidType
*attrs
);
263 bool pdb_get_account_policy(enum pdb_policy_type type
, uint32_t *value
);
264 bool pdb_set_account_policy(enum pdb_policy_type type
, uint32_t value
);
265 bool pdb_get_seq_num(time_t *seq_num
);
266 bool pdb_uid_to_sid(uid_t uid
, struct dom_sid
*sid
);
267 bool pdb_gid_to_sid(gid_t gid
, struct dom_sid
*sid
);
268 bool pdb_sid_to_id(const struct dom_sid
*sid
, union unid_t
*id
,
269 enum lsa_SidType
*type
);
270 uint32_t pdb_capabilities(void);
271 bool pdb_new_rid(uint32_t *rid
);
272 bool initialize_password_db(bool reload
, struct event_context
*event_ctx
);
273 struct pdb_search
*pdb_search_init(TALLOC_CTX
*mem_ctx
,
274 enum pdb_search_type type
);
275 struct pdb_search
*pdb_search_users(TALLOC_CTX
*mem_ctx
, uint32_t acct_flags
);
276 struct pdb_search
*pdb_search_groups(TALLOC_CTX
*mem_ctx
);
277 struct pdb_search
*pdb_search_aliases(TALLOC_CTX
*mem_ctx
, const struct dom_sid
*sid
);
278 uint32_t pdb_search_entries(struct pdb_search
*search
,
279 uint32_t start_idx
, uint32_t max_entries
,
280 struct samr_displayentry
**result
);
281 bool pdb_get_trusteddom_pw(const char *domain
, char** pwd
, struct dom_sid
*sid
,
282 time_t *pass_last_set_time
);
283 bool pdb_set_trusteddom_pw(const char* domain
, const char* pwd
,
284 const struct dom_sid
*sid
);
285 bool pdb_del_trusteddom_pw(const char *domain
);
286 NTSTATUS
pdb_enum_trusteddoms(TALLOC_CTX
*mem_ctx
, uint32_t *num_domains
,
287 struct trustdom_info
***domains
);
288 NTSTATUS
pdb_get_trusted_domain(TALLOC_CTX
*mem_ctx
, const char *domain
,
289 struct pdb_trusted_domain
**td
);
290 NTSTATUS
pdb_get_trusted_domain_by_sid(TALLOC_CTX
*mem_ctx
, struct dom_sid
*sid
,
291 struct pdb_trusted_domain
**td
);
292 NTSTATUS
pdb_set_trusted_domain(const char* domain
,
293 const struct pdb_trusted_domain
*td
);
294 NTSTATUS
pdb_del_trusted_domain(const char *domain
);
295 NTSTATUS
pdb_enum_trusted_domains(TALLOC_CTX
*mem_ctx
, uint32_t *num_domains
,
296 struct pdb_trusted_domain
***domains
);
297 NTSTATUS
make_pdb_method( struct pdb_methods
**methods
) ;
299 /* The following definitions come from passdb/pdb_ldap.c */
301 const char** get_userattr_list( TALLOC_CTX
*mem_ctx
, int schema_ver
);
302 NTSTATUS
pdb_init_ldapsam_compat(struct pdb_methods
**pdb_method
, const char *location
);
303 NTSTATUS
pdb_init_ldapsam(struct pdb_methods
**pdb_method
, const char *location
);
304 NTSTATUS
pdb_ldap_init(void);
306 /* The following definitions come from passdb/pdb_nds.c */
308 struct smbldap_state
;
310 int pdb_nds_get_password(
311 struct smbldap_state
*ldap_state
,
315 int pdb_nds_set_password(
316 struct smbldap_state
*ldap_state
,
319 NTSTATUS
pdb_nds_init(void);
321 /* The following definitions come from passdb/pdb_nds.c */
323 NTSTATUS
pdb_ipa_init(void);
325 /* The following definitions come from passdb/pdb_smbpasswd.c */
327 NTSTATUS
pdb_smbpasswd_init(void) ;
329 /* The following definitions come from passdb/pdb_wbc_sam.c */
331 NTSTATUS
pdb_wbc_sam_init(void);
333 /* The following definitions come from passdb/pdb_tdb.c */
335 NTSTATUS
pdb_tdbsam_init(void);
337 /* The following definitions come from passdb/pdb_util.c */
339 NTSTATUS
create_builtin_users(const struct dom_sid
*sid
);
340 NTSTATUS
create_builtin_administrators(const struct dom_sid
*sid
);
342 #endif /* _PASSDB_PROTO_H_ */