Re: looking for qmail-ldap-1.03-20060201-dovecot.v4.patch

Ibrahim Harrani <[email protected]>
Newsgroups gmane.mail.qmail.ldap
Message-ID <[email protected]>
Hi Thomas,

I have one copy of qmail-ldap-1.03-20060201-dovecot.v0.5.patch


On Mon, Feb 8, 2010 at 10:16 AM, Tomas Kuliavas <[email protected]
> wrote:

> Hi,
>
> I am looking for qmail-ldap-1.03-20060201-dovecot.v4.patch patch posted on
> qmail-ldap list in December 2007
> (http://marc.info/?l=qmail-ldap&m=119768286714255&w=2).
> japc.uncovering.org site is dead and archive.org does not have copy of
> that file.
>
> I've found qmail-ldap-1.03-20060201-dovecot.patch
> in marc.info archives, but I want to see changes done in
> qmail-ldap-1.03-20060201-dovecot.v4.patch or
> qmail-ldap-1.03-20060201-dovecot.v0.5.patch
>
> --
> Tomas
>
>
>
qmail-ldap-1.03-20060201-dovecot.v0.5.patch (application/octet-stream, 16.5 KB)
diff -burN qmail-1.03-vanilla/auth_dovecot.c qmail-1.03/auth_dovecot.c
--- qmail-1.03-vanilla/auth_dovecot.c	1970-01-01 01:00:00.000000000 +0100
+++ qmail-1.03/auth_dovecot.c	2008-01-17 00:11:45.000000000 +0000
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 2000-2004 Claudio Jeker,
+ *      Internet Business Solutions AG, CH-8005 Zürich, Switzerland
+ *
+ * Copyright (c) 2007 Jose Celestino
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Internet Business
+ *      Solutions AG and its contributors.
+ * 4. Neither the name of the author nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/* auth_imap.c for courier-imap */
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <unistd.h>
+#include "alloc.h"
+#include "byte.h"
+#include "env.h"
+#include "error.h"
+#include "exit.h"
+#include "fmt.h"
+#include "pbsexec.h"
+#include "qldap-debug.h"
+#include "qldap-errno.h"
+#include "qmail-ldap.h"
+#include "readwrite.h"
+#include "scan.h"
+#include "sgetopt.h"
+#include "sig.h"
+#include "str.h"
+#include "stralloc.h"
+#include "substdio.h"
+#include "timeoutread.h"
+#include "ip.h"
+
+#include <stdio.h>
+#include "auth_mod.h"
+
+#ifndef PORT_IMAP /* this is for testing purposes */
+#define PORT_IMAP	143
+#endif
+
+const unsigned int auth_port = PORT_IMAP;
+
+#define UP_LEN 1024
+static char auth_up[UP_LEN];
+static unsigned int auth_uplen;
+static int auth_argc;
+static char **auth_argv;
+
+void
+set_quota(void)
+{
+  char *qt, *t, *dversion;
+  char *envquota;
+  char   quota_storage[FMT_ULONG];
+  unsigned long  qstorage;
+  unsigned short quota_new = 0;
+  stralloc qenv = {0};
+
+  if (!(qt = env_get(ENV_QUOTA)))
+    return;
+
+  dversion = env_get("DOVECOT_VERSION");
+
+  if (dversion && str_diffn(dversion, "1.0", 3) != 0)
+	quota_new = 1;
+
+  if (!stralloc_copys(&qenv,quota_new?"*":"maildir"))
+    auth_error(ERRNO);
+
+  t = qt;
+  for (;*qt;qt++) {
+    if (*qt == 'S') {
+      *qt = '\0';
+      if (!stralloc_cats(&qenv,":storage=")) auth_error(ERRNO);
+      scan_ulong(t,&qstorage); qstorage/=1024; /* to KB */
+      quota_storage[fmt_ulong(quota_storage,(unsigned long)qstorage)] = 0;
+      if (!stralloc_cats(&qenv, quota_storage)) auth_error(ERRNO);
+      t = qt + 1;
+    } else if (*qt == 'C') {
+      *qt = '\0';
+      if (!stralloc_cats(&qenv, ":messages=")) auth_error(ERRNO);
+      if (!stralloc_cats(&qenv, t+1)) auth_error(ERRNO);
+    }
+
+  }
+
+  if (!stralloc_0(&qenv)) auth_error(ERRNO);
+
+  if (!env_put2("AUTH_DOVECOT", "v0.5")) auth_error(ERRNO);
+  if (quota_new) {
+    if (!env_put2("userdb_quota_rule", qenv.s)) auth_error(ERRNO);
+    if (!env_put2("EXTRA", "userdb_quota_rule")) auth_error(ERRNO);
+  } else {
+    if (!env_put2("userdb_quota", qenv.s)) auth_error(ERRNO);
+    if (!env_put2("EXTRA", "userdb_quota")) auth_error(ERRNO);
+  }
+}
+
+void
+auth_init(int argc, char **argv, stralloc *login, stralloc *authdata)
+{
+	char		*a, *s, *t, *l, *p;
+	int		 waitstat, opt, n;
+	unsigned int	 u;
+
+	while ((opt = getopt(argc, argv, "d:")) != opteof) {
+		switch (opt) {
+		case 'd':
+			pbstool = optarg;
+			break;
+		default:
+			auth_error(AUTH_CONF);
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if (argc < 1)
+		auth_error(AUTH_CONF);
+	auth_argc = argc;
+	auth_argv = argv;
+
+	a = env_get("AUTHENTICATED");
+	if (a && *a) {  /* Already a good guy */
+		logit(8, "auth_init: allready authenticated\n");
+		execvp(*argv, argv);
+		auth_error(AUTH_EXEC);
+	}
+	
+#if 1
+	/*
+	 * remove all zombies, why should I do that?
+	 * Because courier makes zombies for breakfast
+	 */
+	sig_childdefault();
+	while (wait(&waitstat) >= 0) ;
+#endif
+	for (auth_uplen = 0;;) {
+		do {
+			n = read(3, auth_up + auth_uplen,
+			    sizeof(auth_up) - auth_uplen);
+		} while ((n == -1) && (errno == EINTR));
+		if (n == -1)
+			auth_error(ERRNO);
+		if (n == 0) break;
+		auth_uplen += n;
+		if (auth_uplen >= sizeof(auth_up)) {
+			auth_error(PANIC);
+		}
+	}
+	close(3);
+	auth_up[auth_uplen] = '\0';
+	
+	/*
+	 * get the different fields: service<NL>AUTHTYPE<NL>AUTHDATA
+	 */
+	u = 0;
+	s = auth_up; /* ignore service field */
+	while (auth_up[u] && auth_up[u] != '\n' ) u++;
+  if (auth_up[u] != '\n') { /* no service<nl>type<nl> */
+    u = 0;
+    goto plainint;
+  }
+	if (u >= auth_uplen)
+		auth_error(NEEDED);
+	auth_up[u++] = '\0';
+	t = auth_up + u; /* type has to be "login" else fail ... */
+	while (auth_up[u] && auth_up[u] != '\n' ) u++;
+	if (u >= auth_uplen)
+		auth_error(NEEDED);
+	auth_up[u++] = '\0';
+	if (str_diff("login", t)) {
+		/* 
+		 * this modul supports only "login"-type,
+		 * fail with AUTH_TYPE, so the 
+		 * next modul is called, perhaps with greater success
+		 */
+		auth_fail("unknown", AUTH_TYPE);
+	}
+plainint:
+	l = auth_up + u; /* next login */
+	while (auth_up[u] && auth_up[u] != '\n' ) u++;
+	if (u >= auth_uplen)
+		auth_error(NEEDED);
+	auth_up[u++] = '\0';
+	p = auth_up + u; /* and the password */
+	while (auth_up[u] && auth_up[u] != '\n' ) u++;
+	if (u >= auth_uplen)
+		auth_error(NEEDED);
+	auth_up[u++] = '\0';
+	if (u > auth_uplen) /* paranoia */
+		auth_error(NEEDED);
+
+	/* copy the login and password into the coresponding structures */
+	if (!stralloc_copys(login, l))
+		auth_error(ERRNO);
+	if (!stralloc_0(login))
+		auth_error(ERRNO);
+
+	if (!stralloc_copys(authdata, p))
+		auth_error(ERRNO);
+	if (!stralloc_0(authdata))
+		auth_error(ERRNO);
+
+}
+
+void
+auth_fail(const char *login, int reason)
+{
+	unsigned int	 i;
+	int		 pi[2], n;
+	char		*t = auth_up;
+	
+	logit(2, "warning: auth_fail: user %s failed\n", login);
+	if (reason == NOSUCH || reason == AUTH_TYPE) {
+		logit(4, "warning: auth_fail: %s\n", qldap_err_str(reason));
+		if (!env_unset("AUTHENTICATED"))
+			auth_error(ERRNO);
+		for (i=0; i < auth_uplen; i++)
+			if (!auth_up[i])
+				auth_up[i] = '\n';
+		close(3);
+		if (pipe(pi) == -1)
+			auth_error(ERRNO);
+		if (pi[0] != 3) /* be serious, we closed 3 so ... */
+			auth_error(PANIC);
+		switch (fork()) {
+		case -1:
+			auth_error(ERRNO);
+		case 0:
+			break;
+		default: /* parent process */
+			close(pi[1]);
+			sig_pipedefault();
+			/* start next auth module */
+			execvp(*auth_argv, auth_argv);
+			auth_error(AUTH_EXEC);
+		}
+		/* child process */
+		close(pi[0]);
+		while (auth_uplen) {
+			n = subwrite(pi[1],t,auth_uplen);
+			if (n == -1) {
+				if (errno == error_intr) continue;
+				/* note that some data may have been written */
+			}
+			t += n;
+			auth_uplen -= n;
+		}
+		byte_zero(auth_up, sizeof(auth_up));
+		close(pi[1]);
+		_exit(0);
+	}
+	auth_error(reason); /* complete failure */
+}
+
+void
+auth_success(const char *login)
+{
+	byte_zero(auth_up, sizeof(auth_up));
+	
+	/* pop befor smtp */
+	pbsexec();
+	
+	/* set quota env */
+	set_quota();
+
+	/* start imap process */
+	execvp(*(auth_argv+1), auth_argv+1);
+
+	auth_error(AUTH_EXEC);
+	/* end */
+}
+
+void auth_error(int errnum)
+{
+	char envname[FMT_ULONG+8];
+	char *env, *n, *n2;
+	char **argvs;
+	unsigned long numarg, i;
+	
+	/* XXX under courier-imap it is not simple to give the correct failure
+	 * XXX back to the user, perhaps somebody has a good idea */
+
+	byte_zero(auth_up, sizeof(auth_up));
+	
+	logit(2, "warning: auth_error: authorization failed (%s)\n",
+		   qldap_err_str(errnum));
+	if (!(env = env_get("AUTHARGC")))
+		_exit(111);
+	scan_ulong(env, &numarg);
+	argvs = (char **) alloc((numarg+1) * sizeof(char *));
+	n = envname;
+	n += fmt_str(n, "AUTHARGV");
+	for (i = 0; i < numarg; i++) {
+		n2 = n;
+		n2 += fmt_ulong(n2, i);
+		*n2 = 0;
+		if (!(argvs[i] = env_get(envname)))
+			_exit(111);
+	}
+	argvs[i+1] = (char *)0;
+#if 0
+	/*
+	 * can no longer find AUTHUSER in authlib(7) of courier-imap 1.7.2
+	 * but it still exists. So what should I do? Drop my pants?
+	 */
+	if (!(env = env_get("AUTHUSER")))
+		_exit(100);
+#endif
+	execv(*argvs, argvs);
+	_exit(111);
+	
+}
+
+char *
+auth_aliasempty(void)
+{
+	if (auth_argc > 0)
+		return auth_argv[0];
+	return (char *)0;
+}
+
+#ifdef QLDAP_CLUSTER
+void
+auth_forward_pre(struct ip_address *ip)
+{
+	char host[IPFMT];
+
+	/* build the ip string and call auth_forward already
+     * as we have all we need for dovecot forwarding */
+	host[ip_fmt(host,ip)] = '\0';
+	auth_forward(0, host, NULL);
+}
+
+void
+auth_forward(int fd, char *host, char *s __attribute__((unused)))
+{
+	byte_zero(auth_up, sizeof(auth_up));
+
+	/* not to be userdb_ prefixed */
+	if (!env_put2("proxy", "1")) auth_error(ERRNO);
+	if (!env_put2("host", host)) auth_error(ERRNO);
+
+ 	if (!env_put2("EXTRA", "proxy host")) auth_error(ERRNO);
+
+    /* pass it on to dovecot, it should forward */
+    execvp(*(auth_argv+1), auth_argv+1);
+
+	/* should never be reached */
+    auth_error(AUTH_EXEC);
+    /* end */
+}
+
+#endif /* QLDAP_CLUSTER */
+
diff -burN qmail-1.03-vanilla/auth_imap.c qmail-1.03/auth_imap.c
--- qmail-1.03-vanilla/auth_imap.c	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/auth_imap.c	2008-01-16 22:02:07.000000000 +0000
@@ -328,6 +328,11 @@
 }
 
 void
+auth_forward_pre(struct ip_address *ip __attribute__((unused)))
+{
+}
+
+void
 auth_forward(int fd, char *login, char *passwd)
 {
 	char *tag;
diff -burN qmail-1.03-vanilla/auth_mod.c qmail-1.03/auth_mod.c
--- qmail-1.03-vanilla/auth_mod.c	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/auth_mod.c	2008-01-16 22:02:07.000000000 +0000
@@ -374,6 +374,8 @@
 	if (ipme_is(&ip.ix[0].ip) == 1)
 		auth_error(BADCLUSTER);
 
+	auth_forward_pre(&ip.ix[0].ip);
+
 	ffd = socket(AF_INET, SOCK_STREAM, 0);
 	if (ffd == -1)
 		auth_error(ERRNO);
diff -burN qmail-1.03-vanilla/auth_pop.c qmail-1.03/auth_pop.c
--- qmail-1.03-vanilla/auth_pop.c	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/auth_pop.c	2008-01-16 22:02:07.000000000 +0000
@@ -217,6 +217,11 @@
 	auth_error(BADCLUSTER);
 }
 
+void
+auth_forward_pre(struct ip_address *ip __attribute__((unused)))
+{
+}
+
 void auth_forward(int fd, char *login, char *passwd)
 {
 	char buf[512];
diff -burN qmail-1.03-vanilla/hier.c qmail-1.03/hier.c
--- qmail-1.03-vanilla/hier.c	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/hier.c	2008-01-16 22:02:07.000000000 +0000
@@ -233,6 +233,7 @@
   c(auto_qmail,"bin","pinq",auto_uido,auto_gidq,0755);
   c(auto_qmail,"bin","qmail-reply",auto_uido,auto_gidq,0755);
   c(auto_qmail,"bin","qmail-quotawarn",auto_uido,auto_gidq,0755);
+  c(auto_qmail,"bin","auth_dovecot",auto_uido,auto_gidq,04755);
   c(auto_qmail,"bin","auth_pop",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","auth_imap",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","auth_smtp",auto_uido,auto_gidq,0755);
diff -burN qmail-1.03-vanilla/install-big.c qmail-1.03/install-big.c
--- qmail-1.03-vanilla/install-big.c	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/install-big.c	2008-01-16 22:02:07.000000000 +0000
@@ -233,6 +233,7 @@
   c(auto_qmail,"bin","pinq",auto_uido,auto_gidq,0755);
   c(auto_qmail,"bin","qmail-reply",auto_uido,auto_gidq,0755);
   c(auto_qmail,"bin","qmail-quotawarn",auto_uido,auto_gidq,0755);
+  c(auto_qmail,"bin","auth_dovecot",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","auth_pop",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","auth_imap",auto_uido,auto_gidq,0700);
   c(auto_qmail,"bin","auth_smtp",auto_uido,auto_gidq,0755);
diff -burN qmail-1.03-vanilla/Makefile qmail-1.03/Makefile
--- qmail-1.03-vanilla/Makefile	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/Makefile	2008-01-16 22:02:07.000000000 +0000
@@ -90,8 +90,8 @@
 
 default: it ldap
 
-ldap: qmail-quotawarn qmail-reply auth_pop auth_imap auth_smtp digest \
-qmail-ldaplookup pbsadd pbscheck pbsdbd qmail-todo qmail-forward \
+ldap: qmail-quotawarn qmail-reply auth_pop auth_dovecot auth_imap auth_smtp \
+digest qmail-ldaplookup pbsadd pbscheck pbsdbd qmail-todo qmail-forward \
 qmail-secretary qmail-group qmail-verify condwrite qmail-cdb \
 qmail-imapd.run qmail-pbsdbd.run qmail-pop3d.run qmail-qmqpd.run \
 qmail-smtpd.run qmail.run qmail-imapd-ssl.run qmail-pop3d-ssl.run \
@@ -113,6 +113,29 @@
 compile alloc_re.c alloc.h byte.h
 	./compile alloc_re.c
 
+auth_dovecot: \
+load auth_dovecot.o auth_mod.o checkpassword.o passwd.o digest_md4.o \
+digest_md5.o digest_rmd160.o digest_sha1.o base64.o read-ctrl.o getopt.a \
+control.o dirmaker.o mailmaker.o qldap.a localdelivery.o locallookup.o \
+pbsexec.o constmap.o getln.a strerr.a substdio.a stralloc.a env.a wait.a \
+dns.o ip.o ipalloc.o ipme.o alloc.a str.a case.a fs.a error.a timeoutconn.o \
+timeoutread.o ndelay.a open.a sig.a prot.o auto_uids.o auto_qmail.o \
+dns.lib socket.lib stralloc.a
+	./load auth_dovecot auth_mod.o checkpassword.o passwd.o digest_md4.o \
+	digest_md5.o digest_rmd160.o digest_sha1.o base64.o read-ctrl.o \
+	getopt.a control.o dirmaker.o mailmaker.o qldap.a localdelivery.o \
+	locallookup.o pbsexec.o constmap.o getln.a strerr.a substdio.a \
+	stralloc.a env.a wait.a dns.o ip.o ipalloc.o ipme.o alloc.a str.a \
+	case.a fs.a error.a timeoutconn.o timeoutread.o ndelay.a open.a \
+	sig.a prot.o auto_uids.o auto_qmail.o $(LDAPLIBS) $(SHADOWLIBS) \
+	`cat dns.lib` `cat socket.lib`
+
+auth_dovecot.o: \
+compile auth_dovecot.c alloc.h byte.h env.h error.h exit.h fmt.h pbsexec.h \
+qldap-debug.h qldap-errno.h qmail-ldap.h readwrite.h scan.h sgetopt.h \
+sig.h str.h stralloc.h substdio.h timeoutread.h auth_mod.h
+	./compile $(LDAPFLAGS) $(DEBUG) auth_dovecot.c
+
 auth_imap: \
 load auth_imap.o auth_mod.o checkpassword.o passwd.o digest_md4.o \
 digest_md5.o digest_rmd160.o digest_sha1.o base64.o read-ctrl.o getopt.a \
diff -burN qmail-1.03-vanilla/README.dovecot qmail-1.03/README.dovecot
--- qmail-1.03-vanilla/README.dovecot	1970-01-01 01:00:00.000000000 +0100
+++ qmail-1.03/README.dovecot	2008-01-16 22:02:07.000000000 +0000
@@ -0,0 +1,32 @@
+
+You have to configure auth as follows on dovecot.conf:
+
+  passdb checkpassword {
+    # Path for checkpassword binary
+    args = /var/qmail/bin/auth_dovecot ./Maildir/
+  }
+
+  userdb prefetch {
+  }
+
+Quota supported via:
+
+  plugin {
+    quota = maildir
+    # This one will be your default, auth_dovecot will
+	# overwrite it with what it gets from ldap
+    quota_rule = *:storage=1GB
+  }
+  
+Remember to have dirmaker configured (as you would for qmail) if *DIRMAKE
+is selected:
+
+root@mail:~# cat /var/qmail/control/dirmaker
+/var/qmail/bin/dirmaker
+root@mail:~# cat /var/qmail/bin/dirmaker
+#!/bin/sh
+/bin/mkdir -m 700 -p $1
+#EOF
+
+QLDAP_CLUSTER is supported throught dovecot's awesome proxy engine since patch v4.
+
diff -burN qmail-1.03-vanilla/TARGETS qmail-1.03/TARGETS
--- qmail-1.03-vanilla/TARGETS	2007-12-15 01:19:10.000000000 +0000
+++ qmail-1.03/TARGETS	2008-01-16 22:02:07.000000000 +0000
@@ -383,6 +383,8 @@
 check
 auth_imap
 Makefile.cdb-p
+auth_dovecot
+auth_dovecot.o
 auth_imap.o
 auth_mod.o
 auth_pop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.