I'm interested in knowing not only what IP the user last auth'd, but also
how they connected. That gives me more info right from the tables on how a
particular is using the system, and how the system is utilized overall.
I attached a patch and honestly I haven't even tested yet - just thought
I'd throw it out there..
- It utilizes a new field 'type' char(10), and puts the text AuthType in
there. I'm not sure if a table change is handled via README or automated..
- It also adjusts the vget_lastauth to grab the 'latest' record for that
user from the lastauth table, no matter how they auth'd.
- The new info is only accessible by direct query.
Rick
!DSPAM:4cd9a51632711680712101!
diff -u vpopmail-5.4.32-orig/authvchkpw.c vpopmail-5.4.32/authvchkpw.c
--- vpopmail-5.4.32-orig/authvchkpw.c 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/authvchkpw.c 2010-11-09 12:48:02.908186101 -0600
@@ -157,7 +157,7 @@
#endif
if (!(ptr = getenv("TCPERMOTEIP")))
ptr = "0.0.0.0";
- vset_lastauth(pw->pw_name, domain, ptr);
+ vset_lastauth(pw->pw_name, domain, ptr, ServiceType );
#ifdef MIN_LOGIN_INTERVAL
if(( vget_lastauth(vpw,TheDomain ) - last_time ) < MIN_LOGIN_INTERVAL ) {
vchkpw_exit(1);
diff -u vpopmail-5.4.32-orig/vauth.c vpopmail-5.4.32/vauth.c
--- vpopmail-5.4.32-orig/vauth.c 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vauth.c 2010-11-09 13:21:04.353502283 -0600
@@ -1274,15 +1274,15 @@
/************************************************************************/
#ifdef ENABLE_AUTH_LOGGING
-int vset_lastauth(char *user, char *domain, char *remoteip )
+int vset_lastauth(char *user, char *domain, char *remoteip , char *authtype )
{
int err;
if ( (err=vauth_open_update()) != 0 ) return(err);
-
+
qnprintf( SqlBufUpdate, SQL_BUF_SIZE,
"replace into lastauth set user='%s', domain='%s', \
-remote_ip='%s', timestamp=%lu", user, domain, remoteip, time(NULL));
+remote_ip='%s', timestamp=%lu, type='%s'", user, domain, remoteip, time(NULL),
authtype);
if (mysql_query(&mysql_update,SqlBufUpdate)) {
vcreate_lastauth_table();
if (mysql_query(&mysql_update,SqlBufUpdate)) {
@@ -1302,7 +1302,7 @@
if ( (err=vauth_open_read()) != 0 ) return(err);
qnprintf( SqlBufRead, SQL_BUF_SIZE,
- "select timestamp from lastauth where user='%s' and domain='%s'",
+ "select timestamp from lastauth where user='%s' and domain='%s' order by
timestamp LIMIT 1",
pw->pw_name, domain);
if (mysql_query(&mysql_read,SqlBufRead)) {
vcreate_lastauth_table();
diff -u vpopmail-5.4.32-orig/vauth.h vpopmail-5.4.32/vauth.h
--- vpopmail-5.4.32-orig/vauth.h 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vauth.h 2010-11-09 12:46:01.627550711 -0600
@@ -68,7 +68,7 @@
void vclose();
void vclose1();
-int vset_lastauth( char *user, char *domain, char *remoteip);
+int vset_lastauth( char *user, char *domain, char *remoteip, char *authtype);
time_t vget_lastauth( struct vqpasswd *pw, char *domain);
char *vget_lastauthip( struct vqpasswd *pw, char *domain);
diff -u vpopmail-5.4.32-orig/vchkpw.c vpopmail-5.4.32/vchkpw.c
--- vpopmail-5.4.32-orig/vchkpw.c 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vchkpw.c 2010-11-09 13:16:33.795496514 -0600
@@ -579,7 +579,7 @@
#ifdef MIN_LOGIN_INTERVAL
last_time = vget_lastauth(vpw, TheDomain );
#endif
- vset_lastauth(TheUser,TheDomain,IpAddr);
+ vset_lastauth(TheUser,TheDomain,IpAddr, AuthType);
#ifdef MIN_LOGIN_INTERVAL
if(( vget_lastauth(vpw,TheDomain ) - last_time ) < MIN_LOGIN_INTERVAL ) {
vchkpw_exit(1);
diff -u vpopmail-5.4.32-orig/vmysql.c vpopmail-5.4.32/vmysql.c
--- vpopmail-5.4.32-orig/vmysql.c 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vmysql.c 2010-11-09 13:21:04.353502283 -0600
@@ -1274,15 +1274,15 @@
/************************************************************************/
#ifdef ENABLE_AUTH_LOGGING
-int vset_lastauth(char *user, char *domain, char *remoteip )
+int vset_lastauth(char *user, char *domain, char *remoteip , char *authtype )
{
int err;
if ( (err=vauth_open_update()) != 0 ) return(err);
-
+
qnprintf( SqlBufUpdate, SQL_BUF_SIZE,
"replace into lastauth set user='%s', domain='%s', \
-remote_ip='%s', timestamp=%lu", user, domain, remoteip, time(NULL));
+remote_ip='%s', timestamp=%lu, type='%s'", user, domain, remoteip, time(NULL),
authtype);
if (mysql_query(&mysql_update,SqlBufUpdate)) {
vcreate_lastauth_table();
if (mysql_query(&mysql_update,SqlBufUpdate)) {
@@ -1302,7 +1302,7 @@
if ( (err=vauth_open_read()) != 0 ) return(err);
qnprintf( SqlBufRead, SQL_BUF_SIZE,
- "select timestamp from lastauth where user='%s' and domain='%s'",
+ "select timestamp from lastauth where user='%s' and domain='%s' order by
timestamp LIMIT 1",
pw->pw_name, domain);
if (mysql_query(&mysql_read,SqlBufRead)) {
vcreate_lastauth_table();
diff -u vpopmail-5.4.32-orig/vmysql.h vpopmail-5.4.32/vmysql.h
--- vpopmail-5.4.32-orig/vmysql.h 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vmysql.h 2010-11-09 13:13:15.877302985 -0600
@@ -111,6 +111,7 @@
domain char(96) NOT NULL,\
remote_ip char(18) not null, \
timestamp bigint default 0 NOT NULL, \
+type char(10) NOT NULL,\
primary key (user, domain)"
char *vauth_munch_domain(char *);
diff -u vpopmail-5.4.32-orig/vpopmail.c vpopmail-5.4.32/vpopmail.c
--- vpopmail-5.4.32-orig/vpopmail.c 2010-11-08 09:02:52.000000000 -0600
+++ vpopmail-5.4.32/vpopmail.c 2010-11-09 12:51:22.658966976 -0600
@@ -732,7 +732,7 @@
#endif
#ifdef ENABLE_AUTH_LOGGING
- if (vset_lastauth(username,domain,NULL_REMOTE_IP) !=0) {
+ if (vset_lastauth(username,domain,NULL_REMOTE_IP, "") !=0) {
/* should we back out of all the work we have done so far? */
chdir(calling_dir);
fprintf (stderr, "Failed to create create lastauth entry\n");