2 # Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 # Use is subject to license terms.
7 # The contents of this file are subject to the terms of the
8 # Common Development and Distribution License, Version 1.0 only
9 # (the "License"). You may not use this file except in compliance
12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13 # or http://www.opensolaris.org/os/licensing.
14 # See the License for the specific language governing permissions
15 # and limitations under the License.
17 # When distributing Covered Code, include this CDDL HEADER in each
18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19 # If applicable, add the following below this CDDL HEADER, with the
20 # fields enclosed by brackets "[]" replaced with your own identifying
21 # information: Portions Copyright [yyyy] [name of copyright owner]
27 # This file generates three different C files:
30 # An implementation private set of manifest integer constant
31 # for privileges and privilege sets and manifest constants for
32 # set size, number of sets, number of privileges
35 # A C source file containing the set names, privilege names
36 # arrays for the name <-> number mappings
39 # A public header file containing the PRIV_* defines
40 # that map to strings; these are for convenience.
41 # (it's easy to misspell a string, harder to misspell a
44 # /etc/security/priv_names
45 # A privilege name to explanation mapping.
48 # The files are output on the awk variable privhfile, pubhfile, cfile,
49 # and pnamesfile respectively
51 # The input file should contain a standard Sun comment and ident string
52 # which is copied verbatim and lines of
54 # [keyword] privilege PRIV_<privilege>
57 # Which are converted to privileges and privilege sets
62 # Number of privileges read
65 # Number of privilege sets
68 # Length of all strings concatenated, including \0
72 # Number of reserved privilege slots
76 " * Privilege constant definitions; these constants are subject to\n" \
77 " * change, including renumbering, without notice and should not be\n" \
78 " * used in any code. Privilege names must be used instead.\n" \
79 " * Privileges and privilege sets must not be stored in binary\n" \
80 " * form; privileges and privileges sets must be converted to\n" \
81 " * textual representation before being committed to persistent store."
84 " * Privilege name table and size definitions."
87 " * Privilege constant definitions. Privileges and privilege sets\n" \
88 " * are only known by name and should be mapped at runtime."
92 "# Privilege name explanation file\n" \
93 "# The format of entries is a privilege name starting at the\n" \
94 "# beginning of a line directly folowed by a new line followed\n" \
95 "# by several lines of texts starting with white space terminated\n" \
96 "# by a line with a single newline or not starting with white space\n" \
101 # Privilege strings are represented as lower case strings;
102 # PRIV_ is stripped from the strings.
104 /^
([A
-Za
-z
]* )?privilege
/ {
109 set
[key
] = set
[key
] ";"
110 set
[key
] = set
[key
] "\\\n\t\tPRIV_ADDSET((set), " priv
")"
114 privs
[npriv
] =
tolower(substr(priv
, 6));
118 privind
[npriv
] = privbytes
;
120 tabs =
(32 - length(priv
) - 1)/8
121 # length + \0 - PRIV_
122 privbytes
+=
length(priv
) - 4
123 pdef
[npriv
] =
"#define\t" priv
substr("\t\t\t\t\t", 1, tabs
)
130 # Set strings are represented as strings with an initial cap;
131 # PRIV_ is stripped from the strings.
135 sets
[nset
] =
toupper(substr($
2, 6, 1)) tolower(substr($
2, 7));
139 setind
[nset
] = setbytes
141 # length + \0 - PRIV_
142 setbytes
+=
length($
2) - 4
143 tabs =
(32 - length($
2) - 1)/8
144 sdef
[nset
] =
"#define\t" $
2 substr("\t\t\t\t\t", 1, tabs
)
151 acmt =
" *\n * THIS FILE WAS GENERATED; DO NOT EDIT"
157 print privhcmt
> privhfile
158 print acmt
> privhfile
161 print pubhcmt
> pubhfile
162 print acmt
> pubhfile
169 print "#" substr($
0, 9) > pnamesfile
174 /^
#/ && ! /^#pragma/{
181 # Comments describing privileges and sets follow the definitions.
183 if (inset
|| inpriv
) {
189 setcmt
[nset
- 1] = setcmt
[nset
- 1] " * " $
0 "\n"
193 privcmt
[npriv
- 1] = privcmt
[npriv
- 1] " * " $
0 "\n"
194 privncmt
[npriv
- 1] = privncmt
[npriv
- 1] "\t" $
0 "\n"
215 if (!pubhfile
&& !privhfile
&& !cfile
&& !pnamesfile
) {
216 print "Output file parameter not set" > "/dev/stderr"
220 setsize = int
((npriv
+ slack
)/(8 * 4)) + 1
221 maxnpriv = setsize
* 8 * 4
222 # Assume allocated privileges are on average "NSDQ" bytes larger.
223 maxprivbytes = int
((privbytes
/ npriv
+ 5.5)) * (maxnpriv
- npriv
)
224 maxprivbytes
+= privbytes
228 print pragma
"\n"> cfile
229 print "#include <sys/types.h>" > cfile
230 print "#include <sys/priv_const.h>" > cfile
231 print "#include <sys/priv_impl.h>" > cfile
232 print "#include <sys/priv.h>" > cfile
233 print "#include <sys/sysmacros.h>" > cfile
236 # Create the entire priv info structure here.
237 # When adding privileges, the kernel needs to update
238 # too many fields as the number of privileges is kept in
242 "static struct _info {\n" \
243 " priv_impl_info_t impl_info;\n" \
244 " priv_info_t settype;\n" \
246 " const char sets[" setbytes
"];\n" \
247 " priv_info_t privtype;\n" \
249 " char privs[" maxprivbytes
"];\n" \
250 " priv_info_t sysset;\n" \
251 " priv_set_t basicset;\n" \
253 " { sizeof (priv_impl_info_t), 0, PRIV_NSET, " \
254 "PRIV_SETSIZE, " npriv
",\n" \
255 "\t\tsizeof (priv_info_uint_t),\n" \
256 "\t\tsizeof (info) - sizeof (info.impl_info)},\n" \
257 " { PRIV_INFO_SETNAMES,\n" \
258 " offsetof(struct _info, privtype) - " \
259 "offsetof(struct _info, settype)},\n\tPRIV_NSET," > cfile
263 for (i =
0; i
< nset
; i
++) {
264 if (len
+ length(sets
[i
]) > 80) {
268 printf sep sets
[i
] > cfile
269 len
+=
length(sets
[i
]) + length(sep
);
272 print "\\0\"," > cfile
274 print "\t{ PRIV_INFO_PRIVNAMES,\n\t " \
275 "offsetof(struct _info, sysset) - " \
276 "offsetof(struct _info, privtype)},\n\t" npriv
"," \
281 for (i =
0; i
< npriv
; i
++) {
282 if (len
+ length(privs
[i
]) > 80) {
286 printf sep privs
[i
] > cfile
287 len
+=
length(privs
[i
]) + length(sep
);
290 print "\\0\"," > cfile
292 print "\t{ PRIV_INFO_BASICPRIVS, sizeof (info) - " \
293 "offsetof(struct _info, sysset)}," > cfile
297 print "\nconst char *priv_names[" maxnpriv
"] =\n{" > cfile
298 for (i =
0; i
< npriv
; i
++)
299 print "\t&info.privs[" privind
[i
] "]," > cfile
303 print "\nconst char *priv_setnames[" nset
"] =\n{" > cfile
304 for (i =
0; i
< nset
; i
++)
305 print "\t&info.sets[" setind
[i
] "]," > cfile
309 print "int nprivs = " npriv
";" > cfile
310 print "int privbytes = " privbytes
";" > cfile
311 print "int maxprivbytes = " maxprivbytes
";" > cfile
312 print "size_t privinfosize = sizeof (info);" > cfile
313 print "char *priv_str = info.privs;" > cfile
314 print "priv_set_t *priv_basic = &info.basicset;" > cfile
315 print "priv_impl_info_t *priv_info = &info.impl_info;" > cfile
316 print "priv_info_names_t *priv_ninfo = " \
317 "(priv_info_names_t *)&info.privtype;" > cfile
323 print "#ifndef _SYS_PRIV_CONST_H" > privhfile
324 print "#define\t_SYS_PRIV_CONST_H\n" > privhfile
325 print pragma
"\n"> privhfile
326 print "\n#include <sys/types.h>\n\n" > privhfile
327 print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > privhfile
329 print "#if defined(_KERNEL) || defined(_KMEMUSER)" > privhfile
330 print "#define\tPRIV_NSET\t\t\t " nset
> privhfile
331 print "#define\tPRIV_SETSIZE\t\t\t " setsize
> privhfile
332 print "#endif\n\n#ifdef _KERNEL" > privhfile
333 print "#define\t__PRIV_CONST_IMPL\n" > privhfile
334 print "extern const char *priv_names[];" > privhfile
335 print "extern const char *priv_setnames[];" > privhfile
337 print "extern int nprivs;" > privhfile
338 print "extern int privbytes;" > privhfile
339 print "extern int maxprivbytes;" > privhfile
340 print "extern size_t privinfosize;" > privhfile
341 print "extern char *priv_str;" > privhfile
342 print "extern struct priv_set *priv_basic;" > privhfile
343 print "extern struct priv_impl_info *priv_info;" > privhfile
344 print "extern struct priv_info_names *priv_ninfo;" > privhfile
346 print "\n/* Privileges */" > privhfile
348 for (i =
0; i
< npriv
; i
++)
349 print pdef
[i
] sprintf("%3d", i
) > privhfile
351 print "\n/* Privilege sets */" > privhfile
352 for (i =
0; i
< nset
; i
++)
353 print sdef
[i
] sprintf("%3d", i
) > privhfile
355 print "\n#define\tMAX_PRIVILEGE\t\t\t " setsize
* 32 \
358 # Special privilege categories.
360 print "\n#define\tPRIV_" s
"_ADDSET(set)" set
[s
] \
363 print "\n#endif /* _KERNEL */" > privhfile
364 print "\n#ifdef __cplusplus\n}\n#endif" > privhfile
365 print "\n#endif /* _SYS_PRIV_CONST_H */" > privhfile
370 cast=
"((const char *)"
371 print "#ifndef _SYS_PRIV_NAMES_H" > pubhfile
372 print "#define\t_SYS_PRIV_NAMES_H\n" > pubhfile
374 print pragma
"\n" > pubhfile
375 print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > pubhfile
377 print "#ifndef __PRIV_CONST_IMPL" > pubhfile
378 print "/*\n * Privilege names\n */" > pubhfile
379 for (i =
0; i
< npriv
; i
++) {
380 print "/*\n" privcmt
[i
] " */" > pubhfile
381 print pdef
[i
] cast
"\"" privs
[i
] "\")\n" > pubhfile
386 print "/*\n * Privilege set names\n */" > pubhfile
387 for (i =
0; i
< nset
; i
++) {
388 print "/*\n" setcmt
[i
] " */" > pubhfile
389 print sdef
[i
] cast
"\"" sets
[i
] "\")\n" > pubhfile
392 print "\n#endif /* __PRIV_CONST_IMPL */" > pubhfile
393 print "\n#ifdef __cplusplus\n}\n#endif" > pubhfile
394 print "\n#endif /* _SYS_PRIV_NAMES_H */" > pubhfile
399 print pnamescmt
> pnamesfile
400 for (i =
0; i
< npriv
; i
++) {
401 print privs
[i
] > pnamesfile
402 print privncmt
[i
] > pnamesfile