Somehow I attached the old patch to the last email, the correct patch courier-imap-setenv-4.patch is attached to this email.

Dave Diffenbaugh
Open System Solutions
Office of Information Technology
Rutgers University

On Fri, 25 Jul 2008, David Diffenbaugh wrote:

I've taken your suggestions and come up with the attached patch. It changes configure.in so that configure will check for setenv. It also changes the files that use setenv to only compile that code if setenv is available. Otherwise it will compile a mysetenv function which will use putenv. After applying the patch, autoconf and autoheader should be run in the tcpd directory. I also noticed but didn't make any changes to the file tcpd.c which makes use of putenv. This should probably use setenv on the systems which have it.

David Diffenbaugh
Open System Solutions
Office of Information Technology
Rutgers University

On Wed, 23 Jul 2008, Sam Varshavchik wrote:

David Diffenbaugh writes:

I found an error in the patch I just posted, I have attached the
correction. I had used sizeof() where it should have been strlen().

Linux documentation for putenv reads:

                  The string pointed to by string becomes part of
     the environment, so altering the string changes the environment.

You free()ing the string alters the environment, and this breaks on
Linux.

The Linux man page for putenv contains a bit of history of the various
versions of putenv and its behavior according to a number of historical
standards: http://manpages.courier-mta.org/htmlman3/putenv.3.html

Given all this mess, that's why the code was changed to use setenv(),
whose
semantics are somewhat more stable. This is not the correct solution for
this
issue, a different approach will probably be necessary -- something
that's
conditionally compiled only for Solaris 9.
diff -ruN tcpd/configure.in tcpd.new/configure.in
--- tcpd/configure.in   2008-07-25 13:00:07.000000000 -0400
+++ tcpd.new/configure.in       2008-07-25 13:01:06.000000000 -0400
@@ -158,7 +158,7 @@
 
 dnl Checks for library functions.
 
-AC_CHECK_FUNCS(setpgrp setpgid)
+AC_CHECK_FUNCS(setpgrp setpgid setenv)
 AC_CHECK_FUNC(setpgrp,
        [
        AC_FUNC_SETPGRP
diff -ruN tcpd/starttls.c tcpd.new/starttls.c
--- tcpd/starttls.c     2008-07-25 13:00:07.000000000 -0400
+++ tcpd.new/starttls.c 2008-07-25 13:00:38.000000000 -0400
@@ -80,6 +80,24 @@
 
 const char *printx509=0;
 
+#if HAVE_SETENV
+#else
+static void mysetenv (const char *name, const char *value, int overwrite)
+{
+        int length = strlen(name) + strlen(value) + 2;
+        char *buffer = malloc(length);
+        if (buffer == 0)
+        {
+                perror("malloc");
+                exit(1);
+        }
+        if (!overwrite && getenv(name)) return;
+        snprintf (buffer, length, "%s=%s", name, value);
+        putenv(buffer);
+        free(buffer);
+}
+#endif
+
 static void ssl_errmsg(const char *errmsg, void *dummy)
 {
        fprintf(errfp, "%s\n", errmsg);
@@ -275,7 +293,11 @@
                                 "TLS_SUBJECT_%s", n)]=0;
 
                if (dcs->set_subject)
+#if HAVE_SETENV
                        setenv(namebuf, v, 1);
+#else
+                        mysetenv(namebuf, v, 1);
+#endif
        }
 }
 
@@ -320,9 +342,13 @@
        }
 
        buf=tls_get_encryption_desc(ssl);
-
+#if HAVE_SETENV
        setenv("TLS_CONNECTED_PROTOCOL",
               buf ? buf:"(unknown)", 1);
+#else
+        mysetenv("TLS_CONNECTED_PROTOCOL",
+               buf ? buf:"(unknown)", 1);
+#endif
 
        if (buf)
                free(buf);
diff -ruN tcpd/tlsclient.c tcpd.new/tlsclient.c
--- tcpd/tlsclient.c    2008-07-25 13:00:07.000000000 -0400
+++ tcpd.new/tlsclient.c        2008-07-25 13:00:38.000000000 -0400
@@ -60,6 +60,24 @@
 #define SYSERRMSG (strncat(strcpy(cinfo->errmsg, "Failed: "), \
                strerror(errno), sizeof(cinfo->errmsg)-15))
 
+#if HAVE_SETENV
+#else
+static void mysetenv (const char *name, const char *value, int overwrite)
+{
+        int length = strlen(name) + strlen(value) + 2;
+        char *buffer = malloc(length);
+        if (buffer == 0)
+        {
+                perror("malloc");
+                exit(1);
+        }
+        if (!overwrite && getenv(name)) return;
+        snprintf (buffer, length, "%s=%s", name, value);
+        putenv(buffer);
+        free(buffer);
+}
+#endif
+
 void couriertls_init(struct couriertls_info *cinfo)
 {
        memset(cinfo, 0, sizeof(*cinfo));
@@ -272,8 +290,11 @@
                for (p=a; *p; p++)
                        if (*p >= 'a' && *p <= 'z')
                                *p -= 'a' - 'A';
-
+#if HAVE_SETENV
                setenv(a, b, 1);
+#else
+               mysetenv(a, b, 1);
+#endif
                free(a);
        }
 }
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Courier-imap mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-imap

Reply via email to