about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2011-08-20 18:33:57 +0000
committerBart Schaefer <barts@users.sourceforge.net>2011-08-20 18:33:57 +0000
commit14f5735ed0ec5bc22c46468d52f972953e2f6737 (patch)
tree2a60c9298324fa07496579d24b8e08d6dafd7303
parentcfdb417a6b91364706a8fd5ba319eac086d0d568 (diff)
downloadzsh-14f5735ed0ec5bc22c46468d52f972953e2f6737.tar.gz
zsh-14f5735ed0ec5bc22c46468d52f972953e2f6737.tar.xz
zsh-14f5735ed0ec5bc22c46468d52f972953e2f6737.zip
29711: Avoid expensive "getent group" unless directories are group writable.
-rw-r--r--ChangeLog7
-rw-r--r--Completion/compaudit40
2 files changed, 27 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index a7d2c0bac..315083080 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-20  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 29711: Completion/compaudit: avoid calling potentially-slow
+	"getent group" unless group-writable directories are found.
+
 2011-08-20  Nikolai Weibull  <now@bitwi.se>
 
 	* 29707: Completion/Unix/Command/.distfiles,
@@ -15323,5 +15328,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5443 $
+* $Revision: 1.5444 $
 *****************************************************
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 ]]