Blob Blame Raw
#!/bin/sh

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This script updates a cache of the unix group database. It's purpose is to
# speedup group authorization when using large groups with slow nss backends.
# For more info consult the README.groupcache file.
#
# This script can safely be run as root, it will reexec itself as user
# cyrus if needed.
#
# author: Simon Matter, Invoca Systems <simon.matter@invoca.ch>

# changelog
# v1.0.0, Dec 15 2004 Simon Matter <simon.matter@invoca.ch>
# - initial release

if [ ! -f /etc/imapd.conf ]; then
  echo "ERROR: configuration file not found."
  exit 1
fi

# fallback to su if runuser not available
if [ -x /sbin/runuser ]; then
  RUNUSER=runuser
else
  RUNUSER=su
fi

# force cyrus user for security reasons
if [ ! $(whoami) = "cyrus" ]; then
  exec $RUNUSER - cyrus -c "cd $PWD < /dev/null ; $0"
fi

# files get mode 0600
umask 166

# get_config [config default]
# extracts config option from config file
get_config() {
  if config=$(grep "^$1" /etc/imapd.conf); then
    echo $config | cut -d: -f2
  else
    echo $2
  fi
}

# where to find files and directories
imap_prefix=$(get_config configdirectory /var/lib/imap)
group_cache=${imap_prefix}/group.cache

TMPCACHE=$(mktemp ${group_cache}.XXXXXX) || exit 1
getent group >> $TMPCACHE
mv -f $TMPCACHE $group_cache