@@ -0,0 +1,39423 @@
+diff -ruN qmail-1.03-orig/alloc.c qmail-1.03-ldap-20060201-orig/alloc.c
+--- qmail-1.03-orig/alloc.c 1998-06-15 12:53:16.000000000 +0200
++++ qmail-1.03-ldap-20060201-orig/alloc.c 2006-02-25 11:00:55.000000000 +0100
+@@ -1,32 +1,18 @@
++#include <stdlib.h>
+ #include "alloc.h"
+ #include "error.h"
+-extern char *malloc();
+-extern void free();
+
+-#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
+-#define SPACE 4096 /* must be multiple of ALIGNMENT */
+-
+-typedef union { char irrelevant[ALIGNMENT]; double d; } aligned;
+-static aligned realspace[SPACE / ALIGNMENT];
+-#define space ((char *) realspace)
+-static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
+-
+-/*@null@*//*@out@*/char *alloc(n)
++/*@null@*//*@out@*/void *alloc(n)
+ unsigned int n;
+ {
+- char *x;
+- n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
+- if (n <= avail) { avail -= n; return space + avail; }
++ void *x;
+ x = malloc(n);
+ if (!x) errno = error_nomem;
+ return x;
+ }
+
+ void alloc_free(x)
+-char *x;
++void *x;
+ {
+- if (x >= space)
+- if (x < space + SPACE)
+- return; /* XXX: assuming that pointers are flat */
+ free(x);
+ }
+diff -ruN qmail-1.03-orig/alloc.h qmail-1.03-ldap-20060201-orig/alloc.h
+--- qmail-1.03-orig/alloc.h 1998-06-15 12:53:16.000000000 +0200
++++ qmail-1.03-ldap-20060201-orig/alloc.h 2006-02-25 11:00:55.000000000 +0100
+@@ -1,8 +1,8 @@
+ #ifndef ALLOC_H
+ #define ALLOC_H
+
+-extern /*@null@*//*@out@*/char *alloc();
+-extern void alloc_free();
+-extern int alloc_re();
++extern /*@null@*//*@out@*/void *alloc(unsigned int);
++extern void alloc_free(void *);
++extern int alloc_re(char **, unsigned int, unsigned int);
+
+ #endif
+diff -ruN qmail-1.03-orig/auth_imap.c qmail-1.03-ldap-20060201-orig/auth_imap.c
+--- qmail-1.03-orig/auth_imap.c 1970-01-01 01:00:00.000000000 +0100
++++ qmail-1.03-ldap-20060201-orig/auth_imap.c 2006-02-25 11:00:55.000000000 +0100
+@@ -0,0 +1,354 @@
++/*
++ * Copyright (c) 2000-2004 Claudio Jeker,
++ * Internet Business Solutions AG, CH-8005 Zürich, Switzerland
++ *
++ * 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 "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
++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 (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);
|