summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-08-18 05:36:45 +0000
committerDamien Miller <djm@mindrot.org>2017-08-23 19:47:06 +1000
commitde4ae07f12dabf8815ecede54235fce5d22e3f63 (patch)
treee62b3e975ed519f37c7cda4b5229bcffca73023f /session.c
parent643c2ad82910691b2240551ea8b14472f60b5078 (diff)
upstream commit
Move several subprocess-related functions from various locations to misc.c. Extend subprocess() to offer a little more control over stdio disposition. feedback & ok dtucker@ Upstream-ID: 3573dd7109d13ef9bd3bed93a3deb170fbfce049
Diffstat (limited to 'session.c')
-rw-r--r--session.c61
1 files changed, 1 insertions, 60 deletions
diff --git a/session.c b/session.c
index 698eaa879..cd03fd423 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.290 2017/06/24 06:34:38 djm Exp $ */ 1/* $OpenBSD: session.c,v 1.291 2017/08/18 05:36:45 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -825,65 +825,6 @@ check_quietlogin(Session *s, const char *command)
825} 825}
826 826
827/* 827/*
828 * Sets the value of the given variable in the environment. If the variable
829 * already exists, its value is overridden.
830 */
831void
832child_set_env(char ***envp, u_int *envsizep, const char *name,
833 const char *value)
834{
835 char **env;
836 u_int envsize;
837 u_int i, namelen;
838
839 if (strchr(name, '=') != NULL) {
840 error("Invalid environment variable \"%.100s\"", name);
841 return;
842 }
843
844 /*
845 * If we're passed an uninitialized list, allocate a single null
846 * entry before continuing.
847 */
848 if (*envp == NULL && *envsizep == 0) {
849 *envp = xmalloc(sizeof(char *));
850 *envp[0] = NULL;
851 *envsizep = 1;
852 }
853
854 /*
855 * Find the slot where the value should be stored. If the variable
856 * already exists, we reuse the slot; otherwise we append a new slot
857 * at the end of the array, expanding if necessary.
858 */
859 env = *envp;
860 namelen = strlen(name);
861 for (i = 0; env[i]; i++)
862 if (strncmp(env[i], name, namelen) == 0 && env[i][namelen] == '=')
863 break;
864 if (env[i]) {
865 /* Reuse the slot. */
866 free(env[i]);
867 } else {
868 /* New variable. Expand if necessary. */
869 envsize = *envsizep;
870 if (i >= envsize - 1) {
871 if (envsize >= 1000)
872 fatal("child_set_env: too many env vars");
873 envsize += 50;
874 env = (*envp) = xreallocarray(env, envsize, sizeof(char *));
875 *envsizep = envsize;
876 }
877 /* Need to set the NULL pointer at end of array beyond the new slot. */
878 env[i + 1] = NULL;
879 }
880
881 /* Allocate space and format the variable in the appropriate slot. */
882 env[i] = xmalloc(strlen(name) + 1 + strlen(value) + 1);
883 snprintf(env[i], strlen(name) + 1 + strlen(value) + 1, "%s=%s", name, value);
884}
885
886/*
887 * Reads environment variables from the given file and adds/overrides them 828 * Reads environment variables from the given file and adds/overrides them
888 * into the environment. If the file does not exist, this does nothing. 829 * into the environment. If the file does not exist, this does nothing.
889 * Otherwise, it must consist of empty lines, comments (line starts with '#') 830 * Otherwise, it must consist of empty lines, comments (line starts with '#')