replacing getenv/setenv on Windows - ticket 2636

Jeffrey Altman jaltman at MIT.EDU
Thu Sep 21 20:15:43 EDT 2006


Jeffrey Hutzelman wrote:
> 
> On Thursday, September 21, 2006 10:40:21 AM -0400 Jeffrey Altman 
> <jaltman at mit.edu> wrote:
> 
>> I would like to bring this topic back to the foreground.
>> As a refresher, the Kerberos libraries and applications make
>> extensive use of getenv() and setenv() for manipulating the
>> environment.  On Windows this is problem because the getenv
>> and setenv CRT functions do not access the real environment
>> of the application.  Instead they manipulate a private
>> implementation of environ[].
> 
> Note that this is effectively what UNIX systems do as well.  The 
> environment is not shared; it is copied from parent to child as one of the 
> arguemnts to execve(2).

The Windows behavior is not the same as Windows.  A call to
SetEnvironmentVariable() will change the process environment and this
change will not be reflected in the CRT environ[].  In addition, each
module in the process (EXE or DLL) can have its own private CRT instance
which means that even if the application is calling setenv() that the
Kerberos library call to getenv() may not see it.

UNIX system processes share a single environment.  On Windows they do
as well, but only if you using the SetEnvironmentVariable and
GetEnvironmentVariable APIs to manipulate it.

Jeffrey Altman



More information about the krbdev mailing list