add pass proto

This commit is contained in:
rsc 2005-02-13 18:32:56 +00:00
parent 05abefb2a0
commit fb7a39bc56
4 changed files with 39 additions and 90 deletions

View file

@ -36,7 +36,7 @@ ctlwrite(char *a)
{ {
char *p; char *p;
int i, nmatch, ret; int i, nmatch, ret;
Attr *attr, **l, **lpriv, **lprotos, *pa, *priv, *protos; Attr *attr, *kpa, **l, **lpriv, **lprotos, *pa, *priv, *protos;
Key *k; Key *k;
Proto *proto; Proto *proto;
@ -107,17 +107,22 @@ ctlwrite(char *a)
ret = -1; ret = -1;
continue; continue;
} }
if(proto->checkkey == nil){ if(proto->keyprompt){
werrstr("proto %s does not accept keys", proto->name); kpa = parseattr(proto->keyprompt);
ret = -1; if(!matchattr(kpa, attr, priv)){
continue; freeattr(kpa);
werrstr("missing attributes -- want %s", proto->keyprompt);
ret = -1;
continue;
}
freeattr(kpa);
} }
k = emalloc(sizeof(Key)); k = emalloc(sizeof(Key));
k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr)); k->attr = mkattr(AttrNameval, "proto", proto->name, copyattr(attr));
k->privattr = copyattr(priv); k->privattr = copyattr(priv);
k->ref = 1; k->ref = 1;
k->proto = proto; k->proto = proto;
if((*proto->checkkey)(k) < 0){ if(proto->checkkey && (*proto->checkkey)(k) < 0){
ret = -1; ret = -1;
keyclose(k); keyclose(k);
continue; continue;

View file

@ -4,8 +4,10 @@ TARG=factotum
PROTO=\ PROTO=\
apop.$O\ apop.$O\
chap.$O\ chap.$O\
dsa.$O\
p9any.$O\ p9any.$O\
p9sk1.$O\ p9sk1.$O\
pass.$O\
rsa.$O\ rsa.$O\
OFILES=\ OFILES=\
@ -14,7 +16,6 @@ OFILES=\
confirm.$O\ confirm.$O\
conv.$O\ conv.$O\
ctl.$O\ ctl.$O\
dsa.$O\
fs.$O\ fs.$O\
key.$O\ key.$O\
log.$O\ log.$O\

View file

@ -2,99 +2,40 @@
* This is just a repository for a password. * This is just a repository for a password.
* We don't want to encourage this, there's * We don't want to encourage this, there's
* no server side. * no server side.
*
* Client:
* start proto=pass ...
* read password
*/ */
#include "std.h"
#include "dat.h" #include "dat.h"
typedef struct State State;
struct State
{
Key *key;
};
enum
{
HavePass,
Maxphase,
};
static char *phasenames[Maxphase] =
{
[HavePass] "HavePass",
};
static int static int
passinit(Proto *p, Fsstate *fss) passproto(Conv *c)
{ {
int ask;
Key *k; Key *k;
State *s;
k = keyfetch(c, "%A", c->attr);
k = findkey(fss, Kuser, &ask, 0, fss->attr, "%s", p->keyprompt); if(k == nil)
if(k == nil){ return -1;
if(ask) c->state = "write";
return RpcNeedkey; convprint(c, "%q %q",
return failure(fss, nil); strfindattr(k->attr, "user"),
} strfindattr(k->privattr, "!password"));
setattrs(fss->attr, k->attr); return 0;
s = emalloc(sizeof(*s));
s->key = k;
fss->ps = s;
return RpcOk;
} }
static void static Role passroles[] = {
passclose(Fsstate *fss) "client", passproto,
{ 0
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;
}
}
static int
passwrite(Fsstate *fss, void*, uint)
{
return phaseerror(fss, "write");
}
Proto pass = Proto pass =
{ {
.name= "pass", "pass",
.init= passinit, passroles,
.write= passwrite, "user? !password?",
.read= passread, nil,
.close= passclose, nil,
.addkey= replacekey,
.keyprompt= "user? !password?",
}; };

View file

@ -9,6 +9,7 @@ extern Proto mschap; /* chap.c */
extern Proto p9any; /* p9any.c */ extern Proto p9any; /* p9any.c */
extern Proto p9sk1; /* p9sk1.c */ extern Proto p9sk1; /* p9sk1.c */
extern Proto p9sk2; /* p9sk2.c */ extern Proto p9sk2; /* p9sk2.c */
extern Proto pass; /* pass.c */
extern Proto rsa; /* rsa.c */ extern Proto rsa; /* rsa.c */
Proto *prototab[] = { Proto *prototab[] = {
@ -18,6 +19,7 @@ Proto *prototab[] = {
&p9any, &p9any,
&p9sk1, &p9sk1,
&p9sk2, &p9sk2,
&pass,
&rsa, &rsa,
nil, nil,
}; };