diff options
author | Conrad Scott <conrad.scott@dsl.pipex.com> | 2002-07-01 17:53:40 +0400 |
---|---|---|
committer | Conrad Scott <conrad.scott@dsl.pipex.com> | 2002-07-01 17:53:40 +0400 |
commit | 7365f71d651705dcd560b2be95e4195580a1554f (patch) | |
tree | 43fa1800c7a7ca560001873b8c7be8981491df61 /winsup/cygwin | |
parent | bf52bde7dfacc659fcd90dea06f82660dc6f31d7 (diff) |
Merged changes from HEAD
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/ChangeLog | 34 | ||||
-rw-r--r-- | winsup/cygwin/environ.cc | 45 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.h | 7 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_process.cc | 56 | ||||
-rw-r--r-- | winsup/cygwin/security.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/uinfo.cc | 24 |
6 files changed, 118 insertions, 50 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9d4fecdb9..982aa2ab0 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -76,7 +76,39 @@ (transport_layer_sockets::accept): Rename local variable `accept_fd' to avoid shadowing the `fd' field. -2002-06-29 Pierre Humblet <pierre.humblet@ieee.org> +2002-06-30 Christopher Faylor <cgf@redhat.com> + + * uinfo.cc (cygheap_user::ontherange): Potentially set HOME from + existing homepath and homedrive cygheap_user fields (not currently used + yet). Set HOME to / if no other alternative. + (cygheap_user::test_uid): Simplify. + +2002-06-30 Christopher Faylor <cgf@redhat.com> + + * environ.cc (parse_options): Use setenv to potentially replace CYGWIN + value on export. Fixes broken behavior since November 2000 changes. + (regopt): Return indication of whether or not something has been parsed + from the registry. + (environ_init): Only attempt to export CYGWIN variable when values were + set from the registry. It is exported automatically otherwise. + +2002-06-30 Christopher Faylor <cgf@redhat.com> + + * fhandler.h (fhandler_process::pid): New field. + (fhandler_process::fstat): Remove unneeded array. Set pid element. + (fhandler_process::open): Ditto. + (fhandler_process::fill_filebuf): Handle case where 'p' field is NULL. + +2002-06-30 Christopher Faylor <cgf@redhat.com> + + * fhandler.h (fhandler_process::p): New field. + (fhandler_process:fill_filebuf): Revert to same definition as virtual + in parent class. + (fhandler_process::open): Fill out p field rather than passing as an + argument. + (fhandler_process::fill_filebuf): Use p pointer rather than argument. + +2002-06-29 Pierre Humblet <pierre.humblet@ieee.org> * security.cc (extract_nt_dom_user): Check for all buffer overflows. Call LookupAccountSid after trying to get domain & user from passwd. diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index d0c60edf9..04436edc1 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -366,7 +366,7 @@ ucenv (char *p, char *eq) /* Parse CYGWIN options */ -static NO_COPY BOOL export_settings = FALSE; +static NO_COPY BOOL export_settings = false; enum settings { @@ -536,7 +536,8 @@ parse_options (char *buf) if (buf == NULL) { - char newbuf[MAX_PATH + 7] = "CYGWIN"; + char newbuf[MAX_PATH + 7]; + newbuf[0] = '\0'; for (k = known; k->name != NULL; k++) if (k->remember) { @@ -544,11 +545,12 @@ parse_options (char *buf) free (k->remember); k->remember = NULL; } - if (!export_settings) - return; - newbuf[sizeof ("CYGWIN") - 1] = '='; - debug_printf ("%s", newbuf); - putenv (newbuf); + + if (export_settings) + { + debug_printf ("%s", newbuf + 1); + setenv ("CYGWIN", newbuf + 1, 1); + } return; } @@ -612,16 +614,21 @@ parse_options (char *buf) } /* Set options from the registry. */ -static void __stdcall +static bool __stdcall regopt (const char *name) { + bool parsed_something = false; /* 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); + { + parse_options (buf); + parsed_something = true; + } else { reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE", @@ -629,9 +636,13 @@ regopt (const char *name) CYGWIN_INFO_CYGWIN_REGISTRY_NAME, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL); if (r1.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS) - parse_options (buf); + { + parse_options (buf); + parsed_something = true; + } } MALLOC_CHECK; + return parsed_something; } /* Initialize the environ array. Look for the CYGWIN environment @@ -645,6 +656,7 @@ environ_init (char **envp, int envc) char *newp; int sawTERM = 0; bool envp_passed_in; + bool got_something_from_registry; static char NO_COPY cygterm[] = "TERM=cygwin"; static int initted; @@ -658,9 +670,9 @@ environ_init (char **envp, int envc) initted = 1; } - regopt ("default"); + got_something_from_registry = regopt ("default"); if (myself->progname[0]) - regopt (myself->progname); + got_something_from_registry = regopt (myself->progname) || got_something_from_registry; #ifdef NTSEC_ON_BY_DEFAULT /* Set ntsec explicit as default, if NT is running */ @@ -736,7 +748,10 @@ out: if (p) parse_options (p); } - parse_options (NULL); + + if (got_something_from_registry) + parse_options (NULL); /* possibly export registry settings to + environment */ MALLOC_CHECK; } @@ -893,12 +908,13 @@ build_env (const char * const *envp, char *&envblock, int &envc, continue; } + assert ((srcp - envp) == n); /* Fill in any required-but-missing environment variables. */ for (unsigned i = 0; i < SPENVS_SIZE; i++) if (!saw_spenv[i]) { *dstp = spenvs[i].retrieve (no_envblock); - if (*dstp && *dstp != env_dontadd && !no_envblock) + if (*dstp && !no_envblock && *dstp != env_dontadd) { tl += strlen (*dstp) + 1; dstp++; @@ -906,6 +922,7 @@ build_env (const char * const *envp, char *&envblock, int &envc, } envc = dstp - newenv; /* Number of entries in newenv */ + assert ((size_t) envc <= (n + SPENVS_SIZE)); *dstp = NULL; /* Terminate */ if (no_envblock) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index e0521d4ef..ebb07a8df 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1107,7 +1107,6 @@ class fhandler_proc: public fhandler_virtual void fill_filebuf (); }; -class pinfo; class fhandler_registry: public fhandler_proc { public: @@ -1125,16 +1124,18 @@ class fhandler_registry: public fhandler_proc void fill_filebuf (); }; -struct _pinfo; +class pinfo; class fhandler_process: public fhandler_proc { + pid_t pid; + pinfo *p; public: fhandler_process (); int exists(); struct dirent *readdir (DIR *); int open (path_conv *real_path, int flags, mode_t mode = 0); int __stdcall fstat (struct __stat64 *buf, path_conv *) __attribute__ ((regparm (3))); - void fill_filebuf (pinfo& p); + void fill_filebuf (); }; typedef union diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 86393db05..a0ba4af90 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -100,12 +100,11 @@ fhandler_process::fstat (struct __stat64 *buf, path_conv *pc) int file_type = exists (); (void) fhandler_base::fstat (buf, pc); path += proc_len + 1; - int pid = atoi (path); - winpids pids; + pid = atoi (path); pinfo p (pid); if (!p) { - set_errno(ENOENT); + set_errno (ENOENT); return -1; } @@ -154,8 +153,7 @@ fhandler_process::readdir (DIR * dir) int fhandler_process::open (path_conv *pc, int flags, mode_t mode) { - int process_file_no = -1, pid; - winpids pids; + int process_file_no = -1; int res = fhandler_virtual::open (pc, flags, mode); if (!res) @@ -227,12 +225,14 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode) } fileid = process_file_no; - fill_filebuf (p); + this->p = &p; + fill_filebuf (); if (flags & O_APPEND) position = filesize; else position = 0; + this->p = NULL; } success: @@ -245,8 +245,19 @@ out: } void -fhandler_process::fill_filebuf (pinfo& p) +fhandler_process::fill_filebuf () { + pinfo pmaybe; + + if (!p) + { + pmaybe.init (pid); + p = &pmaybe; + } + + if (!p) + return; + switch (fileid) { case PROCESS_UID: @@ -262,22 +273,22 @@ fhandler_process::fill_filebuf (pinfo& p) switch (fileid) { case PROCESS_PPID: - num = p->ppid; + num = (*p)->ppid; break; case PROCESS_UID: - num = p->uid; + num = (*p)->uid; break; case PROCESS_PGID: - num = p->pgid; + num = (*p)->pgid; break; case PROCESS_SID: - num = p->sid; + num = (*p)->sid; break; case PROCESS_GID: - num = p->gid; + num = (*p)->gid; break; case PROCESS_CTTY: - num = p->ctty; + num = (*p)->ctty; break; default: // what's this here for? num = 0; @@ -291,11 +302,11 @@ fhandler_process::fill_filebuf (pinfo& p) { if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = MAX_PATH); - if (p->process_state & (PID_ZOMBIE | PID_EXITED)) + if ((*p)->process_state & (PID_ZOMBIE | PID_EXITED)) strcpy (filebuf, "<defunct>"); else { - mount_table->conv_to_posix_path (p->progname, filebuf, 1); + mount_table->conv_to_posix_path ((*p)->progname, filebuf, 1); int len = strlen (filebuf); if (len > 4) { @@ -311,16 +322,16 @@ fhandler_process::fill_filebuf (pinfo& p) { if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40); - __small_sprintf (filebuf, "%d\n", p->dwProcessId); + __small_sprintf (filebuf, "%d\n", (*p)->dwProcessId); filesize = strlen (filebuf); break; } case PROCESS_WINEXENAME: { - int len = strlen (p->progname); + int len = strlen ((*p)->progname); if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = (len + 2)); - strcpy (filebuf, p->progname); + strcpy (filebuf, (*p)->progname); filebuf[len] = '\n'; filesize = len + 1; break; @@ -329,24 +340,27 @@ fhandler_process::fill_filebuf (pinfo& p) { if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_status (p, filebuf, bufalloc); + filesize = format_process_status ((*p), filebuf, bufalloc); break; } case PROCESS_STAT: { if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_stat (p, filebuf, bufalloc); + filesize = format_process_stat ((*p), filebuf, bufalloc); break; } case PROCESS_STATM: { if (!filebuf) filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_statm (p, filebuf, bufalloc); + filesize = format_process_statm ((*p), filebuf, bufalloc); break; } } + + if (p == &pmaybe) + p = NULL; } static diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index b587af20a..f5516aa60 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -75,7 +75,7 @@ extract_nt_dom_user (const struct passwd *pw, char *domain, char *user) else if (u - d <= INTERNET_MAX_HOST_NAME_LENGTH + 2) strlcpy(domain, d + 2, u - d - 1); if (c == NULL) - c = u + UNLEN + 1; + c = u + UNLEN + 1; if (c - u <= UNLEN + 1) strlcpy(user, u + 1, c - u); } diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index cd39097d5..d8fb3829b 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -204,10 +204,14 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw) if (what == CH_HOME) { char *p; - if ((p = getenv ("HOMEDRIVE"))) + if (homedrive) + newhomedrive = homedrive; + else if ((p = getenv ("HOMEDRIVE"))) newhomedrive = p; - if ((p = getenv ("HOMEPATH"))) + if (homepath) + newhomepath = homepath; + else if ((p = getenv ("HOMEPATH"))) newhomepath = p; if ((p = getenv ("HOME"))) @@ -218,18 +222,20 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw) pw = getpwnam (name ()); if (pw && pw->pw_dir && *pw->pw_dir) { - setenv ("HOME", pw->pw_dir, 1); debug_printf ("Set HOME (from /etc/passwd) to %s", pw->pw_dir); + setenv ("HOME", pw->pw_dir, 1); } - else if (newhomedrive && newhomepath) + else if (!newhomedrive || !newhomepath) + setenv ("HOME", "/", 1); + else { char home[MAX_PATH]; char buf[MAX_PATH + 1]; strcpy (buf, newhomedrive); strcat (buf, newhomepath); cygwin_conv_to_full_posix_path (buf, home); - setenv ("HOME", home, 1); debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home); + setenv ("HOME", home, 1); } } } @@ -285,11 +291,11 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw) } } - if (newhomedrive) + if (newhomedrive && newhomedrive != homedrive) cfree_and_set (homedrive, (newhomedrive == almost_null) ? almost_null : cstrdup (newhomedrive)); - if (newhomepath) + if (newhomepath && newhomepath != homepath) cfree_and_set (homepath, cstrdup (newhomepath)); switch (what) @@ -306,9 +312,7 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw) const char * cygheap_user::test_uid (char *&what, const char *name, size_t namelen) { - if (what) - return what; - if (!issetuid ()) + if (!what && !issetuid ()) what = getwinenveq (name, namelen, HEAP_STR); return what; } |