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