a tiny fix to Python hooks in INN

Ilya Etingof ilya at glas.net
Thu Dec 2 11:06:07 UTC 1999



Greetings,

While being coding Python authentication hooks into nnrpd, I've noticed
that configure.in doesn't link in libraries used by [optional] compiled 
in Python modules.

Also, setenv(3) function (used in innd/python.c) doesn't exist on SysV
machines so I coded a plug-in replacement for it.

I'm attaching a patch to 11-24_03-01 snapshot against these two problems.
Please, let me know if I should commit my fixes to some other place rather
than to this list.

Thanks,
ilya


-- Attached file included as plaintext by Listar --
-- File: inn-1999-11-24_03-01.fix

*** configure.in%	Tue Nov 23 04:31:37 1999
--- configure.in	Thu Dec  2 00:56:52 1999
***************
*** 489,495 ****
      py_libs=`grep '^LIBS=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
      py_libc=`grep '^LIBC=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
      py_libm=`grep '^LIBM=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
!     PYTHON_LIB="-L$py_libdir/config $py_libs $py_libc $py_libm -lpython$py_ver"
      PYTHON_LIB=`echo $PYTHON_LIB | sed -e 's/[ \\t]*/ /g'`
      AC_MSG_RESULT($py_libdir)
  else
--- 489,497 ----
      py_libs=`grep '^LIBS=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
      py_libc=`grep '^LIBC=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
      py_libm=`grep '^LIBM=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
!     py_liblocalmod=`grep '^LOCALMODLIBS=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
!     py_libbasemod=`grep '^BASEMODLIBS=' $py_libdir/config/Makefile | sed -e 's/^.*=//'`
!     PYTHON_LIB="-L$py_libdir/config $py_libs $py_libc $py_libm -lpython$py_ver $py_liblocalmod $py_libbasemod"
      PYTHON_LIB=`echo $PYTHON_LIB | sed -e 's/[ \\t]*/ /g'`
      AC_MSG_RESULT($py_libdir)
  else
***************
*** 802,808 ****
  
  dnl If we can't find any of the following, we have replacements for them.
  AC_REPLACE_FUNCS(getopt inet_aton inet_ntoa pread pwrite strcasecmp \
!                  strdup strerror strspn)
  
  MISSING_OBJ="$LIBOBJS"
  MISSING_SRC=`echo "$MISSING_OBJ" | sed 's/\.o/.c/g'`
--- 804,810 ----
  
  dnl If we can't find any of the following, we have replacements for them.
  AC_REPLACE_FUNCS(getopt inet_aton inet_ntoa pread pwrite strcasecmp \
!                  strdup strerror strspn setenv)
  
  MISSING_OBJ="$LIBOBJS"
  MISSING_SRC=`echo "$MISSING_OBJ" | sed 's/\.o/.c/g'`
*** lib/setenv.c%	Thu Dec  2 13:10:43 1999
--- lib/setenv.c	Thu Dec  2 12:59:03 1999
***************
*** 0 ****
--- 1,114 ----
+ /*  $Revision$
+ **
+ **  This is a plug-in replacement for setenv() libc function which is
+ **  native to BSD 4.3 systems. Derived from setenv.c C module taken
+ **  from GNU C library.
+ **
+ **  Written by Ilya Etingof <ilya at glas.net>, 1999.
+ **
+ */
+ 
+ #include <stdlib.h>
+ #include <errno.h>
+ 
+ extern char	**environ;
+ 
+ #if !defined(HAVE_GNU_LD) && !defined (__ELF__)
+ #define	__environ	environ
+ #endif
+ 
+ /*
+ ** Set environmental variable either overriding its existing value
+ ** or not depending of the overwrite flag setting.
+ */
+ int setenv(const char *name, const char *value, int overwrite)
+ {
+ 	register char **ep;
+ 	register size_t size = 0;
+ 	size_t namelen = strlen (name);
+ 	size_t vallen = strlen (value);
+ 	int result = 0;
+ 
+ 	/* Already have this variable set? */
+ 	for (ep = __environ; *ep != NULL; ++ep)
+ 	{
+ 		if (!memcmp (*ep, name, namelen) && (*ep)[namelen] == '=')
+ 			break;
+ 		else
+ 			++size;
+ 	}
+   
+ 	/* No such variable in environment, adding one... */
+ 	if (*ep == NULL)
+ 	{
+ 		static char **last_environ = NULL;
+ 		char **new_environ = (char **) malloc((size + 2) * sizeof(char *));
+ 
+ 		/* Check for memory allocation problems */
+ 		if (new_environ == NULL)
+ 		{
+ 			result = -1;
+ 			goto do_return;
+ 		}
+ 
+ 		/* Copy old pointers to new chunk of memory */
+ 		(void) memcpy(new_environ, __environ, size * sizeof(char *));
+ 
+ 		/* Allocate new chunk of memory for new variable */
+ 		new_environ[size] = malloc (namelen + 1 + vallen + 1);
+ 
+ 		/* Check for memory allocation problems */
+ 		if (new_environ[size] == NULL)
+ 		{
+ 			free (new_environ);
+ 			errno = ENOMEM;
+ 			result = -1;
+ 			goto do_return;
+ 		}
+ 
+ 		/* Copy given variable & value into new environment entry */
+ 		memcpy (new_environ[size], name, namelen);
+ 		new_environ[size][namelen] = '=';
+ 		memcpy (&new_environ[size][namelen + 1], value, vallen + 1);
+ 
+ 		/* Terminate the array of pointers */
+ 		new_environ[size + 1] = NULL;
+ 
+ 		/* Release old environment */
+ 		if (last_environ != NULL)
+ 		{
+ 			free (last_environ);
+ 		}
+ 
+ 		/* Replace old environment with new one */
+ 		last_environ = new_environ;
+ 		__environ = new_environ;
+ 	}
+ 	/* Variable already exists and overwrite flag set */
+ 	else if (overwrite)
+ 	{
+ 		size_t len = strlen (*ep);
+ 
+ 		/* See it new value fits into old chunk */
+ 		if (len < namelen + 1 + vallen)
+ 		{
+ 			char *new = malloc (namelen + 1 + vallen + 1);
+ 
+ 			/* Need to re-allocate chunk, see if it worked out */
+ 			if (new == NULL)
+ 			{
+ 				result = -1;
+ 				goto do_return;
+ 			}
+ 			*ep = new;
+ 		}
+ 
+ 		/* Copy given variable & value into new environment entry */
+ 		memcpy (*ep, name, namelen);
+ 		(*ep)[namelen] = '=';
+ 		memcpy (&(*ep)[namelen + 1], value, vallen + 1);
+ 	    }
+ 
+ do_return:
+ 	  return result;
+ }



More information about the inn-workers mailing list