#!/bin/sh # Install a linuxkmsgd service directory. cleanup () { rm -f $$groupof $$groupof.c } die () { echo >&2 $1 cleanup exit 21 } _mkdir () { mkdir $1 || die "Unable to make directory $1" } _chmod () { chmod $1 $2 || die "Unable to change mode of $2 to $1" } _chowngrp () { chown $1 $3 || die "Unable to set owner of $3 to $1" chgrp $2 $3 || die "Unable to set group of $3 to $1" } _cd () { cd $1 || die "Unable to change to $1" } _touch () { touch $1 || die "Unable to touch $1" } if [ $# -lt 3 ] ; then echo Usage: mkservice account logaccount servicedir echo e.g. mkservice root kernellog /etc/linuxkmsgd exit 20 fi cat >$$groupof.c < #include #include struct passwd *pw; int main(int argc, char **argv) { if (argc != 2) exit(20); pw = getpwnam(argv[1]); if (!pw) exit(21); printf("%d\n", pw->pw_gid); exit(0); } EOF cc -o $$groupof $$groupof.c || die "Unable to compile groupof program" user=$1 grp=`./$$groupof $user` || die "Unable to get group of $user" loguser=$2 loggrp=`./$$groupof $loguser` || die "Unable to get group of $loguser" dir=$3 _mkdir $dir _chmod 03700 $dir _cd $dir _mkdir log _chmod 02755 log _mkdir log/main _chowngrp $loguser $loggrp log/main _chmod 02755 log/main _touch log/main/status _chowngrp $loguser $loggrp log/main/status _chmod 0644 log/main/status _touch run _chmod 0644 run cat >run <&1 exec setuidgid $user #some command# EOF _chmod 0755 run _touch log/run _chmod 0644 log/run cat >log/run <