#include <sys/types.h>
#include "env.h"
+#include "all-io.h"
#ifndef HAVE_ENVIRON_DECL
extern char **environ;
return ls;
}
+/*
+ * Use env_from_fd() to read environment from @fd.
+ *
+ * @fd must be /proc/<pid>/environ file.
+*/
+struct ul_env_list *env_from_fd(int fd)
+{
+ char *buf = NULL, *p;
+ ssize_t rc = 0;
+ struct ul_env_list *ls = NULL;
+
+ if ((rc = read_all_alloc(fd, &buf)) < 1)
+ return NULL;
+ buf[rc] = '\0';
+ p = buf;
+
+ while (rc > 0) {
+ ls = env_list_add(ls, p);
+ p += strlen(p) + 1;
+ rc -= strlen(p) + 1;
+ }
+
+ free(buf);
+ return ls;
+}
+
/*
* Use setenv() for all stuff in @ls.
*
if (strncmp(*cur, *bad, strlen(*bad)) == 0) {
if (org)
*org = env_list_add(*org, *cur);
- last = remote_entry(envp, cur - envp, last);
+ last = remove_entry(envp, cur - envp, last);
cur--;
break;
}
continue; /* OK */
if (org)
*org = env_list_add(*org, *cur);
- last = remote_entry(envp, cur - envp, last);
+ last = remove_entry(envp, cur - envp, last);
cur--;
break;
}
char *safe_getenv(const char *arg)
{
- uid_t ruid = getuid();
-
- if (ruid != 0 || (ruid != geteuid()) || (getgid() != getegid()))
+ if ((getuid() != geteuid()) || (getgid() != getegid()))
return NULL;
#ifdef HAVE_PRCTL
if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)