Project

General

Profile

Bug #8106 ยป module.c

Marcel Telka, 2017-04-26 01:58 PM

 
1
#include <sys/modctl.h>
2

    
3
static struct modlmisc modlmisc = {
4
	&mod_miscops, "TEST MODULE"
5
};
6

    
7
static struct modlinkage modlinkage = {
8
	MODREV_1,
9
	{(void *)&modlmisc, NULL}
10
};
11

    
12
#include <sys/cmn_err.h>
13
#include <rpc/rpc.h>
14

    
15
int
16
_init(void)
17
{
18
	int i;
19

    
20
	i = mod_install(&modlinkage);
21
	if (i != 0)
22
		return i;
23

    
24

    
25
	char *mem;
26
	bool_t r;
27
	mblk_t *mp;
28
	cred_t *cr = cralloc();
29
	gid_t grps[80];
30

    
31
	AUTH *auth = authloopback_create();
32
	AUTH *authsys = authkern_create();
33

    
34
	XDR xdrs;
35

    
36

    
37
	if (crsetgroups(cr, 70, grps)) {
38
		cmn_err(CE_NOTE, "!crsetgroups(70) failed");
39
	}
40

    
41
	mem = kmem_alloc(1024, KM_SLEEP);
42
	xdrmem_create(&xdrs, mem, 1024, XDR_ENCODE);
43
	r = AUTH_MARSHALL(auth, &xdrs, cr);
44
	if (r) {
45
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 70 groups, xdrmem success: %02x%02x%02x%02x %02x%02x%02x%02x",
46
		    (uint8_t) mem[0], (uint8_t) mem[1], (uint8_t) mem[2], (uint8_t) mem[3],
47
		    (uint8_t) mem[4], (uint8_t) mem[5], (uint8_t) mem[6], (uint8_t) mem[7]);
48
	} else {
49
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 70 groups, xdrmem FAILED");
50
	}
51
	XDR_DESTROY(&xdrs);
52
	kmem_free(mem, 1024);
53

    
54

    
55
	mp = allocb(32, BPRI_LO);
56
	xdrmblk_init(&xdrs, mp, XDR_ENCODE, 8);
57
	r = AUTH_MARSHALL(auth, &xdrs, cr);
58
	if (r) {
59
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 70 groups, xdrmblk success: %02x%02x%02x%02x %02x%02x%02x%02x",
60
		    (uint8_t) mp->b_rptr[0], (uint8_t) mp->b_rptr[1], (uint8_t) mp->b_rptr[2], (uint8_t) mp->b_rptr[3],
61
		    (uint8_t) mp->b_rptr[4], (uint8_t) mp->b_rptr[5], (uint8_t) mp->b_rptr[6], (uint8_t) mp->b_rptr[7]);
62
	} else {
63
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 70 groups, xdrmblk FAILED");
64
	}
65
	XDR_DESTROY(&xdrs);
66
	freemsg(mp);
67

    
68

    
69
	if (crsetgroups(cr, 80, grps)) {
70
		cmn_err(CE_NOTE, "!crsetgroups(80) failed");
71
	}
72

    
73
	mem = kmem_alloc(1024, KM_SLEEP);
74
	xdrmem_create(&xdrs, mem, 1024, XDR_ENCODE);
75
	r = AUTH_MARSHALL(auth, &xdrs, cr);
76
	if (r) {
77
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 80 groups, xdrmem success: %02x%02x%02x%02x %02x%02x%02x%02x",
78
		    (uint8_t) mem[0], (uint8_t) mem[1], (uint8_t) mem[2], (uint8_t) mem[3],
79
		    (uint8_t) mem[4], (uint8_t) mem[5], (uint8_t) mem[6], (uint8_t) mem[7]);
80
	} else {
81
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 80 groups, xdrmem FAILED");
82
	}
83
	XDR_DESTROY(&xdrs);
84
	kmem_free(mem, 1024);
85

    
86

    
87
	mp = allocb(32, BPRI_LO);
88
	xdrmblk_init(&xdrs, mp, XDR_ENCODE, 8);
89
	r = AUTH_MARSHALL(auth, &xdrs, cr);
90
	if (r) {
91
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 80 groups, xdrmblk success: %02x%02x%02x%02x %02x%02x%02x%02x",
92
		    (uint8_t) mp->b_rptr[0], (uint8_t) mp->b_rptr[1], (uint8_t) mp->b_rptr[2], (uint8_t) mp->b_rptr[3],
93
		    (uint8_t) mp->b_rptr[4], (uint8_t) mp->b_rptr[5], (uint8_t) mp->b_rptr[6], (uint8_t) mp->b_rptr[7]);
94
	} else {
95
		cmn_err(CE_NOTE, "!AUTH_LOOPBACK, 80 groups, xdrmblk FAILED");
96
	}
97
	XDR_DESTROY(&xdrs);
98
	freemsg(mp);
99

    
100

    
101
	mem = kmem_alloc(1024, KM_SLEEP);
102
	xdrmem_create(&xdrs, mem, 1024, XDR_ENCODE);
103
	r = AUTH_MARSHALL(authsys, &xdrs, cr);
104
	if (r) {
105
		cmn_err(CE_NOTE, "!AUTH_SYS, 80 groups, xdrmem success: %02x%02x%02x%02x %02x%02x%02x%02x",
106
		    (uint8_t) mem[0], (uint8_t) mem[1], (uint8_t) mem[2], (uint8_t) mem[3],
107
		    (uint8_t) mem[4], (uint8_t) mem[5], (uint8_t) mem[6], (uint8_t) mem[7]);
108
	} else {
109
		cmn_err(CE_NOTE, "!AUTH_SYS, 80 groups, xdrmem FAILED");
110
	}
111
	XDR_DESTROY(&xdrs);
112
	kmem_free(mem, 1024);
113

    
114

    
115
	mp = allocb(32, BPRI_LO);
116
	xdrmblk_init(&xdrs, mp, XDR_ENCODE, 8);
117
	r = AUTH_MARSHALL(authsys, &xdrs, cr);
118
	if (r) {
119
		cmn_err(CE_NOTE, "!AUTH_SYS, 80 groups, xdrmblk success: %02x%02x%02x%02x %02x%02x%02x%02x",
120
		    (uint8_t) mp->b_rptr[0], (uint8_t) mp->b_rptr[1], (uint8_t) mp->b_rptr[2], (uint8_t) mp->b_rptr[3],
121
		    (uint8_t) mp->b_rptr[4], (uint8_t) mp->b_rptr[5], (uint8_t) mp->b_rptr[6], (uint8_t) mp->b_rptr[7]);
122
	} else {
123
		cmn_err(CE_NOTE, "!AUTH_SYS, 80 groups, xdrmblk FAILED");
124
	}
125
	XDR_DESTROY(&xdrs);
126
	freemsg(mp);
127

    
128

    
129

    
130
	AUTH_DESTROY(auth);
131
	AUTH_DESTROY(authsys);
132

    
133
	crfree(cr);
134

    
135
	return (0);
136
}
137

    
138
int
139
_info(struct modinfo *modinfop)
140
{
141
	return (mod_info(&modlinkage, modinfop));
142
}
143

    
144
int
145
_fini(void)
146
{
147
	return (mod_remove(&modlinkage));
148
}
    (1-1/1)