#
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#ident "%Z%%M% %I% %E% SMI"
#
# This file generates three different C files:
#
# <sys/priv_const.h>
# An implementation private set of manifest integer constant
# for privileges and privilege sets and manifest constants for
# set size, number of sets, number of privileges
#
# A C source file containing the set names, privilege names
# arrays for the name <-> number mappings
#
# <sys/priv_names.h>
# A public header file containing the PRIV_* defines
# that map to strings; these are for convenience.
# (it's easy to misspell a string, harder to misspell a
# manifest constant)
#
# A privilege name to explanation mapping.
#
#
# The files are output on the awk variable privhfile, pubhfile, cfile,
# and pnamesfile respectively
#
# The input file should contain a standard Sun comment and ident string
# which is copied verbatim and lines of
#
# [keyword] privilege PRIV_<privilege>
# set PRIV_<set>
#
# Which are converted to privileges and privilege sets
#
BEGIN {
# Number of privileges read
npriv = 0
# Number of privilege sets
nset = 0
# Length of all strings concatenated, including \0
privbytes = 0
setbytes = 0
# Number of reserved privilege slots
slack = 10
privhcmt = \
" * Privilege constant definitions; these constants are subject to\n" \
" * change, including renumbering, without notice and should not be\n" \
" * used in any code. Privilege names must be used instead.\n" \
" * Privileges and privilege sets must not be stored in binary\n" \
" * form; privileges and privileges sets must be converted to\n" \
" * textual representation before being committed to persistent store."
ccmt = \
" * Privilege name table and size definitions."
pubhcmt = \
" * Privilege constant definitions. Privileges and privilege sets\n" \
" * are only known by name and should be mapped at runtime."
pnamescmt = \
"#\n" \
"# Privilege name explanation file\n" \
"# The format of entries is a privilege name starting at the\n" \
"# beginning of a line directly folowed by a new line followed\n" \
"# by several lines of texts starting with white space terminated\n" \
"# by a line with a single newline or not starting with white space\n" \
"#\n"
}
#
# Privilege strings are represented as lower case strings;
# PRIV_ is stripped from the strings.
#
} else {
}
inset = 0
inpriv = 1
# length + \0 - PRIV_
npriv++
next
}
#
# Set strings are represented as strings with an initial cap;
# PRIV_ is stripped from the strings.
#
/^set / {
$2 = toupper($2)
inset = 1
inpriv = 0
# length + \0 - PRIV_
nset++
next
}
acmt = " *\n * THIS FILE WAS GENERATED; DO NOT EDIT"
}
}
}
next
}
/^#pragma/ {
pragma = $0;
if (pnamesfile) {
}
next;
}
/^#/ && ! /^#pragma/{
# Comments, ignore
next
}
{
#
# Comments describing privileges and sets follow the definitions.
#
sub("^[ ]*", "")
sub("[ ]*$", "")
if (/^$/) next;
}
next
sub("^[ ]*", "")
next
}
if (cfile)
print > cfile
if (privhfile)
print > privhfile
if (pubhfile)
print > pubhfile
sub("^/\\*", "#")
sub("^ \\*/", "")
sub("^ \\*", "#")
if (/^$/) next;
print > pnamesfile
}
}
END {
exit 1
}
# Assume allocated privileges are on average "NSDQ" bytes larger.
#
# Create the entire priv info structure here.
# When adding privileges, the kernel needs to update
# too many fields as the number of privileges is kept in
# many places.
#
print \
"static struct _info {\n" \
" priv_impl_info_t impl_info;\n" \
" priv_info_t settype;\n" \
" int nsets;\n" \
" priv_info_t privtype;\n" \
" int nprivs;\n" \
" priv_info_t sysset;\n" \
" priv_set_t basicset;\n" \
"} info = {\n" \
" { sizeof (priv_impl_info_t), 0, PRIV_NSET, " \
"\t\tsizeof (priv_info_uint_t),\n" \
" { PRIV_INFO_SETNAMES,\n" \
" offsetof(struct _info, privtype) - " \
sep = "\t\""
len = 9;
sep = "\\0\"\n\t\""
len = 9
}
sep = "\\0"
}
print "\t{ PRIV_INFO_PRIVNAMES,\n\t " \
"offsetof(struct _info, sysset) - " \
> cfile
sep = "\t\""
len = 9;
sep = "\\0\"\n\t\""
len = 9
}
sep = "\\0"
}
print "\t{ PRIV_INFO_BASICPRIVS, sizeof (info) - " \
for (i = 0; i < npriv; i++)
for (i = 0; i < nset; i++)
print "priv_info_names_t *priv_ninfo = " \
}
# Kernel private
for (i = 0; i < npriv; i++)
for (i = 0; i < nset; i++)
# Special privilege categories.
for (s in set)
print "\n#define\tPRIV_" s "_ASSERT(set)" set[s] \
}
cast="((const char *)"
}
}
}
print pnamescmt > pnamesfile
print privs[i] > pnamesfile
print privncmt[i] > pnamesfile
}
}
}