Discussion: track user login
Afficher un message
Vieux 12/03/2006, 18h37   #2
Mark Crispin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: track user login

On Sun, 12 Mar 2006, P$Be(Bl Monstad wrote:
> I think I'm running imap2000 on Fedora core 2.


If you are really running imap-2000, that is a very old version of UW
imapd. Drop whatever you are doing and immediately upgrade to the latest
release version, imap-2004g:
ftp://ftp.cac.washington.edu/mail/imap.tar.Z

If you feel adventuresome (you must be for running such an old version),
you could try a development snapshot of imap-2006:
ftp://ftp.cac.washington.edu/mail/imap-2006.DEV.tar.Z
although note that a major update is coming in the next few weeks.

> I know user login actions are
> logged in /etc/log/maillog. It is hard to track which user have logged in
> and which has never logged in. I'd like to have a log with user login
> statistic, i.g. when a certain user logged in, years back in time, only
> containing the last user's login. Is there a way to tell imapd to run a
> script each time a user logs in? I'd like to have a script which changes
> date stamp on a user specific file each time a user logs in. Is this
> possible, or is there any other way around this?


There isn't anything in UW imapd itself to do that, but it would be very
easy to write code to do this. The file that you want to edit is
imap-????/src/osdep/unix/log_std.c
It consists of a single function, loginpw(). What you want to do is
insert code in that function to perform whatever action you like.

Note that, although loginpw() is called with a struct passwd * for the
user that is logging in, that struct (in pw) may be clobbered by the
initgroups() call depending upon your C library (hence the seemingly
pointless and silly copy of the uid and name). So, if you need any of
that data for your action, be sure that you either do it before the
initgroups() call or do a save.

For example, here's a modified version that will create/update the
timestamp of a file called ".lastimap" in the user's home directory (this
is off the top of my head, I haven't actually tested it).

#define STAMP "/.lastimap"

long loginpw (struct passwd *pw,int argc,char *argv[])
{
uid_t uid = pw->pw_uid;
char *name = cpystr (pw->pw_name);
char *stamp = strcat (strcpy ((char *) fs_get (strlen (pw->pw_dir) +
sizeof (STAMP)),pw->pw_dir),
STAMP);
long ret = !(setgid (pw->pw_gid) || initgroups (name,pw->pw_gid) ||
setuid (uid));
int fd = ret ? creat (stamp,0400) : -1;
if (fd >= 0) close (fd);
fs_give ((void **) &stamp);
fs_give ((void **) &name);
return ret;
}

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.
  Réponse avec citation
 
Page generated in 0,07003 seconds with 9 queries