Skip Menu |
 

Subject: replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
The getenv()/setenv() functions are local to the instance of the C
Runtime Library used by the library. Changes to the process environment
made by the process after initialization will not be reflected in the
response.
This means that an app cannot change the default ccache by changing the
environment variable; or set/unset other options.
Cc: krb5-prs@mit.edu
From: Ken Raeburn <raeburn@MIT.EDU>
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
Date: Wed, 14 Jul 2004 15:52:53 -0400
To: rt-comment@krbdev.mit.edu
RT-Send-Cc:
Can this be done with a macro in win-mac.h?
Date: Wed, 14 Jul 2004 15:57:11 -0400
From: Jeffrey Altman <jaltman@columbia.edu>
To: rt-comment@krbdev.mit.edu
Cc: krb5-prs@MIT.EDU
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
RT-Send-Cc:
Ken Raeburn wrote:

Show quoted text
> Can this be done with a macro in win-mac.h?

Unfortunately not. GetEnvironmentVariable() requires that the user
provide the input buffer as well as a length. The return value is the
length of the returned string.

The variable is undefined if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
Download smime.p7s
application/x-pkcs7-signature 3.1KiB

Message body not shown because it is not plain text.

Cc: rt-comment@krbdev.mit.edu, krb5-prs@mit.edu
From: Ken Raeburn <raeburn@MIT.EDU>
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
Date: Wed, 14 Jul 2004 16:01:48 -0400
To: Jeffrey Altman <jaltman@columbia.edu>
RT-Send-Cc:
Show quoted text
> Unfortunately not. GetEnvironmentVariable() requires that the user
> provide the input buffer as well as a length. The return value is the
> length of the returned string.

On the plus side, that'll likely be a thread-safe interface, compared
with the UNIX one (if setenv is used). Perhaps we should modify our
uses of getenv to call a helper function which returns us a string in
allocated storage; then that helper function could use either getenv or
GetEnvironmentVariable, and in the getenv case, while it still wouldn't
be thread-safe, it would reduce the window of exposure somewhat.

Ken
Date: Wed, 14 Jul 2004 16:10:55 -0400
From: Jeffrey Altman <jaltman@columbia.edu>
To: rt-comment@krbdev.mit.edu
Cc: krb5-prs@MIT.EDU
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
RT-Send-Cc:
Ken Raeburn wrote:

Show quoted text
> On the plus side, that'll likely be a thread-safe interface, compared
> with the UNIX one (if setenv is used). Perhaps we should modify our
> uses of getenv to call a helper function which returns us a string in
> allocated storage; then that helper function could use either getenv
> or GetEnvironmentVariable, and in the getenv case, while it still
> wouldn't be thread-safe, it would reduce the window of exposure somewhat.
>
> Ken

A mutex could be placed in the helper function to ensure that at most
one krb5 library call is accessing the environment variables
we care about at a time.
Download smime.p7s
application/x-pkcs7-signature 3.1KiB

Message body not shown because it is not plain text.

Date: Wed, 14 Jul 2004 15:26:22 -0500
From: Nicolas Williams <Nicolas.Williams@sun.com>
To: "Jeffrey Altman [Kermit Project] via RT" <rt-comment@krbdev.mit.edu>
Cc: krb5-prs@mit.edu
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
RT-Send-Cc:
On Wed, Jul 14, 2004 at 04:11:01PM -0400, Jeffrey Altman [Kermit Project] via RT wrote:
Show quoted text
>
> Ken Raeburn wrote:
>
> > On the plus side, that'll likely be a thread-safe interface, compared
> > with the UNIX one (if setenv is used). Perhaps we should modify our
> > uses of getenv to call a helper function which returns us a string in
> > allocated storage; then that helper function could use either getenv
> > or GetEnvironmentVariable, and in the getenv case, while it still
> > wouldn't be thread-safe, it would reduce the window of exposure somewhat.

Yes.

Show quoted text
> > Ken
>
> A mutex could be placed in the helper function to ensure that at most
> one krb5 library call is accessing the environment variables
> we care about at a time.

The krb5 library doesn't use setenv()/putenv() and I think it's safe to
assume that getenv() is always safe with respect to other concurrent
calls to getenv(), so the krb5 lib should not worry about getenv()'s
thread-safety (there's nothing it could w.r.t. other threads that do a
setenv() outside the context of krb5).

Nico
--
Date: Thu, 21 Sep 2006 00:12:09 -0400
From: Jeffrey Altman <jaltman@mit.edu>
To: rt@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #2636] replace all calls to getenv()/setenv() with Get/SetEnvironmentVariable on Windows
RT-Send-Cc:
Download (untitled) / with headers
text/plain 1.4KiB
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[].

There are several mechanisms via which we can address this
issue. Here is a proposal for implementation:

We leave the POSIX systems alone and for Windows implement
new support functions:

const char * win32_getenv(const char * var)
int win32_setenv(const char *var, const char *value)

and a macro

free_envstr(str)

win32_getenv() would be implemented in terms of the Win32
GetEnvironmentVariable API. This API can be called in two
ways. First it can be used to obtain the required buffer
size and secondly to obtain the value in a provided buffer.
win32_getenv() would determine the appropriate buffer size,
allocate the buffer with malloc(), and then obtain the value
and return the buffer. This buffer would then need to be
freed by the caller.

win32_setenv() would take a variable name and value and
pass them to the SetEnvironmentVariable API

On Windows, the free_envstr macro would call an appropriate
function to free the allocated memory.

On POSIX systems, the free_envstr macro would be a no-op.

What do people think?

Jeffrey Altman