Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include	"u.h"
2
#include	"../port/lib.h"
3
#include	"mem.h"
4
#include	"dat.h"
5
#include	"fns.h"
6
#include	"../port/error.h"
7
 
8
#include	<authsrv.h>
9
 
10
char	*eve;
11
char	hostdomain[DOMLEN];
12
 
13
/*
14
 *  return true if current user is eve
15
 */
16
int
17
iseve(void)
18
{
19
	return strcmp(eve, up->user) == 0;
20
}
21
 
22
long
23
sysfversion(ulong *arg)
24
{
25
	char *vers;
26
	uint arglen, m, msize;
27
	Chan *c;
28
 
29
	msize = arg[1];
30
	vers = (char*)arg[2];
31
	arglen = arg[3];
32
	validaddr(arg[2], arglen, 1);
33
	/* check there's a NUL in the version string */
34
	if(arglen==0 || memchr(vers, 0, arglen)==0)
35
		error(Ebadarg);
36
	c = fdtochan(arg[0], ORDWR, 0, 1);
37
	if(waserror()){
38
		cclose(c);
39
		nexterror();
40
	}
41
 
42
	m = mntversion(c, vers, msize, arglen);
43
 
44
	cclose(c);
45
	poperror();
46
	return m;
47
}
48
 
49
long
50
sys_fsession(ulong *arg)
51
{
52
	/* deprecated; backwards compatibility only */
53
 
54
	if(arg[2] == 0)
55
		error(Ebadarg);
56
	validaddr(arg[1], arg[2], 1);
57
	((uchar*)arg[1])[0] = '\0';
58
	return 0;
59
}
60
 
61
long
62
sysfauth(ulong *arg)
63
{
64
	Chan *c, *ac;
65
	char *aname;
66
	int fd;
67
 
68
	validaddr(arg[1], 1, 0);
69
	aname = validnamedup((char*)arg[1], 1);
70
	if(waserror()){
71
		free(aname);
72
		nexterror();
73
	}
74
	c = fdtochan(arg[0], ORDWR, 0, 1);
75
	if(waserror()){
76
		cclose(c);
77
		nexterror();
78
	}
79
 
80
	ac = mntauth(c, aname);
81
	/* at this point ac is responsible for keeping c alive */
82
	poperror();	/* c */
83
	cclose(c);
84
	poperror();	/* aname */
85
	free(aname);
86
 
87
	if(waserror()){
88
		cclose(ac);
89
		nexterror();
90
	}
91
 
92
	fd = newfd(ac);
93
	if(fd < 0)
94
		error(Enofd);
95
	poperror();	/* ac */
96
 
97
	/* always mark it close on exec */
98
	ac->flag |= CCEXEC;
99
 
100
	return fd;
101
}
102
 
103
/*
104
 *  called by devcons() for user device
105
 *
106
 *  anyone can become none
107
 */
108
long
109
userwrite(char *a, int n)
110
{
111
	if(n!=4 || strncmp(a, "none", 4)!=0)
112
		error(Eperm);
113
	kstrdup(&up->user, "none");
114
	up->basepri = PriNormal;
115
	return n;
116
}
117
 
118
/*
119
 *  called by devcons() for host owner/domain
120
 *
121
 *  writing hostowner also sets user
122
 */
123
long
124
hostownerwrite(char *a, int n)
125
{
126
	char buf[128];
127
 
128
	if(!iseve())
129
		error(Eperm);
130
	if(n <= 0 || n >= sizeof buf)
131
		error(Ebadarg);
132
	memmove(buf, a, n);
133
	buf[n] = 0;
134
 
135
	renameuser(eve, buf);
136
	kstrdup(&eve, buf);
137
	kstrdup(&up->user, buf);
138
	up->basepri = PriNormal;
139
	return n;
140
}
141
 
142
long
143
hostdomainwrite(char *a, int n)
144
{
145
	char buf[DOMLEN];
146
 
147
	if(!iseve())
148
		error(Eperm);
149
	if(n >= DOMLEN)
150
		error(Ebadarg);
151
	memset(buf, 0, DOMLEN);
152
	strncpy(buf, a, n);
153
	if(buf[0] == 0)
154
		error(Ebadarg);
155
	memmove(hostdomain, buf, DOMLEN);
156
	return n;
157
}