Novell Home

Finding Out the Last Login Time for a User

Novell Cool Solutions: Trench

Digg This - Slashdot This

Posted: 30 Sep 2004
 

Question: Andrew T. wrote: I noticed that every entry in workstation object WM:User history has a Modification time attribute that effectively is the last login time for that user. Is there a way to export this somehow ( via LDAP maybe?) to have a list of logged in users sorted by last login time rather than by user name? I know I should be using audit for this probably but data seems to be already there.

Answer: OPEN CALL: Anyone have any cool ideas for Andrew? Let us know.

Suggestions

Mike Henderson

Use NDS Report: http://www.novell.com/coolsolutions/tools/1448.html

You can export all kinds of great things like "Last Login Time" or "Login Time", both of which are NDS attributes.

Greg Pott

You can also query eDirectory with the odbc driver usually located in
..\PUBLIC\mgmt\ConsoleOne\1.2\reporting\bin\

I have a number of queries saved which quickly fetch information using msquery.

Jim Trotter

I like to use the eDirectory ODBC drivers to do a query on the USER object. I can import the user CN, Surname, context and Last Login time, then sort using context and last login time. It's a great way to find "deadbeats." One can use the ODBC drivers to pull a ton of useful data from eDirectory. I found the drivers at http://developer.novell.com/ndk/odbcrw.htm

Brett McQuiston

The eDirectory ODBC driver works for me: http://developer.novell.com/ndk/odbcrw.htm

You can pull the data directly into Excel and sort or format it however you want. Novell AppNotes also did 3 or 4 articles on configuring the ODBC driver. Part 1 walks you through a quick and easy config.

Rainer Brunold

I haven't done it for workstation objects but quite often for user objects.

I installed the ODBC driver for eDirectory from the Novell developer page and use Excel for querying the specific user information, like CN, NDS Context, Last Login Time, etc.

You can get it at: http://developer.novell.com/ndk/odbcrw.htm

That works quite fine for me.

Justin Birt

Download a copy of the ODBC drivers for NetWare. You can then run queries straight into Excel.

Phillip Thomas

The last login times of the users in the WM:User History are not stored on the workstation object. The "Last Login Time" and "Login Time" user attributes are for logins to eDirectory from anywhere, not logins to a particular workstation! However I can still see the value in being able to easily query the last login times of those users.

For what it's worth, here is a perl script that will find a workstation object, query the User History, and print out their "Login Time". It's not sorted, and the login time format is pretty ugly, but what do you want for nothing? :)

#!/usr/bin/perl 

# 
#   Last login time for user history 
#   Sep 2004 
#   Phillip E. Thomas 
# 
# 
# finds one workstation object, retrieves the WM:User History list 
# and finds the latest login time for each user 
# 
# since calls are made to localhost, I don't bother with SSL or TLS 
# 
# Replace LDAPHOST, USERNAME, PASSWORD, and BASE with 
# values for your network. 
# 
# 
use strict; 
use warnings; 

use Net::LDAP; 
use Net::LDAP::LDIF; 

our 
    ($LDAPHOST,$USERNAME,$PASSWORD,$BASE, 
     $ldap,$userdn,$user, 
     $cn,$FullName,$Logintime,$OutputFileName, 
     $workstation,$WMUserHistory); 

$LDAPHOST='127.0.0.1'; 
$USERNAME="cn=admin,o=MyOrg"; 
$PASSWORD="MyPassword"; 
$BASE="o=MyOrg"; 

#initialize the LDAP connection 
InitLDAP(); 

#parse commandline and find the workstation 
if ($#ARGV eq 0){ 
    $workstation=FindWorkstation($ARGV[0]); 
    if (not $workstation){ 
        print "Workstation $ARGV[0] not found!\n"; 
        exit 0; 
    } 
} 
else { 
    print "usage: userhistory .\n"; 
    exit 0; 
} 

#for each member of the WM:User History attribute, find the user object and get info 
foreach $userdn ($workstation->get_value('WMUserHistory')) { 
    $user=FindUser($userdn); 
    if ($user) { 
        $FullName=$user->get_value('FullName'); 
        $Logintime=$user->get_value('loginTime'); 
        print "$Logintime;$userdn;$FullName\n"; 
    } 
} 
  
#close the LDAP connection 
$ldap->unbind; 

#END PROGRAM 
exit; 

sub FindUser { 
    my $myuserdn=$_[0]; 

    #clumsy way to extract cn from dn 
    my ($myusercn)=split(",",$myuserdn); 
    (undef, $myusercn)=split("=",$myusercn); 

    my $myfilter="(&(objectclass=inetOrgPerson)(cn=$myusercn))"; 

    my $myuser=QueryLDAP($myfilter); 
    return $myuser; 
} 

sub FindWorkstation { 
    my $myworkstationname=$_[0]; 
    my $myfilter="(&(objectclass=Workstation)(cn=$myworkstationname))"; 
    my $myworkstation=QueryLDAP($myfilter); 
    return $myworkstation; 
} 



sub QueryLDAP { 

    my $myfilter=$_[0]; 

    #create a new blank LDAP entry object 
    my $mesg=Net::LDAP::Entry->new; 

    #LDAP search, assign the returned value to $mesg.  This is potentially 
    #an array containing multiple hits for the search. 
    $mesg = $ldap->search ( base => $BASE, 
                            filter => $myfilter 
                            ); 
    if ($mesg->code) { 
        print $mesg->code," ",$mesg->error," ",$mesg->server_error," ", 
        "while searching for $cn.\n"; 
        return 0; 
    } 
    if ($mesg->count eq 0) { 
        return 0; 
    } 

    if ($mesg->count > 1)  { 
        print "Duplicate objects found in eDirectory\n"; 
        return 0; 
    } 

    #should have only one to return 
    foreach my $entry ($mesg->all_entries) { 
        return $entry; 
    } 
} 

sub InitLDAP { 

    $ldap=Net::LDAP->new($LDAPHOST, version => 3 ) or die "$@"; 
    $ldap->bind($USERNAME, password => $PASSWORD); 
} 

sub CloseLDAP { 

    $ldap->unbind; 
} 

Andrew T.

I guess there has been some confusion about my question. I was not asking about the actual USER attribute "Last Login Time" or "Login Time" (which indeed is not stored on the workstation object).

If you look at any workstation object under WM:User history ( e.g. using DSbrowse ) then every entry ( for every user logged in on THAT particular workstation ) has a "modification time" attribute (of that entry, not of the workstation itself) which is workstation specific and varies for the same user on different machines. It still does not give you a full user login history, but is better than a single last login time anyway.

Thanks, everyone. I will look into ODBC.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell