diff options
author | Jeremy Allison <jra@samba.org> | 1998-05-18 23:57:28 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 1998-05-18 23:57:28 +0000 |
commit | 118827376f8ccedb455e81b7d2b3bff029cde457 (patch) | |
tree | 2d30e099e7d04926af763ec530cdbd281ce6fafd /source3 | |
parent | ffab54750f0eec202895670dd9293ee4aa3eb475 (diff) | |
download | samba-118827376f8ccedb455e81b7d2b3bff029cde457.tar.gz samba-118827376f8ccedb455e81b7d2b3bff029cde457.tar.bz2 samba-118827376f8ccedb455e81b7d2b3bff029cde457.zip |
Abstracted all the crappy password interfaces through an indirect
function table, selectable at compile time. This should make the
code that implements all the password functions much cleaner, as
it's now very clear exactly what a particular password database
needs to provide to Samba.
Jeremy.
(This used to be commit 27ca536ad974242524c12f7100e419d9e7f9647f)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 34 | ||||
-rw-r--r-- | source3/include/smb.h | 38 | ||||
-rw-r--r-- | source3/passdb/ldap.c | 71 | ||||
-rw-r--r-- | source3/passdb/nispass.c | 69 | ||||
-rw-r--r-- | source3/passdb/passdb.c | 353 | ||||
-rw-r--r-- | source3/passdb/smbpass.c | 74 | ||||
-rw-r--r-- | source3/smbd/server.c | 3 | ||||
-rw-r--r-- | source3/utils/smbpasswd.c | 6 |
8 files changed, 328 insertions, 320 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index aea8543271..8207aa8adc 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -225,16 +225,7 @@ void initialize_multibyte_vectors( int client_codepage); /*The following definitions come from ldap.c */ -BOOL add_ldappwd_entry(struct smb_passwd *newpwd); -BOOL mod_ldappwd_entry(struct smb_passwd *pwd, BOOL override); -BOOL add_ldap21pwd_entry(struct sam_passwd *newpwd); -BOOL mod_ldap21pwd_entry(struct sam_passwd *pwd, BOOL override); -void *startldappwent(BOOL update); -struct smb_passwd *getldappwent(void *vp); -struct sam_passwd *getldap21pwent(void *vp); -void endldappwent(void *vp); -unsigned long getldappwpos(void *vp); -BOOL setldappwpos(void *vp, unsigned long tok); +struct passdb_ops *ldap_initialize_password_db(void); /*The following definitions come from lib/rpc/client/cli_login.c */ @@ -1213,15 +1204,7 @@ BOOL resolve_name(char *name, struct in_addr *return_ip); /*The following definitions come from nisppass.c */ -void *startnisppwent(BOOL update); -void endnisppwent(void *vp); -struct sam_passwd *getnisp21pwent(void *vp); -unsigned long getnisppwpos(void *vp); -BOOL setnisppwpos(void *vp, unsigned long tok); -BOOL add_nisp21pwd_entry(struct sam_passwd *newpwd); -BOOL mod_nisp21pwd_entry(struct sam_passwd* pwd, BOOL override); -struct sam_passwd *getnisp21pwnam(char *name); -struct sam_passwd *getnisp21pwuid(int smb_userid); +struct passdb_ops *nisplus_initialize_password_db(void); /*The following definitions come from nmbd.c */ @@ -1572,6 +1555,9 @@ BOOL pm_process( char *FileName, /*The following definitions come from passdb.c */ +struct smb_passwd *iterate_getsmbpwuid(uid_t smb_userid); +struct smb_passwd *iterate_getsmbpwnam(char *name); +BOOL initialize_password_db(void); void *startsmbpwent(BOOL update); void endsmbpwent(void *vp); struct smb_passwd *getsmbpwent(void *vp); @@ -1581,6 +1567,8 @@ BOOL add_smbpwd_entry(struct smb_passwd *newpwd); BOOL mod_smbpwd_entry(struct smb_passwd* pwd, BOOL override); struct smb_passwd *getsmbpwnam(char *name); struct smb_passwd *getsmbpwuid(uid_t smb_userid); +struct sam_passwd *iterate_getsam21pwnam(char *name); +struct sam_passwd *iterate_getsam21pwuid(uint32 uid); struct sam_disp_info *getsamdispent(void *vp); struct sam_passwd *getsam21pwent(void *vp); BOOL add_sam21pwd_entry(struct sam_passwd *newpwd); @@ -1830,16 +1818,10 @@ char *smb_errstr(char *inbuf); /*The following definitions come from smbpass.c */ -void *startsmbfilepwent(BOOL update); -void endsmbfilepwent(void *vp); -struct sam_passwd *getsmbfile21pwent(void *vp); struct smb_passwd *getsmbfilepwent(void *vp); -unsigned long getsmbfilepwpos(void *vp); -BOOL setsmbfilepwpos(void *vp, unsigned long tok); -BOOL add_smbfile21pwd_entry(struct sam_passwd *newpwd); -BOOL add_smbfilepwd_entry(struct smb_passwd *newpwd); BOOL mod_smbfile21pwd_entry(struct sam_passwd* pwd, BOOL override); BOOL mod_smbfilepwd_entry(struct smb_passwd* pwd, BOOL override); +struct passdb_ops *file_initialize_password_db(void); /*The following definitions come from smbpassfile.c */ diff --git a/source3/include/smb.h b/source3/include/smb.h index c90f77a593..fff44f179d 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -332,7 +332,6 @@ struct sam_disp_info char *full_name; /* user's full name string */ }; - /* DOM_CHAL - challenge info */ typedef struct chal_info { @@ -635,8 +634,45 @@ struct shmem_ops { unsigned (*hash_size)(void); }; +/* + * Each implementation of the password database code needs + * to support the following operations. + */ + +struct passdb_ops { + /* + * Password database ops. + */ + void *(*startsmbpwent)(BOOL); + void (*endsmbpwent)(void *); + unsigned long (*getsmbpwpos)(void *); + BOOL (*setsmbpwpos)(void *, unsigned long); + /* + * smb password database query functions. + */ + struct smb_passwd *(*getsmbpwnam)(char *); + struct smb_passwd *(*getsmbpwuid)(uid_t); + struct smb_passwd *(*getsmbpwent)(void *); + /* + * smb password database modification functions. + */ + BOOL (*add_smbpwd_entry)(struct smb_passwd *); + BOOL (*mod_smbpwd_entry)(struct smb_passwd *, BOOL); + + /* + * Functions that manupulate a struct sam_passwd. + */ + struct sam_passwd *(*getsam21pwent)(void *); + + struct sam_passwd *(*getsam21pwnam)(char *); + struct sam_passwd *(*getsam21pwuid)(uint32); + + BOOL (*add_sam21pwd_entry)(struct sam_passwd *); + BOOL (*mod_sam21pwd_entry)(struct sam_passwd *, BOOL); +}; /* this is used for smbstatus */ + struct connect_record { int magic; diff --git a/source3/passdb/ldap.c b/source3/passdb/ldap.c index 912aa8e5f9..de1e3cc9ab 100644 --- a/source3/passdb/ldap.c +++ b/source3/passdb/ldap.c @@ -725,7 +725,7 @@ static BOOL modadd_ldap21pwd_entry(struct sam_passwd *newpwd, int flag) do not call this function directly. use passdb.c instead. *************************************************************************/ -BOOL add_ldappwd_entry(struct smb_passwd *newpwd) +static BOOL add_ldappwd_entry(struct smb_passwd *newpwd) { return (modadd_ldappwd_entry(newpwd, ADD_USER) ); } @@ -741,7 +741,7 @@ BOOL add_ldappwd_entry(struct smb_passwd *newpwd) do not call this function directly. use passdb.c instead. ************************************************************************/ -BOOL mod_ldappwd_entry(struct smb_passwd *pwd, BOOL override) +static BOOL mod_ldappwd_entry(struct smb_passwd *pwd, BOOL override) { return (modadd_ldappwd_entry(pwd, MODIFY_USER) ); } @@ -752,7 +752,7 @@ BOOL mod_ldappwd_entry(struct smb_passwd *pwd, BOOL override) do not call this function directly. use passdb.c instead. *************************************************************************/ -BOOL add_ldap21pwd_entry(struct sam_passwd *newpwd) +static BOOL add_ldap21pwd_entry(struct sam_passwd *newpwd) { return( modadd_ldappwd_entry(newpwd, ADD_USER)? modadd_ldap21pwd_entry(newpwd, ADD_USER):False); @@ -769,7 +769,7 @@ BOOL add_ldap21pwd_entry(struct sam_passwd *newpwd) do not call this function directly. use passdb.c instead. ************************************************************************/ -BOOL mod_ldap21pwd_entry(struct sam_passwd *pwd, BOOL override) +static BOOL mod_ldap21pwd_entry(struct sam_passwd *pwd, BOOL override) { return( modadd_ldappwd_entry(pwd, MODIFY_USER)? modadd_ldap21pwd_entry(pwd, MODIFY_USER):False); @@ -791,7 +791,7 @@ static struct ldap_enum_info ldap_ent; do not call this function directly. use passdb.c instead. ****************************************************************/ -void *startldappwent(BOOL update) +static void *startldappwent(BOOL update) { int scope = LDAP_SCOPE_ONELEVEL; int rc; @@ -843,7 +843,7 @@ void *startldappwent(BOOL update) do not call this function directly. use passdb.c instead. *************************************************************************/ -struct smb_passwd *getldappwent(void *vp) +static struct smb_passwd *getldappwent(void *vp) { static struct smb_passwd user; struct ldap_enum_info *ldap_vp = (struct ldap_enum_info *)vp; @@ -864,7 +864,7 @@ struct smb_passwd *getldappwent(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -struct sam_passwd *getldap21pwent(void *vp) +static struct sam_passwd *getldap21pwent(void *vp) { static struct sam_passwd user; struct ldap_enum_info *ldap_vp = (struct ldap_enum_info *)vp; @@ -885,7 +885,7 @@ struct sam_passwd *getldap21pwent(void *vp) do not call this function directly. use passdb.c instead. ****************************************************************/ -void endldappwent(void *vp) +static void endldappwent(void *vp) { struct ldap_enum_info *ldap_vp = (struct ldap_enum_info *)vp; ldap_msgfree(ldap_vp->result); @@ -899,7 +899,7 @@ void endldappwent(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -unsigned long getldappwpos(void *vp) +static unsigned long getldappwpos(void *vp) { return 0; } @@ -911,11 +911,62 @@ unsigned long getldappwpos(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -BOOL setldappwpos(void *vp, unsigned long tok) +static BOOL setldappwpos(void *vp, unsigned long tok) { return False; } +/* + * Ldap derived functions. + */ + +static struct smb_passwd *getldappwnam(char *name) +{ + return pdb_sam_to_smb(iterate_getsam21pwnam(name)); +} + +static struct smb_passwd *getldappwuid(uid_t smb_userid) +{ + return pdb_sam_to_smb(iterate_getsam21pwuid(smb_userid)); +} + +static struct smb_passwd *getldappwent(void *vp) +{ + return pdb_sam_to_smb(getldap21pwent(vp)); +} + +static BOOL add_ldappwd_entry(struct smb_passwd *newpwd) +{ + return add_ldap21pwd_entry(pdb_smb_to_sam(newpwd)); +} + +static BOOL mod_ldappwd_entry(struct smb_passwd* pwd, BOOL override) +{ + return mod_ldap21pwd_entry(pdb_smb_to_sam(pwd), override); +} + +static struct passdb_ops ldap_ops = { + startldappwent, + endldappwent, + getldappwpos, + setldappwpos, + getldappwnam, + getldappwuid, + getldappwent, + add_ldappwd_entry, + mod_ldappwd_entry, + getldap21pwent, + iterate_getsam21pwnam, /* From passdb.c */ + iterate_getsam21pwuid, /* From passdb.c */ + add_ldap21pwd_entry, + mod_ldap21pwd_entry +}; + +struct passdb_ops *ldap_initialize_password_db(void) +{ + return &ldap_ops; +} + #else void dummy_function(void) { } /* stop some compilers complaining */ #endif diff --git a/source3/passdb/nispass.c b/source3/passdb/nispass.c index 9ae6ba3c52..436fbc0e91 100644 --- a/source3/passdb/nispass.c +++ b/source3/passdb/nispass.c @@ -140,7 +140,7 @@ static char *make_nisname_from_name(char *user_name) do not call this function directly. use passdb.c instead. ****************************************************************/ -void *startnisppwent(BOOL update) +static void *startnisppwent(BOOL update) { return NULL; } @@ -148,7 +148,7 @@ void *startnisppwent(BOOL update) /*************************************************************** End enumeration of the nisplus passwd list. ****************************************************************/ -void endnisppwent(void *vp) +static void endnisppwent(void *vp) { } @@ -162,7 +162,7 @@ void endnisppwent(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -struct sam_passwd *getnisp21pwent(void *vp) +static struct sam_passwd *getnisp21pwent(void *vp) { return NULL; } @@ -174,7 +174,7 @@ struct sam_passwd *getnisp21pwent(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -unsigned long getnisppwpos(void *vp) +static unsigned long getnisppwpos(void *vp) { return 0; } @@ -186,7 +186,7 @@ unsigned long getnisppwpos(void *vp) do not call this function directly. use passdb.c instead. *************************************************************************/ -BOOL setnisppwpos(void *vp, unsigned long tok) +static BOOL setnisppwpos(void *vp, unsigned long tok) { return False; } @@ -197,7 +197,7 @@ BOOL setnisppwpos(void *vp, unsigned long tok) do not call this function directly. use passdb.c instead. *************************************************************************/ -BOOL add_nisp21pwd_entry(struct sam_passwd *newpwd) +static BOOL add_nisp21pwd_entry(struct sam_passwd *newpwd) { /* Static buffers we will return. */ static pstring user_name; @@ -347,7 +347,7 @@ BOOL add_nisp21pwd_entry(struct sam_passwd *newpwd) do not call this function directly. use passdb.c instead. ************************************************************************/ -BOOL mod_nisp21pwd_entry(struct sam_passwd* pwd, BOOL override) +static BOOL mod_nisp21pwd_entry(struct sam_passwd* pwd, BOOL override) { return False; } @@ -420,7 +420,7 @@ static BOOL make_sam_from_nisp(struct sam_passwd *pw_buf, nis_result *result) /************************************************************************* Routine to search the nisplus passwd file for an entry matching the username *************************************************************************/ -struct sam_passwd *getnisp21pwnam(char *name) +static struct sam_passwd *getnisp21pwnam(char *name) { /* Static buffers we will return. */ static struct sam_passwd pw_buf; @@ -465,7 +465,7 @@ struct sam_passwd *getnisp21pwnam(char *name) /************************************************************************* Routine to search the nisplus passwd file for an entry matching the username *************************************************************************/ -struct sam_passwd *getnisp21pwuid(int smb_userid) +static struct sam_passwd *getnisp21pwuid(int smb_userid) { /* Static buffers we will return. */ static struct sam_passwd pw_buf; @@ -507,6 +507,57 @@ struct sam_passwd *getnisp21pwuid(int smb_userid) return ret ? &pw_buf : NULL; } +/* + * Derived functions for NIS+. + */ + +static struct smb_passwd *getnispwnam(char *name) +{ + return pdb_sam_to_smb(iterate_getsam21pwnam(name)); +} + +static struct smb_passwd *getnispwuid(uid_t smb_userid) +{ + return pdb_sam_to_smb(iterate_getsam21pwuid(smb_userid)); +} + +static struct smb_passwd *getnispwent(void *vp) +{ + return pdb_sam_to_smb(getnisp21pwent(vp)); +} + +static BOOL add_nispwd_entry(struct smb_passwd *newpwd) +{ + return add_nisp21pwd_entry(pdb_smb_to_sam(newpwd)); +} + +static BOOL mod_nispwd_entry(struct smb_passwd* pwd, BOOL override) +{ + return mod_nisp21pwd_entry(pdb_smb_to_sam(pwd), override); +} + +static struct passdb_ops nispasswd_ops = { + startnisppwent, + endnisppwent, + getnisppwpos, + setnisppwpos, + getnispwnam, + getsmbpwuid, + getnispwent, + add_nispwd_entry, + mod_nispwd_entry, + getnisp21pwent, + iterate_getsam21pwnam, /* Found in passdb.c */ + iterate_getsam21pwuid, /* Found in passdb.c */ + add_nisp21pwd_entry, + mod_nisp21pwd_entry +}; + +struct passdb_ops *nisplus_initialize_password_db(void) +{ + return &nispasswd_ops; +} + #else void nisplus_dummy_function(void) { } /* stop some compilers complaining */ #endif /* USE_NISPLUS_DB */ diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 90cb9d4de9..acc8d1c609 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -33,32 +33,34 @@ extern int DEBUGLEVEL; DOM_SID global_machine_sid; /* - * TODO NOTE. All these functions will be abstracted into a structure + * NOTE. All these functions are abstracted into a structure * that points to the correct function for the selected database. JRA. */ +static struct passdb_ops *pdb_ops; + /* * Functions that return/manipulate a struct smb_passwd. */ /************************************************************************ - Routine to search smb passwd by uid. use this if your database + Utility function to search smb passwd by uid. use this if your database does not have search facilities. *************************************************************************/ -static struct smb_passwd *_getsmbpwuid(uid_t smb_userid) +struct smb_passwd *iterate_getsmbpwuid(uid_t smb_userid) { struct smb_passwd *pwd = NULL; void *fp = NULL; - DEBUG(10, ("getsmbpwuid: search by smb_userid: %x\n", smb_userid)); + DEBUG(10, ("iterate_getsmbpwuid: search by smb_userid: %x\n", smb_userid)); /* Open the smb password database - not for update. */ fp = startsmbpwent(False); if (fp == NULL) { - DEBUG(0, ("getsmbpwuid: unable to open smb password database.\n")); + DEBUG(0, ("iterate_getsmbpwuid: unable to open smb password database.\n")); return NULL; } @@ -67,7 +69,7 @@ static struct smb_passwd *_getsmbpwuid(uid_t smb_userid) if (pwd != NULL) { - DEBUG(10, ("getsmbpwuid: found by smb_userid: %x\n", smb_userid)); + DEBUG(10, ("iterate_getsmbpwuid: found by smb_userid: %x\n", smb_userid)); } endsmbpwent(fp); @@ -75,23 +77,23 @@ static struct smb_passwd *_getsmbpwuid(uid_t smb_userid) } /************************************************************************ - Routine to search smb passwd by name. use this if your database + Utility function to search smb passwd by name. use this if your database does not have search facilities. *************************************************************************/ -static struct smb_passwd *_getsmbpwnam(char *name) +struct smb_passwd *iterate_getsmbpwnam(char *name) { struct smb_passwd *pwd = NULL; void *fp = NULL; - DEBUG(10, ("getsmbpwnam: search by name: %s\n", name)); + DEBUG(10, ("iterate_getsmbpwnam: search by name: %s\n", name)); /* Open the sam password file - not for update. */ fp = startsmbpwent(False); if (fp == NULL) { - DEBUG(0, ("_getsmbpwnam: unable to open smb password database.\n")); + DEBUG(0, ("iterate_getsmbpwnam: unable to open smb password database.\n")); return NULL; } @@ -100,7 +102,7 @@ static struct smb_passwd *_getsmbpwnam(char *name) if (pwd != NULL) { - DEBUG(10, ("_getsmbpwnam: found by name: %s\n", name)); + DEBUG(10, ("iterate_getsmbpwnam: found by name: %s\n", name)); } endsmbpwent(fp); @@ -108,6 +110,30 @@ static struct smb_passwd *_getsmbpwnam(char *name) } /*************************************************************** + Initialize the password db operations. +***************************************************************/ + +BOOL initialize_password_db(void) +{ + if(pdb_ops) + return True; + +#ifdef USE_NISPLUS_DB + pdb_ops = nisplus_initialize_password_db(); +#endif /* USE_NISPLUS_DB */ + +#ifdef USE_LDAP_DB + pdb_ops = ldap_initialize_password_db(); +#endif /* USE_LDAP_DB */ + +#ifdef USE_SMBPASS_DB + pdb_ops = file_initialize_password_db(); +#endif /* USE_SMBPASS_DB */ + + return (pdb_ops != NULL); +} + +/*************************************************************** Start to enumerate the smb or sam passwd list. Returns a void pointer to ensure no modification outside this module. @@ -119,17 +145,7 @@ static struct smb_passwd *_getsmbpwnam(char *name) void *startsmbpwent(BOOL update) { -#ifdef USE_NISPLUS_DB - return startnisppwent(update); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return startldappwent(update); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return startsmbfilepwent(update); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->startsmbpwent(update); } /*************************************************************** @@ -144,37 +160,16 @@ void *startsmbpwent(BOOL update) void endsmbpwent(void *vp) { -#ifdef USE_NISPLUS_DB - endnisppwent(vp); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - endldappwent(vp); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - endsmbfilepwent(vp); -#endif /* USE_SMBPASS_DB */ + pdb_ops->endsmbpwent(vp); } /************************************************************************* - Routine to return the next entry in the sam passwd list. + Routine to return the next entry in the smb passwd list. *************************************************************************/ struct smb_passwd *getsmbpwent(void *vp) { -#ifdef USE_NISPLUS_DB - return pdb_sam_to_smb(getnisp21pwent(vp)); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return pdb_sam_to_smb(getldap21pwent(vp)); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return getsmbfilepwent(vp); -#endif /* USE_SMBPASS_DB */ - return NULL; + return pdb_ops->getsmbpwent(vp); } /************************************************************************* @@ -190,17 +185,7 @@ struct smb_passwd *getsmbpwent(void *vp) unsigned long getsmbpwpos(void *vp) { -#ifdef USE_NISPLUS_DB - return getnisppwpos(vp); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return getldappwpos(vp); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return getsmbfilepwpos(vp); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->getsmbpwpos(vp); } /************************************************************************* @@ -216,17 +201,7 @@ unsigned long getsmbpwpos(void *vp) BOOL setsmbpwpos(void *vp, unsigned long tok) { -#ifdef USE_NISPLUS_DB - return setnisppwpos(vp, tok); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return setldappwpos(vp, tok); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return setsmbfilepwpos(vp, tok); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->setsmbpwpos(vp, tok); } /************************************************************************ @@ -235,17 +210,7 @@ BOOL setsmbpwpos(void *vp, unsigned long tok) BOOL add_smbpwd_entry(struct smb_passwd *newpwd) { -#ifdef USE_NISPLUS_DB - return add_nisp21pwd_entry(pdb_smb_to_sam(newpwd)); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return add_ldap21pwd_entry(pdb_smb_to_sam(newpwd)); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return add_smbfilepwd_entry(newpwd); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->add_smbpwd_entry(newpwd); } /************************************************************************ @@ -259,17 +224,7 @@ BOOL add_smbpwd_entry(struct smb_passwd *newpwd) BOOL mod_smbpwd_entry(struct smb_passwd* pwd, BOOL override) { -#ifdef USE_NISPLUS_DB - return mod_nisp21pwd_entry(pdb_smb_to_sam(pwd), override); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return mod_ldap21pwd_entry(pdb_smb_to_sam(pwd), override); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return mod_smbfilepwd_entry(pwd, override); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->mod_smbpwd_entry(pwd, override); } /************************************************************************ @@ -278,17 +233,7 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd, BOOL override) struct smb_passwd *getsmbpwnam(char *name) { -#ifdef USE_NISPLUS_DB - return pdb_sam_to_smb(_getsam21pwnam(name)); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return pdb_sam_to_smb(_getsam21pwnam(name)); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return _getsmbpwnam(name); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->getsmbpwnam(name); } /************************************************************************ @@ -297,178 +242,64 @@ struct smb_passwd *getsmbpwnam(char *name) struct smb_passwd *getsmbpwuid(uid_t smb_userid) { -#ifdef USE_NISPLUS_DB - return pdb_sam_to_smb(_getsam21pwrid(smb_userid)); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return pdb_sam_to_smb(_getsam21pwrid(smb_userid)); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return _getsmbpwuid(smb_userid); -#endif /* USE_SMBPASS_DB */ + return pdb_ops->getsmbpwuid(smb_userid); } /* * Functions that manupulate a struct sam_passwd. */ -/************************************************************************* - Routine to return the next entry in the sam passwd list. - *************************************************************************/ - -struct sam_disp_info *getsamdispent(void *vp) -{ -#ifdef USE_NISPLUS_DB - return pdb_sam_to_dispinfo(getnisp21pwent(vp)); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return pdb_sam_to_dispinfo(getldap21pwent(vp)); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return pdb_sam_to_dispinfo(getsmbfile21pwent(vp)); -#endif /* USE_SMBPASS_DB */ - - return NULL; -} - -/************************************************************************* - Routine to return the next entry in the sam passwd list. - *************************************************************************/ - -struct sam_passwd *getsam21pwent(void *vp) -{ -#ifdef USE_NISPLUS_DB - return getnisp21pwent(vp); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return getldap21pwent(vp); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return getsmbfile21pwent(vp); -#endif /* USE_SMBPASS_DB */ - - return NULL; -} - -/************************************************************************ - Routine to add an entry to the sam passwd file. -*************************************************************************/ - -BOOL add_sam21pwd_entry(struct sam_passwd *newpwd) -{ -#ifdef USE_NISPLUS_DB - return add_nisp21pwd_entry(newpwd); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return add_ldap21pwd_entry(newpwd); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return add_smbfile21pwd_entry(newpwd); -#endif /* USE_SMBPASS_DB */ -} - /************************************************************************ - Routine to search the sam passwd database for an entry matching the username. - and then modify its password entry. We can't use the startsampwent()/ - getsampwent()/endsampwent() interfaces here as we depend on looking - in the actual file to decide how much room we have to write data. - override = False, normal - override = True, override XXXXXXXX'd out password or NO PASS -************************************************************************/ - -BOOL mod_sam21pwd_entry(struct sam_passwd* pwd, BOOL override) -{ -#ifdef USE_NISPLUS_DB - return mod_nisp21pwd_entry(pwd, override); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return mod_ldap21pwd_entry(pwd, override); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return mod_smbfile21pwd_entry(pwd, override); -#endif /* USE_SMBPASS_DB */ -} - -/************************************************************************ - Routine to search sam passwd by name. use this if your database + Utility function to search sam passwd by name. use this if your database does not have search facilities. *************************************************************************/ -static struct sam_passwd *_getsam21pwnam(char *name) +struct sam_passwd *iterate_getsam21pwnam(char *name) { struct sam_passwd *pwd = NULL; void *fp = NULL; - DEBUG(10, ("_getsam21pwnam: search by name: %s\n", name)); + DEBUG(10, ("iterate_getsam21pwnam: search by name: %s\n", name)); /* Open the smb password database - not for update. */ fp = startsmbpwent(False); if (fp == NULL) { - DEBUG(0, ("_getsam21pwnam: unable to open sam password database.\n")); + DEBUG(0, ("iterate_getsam21pwnam: unable to open sam password database.\n")); return NULL; } - while ((pwd = getsam21pwent(fp)) != NULL && !strequal(pwd->smb_name, name)); + while ((pwd = getsam21pwent(fp)) != NULL && !strequal(pwd->smb_name, name)) + ; if (pwd != NULL) { - DEBUG(10, ("_getsam21pwnam: found by name: %s\n", name)); + DEBUG(10, ("iterate_getsam21pwnam: found by name: %s\n", name)); } endsmbpwent(fp); return pwd; } - /************************************************************************ - Routine to search sam passwd by name. -*************************************************************************/ - -struct sam_passwd *getsam21pwnam(char *name) -{ -#ifdef USE_NISPLUS_DB - return _getsam21pwnam(name); -#endif /* USE_NISPLUS_DB */ - -#ifdef USE_LDAP_DB - return _getsam21pwnam(name); -#endif /* USE_LDAP_DB */ - -#ifdef USE_SMBPASS_DB - return _getsam21pwnam(name); -#endif /* USE_SMBPASS_DB */ -} - -/************************************************************************ - Routine to search sam passwd by uid. use this if your database + Utility function to search sam passwd by uid. use this if your database does not have search facilities. *************************************************************************/ -static struct sam_passwd *_getsam21pwuid(uint32 uid) +struct sam_passwd *iterate_getsam21pwuid(uint32 uid) { struct sam_passwd *pwd = NULL; void *fp = NULL; - DEBUG(10, ("_getsam21pwuid: search by uid: %x\n", uid)); + DEBUG(10, ("iterate_getsam21pwuid: search by uid: %x\n", uid)); /* Open the smb password file - not for update. */ fp = startsmbpwent(False); if (fp == NULL) { - DEBUG(0, ("_getsam21pwuid: unable to open sam password database.\n")); + DEBUG(0, ("iterate_getsam21pwuid: unable to open sam password database.\n")); return NULL; } @@ -477,30 +308,71 @@ static struct sam_passwd *_getsam21pwuid(uint32 uid) if (pwd != NULL) { - DEBUG(10, ("_getsam21pwuid: found by smb_userid: %x\n", uid)); + DEBUG(10, ("iterate_getsam21pwuid: found by smb_userid: %x\n", uid)); } endsmbpwent(fp); return pwd; } +/************************************************************************* + Routine to return the next entry in the sam passwd list. + *************************************************************************/ + +struct sam_disp_info *getsamdispent(void *vp) +{ + return pdb_sam_to_dispinfo(pdb_ops->getsam21pwent(vp)); +} + +/************************************************************************* + Routine to return the next entry in the sam passwd list. + *************************************************************************/ + +struct sam_passwd *getsam21pwent(void *vp) +{ + return pdb_ops->getsam21pwent(vp); +} + /************************************************************************ - Routine to search sam passwd by uid. + Routine to add an entry to the sam passwd file. *************************************************************************/ -struct sam_passwd *getsam21pwuid(uint32 uid) +BOOL add_sam21pwd_entry(struct sam_passwd *newpwd) { -#ifdef USE_NISPLUS_DB - return _getsam21pwuid(uid); -#endif /* USE_NISPLUS_DB */ + return pdb_ops->add_sam21pwd_entry(newpwd); +} -#ifdef USE_LDAP_DB - return _getsam21pwuid(uid); -#endif /* USE_LDAP_DB */ +/************************************************************************ + Routine to search the sam passwd database for an entry matching the username. + and then modify its password entry. We can't use the startsampwent()/ + getsampwent()/endsampwent() interfaces here as we depend on looking + in the actual file to decide how much room we have to write data. + override = False, normal + override = True, override XXXXXXXX'd out password or NO PASS +************************************************************************/ -#ifdef USE_SMBPASS_DB - return _getsam21pwuid(uid); -#endif /* USE_SMBPASS_DB */ +BOOL mod_sam21pwd_entry(struct sam_passwd* pwd, BOOL override) +{ + return pdb_ops->mod_sam21pwd_entry(pwd, override); +} + + +/************************************************************************ + Routine to search sam passwd by name. +*************************************************************************/ + +struct sam_passwd *getsam21pwnam(char *name) +{ + return pdb_ops->getsam21pwnam(name); +} + +/************************************************************************ + Routine to search sam passwd by uid. +*************************************************************************/ + +struct sam_passwd *getsam21pwuid(uint32 uid) +{ + return pdb_ops->getsam21pwuid(uid); } @@ -552,6 +424,7 @@ void pdb_init_sam(struct sam_passwd *user) /************************************************************************* Routine to return the next entry in the sam passwd list. *************************************************************************/ + struct sam_disp_info *pdb_sam_to_dispinfo(struct sam_passwd *user) { static struct sam_disp_info disp_info; @@ -1051,5 +924,5 @@ uint32 pdb_gid_to_group_rid(uint32 gid) BOOL pdb_rid_is_user(uint32 rid) { /* Punt for now - we need to look at the encoding here. JRA. */ - return False; + return True; } diff --git a/source3/passdb/smbpass.c b/source3/passdb/smbpass.c index e37e2a5f87..8e0ace9986 100644 --- a/source3/passdb/smbpass.c +++ b/source3/passdb/smbpass.c @@ -31,11 +31,9 @@ static char s_readbuf[16 * 1024]; /*************************************************************** Start to enumerate the smbpasswd list. Returns a void pointer to ensure no modification outside this module. +****************************************************************/ - do not call this function directly. use passdb.c instead. - - ****************************************************************/ -void *startsmbfilepwent(BOOL update) +static void *startsmbfilepwent(BOOL update) { FILE *fp = NULL; char *pfile = lp_smb_passwd_file(); @@ -73,7 +71,8 @@ void *startsmbfilepwent(BOOL update) /*************************************************************** End enumeration of the smbpasswd list. ****************************************************************/ -void endsmbfilepwent(void *vp) + +static void endsmbfilepwent(void *vp) { FILE *fp = (FILE *)vp; @@ -88,11 +87,9 @@ void endsmbfilepwent(void *vp) - the smbpasswd file - the unix password database - smb.conf options (not done at present). - - do not call this function directly. use passdb.c instead. - *************************************************************************/ -struct sam_passwd *getsmbfile21pwent(void *vp) + +static struct sam_passwd *getsmbfile21pwent(void *vp) { struct smb_passwd *pw_buf = getsmbfilepwent(vp); static struct sam_passwd user; @@ -183,10 +180,8 @@ struct sam_passwd *getsmbfile21pwent(void *vp) /************************************************************************* Routine to return the next entry in the smbpasswd list. - - do not call this function directly. use passdb.c instead. - *************************************************************************/ + struct smb_passwd *getsmbfilepwent(void *vp) { /* Static buffers we will return. */ @@ -407,11 +402,9 @@ struct smb_passwd *getsmbfilepwent(void *vp) /************************************************************************* Return the current position in the smbpasswd list as an unsigned long. This must be treated as an opaque token. - - do not call this function directly. use passdb.c instead. - *************************************************************************/ -unsigned long getsmbfilepwpos(void *vp) + +static unsigned long getsmbfilepwpos(void *vp) { return (unsigned long)ftell((FILE *)vp); } @@ -419,33 +412,27 @@ unsigned long getsmbfilepwpos(void *vp) /************************************************************************* Set the current position in the smbpasswd list from unsigned long. This must be treated as an opaque token. - - do not call this function directly. use passdb.c instead. - *************************************************************************/ -BOOL setsmbfilepwpos(void *vp, unsigned long tok) + +static BOOL setsmbfilepwpos(void *vp, unsigned long tok) { return !fseek((FILE *)vp, tok, SEEK_SET); } /************************************************************************ Routine to add an entry to the smbpasswd file. - - do not call this function directly. use passdb.c instead. - *************************************************************************/ -BOOL add_smbfile21pwd_entry(struct sam_passwd *newpwd) + +static BOOL add_smbfile21pwd_entry(struct sam_passwd *newpwd) { return False; } /************************************************************************ Routine to add an entry to the smbpasswd file. - - do not call this function directly. use passdb.c instead. - *************************************************************************/ -BOOL add_smbfilepwd_entry(struct smb_passwd *newpwd) + +static BOOL add_smbfilepwd_entry(struct smb_passwd *newpwd) { char *pfile = lp_smb_passwd_file(); struct smb_passwd *pwd = NULL; @@ -575,10 +562,8 @@ Error was %s. Password file may be corrupt ! Please examine by hand !\n", in the actual file to decide how much room we have to write data. override = False, normal override = True, override XXXXXXXX'd out password or NO PASS - - do not call this function directly. use passdb.c instead. - ************************************************************************/ + BOOL mod_smbfile21pwd_entry(struct sam_passwd* pwd, BOOL override) { return False; @@ -591,10 +576,8 @@ BOOL mod_smbfile21pwd_entry(struct sam_passwd* pwd, BOOL override) in the actual file to decide how much room we have to write data. override = False, normal override = True, override XXXXXXXX'd out password or NO PASS - - do not call this function directly. use passdb.c instead. - ************************************************************************/ + BOOL mod_smbfilepwd_entry(struct smb_passwd* pwd, BOOL override) { /* Static buffers we will return. */ @@ -936,6 +919,29 @@ BOOL mod_smbfilepwd_entry(struct smb_passwd* pwd, BOOL override) fclose(fp); return True; } + +static struct passdb_ops file_ops = { + startsmbfilepwent, + endsmbfilepwent, + getsmbfilepwpos, + setsmbfilepwpos, + iterate_getsmbpwnam, /* In passdb.c */ + iterate_getsmbpwuid, /* In passdb.c */ + getsmbfilepwent, + add_smbfilepwd_entry, + mod_smbfilepwd_entry, + getsmbfile21pwent, + iterate_getsam21pwnam, /* In passdb.c */ + iterate_getsam21pwuid, /* In passdb.c */ + add_smbfile21pwd_entry, + mod_smbfile21pwd_entry +}; + +struct passdb_ops *file_initialize_password_db(void) +{ + return &file_ops; +} + #else static void dummy_function(void) { } /* stop some compilers complaining */ #endif /* USE_SMBPASS_DB */ diff --git a/source3/smbd/server.c b/source3/smbd/server.c index a35c3a2fdc..2b2ebb5304 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -5247,6 +5247,9 @@ static void usage(char *pname) if (!locking_init(0)) exit(1); + if(!initialize_password_db()) + exit(1); + /* possibly reload the services file. */ reload_services(True); diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c index c01f29f94f..8e744c8641 100644 --- a/source3/utils/smbpasswd.c +++ b/source3/utils/smbpasswd.c @@ -297,8 +297,14 @@ int main(int argc, char **argv) charset_initialise(); + if(!initialize_password_db()) { + fprintf(stderr, "%s: Can't setup password database vectors.\n", prog_name); + exit(1); + } + if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", prog_name, servicesf); + exit(1); } if(!get_myname(myhostname,NULL)) { |