xref: /onnv-gate/usr/src/uts/common/os/privs.awk (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#
2*0Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate# Use is subject to license terms.
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# CDDL HEADER START
6*0Sstevel@tonic-gate#
7*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
8*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
9*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
10*0Sstevel@tonic-gate# with the License.
11*0Sstevel@tonic-gate#
12*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
14*0Sstevel@tonic-gate# See the License for the specific language governing permissions
15*0Sstevel@tonic-gate# and limitations under the License.
16*0Sstevel@tonic-gate#
17*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
18*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
20*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
21*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate# CDDL HEADER END
24*0Sstevel@tonic-gate#
25*0Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
26*0Sstevel@tonic-gate#
27*0Sstevel@tonic-gate# This file generates three different C files:
28*0Sstevel@tonic-gate#
29*0Sstevel@tonic-gate#	<sys/priv_const.h>
30*0Sstevel@tonic-gate#		An implementation private set of manifest integer constant
31*0Sstevel@tonic-gate#		for privileges and privilege sets and manifest constants for
32*0Sstevel@tonic-gate#		set size, number of sets, number of privileges
33*0Sstevel@tonic-gate#
34*0Sstevel@tonic-gate#	os/priv_const.c
35*0Sstevel@tonic-gate#		A C source file containing the set names, privilege names
36*0Sstevel@tonic-gate#		arrays for the name <-> number mappings
37*0Sstevel@tonic-gate#
38*0Sstevel@tonic-gate#	<sys/priv_names.h>
39*0Sstevel@tonic-gate#		A public header file containing the PRIV_* defines
40*0Sstevel@tonic-gate#		that map to strings; these are for convenience.
41*0Sstevel@tonic-gate#		(it's easy to misspell a string, harder to misspell a
42*0Sstevel@tonic-gate#		manifest constant)
43*0Sstevel@tonic-gate#
44*0Sstevel@tonic-gate#	/etc/security/priv_names
45*0Sstevel@tonic-gate#		A privilege name to explanation mapping.
46*0Sstevel@tonic-gate#
47*0Sstevel@tonic-gate#
48*0Sstevel@tonic-gate# The files are output on the awk variable privhfile, pubhfile, cfile,
49*0Sstevel@tonic-gate# and pnamesfile respectively
50*0Sstevel@tonic-gate#
51*0Sstevel@tonic-gate# The input file should contain a standard Sun comment and ident string
52*0Sstevel@tonic-gate# which is copied verbatim and lines of
53*0Sstevel@tonic-gate#
54*0Sstevel@tonic-gate#	[keyword] privilege	PRIV_<privilege>
55*0Sstevel@tonic-gate#	set			PRIV_<set>
56*0Sstevel@tonic-gate#
57*0Sstevel@tonic-gate# Which are converted to privileges and privilege sets
58*0Sstevel@tonic-gate#
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gateBEGIN	{
62*0Sstevel@tonic-gate	# Number of privileges read
63*0Sstevel@tonic-gate	npriv = 0
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate	# Number of privilege sets
66*0Sstevel@tonic-gate	nset = 0
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate	# Length of all strings concatenated, including \0
69*0Sstevel@tonic-gate	privbytes = 0
70*0Sstevel@tonic-gate	setbytes = 0
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate	# Number of reserved privilege slots
73*0Sstevel@tonic-gate	slack = 10
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate	privhcmt = \
76*0Sstevel@tonic-gate	" * Privilege constant definitions; these constants are subject to\n" \
77*0Sstevel@tonic-gate	" * change, including renumbering, without notice and should not be\n" \
78*0Sstevel@tonic-gate	" * used in any code.  Privilege names must be used instead.\n" \
79*0Sstevel@tonic-gate	" * Privileges and privilege sets must not be stored in binary\n" \
80*0Sstevel@tonic-gate	" * form; privileges and privileges sets must be converted to\n" \
81*0Sstevel@tonic-gate	" * textual representation before being committed to persistent store."
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate	ccmt = \
84*0Sstevel@tonic-gate	" * Privilege name table and size definitions."
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate	pubhcmt = \
87*0Sstevel@tonic-gate	" * Privilege constant definitions.  Privileges and privilege sets\n" \
88*0Sstevel@tonic-gate	" * are only known by name and should be mapped at runtime."
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate	pnamescmt = \
91*0Sstevel@tonic-gate	"#\n" \
92*0Sstevel@tonic-gate	"# Privilege name explanation file\n" \
93*0Sstevel@tonic-gate	"# The format of entries is a privilege name starting at the\n" \
94*0Sstevel@tonic-gate	"# beginning of a line directly folowed by a new line followed\n" \
95*0Sstevel@tonic-gate	"# by several lines of texts starting with white space terminated\n" \
96*0Sstevel@tonic-gate	"# by a line with a single newline or not starting with white space\n" \
97*0Sstevel@tonic-gate	"#\n"
98*0Sstevel@tonic-gate}
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate#
101*0Sstevel@tonic-gate# Privilege strings are represented as lower case strings;
102*0Sstevel@tonic-gate# PRIV_ is stripped from the strings.
103*0Sstevel@tonic-gate#
104*0Sstevel@tonic-gate/^([A-Za-z]* )?privilege / {
105*0Sstevel@tonic-gate	if (NF == 3) {
106*0Sstevel@tonic-gate		key = toupper($1)
107*0Sstevel@tonic-gate		priv = toupper($3)
108*0Sstevel@tonic-gate		if (set[key] != "")
109*0Sstevel@tonic-gate			set[key] = set[key] ";"
110*0Sstevel@tonic-gate		set[key] = set[key] "\\\n\t\tPRIV_ASSERT((set), " priv ")"
111*0Sstevel@tonic-gate	} else {
112*0Sstevel@tonic-gate		priv = toupper($2);
113*0Sstevel@tonic-gate	}
114*0Sstevel@tonic-gate	privs[npriv] = tolower(substr(priv, 6));
115*0Sstevel@tonic-gate	inset = 0
116*0Sstevel@tonic-gate	inpriv = 1
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gate	privind[npriv] = privbytes;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate	tabs = (32 - length(priv) - 1)/8
121*0Sstevel@tonic-gate	# length + \0 - PRIV_
122*0Sstevel@tonic-gate	privbytes += length(priv) - 4
123*0Sstevel@tonic-gate	pdef[npriv] = "#define\t" priv substr("\t\t\t\t\t", 1, tabs)
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate	npriv++
126*0Sstevel@tonic-gate	next
127*0Sstevel@tonic-gate}
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate#
130*0Sstevel@tonic-gate# Set strings are represented as strings with an initial cap;
131*0Sstevel@tonic-gate# PRIV_ is stripped from the strings.
132*0Sstevel@tonic-gate#
133*0Sstevel@tonic-gate/^set / {
134*0Sstevel@tonic-gate	$2 = toupper($2)
135*0Sstevel@tonic-gate	sets[nset] = toupper(substr($2, 6, 1)) tolower(substr($2, 7));
136*0Sstevel@tonic-gate	inset = 1
137*0Sstevel@tonic-gate	inpriv = 0
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate	setind[nset] = setbytes
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate	# length + \0 - PRIV_
142*0Sstevel@tonic-gate	setbytes += length($2) - 4
143*0Sstevel@tonic-gate	tabs = (32 - length($2) - 1)/8
144*0Sstevel@tonic-gate	sdef[nset] = "#define\t" $2 substr("\t\t\t\t\t", 1, tabs)
145*0Sstevel@tonic-gate
146*0Sstevel@tonic-gate	nset++
147*0Sstevel@tonic-gate	next
148*0Sstevel@tonic-gate}
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate/INSERT COMMENT/ {
151*0Sstevel@tonic-gate	acmt = " *\n * THIS FILE WAS GENERATED; DO NOT EDIT"
152*0Sstevel@tonic-gate	if (cfile) {
153*0Sstevel@tonic-gate		print ccmt > cfile
154*0Sstevel@tonic-gate		print acmt > cfile
155*0Sstevel@tonic-gate	}
156*0Sstevel@tonic-gate	if (privhfile) {
157*0Sstevel@tonic-gate		print privhcmt > privhfile
158*0Sstevel@tonic-gate		print acmt > privhfile
159*0Sstevel@tonic-gate	}
160*0Sstevel@tonic-gate	if (pubhfile) {
161*0Sstevel@tonic-gate		print pubhcmt > pubhfile
162*0Sstevel@tonic-gate		print acmt > pubhfile
163*0Sstevel@tonic-gate	}
164*0Sstevel@tonic-gate	next
165*0Sstevel@tonic-gate}
166*0Sstevel@tonic-gate/^#pragma/ {
167*0Sstevel@tonic-gate	pragma = $0;
168*0Sstevel@tonic-gate	if (pnamesfile) {
169*0Sstevel@tonic-gate		print "#" substr($0, 9) > pnamesfile
170*0Sstevel@tonic-gate	}
171*0Sstevel@tonic-gate	next;
172*0Sstevel@tonic-gate}
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate/^#/ && ! /^#pragma/{
175*0Sstevel@tonic-gate	# Comments, ignore
176*0Sstevel@tonic-gate	next
177*0Sstevel@tonic-gate}
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate{
180*0Sstevel@tonic-gate	#
181*0Sstevel@tonic-gate	# Comments describing privileges and sets follow the definitions.
182*0Sstevel@tonic-gate	#
183*0Sstevel@tonic-gate	if (inset || inpriv) {
184*0Sstevel@tonic-gate		sub("^[ 	]*", "")
185*0Sstevel@tonic-gate		sub("[ 	]*$", "")
186*0Sstevel@tonic-gate		if (/^$/) next;
187*0Sstevel@tonic-gate	}
188*0Sstevel@tonic-gate	if (inset) {
189*0Sstevel@tonic-gate		setcmt[nset - 1] = setcmt[nset - 1] " * " $0 "\n"
190*0Sstevel@tonic-gate		next
191*0Sstevel@tonic-gate	} else if (inpriv) {
192*0Sstevel@tonic-gate		sub("^[ 	]*", "")
193*0Sstevel@tonic-gate		privcmt[npriv - 1] = privcmt[npriv - 1] " * " $0 "\n"
194*0Sstevel@tonic-gate		privncmt[npriv - 1] = privncmt[npriv - 1] "\t" $0 "\n"
195*0Sstevel@tonic-gate		next
196*0Sstevel@tonic-gate	}
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate	if (cfile)
199*0Sstevel@tonic-gate		print > cfile
200*0Sstevel@tonic-gate	if (privhfile)
201*0Sstevel@tonic-gate		print > privhfile
202*0Sstevel@tonic-gate	if (pubhfile)
203*0Sstevel@tonic-gate		print > pubhfile
204*0Sstevel@tonic-gate	if (pnamesfile) {
205*0Sstevel@tonic-gate		sub("^/\\*", "#")
206*0Sstevel@tonic-gate		sub("^ \\*/", "")
207*0Sstevel@tonic-gate		sub("^ \\*", "#")
208*0Sstevel@tonic-gate		if (/^$/) next;
209*0Sstevel@tonic-gate		print > pnamesfile
210*0Sstevel@tonic-gate	}
211*0Sstevel@tonic-gate}
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gateEND	{
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate	if (!pubhfile && !privhfile && !cfile && !pnamesfile) {
216*0Sstevel@tonic-gate		print "Output file parameter not set" > "/dev/stderr"
217*0Sstevel@tonic-gate		exit 1
218*0Sstevel@tonic-gate	}
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate	setsize = int((npriv + slack)/(8 * 4)) + 1
221*0Sstevel@tonic-gate	maxnpriv = setsize * 8 * 4
222*0Sstevel@tonic-gate	# Assume allocated privileges are on average "NSDQ" bytes larger.
223*0Sstevel@tonic-gate	maxprivbytes = int((privbytes / npriv + 5.5)) * (maxnpriv - npriv)
224*0Sstevel@tonic-gate	maxprivbytes += privbytes
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate	if (cfile) {
227*0Sstevel@tonic-gate		print "\n" > cfile
228*0Sstevel@tonic-gate		print pragma "\n"> cfile
229*0Sstevel@tonic-gate		print "#include <sys/types.h>" > cfile
230*0Sstevel@tonic-gate		print "#include <sys/priv_const.h>" > cfile
231*0Sstevel@tonic-gate		print "#include <sys/priv_impl.h>" > cfile
232*0Sstevel@tonic-gate		print "#include <sys/priv.h>" > cfile
233*0Sstevel@tonic-gate		print "#include <sys/sysmacros.h>" > cfile
234*0Sstevel@tonic-gate		print "\n" > cfile
235*0Sstevel@tonic-gate		#
236*0Sstevel@tonic-gate		# Create the entire priv info structure here.
237*0Sstevel@tonic-gate		# When adding privileges, the kernel needs to update
238*0Sstevel@tonic-gate		# too many fields as the number of privileges is kept in
239*0Sstevel@tonic-gate		# many places.
240*0Sstevel@tonic-gate		#
241*0Sstevel@tonic-gate		print \
242*0Sstevel@tonic-gate		    "static struct _info {\n" \
243*0Sstevel@tonic-gate		    "	priv_impl_info_t	impl_info;\n" \
244*0Sstevel@tonic-gate		    "	priv_info_t		settype;\n" \
245*0Sstevel@tonic-gate		    "	int			nsets;\n" \
246*0Sstevel@tonic-gate		    "	const char		sets[" setbytes "];\n" \
247*0Sstevel@tonic-gate		    "	priv_info_t		privtype;\n" \
248*0Sstevel@tonic-gate		    "	int			nprivs;\n" \
249*0Sstevel@tonic-gate		    "	char			privs[" maxprivbytes "];\n" \
250*0Sstevel@tonic-gate		    "	priv_info_t		sysset;\n" \
251*0Sstevel@tonic-gate		    "	priv_set_t		basicset;\n" \
252*0Sstevel@tonic-gate		    "} info = {\n" \
253*0Sstevel@tonic-gate		    "	{ sizeof (priv_impl_info_t), 0, PRIV_NSET, " \
254*0Sstevel@tonic-gate			"PRIV_SETSIZE, " npriv ",\n" \
255*0Sstevel@tonic-gate			"\t\tsizeof (priv_info_uint_t),\n" \
256*0Sstevel@tonic-gate			"\t\tsizeof (info) - sizeof (info.impl_info)},\n" \
257*0Sstevel@tonic-gate		    "	{ PRIV_INFO_SETNAMES,\n" \
258*0Sstevel@tonic-gate		    "	    offsetof(struct _info, privtype) - " \
259*0Sstevel@tonic-gate		    "offsetof(struct _info, settype)},\n\tPRIV_NSET," > cfile
260*0Sstevel@tonic-gate
261*0Sstevel@tonic-gate		sep = "\t\""
262*0Sstevel@tonic-gate		len = 9;
263*0Sstevel@tonic-gate		for (i = 0; i < nset; i++) {
264*0Sstevel@tonic-gate			if (len + length(sets[i]) > 80) {
265*0Sstevel@tonic-gate				sep = "\\0\"\n\t\""
266*0Sstevel@tonic-gate				len = 9
267*0Sstevel@tonic-gate			}
268*0Sstevel@tonic-gate			printf sep sets[i]  > cfile
269*0Sstevel@tonic-gate			len += length(sets[i]) + length(sep);
270*0Sstevel@tonic-gate			sep = "\\0"
271*0Sstevel@tonic-gate		}
272*0Sstevel@tonic-gate		print "\\0\"," > cfile
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate		print "\t{ PRIV_INFO_PRIVNAMES,\n\t    " \
275*0Sstevel@tonic-gate			"offsetof(struct _info, sysset) - " \
276*0Sstevel@tonic-gate			"offsetof(struct _info, privtype)},\n\t" npriv "," \
277*0Sstevel@tonic-gate			> cfile
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate		sep = "\t\""
280*0Sstevel@tonic-gate		len = 9;
281*0Sstevel@tonic-gate		for (i = 0; i < npriv; i++) {
282*0Sstevel@tonic-gate			if (len + length(privs[i]) > 80) {
283*0Sstevel@tonic-gate				sep = "\\0\"\n\t\""
284*0Sstevel@tonic-gate				len = 9
285*0Sstevel@tonic-gate			}
286*0Sstevel@tonic-gate			printf sep privs[i]  > cfile
287*0Sstevel@tonic-gate			len += length(privs[i]) + length(sep);
288*0Sstevel@tonic-gate			sep = "\\0"
289*0Sstevel@tonic-gate		}
290*0Sstevel@tonic-gate		print "\\0\"," > cfile
291*0Sstevel@tonic-gate
292*0Sstevel@tonic-gate		print "\t{ PRIV_INFO_BASICPRIVS, sizeof (info) - " \
293*0Sstevel@tonic-gate			"offsetof(struct _info, sysset)},"  > cfile
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate		print "};\n" > cfile
296*0Sstevel@tonic-gate
297*0Sstevel@tonic-gate		print "\nconst char *priv_names[" maxnpriv "] =\n{" > cfile
298*0Sstevel@tonic-gate		for (i = 0; i < npriv; i++)
299*0Sstevel@tonic-gate			print "\t&info.privs[" privind[i] "]," > cfile
300*0Sstevel@tonic-gate
301*0Sstevel@tonic-gate		print "};\n" > cfile
302*0Sstevel@tonic-gate
303*0Sstevel@tonic-gate		print "\nconst char *priv_setnames[" nset "] =\n{" > cfile
304*0Sstevel@tonic-gate		for (i = 0; i < nset; i++)
305*0Sstevel@tonic-gate			print "\t&info.sets[" setind[i] "]," > cfile
306*0Sstevel@tonic-gate
307*0Sstevel@tonic-gate		print "};\n" > cfile
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate		print "int nprivs = " npriv ";" > cfile
310*0Sstevel@tonic-gate		print "int privbytes = " privbytes ";" > cfile
311*0Sstevel@tonic-gate		print "int maxprivbytes = " maxprivbytes ";" > cfile
312*0Sstevel@tonic-gate		print "size_t privinfosize = sizeof (info);" > cfile
313*0Sstevel@tonic-gate		print "char *priv_str = info.privs;" > cfile
314*0Sstevel@tonic-gate		print "priv_set_t *priv_basic = &info.basicset;" > cfile
315*0Sstevel@tonic-gate		print "priv_impl_info_t *priv_info = &info.impl_info;" > cfile
316*0Sstevel@tonic-gate		print "priv_info_names_t *priv_ninfo = " \
317*0Sstevel@tonic-gate			"(priv_info_names_t *)&info.privtype;" > cfile
318*0Sstevel@tonic-gate		close(cfile)
319*0Sstevel@tonic-gate	}
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gate	# Kernel private
322*0Sstevel@tonic-gate	if (privhfile) {
323*0Sstevel@tonic-gate		print "#ifndef _SYS_PRIV_CONST_H" > privhfile
324*0Sstevel@tonic-gate		print "#define\t_SYS_PRIV_CONST_H\n" > privhfile
325*0Sstevel@tonic-gate		print pragma "\n"> privhfile
326*0Sstevel@tonic-gate		print "\n#include <sys/types.h>\n\n" > privhfile
327*0Sstevel@tonic-gate		print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > privhfile
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate		print "#if defined(_KERNEL) || defined(_KMEMUSER)" > privhfile
330*0Sstevel@tonic-gate		print "#define\tPRIV_NSET\t\t\t  " nset > privhfile
331*0Sstevel@tonic-gate		print "#define\tPRIV_SETSIZE\t\t\t  " setsize > privhfile
332*0Sstevel@tonic-gate		print "#endif\n\n#ifdef _KERNEL" > privhfile
333*0Sstevel@tonic-gate		print "#define\t__PRIV_CONST_IMPL\n" > privhfile
334*0Sstevel@tonic-gate		print "extern const char *priv_names[];" > privhfile
335*0Sstevel@tonic-gate		print "extern const char *priv_setnames[];" > privhfile
336*0Sstevel@tonic-gate
337*0Sstevel@tonic-gate		print "extern int nprivs;" > privhfile
338*0Sstevel@tonic-gate		print "extern int privbytes;" > privhfile
339*0Sstevel@tonic-gate		print "extern int maxprivbytes;" > privhfile
340*0Sstevel@tonic-gate		print "extern size_t privinfosize;" > privhfile
341*0Sstevel@tonic-gate		print "extern char *priv_str;" > privhfile
342*0Sstevel@tonic-gate		print "extern struct priv_set *priv_basic;" > privhfile
343*0Sstevel@tonic-gate		print "extern struct priv_impl_info *priv_info;" > privhfile
344*0Sstevel@tonic-gate		print "extern struct priv_info_names *priv_ninfo;" > privhfile
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gate		print "\n/* Privileges */" > privhfile
347*0Sstevel@tonic-gate
348*0Sstevel@tonic-gate		for (i = 0; i < npriv; i++)
349*0Sstevel@tonic-gate			print pdef[i] sprintf("%3d", i) > privhfile
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate		print "\n/* Privilege sets */" > privhfile
352*0Sstevel@tonic-gate		for (i = 0; i < nset; i++)
353*0Sstevel@tonic-gate			print sdef[i] sprintf("%3d", i) > privhfile
354*0Sstevel@tonic-gate
355*0Sstevel@tonic-gate		print "\n#define\tMAX_PRIVILEGE\t\t\t "  setsize * 32 \
356*0Sstevel@tonic-gate			> privhfile
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate		# Special privilege categories.
359*0Sstevel@tonic-gate		for (s in set)
360*0Sstevel@tonic-gate			print "\n#define\tPRIV_" s "_ASSERT(set)" set[s] \
361*0Sstevel@tonic-gate				> privhfile
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate		print "\n#endif /* _KERNEL */" > privhfile
364*0Sstevel@tonic-gate		print "\n#ifdef __cplusplus\n}\n#endif" > privhfile
365*0Sstevel@tonic-gate		print "\n#endif /* _SYS_PRIV_CONST_H */" > privhfile
366*0Sstevel@tonic-gate		close(privhfile)
367*0Sstevel@tonic-gate	}
368*0Sstevel@tonic-gate
369*0Sstevel@tonic-gate	if (pubhfile) {
370*0Sstevel@tonic-gate		cast="((const char *)"
371*0Sstevel@tonic-gate		print "#ifndef _SYS_PRIV_NAMES_H" > pubhfile
372*0Sstevel@tonic-gate		print "#define\t_SYS_PRIV_NAMES_H\n" > pubhfile
373*0Sstevel@tonic-gate
374*0Sstevel@tonic-gate		print pragma "\n" > pubhfile
375*0Sstevel@tonic-gate		print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > pubhfile
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gate		print "#ifndef __PRIV_CONST_IMPL" > pubhfile
378*0Sstevel@tonic-gate		print "/*\n * Privilege names\n */" > pubhfile
379*0Sstevel@tonic-gate		for (i = 0; i < npriv; i++) {
380*0Sstevel@tonic-gate			print "/*\n" privcmt[i] " */" > pubhfile
381*0Sstevel@tonic-gate			print pdef[i] cast "\"" privs[i] "\")\n" > pubhfile
382*0Sstevel@tonic-gate		}
383*0Sstevel@tonic-gate
384*0Sstevel@tonic-gate		print "" > pubhfile
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gate		print "/*\n * Privilege set names\n */" > pubhfile
387*0Sstevel@tonic-gate		for (i = 0; i < nset; i++) {
388*0Sstevel@tonic-gate			print "/*\n" setcmt[i] " */" > pubhfile
389*0Sstevel@tonic-gate			print sdef[i] cast "\"" sets[i] "\")\n" > pubhfile
390*0Sstevel@tonic-gate		}
391*0Sstevel@tonic-gate
392*0Sstevel@tonic-gate		print "\n#endif /* __PRIV_CONST_IMPL */" > pubhfile
393*0Sstevel@tonic-gate		print "\n#ifdef __cplusplus\n}\n#endif" > pubhfile
394*0Sstevel@tonic-gate		print "\n#endif /* _SYS_PRIV_NAMES_H */" > pubhfile
395*0Sstevel@tonic-gate		close(pubhfile)
396*0Sstevel@tonic-gate	}
397*0Sstevel@tonic-gate
398*0Sstevel@tonic-gate	if (pnamesfile) {
399*0Sstevel@tonic-gate		print pnamescmt > pnamesfile
400*0Sstevel@tonic-gate		for (i = 0; i < npriv; i++) {
401*0Sstevel@tonic-gate			print privs[i] > pnamesfile
402*0Sstevel@tonic-gate			print privncmt[i] > pnamesfile
403*0Sstevel@tonic-gate		}
404*0Sstevel@tonic-gate	}
405*0Sstevel@tonic-gate
406*0Sstevel@tonic-gate}
407