include/passdb.h

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    passdb structures and parameters
00004    Copyright (C) Gerald Carter 2001
00005    Copyright (C) Luke Kenneth Casson Leighton 1998 - 2000
00006    Copyright (C) Andrew Bartlett 2002
00007    Copyright (C) Simo Sorce 2003
00008    
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2 of the License, or
00012    (at your option) any later version.
00013    
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018    
00019    You should have received a copy of the GNU General Public License
00020    along with this program; if not, write to the Free Software
00021    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022 */
00023 
00024 #ifndef _PASSDB_H
00025 #define _PASSDB_H
00026 
00027 
00028 /*
00029  * fields_present flags meanings
00030  * same names as found in samba4 idl files
00031  */
00032 
00033 #define ACCT_USERNAME           0x00000001
00034 #define ACCT_FULL_NAME          0x00000002
00035 #define ACCT_RID                0x00000004
00036 #define ACCT_PRIMARY_GID        0x00000008
00037 #define ACCT_DESCRIPTION        0x00000010
00038 #define ACCT_COMMENT            0x00000020
00039 #define ACCT_HOME_DIR           0x00000040
00040 #define ACCT_HOME_DRIVE         0x00000080
00041 #define ACCT_LOGON_SCRIPT       0x00000100
00042 #define ACCT_PROFILE            0x00000200
00043 #define ACCT_WORKSTATIONS       0x00000400
00044 #define ACCT_LAST_LOGON         0x00000800
00045 #define ACCT_LAST_LOGOFF        0x00001000
00046 #define ACCT_LOGON_HOURS        0x00002000
00047 #define ACCT_BAD_PWD_COUNT      0x00004000
00048 #define ACCT_NUM_LOGONS         0x00008000
00049 #define ACCT_ALLOW_PWD_CHANGE   0x00010000
00050 #define ACCT_FORCE_PWD_CHANGE   0x00020000
00051 #define ACCT_LAST_PWD_CHANGE    0x00040000
00052 #define ACCT_EXPIRY             0x00080000
00053 #define ACCT_FLAGS              0x00100000
00054 #define ACCT_CALLBACK           0x00200000
00055 #define ACCT_COUNTRY_CODE       0x00400000
00056 #define ACCT_CODE_PAGE          0x00800000
00057 #define ACCT_NT_PWD_SET         0x01000000
00058 #define ACCT_LM_PWD_SET         0x02000000
00059 #define ACCT_PRIVATEDATA        0x04000000
00060 #define ACCT_EXPIRED_FLAG       0x08000000
00061 #define ACCT_SEC_DESC           0x10000000
00062 #define ACCT_OWF_PWD            0x20000000
00063 
00064 /*
00065  * bit flags representing initialized fields in struct samu
00066  */
00067 enum pdb_elements {
00068         PDB_UNINIT,
00069         PDB_SMBHOME,
00070         PDB_PROFILE,
00071         PDB_DRIVE,
00072         PDB_LOGONSCRIPT,
00073         PDB_LOGONTIME,
00074         PDB_LOGOFFTIME,
00075         PDB_KICKOFFTIME,
00076         PDB_BAD_PASSWORD_TIME,
00077         PDB_CANCHANGETIME,
00078         PDB_MUSTCHANGETIME,
00079         PDB_PLAINTEXT_PW,
00080         PDB_USERNAME,
00081         PDB_FULLNAME,
00082         PDB_DOMAIN,
00083         PDB_NTUSERNAME,
00084         PDB_HOURSLEN,
00085         PDB_LOGONDIVS,
00086         PDB_USERSID,
00087         PDB_GROUPSID,
00088         PDB_ACCTCTRL,
00089         PDB_PASSLASTSET,
00090         PDB_UNIXHOMEDIR,
00091         PDB_ACCTDESC,
00092         PDB_WORKSTATIONS,
00093         PDB_COMMENT,
00094         PDB_MUNGEDDIAL,
00095         PDB_HOURS,
00096         PDB_FIELDS_PRESENT,
00097         PDB_BAD_PASSWORD_COUNT,
00098         PDB_LOGON_COUNT,
00099         PDB_UNKNOWN6,
00100         PDB_LMPASSWD,
00101         PDB_NTPASSWD,
00102         PDB_PWHISTORY,
00103         PDB_BACKEND_PRIVATE_DATA,
00104 
00105         /* this must be the last element */
00106         PDB_COUNT
00107 };
00108 
00109 enum pdb_group_elements {
00110         PDB_GROUP_NAME,
00111         PDB_GROUP_SID,
00112         PDB_GROUP_SID_NAME_USE,
00113         PDB_GROUP_MEMBERS,
00114 
00115         /* this must be the last element */
00116         PDB_GROUP_COUNT
00117 };
00118 
00119 
00120 enum pdb_value_state {
00121         PDB_DEFAULT=0,
00122         PDB_SET,
00123         PDB_CHANGED
00124 };
00125 
00126 #define IS_SAM_SET(x, flag)     (pdb_get_init_flags(x, flag) == PDB_SET)
00127 #define IS_SAM_CHANGED(x, flag) (pdb_get_init_flags(x, flag) == PDB_CHANGED)
00128 #define IS_SAM_DEFAULT(x, flag) (pdb_get_init_flags(x, flag) == PDB_DEFAULT)
00129 
00130 /* cache for bad password lockout data, to be used on replicated SAMs */
00131 typedef struct logon_cache_struct {
00132         time_t entry_timestamp;
00133         uint32 acct_ctrl;
00134         uint16 bad_password_count;
00135         time_t bad_password_time;
00136 } LOGIN_CACHE;
00137                 
00138 struct samu {
00139         struct pdb_methods *methods;
00140 
00141         /* initialization flags */
00142         struct bitmap *change_flags;
00143         struct bitmap *set_flags;
00144 
00145         time_t logon_time;            /* logon time */
00146         time_t logoff_time;           /* logoff time */
00147         time_t kickoff_time;          /* kickoff time */
00148         time_t bad_password_time;     /* last bad password entered */
00149         time_t pass_last_set_time;    /* password last set time */
00150         time_t pass_can_change_time;  /* password can change time */
00151         time_t pass_must_change_time; /* password must change time */
00152                 
00153         const char *username;     /* UNIX username string */
00154         const char *domain;       /* Windows Domain name */
00155         const char *nt_username;  /* Windows username string */
00156         const char *full_name;    /* user's full name string */
00157         const char *home_dir;     /* home directory string */
00158         const char *dir_drive;    /* home directory drive string */
00159         const char *logon_script; /* logon script string */
00160         const char *profile_path; /* profile path string */
00161         const char *acct_desc;    /* user description string */
00162         const char *workstations; /* login from workstations string */
00163         const char *comment;
00164         const char *munged_dial;  /* munged path name and dial-back tel number */
00165                 
00166         DOM_SID user_sid;  
00167         DOM_SID *group_sid;
00168                 
00169         DATA_BLOB lm_pw; /* .data is Null if no password */
00170         DATA_BLOB nt_pw; /* .data is Null if no password */
00171         DATA_BLOB nt_pw_his; /* nt hashed password history .data is Null if not available */
00172         char* plaintext_pw; /* is Null if not available */
00173                 
00174         uint32 acct_ctrl; /* account info (ACB_xxxx bit-mask) */
00175         uint32 fields_present; /* 0x00ff ffff */
00176                 
00177         uint16 logon_divs; /* 168 - number of hours in a week */
00178         uint32 hours_len; /* normally 21 bytes */
00179         uint8 hours[MAX_HOURS_LEN];
00180         
00181         /* Was unknown_5. */
00182         uint16 bad_password_count;
00183         uint16 logon_count;
00184 
00185         uint32 unknown_6; /* 0x0000 04ec */
00186 
00187         /* a tag for who added the private methods */
00188 
00189         const struct pdb_methods *backend_private_methods;
00190         void *backend_private_data; 
00191         void (*backend_private_data_free_fn)(void **);
00192         
00193         /* maintain a copy of the user's struct passwd */
00194 
00195         struct passwd *unix_pw;
00196 };
00197 
00198 struct acct_info {
00199         fstring acct_name; /* account name */
00200         fstring acct_desc; /* account name */
00201         uint32 rid; /* domain-relative RID */
00202 };
00203 
00204 struct samr_displayentry {
00205         uint32 idx;
00206         uint32 rid;
00207         uint32 acct_flags;
00208         const char *account_name;
00209         const char *fullname;
00210         const char *description;
00211 };
00212 
00213 enum pdb_search_type {
00214         PDB_USER_SEARCH,
00215         PDB_GROUP_SEARCH,
00216         PDB_ALIAS_SEARCH
00217 };
00218 
00219 struct pdb_search {
00220         TALLOC_CTX *mem_ctx;
00221         enum pdb_search_type type;
00222         struct samr_displayentry *cache;
00223         uint32 num_entries;
00224         ssize_t cache_size;
00225         BOOL search_ended;
00226         void *private_data;
00227         BOOL (*next_entry)(struct pdb_search *search,
00228                            struct samr_displayentry *entry);
00229         void (*search_end)(struct pdb_search *search);
00230 };
00231 
00232 /*****************************************************************
00233  Functions to be implemented by the new (v2) passdb API 
00234 ****************************************************************/
00235 
00236 /*
00237  * This next constant specifies the version number of the PASSDB interface
00238  * this SAMBA will load. Increment this if *ANY* changes are made to the interface. 
00239  * Changed interface to fix int -> size_t problems. JRA.
00240  * There's no point in allocating arrays in
00241  * samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in
00242  * the pdb module. Remove the latter, this might happen more often. VL.
00243  * changed to version 14 to move lookup_rids and lookup_names to return
00244  * enum lsa_SidType rather than uint32.
00245  */
00246 
00247 #define PASSDB_INTERFACE_VERSION 15
00248 
00249 struct pdb_methods 
00250 {
00251         const char *name; /* What name got this module */
00252 
00253         NTSTATUS (*setsampwent)(struct pdb_methods *, BOOL update, uint32 acb_mask);
00254         
00255         void (*endsampwent)(struct pdb_methods *);
00256         
00257         NTSTATUS (*getsampwent)(struct pdb_methods *, struct samu *user);
00258         
00259         NTSTATUS (*getsampwnam)(struct pdb_methods *, struct samu *sam_acct, const char *username);
00260         
00261         NTSTATUS (*getsampwsid)(struct pdb_methods *, struct samu *sam_acct, const DOM_SID *sid);
00262 
00263         NTSTATUS (*create_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
00264                                 const char *name, uint32 acct_flags,
00265                                 uint32 *rid);
00266 
00267         NTSTATUS (*delete_user)(struct pdb_methods *, TALLOC_CTX *tmp_ctx,
00268                                 struct samu *sam_acct);
00269         
00270         NTSTATUS (*add_sam_account)(struct pdb_methods *, struct samu *sampass);
00271         
00272         NTSTATUS (*update_sam_account)(struct pdb_methods *, struct samu *sampass);
00273         
00274         NTSTATUS (*delete_sam_account)(struct pdb_methods *, struct samu *username);
00275         
00276         NTSTATUS (*rename_sam_account)(struct pdb_methods *, struct samu *oldname, const char *newname);
00277         
00278         NTSTATUS (*update_login_attempts)(struct pdb_methods *methods, struct samu *sam_acct, BOOL success);
00279 
00280         NTSTATUS (*getgrsid)(struct pdb_methods *methods, GROUP_MAP *map, DOM_SID sid);
00281 
00282         NTSTATUS (*getgrgid)(struct pdb_methods *methods, GROUP_MAP *map, gid_t gid);
00283 
00284         NTSTATUS (*getgrnam)(struct pdb_methods *methods, GROUP_MAP *map, const char *name);
00285 
00286         NTSTATUS (*create_dom_group)(struct pdb_methods *methods,
00287                                      TALLOC_CTX *mem_ctx, const char *name,
00288                                      uint32 *rid);
00289 
00290         NTSTATUS (*delete_dom_group)(struct pdb_methods *methods,
00291                                      TALLOC_CTX *mem_ctx, uint32 rid);
00292 
00293         NTSTATUS (*add_group_mapping_entry)(struct pdb_methods *methods,
00294                                             GROUP_MAP *map);
00295 
00296         NTSTATUS (*update_group_mapping_entry)(struct pdb_methods *methods,
00297                                                GROUP_MAP *map);
00298 
00299         NTSTATUS (*delete_group_mapping_entry)(struct pdb_methods *methods,
00300                                                DOM_SID sid);
00301 
00302         NTSTATUS (*enum_group_mapping)(struct pdb_methods *methods,
00303                                        const DOM_SID *sid, enum lsa_SidType sid_name_use,
00304                                        GROUP_MAP **pp_rmap, size_t *p_num_entries,
00305                                        BOOL unix_only);
00306 
00307         NTSTATUS (*enum_group_members)(struct pdb_methods *methods,
00308                                        TALLOC_CTX *mem_ctx,
00309                                        const DOM_SID *group,
00310                                        uint32 **pp_member_rids,
00311                                        size_t *p_num_members);
00312 
00313         NTSTATUS (*enum_group_memberships)(struct pdb_methods *methods,
00314                                            TALLOC_CTX *mem_ctx,
00315                                            struct samu *user,
00316                                            DOM_SID **pp_sids, gid_t **pp_gids,
00317                                            size_t *p_num_groups);
00318 
00319         NTSTATUS (*set_unix_primary_group)(struct pdb_methods *methods,
00320                                            TALLOC_CTX *mem_ctx,
00321                                            struct samu *user);
00322 
00323         NTSTATUS (*add_groupmem)(struct pdb_methods *methods,
00324                                  TALLOC_CTX *mem_ctx,
00325                                  uint32 group_rid, uint32 member_rid);
00326 
00327         NTSTATUS (*del_groupmem)(struct pdb_methods *methods,
00328                                  TALLOC_CTX *mem_ctx,
00329                                  uint32 group_rid, uint32 member_rid);
00330 
00331         NTSTATUS (*find_alias)(struct pdb_methods *methods,
00332                                const char *name, DOM_SID *sid);
00333 
00334         NTSTATUS (*create_alias)(struct pdb_methods *methods,
00335                                  const char *name, uint32 *rid);
00336 
00337         NTSTATUS (*delete_alias)(struct pdb_methods *methods,
00338                                  const DOM_SID *sid);
00339 
00340         NTSTATUS (*get_aliasinfo)(struct pdb_methods *methods,
00341                                   const DOM_SID *sid,
00342                                   struct acct_info *info);
00343 
00344         NTSTATUS (*set_aliasinfo)(struct pdb_methods *methods,
00345                                   const DOM_SID *sid,
00346                                   struct acct_info *info);
00347 
00348         NTSTATUS (*add_aliasmem)(struct pdb_methods *methods,
00349                                  const DOM_SID *alias, const DOM_SID *member);
00350         NTSTATUS (*del_aliasmem)(struct pdb_methods *methods,
00351                                  const DOM_SID *alias, const DOM_SID *member);
00352         NTSTATUS (*enum_aliasmem)(struct pdb_methods *methods,
00353                                   const DOM_SID *alias, DOM_SID **members,
00354                                   size_t *p_num_members);
00355         NTSTATUS (*enum_alias_memberships)(struct pdb_methods *methods,
00356                                            TALLOC_CTX *mem_ctx,
00357                                            const DOM_SID *domain_sid,
00358                                            const DOM_SID *members,
00359                                            size_t num_members,
00360                                            uint32 **pp_alias_rids,
00361                                            size_t *p_num_alias_rids);
00362 
00363         NTSTATUS (*lookup_rids)(struct pdb_methods *methods,
00364                                 const DOM_SID *domain_sid,
00365                                 int num_rids,
00366                                 uint32 *rids,
00367                                 const char **pp_names,
00368                                 enum lsa_SidType *attrs);
00369 
00370         NTSTATUS (*lookup_names)(struct pdb_methods *methods,
00371                                  const DOM_SID *domain_sid,
00372                                  int num_names,
00373                                  const char **pp_names,
00374                                  uint32 *rids,
00375                                  enum lsa_SidType *attrs);
00376 
00377         NTSTATUS (*get_account_policy)(struct pdb_methods *methods,
00378                                        int policy_index, uint32 *value);
00379 
00380         NTSTATUS (*set_account_policy)(struct pdb_methods *methods,
00381                                        int policy_index, uint32 value);
00382 
00383         NTSTATUS (*get_seq_num)(struct pdb_methods *methods, time_t *seq_num);
00384 
00385         BOOL (*search_users)(struct pdb_methods *methods,
00386                              struct pdb_search *search,
00387                              uint32 acct_flags);
00388         BOOL (*search_groups)(struct pdb_methods *methods,
00389                               struct pdb_search *search);
00390         BOOL (*search_aliases)(struct pdb_methods *methods,
00391                                struct pdb_search *search,
00392                                const DOM_SID *sid);
00393 
00394         BOOL (*uid_to_rid)(struct pdb_methods *methods, uid_t uid,
00395                            uint32 *rid);
00396         BOOL (*uid_to_sid)(struct pdb_methods *methods, uid_t uid,
00397                            DOM_SID *sid);
00398         BOOL (*gid_to_sid)(struct pdb_methods *methods, gid_t gid,
00399                            DOM_SID *sid);
00400         BOOL (*sid_to_id)(struct pdb_methods *methods, const DOM_SID *sid,
00401                           union unid_t *id, enum lsa_SidType *type);
00402 
00403         BOOL (*rid_algorithm)(struct pdb_methods *methods);
00404         BOOL (*new_rid)(struct pdb_methods *methods, uint32 *rid);
00405 
00406         void *private_data;  /* Private data of some kind */
00407         
00408         void (*free_private_data)(void **);
00409 };
00410 
00411 typedef NTSTATUS (*pdb_init_function)(struct pdb_methods **, const char *);
00412 
00413 struct pdb_init_function_entry {
00414         const char *name;
00415 
00416         /* Function to create a member of the pdb_methods list */
00417         pdb_init_function init;
00418 
00419         struct pdb_init_function_entry *prev, *next;
00420 };
00421 
00422 #endif /* _PASSDB_H */

Sambaに対してSat Aug 29 21:22:54 2009に生成されました。  doxygen 1.4.7