12 #define EPROTONOSUPPORT 93 // XXX
17 int (*auth
)(Npcfid
*fid
, Npuser
*user
, void *aux
);
20 static struct authproto authprotos
[] = {
21 { "p9sk1", authp9sk1
},
26 srvp9any(struct npsrvauth
*a
, char *msg
, int len
, char *resp
, int resplen
)
34 || resplen
< strlen(a
->dom
) + 32)
35 return err("internal error", EINVAL
);
36 sprintf(resp
, "v.2 p9sk1@%s", a
->dom
);
38 return strlen(resp
) + 1;
43 || strlen(msg
) != len
-1
44 || getWord(&msg
, ' ', &proto
) == -1
45 || getWord(&msg
, 0, &dom
) == -1
46 || strcmp(dom
, a
->dom
) != 0)
47 return err("botch", EINVAL
);
48 if(strcmp(proto
, "p9sk1") != 0)
49 return err("unsupported", EPROTONOSUPPORT
);
51 return err("internal error", EINVAL
);
54 return strlen(resp
) + 1;
57 a
->state
-= 1; // map state [2..] to [1..] (skip state 0)
58 r
= srvp9sk1(a
, msg
, len
, resp
, resplen
);
66 authp9any(Npcfid
*afid
, Npuser
*user
, void *aux
)
68 char buf
[128], *p
, *word
, *proto
, *dom
;
69 int (*found
)(Npcfid
*afid
, Npuser
*user
, void *aux
);
72 if(getline0(afid
, buf
, sizeof buf
) <= 0)
73 return err("botch", EINVAL
);
78 if(strncmp(p
, "v.2 ", 4) == 0) {
83 if(getWord(&p
, ' ', &word
) == -1
84 || getWord(&word
, '@', &proto
) == -1
85 || getWord(&word
, 0, &dom
) == -1)
86 return err("botch", EINVAL
);
87 for(i
= 0; authprotos
[i
].name
; i
++) {
88 if(strcmp(authprotos
[i
].name
, "p9sk1") == 0) {
89 found
= authprotos
[i
].auth
;
95 return err("unsupported", EPROTONOSUPPORT
);
97 if(putline0(afid
, "%s %s", proto
, dom
) <= 0)
98 return err("botch", EINVAL
);
101 if(getline0(afid
, buf
, sizeof buf
) <= 0)
102 return err("botch", EINVAL
);
103 if(strcmp(buf
, "OK") != 0)
104 return err("botch", EINVAL
);
106 return found(afid
, user
, aux
);