2000-02-18 03:38:33 +08:00
|
|
|
/* environ.cc: Cygwin-adopted functions from newlib to manipulate
|
|
|
|
process's environment.
|
|
|
|
|
2002-06-05 12:01:43 +08:00
|
|
|
Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-07-26 09:44:16 +08:00
|
|
|
#include <errno.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <ctype.h>
|
2000-09-08 10:56:55 +08:00
|
|
|
#include <sys/cygwin.h>
|
|
|
|
#include <cygwin/version.h>
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-03-05 14:28:25 +08:00
|
|
|
#include "perprocess.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "path.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
2000-09-03 12:45:52 +08:00
|
|
|
#include "cygheap.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "registry.h"
|
|
|
|
#include "environ.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-02-28 22:30:38 +08:00
|
|
|
extern BOOL allow_daemon;
|
2000-02-18 03:38:33 +08:00
|
|
|
extern BOOL allow_glob;
|
2001-03-05 14:28:25 +08:00
|
|
|
extern bool ignore_case_with_glob;
|
2000-02-18 03:38:33 +08:00
|
|
|
extern BOOL allow_ntea;
|
2000-12-20 03:52:57 +08:00
|
|
|
extern BOOL allow_smbntsec;
|
2001-03-02 19:41:09 +08:00
|
|
|
extern BOOL allow_winsymlinks;
|
2000-02-18 03:38:33 +08:00
|
|
|
extern BOOL strip_title_path;
|
2001-04-13 05:21:37 +08:00
|
|
|
extern int pcheck_case;
|
2001-05-01 05:19:42 +08:00
|
|
|
extern int subauth_id;
|
2001-11-01 00:30:46 +08:00
|
|
|
BOOL reset_com = FALSE;
|
2000-02-18 03:38:33 +08:00
|
|
|
static BOOL envcache = TRUE;
|
|
|
|
|
2001-09-06 12:41:59 +08:00
|
|
|
static char **lastenviron;
|
2000-09-03 12:16:35 +08:00
|
|
|
|
2000-11-09 04:36:37 +08:00
|
|
|
#define ENVMALLOC \
|
|
|
|
(CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \
|
|
|
|
<= CYGWIN_VERSION_DLL_MALLOC_ENV)
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* List of names which are converted from dos to unix
|
2000-12-10 08:45:12 +08:00
|
|
|
on the way in and back again on the way out.
|
2001-03-19 05:11:25 +08:00
|
|
|
|
2000-12-10 08:45:12 +08:00
|
|
|
PATH needs to be here because CreateProcess uses it and gdb uses
|
|
|
|
CreateProcess. HOME is here because most shells use it and would be
|
|
|
|
confused by Windows style path names. */
|
2000-02-18 03:38:33 +08:00
|
|
|
static int return_MAX_PATH (const char *) {return MAX_PATH;}
|
2001-09-06 13:17:22 +08:00
|
|
|
static NO_COPY win_env conv_envvars[] =
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
{"PATH=", 5, NULL, NULL, cygwin_win32_to_posix_path_list,
|
|
|
|
cygwin_posix_to_win32_path_list,
|
|
|
|
cygwin_win32_to_posix_path_list_buf_size,
|
|
|
|
cygwin_posix_to_win32_path_list_buf_size},
|
|
|
|
{"HOME=", 5, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
|
|
|
return_MAX_PATH, return_MAX_PATH},
|
|
|
|
{"LD_LIBRARY_PATH=", 16, NULL, NULL, cygwin_conv_to_full_posix_path,
|
|
|
|
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
|
2000-03-25 13:25:27 +08:00
|
|
|
{"TMPDIR=", 7, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
|
|
|
return_MAX_PATH, return_MAX_PATH},
|
2000-06-15 11:50:03 +08:00
|
|
|
{"TMP=", 4, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
|
|
|
return_MAX_PATH, return_MAX_PATH},
|
|
|
|
{"TEMP=", 5, NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path,
|
|
|
|
return_MAX_PATH, return_MAX_PATH},
|
2000-02-21 13:20:38 +08:00
|
|
|
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2000-10-19 08:45:39 +08:00
|
|
|
static unsigned char conv_start_chars[256] = {0};
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
|
|
|
win_env::add_cache (const char *in_posix, const char *in_native)
|
|
|
|
{
|
2001-10-03 11:49:26 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
posix = (char *) realloc (posix, strlen (in_posix) + 1);
|
|
|
|
strcpy (posix, in_posix);
|
|
|
|
if (in_native)
|
|
|
|
{
|
|
|
|
native = (char *) realloc (native, namelen + 1 + strlen (in_native));
|
|
|
|
(void) strcpy (native, name);
|
|
|
|
(void) strcpy (native + namelen, in_native);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
native = (char *) realloc (native, namelen + 1 + win32_len (in_posix));
|
|
|
|
(void) strcpy (native, name);
|
|
|
|
towin32 (in_posix, native + namelen);
|
|
|
|
}
|
2001-10-03 11:49:26 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("posix %s", posix);
|
|
|
|
debug_printf ("native %s", native);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check for a "special" environment variable name. *env is the pointer
|
|
|
|
* to the beginning of the environment variable name. n is the length
|
|
|
|
* of the name including a mandatory '='. Returns a pointer to the
|
|
|
|
* appropriate conversion structure.
|
|
|
|
*/
|
2000-02-21 11:13:24 +08:00
|
|
|
win_env * __stdcall
|
2000-02-18 03:38:33 +08:00
|
|
|
getwinenv (const char *env, const char *in_posix)
|
|
|
|
{
|
2000-10-19 08:45:39 +08:00
|
|
|
if (!conv_start_chars[(unsigned char)*env])
|
|
|
|
return NULL;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
2001-04-19 05:10:15 +08:00
|
|
|
if (strncmp (env, conv_envvars[i].name, conv_envvars[i].namelen) == 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-09-06 13:17:22 +08:00
|
|
|
win_env * const we = conv_envvars + i;
|
2000-02-18 03:38:33 +08:00
|
|
|
const char *val;
|
2000-08-03 00:28:18 +08:00
|
|
|
if (!cur_environ () || !(val = in_posix ?: getenv(we->name)))
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("can't set native for %s since no environ yet",
|
|
|
|
we->name);
|
2001-05-05 04:39:38 +08:00
|
|
|
else if (!envcache || !we->posix || strcmp (val, we->posix) != 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
we->add_cache (val);
|
|
|
|
return we;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert windows path specs to POSIX, if appropriate.
|
|
|
|
*/
|
|
|
|
static void __stdcall
|
2000-09-03 12:16:35 +08:00
|
|
|
posify (char **here, const char *value)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
char *src = *here;
|
|
|
|
win_env *conv;
|
|
|
|
|
|
|
|
if (!(conv = getwinenv (src)))
|
|
|
|
return;
|
|
|
|
|
2000-10-18 12:53:37 +08:00
|
|
|
int len = strcspn (src, "=") + 1;
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
/* Turn all the items from c:<foo>;<bar> into their
|
|
|
|
mounted equivalents - if there is one. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
char *outenv = (char *) malloc (1 + len + conv->posix_len (value));
|
|
|
|
memcpy (outenv, src, len);
|
|
|
|
conv->toposix (value, outenv + len);
|
2001-03-26 09:16:11 +08:00
|
|
|
conv->add_cache (outenv + len, *value != '/' ? value : NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
debug_printf ("env var converted to %s", outenv);
|
|
|
|
*here = outenv;
|
|
|
|
free (src);
|
2001-10-03 11:49:26 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* my_findenv --
|
|
|
|
* Returns pointer to value associated with name, if any, else NULL.
|
|
|
|
* Sets offset to be the offset of the name/value combination in the
|
|
|
|
* environment array, for use by setenv(3) and unsetenv(3).
|
|
|
|
* Explicitly removes '=' in argument name.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char * __stdcall
|
|
|
|
my_findenv (const char *name, int *offset)
|
|
|
|
{
|
|
|
|
register int len;
|
|
|
|
register char **p;
|
|
|
|
const char *c;
|
|
|
|
|
|
|
|
c = name;
|
|
|
|
len = 0;
|
|
|
|
while (*c && *c != '=')
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
for (p = cur_environ (); *p; ++p)
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!strncmp (*p, name, len))
|
|
|
|
if (*(c = *p + len) == '=')
|
|
|
|
{
|
2000-08-03 00:28:18 +08:00
|
|
|
*offset = p - cur_environ ();
|
2000-02-18 03:38:33 +08:00
|
|
|
return (char *) (++c);
|
|
|
|
}
|
2001-10-03 11:49:26 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getenv --
|
|
|
|
* Returns ptr to value associated with name, if any, else NULL.
|
|
|
|
*/
|
|
|
|
|
2000-02-21 11:13:24 +08:00
|
|
|
extern "C" char *
|
2000-02-18 03:38:33 +08:00
|
|
|
getenv (const char *name)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
return my_findenv (name, &offset);
|
|
|
|
}
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
extern int __stdcall
|
|
|
|
envsize (const char * const *in_envp, int debug_print)
|
|
|
|
{
|
|
|
|
const char * const *envp;
|
|
|
|
for (envp = in_envp; *envp; envp++)
|
2000-10-28 13:41:44 +08:00
|
|
|
if (debug_print)
|
2000-09-03 12:16:35 +08:00
|
|
|
debug_printf ("%s", *envp);
|
|
|
|
return (1 + envp - in_envp) * sizeof (const char *);
|
|
|
|
}
|
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
/* Takes similar arguments to setenv except that overwrite is
|
|
|
|
either -1, 0, or 1. 0 or 1 signify that the function should
|
|
|
|
perform similarly to setenv. Otherwise putenv is assumed. */
|
|
|
|
static int __stdcall
|
|
|
|
_addenv (const char *name, const char *value, int overwrite)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-07-26 09:44:16 +08:00
|
|
|
int issetenv = overwrite >= 0;
|
|
|
|
int offset;
|
|
|
|
char *p;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
unsigned int valuelen = strlen (value);
|
|
|
|
if ((p = my_findenv (name, &offset)))
|
|
|
|
{ /* Already exists. */
|
|
|
|
if (!overwrite) /* Ok to overwrite? */
|
|
|
|
return 0; /* No. Wanted to add new value. FIXME: Right return value? */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
/* We've found the offset into environ. If this is a setenv call and
|
|
|
|
there is room in the current environment entry then just overwrite it.
|
|
|
|
Otherwise handle this case below. */
|
|
|
|
if (issetenv && strlen (p) >= valuelen)
|
|
|
|
{
|
|
|
|
strcpy (p, value);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-07-26 09:44:16 +08:00
|
|
|
{ /* Create new slot. */
|
2000-09-03 12:16:35 +08:00
|
|
|
int sz = envsize (cur_environ ());
|
2001-10-03 11:49:26 +08:00
|
|
|
int allocsz = sz + (2 * sizeof (char *));
|
2000-07-26 09:44:16 +08:00
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
offset = (sz - 1) / sizeof (char *);
|
2000-07-26 09:44:16 +08:00
|
|
|
|
|
|
|
/* Allocate space for additional element plus terminating NULL. */
|
2001-10-03 11:49:26 +08:00
|
|
|
if (cur_environ () == lastenviron)
|
2000-09-03 12:16:35 +08:00
|
|
|
lastenviron = __cygwin_environ = (char **) realloc (cur_environ (),
|
|
|
|
allocsz);
|
|
|
|
else if ((lastenviron = (char **) malloc (allocsz)) != NULL)
|
|
|
|
__cygwin_environ = (char **) memcpy ((char **) lastenviron,
|
|
|
|
__cygwin_environ, sz);
|
|
|
|
|
2000-07-17 23:59:27 +08:00
|
|
|
if (!__cygwin_environ)
|
2000-10-23 11:35:50 +08:00
|
|
|
{
|
2000-11-08 03:00:02 +08:00
|
|
|
#ifdef DEBUGGING
|
2000-10-23 11:35:50 +08:00
|
|
|
try_to_debug ();
|
|
|
|
#endif
|
2001-10-03 11:49:26 +08:00
|
|
|
return -1; /* Oops. No more memory. */
|
2000-10-23 11:35:50 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
__cygwin_environ[offset + 1] = NULL; /* NULL terminate. */
|
|
|
|
update_envptrs (); /* Update any local copies of 'environ'. */
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
char *envhere;
|
|
|
|
if (!issetenv)
|
2000-11-09 04:36:37 +08:00
|
|
|
/* Not setenv. Just overwrite existing. */
|
|
|
|
envhere = cur_environ ()[offset] = (char *) (ENVMALLOC ? strdup (name) : name);
|
2000-07-26 09:44:16 +08:00
|
|
|
else
|
|
|
|
{ /* setenv */
|
|
|
|
/* Look for an '=' in the name and ignore anything after that if found. */
|
|
|
|
for (p = (char *) name; *p && *p != '='; p++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int namelen = p - name; /* Length of name. */
|
|
|
|
/* Allocate enough space for name + '=' + value + '\0' */
|
2000-08-03 00:28:18 +08:00
|
|
|
envhere = cur_environ ()[offset] = (char *) malloc (namelen + valuelen + 2);
|
2000-07-26 09:44:16 +08:00
|
|
|
if (!envhere)
|
|
|
|
return -1; /* Oops. No more memory. */
|
|
|
|
|
|
|
|
/* Put name '=' value into current slot. */
|
|
|
|
strncpy (envhere, name, namelen);
|
|
|
|
envhere[namelen] = '=';
|
|
|
|
strcpy (envhere + namelen + 1, value);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-26 09:44:16 +08:00
|
|
|
/* Update cygwin's cache, if appropriate */
|
2000-02-18 03:38:33 +08:00
|
|
|
win_env *spenv;
|
2000-07-26 09:44:16 +08:00
|
|
|
if ((spenv = getwinenv (envhere)))
|
2000-02-18 03:38:33 +08:00
|
|
|
spenv->add_cache (value);
|
|
|
|
|
2001-10-03 11:49:26 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-10 08:45:12 +08:00
|
|
|
/* putenv Sets an environment variable */
|
2000-07-26 09:44:16 +08:00
|
|
|
extern "C" int
|
|
|
|
putenv (const char *str)
|
|
|
|
{
|
2000-07-27 02:51:14 +08:00
|
|
|
int res;
|
2001-06-28 10:19:57 +08:00
|
|
|
if ((res = check_null_empty_str (str)))
|
2000-07-27 02:51:14 +08:00
|
|
|
{
|
|
|
|
if (res == ENOENT)
|
2000-09-03 12:16:35 +08:00
|
|
|
return 0;
|
2000-07-27 02:51:14 +08:00
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-07-26 09:44:16 +08:00
|
|
|
char *eq = strchr (str, '=');
|
|
|
|
if (eq)
|
|
|
|
return _addenv (str, eq + 1, -1);
|
|
|
|
|
|
|
|
/* Remove str from the environment. */
|
|
|
|
unsetenv (str);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-10 08:45:12 +08:00
|
|
|
/* setenv -- Set the value of the environment variable "name" to be
|
|
|
|
"value". If overwrite is set, replace any current value. */
|
2000-07-26 09:44:16 +08:00
|
|
|
extern "C" int
|
|
|
|
setenv (const char *name, const char *value, int overwrite)
|
|
|
|
{
|
|
|
|
int res;
|
2001-06-28 10:19:57 +08:00
|
|
|
if ((res = check_null_empty_str (value)) == EFAULT)
|
2000-07-27 02:51:14 +08:00
|
|
|
{
|
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
2001-06-28 10:19:57 +08:00
|
|
|
if ((res = check_null_empty_str (name)))
|
2000-07-26 09:44:16 +08:00
|
|
|
{
|
2000-07-27 02:51:14 +08:00
|
|
|
if (res == ENOENT)
|
2000-09-03 12:16:35 +08:00
|
|
|
return 0;
|
2000-07-26 09:44:16 +08:00
|
|
|
set_errno (res);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (*value == '=')
|
|
|
|
value++;
|
|
|
|
return _addenv (name, value, !!overwrite);
|
|
|
|
}
|
|
|
|
|
2000-12-10 08:45:12 +08:00
|
|
|
/* unsetenv(name) -- Delete environment variable "name". */
|
2000-02-21 11:13:24 +08:00
|
|
|
extern "C" void
|
2000-02-18 03:38:33 +08:00
|
|
|
unsetenv (const char *name)
|
|
|
|
{
|
2000-07-18 03:18:21 +08:00
|
|
|
register char **e;
|
2000-02-18 03:38:33 +08:00
|
|
|
int offset;
|
|
|
|
|
|
|
|
while (my_findenv (name, &offset)) /* if set multiple times */
|
2000-07-18 03:18:21 +08:00
|
|
|
/* Move up the rest of the array */
|
2000-08-03 00:28:18 +08:00
|
|
|
for (e = cur_environ () + offset; ; e++)
|
2000-07-18 03:18:21 +08:00
|
|
|
if (!(*e = *(e + 1)))
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn environment variable part of a=b string into uppercase. */
|
2000-02-21 13:20:38 +08:00
|
|
|
static __inline__ void
|
2000-02-18 03:38:33 +08:00
|
|
|
ucenv (char *p, char *eq)
|
|
|
|
{
|
|
|
|
/* Amazingly, NT has a case sensitive environment name list,
|
|
|
|
but only sometimes.
|
|
|
|
It's normal to have NT set your "Path" to something.
|
|
|
|
Later, you set "PATH" to something else. This alters "Path".
|
|
|
|
But if you try and do a naive getenv on "PATH" you'll get nothing.
|
|
|
|
|
|
|
|
So we upper case the labels here to prevent confusion later but
|
|
|
|
we only do it for the first process in a session group. */
|
|
|
|
for (; p < eq; p++)
|
|
|
|
if (islower (*p))
|
2000-10-19 11:12:44 +08:00
|
|
|
*p = cyg_toupper (*p);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse CYGWIN options */
|
|
|
|
|
|
|
|
static NO_COPY BOOL export_settings = FALSE;
|
|
|
|
|
|
|
|
enum settings
|
|
|
|
{
|
|
|
|
justset,
|
|
|
|
isfunc,
|
|
|
|
setbit,
|
|
|
|
set_process_state,
|
|
|
|
};
|
|
|
|
|
2000-11-11 13:36:34 +08:00
|
|
|
/* When BUF is:
|
2000-12-10 08:45:12 +08:00
|
|
|
null or empty: disables globbing
|
|
|
|
"ignorecase": enables case-insensitive globbing
|
|
|
|
anything else: enables case-sensitive globbing */
|
2000-11-11 13:36:34 +08:00
|
|
|
static void
|
|
|
|
glob_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
{
|
|
|
|
allow_glob = FALSE;
|
|
|
|
ignore_case_with_glob = FALSE;
|
|
|
|
}
|
|
|
|
else if (strncasematch (buf, "ignorecase", 10))
|
|
|
|
{
|
|
|
|
allow_glob = TRUE;
|
|
|
|
ignore_case_with_glob = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
allow_glob = TRUE;
|
|
|
|
ignore_case_with_glob = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-13 05:21:37 +08:00
|
|
|
static void
|
|
|
|
check_case_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (strncmp (buf, "relax", 5)== 0)
|
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_RELAXED;
|
|
|
|
debug_printf ("File case checking set to RELAXED");
|
|
|
|
}
|
|
|
|
else if (strcmp (buf, "adjust")== 0)
|
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_ADJUST;
|
|
|
|
debug_printf ("File case checking set to ADJUST");
|
|
|
|
}
|
|
|
|
else if (strcmp (buf, "strict")== 0)
|
|
|
|
{
|
|
|
|
pcheck_case = PCHECK_STRICT;
|
|
|
|
debug_printf ("File case checking set to STRICT");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("Wrong case checking name: %s", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-12 19:31:05 +08:00
|
|
|
void
|
|
|
|
set_file_api_mode (codepage_type cp)
|
|
|
|
{
|
|
|
|
if (cp == oem_cp)
|
|
|
|
{
|
|
|
|
SetFileApisToOEM ();
|
|
|
|
debug_printf ("File APIs set to OEM");
|
|
|
|
}
|
|
|
|
else if (cp == ansi_cp)
|
|
|
|
{
|
|
|
|
SetFileApisToANSI ();
|
|
|
|
debug_printf ("File APIs set to ANSI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-08 12:02:02 +08:00
|
|
|
static void
|
|
|
|
codepage_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
2001-03-19 05:11:25 +08:00
|
|
|
if (strcmp (buf, "oem")== 0)
|
2001-01-08 12:02:02 +08:00
|
|
|
{
|
|
|
|
current_codepage = oem_cp;
|
2001-06-12 19:31:05 +08:00
|
|
|
set_file_api_mode (current_codepage);
|
2001-01-08 12:02:02 +08:00
|
|
|
}
|
2001-03-19 05:11:25 +08:00
|
|
|
else if (strcmp (buf, "ansi")== 0)
|
2001-01-08 12:02:02 +08:00
|
|
|
{
|
|
|
|
current_codepage = ansi_cp;
|
2001-06-12 19:31:05 +08:00
|
|
|
set_file_api_mode (current_codepage);
|
2001-01-08 12:02:02 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-19 05:11:25 +08:00
|
|
|
debug_printf ("Wrong codepage name: %s", buf);
|
2001-01-08 12:02:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-01 05:19:42 +08:00
|
|
|
static void
|
|
|
|
subauth_id_init (const char *buf)
|
|
|
|
{
|
|
|
|
if (!buf || !*buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int i = strtol (buf, NULL, 0);
|
|
|
|
|
|
|
|
/* 0..127 are reserved by Microsoft, 132 is IIS subauthentication. */
|
|
|
|
if (i > 127 && i != 132 && i <= 255)
|
|
|
|
subauth_id = i;
|
|
|
|
}
|
|
|
|
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
static void
|
|
|
|
set_chunksize (const char *buf)
|
|
|
|
{
|
|
|
|
wincap.set_chunksize (strtol (buf, NULL, 0));
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* The structure below is used to set up an array which is used to
|
2000-12-10 08:45:12 +08:00
|
|
|
parse the CYGWIN environment variable or, if enabled, options from
|
|
|
|
the registry. */
|
2001-09-06 13:17:22 +08:00
|
|
|
static struct parse_thing
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
union parse_setting
|
|
|
|
{
|
|
|
|
BOOL *b;
|
|
|
|
DWORD *x;
|
|
|
|
int *i;
|
|
|
|
void (*func)(const char *);
|
|
|
|
} setting;
|
|
|
|
|
|
|
|
enum settings disposition;
|
|
|
|
char *remember;
|
|
|
|
union parse_values
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
const char *s;
|
|
|
|
} values[2];
|
2001-09-06 13:17:22 +08:00
|
|
|
} known[] NO_COPY =
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-08-25 01:54:43 +08:00
|
|
|
{"binmode", {x: &binmode}, justset, NULL, {{O_TEXT}, {O_BINARY}}},
|
2001-04-13 05:21:37 +08:00
|
|
|
{"check_case", {func: &check_case_init}, isfunc, NULL, {{0}, {0}}},
|
2000-12-10 08:45:12 +08:00
|
|
|
{"codepage", {func: &codepage_init}, isfunc, NULL, {{0}, {0}}},
|
2002-02-28 22:30:38 +08:00
|
|
|
{"daemon", {&allow_daemon}, justset, NULL, {{FALSE}, {TRUE}}},
|
2000-02-18 03:38:33 +08:00
|
|
|
{"envcache", {&envcache}, justset, NULL, {{TRUE}, {FALSE}}},
|
|
|
|
{"error_start", {func: &error_start_init}, isfunc, NULL, {{0}, {0}}},
|
|
|
|
{"export", {&export_settings}, justset, NULL, {{FALSE}, {TRUE}}},
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
{"forkchunk", {func: set_chunksize}, isfunc, NULL, {{0}, {0}}},
|
2000-11-11 13:36:34 +08:00
|
|
|
{"glob", {func: &glob_init}, isfunc, NULL, {{0}, {s: "normal"}}},
|
2000-02-18 03:38:33 +08:00
|
|
|
{"ntea", {&allow_ntea}, justset, NULL, {{FALSE}, {TRUE}}},
|
|
|
|
{"ntsec", {&allow_ntsec}, justset, NULL, {{FALSE}, {TRUE}}},
|
2000-12-20 03:52:57 +08:00
|
|
|
{"smbntsec", {&allow_smbntsec}, justset, NULL, {{FALSE}, {TRUE}}},
|
2000-02-18 03:38:33 +08:00
|
|
|
{"reset_com", {&reset_com}, justset, NULL, {{FALSE}, {TRUE}}},
|
|
|
|
{"strip_title", {&strip_title_path}, justset, NULL, {{FALSE}, {TRUE}}},
|
2001-05-01 05:19:42 +08:00
|
|
|
{"subauth_id", {func: &subauth_id_init}, isfunc, NULL, {{0}, {0}}},
|
2000-02-18 03:38:33 +08:00
|
|
|
{"title", {&display_title}, justset, NULL, {{FALSE}, {TRUE}}},
|
|
|
|
{"tty", {NULL}, set_process_state, NULL, {{0}, {PID_USETTY}}},
|
2001-03-02 19:41:09 +08:00
|
|
|
{"winsymlinks", {&allow_winsymlinks}, justset, NULL, {{FALSE}, {TRUE}}},
|
2000-02-18 03:38:33 +08:00
|
|
|
{NULL, {0}, justset, 0, {{0}, {0}}}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse a string of the form "something=stuff somethingelse=more-stuff",
|
2000-12-10 08:45:12 +08:00
|
|
|
silently ignoring unknown "somethings". */
|
2000-02-18 03:38:33 +08:00
|
|
|
static void __stdcall
|
|
|
|
parse_options (char *buf)
|
|
|
|
{
|
|
|
|
int istrue;
|
2001-03-14 23:32:49 +08:00
|
|
|
char *p, *lasts;
|
2000-02-18 03:38:33 +08:00
|
|
|
parse_thing *k;
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
char newbuf[MAX_PATH + 7] = "CYGWIN";
|
|
|
|
for (k = known; k->name != NULL; k++)
|
|
|
|
if (k->remember)
|
|
|
|
{
|
|
|
|
strcat (strcat (newbuf, " "), k->remember);
|
|
|
|
free (k->remember);
|
|
|
|
k->remember = NULL;
|
|
|
|
}
|
|
|
|
if (!export_settings)
|
|
|
|
return;
|
|
|
|
newbuf[sizeof ("CYGWIN") - 1] = '=';
|
|
|
|
debug_printf ("%s", newbuf);
|
|
|
|
putenv (newbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = strcpy ((char *) alloca (strlen (buf) + 1), buf);
|
2001-03-14 23:32:49 +08:00
|
|
|
for (p = strtok_r (buf, " \t", &lasts);
|
|
|
|
p != NULL;
|
|
|
|
p = strtok_r (NULL, " \t", &lasts))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (!(istrue = !strncasematch (p, "no", 2)))
|
|
|
|
p += 2;
|
|
|
|
else if (!(istrue = *p != '-'))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
char ch, *eq;
|
|
|
|
if ((eq = strchr (p, '=')) != NULL || (eq = strchr (p, ':')) != NULL)
|
|
|
|
ch = *eq, *eq++ = '\0';
|
|
|
|
else
|
|
|
|
ch = 0;
|
|
|
|
|
|
|
|
for (parse_thing *k = known; k->name != NULL; k++)
|
|
|
|
if (strcasematch (p, k->name))
|
|
|
|
{
|
|
|
|
switch (k->disposition)
|
|
|
|
{
|
|
|
|
case isfunc:
|
|
|
|
k->setting.func ((!eq || !istrue) ?
|
|
|
|
k->values[istrue].s : eq);
|
|
|
|
debug_printf ("%s (called func)", k->name);
|
|
|
|
break;
|
|
|
|
case justset:
|
|
|
|
if (!istrue || !eq)
|
|
|
|
*k->setting.x = k->values[istrue].i;
|
|
|
|
else
|
|
|
|
*k->setting.x = strtol (eq, NULL, 0);
|
|
|
|
debug_printf ("%s %d", k->name, *k->setting.x);
|
|
|
|
break;
|
|
|
|
case set_process_state:
|
|
|
|
k->setting.x = &myself->process_state;
|
|
|
|
/* fall through */
|
|
|
|
case setbit:
|
|
|
|
*k->setting.x &= ~k->values[istrue].i;
|
|
|
|
if (istrue || (eq && strtol (eq, NULL, 0)))
|
|
|
|
*k->setting.x |= k->values[istrue].i;
|
|
|
|
debug_printf ("%s %x", k->name, *k->setting.x);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eq)
|
|
|
|
*--eq = ch;
|
|
|
|
|
|
|
|
int n = eq - p;
|
|
|
|
p = strdup (p);
|
|
|
|
if (n > 0)
|
|
|
|
p[n] = ':';
|
|
|
|
k->remember = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug_printf ("returning");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set options from the registry. */
|
|
|
|
static void __stdcall
|
|
|
|
regopt (const char *name)
|
|
|
|
{
|
|
|
|
/* FIXME: should not be under mount */
|
|
|
|
reg_key r (KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
char lname[strlen(name) + 1];
|
|
|
|
strlwr (strcpy (lname, name));
|
|
|
|
if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
|
|
|
|
parse_options (buf);
|
2000-05-23 05:19:36 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-25 01:54:43 +08:00
|
|
|
reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
|
|
|
|
CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
|
|
|
|
CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
|
|
|
|
CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
|
2000-05-23 05:19:36 +08:00
|
|
|
if (r1.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
|
|
|
|
parse_options (buf);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
MALLOC_CHECK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the environ array. Look for the CYGWIN environment
|
2000-12-10 08:45:12 +08:00
|
|
|
environment variable and set appropriate options from it. */
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
2000-10-17 07:55:58 +08:00
|
|
|
environ_init (char **envp, int envc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
char *rawenv;
|
2000-10-17 07:55:58 +08:00
|
|
|
int i;
|
2000-07-26 09:44:16 +08:00
|
|
|
char *p;
|
2000-09-03 12:16:35 +08:00
|
|
|
char *newp;
|
2000-02-18 03:38:33 +08:00
|
|
|
int sawTERM = 0;
|
2000-09-26 00:36:12 +08:00
|
|
|
bool envp_passed_in;
|
2001-09-06 13:17:22 +08:00
|
|
|
static char NO_COPY cygterm[] = "TERM=cygwin";
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-06 12:41:59 +08:00
|
|
|
static int initted;
|
2000-10-19 08:45:39 +08:00
|
|
|
if (!initted)
|
|
|
|
{
|
|
|
|
for (int i = 0; conv_envvars[i].name != NULL; i++)
|
|
|
|
{
|
2000-10-19 11:12:44 +08:00
|
|
|
conv_start_chars[cyg_tolower(conv_envvars[i].name[0])] = 1;
|
|
|
|
conv_start_chars[cyg_toupper(conv_envvars[i].name[0])] = 1;
|
2000-10-19 08:45:39 +08:00
|
|
|
}
|
|
|
|
initted = 1;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
regopt ("default");
|
|
|
|
if (myself->progname[0])
|
|
|
|
regopt (myself->progname);
|
|
|
|
|
|
|
|
#ifdef NTSEC_ON_BY_DEFAULT
|
|
|
|
/* Set ntsec explicit as default, if NT is running */
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.has_security ())
|
2000-02-18 03:38:33 +08:00
|
|
|
allow_ntsec = TRUE;
|
|
|
|
#endif
|
|
|
|
|
2000-09-26 00:36:12 +08:00
|
|
|
if (!envp)
|
|
|
|
envp_passed_in = 0;
|
|
|
|
else
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
2000-10-17 07:55:58 +08:00
|
|
|
char **newenv = (char **) malloc (envc);
|
|
|
|
memcpy (newenv, envp, envc);
|
2000-09-03 12:16:35 +08:00
|
|
|
cfree (envp);
|
2000-11-09 04:36:37 +08:00
|
|
|
|
|
|
|
/* Older applications relied on the fact that cygwin malloced elements of the
|
|
|
|
environment list. */
|
2000-09-03 12:45:52 +08:00
|
|
|
envp = newenv;
|
2000-11-09 04:36:37 +08:00
|
|
|
if (ENVMALLOC)
|
|
|
|
for (char **e = newenv; *e; e++)
|
|
|
|
{
|
|
|
|
char *p = *e;
|
|
|
|
*e = strdup (p);
|
|
|
|
cfree (p);
|
|
|
|
}
|
2000-09-26 00:36:12 +08:00
|
|
|
envp_passed_in = 1;
|
2000-09-03 12:16:35 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for environment + trailing NULL + CYGWIN env. */
|
2000-10-17 07:55:58 +08:00
|
|
|
lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *));
|
2000-09-03 12:16:35 +08:00
|
|
|
rawenv = GetEnvironmentStrings ();
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Current directory information is recorded as variables of the
|
|
|
|
form "=X:=X:\foo\bar; these must be changed into something legal
|
|
|
|
(we could just ignore them but maybe an application will
|
|
|
|
eventually want to use them). */
|
|
|
|
for (i = 0, p = rawenv; *p != '\0'; p = strchr (p, '\0') + 1, i++)
|
|
|
|
{
|
2000-07-27 02:51:14 +08:00
|
|
|
newp = strdup (p);
|
2000-10-17 07:55:58 +08:00
|
|
|
if (i >= envc)
|
|
|
|
envp = (char **) realloc (envp, (4 + (envc += 100)) * sizeof (char *));
|
2000-07-27 02:51:14 +08:00
|
|
|
envp[i] = newp;
|
|
|
|
if (*newp == '=')
|
|
|
|
*newp = '!';
|
2000-02-18 03:38:33 +08:00
|
|
|
char *eq;
|
2000-07-27 02:51:14 +08:00
|
|
|
if ((eq = strchr (newp, '=')) == NULL)
|
|
|
|
eq = strchr (newp, '\0');
|
2000-11-15 14:27:48 +08:00
|
|
|
if (!myself->ppid_handle)
|
2000-07-27 02:51:14 +08:00
|
|
|
ucenv (newp, eq);
|
2000-10-19 08:45:39 +08:00
|
|
|
if (*newp == 'T' && strncmp (newp, "TERM=", 5) == 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
sawTERM = 1;
|
2000-10-19 08:45:39 +08:00
|
|
|
if (*newp == 'C' && strncmp (newp, "CYGWIN=", sizeof("CYGWIN=") - 1) == 0)
|
2000-07-27 02:51:14 +08:00
|
|
|
parse_options (newp + sizeof("CYGWIN=") - 1);
|
2000-10-19 08:45:39 +08:00
|
|
|
if (*eq && conv_start_chars[(unsigned char)envp[i][0]])
|
2000-09-03 12:16:35 +08:00
|
|
|
posify (envp + i, *++eq ? eq : --eq);
|
2000-11-08 03:00:02 +08:00
|
|
|
debug_printf ("%p: %s", envp[i], envp[i]);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!sawTERM)
|
2000-07-26 09:44:16 +08:00
|
|
|
envp[i++] = cygterm;
|
2000-02-18 03:38:33 +08:00
|
|
|
envp[i] = NULL;
|
2000-09-03 12:16:35 +08:00
|
|
|
FreeEnvironmentStrings (rawenv);
|
|
|
|
|
|
|
|
out:
|
2000-07-17 04:06:11 +08:00
|
|
|
__cygwin_environ = envp;
|
2000-07-15 10:48:11 +08:00
|
|
|
update_envptrs ();
|
2000-09-26 00:36:12 +08:00
|
|
|
if (envp_passed_in)
|
|
|
|
{
|
|
|
|
p = getenv ("CYGWIN");
|
|
|
|
if (p)
|
|
|
|
parse_options (p);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
parse_options (NULL);
|
|
|
|
MALLOC_CHECK;
|
|
|
|
}
|
|
|
|
|
2000-12-10 08:45:12 +08:00
|
|
|
/* Function called by qsort to sort environment strings. */
|
2000-02-18 03:38:33 +08:00
|
|
|
static int
|
|
|
|
env_sort (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const char **p = (const char **) a;
|
|
|
|
const char **q = (const char **) b;
|
|
|
|
|
|
|
|
return strcmp (*p, *q);
|
|
|
|
}
|
|
|
|
|
2001-05-11 11:27:22 +08:00
|
|
|
/* Keep this list in upper case and sorted */
|
2001-09-06 13:17:22 +08:00
|
|
|
static const NO_COPY char* forced_winenv_vars [] =
|
2001-05-11 11:27:22 +08:00
|
|
|
{
|
|
|
|
"SYSTEMDRIVE",
|
|
|
|
"SYSTEMROOT",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2001-06-26 22:47:48 +08:00
|
|
|
#define FORCED_WINENV_SIZE (sizeof (forced_winenv_vars) / sizeof (forced_winenv_vars[0]))
|
2001-05-11 11:27:22 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Create a Windows-style environment block, i.e. a typical character buffer
|
2000-12-10 08:45:12 +08:00
|
|
|
filled with null terminated strings, terminated by double null characters.
|
|
|
|
Converts environment variables noted in conv_envvars into win32 form
|
|
|
|
prior to placing them in the string. */
|
2000-02-21 11:13:24 +08:00
|
|
|
char * __stdcall
|
2000-04-26 13:13:32 +08:00
|
|
|
winenv (const char * const *envp, int keep_posix)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int len, n, tl;
|
|
|
|
const char * const *srcp;
|
2001-05-11 11:27:22 +08:00
|
|
|
const char **dstp;
|
|
|
|
bool saw_forced_winenv[FORCED_WINENV_SIZE] = {0};
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
debug_printf ("envp %p, keep_posix %d", envp, keep_posix);
|
|
|
|
|
|
|
|
tl = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (n = 0; envp[n]; n++)
|
|
|
|
continue;
|
|
|
|
|
2001-05-11 11:27:22 +08:00
|
|
|
const char *newenvp[n + 1 + FORCED_WINENV_SIZE];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-05-11 11:27:22 +08:00
|
|
|
for (srcp = envp, dstp = newenvp; *srcp; srcp++, dstp++)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-05-11 11:27:22 +08:00
|
|
|
len = strcspn (*srcp, "=");
|
2000-02-18 03:38:33 +08:00
|
|
|
win_env *conv;
|
|
|
|
|
2001-05-11 11:27:22 +08:00
|
|
|
if (keep_posix || !(conv = getwinenv (*srcp, *srcp + len + 1)))
|
2000-02-18 03:38:33 +08:00
|
|
|
*dstp = *srcp;
|
2001-04-19 05:10:15 +08:00
|
|
|
else
|
|
|
|
{
|
2001-05-11 11:27:22 +08:00
|
|
|
p = (char *) alloca (strlen (conv->native) + 1);
|
2001-04-19 05:10:15 +08:00
|
|
|
strcpy (p, conv->native);
|
|
|
|
*dstp = p;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
tl += strlen (*dstp) + 1;
|
2000-05-30 08:38:51 +08:00
|
|
|
if ((*dstp)[0] == '!' && isdrive ((*dstp) + 1) && (*dstp)[3] == '=')
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-05-11 11:27:22 +08:00
|
|
|
p = (char *) alloca (strlen (*dstp) + 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
strcpy (p, *dstp);
|
|
|
|
*p = '=';
|
|
|
|
*dstp = p;
|
|
|
|
}
|
2001-05-11 11:27:22 +08:00
|
|
|
|
|
|
|
for (int i = 0; forced_winenv_vars[i]; i++)
|
|
|
|
if (!saw_forced_winenv[i])
|
|
|
|
saw_forced_winenv[i] = strncasematch (forced_winenv_vars[i], *srcp, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-10-01 05:37:53 +08:00
|
|
|
char dum[1];
|
2001-05-11 11:27:22 +08:00
|
|
|
for (int i = 0; forced_winenv_vars[i]; i++)
|
|
|
|
if (!saw_forced_winenv[i])
|
|
|
|
{
|
2001-10-03 11:49:26 +08:00
|
|
|
int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0);
|
|
|
|
if (vallen > 0)
|
2001-05-11 11:27:22 +08:00
|
|
|
{
|
2001-10-03 11:49:26 +08:00
|
|
|
int namelen = strlen (forced_winenv_vars[i]) + 1;
|
|
|
|
p = (char *) alloca (namelen + ++vallen);
|
|
|
|
strcpy (p, forced_winenv_vars[i]);
|
|
|
|
strcat (p, "=");
|
|
|
|
if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen,
|
|
|
|
vallen))
|
|
|
|
debug_printf ("warning: %s not present in environment", *srcp);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dstp++ = p;
|
|
|
|
tl += strlen (p) + 1;
|
|
|
|
}
|
2001-05-11 11:27:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
*dstp = NULL; /* Terminate */
|
|
|
|
|
|
|
|
int envlen = dstp - newenvp;
|
|
|
|
debug_printf ("env count %d, bytes %d", envlen, tl);
|
|
|
|
|
|
|
|
/* Windows programs expect the environment block to be sorted. */
|
|
|
|
qsort (newenvp, envlen, sizeof (char *), env_sort);
|
|
|
|
|
|
|
|
/* Create an environment block suitable for passing to CreateProcess. */
|
|
|
|
char *ptr, *envblock;
|
|
|
|
envblock = (char *) malloc (tl + 2);
|
|
|
|
for (srcp = newenvp, ptr = envblock; *srcp; srcp++)
|
|
|
|
{
|
|
|
|
len = strlen (*srcp);
|
|
|
|
memcpy (ptr, *srcp, len + 1);
|
|
|
|
ptr += len + 1;
|
|
|
|
}
|
|
|
|
*ptr = '\0'; /* Two null bytes at the end */
|
|
|
|
|
|
|
|
return envblock;
|
|
|
|
}
|
2000-07-17 04:06:11 +08:00
|
|
|
|
|
|
|
/* This idiocy is necessary because the early implementers of cygwin
|
|
|
|
did not seem to know about importing data variables from the DLL.
|
|
|
|
So, we have to synchronize cygwin's idea of the environment with the
|
|
|
|
main program's with each reference to the environment. */
|
2000-07-30 00:24:59 +08:00
|
|
|
extern "C" char ** __stdcall
|
2000-07-17 04:06:11 +08:00
|
|
|
cur_environ ()
|
|
|
|
{
|
|
|
|
if (*main_environ != __cygwin_environ)
|
|
|
|
{
|
|
|
|
__cygwin_environ = *main_environ;
|
|
|
|
update_envptrs ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return __cygwin_environ;
|
|
|
|
}
|