[dovecot-cvs] dovecot/src/lib env-util.c,NONE,1.1 env-util.h,NONE,1.1 Makefile.am,1.14,1.15 restrict-access.c,1.2,1.3

cras at procontrol.fi cras at procontrol.fi
Tue Nov 26 21:49:08 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv2066/lib

Modified Files:
	Makefile.am restrict-access.c 
Added Files:
	env-util.c env-util.h 
Log Message:
Created env_put() and env_clean() for a bit easier handling of environment
variables.



--- NEW FILE: env-util.c ---
/*
 env-util.c : Environment variable handling

    Copyright (c) 2002 Timo Sirainen

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "lib.h"
#include "env-util.h"

#include <stdlib.h>

static Pool pool = NULL;

void env_put(const char *env)
{
	if (pool == NULL)
		pool = pool_create("Environment", 1024, FALSE);

	putenv(p_strdup(pool, env));
}

void env_clean(void)
{
	extern char **environ;

	if (environ != NULL)
		*environ = NULL;

	pool_unref(pool);
	pool = NULL;
}

--- NEW FILE: env-util.h ---
#ifndef __ENV_UTIL_H
#define __ENV_UTIL_H

/* Add new environment variable. Wrapper to putenv(). Note that calls to this
   function allocates memory which isn't free'd until env_clean() is called. */
void env_put(const char *env);
/* Clear all environment variables. */
void env_clean(void);

#endif

Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Makefile.am	26 Nov 2002 18:39:57 -0000	1.14
+++ Makefile.am	26 Nov 2002 19:49:06 -0000	1.15
@@ -5,6 +5,7 @@
 	base64.c \
 	compat.c \
 	data-stack.c \
+	env-util.c \
 	failures.c \
 	fdpass.c \
 	file-lock.c \
@@ -50,6 +51,7 @@
 	base64.h \
 	compat.h \
 	data-stack.h \
+	env-util.h \
 	failures.h \
 	fdpass.h \
 	file-lock.h \

Index: restrict-access.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/restrict-access.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- restrict-access.c	6 Oct 2002 11:03:24 -0000	1.2
+++ restrict-access.c	26 Nov 2002 19:49:06 -0000	1.3
@@ -23,6 +23,7 @@
 
 #include "lib.h"
 #include "restrict-access.h"
+#include "env-util.h"
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -33,12 +34,12 @@
 			     const char *chroot_dir)
 {
 	if (user != NULL && *user != '\0')
-		putenv((char *) t_strconcat("USER=", user, NULL));
+		env_put(t_strconcat("USER=", user, NULL));
 	if (chroot_dir != NULL && *chroot_dir != '\0')
-		putenv((char *) t_strconcat("CHROOT=", chroot_dir, NULL));
+		env_put(t_strconcat("CHROOT=", chroot_dir, NULL));
 
-	putenv((char *) t_strdup_printf("SETUID=%ld", (long) uid));
-	putenv((char *) t_strdup_printf("SETGID=%ld", (long) gid));
+	env_put(t_strdup_printf("SETUID=%ld", (long) uid));
+	env_put(t_strdup_printf("SETGID=%ld", (long) gid));
 }
 
 void restrict_access_by_env(void)




More information about the dovecot-cvs mailing list