summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2002-04-20 13:42:53 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2002-04-20 13:42:53 +0000
commit89ef1693e0fed4dd80d8afa1c98a120a4627b040 (patch)
treebe678e86c8eb513ad5fda87e2bb578d9758441f4
parentd1224fc6f855f84f2fe5c3660748fb7f94da9e27 (diff)
Split out a new function askpass() and as a result
greatly simplify both getresp() and the code around obtaining passwords. Shrinks, simplifies and makes the code clearer. From espie@. ok deraadt@ and espie@.
-rw-r--r--distrib/miniroot/install.sh16
-rw-r--r--distrib/miniroot/install.sub62
2 files changed, 34 insertions, 44 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh
index 2aff7e7c0e0..57a22686660 100644
--- a/distrib/miniroot/install.sh
+++ b/distrib/miniroot/install.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: install.sh,v 1.95 2002/04/12 03:24:02 millert Exp $
+# $OpenBSD: install.sh,v 1.96 2002/04/20 13:42:52 krw Exp $
# $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -294,19 +294,11 @@ _oifs=$IFS
IFS=
resp=
while [ -z "$resp" ]; do
- echo -n "Password (will not echo): "
- stty -echo
- getresp -n
- stty echo
- echo
+ askpass "Password (will not echo):"
_password=$resp
- echo -n "Password (again): "
- stty -echo
- getresp -n
- stty echo
- echo
- if [ "${_password}" != "${resp}" ]; then
+ askpass "Password (again):"
+ if [ "$_password" != "$resp" ]; then
echo "Passwords do not match, try again."
resp=
fi
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index f71549e7588..063e9a6102f 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,5 +1,5 @@
#!/bin/sh
-# $OpenBSD: install.sub,v 1.205 2002/04/13 21:03:58 deraadt Exp $
+# $OpenBSD: install.sub,v 1.206 2002/04/20 13:42:52 krw Exp $
# $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $
#
# Copyright (c) 1997-2002 Todd Miller, Theo de Raadt, Ken Westerback
@@ -84,35 +84,37 @@
# include machine dependent subroutines
. install.md
-getresp() {
- local _no_shell=0
-
- # -n option means don't try to run shell commands
- if [ "$1" = "-n" ]; then
- _no_shell=1
- shift
- fi
+# Ask for a password, saving the input in $resp.
+# Display $1 as the prompt.
+# *Don't* allow the '!' options that getresp does.
+# *Don't* echo input.
+askpass() {
+ set -o noglob
+ stty -echo
+ read resp?"$1 "
+ stty echo
+ set +o noglob
+ echo
+}
+# Ask for user input, saving the input (or the default value
+# given in $1 if the input is empty) in $resp. Allow the user
+# to escape to shells ('!') or execute commands ('!foo')
+# before entering the input.
+getresp() {
set -o noglob
- valid=
- while [ -z "$valid" ]; do
+ while : ; do
read resp
- if [ ${_no_shell} -eq 1 ]; then
- [ -z "$resp" ] && resp=$1
- else
- case $resp in
- "") resp=$1
- ;;
- !) echo "Type 'exit' to return to install."
- sh
- continue
- ;;
- !*) eval ${resp#?}
- continue
- ;;
- esac
- fi
- valid=true
+ case $resp in
+ !) echo "Type 'exit' to return to install."
+ sh
+ ;;
+ !*) eval ${resp#?}
+ ;;
+ *) : ${resp:=$1}
+ break
+ ;;
+ esac
done
set +o noglob
}
@@ -1239,11 +1241,7 @@ __EOT
if [ "${_ftp_server_login}" != "anonymous" ]; then
resp=
while [ -z "$resp" ] ; do
- echo -n "Password (will not echo): "
- stty -echo
- getresp -n "$_ftp_server_password"
- stty echo
- echo
+ askpass "Password (will not echo):"
_ftp_server_password=$resp
done
else