ref: ffb120199a951396f7e99aeca453715dc4e65601
parent: 226cb1405853edadc0bac6749bff0b89e3c693f2
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Mar 23 14:10:04 EDT 2014
auth/login: find authdom instead of using hardcoded cs.bell-labs.com (thanks erik)
--- a/sys/man/8/auth
+++ b/sys/man/8/auth
@@ -35,6 +35,10 @@
.B auth/wrkey
.PP
.B auth/login
+[
+.B -a
+.I authdom
+]
.I user
.PP
.B auth/newns
--- a/sys/src/cmd/auth/login.c
+++ b/sys/src/cmd/auth/login.c
@@ -2,7 +2,11 @@
#include <libc.h>
#include <auth.h>
#include <authsrv.h>
+#include <bio.h>
+#include <ndb.h>
+char *authdom;
+
void
readln(char *prompt, char *line, int len, int raw)
{
@@ -111,6 +115,35 @@
}
/*
+ * find authdom
+ */
+char*
+getauthdom(void)
+{
+ char *sysname, *s;
+ Ndbtuple *t, *p;
+
+ if(authdom != nil)
+ return authdom;
+
+ sysname = getenv("sysname");
+ if(sysname == nil)
+ return strdup("cs.bell-labs.com");
+
+ s = "authdom";
+ t = csipinfo(nil, "sys", sysname, &s, 1);
+ free(sysname);
+ for(p = t; p != nil; p = p->entry)
+ if(strcmp(p->attr, s) == 0){
+ authdom = strdup(p->val);
+ break;
+ }
+ ndbfree(t);
+fprint(2, "authdom=%s\n", authdom);
+ return authdom;
+}
+
+/*
* start a new factotum and pass it the username and password
*/
void
@@ -141,11 +174,18 @@
fd = open("/mnt/factotum/ctl", ORDWR);
if(fd < 0)
sysfatal("opening factotum: %r");
- fprint(fd, "key proto=p9sk1 dom=cs.bell-labs.com user=%q !password=%q", user, password);
+ fprint(fd, "key proto=p9sk1 dom=%s user=%q !password=%q", getauthdom(), user, password);
close(fd);
}
void
+usage(void)
+{
+ fprint(2, "usage: %s [-a authdom] user\n", argv0);
+ exits("");
+}
+
+void
main(int argc, char *argv[])
{
char pass[ANAMELEN];
@@ -156,7 +196,16 @@
AuthInfo *ai;
ARGBEGIN{
+ case 'a':
+ authdom = EARGF(usage());
+ break;
+ default:
+ usage();
+ break;
}ARGEND;
+
+ if(argc != 1)
+ usage();
rfork(RFENVG|RFNAMEG);