*/
-#ifdef USE_LDAP
+#ifdef WITH_LDAP
#include "includes.h"
{
if ( (*ldap_struct = ldap_open(lp_ldap_server(),lp_ldap_port()) ) == NULL)
{
- DEBUG(0,("%s: The LDAP server is not responding !\n",timestring()));
- return(False);
+ DEBUG( 0, ( "The LDAP server is not responding !\n" ) );
+ return( False );
}
DEBUG(2,("ldap_open_connection: connection opened\n"));
return (True);
{
if ( ldap_simple_bind_s(ldap_struct,lp_ldap_root(),lp_ldap_rootpasswd()) ! = LDAP_SUCCESS)
{
- DEBUG(0,("%s: Couldn't bind to the LDAP server !\n", timestring() ));
+ DEBUG( 0, ( "Couldn't bind to the LDAP server !\n" ) );
return(False);
}
return (True);
{
if ( ldap_simple_bind_s(ldap_struct,lp_ldap_root(),lp_ldap_rootpasswd()) ! = LDAP_SUCCESS)
{
- DEBUG(0,("%s: Couldn't bind to the LDAP server !\n", timestring() ));
+ DEBUG( 0, ( "Couldn't bind to the LDAP server!\n" ) );
return(False);
}
DEBUG(2,("ldap_connect_system: succesful connection to the LDAP server\n"));
{
if ( ldap_simple_bind_s(ldap_struct,lp_ldap_root(),lp_ldap_rootpasswd()) ! = LDAP_SUCCESS)
{
- DEBUG(0,("%s: Couldn't bind to the LDAP server !\n", timestring() ));
+ DEBUG( 0, ( "Couldn't bind to the LDAP server !\n" ) );
return(False);
}
DEBUG(2,("ldap_connect_user: succesful connection to the LDAP server\n"));
if (rc ! = LDAP_SUCCESS )
{
- DEBUG(0,("%s: Problem during the LDAP search\n",timestring()));
+ DEBUG( 0, ( "Problem during the LDAP search\n" ) );
return(False);
}
return (True);
so in ldap filter, %u MUST exist :-)
*/
pstrcpy(filter,lp_ldap_filter());
- string_sub(filter,"%u",user);
+ pstring_sub(filter,"%u",user);
if ( !ldap_search_one_user(ldap_struct, filter, result) )
{
{
pstring filter;
- snprintf(filter, sizeof(pstring), "uidAccount = %d", uid);
+ slprintf(filter, sizeof(pstring)-1, "uidAccount = %d", uid);
if ( !ldap_search_one_user(ldap_struct, filter, result) )
{
pdb_init_smb(user);
- bzero(smblmpwd, sizeof(smblmpwd));
- bzero(smbntpwd, sizeof(smbntpwd));
+ memset((char *)smblmpwd, '\0', sizeof(smblmpwd));
+ memset((char *)smbntpwd, '\0', sizeof(smbntpwd));
get_single_attribute(ldap_struct, entry, "cn", user_name);
DEBUG(2,("ldap_get_smb_passwd: user: %s\n",user_name));
#ifdef LDAP_PLAINTEXT_PASSWORD
get_single_attribute(ldap_struct, entry, "userPassword", temp);
nt_lm_owf_gen(temp, user->smb_nt_passwd, user->smb_passwd);
- bzero(temp, sizeof(temp)); /* destroy local copy of the password */
+ memset((char *)temp, '\0', sizeof(temp)); /* destroy local copy of the password */
#else
get_single_attribute(ldap_struct, entry, "unicodePwd", temp);
pdb_gethexpwd(temp, smbntpwd);
- bzero(temp, sizeof(temp)); /* destroy local copy of the password */
+ memset((char *)temp, '\0', sizeof(temp)); /* destroy local copy of the password */
get_single_attribute(ldap_struct, entry, "dBCSPwd", temp);
pdb_gethexpwd(temp, smblmpwd);
- bzero(temp, sizeof(temp)); /* destroy local copy of the password */
+ memset((char *)temp, '\0', sizeof(temp)); /* destroy local copy of the password */
#endif
get_single_attribute(ldap_struct, entry, "userAccountControl", temp);
if (mods == NULL)
{
mods = (LDAPMod **)malloc( sizeof(LDAPMod *) );
+ if (mods == NULL)
+ {
+ DEBUG(0,("make_a_mod: out of memory!\n"));
+ return;
+ }
mods[0] = NULL;
}
if (mods[i] == NULL)
{
mods = (LDAPMod **)realloc( mods, (i+2) * sizeof( LDAPMod * ) );
+ if (mods == NULL)
+ {
+ DEBUG(0,("make_a_mod: out of memory!\n"));
+ return;
+ }
mods[i] = (LDAPMod *)malloc( sizeof( LDAPMod ) );
+ if (mods[i] == NULL)
+ {
+ DEBUG(0,("make_a_mod: out of memory!\n"));
+ return;
+ }
mods[i]->mod_op = modop;
mods[i]->mod_values = NULL;
mods[i]->mod_type = strdup( attribute );
}
mods[ i ]->mod_values = (char **)realloc(mods[ i ]->mod_values,
(j+2) * sizeof( char * ));
+ if ( mods[ i ]->mod_values == NULL)
+ {
+ DEBUG(0, "make_a_mod: Memory allocation failure!\n");
+ return;
+ }
mods[ i ]->mod_values[ j ] = strdup(value);
mods[ i ]->mod_values[ j + 1 ] = NULL;
}
make_a_mod(&mods, ldap_state, "rid", rid);
make_a_mod(&mods, ldap_state, "pwdLastSet", lst);
- make_a_mod(&mods, ldap_state, "userAccountControl", pdb_encode_acct_ctrl(newpwd->acct_ctrl));
+ make_a_mod(&mods, ldap_state, "userAccountControl", pdb_encode_acct_ctrl(newpwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN));
switch(flag)
{
make_a_mod(&mods, ldap_state, "rid", rid);
make_a_mod(&mods, ldap_state, "pwdLastSet", lst);
- make_a_mod(&mods, ldap_state, "userAccountControl", pdb_encode_acct_ctrl(newpwd->acct_ctrl));
+ make_a_mod(&mods, ldap_state, "userAccountControl", pdb_encode_acct_ctrl(newpwd->acct_ctrl,NEW_PW_FORMAT_SPACE_PADDED_LEN));
ldap_modify_s(ldap_struct, dn, mods);
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) );
}
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) );
}
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);
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);
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;
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;
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;
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);
}
/*************************************************************************
- Return the current position in the ldap passwd list as an unsigned long.
+ Return the current position in the ldap passwd list as an SMB_BIG_UINT.
This must be treated as an opaque token.
do not call this function directly. use passdb.c instead.
*************************************************************************/
-unsigned long getldappwpos(void *vp)
+static SMB_BIG_UINT getldappwpos(void *vp)
{
- return 0;
+ return (SMB_BIG_UINT)0;
}
/*************************************************************************
- Set the current position in the ldap passwd list from unsigned long.
+ Set the current position in the ldap passwd list from SMB_BIG_UINT.
This must be treated as an opaque token.
do not call this function directly. use passdb.c instead.
*************************************************************************/
-BOOL setldappwpos(void *vp, unsigned long tok)
+static BOOL setldappwpos(void *vp, SMB_BIG_UINT 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 *getldappwrid(uint32 user_rid)
+{
+ return pdb_sam_to_smb(iterate_getsam21pwuid(pdb_user_rid_to_uid(user_rid)));
+}
+
+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 BOOL del_ldappwd_entry(const char *name)
+{
+ return False; /* Dummy... */
+}
+
+static struct sam_disp_info *getldapdispnam(char *name)
+{
+ return pdb_sam_to_dispinfo(getldap21pwnam(name));
+}
+
+static struct sam_disp_info *getldapdisprid(uint32 rid)
+{
+ return pdb_sam_to_dispinfo(getldap21pwrid(rid));
+}
+
+static struct sam_disp_info *getldapdispent(void *vp)
+{
+ return pdb_sam_to_dispinfo(getldap21pwent(vp));
+}
+
+static struct sam_passwd *getldap21pwuid(uid_t uid)
+{
+ return pdb_smb_to_sam(iterate_getsam21pwuid(pdb_uid_to_user_rid(uid)));
+}
+
+static struct passdb_ops ldap_ops =
+{
+ startldappwent,
+ endldappwent,
+ getldappwpos,
+ setldappwpos,
+ getldappwnam,
+ getldappwuid,
+ getldappwrid,
+ getldappwent,
+ add_ldappwd_entry,
+ mod_ldappwd_entry,
+ del_ldappwd_entry,
+ getldap21pwent,
+ iterate_getsam21pwnam, /* From passdb.c */
+ iterate_getsam21pwuid, /* From passdb.c */
+ iterate_getsam21pwrid, /* From passdb.c */
+ add_ldap21pwd_entry,
+ mod_ldap21pwd_entry,
+ getldapdispnam,
+ getldapdisprid,
+ getldapdispent
+};
+
+struct passdb_ops *ldap_initialize_password_db(void)
+{
+ return &ldap_ops;
+}
+
#else
-static void dummy_function(void) { } /* stop some compilers complaining */
+ void dummy_function(void);
+ void dummy_function(void) { } /* stop some compilers complaining */
#endif