pam/pamtool

Mon, 28 Jan 2013 17:37:18 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 28 Jan 2013 17:37:18 +0100
changeset 758
a2c6460cfb16
permissions
-rw-r--r--

Correct socket error reporting improvement with IPv6 portable code,
after helpful recommendation by Saúl Ibarra Corretgé on OSips devlist.

michael@480 1 #!/bin/sh
michael@480 2 ##
michael@480 3 ## pamtool -- OpenPKG PAM Auxiliary Tool
michael@480 4 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
michael@480 5 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
michael@480 6 ##
michael@480 7 ## Permission to use, copy, modify, and distribute this software for
michael@480 8 ## any purpose with or without fee is hereby granted, provided that
michael@480 9 ## the above copyright notice and this permission notice appear in all
michael@480 10 ## copies.
michael@480 11 ##
michael@480 12 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
michael@480 13 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
michael@480 14 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
michael@480 15 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
michael@480 16 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@480 17 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@480 18 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
michael@480 19 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
michael@480 20 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
michael@480 21 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
michael@480 22 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
michael@480 23 ## SUCH DAMAGE.
michael@480 24 ##
michael@480 25
michael@480 26 # program name, version and date
michael@480 27 progname="pamtool"
michael@480 28 progvers="0.9.0"
michael@480 29 progdate="11-Mar-2002"
michael@480 30
michael@480 31 # the OpenPKG instance information
michael@480 32 l_prefix="@l_prefix@"
michael@480 33 l_platform="@l_platform@"
michael@480 34
michael@480 35 # default parameters
michael@480 36 verbose=no
michael@480 37 help=no
michael@480 38 add=no
michael@480 39 remove=no
michael@480 40 smart=no
michael@480 41 name=""
michael@480 42 id=""
michael@480 43
michael@480 44 # iterate over argument line
michael@480 45 while [ $# -gt 0 ]; do
michael@480 46 opt=$1
michael@480 47 case $opt in
michael@480 48 -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
michael@480 49 *) arg='' ;;
michael@480 50 esac
michael@480 51 case $opt in
michael@480 52 -v|--verbose ) verbose=yes ;;
michael@480 53 -h|--help ) help=yes ;;
michael@480 54 -a|--add ) add=yes ;;
michael@480 55 -r|--remove ) remove=yes ;;
michael@480 56 -s|--smart ) smart=yes ;;
michael@480 57 --name=* ) name=$arg ;;
michael@480 58 --id=* ) id=$arg ;;
michael@480 59 -* ) help="Invalid option \`$opt'"; break ;;
michael@480 60 * ) break ;;
michael@480 61 esac
michael@480 62 shift
michael@480 63 done
michael@480 64 if [ ".$help" = .yes ]; then
michael@480 65 echo "$progname --add|--remove --name=NAME [--smart] [--id=ID]";
michael@480 66 exit 0
michael@480 67 fi
michael@480 68 if [ ".$add" = .no -a ".$remove" = .no ]; then
michael@480 69 echo "$progname:ERROR: either option -a/--add or -r/--remove have to be specified" 1>&2
michael@480 70 exit 1
michael@480 71 fi
michael@480 72 if [ ".$add" = .yes -a ".$remove" = .yes ]; then
michael@480 73 echo "$progname:ERROR: option -a/--add and -r/--remove cannot be specified in parallel" 1>&2
michael@480 74 exit 1
michael@480 75 fi
michael@480 76 if [ ".$name" = . ]; then
michael@480 77 echo "$progname:ERROR: option --name has to be specified" 1>&2
michael@480 78 exit 1
michael@480 79 fi
michael@480 80 if [ ".$id" = . ]; then
michael@480 81 id="$l_prefix:$name"
michael@480 82 fi
michael@480 83
michael@480 84
michael@480 85 # find a reasonable temporary location
michael@480 86 if [ ".$TMPDIR" != . ]; then
michael@480 87 tmpdir="$TMPDIR"
michael@480 88 elif [ ".$TEMPDIR" != . ]; then
michael@480 89 tmpdir="$TEMPDIR"
michael@480 90 else
michael@480 91 tmpdir="/tmp"
michael@480 92 fi
michael@480 93 tmpfile="$tmpdir/pamtool.$$.tmp"
michael@480 94
michael@480 95 # determine PAM information from OpenPKG configuration
michael@480 96 if [ ! -f "$l_prefix/etc/rc" ]; then
michael@480 97 echo "$progname:$ERROR: OpenPKG run-command facility not found under $l_prefix" 1>&2
michael@480 98 exit 1
michael@480 99 fi
michael@480 100 pam_enable=`$l_prefix/bin/openpkg rc --query pam_enable`
michael@480 101 pam_cfgloc=`$l_prefix/bin/openpkg rc --query pam_cfgloc`
michael@480 102 pam_modpfx=`$l_prefix/bin/openpkg rc --query pam_modpfx`
michael@480 103
michael@480 104 # perform operation
michael@480 105 if [ ! -f "$l_prefix/lib/openpkg/rpmtool" ]; then
michael@480 106 echo "$progname:$ERROR: OpenPKG rpmtool not found under $l_prefix/sbin/" 1>&2
michael@480 107 exit 1
michael@480 108 fi
michael@480 109 rpmtool_config="$l_prefix/lib/openpkg/rpmtool config"
michael@480 110 if [ ".$smart" = .yes ]; then
michael@480 111 rpmtool_config="$rpmtool_config -s"
michael@480 112 fi
michael@480 113 if [ ".$add" = .yes ]; then
michael@480 114 #
michael@480 115 # add a PAM entry
michael@480 116 #
michael@480 117
michael@480 118 # determine platform specific PAM entries
michael@480 119 ( case "$l_platform" in
michael@480 120 *-freebsd* )
michael@480 121 echo "auth sufficient ${pam_modpfx}pam_opie.so no_warn no_fake_prompts"
michael@480 122 echo "auth requisite ${pam_modpfx}pam_opieaccess.so no_warn allow_local"
michael@480 123 echo "auth required ${pam_modpfx}pam_unix.so try_first_pass"
michael@480 124 echo "account required ${pam_modpfx}pam_unix.so"
michael@480 125 echo "password required ${pam_modpfx}pam_permit.so"
michael@480 126 echo "session required ${pam_modpfx}pam_permit.so"
michael@480 127 ;;
michael@480 128 *-linux* )
michael@480 129 echo "auth required ${pam_modpfx}pam_unix_auth.so shadow nodelay"
michael@480 130 echo "auth required ${pam_modpfx}pam_nologin.so"
michael@480 131 echo "account required ${pam_modpfx}pam_unix_acct.so"
michael@480 132 echo "password required ${pam_modpfx}pam_unix_passwd.so shadow nullok use_authtok"
michael@480 133 echo "session required ${pam_modpfx}pam_unix_session.so"
michael@480 134 echo "session required ${pam_modpfx}pam_limits.so"
michael@480 135 ;;
michael@480 136 *-sunos* )
michael@480 137 echo "auth required ${pam_modpfx}pam_unix.so try_first_pass"
michael@480 138 echo "account required ${pam_modpfx}pam_unix.so"
michael@480 139 echo "password required ${pam_modpfx}pam_unix.so"
michael@480 140 echo "session required ${pam_modpfx}pam_unix.so"
michael@480 141 ;;
michael@480 142 *-aix* )
michael@480 143 echo "auth required ${pam_modpfx}pam_aix try_first_pass"
michael@480 144 echo "account required ${pam_modpfx}pam_aix"
michael@480 145 echo "password required ${pam_modpfx}pam_aix"
michael@480 146 echo "session required ${pam_modpfx}pam_aix"
michael@480 147 ;;
michael@480 148 * )
michael@480 149 echo "auth required ${pam_modpfx}pam_unix.so try_first_pass"
michael@480 150 echo "account required ${pam_modpfx}pam_unix.so"
michael@480 151 echo "password required ${pam_modpfx}pam_unix.so"
michael@480 152 echo "session required ${pam_modpfx}pam_unix.so"
michael@480 153 ;;
michael@480 154 esac
michael@480 155 ) >$tmpfile
michael@480 156
michael@480 157 # add application name prefix if using combined configuration
michael@480 158 if [ -f $pam_cfgloc ]; then
michael@480 159 sed -e "s;^;$name ;" <$tmpfile >$tmpfile.n
michael@480 160 mv $tmpfile.n $tmpfile
michael@480 161 fi
michael@480 162
michael@480 163 # create entry
michael@480 164 if [ -f $pam_cfgloc ]; then
michael@480 165 if [ ".$verbose" = .yes ]; then
michael@480 166 echo "++ adding entry to $pam_cfgloc"
michael@480 167 fi
michael@480 168 $rpmtool_config -a -i $id $pam_cfgloc <$tmpfile || exit $?
michael@480 169 elif [ -d $pam_cfgloc ]; then
michael@480 170 if [ ".$verbose" = .yes ]; then
michael@480 171 echo "++ adding entry to $pam_cfgloc/$name"
michael@480 172 fi
michael@480 173 $rpmtool_config -a -i $id $pam_cfgloc/$name <$tmpfile || exit $?
michael@480 174 fi
michael@480 175
michael@480 176 elif [ ".$remove" = .yes ]; then
michael@480 177 #
michael@480 178 # remove a PAM entry
michael@480 179 #
michael@480 180
michael@480 181 # remove entry
michael@480 182 if [ -f $pam_cfgloc ]; then
michael@480 183 if [ ".$verbose" = .yes ]; then
michael@480 184 echo "++ removing entry from $pam_cfgloc"
michael@480 185 fi
michael@480 186 $rpmtool_config -r -i $id $pam_cfgloc || exit $?
michael@480 187 elif [ -d $pam_cfgloc ]; then
michael@480 188 if [ ".$verbose" = .yes ]; then
michael@480 189 echo "++ removing entry from $pam_cfgloc/$name"
michael@480 190 fi
michael@480 191 $rpmtool_config -r -i $id $pam_cfgloc/$name || exit $?
michael@480 192 if [ ! -s $pam_cfgloc/$name ]; then
michael@480 193 rm -f $pam_cfgloc/$name >/dev/null 2>&1 || true
michael@480 194 fi
michael@480 195 fi
michael@480 196 fi
michael@480 197
michael@480 198 # cleanup
michael@480 199 rm -f $tmpfile
michael@480 200 exit 0
michael@480 201

mercurial