aboutsummaryrefslogtreecommitdiff
path: root/src/libsunrpc/authunix.c
blob: 43600163949fc7a93cdf5b870cda485854e91ee8 (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
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <sunrpc.h>

uint
sunauthunixsize(SunAuthUnix *x)
{
	return 4 + sunstringsize(x->sysname) + 4 + 4 + 4 + 4*x->ng;
}
int
sunauthunixunpack(uchar *a, uchar *ea, uchar **pa, SunAuthUnix *x)
{
	int i;

	if(sunuint32unpack(a, ea, &a, &x->stamp) < 0) goto Err;
	if(sunstringunpack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
	if(sunuint32unpack(a, ea, &a, &x->uid) < 0) goto Err;
	if(sunuint32unpack(a, ea, &a, &x->gid) < 0) goto Err;
	if(sunuint32unpack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
	for(i=0; i<x->ng; i++)
		if(sunuint32unpack(a, ea, &a, &x->g[i]) < 0) goto Err;

	*pa = a;
	return 0;

Err:
	*pa = ea;
	return -1;
}
int
sunauthunixpack(uchar *a, uchar *ea, uchar **pa, SunAuthUnix *x)
{
	int i;

	if(sunuint32pack(a, ea, &a, &x->stamp) < 0) goto Err;
	if(sunstringpack(a, ea, &a, &x->sysname, 256) < 0) goto Err;
	if(sunuint32pack(a, ea, &a, &x->uid) < 0) goto Err;
	if(sunuint32pack(a, ea, &a, &x->gid) < 0) goto Err;
	if(sunuint32pack(a, ea, &a, &x->ng) < 0 || x->ng > nelem(x->g)) goto Err;
	for(i=0; i<x->ng; i++)
		if(sunuint32pack(a, ea, &a, &x->g[i]) < 0) goto Err;

	*pa = a;
	return 0;

Err:
	*pa = ea;
	return -1;
}
void
sunauthunixprint(Fmt *fmt, SunAuthUnix *x)
{
	int i;
	fmtprint(fmt, "unix %.8lux %s %lud %lud (", (ulong)x->stamp,
		x->sysname, (ulong)x->uid, (ulong)x->gid);
	for(i=0; i<x->ng; i++)
		fmtprint(fmt, "%s%lud", i ? " ":"", (ulong)x->g[i]);
	fmtprint(fmt, ")");
}