]> andersk Git - openssh.git/commitdiff
- (dtucker) [session.c openbsd-compat/bsd-cygwin_util.{c,h}] Bug #915: only
authordtucker <dtucker>
Mon, 30 Aug 2004 10:42:08 +0000 (10:42 +0000)
committerdtucker <dtucker>
Mon, 30 Aug 2004 10:42:08 +0000 (10:42 +0000)
   copy required environment variables on Cygwin.  Patch from vinschen at
   redhat.com, ok djm@

ChangeLog
openbsd-compat/bsd-cygwin_util.c
openbsd-compat/bsd-cygwin_util.h
session.c

index 6b0e874e6f50aa3b1764021f2330832e9299cf0a..0c6d9a4b7d158cfc97851b0f881e654aa0047f64 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+20040830
+ - (dtucker) [session.c openbsd-compat/bsd-cygwin_util.{c,h}] Bug #915: only
+   copy required environment variables on Cygwin.  Patch from vinschen at
+   redhat.com, ok djm@
+
 20040829
  - (dtucker) [openbsd-compat/getrrsetbyname.c] Prevent getrrsetbyname from
    failing with NOMEMORY if no sigs are returned and malloc(0) returns NULL.
index 238a866ff251982d7df7ed2e53bc0be550ce5ef1..eb983def2d5ec7d14ea568c7480cb774c5094786 100644 (file)
@@ -38,6 +38,7 @@ RCSID("$Id$");
 #include <sys/utsname.h>
 #include <sys/vfs.h>
 #include <windows.h>
+#include "xmalloc.h"
 #define is_winnt       (GetVersion() < 0x80000000)
 
 #define ntsec_on(c)    ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec"))
@@ -96,7 +97,6 @@ has_capability(int what)
         */
        if (!inited) {
                struct utsname uts;
-               char *c;
                
                if (!uname(&uts)) {
                        int major_high = 0, major_low = 0, minor = 0;
@@ -236,4 +236,54 @@ register_9x_service(void)
        RegisterServiceProcess(0, 1);
 }
 
+#define NL(x) x, (sizeof (x) - 1)
+#define WENV_SIZ (sizeof (wenv_arr) / sizeof (wenv_arr[0]))
+
+static struct wenv {
+       const char *name;
+       size_t namelen;
+} wenv_arr[] = {
+       { NL("ALLUSERSPROFILE=") },
+       { NL("COMMONPROGRAMFILES=") },
+       { NL("COMPUTERNAME=") },
+       { NL("COMSPEC=") },
+       { NL("NUMBER_OF_PROCESSORS=") },
+       { NL("OS=") },
+       { NL("PATH=") },
+       { NL("PATHEXT=") },
+       { NL("PROCESSOR_ARCHITECTURE=") },
+       { NL("PROCESSOR_IDENTIFIER=") },
+       { NL("PROCESSOR_LEVEL=") },
+       { NL("PROCESSOR_REVISION=") },
+       { NL("PROGRAMFILES=") },
+       { NL("SYSTEMDRIVE=") },
+       { NL("SYSTEMROOT=") },
+       { NL("TMP=") },
+       { NL("TEMP=") },
+       { NL("WINDIR=") },
+};
+
+char **
+fetch_windows_environment(void)
+{
+       char **e, **p;
+       int i, idx = 0;
+
+       p = xmalloc(WENV_SIZ * sizeof(char *));
+       for (e = environ; *e != NULL; ++e) {
+               for (i = 0; i < WENV_SIZ; ++i) {
+                       if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen))
+                               p[idx++] = *e;
+               }
+       }
+       p[idx] = NULL;
+       return p;
+}
+
+void
+free_windows_environment(char **p)
+{
+       xfree(p);
+}
+
 #endif /* HAVE_CYGWIN */
index a0429ebc6399692bbcdbcbd0b84322e6c1b50976..03b64d20de183c1ec7ae81f391384a7167e16d73 100644 (file)
@@ -46,6 +46,8 @@ int binary_pipe(int fd[2]);
 int check_nt_auth(int, struct passwd *);
 int check_ntsec(const char *);
 void register_9x_service(void);
+char **fetch_windows_environment(void);
+void free_windows_environment(char **);
 
 #define open binary_open
 #define pipe binary_pipe
index ee4008acff67b03e482893e722605624152c605f..89e1ec8922a009a203cb89e47b7cfce0617ba0a3 100644 (file)
--- a/session.c
+++ b/session.c
@@ -979,7 +979,13 @@ do_setup_env(Session *s, const char *shell)
         * The Windows environment contains some setting which are
         * important for a running system. They must not be dropped.
         */
-       copy_environment(environ, &env, &envsize);
+       {
+               char **p;
+
+               p = fetch_windows_environment();
+               copy_environment(p, &env, &envsize);
+               free_windows_environment(p);
+       }
 #endif
 
 #ifdef GSSAPI
This page took 0.059951 seconds and 5 git commands to generate.