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