d0d307a
#!/bin/sh
d0d307a
d0d307a
# This program is free software; you can redistribute it and/or modify
d0d307a
# it under the terms of the GNU General Public License as published by
d0d307a
# the Free Software Foundation; either version 2 of the License, or
d0d307a
# (at your option) any later version.
d0d307a
#
d0d307a
# This program is distributed in the hope that it will be useful,
d0d307a
# but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d307a
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d0d307a
# GNU General Public License for more details.
d0d307a
#
d0d307a
# You should have received a copy of the GNU General Public License
d0d307a
# along with this program; if not, write to the Free Software
d0d307a
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d0d307a
d0d307a
# This script updates a cache of the unix group database. It's purpose is to
d0d307a
# speedup group authorization when using large groups with slow nss backends.
d0d307a
# For more info consult the README.groupcache file.
d0d307a
#
d0d307a
# This script can safely be run as root, it will reexec itself as user
d0d307a
# cyrus if needed.
d0d307a
#
d0d307a
# author: Simon Matter, Invoca Systems <simon.matter@invoca.ch>
d0d307a
d0d307a
# changelog
d0d307a
# v1.0.0, Dec 15 2004 Simon Matter <simon.matter@invoca.ch>
d0d307a
# - initial release
d0d307a
d0d307a
if [ ! -f /etc/imapd.conf ]; then
d0d307a
  echo "ERROR: configuration file not found."
d0d307a
  exit 1
d0d307a
fi
d0d307a
d0d307a
# fallback to su if runuser not available
d0d307a
if [ -x /sbin/runuser ]; then
d0d307a
  RUNUSER=runuser
d0d307a
else
d0d307a
  RUNUSER=su
d0d307a
fi
d0d307a
d0d307a
# force cyrus user for security reasons
d0d307a
if [ ! $(whoami) = "cyrus" ]; then
d0d307a
  exec $RUNUSER - cyrus -c "cd $PWD < /dev/null ; $0"
d0d307a
fi
d0d307a
d0d307a
# files get mode 0600
d0d307a
umask 166
d0d307a
d0d307a
# get_config [config default]
d0d307a
# extracts config option from config file
d0d307a
get_config() {
d0d307a
  if config=$(grep "^$1" /etc/imapd.conf); then
d0d307a
    echo $config | cut -d: -f2
d0d307a
  else
d0d307a
    echo $2
d0d307a
  fi
d0d307a
}
d0d307a
d0d307a
# where to find files and directories
d0d307a
imap_prefix=$(get_config configdirectory /var/lib/imap)
d0d307a
group_cache=${imap_prefix}/group.cache
d0d307a
d0d307a
TMPCACHE=$(mktemp ${group_cache}.XXXXXX) || exit 1
d0d307a
getent group >> $TMPCACHE
d0d307a
mv -f $TMPCACHE $group_cache