Re: Avoiding /etc/passwd and /etc/group scans
On Mon, Oct 21, 2002 at 11:01:59AM -0400, Pierre A. Humblet wrote: >Cygwin scans the passwd and group files to map sids >to/from uid & gid. It does so even for the current user, >although the relevant mappings are stored internally. >This is inefficient and causes problems (e.g. gcc produces >non executable files) as soon as /etc/passwd is incomplete. It's only supposed to be doing this for the first cygwin process that start up on a given console. Is that, again, no longer the case? It seems like we keep drifting here. We shouldn't be incurring the /etc/group and /etc/passwd startup costs even when ntsec isn't available. Anyway, I'll take a look at your patch later today, Pierre. cgf
Avoiding /etc/passwd and /etc/group scans
Chris, Cygwin scans the passwd and group files to map sids to/from uid & gid. It does so even for the current user, although the relevant mappings are stored internally. This is inefficient and causes problems (e.g. gcc produces non executable files) as soon as /etc/passwd is incomplete. security.cc:alloc_sd already uses internal structures to map uid to sid. This small patch proceeds similarly to map gid to sid and to map sid to uid/gid, thus improving both the efficiency and robustness of Cygwin. The patch is very simple, most changed lines only differ in blank spaces. Pierre 2002-10-21 Pierre Humblet <[EMAIL PROTECTED]> * sec_helper.cc (cygsid::get_id): If the sid matches a sid stored in cygheap->user, return the uid or gid from myself. * security.cc (alloc_sd): If gid == myself->gid, return the group sid from cygheap->user. Remove the test for uid == original_uid, which is counter-productive. --- sec_helper.cc.orig 2002-10-19 12:57:48.0 -0400 +++ sec_helper.cc 2002-10-21 10:25:50.0 -0400 @@ -162,14 +162,17 @@ cygsid::get_id (BOOL search_grp, int *ty if (!search_grp) { struct passwd *pw; - for (int pidx = 0; (pw = internal_getpwent (pidx)); ++pidx) - { - if (sid.getfrompw (pw) && sid == psid) - { - id = pw->pw_uid; - break; - } - } + if (EqualSid(psid, cygheap->user.sid ())) + id = myself->uid; + else + for (int pidx = 0; (pw = internal_getpwent (pidx)); ++pidx) + { + if (sid.getfrompw (pw) && sid == psid) + { + id = pw->pw_uid; + break; + } + } if (id >= 0) { if (type) @@ -180,14 +183,17 @@ cygsid::get_id (BOOL search_grp, int *ty if (search_grp || type) { struct __group32 *gr; - for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) - { - if (sid.getfromgr (gr) && sid == psid) - { - id = gr->gr_gid; - break; - } - } + if (cygheap->user.groups.pgsid == psid) + id = myself->gid; + else + for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) + { + if (sid.getfromgr (gr) && sid == psid) + { + id = gr->gr_gid; + break; + } + } if (id >= 0) { if (type) --- security.cc.orig2002-09-30 20:24:00.0 -0400 +++ security.cc 2002-10-21 09:31:53.0 -0400 @@ -1536,9 +1536,7 @@ alloc_sd (__uid32_t uid, __gid32_t gid, /* Check for current user first */ if (uid == myself->uid) owner_sid = cygheap->user.sid (); - else if (uid == cygheap->user.orig_uid) -owner_sid = cygheap->user.orig_sid (); - if (!owner_sid) + else { /* Otherwise retrieve user data from /etc/passwd */ struct passwd *pw = getpwuid32 (uid); @@ -1559,12 +1557,17 @@ alloc_sd (__uid32_t uid, __gid32_t gid, /* Get SID of new group. */ cygsid group_sid (NO_SID); - struct __group32 *grp = getgrgid32 (gid); - if (!grp) -debug_printf ("no /etc/group entry for %d", gid); - else if (!group_sid.getfromgr (grp)) -debug_printf ("no SID for group %d", gid); - + /* Check for current user first */ + if (gid == myself->gid) +group_sid = cygheap->user.groups.pgsid; + else + { + struct __group32 *grp = getgrgid32 (gid); + if (!grp) +debug_printf ("no /etc/group entry for %d", gid); + else if (!group_sid.getfromgr (grp)) +debug_printf ("no SID for group %d", gid); + } /* Initialize local security descriptor. */ SECURITY_DESCRIPTOR sd; PSECURITY_DESCRIPTOR psd = NULL;
FIXED Re: [PATCH] fhandler_tty deadlock patch
On Mon, 21 Oct 2002, Igor Pechtchanski wrote: > On Mon, 21 Oct 2002, Steve O wrote: > > > On Sun, Oct 20, 2002 at 11:15:47PM -0400, Igor Pechtchanski wrote: > > > However, there are a couple of problems with this patch. For example, > > > this makes bash run from a command prompt (or a shortcut) treat every > > > character as a ^D. > > > > So every character closes bash? I'm not able to reproduce this on > > WinXP, have an strace? > > Sure. I'm attaching an strace for 'bash --rcfile /dev/null'; the > character pressed was a space. This affects most programs, btw (vi from a > command prompt, for example, and tcsh), but not sh, cat or less. My guess > is that anything that uses readline is affected. I'm running Win2k SP2, > if it makes any difference. Well, rebuilding cygwin1.dll from scratch seems to have solved this problem, which probably indicates that some dependence is not computed correctly. So, Steve's patch works for me, sorry for the false alarm. > > > /bin/sh ignores Enter (or ^J, or ^M). > > > > Good find. I've attached a diff that should fix this. Unsure > > how to proceed since the original patch hasn't been applied. > > Do I resubmit the original patch or treat this one as it's own > > thing? > > Thanks, I'll try it out and let you know if it works for me. This also works. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_[EMAIL PROTECTED] ZZZzz /,`.-'`'-. ;-;;,_[EMAIL PROTECTED] |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51
Re: [PATCH] fhandler_tty deadlock patch
On Mon, 21 Oct 2002, Steve O wrote: > On Sun, Oct 20, 2002 at 11:15:47PM -0400, Igor Pechtchanski wrote: > > However, there are a couple of problems with this patch. For example, > > this makes bash run from a command prompt (or a shortcut) treat every > > character as a ^D. > > So every character closes bash? I'm not able to reproduce this on > WinXP, have an strace? Sure. I'm attaching an strace for 'bash --rcfile /dev/null'; the character pressed was a space. This affects most programs, btw (vi from a command prompt, for example, and tcsh), but not sh, cat or less. My guess is that anything that uses readline is affected. I'm running Win2k SP2, if it makes any difference. > > /bin/sh ignores Enter (or ^J, or ^M). > > Good find. I've attached a diff that should fix this. Unsure > how to proceed since the original patch hasn't been applied. > Do I resubmit the original patch or treat this one as it's own > thing? Thanks, I'll try it out and let you know if it works for me. > > Running 'bash -c "echo BLAH && exit"' from > > a command prompt works, however, running "bash -c 'echo BLAH && exit' > > ... > > Curious behavior, but not related to the tty patch. Happens > with previous cygwin dll's and in rxvt -e cmd. > > Thanks, > -steve I see. Well, anyway, I sent an strace for that one, hopefully someone can figure out what's going on. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_[EMAIL PROTECTED] ZZZzz /,`.-'`'-. ;-;;,_[EMAIL PROTECTED] |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51 steve_o-paste-bash1.strace.bz2 Description: Binary data
[PATCH] fhandler_tty deadlock patch + console
On Mon, Oct 21, 2002 at 12:20:38PM -0400, Christopher Faylor wrote: > Keep resubmitting on large patch until it is accepted. > > My time is limited right now so I may not be able to completely review > this for a couple of weeks. I'm going to be on a business trip starting > on Wednesday. > > So, I would appreciate it if people would try this out and report their > experiences. > > cgf Here's the original patch plus the recent fix. -steve 2002-10-17 Steve Osborn <[EMAIL PROTECTED]> * fhandler.cc (fhandler_base::put_readahead): Limited size of buffer to reduce amount of garbage from cat'ing a binary file. * fhandler.h (fhandler_termios::doecho): Returns int, added force. (fhandler_termios::accept_input): Changed sense of return. (fhandler_termios::line_edit_cnt): Added. (fhandler_console::doecho): Returns int, added force. (fhandler_pty_master::doecho): Returns int, added force. (fhandler_pty_master::get_echobuf_valid): Added. (fhandler_pty_master::get_echobuf_into_buffer): Added. (fhandler_pty_master::clear_echobuf): Added. (fhandler_pty_master::ebbuf): Added pointer to echobuf. (fhandler_pty_master::ebixget): Added echobuf get index. (fhandler_pty_master::ebixput): Added echobuf put index. (fhandler_pty_master::ebbuflen): Added echobuf length. (fhandler_pty_master::ebguard): Added handle for guard mutex. * fhandler_termios.cc (fhandler_termios::line_edit): Wraps line_edit_cnt to provide previous signature. (fhandler_termios::line_edit_cnt): Added line_edit function with the ability to report number of bytes written. Handles cases where the echo or readahead buffer is full. (fhandler_termios::line_edit_cnt): Returns true if the last character resulted in an input_done - necessary for console. * fhandler_tty.cc (fhandler_pty_master::get_echobuf_valid): Added. (fhandler_pty_master::doecho): Rewritten to return bytes written to echobuf. Added force option to expand the buffer as necessary. (fhandler_pty_master::get_echobuf_into_buffer): Added. (fhandler_pty_master::clear_echobuf): Added. (fhandler_pty_master::accept_input): Sense of return changed to number of bytes not written. Added support for partial write. (fhandler_pty_master::process_slave_output): Prime read with echobuf. (fhandler_pty_master::fhandler_pty_master): Initializers for echobuf. (fhandler_pty_master::open): Calls clear_echobuf. (fhandler_pty_master::close): Calls clear_echobuf. (fhandler_pty_master::write): Returns number of bytes written. * select.cc (peek_pipe): Check for echobuf valid. Index: cygwin/fhandler.cc === RCS file: /cvs/src/src/winsup/cygwin/fhandler.cc,v retrieving revision 1.138 diff -u -p -r1.138 fhandler.cc --- cygwin/fhandler.cc 23 Sep 2002 00:31:30 - 1.138 +++ cygwin/fhandler.cc 22 Oct 2002 05:15:00 - @@ -58,13 +58,15 @@ fhandler_base::puts_readahead (const cha return success; } +#define READAHEAD_BUFFER_MAXSIZE 4096 int fhandler_base::put_readahead (char value) { char *newrabuf; if (raixput < rabuflen) /* Nothing to do */; - else if ((newrabuf = (char *) realloc (rabuf, rabuflen += 32))) + else if (rabuflen < READAHEAD_BUFFER_MAXSIZE && + (newrabuf = (char *) realloc (rabuf, rabuflen += 32))) rabuf = newrabuf; else return 0; Index: cygwin/fhandler.h === RCS file: /cvs/src/src/winsup/cygwin/fhandler.h,v retrieving revision 1.143 diff -u -p -r1.143 fhandler.h --- cygwin/fhandler.h 9 Oct 2002 05:55:40 - 1.143 +++ cygwin/fhandler.h 22 Oct 2002 05:15:03 - @@ -682,8 +682,8 @@ class fhandler_termios: public fhandler_ { protected: HANDLE output_handle; - virtual void doecho (const void *, DWORD) {}; - virtual int accept_input () {return 1;}; + virtual int doecho (const void *, DWORD, int force = 1) {return 1;}; + virtual int accept_input () {return 0;}; public: tty_min *tc; fhandler_termios (DWORD dev, int unit = 0) : @@ -693,6 +693,7 @@ class fhandler_termios: public fhandler_ } HANDLE& get_output_handle () { return output_handle; } int line_edit (const char *rptr, int nread, int always_accept = 0); + int line_edit_cnt (const char *rptr, int *nread, int always_accept = 0); void set_output_handle (HANDLE h) { output_handle = h; } void tcinit (tty_min *this_tc, int force = FALSE); virtual int is_tty () { return 1; } @@ -812,7 +813,7 @@ class fhandler_console: public fhandler_ int open (path_conv *, int flags, mode_t mode = 0); int write (const void *ptr, size_t len); - void doecho (const void *str, DWORD len) { (void) write (str, len); } + int doecho (const void *str, DWORD len,