aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/auth/factotum/wep.c
blob: 701018e776006662de0cc4c78ce27622f8881cff (plain)
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
/*
 * Copy WEP key to ethernet device.
 */

#include "std.h"
#include "dat.h"

static int
wepclient(Conv *c)
{
	char *dev, buf[128], *p, *kp;
	Key *k;
	int ret, fd, cfd;

	fd = cfd = -1;
	ret = -1;
	dev = nil;

	if((k = keylookup("%A !key1?", c->attr)) == nil
	&& (k = keylookup("%A !key2?", c->attr)) == nil
	&& (k = keylookup("%A !key3?", c->attr)) == nil){
		werrstr("cannot find wep keys");
		goto out;
	}
	if(convreadm(c, &dev) < 0)
		return -1;
	if(dev[0] != '#' || dev[1] != 'l'){
		werrstr("not an ethernet device: %s", dev);
		goto out;
	}
	snprint(buf, sizeof buf, "%s!0", dev);
	if((fd = dial(buf, 0, 0, &cfd)) < 0)
		goto out;
	if(!(p = strfindattr(k->privattr, kp="!key1"))
	&& !(p = strfindattr(k->privattr, kp="key2"))
	&& !(p = strfindattr(k->privattr, kp="key3"))){
		werrstr("lost key");
		goto out;
	}
	if(fprint(cfd, "%s %q", kp+1, p) < 0)
		goto out;
	if((p = strfindattr(k->attr, "essid")) != nil
	&& fprint(cfd, "essid %q", p) < 0)
		goto out;
	if(fprint(cfd, "crypt on") < 0)
		goto out;
	ret = 0;

out:
	free(dev);
	if(cfd >= 0)
		close(cfd);
	if(fd >= 0)
		close(fd);
	keyclose(k);
	return ret;
}

static int
wepcheck(Key *k)
{
	if(strfindattr(k->privattr, "!key1") == nil
	&& strfindattr(k->privattr, "!key2") == nil
	&& strfindattr(k->privattr, "!key3") == nil){
		werrstr("need !key1, !key2, or !key3 attribute");
		return -1;
	}
	return 0;
}

static Role weproles[] = {
	"client",	wepclient,
	0
};

Proto wep =
{
	"wep",
	weproles,
	nil,
	wepcheck,
	nil
};