Imaplogin - lastauth

View: New views
8 Messages — Rating Filter:   Alert me  

Imaplogin - lastauth

by Carlos García Gómez :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello,
 
I need to store last authentication time for imap login.
 
I use courier-imap with openldap ( I don´t use vpopmail !!! )
 
I have thought I would do something like this:
 

    char *tmpbuf;
    FILE *fs;
 
    tmpbuf = (char *) malloc(300);
    sprintf(tmpbuf, "%s/lastauth", user_maildir); // I would nee user_maildir 
    if ( (fs = fopen(tmpbuf,"w+")) == NULL ) {
        free(tmpbuf);
        return -1;
    }
 
    fprintf(fs, "%s", mbox);
    fprintf(fs, "%s", "imap");
    fclose(fs);
    free(tmpbuf);
 
 
but I don´t know where can I put it on.
 
Any Ideas?
 
 
 
 

-------------------------------------------------------------------------
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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Re: Imaplogin - lastauth

by MrC-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Carlos,

Carlos García Gómez wrote:
> I need to store last authentication time for imap login.
> I use courier-imap with openldap ( I don´t use vpopmail !!! )
> I have thought I would do something like this:

>     char *tmpbuf;
>     FILE *fs;
>
>     tmpbuf = (char *) malloc(300);
>     sprintf(tmpbuf, "%s/lastauth", user_maildir); // I would nee user_maildir
>     if ( (fs = fopen(tmpbuf,"w+")) == NULL ) {
>         free(tmpbuf);
>         return -1;
>     }
>
>     fprintf(fs, "%s", mbox);
>     fprintf(fs, "%s", "imap");
>     fclose(fs);
>     free(tmpbuf);
>
>
> but I don´t know where can I put it on.
>
> Any Ideas?

You mean you need something more than your maillog provides, such as:

Jul  3 09:47:30 glacier imapd-ssl: LOGIN, user=me@...,
   ip=[192.168.0.50], port=[2813], protocol=IMAP

-------------------------------------------------------------------------
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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Parent Message unknown Re: Imaplogin - lastauth

by Aaron Brace-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

---Aaron

  

Aaron Brace
Director of Engineering & Principal Architect
Metrocast Cablevision
abrace@...
603-330-7772


On Thu 07/03/08 07:16 , Carlos García Gómez carlos.garcia@... sent:
Hello,
 
I need to store last authentication time for imap login.
 
I use courier-imap with openldap ( I don´t use vpopmail !!! )
 
I have thought I would do something like this:
 

    char *tmpbuf;
    FILE *fs;
 
    tmpbuf = (char *) malloc(300);
    sprintf(tmpbuf, "%s/lastauth", user_maildir); // I would nee user_maildir 
    if ( (fs = fopen(tmpbuf,"w+")) == NULL ) {
        free(tmpbuf);
        return -1;
    }
 
    fprintf(fs, "%s", mbox);
    fprintf(fs, "%s", "imap");
    fclose(fs);
    free(tmpbuf);
 
 
but I don´t know where can I put it on.
 
Any Ideas?
 
 
 
 


-------------------------------------------------------------------------
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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Re: Imaplogin - lastauth

by Jeronimo Zucco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

abrace@... 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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Parent Message unknown Re: Imaplogin - lastauth

by Aaron Brace-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
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 jczucco@... sent:
abrace@... 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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Re: Imaplogin - lastauth

by Brian Candler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.c Sun May 22 18:16:33 2005
@@ -358,6 +358,7 @@
 struct dirent *de;
 unsigned long left_unseen=0;
 int dowritecache=0;
+int gotnew=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.c Thu 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;
  char acl_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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Re: Imaplogin - lastauth

by Jeronimo Zucco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

    I'll try Aaron's solution. Thank you all !

--
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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Re: Imaplogin - lastauth

by Brian Candler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap