--- spawn.cc.orig 2002-06-06 21:02:22.000000000 -0400 +++ spawn.cc 2002-06-08 15:00:32.000000000 -0400 @@ -567,13 +567,7 @@ ciresrv.moreinfo->argv = newargv; ciresrv.moreinfo->envc = envsize (envp, 1); - ciresrv.moreinfo->envp = (char **) cmalloc (HEAP_1_ARGV, ciresrv.moreinfo->envc); ciresrv.hexec_proc = hexec_proc; - char **c; - const char * const *e; - for (c = ciresrv.moreinfo->envp, e = envp; *e;) - *c++ = cstrdup1 (*e++); - *c = NULL; if (mode != _P_OVERLAY || !DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc, &ciresrv.moreinfo->myself_pinfo, 0, @@ -604,14 +598,6 @@ if (cygheap->fdtab.need_fixup_before ()) flags |= CREATE_SUSPENDED; - - /* Build windows style environment list */ - char *envblock; - if (real_path.iscygexec ()) - envblock = NULL; - else - envblock = winenv (envp, 0); - /* Preallocated buffer for `sec_user' call */ char sa_buf[1024]; @@ -624,9 +610,22 @@ syscall_printf ("spawn_guts null_app_name %d (%s, %.132s)", null_app_name, runpath, one_line.buf); void *newheap; + char *envblock; cygbench ("spawn-guts"); if (!hToken) { + ciresrv.moreinfo->envp = (char **) cmalloc (HEAP_1_ARGV, ciresrv.moreinfo->envc); + char **c; + const char * const *e; + for (c = ciresrv.moreinfo->envp, e = envp; *e;) + *c++ = cstrdup1 (*e++); + *c = NULL; + /* Build windows style environment list */ + if (real_path.iscygexec ()) + envblock = NULL; + else + envblock = winenv (envp, 0); + PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf); ciresrv.moreinfo->uid = getuid32 (); /* FIXME: This leaks a handle in the CreateProcessAsUser case since the child process doesn't know about cygwin_mount_h. */ @@ -634,10 +633,8 @@ newheap = cygheap_setup_for_child (&ciresrv, cygheap->fdtab.need_fixup_before ()); rc = CreateProcess (runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ - /* process security attrs */ - sec_user_nih (sa_buf), - /* thread security attrs */ - sec_user_nih (sa_buf), + sec_attribs, /* process security attrs */ + sec_attribs, /* thread security attrs */ TRUE, /* inherit handles from parent */ flags, envblock,/* environment */ @@ -659,10 +656,25 @@ PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf, sid); /* Remove impersonation */ - if (cygheap->user.impersonated - && cygheap->user.token != INVALID_HANDLE_VALUE) + if (cygheap->user.impersonated && + cygheap->user.token != INVALID_HANDLE_VALUE) RevertToSelf (); + ciresrv.moreinfo->envp = (char **) cmalloc (HEAP_1_ARGV, + ciresrv.moreinfo->envc + + WINDEFENVC); + char **c; + const char * const *e; + for (c = ciresrv.moreinfo->envp, e = envp; *e; e++) + if (!inWinDefEnv(*e)) *c++ = cstrdup1 (*e); + ciresrv.moreinfo->envc = (1 + buildWinDefEnv((char **) c, sid) - + ciresrv.moreinfo->envp) * sizeof (char *); + /* Build windows style environment list */ + if (real_path.iscygexec ()) + envblock = NULL; + else + envblock = winenv (ciresrv.moreinfo->envp, 0); + /* Load users registry hive. */ load_registry_hive (sid);