From fb7a39bc56092ecd2a52d8b6fc403eda6b905ba1 Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 13 Feb 2005 18:32:56 +0000 Subject: add pass proto --- src/cmd/auth/factotum/ctl.c | 17 ++++--- src/cmd/auth/factotum/mkfile | 3 +- src/cmd/auth/factotum/pass.c | 107 ++++++++++-------------------------------- src/cmd/auth/factotum/proto.c | 2 + 4 files changed, 39 insertions(+), 90 deletions(-) (limited to 'src') diff --git a/src/cmd/auth/factotum/ctl.c b/src/cmd/auth/factotum/ctl.c index 85fbe5d8..d426f86f 100644 --- a/src/cmd/auth/factotum/ctl.c +++ b/src/cmd/auth/factotum/ctl.c @@ -36,7 +36,7 @@ ctlwrite(char *a) { char *p; int i, nmatch, ret; - Attr *attr, **l, **lpriv, **lprotos, *pa, *priv, *protos; + Attr *attr, *kpa, **l, **lpriv, **lprotos, *pa, *priv, *protos; Key *k; Proto *proto; @@ -107,17 +107,22 @@ ctlwrite(char *a) ret = -1; continue; } - if(proto->checkkey == nil){ - werrstr("proto %s does not accept keys", proto->name); - ret = -1; - continue; + if(proto->keyprompt){ + kpa = parseattr(proto->keyprompt); + if(!matchattr(kpa, attr, priv)){ + freeattr(kpa); + werrstr("missing attributes -- want %s", proto->keyprompt); + ret = -1; + continue; + } + freeattr(kpa); } k = emalloc(sizeof(Key)); k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr)); k->privattr = copyattr(priv); k->ref = 1; k->proto = proto; - if((*proto->checkkey)(k) < 0){ + if(proto->checkkey && (*proto->checkkey)(k) < 0){ ret = -1; keyclose(k); continue; diff --git a/src/cmd/auth/factotum/mkfile b/src/cmd/auth/factotum/mkfile index 7c716021..d6d58af9 100644 --- a/src/cmd/auth/factotum/mkfile +++ b/src/cmd/auth/factotum/mkfile @@ -4,8 +4,10 @@ TARG=factotum PROTO=\ apop.$O\ chap.$O\ + dsa.$O\ p9any.$O\ p9sk1.$O\ + pass.$O\ rsa.$O\ OFILES=\ @@ -14,7 +16,6 @@ OFILES=\ confirm.$O\ conv.$O\ ctl.$O\ - dsa.$O\ fs.$O\ key.$O\ log.$O\ diff --git a/src/cmd/auth/factotum/pass.c b/src/cmd/auth/factotum/pass.c index b3d4cb6a..9c6c7341 100644 --- a/src/cmd/auth/factotum/pass.c +++ b/src/cmd/auth/factotum/pass.c @@ -2,99 +2,40 @@ * This is just a repository for a password. * We don't want to encourage this, there's * no server side. + * + * Client: + * start proto=pass ... + * read password */ +#include "std.h" #include "dat.h" -typedef struct State State; -struct State -{ - Key *key; -}; - -enum -{ - HavePass, - Maxphase, -}; - -static char *phasenames[Maxphase] = -{ -[HavePass] "HavePass", -}; - static int -passinit(Proto *p, Fsstate *fss) +passproto(Conv *c) { - int ask; Key *k; - State *s; - - k = findkey(fss, Kuser, &ask, 0, fss->attr, "%s", p->keyprompt); - if(k == nil){ - if(ask) - return RpcNeedkey; - return failure(fss, nil); - } - setattrs(fss->attr, k->attr); - s = emalloc(sizeof(*s)); - s->key = k; - fss->ps = s; - return RpcOk; -} - -static void -passclose(Fsstate *fss) -{ - State *s; - - s = fss->ps; - if(s->key) - closekey(s->key); - free(s); -} - -static int -passread(Fsstate *fss, void *va, uint *n) -{ - int m; - char buf[500]; - char *pass, *user; - State *s; - - s = fss->ps; - switch(fss->phase){ - default: - return phaseerror(fss, "read"); - - case HavePass: - user = strfindattr(s->key->attr, "user"); - pass = strfindattr(s->key->privattr, "!password"); - if(user==nil || pass==nil) - return failure(fss, "passread cannot happen"); - snprint(buf, sizeof buf, "%q %q", user, pass); - m = strlen(buf); - if(m > *n) - return toosmall(fss, m); - *n = m; - memmove(va, buf, m); - return RpcOk; - } + + k = keyfetch(c, "%A", c->attr); + if(k == nil) + return -1; + c->state = "write"; + convprint(c, "%q %q", + strfindattr(k->attr, "user"), + strfindattr(k->privattr, "!password")); + return 0; } -static int -passwrite(Fsstate *fss, void*, uint) -{ - return phaseerror(fss, "write"); -} +static Role passroles[] = { + "client", passproto, + 0 +}; Proto pass = { -.name= "pass", -.init= passinit, -.write= passwrite, -.read= passread, -.close= passclose, -.addkey= replacekey, -.keyprompt= "user? !password?", + "pass", + passroles, + "user? !password?", + nil, + nil, }; diff --git a/src/cmd/auth/factotum/proto.c b/src/cmd/auth/factotum/proto.c index a455bd0a..5a65e5cd 100644 --- a/src/cmd/auth/factotum/proto.c +++ b/src/cmd/auth/factotum/proto.c @@ -9,6 +9,7 @@ extern Proto mschap; /* chap.c */ extern Proto p9any; /* p9any.c */ extern Proto p9sk1; /* p9sk1.c */ extern Proto p9sk2; /* p9sk2.c */ +extern Proto pass; /* pass.c */ extern Proto rsa; /* rsa.c */ Proto *prototab[] = { @@ -18,6 +19,7 @@ Proto *prototab[] = { &p9any, &p9sk1, &p9sk2, + &pass, &rsa, nil, }; -- cgit v1.2.3