On Friday 17 March 2006 09:27, Hrvoje Habjanic wrote:
> Hi.
>
> I'm writing my own module for authentication, under authdeamon. But, i need
> client's ip address in authentication module, which currently isn't there.
>
[bla bla bla ...]

Wow! I'm quite amazed that no one is intrested in this?! To me, this is quite 
useful feature ...

Anyway, here are 2 patches. First is against authlib, and second is against 
courier-imap.

This isn't tested (yet), but it compiles.

Any feedback is welcomed! :-)

H.
Index: imap/pop3login.c
===================================================================
--- imap/pop3login.c	(revision 3249)
+++ imap/pop3login.c	(working copy)
@@ -372,6 +372,7 @@
 
 						rc=auth_generic(q,
 							     authtype,
+							     ip,
 							     authdata,
 							     login_callback,
 							     NULL);
@@ -418,7 +419,7 @@
 				if (!q || !*q)
 					q="pop3";
 
-				rc=auth_login(q, user, p, login_callback, NULL);
+				rc=auth_login(q, ip, user, p, login_callback, NULL);
 				courier_safe_printf("INFO: LOGIN "
 					"FAILED, user=%s, ip=[%s]",
 					user, ip);
Index: imap/imaplogin.c
===================================================================
--- imap/imaplogin.c	(revision 3249)
+++ imap/imaplogin.c	(working copy)
@@ -325,6 +325,7 @@
 	char	*passwd;
 	const char *p;
 	int	rc;
+	char	*ip=getenv("TCPREMOTEIP");
 
 		if (have_starttls() && tlsrequired())	/* Not yet */
 		{
@@ -372,9 +373,9 @@
 		if (!p || !*p)
 			p="imap";
 
-		rc=auth_login(p, userid, passwd, login_callback, (void *)tag);
+		rc=auth_login(p, ip, userid, passwd, login_callback, (void *)tag);
 		courier_safe_printf("INFO: LOGIN FAILED, user=%s, ip=[%s]",
-				  userid, getenv("TCPREMOTEIP"));
+				  userid, ip);
 		free(userid);
 		free(passwd);
 		if (rc > 0)
Index: imap/authenticate_auth.c
===================================================================
--- imap/authenticate_auth.c	(revision 3249)
+++ imap/authenticate_auth.c	(working copy)
@@ -82,6 +82,7 @@
 char	authservice[40];
 char	*p ;
 int	rc;
