Re: [Courier-imap] Imaplogin - lastauth
On Thu, Jul 03, 2008 at 01:16:57PM +0200, Carlos García Gómez wrote: I need to store last authentication time for imap login. A simple solution is to look at the mtime timestamp on the 'cur' subdirectory of the Maildir. This is because every time the user logs in, any mail in new/ is moved to cur/, and this updates the timestamp on cur/. This doesn't work if the user has no new mail, but you can add a simple patch to update the cur/ directory in that case. The attached patches are a couple of years old, you'll have to see if they still apply cleanly. They have been posted before, e.g. http://sourceforge.net/mailarchive/message.php?msg_id=20080401054905.GA13986%40uk.tiscali.com Regards, Brian. diff -uNr courier-imap-4.0.3.orig/imap/imapscanclient.c courier-imap-4.0.3/imap/imapscanclient.c --- courier-imap-4.0.3.orig/imap/imapscanclient.c Tue Jul 20 00:54:14 2004 +++ courier-imap-4.0.3/imap/imapscanclient.cSun May 22 18:16:33 2005 @@ -358,6 +358,7 @@ struct dirent *de; unsigned long left_unseen=0; intdowritecache=0; +intgotnew=0; if (is_sharedsubdir(dir)) maildir_shared_sync(dir); @@ -723,6 +724,7 @@ } if (dirp) closedir(dirp); + if (n) gotnew = 1; while (n) { @@ -749,6 +751,13 @@ } } while (keepgoing); } + + /* Update the 'cur' timestamp if no new mail arrived */ + if (!gotnew) { + strcpy(p+strlen(p)-3, cur); + utimes(p, 0); + } + free(p); /* diff -uNr courier-imap-4.0.3.orig/maildir/maildirgetnew.c courier-imap-4.0.3/maildir/maildirgetnew.c --- courier-imap-4.0.3.orig/maildir/maildirgetnew.c Tue Jun 8 23:44:24 2004 +++ courier-imap-4.0.3/maildir/maildirgetnew.c Sun May 22 18:09:46 2005 @@ -77,6 +77,7 @@ int n; char *new_buf[20]; char *cur_buf[20]; + int gotnew = 0; do { @@ -125,6 +126,7 @@ } } if (dirp) closedir(dirp); + if (n) gotnew = 1; while (n) { @@ -151,4 +153,7 @@ free(cp); } } while (keepgoing); + + /* Update the 'cur' timestamp even if no new mail arrived */ + if (!gotnew) utimes(curd, 0); } diff --exclude *~ -uNr sqwebmail-5.0.2.orig/sqwebmail/maildir.c sqwebmail-5.0.2/sqwebmail/maildir.c --- sqwebmail-5.0.2.orig/sqwebmail/maildir.cThu Oct 21 02:13:18 2004 +++ sqwebmail-5.0.2/sqwebmail/maildir.c Sun May 22 20:15:03 2005 @@ -1115,6 +1115,7 @@ DIR *dirp; struct dirent *dire; characl_buf[2]; + int gotnew=0; /* Delete old files in tmp */ @@ -1143,8 +1144,14 @@ rename(oldname, newname); free(oldname); free(newname); + gotnew=1; } if (dirp) closedir(dirp); + if (!gotnew) { + /* Update the 'cur' timestamp if no new mail arrived */ + strcpy(dirbuf+strlen(dirbuf)-3, cur); + utimes(dirbuf, 0); + } free(dirbuf); /* Look for any messages mark as deleted. When we delete a message - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08___ Courier-imap mailing list Courier-imap@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap
Re: [Courier-imap] Imaplogin - lastauth
On Fri, Jul 04, 2008 at 08:42:03AM -0300, Jeronimo Zucco wrote: Brian Candler wrote: A simple solution is to look at the mtime timestamp on the 'cur' subdirectory of the Maildir. This is because every time the user logs in, any mail in new/ is moved to cur/, and this updates the timestamp on cur/. For performance reasons, I've disabled log of timestamp access in the Maildir's partition with noatime option, this solution doesn't work in my setup. You misunderstand. There are three inode timestamps: ctime - when file's status was last changed mtime - when file was modified atime - when file was accessed Disabling atime updates doesn't affect the other two. mtime is always updated when a file or directory is changed. 'man 2 stat' for more info. Brian. - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 ___ Courier-imap mailing list Courier-imap@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap
Re: [Courier-imap] Imaplogin - lastauth
Jeronimo, Change your LDAP schema to add an attribute called LastMailCheckTime (or any other name you would like). You can then add this code to the auth_ldap_do3 function in authldaplib.c after the authentication bind is successful. Note that I do an async ldap_modify so that authdaemon does not block waiting on the modify. I wrote this up quick so you may want to double check it. Any questions, let me know. ---Aaron LDAPMod *mod_ctime_send[2]; LDAPMod mod_ctime_up; char *ctime_attribute_name=LastMailCheckTime; char ctime_value[512]; char *mod_update_vals[2]; time_t m_check_time; m_check_time=time(NULL); mod_ctime_send[0]=mod_ctime_up; mod_ctime_send[1]=0; sprintf(ctime_value,%u,(unsigned int) m_check_time); mod_ctime_up.mod_op=LDAP_MOD_REPLACE; mod_ctime_up.mod_type=ctime_attribute_name; mod_ctime_up.mod_values=mod_update_vals; mod_update_vals[0]=ctime_value; mod_update_vals[1]=NULL; //ASYNCHRONUS UPDATE ldap_modify(bindp, dn, mod_ctime_send); On Thu 07/03/08 16:57 , Jeronimo Zucco [EMAIL PROTECTED] sent: wrote: Carlos, Why not make a small LDAP schema change and perform an ldap modify? You can place that code right in authdaemon. That is what I did and it has worked fine for years with more than 75,000 mailboxes. This is what I would like to do in my courier setup. How did you do it? Can you give some information about it ? Thanks -- Jeronimo Zucco LPIC-1 Linux Professional Institute Certified Núcleo de Processamento de Dados Universidade de Caxias do Sul http://jczucco.blogspot.com - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08___ Courier-imap mailing list Courier-imap@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap