1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#include <u.h>
#include <libc.h>
#include <auth.h>
typedef struct Test Test;
struct Test
{
char *name;
int (*server)(Test*, AuthRpc*, int);
int (*client)(Test*, int);
};
int
ai2status(AuthInfo *ai)
{
if(ai == nil)
return -1;
auth_freeAI(ai);
return 0;
}
int
proxyserver(Test *t, AuthRpc *rpc, int fd)
{
char buf[1024];
sprint(buf, "proto=%q role=server", t->name);
return ai2status(fauth_proxy(fd, rpc, nil, buf));
}
int
proxyclient(Test *t, int fd)
{
return ai2status(auth_proxy(fd, auth_getkey, "proto=%q role=client", t->name));
}
Test test[] =
{
"apop", proxyserver, proxyclient,
"cram", proxyserver, proxyclient,
"p9sk1", proxyserver, proxyclient,
"p9sk2", proxyserver, proxyclient,
"p9any", proxyserver, proxyclient,
};
void
usage(void)
{
fprint(2, "usage: test [name]...\n");
exits("usage");
}
void
runtest(AuthRpc *srpc, Test *t)
{
int p[2], bad;
Waitmsg *w;
if(pipe(p) < 0)
sysfatal("pipe: %r");
print("%s...", t->name);
switch(fork()){
case -1:
sysfatal("fork: %r");
case 0:
close(p[0]);
if((*t->server)(t, srpc, p[1]) < 0){
print("\n\tserver: %r");
_exits("oops");
}
close(p[1]);
_exits(nil);
default:
close(p[1]);
if((*t->client)(t, p[0]) < 0){
print("\n\tclient: %r");
bad = 1;
}
close(p[0]);
break;
}
w = wait();
if(w->msg[0])
bad = 1;
print("\n");
}
void
main(int argc, char **argv)
{
int i, j;
int afd;
AuthRpc *srpc;
ARGBEGIN{
default:
usage();
}ARGEND
quotefmtinstall();
afd = open("/n/kremvax/factotum/rpc", ORDWR);
if(afd < 0)
sysfatal("open /n/kremvax/factotum/rpc: %r");
srpc = auth_allocrpc(afd);
if(srpc == nil)
sysfatal("auth_allocrpc: %r");
if(argc == 0)
for(i=0; i<nelem(test); i++)
runtest(srpc, &test[i]);
else
for(i=0; i<argc; i++)
for(j=0; j<nelem(test); j++)
if(strcmp(argv[i], test[j].name) == 0)
runtest(srpc, &test[j]);
exits(nil);
}
|