File: //proc/self/root/opt/VRTSpbx/bin/vxpbxserviceusercmd
#!/bin/sh
LC_ALL=C
export LC_ALL
PBXROOT="/opt/VRTSpbx"
DIRLIST="
/var/VRTSpbx
/var/log/VRTSpbx
"
TESTDIR="/var/testDir"
LOGFILE="/var/log/VRTSpbx/vxpbxserviceusercmd.log"
usage() {
echo "Usage: $0 <service username>";
}
if [ $# -ne 1 ]; then
usage
exit 1;
fi
SERVICE_USER=$1
logmsg() {
FILENAME="vxpbxserviceusercmd"
if [ $1 -eq 1 ]; then
echo "$FILENAME: $2"
fi
echo "$FILENAME: $2" >> $LOGFILE
}
# Restrict the use of this script to root only.
ISROOT=`id | egrep "^uid=0\("`
if [ "${ISROOT}" = "" ] ; then
logmsg 1 "You must be a superuser to run the script"
exit 1
fi
# Check if PBX is running
ISRUNNING=`ps -ef | grep pbx_exchange | grep -v "grep"`
if [ "${ISRUNNING}" != "" ] ; then
logmsg 1 "Stop the PBX exchange before you run this command."
exit 1
fi
change_service_user() {
SUSER=$1
if [ ! -f $PBXROOT/bin/pbxcfg ]; then
logmsg 0 "File $PBXROOT/bin/pbxcfg does not exist."
return 1
fi
$PBXROOT/bin/pbxcfg -a -S $SUSER
if [ $? != 0 ]; then
logmsg 1 "Failed, adding $SUSER to the configuration file"
return 1
fi
for dir in $DIRLIST; do
if [ -d "$dir" ]; then
chown -R $SUSER $dir
else
mkdir -m 755 $dir
chown $SUSER $dir
fi
done
return 0
}
check_acl() {
TDIR=$1
SUSER=$2
TESTFILE="testFile"
OS=`uname`
rm -rf $TDIR
mkdir -m 755 $TDIR
RETVAL=0
case $OS in
AIX)
ACLTEXT="
*
* ACL_type AIXC
*
attributes: SUID
base permissions
owner(root): rw-
group(system): r--
others: r--
extended permissions
enabled
permit rw- u:"$SUSER
CWD=`pwd`
cd $TDIR
touch $TESTFILE
aclput $TESTFILE << EOF > /dev/null 2>&1
$ACLTEXT
EOF
if [ $? -ne 0 ]; then
logmsg 0 "Failed to set ACL premission for the file"
RETVAL=1
fi
aclget $TESTFILE 2>&1 | grep $SUSER > /dev/null 2>&1
if [ $? -ne 0 ]; then
logmsg 0 "Failed to retrieve ACL premissions of the file"
RETVAL=1
fi
cd $CWD
rm -rf $TDIR
;;
SunOS | Linux)
CWD=`pwd`
cd $TDIR
touch $TESTFILE
setfacl -m user:$SUSER:rw- $TESTFILE > /dev/null 2>&1
if [ $? -ne 0 ]; then
logmsg 0 "Failed to set ACL permission for the file"
RETVAL=1
fi
getfacl $TESTFILE 2>&1 | grep $SUSER > /dev/null 2>&1
if [ $? -ne 0 ]; then
logmsg 0 "Failed to retrieve ACL permissions of the file"
RETVAL=1
fi
cd $CWD
rm -rf $TDIR
;;
esac
return "$RETVAL"
}
if [ "$SERVICE_USER" = "" ]; then
usage
else
ERRORMSG=0
if id $SERVICE_USER > /dev/null 2>&1; then
check_acl $TESTDIR $SERVICE_USER
retval=$?
if [ "$retval" != 0 ]; then
logmsg 1 "ACL is not supported on the system. PBX exchange will be run with the root user permissions."
SERVICE_USER="root"
ERRORMSG=0
fi
change_service_user $SERVICE_USER
if [ $? -ne 0 ]; then
ERRORMSG=1
fi
else
logmsg 1 "The specified service username is not valid."
ERRORMSG=1
fi
if [ $ERRORMSG -eq 1 ]; then
echo "Failed to configure service user. For more information check $LOGFILE"
else
echo "Successfully changed service user to '$SERVICE_USER'."
fi
fi