git: 9front

Download patch

ref: 5ff1ec275223dc782ec8be5d219d7d3c7f53c2a9
parent: 4f6fa04fe60dde3f55e4f07589d0373e0fe841c9
author: qwx <qwx@sciops.net>
date: Sun Nov 30 18:25:47 EST 2025

auth/userpasswd: add -n option to suppress prompt (thanks ori, noodle)

--- a/sys/man/1/totp
+++ b/sys/man/1/totp
@@ -4,6 +4,9 @@
 .SH SYNOPSIS
 .PP
 .B auth/userpasswd
+[
+.B -n
+]
 .I fmt
 .PP
 .B auth/totp
@@ -24,14 +27,19 @@
 This can be used to authenticate with services that require time based OTP.
 .PP
 .I Userpasswd
-queries and prints a cleartext user/password pair from factotum
+queries and prints a cleartext user/password pair from
+.IR factotum (4)
 for the
 .B proto=pass
 key tuple specified in
 .IR fmt .
-This can be used by shell scripts to do cleartext password
-authentication.
-Using plain password authentication with factotum is discouraged,
+Option
+.B -n
+suppresses prompting for the key if it doesn't exist.
+.I Userpasswd
+can be used by shell scripts to do cleartext password
+authentication;
+using plain password authentication with factotum is discouraged,
 as it reveals the secrets in plain text.
 .SH EXAMPLES
 .PP
@@ -55,3 +63,5 @@
 % auth/userpasswd 'server=setec service=ssh user=ori'
 toomanysecrets
 .EE
+.SH SEE ALSO
+.IR factotum (4)
--- a/sys/src/cmd/auth/userpasswd.c
+++ b/sys/src/cmd/auth/userpasswd.c
@@ -2,10 +2,12 @@
 #include <libc.h>
 #include <auth.h>
 
+int noprompt;
+
 void
 usage(void)
 {
-	fprint(2, "usage: auth/userpasswd fmt\n");
+	fprint(2, "usage: auth/userpasswd [-n] fmt\n");
 	exits("usage");
 }
 
@@ -15,6 +17,9 @@
 	UserPasswd *up;
 
 	ARGBEGIN{
+	case 'n':
+		noprompt++;
+		break;
 	default:
 		usage();
 	}ARGEND
@@ -23,7 +28,7 @@
 		usage();
 
 	quotefmtinstall();
-	up = auth_getuserpasswd(auth_getkey, "proto=pass %s", argv[0]);
+	up = auth_getuserpasswd(noprompt?nil:auth_getkey, "proto=pass %s", argv[0]);
 	if(up == nil)
 		sysfatal("getuserpasswd: %r");
 
--