]> git.michaelhowe.org Git - packages/m/mh-sysadmin-tools.git/commitdiff
* with-creds now supports specification of user and realm
authorMichael Howe <michael@michaelhowe.org>
Sun, 4 Mar 2012 17:54:09 +0000 (17:54 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sun, 4 Mar 2012 17:54:09 +0000 (17:54 +0000)
bin/with-creds
debian/changelog

index d76e5692b64e2048d8b7853ad451aa702694d44a..9e4ddeacd430acf9589ba8b4cfc6202f6b4934cc 100755 (executable)
@@ -6,23 +6,39 @@
 # $LastChangedBy$
 #
 
-while getopts ":i:" opt; do
+function usage {
+    cat >&2 <<EOH
+Usage: $0 -i service_part -r REALM -u user [command]"
+EOH
+    exit 1
+}
+
+while getopts "i:r:u:h:" opt; do
     case $opt in
         i)
             userpart=$OPTARG
             ;;
+        r)
+            realm=$OPTARG
+            ;;
+        u)
+            localuser=$OPTARG
+            ;;
+        h)
+            usage
+            ;;
         \?)
-            echo "Error: unsupported option -$OPTARG" >&2
-            exit 1
+            usage
+#            echo "Error: unsupported option -$OPTARG" >&2
             ;;
     esac
 done
 
 shift $(($OPTIND - 1))
 
-if [ -z "$userpart" ]; then
-    echo "Error: no service part defined (use -i <service>)" >&2
-    exit 2
+if [ -n "$userpart" ]; then
+    userpart="$userpart"
+    userpart_slash="/$userpart"
 fi
 
 if [ $# -eq 0 ]; then
@@ -30,13 +46,29 @@ if [ $# -eq 0 ]; then
     exit 3
 fi
 
-ccache=/tmp/krb5cc_${UID}_${userpart}
+# Realm:
+REALMARG=""
+if [ -n "$realm" ]; then
+    REALMARG="@$realm"
+fi
 
-if klist -s -c $ccache; then
-    export KRB5CCNAME=$ccache
-else
-    export KRB5CCNAME=$ccache
-    kinit -p $USER/$userpart
+# Fix user:
+KRBUSER=$USER
+if [ -n "$localuser" ]; then
+    KRBUSER=$localuser
 fi
 
+PRINC=$KRBUSER$userpart_slash$REALMARG
+
+export KRB5CCNAME=/tmp/krb5cc_${UID}_${KRBUSER}_${userpart}
+
+k5start -H 30 -u "$PRINC"
+
+#if klist -s -c $ccache; then
+#    export KRB5CCNAME=$ccache
+#else
+#    export KRB5CCNAME=$ccache
+#    kinit -p $KRBUSER$userpart_slash$REALMARG
+#fi
+
 exec "$@"
index 599f7b4d1292d1c2b559b329266780259b018ea8..e67cedaaadba97074784cb97337a33375f688b96 100644 (file)
@@ -1,3 +1,9 @@
+mh-sysadmin-tools (1.2) unstable; urgency=low
+
+  * with-creds now supports specification of user and realm 
+
+ -- Michael Howe <michael@michaelhowe.org>  Sun, 04 Mar 2012 17:52:56 +0000
+
 mh-sysadmin-tools (1.1) unstable; urgency=low
 
   * Don't forward X11 when using SSH