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