On Tue, Oct 29, 2002 at 04:36:08PM +0100, Roland Schneider wrote:
> due to a couple of callbacks the username is not available
> once the login fails
Hmm. authmod(), authchain() and authmod_fail_completely() all use execv, so
the environment is inherited. This should mean that you can set an
environment variable with the attempted username.
I've just tried this, and it seems to be work - the attached patch sets
environment variable UID and uses it for the failure log message.
It should be easy to modify auth_get_cram() to set UID=<user> as well, but I
don't have a CRAM environment to test this in.
Cheers,
Brian.
--- courier-imap-1.6.0.20021025/imap/pop3login.c.orig Mon Oct 28 10:48:56 2002
+++ courier-imap-1.6.0.20021025/imap/pop3login.c Wed Oct 30 16:26:28 2002
@@ -148,7 +148,6 @@
}
else
{
- fprintf(stderr, "ERR: LOGIN FAILED, ip=[%s]\n", ip);
printf("-ERR Login failed.\r\n");
}
--- courier-imap-1.6.0.20021025/imap/imaplogin.c.orig Mon Oct 28 10:48:56 2002
+++ courier-imap-1.6.0.20021025/imap/imaplogin.c Wed Oct 30 16:26:44 2002
@@ -289,7 +289,6 @@
{
writes(tag ? tag:"");
writes(" NO Login failed.\r\n");
- fprintf(stderr, "ERR: LOGIN FAILED, ip=[%s]\n", ip);
}
writeflush();
--- courier-imap-1.6.0.20021025/authlib/authmoduser2.c.orig Wed Oct 30 16:37:04
2002
+++ courier-imap-1.6.0.20021025/authlib/authmoduser2.c Wed Oct 30 16:48:25 2002
@@ -5,6 +5,7 @@
#include "auth.h"
#include "authmod.h"
+#include "debug.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -87,7 +88,13 @@
putenv(p);
}
- if (rc == 0 && errsleep) sleep(errsleep);
+ if (rc == 0)
+ {
+ char *p = getenv("UID");
+ auth_debug_login(0, "LOGIN FAILED%s%s",
+ p?", user=":"", p?p:"");
+ if (errsleep) sleep(errsleep);
+ }
time(&t);
p=getenv("AUTHEXPIRE");
--- courier-imap-1.6.0.20021025/authlib/authmoduser3.c.orig Tue Oct 1 04:00:12
2002
+++ courier-imap-1.6.0.20021025/authlib/authmoduser3.c Wed Oct 30 16:43:09 2002
@@ -18,15 +18,18 @@
const char *passwd)
{
char *p=malloc(strlen(userid)+strlen(passwd)+3);
+char *q=malloc(sizeof("UID=")+strlen(userid));
auth_debug_login( 1, "username=%s", userid );
auth_debug_login( 2, "password=%s", passwd );
- if (!p)
+ if (!p || !q)
{
perror("malloc");
authexit(1);
}
strcat(strcat(strcat(strcpy(p, userid), "\n"), passwd), "\n");
+ strcat(strcpy(q, "UID="), userid);
+ putenv(q);
authmod(argc, argv, service, AUTHTYPE_LOGIN, p);
}