+char	*ip=getenv("TCPREMOTEIP");
 
 	switch (tok->tokentype)	{
 	case IT_ATOM:
@@ -132,7 +133,7 @@
 	if (!p || !*p)
 		p="imap";
 
-	rc=auth_generic(p, authtype, authdata, login_callback, (void *)tag);
+	rc=auth_generic(p, authtype, ip, authdata, login_callback, (void *)tag);
 	free(authtype);
 	free(authdata);
 	return (rc);
Index: authpipe.c
===================================================================
--- authpipe.c	(revision 3248)
+++ authpipe.c	(working copy)
@@ -37,7 +37,8 @@
 static int disabled_flag;
 
 /* modelled on auth_generic() in authdaemon.c */
-int auth_pipe(const char *service, const char *authtype, char *authdata,
+int auth_pipe(const char *service, const char *authtype, const char *authip,
+		char *authdata,
 		int (*callback_func)(struct authinfo *, void *),
 		void *callback_arg)
 {
Index: courierauth.h
===================================================================
--- courierauth.h	(revision 3248)
+++ courierauth.h	(working copy)
@@ -70,12 +70,14 @@
 
 int auth_generic(const char *service,
 		 const char *authtype,
+		 const char *authip,
 		 char *authdata,
 		 int (*callback_func)(struct authinfo *, void *),
 		 void *callback_arg);
 
 	/* Login request: */
 int auth_login(const char *service,
+	       const char *clientip,
 	       const char *userid,
 	       const char *passwd,
 	       int (*callback_func)(struct authinfo *, void *),
Index: authldap.c
===================================================================
--- authldap.c	(revision 3248)
+++ authldap.c	(working copy)
@@ -68,7 +68,8 @@
 }
 #endif
 
-int auth_ldap(const char *service, const char *authtype, char *authdata,
+int auth_ldap(const char *service, const char *authtype, const char *authip,
+	      char *authdata,
 	      int (*callback_func)(struct authinfo *, void *),
 	      void *callback_arg)
 {
Index: authpam.c
===================================================================
--- authpam.c	(revision 3248)
+++ authpam.c	(working copy)
@@ -279,7 +279,8 @@
         int (*callback)(struct authinfo *, void *),
                         void *arg);
 
-int auth_pam(const char *service, const char *type, char *authdata,
+int auth_pam(const char *service, const char *type, const char *authip,
+	     char *authdata,
 	     int (*callback_func)(struct authinfo *, void *),
 	     void *callback_arg)
 {
Index: authshadow.c
===================================================================
--- authshadow.c	(revision 3248)
+++ authshadow.c	(working copy)
@@ -37,7 +37,8 @@
 				void *void_arg);
 
 
-int auth_shadow(const char *service, const char *authtype, char *authdata,
+int auth_shadow(const char *service, const char *authtype, const char *authip,
+		char *authdata,
 		int (*callback_func)(struct authinfo *, void *),
 		void *callback_arg)
 {
Index: authpgsql.c
===================================================================
--- authpgsql.c	(revision 3248)
+++ authpgsql.c	(working copy)
@@ -168,7 +168,8 @@
 }
 #endif
 
-int auth_pgsql(const char *service, const char *authtype, char *authdata,
+int auth_pgsql(const char *service, const char *authtype, const char *authip,
+	       char *authdata,
 	       int (*callback_func)(struct authinfo *, void *),
 	       void *callback_arg)
 {
Index: authpwd.c
===================================================================
--- authpwd.c	(revision 3248)
+++ authpwd.c	(working copy)
@@ -33,7 +33,8 @@
 					       void *void_arg),
 				void *void_arg);
 
-int auth_pwd(const char *service, const char *authtype, char *authdata,
+int auth_pwd(const char *service, const char *authtype, const char *authip,
+	     char *authdata,
 	     int (*callback_func)(struct authinfo *, void *),
 	     void *callback_arg)
 {
Index: authmysql.c
===================================================================
--- authmysql.c	(revision 3248)
+++ authmysql.c	(working copy)
@@ -169,7 +169,8 @@
 }
 #endif
 
-int auth_mysql(const char *service, const char *authtype, char *authdata,
+int auth_mysql(const char *service, const char *authtype, const char *authip,
+	       char *authdata,
 	       int (*callback_func)(struct authinfo *, void *),
 	       void *callback_arg)
 {
Index: authuserdb.c
===================================================================
--- authuserdb.c	(revision 3248)
+++ authuserdb.c	(working copy)
@@ -167,7 +167,8 @@
 	return rc;
 }
 
-int auth_userdb(const char *service, const char *authtype, char *authdata,
+int auth_userdb(const char *service, const char *authtype, const char *authip,
+		char *authdata,
 		int (*callback_func)(struct authinfo *, void *),
 		void *callback_arg)
 {
Index: authvchkpw.c
===================================================================
--- authvchkpw.c	(revision 3248)
+++ authvchkpw.c	(working copy)
@@ -54,7 +54,8 @@
 	return (*i->callback_func)(a, i->callback_arg);
 }
 
-int auth_vchkpw(const char *service, const char *authtype, char *authdata,
+int auth_vchkpw(const char *service, const char *authtype, const char *authip,
+	char *authdata,
 	int (*callback_func)(struct authinfo *, void *), void *callback_arg)
 {
 char *user, *pass;
Index: authtest.c
===================================================================
--- authtest.c	(revision 3248)
+++ authtest.c	(working copy)
@@ -100,7 +100,7 @@
 	}
 	if (argc - argn >= 2)
 	{
-		if (auth_login(service, argv[argn],
+		if (auth_login(service, "127.0.0.1", argv[argn],
 			       argv[argn+1],
 			       callback_pre,
 			       NULL))
Index: authmoduser3.c
===================================================================
--- authmoduser3.c	(revision 3248)
+++ authmoduser3.c	(working copy)
@@ -15,6 +15,7 @@
 
 extern int auth_generic(const char *service,
 			const char *authtype,
+			const char *authip,
 			char *authdata,
 			int (*callback_func)(struct authinfo *, void *),
 			void *callback_arg);
@@ -59,6 +60,7 @@
 }
 
 int auth_login(const char *service,
+	       const char *clientip,
 	       const char *userid,
 	       const char *passwd,
 	       int (*callback_func)(struct authinfo *, void *),
@@ -82,7 +84,7 @@
 	if (!p)
 		return (-1);
 
-	rc=auth_generic(service, AUTHTYPE_LOGIN, p,
+	rc=auth_generic(service, AUTHTYPE_LOGIN, clientip, p,
 			callback_func,
 			callback_arg);
 	free(p);
Index: authdaemon.c
===================================================================
--- authdaemon.c	(revision 3248)
+++ authdaemon.c	(working copy)
@@ -35,6 +35,7 @@
 
 int auth_generic(const char *service,
 		 const char *authtype,
+		 const char *authip,
 		 char *authdata,
 		 int (*callback_func)(struct authinfo *, void *),
 		 void *callback_arg)
@@ -53,6 +54,7 @@
 	strcat(strcat(strcpy(buf, "AUTH "), n), "\n");
 	strcat(strcat(buf, service), "\n");
 	strcat(strcat(buf, authtype), "\n");
+	strcat(strcat(buf, authip), "\n");
 	strcat(buf, authdata);
 
 	rc=authdaemondo(buf, callback_func, callback_arg);
Index: authdaemond.c
===================================================================
--- authdaemond.c	(revision 3248)
+++ authdaemond.c	(working copy)
@@ -728,6 +728,7 @@
 {
 	char *service;
 	char *authtype;
+	char *authip;
 	char	*pp;
 	struct authstaticinfolist *l;
 
@@ -737,6 +738,9 @@
 	authtype=p;
 	if ((p=strchr(p, '\n')) == 0)	return;
 	*p++=0;
+	authip=p;
+	if ((p=strchr(p, '\n')) == 0)	return;
+	*p++=0;
 
 	pp=malloc(strlen(p)+1);
 	if (!pp)
@@ -745,7 +749,7 @@
 		return;
 	}
 
-	DPRINTF("received auth request, service=%s, authtype=%s", service, authtype);
+	DPRINTF("received auth request, service=%s, authtype=%s, authip=%s", service, authtype, authip);
 	for (l=modulelist; l; l=l->next)
 	{
 		struct authstaticinfo *auth=l->info;
@@ -754,7 +758,7 @@
 
 		DPRINTF("%s: trying this module", modname);
 
-		rc=(*auth->auth_func)(service, authtype,
+		rc=(*auth->auth_func)(service, authtype, authip,
 				      strcpy(pp, p),
 				      &printauth, &fd);
 
Index: authcustom.c
===================================================================
--- authcustom.c	(revision 3248)
+++ authcustom.c	(working copy)
@@ -57,7 +57,8 @@
 }
 #endif
 
-int auth_custom(const char *service, const char *authtype, char *authdata,
+int auth_custom(const char *service, const char *authtype, const char *authip,
+		char *authdata,
 		int (*callback_func)(struct authinfo *, void *),
 		void *callback_arg)
 {
Index: authstaticlist.h
===================================================================
--- authstaticlist.h	(revision 3248)
+++ authstaticlist.h	(working copy)
@@ -21,7 +21,7 @@
 
 struct authstaticinfo {
 	const char *auth_name;
-	int (*auth_func)(const char *, const char *, char *,
+	int (*auth_func)(const char *, const char *, const char *, char *,
 			 int (*)(struct authinfo *, void *),
 			 void *);
 	int (*auth_prefunc)(const char *, const char *,

Reply via email to