wm: infra

Download patch

ref: 36c4e4304686a1db0d46b810857e7ac484ecf3b5
parent: dd36a9b70597a241f72799fea39d2ba9cdd9e8bf
author: mkf <mkf@cloud9p.org>
date: Fri Sep 8 02:23:12 EDT 2023

newuser: enable user automaticly, fix some bugs, dont do auth/as

--- a/newuser
+++ b/newuser
@@ -1,5 +1,4 @@
 #!/bin/rc
-
 run_newuser=t
 
 fn usage {
@@ -9,13 +8,13 @@
 
 while (~ $1 -*) {
 	switch ($1) {
-    case -[dier]
-        x=$1 $2
-        shift
-    case -n
-        run_newuser=f
-	case -*
-	   usage
+		case -[dier]
+        		x=$1 $2
+        		shift
+		case -n
+			run_newuser=f
+		case -*
+	 		usage
 	}
 	shift
 }
@@ -22,22 +21,34 @@
 
 if (~ $#* 3) {
 
-    s=$1
-    u=$2
-    p=$3
+	s=$1
+	u=$2
+	p=$3
 
-    if(test -w /srv/cwfs.cmd){
-        echo newsuer $1 >> /srv/cwfs.cmd
-        wm/chusr $x -s $s -p $p $u
-        if(~ $run_newuser t)
-            auth/as $u /sys/lib/newuser
-    }
+	auth/keyfs
 
-    if not
-    {
-        echo 'no cwfs.cmd or access to it'>[2=1]
-        exit 'no cwfs.cmd or access to it'
-    }
+	if(test -w /srv/cwfs.cmd){
+	echo newuser $u >> /srv/cwfs.cmd
+	wm/chusr $x -s $s -p $p $u
+	if(~ $run_newuser t) {
+		# auth/as $u /sys/lib/newuserb # messes up with namespace
+		if(! test -f /env/authdom)
+			authdom=`{ndb/query sys $sysname authdom}
+
+		if(! test -f /env/authdom) {
+					echo 'newuser: no authdom variable or entry in ndb' >[1=2]
+					exit 'no authdom'
+		}
+		echo 'key user='$u' proto=p9sk1 dom='$authdom' role=client !password='$p >/mnt/factotum/ctl
+		rcpu -u $u -c /sys/lib/newuser
+	}
+	auth/enable $u
+	}
+
+	if not {
+		echo 'no cwfs.cmd or access to it'>[2=1]
+		exit 'no cwfs.cmd or access to it'
+	}
 
 }
 if not