s3-passdb Make pdb_element_is_changed available to all passdb modules
[Samba.git] / source3 / passdb / proto.h
blob24a7cba8915041cb65046bea58f1bbaef847cf38
1 /*
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 pdb_methods *methods,
70 struct samu *user, const struct passwd *pwd);
71 char *pdb_encode_acct_ctrl(uint32_t acct_ctrl, size_t length);
72 uint32_t pdb_decode_acct_ctrl(const char *p);
73 void pdb_sethexpwd(char p[33], const unsigned char *pwd, uint32_t acct_ctrl);
74 bool pdb_gethexpwd(const char *p, unsigned char *pwd);
75 void pdb_sethexhours(char *p, const unsigned char *hours);
76 bool pdb_gethexhours(const char *p, unsigned char *hours);
77 int algorithmic_rid_base(void);
78 uid_t algorithmic_pdb_user_rid_to_uid(uint32_t user_rid);
79 uid_t max_algorithmic_uid(void);
80 uint32_t algorithmic_pdb_uid_to_user_rid(uid_t uid);
81 gid_t pdb_group_rid_to_gid(uint32_t group_rid);
82 gid_t max_algorithmic_gid(void);
83 uint32_t algorithmic_pdb_gid_to_group_rid(gid_t gid);
84 bool algorithmic_pdb_rid_is_user(uint32_t rid);
85 bool lookup_global_sam_name(const char *name, int flags, uint32_t *rid,
86 enum lsa_SidType *type);
87 NTSTATUS local_password_change(const char *user_name,
88 int local_flags,
89 const char *new_passwd,
90 char **pp_err_str,
91 char **pp_msg_str);
92 bool init_samu_from_buffer(struct samu *sampass, uint32_t level,
93 uint8_t *buf, uint32_t buflen);
94 uint32_t init_buffer_from_samu (uint8_t **buf, struct samu *sampass, bool size_only);
95 bool pdb_copy_sam_account(struct samu *dst, struct samu *src );
96 bool pdb_update_bad_password_count(struct samu *sampass, bool *updated);
97 bool pdb_update_autolock_flag(struct samu *sampass, bool *updated);
98 bool pdb_increment_bad_password_count(struct samu *sampass);
99 bool is_dc_trusted_domain_situation(const char *domain_name);
100 bool get_trust_pw_clear(const char *domain, char **ret_pwd,
101 const char **account_name,
102 enum netr_SchannelType *channel);
103 bool get_trust_pw_hash(const char *domain, uint8_t ret_pwd[16],
104 const char **account_name,
105 enum netr_SchannelType *channel);
107 /* The following definitions come from passdb/pdb_compat.c */
109 uint32_t pdb_get_user_rid (const struct samu *sampass);
110 uint32_t pdb_get_group_rid (struct samu *sampass);
111 bool pdb_set_user_sid_from_rid (struct samu *sampass, uint32_t rid, enum pdb_value_state flag);
112 bool pdb_set_group_sid_from_rid (struct samu *sampass, uint32_t grid, enum pdb_value_state flag);
114 /* The following definitions come from passdb/pdb_get_set.c */
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);
200 bool pdb_element_is_changed(const struct samu *sampass,
201 enum pdb_elements element);
202 bool pdb_element_is_set_or_changed(const struct samu *sampass,
203 enum pdb_elements element);
205 /* The following definitions come from passdb/pdb_interface.c */
207 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init) ;
208 struct pdb_init_function_entry *pdb_find_backend_entry(const char *name);
209 const struct pdb_init_function_entry *pdb_get_backends(void);
210 struct event_context *pdb_get_event_context(void);
211 NTSTATUS make_pdb_method_name(struct pdb_methods **methods, const char *selected);
212 struct pdb_domain_info *pdb_get_domain_info(TALLOC_CTX *mem_ctx);
213 bool pdb_getsampwnam(struct samu *sam_acct, const char *username) ;
214 bool pdb_getsampwsid(struct samu *sam_acct, const struct dom_sid *sid) ;
215 NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32_t flags,
216 uint32_t *rid);
217 NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct);
218 NTSTATUS pdb_add_sam_account(struct samu *sam_acct) ;
219 NTSTATUS pdb_update_sam_account(struct samu *sam_acct) ;
220 NTSTATUS pdb_delete_sam_account(struct samu *sam_acct) ;
221 NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname);
222 NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, bool success);
223 bool pdb_getgrsid(GROUP_MAP *map, struct dom_sid sid);
224 bool pdb_getgrgid(GROUP_MAP *map, gid_t gid);
225 bool pdb_getgrnam(GROUP_MAP *map, const char *name);
226 NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name,
227 uint32_t *rid);
228 NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32_t rid);
229 NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map);
230 NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map);
231 NTSTATUS pdb_delete_group_mapping_entry(struct dom_sid sid);
232 bool pdb_enum_group_mapping(const struct dom_sid *sid, enum lsa_SidType sid_name_use, GROUP_MAP **pp_rmap,
233 size_t *p_num_entries, bool unix_only);
234 NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
235 const struct dom_sid *sid,
236 uint32_t **pp_member_rids,
237 size_t *p_num_members);
238 NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user,
239 struct dom_sid **pp_sids, gid_t **pp_gids,
240 uint32_t *p_num_groups);
241 NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user);
242 NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
243 uint32_t member_rid);
244 NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32_t group_rid,
245 uint32_t member_rid);
246 NTSTATUS pdb_create_alias(const char *name, uint32_t *rid);
247 NTSTATUS pdb_delete_alias(const struct dom_sid *sid);
248 NTSTATUS pdb_get_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
249 NTSTATUS pdb_set_aliasinfo(const struct dom_sid *sid, struct acct_info *info);
250 NTSTATUS pdb_add_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
251 NTSTATUS pdb_del_aliasmem(const struct dom_sid *alias, const struct dom_sid *member);
252 NTSTATUS pdb_enum_aliasmem(const struct dom_sid *alias, TALLOC_CTX *mem_ctx,
253 struct dom_sid **pp_members, size_t *p_num_members);
254 NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
255 const struct dom_sid *domain_sid,
256 const struct dom_sid *members, size_t num_members,
257 uint32_t **pp_alias_rids,
258 size_t *p_num_alias_rids);
259 NTSTATUS pdb_lookup_rids(const struct dom_sid *domain_sid,
260 int num_rids,
261 uint32_t *rids,
262 const char **names,
263 enum lsa_SidType *attrs);
264 NTSTATUS pdb_lookup_names(const struct dom_sid *domain_sid,
265 int num_names,
266 const char **names,
267 uint32_t *rids,
268 enum lsa_SidType *attrs);
269 bool pdb_get_account_policy(enum pdb_policy_type type, uint32_t *value);
270 bool pdb_set_account_policy(enum pdb_policy_type type, uint32_t value);
271 bool pdb_get_seq_num(time_t *seq_num);
272 bool pdb_uid_to_sid(uid_t uid, struct dom_sid *sid);
273 bool pdb_gid_to_sid(gid_t gid, struct dom_sid *sid);
274 bool pdb_sid_to_id(const struct dom_sid *sid, union unid_t *id,
275 enum lsa_SidType *type);
276 uint32_t pdb_capabilities(void);
277 bool pdb_new_rid(uint32_t *rid);
278 bool initialize_password_db(bool reload, struct event_context *event_ctx);
279 struct pdb_search *pdb_search_init(TALLOC_CTX *mem_ctx,
280 enum pdb_search_type type);
281 struct pdb_search *pdb_search_users(TALLOC_CTX *mem_ctx, uint32_t acct_flags);
282 struct pdb_search *pdb_search_groups(TALLOC_CTX *mem_ctx);
283 struct pdb_search *pdb_search_aliases(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
284 uint32_t pdb_search_entries(struct pdb_search *search,
285 uint32_t start_idx, uint32_t max_entries,
286 struct samr_displayentry **result);
287 bool pdb_get_trusteddom_pw(const char *domain, char** pwd, struct dom_sid *sid,
288 time_t *pass_last_set_time);
289 bool pdb_set_trusteddom_pw(const char* domain, const char* pwd,
290 const struct dom_sid *sid);
291 bool pdb_del_trusteddom_pw(const char *domain);
292 NTSTATUS pdb_enum_trusteddoms(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
293 struct trustdom_info ***domains);
294 NTSTATUS pdb_get_trusted_domain(TALLOC_CTX *mem_ctx, const char *domain,
295 struct pdb_trusted_domain **td);
296 NTSTATUS pdb_get_trusted_domain_by_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid,
297 struct pdb_trusted_domain **td);
298 NTSTATUS pdb_set_trusted_domain(const char* domain,
299 const struct pdb_trusted_domain *td);
300 NTSTATUS pdb_del_trusted_domain(const char *domain);
301 NTSTATUS pdb_enum_trusted_domains(TALLOC_CTX *mem_ctx, uint32_t *num_domains,
302 struct pdb_trusted_domain ***domains);
303 NTSTATUS make_pdb_method( struct pdb_methods **methods ) ;
304 NTSTATUS pdb_get_secret(TALLOC_CTX *mem_ctx,
305 const char *secret_name,
306 DATA_BLOB *secret_current,
307 NTTIME *secret_current_lastchange,
308 DATA_BLOB *secret_old,
309 NTTIME *secret_old_lastchange,
310 struct security_descriptor **sd);
311 NTSTATUS pdb_set_secret(const char *secret_name,
312 DATA_BLOB *secret_current,
313 DATA_BLOB *secret_old,
314 struct security_descriptor *sd);
315 NTSTATUS pdb_delete_secret(const char *secret_name);
317 /* The following definitions come from passdb/pdb_ldap.c */
319 const char** get_userattr_list( TALLOC_CTX *mem_ctx, int schema_ver );
320 NTSTATUS pdb_init_ldapsam_compat(struct pdb_methods **pdb_method, const char *location);
321 NTSTATUS pdb_init_ldapsam(struct pdb_methods **pdb_method, const char *location);
322 NTSTATUS pdb_ldap_init(void);
324 /* The following definitions come from passdb/pdb_nds.c */
326 struct smbldap_state;
328 int pdb_nds_get_password(
329 struct smbldap_state *ldap_state,
330 char *object_dn,
331 size_t *pwd_len,
332 char *pwd );
333 int pdb_nds_set_password(
334 struct smbldap_state *ldap_state,
335 char *object_dn,
336 const char *pwd );
337 NTSTATUS pdb_nds_init(void);
339 /* The following definitions come from passdb/pdb_nds.c */
341 NTSTATUS pdb_ipa_init(void);
343 /* The following definitions come from passdb/pdb_smbpasswd.c */
345 NTSTATUS pdb_smbpasswd_init(void) ;
347 /* The following definitions come from passdb/pdb_wbc_sam.c */
349 NTSTATUS pdb_wbc_sam_init(void);
351 /* The following definitions come from passdb/pdb_tdb.c */
353 NTSTATUS pdb_tdbsam_init(void);
355 /* The following definitions come from passdb/pdb_util.c */
357 NTSTATUS create_builtin_users(const struct dom_sid *sid);
358 NTSTATUS create_builtin_administrators(const struct dom_sid *sid);
360 #endif /* _PASSDB_PROTO_H_ */