Logging "logon time" in the ldap directory
mmessaoudi at vinci-construction.com
mmessaoudi at vinci-construction.com
Thu Jan 17 11:51:39 GMT 2002
Hi everybody,
Still with my samba 2.2.2 (with ldapsam), the logon time was never
updated in the directory;
The problem exists with logofftime, pwdLastSet (3.0 corrects the
problem when the password update is done using smbpasswd, not from a Win
Client);
For now, to solve my problem, i had to put a new function
<passdb/pdb_ldap/pdb_update_sam_logon_time(sampass, time(NULL));> in the
rpc_server/srv_netlog_nt.c/_net_sam_logon;
Is it planned to correct this time stuff in the next release ? (2.2.3
or 3.0)
Thanks
PS : Code of the pdb_update_sam_logon_time
/**********************************************************************
Update logon time
*********************************************************************/
BOOL pdb_update_sam_logon_time(SAM_ACCOUNT * account, time_t logontime)
{
int rc;
char *dn;
LDAP *ldap_struct;
LDAPMessage *result;
LDAPMessage *entry;
LDAPMod **mods;
pstring temp;
if (!ldap_open_connection(&ldap_struct)) /* open a connection to the
server */
return False;
if (!ldap_connect_system(ldap_struct)) /* connect as system account
*/
{
ldap_unbind(ldap_struct);
return False;
}
rc = ldap_search_one_user_by_name(ldap_struct,
pdb_get_username(account), &result);
if (ldap_count_entries(ldap_struct, result) == 0)
{
DEBUG(0, ("No user to modify!\n"));
ldap_msgfree(result);
ldap_unbind(ldap_struct);
return False;
}
mods = NULL;
slprintf(temp, sizeof(temp) - 1, "%li", logontime);
make_a_mod(&mods, LDAP_MOD_REPLACE, "logonTime", temp);
entry = ldap_first_entry(ldap_struct, result);
dn = ldap_get_dn(ldap_struct, entry);
rc = ldap_modify_s(ldap_struct, dn, mods);
if (rc != LDAP_SUCCESS)
{
char *ld_error;
ldap_get_option(ldap_struct, LDAP_OPT_ERROR_STRING,
&ld_error);
DEBUG(0,
("failed to modify logon time with uid = %s with:
%s\n\t%s\n",
pdb_get_username(account), ldap_err2string(rc),
ld_error));
free(ld_error);
ldap_unbind(ldap_struct);
return False;
}
/* Update logon time in the sam structure */
pdb_set_logon_time(account, logontime);
DEBUG(2,
("successfully modified logon time for uid = %s in the LDAP
database\n",
pdb_get_username(account)));
ldap_mods_free(mods, 1);
ldap_unbind(ldap_struct);
return True;
}
More information about the samba-technical
mailing list