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