From 14f5735ed0ec5bc22c46468d52f972953e2f6737 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 20 Aug 2011 18:33:57 +0000 Subject: 29711: Avoid expensive "getent group" unless directories are group writable. --- Completion/compaudit | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'Completion/compaudit') diff --git a/Completion/compaudit b/Completion/compaudit index 7107c2fff..df431afb1 100644 --- a/Completion/compaudit +++ b/Completion/compaudit @@ -82,19 +82,6 @@ fi [[ $_i_fail == use ]] && return 0 -# RedHat Linux "per-user groups" check. This is tricky, because it's very -# difficult to tell whether the sysadmin has put someone else into your -# "private" group (e.g., via the default group field in /etc/passwd, or -# by NFS group sharing with an untrustworthy machine). So we must assume -# that this has not happened, and pick the best group. - -local GROUP GROUPMEM _i_pw _i_gid _i_ulwdirs -if ((UID == EUID )); then - getent group $LOGNAME | IFS=: read GROUP _i_pw _i_gid GROUPMEM -else - getent group $EGID | IFS=: read GROUP _i_pw _i_gid GROUPMEM -fi - # We search for: # - world/group-writable directories in fpath not owned by root and the user # - parent-directories of directories in fpath that are world/group-writable @@ -105,12 +92,27 @@ fi # - and for files in directories from fpath not owned by root and the user # (including zwc files) -if [[ $GROUP == $LOGNAME && ( -z $GROUPMEM || $GROUPMEM == $LOGNAME ) ]]; then - _i_wdirs=( ${^fpath}(N-f:g+w:^g:${GROUP}:,-f:o+w:,-^u0u${EUID}) - ${^fpath:h}(N-f:g+w:^g:${GROUP}:,-f:o+w:,-^u0u${EUID}) ) -else - _i_wdirs=( ${^fpath}(N-f:g+w:,-f:o+w:,-^u0u${EUID}) - ${^fpath:h}(N-f:g+w:,-f:o+w:,-^u0u${EUID}) ) +_i_wdirs=( ${^fpath}(N-f:g+w:,-f:o+w:,-^u0u${EUID}) + ${^fpath:h}(N-f:g+w:,-f:o+w:,-^u0u${EUID}) ) + +# RedHat Linux "per-user groups" check. This is tricky, because it's very +# difficult to tell whether the sysadmin has put someone else into your +# "private" group (e.g., via the default group field in /etc/passwd, or +# by NFS group sharing with an untrustworthy machine). So we must assume +# that this has not happened, and pick the best group. + +if (( $#_i_wdirs )); then + local GROUP GROUPMEM _i_pw _i_gid _i_ulwdirs + if ((UID == EUID )); then + getent group $LOGNAME | IFS=: read GROUP _i_pw _i_gid GROUPMEM + else + getent group $EGID | IFS=: read GROUP _i_pw _i_gid GROUPMEM + fi + + if [[ $GROUP == $LOGNAME && ( -z $GROUPMEM || $GROUPMEM == $LOGNAME ) ]] + then + _i_wdirs=( ${^_i_wdirs}(N-f:g+w:^g:${GROUP}:,-f:o+w:,-^u0u${EUID}) ) + fi fi if [[ -f /etc/debian_version ]] -- cgit v1.2.3 From 571015bc32e6ff3ed648a6b351d05272329386bc Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 10 Sep 2011 17:09:50 +0000 Subject: 29760: fix references to _i_ulwdirs --- ChangeLog | 15 ++++++++++----- Completion/compaudit | 7 ++++--- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'Completion/compaudit') diff --git a/ChangeLog b/ChangeLog index d88276c17..980e311d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-09-10 Barton E. Schaefer + + * 29760: Completion/compaudit: declare _i_ulwdirs and make sure + it is correctly referenced. + 2011-09-07 Peter Stephenson * unposted: Completion/Unix/Command/_perforce: updates for @@ -31,7 +36,7 @@ * 29733: Jonathan Kolberg: Completion/Debian/Command/_apt: add completion for apt-get changelog. -2011-09-05 Barton E. Schaefer +2011-09-05 Barton E. Schaefer * users/16302: Completion/Unix/Type/_path_files: pattern matching for plain files (e.g., *.pdf for xpdf completion) was broken by @@ -47,7 +52,7 @@ * 29744: Src/builtin.c: don't mess up non '-A' case in 29731. -2011-08-29 Barton E. Schaefer +2011-08-29 Barton E. Schaefer * users/16291: Functions/Prompts/prompt_bart_setup: revert to using history text in non-"fg" case to avoid alias expansion. @@ -66,7 +71,7 @@ * users/16289: Doc/Zsh/expn.yo, Src/exec.c, Src/jobs.c: don't delete temporary files when disowning and document this. -2011-08-20 Barton E. Schaefer +2011-08-20 Barton E. Schaefer * unposted: Functions/Zle/.distfiles: add move-line-in-buffer @@ -188,7 +193,7 @@ * 29661: Doc/Zsh/redirect.yo: Improve the documentation for {var}>... redirections. -2011-08-09 Barton E. Schaefer +2011-08-09 Barton E. Schaefer * 29654: Src/jobs.c: "wait" should resume stopped jobs identified by process ID as well as by job number. @@ -15398,5 +15403,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5463 $ +* $Revision: 1.5464 $ ***************************************************** diff --git a/Completion/compaudit b/Completion/compaudit index df431afb1..72e0b62ba 100644 --- a/Completion/compaudit +++ b/Completion/compaudit @@ -102,7 +102,7 @@ _i_wdirs=( ${^fpath}(N-f:g+w:,-f:o+w:,-^u0u${EUID}) # that this has not happened, and pick the best group. if (( $#_i_wdirs )); then - local GROUP GROUPMEM _i_pw _i_gid _i_ulwdirs + local GROUP GROUPMEM _i_pw _i_gid if ((UID == EUID )); then getent group $LOGNAME | IFS=: read GROUP _i_pw _i_gid GROUPMEM else @@ -117,8 +117,9 @@ fi if [[ -f /etc/debian_version ]] then -_i_ulwdirs=( ${(M)_i_wdirs:#/usr/local/*} ) -_i_wdirs=( ${_i_wdirs:#/usr/local/*} ${^_i_ulwdir}(Nf:g+ws:^g:staff:,f:o+w:,^u0) ) + local _i_ulwdirs + _i_ulwdirs=( ${(M)_i_wdirs:#/usr/local/*} ) + _i_wdirs=( ${_i_wdirs:#/usr/local/*} ${^_i_ulwdirs}(Nf:g+ws:^g:staff:,f:o+w:,^u0) ) fi _i_wdirs=( $_i_wdirs ${^fpath}.zwc^([^_]*|*~)(N-^u0u${EUID}) ) -- cgit v1.2.3