wm: infra

Download patch

ref: dd36a9b70597a241f72799fea39d2ba9cdd9e8bf
parent: 59010de9c8def735a8229691b65848bea184c355
author: mkf <mkf@x230>
date: Thu Sep 7 08:00:07 EDT 2023

chusr.c: add debug flag, fixed two bugs and some styling changes

--- a/chusr.c
+++ b/chusr.c
@@ -10,17 +10,11 @@
 #define AUTHLOG		"auth"
 
 enum{
+    Nemail      = 10,           /* from authcmdlib.h */
 	MAXNETCHAL	= 100000,		/* max securenet challenge */
 	Maxpath		= 256,
 };
 
-enum
-{
-	Nemail		= 10,
-	Plan9		= 1,
-	Securenet	= 2,
-};
-
 typedef struct
 {
 	char	*user;
@@ -63,8 +57,8 @@
 void
 main(int argc, char *argv[])
 {
-	char *u, *pass;
-	long t;
+    int debug = 1;
+	char *u, *pass = "";
 	Authkey key;
 	Acctbio a;
 	Fs *f;
@@ -72,35 +66,45 @@
 	fmtinstall('K', deskeyfmt);
 
 	ARGBEGIN{
-    case 'd':
-        a.dept = EARGF(usage());
-        break;
-    case 'i':
-        a.postid = EARGF(usage());
-        break;
-    case 'e':
-        a.email[0] = EARGF(usage());
-        break;
-	case 'p':
-		pass = EARGF(usage());
-		break;
-    /* sponsor's email */
-    case 's':
-        // a->email[1] = EARGF(usage());
-        break;
+        case 'D':
+            debug = 1;
+            break;
 
-	default:
-		usage();
+        case 'd':
+            a.dept = EARGF(usage());
+            break;
+
+        case 'i':
+            a.postid = EARGF(usage());
+            break;
+
+        case 'e':
+            a.email[0] = EARGF(usage());
+            break;
+
+        case 'p':
+            pass = EARGF(usage());
+            break;
+
+        case 's':
+            a.email[1] = EARGF(usage());
+            break;
+
+        default:
+            usage();
+
 	}ARGEND
 
-	if(argc < 3)
-		usage();
-	u = *argv;
+	if(utflen(pass) < 8)
+        usage();
+
+	u = argv[0];
+
 	if(memchr(u, '\0', ANAMELEN) == 0)
 		sysfatal("bad user name");
+    if(!debug)
+	   private();
 
-	private();
-	t = 0;
 	a.user = 0;
 	memset(&key, 0, sizeof(key));
 	f = &fs;
@@ -107,7 +111,7 @@
 
 	passtokey(&key, pass);
 
-	install(f->keys, u, &key, t);
+	install(f->keys, u, &key, 0);
 
 	if(setsecret(KEYDB, u, pass) == 0)
 		sysfatal("error writing Inferno/POP secret");