[dovecot-cvs] dovecot/src/lib env-util.c,1.6,1.7 env-util.h,1.1,1.2 restrict-access.c,1.8,1.9 restrict-access.h,1.2,1.3

cras at procontrol.fi cras at procontrol.fi
Fri Feb 21 15:01:58 EET 2003


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

Modified Files:
	env-util.c env-util.h restrict-access.c restrict-access.h 
Log Message:
Added env_remove() and restrict_access_clear_env().



Index: env-util.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/env-util.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- env-util.c	5 Jan 2003 13:09:51 -0000	1.6
+++ env-util.c	21 Feb 2003 13:01:55 -0000	1.7
@@ -39,6 +39,26 @@
 		i_fatal("Environment full, can't add: %s", env);
 }
 
+void env_remove(const char *env)
+{
+	extern char **environ;
+	size_t len;
+
+	if (environ == NULL)
+		return;
+
+	len = strlen(env);
+	for (; *environ != NULL; environ++) {
+		if (strncmp(*environ, env, len) == 0 &&
+		    (*environ)[len] == '=') {
+			char **p;
+
+			for (p = environ; *p != NULL; p++)
+				p[0] = p[1];
+		}
+	}
+}
+
 void env_clean(void)
 {
 	extern char **environ;

Index: env-util.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/env-util.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- env-util.h	26 Nov 2002 19:49:06 -0000	1.1
+++ env-util.h	21 Feb 2003 13:01:55 -0000	1.2
@@ -4,6 +4,8 @@
 /* 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);
+/* Remove environment variable. */
+void env_remove(const char *env);
 /* Clear all environment variables. */
 void env_clean(void);
 

Index: restrict-access.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/restrict-access.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- restrict-access.c	14 Jan 2003 02:03:56 -0000	1.8
+++ restrict-access.c	21 Feb 2003 13:01:55 -0000	1.9
@@ -42,6 +42,14 @@
 	env_put(t_strdup_printf("RESTRICT_SETGID=%s", dec2str(gid)));
 }
 
+void restrict_access_clear_env(void)
+{
+	env_remove("RESTRICT_USER");
+	env_remove("RESTRICT_CHROOT");
+	env_remove("RESTRICT_SETUID");
+	env_remove("RESTRICT_SETGID");
+}
+
 void restrict_access_by_env(int disallow_root)
 {
 	const char *env;

Index: restrict-access.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/restrict-access.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- restrict-access.h	18 Dec 2002 04:00:01 -0000	1.2
+++ restrict-access.h	21 Feb 2003 13:01:55 -0000	1.3
@@ -6,6 +6,9 @@
 void restrict_access_set_env(const char *user, uid_t uid, gid_t gid,
 			     const char *chroot_dir);
 
+/* clear the environment variables set by restrict_access_set_env() */
+void restrict_access_clear_env(void);
+
 /* chroot, setuid() and setgid() based on environment variables.
    If disallow_roots is TRUE, we'll kill ourself if we didn't have the
    environment settings and we have root uid or gid. */




More information about the dovecot-cvs mailing list