Print this page
uts: add a concept of a 'default' set of privileges, separate from 'basic'
uts: give privilege macros more sensible names


  90         pnamescmt = \
  91         "#\n" \
  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" \
  97         "#\n"
  98 }
  99 
 100 #
 101 # Privilege strings are represented as lower case strings;
 102 # PRIV_ is stripped from the strings.
 103 #
 104 /^([A-Za-z]* )?privilege / {
 105         if (NF == 3) {
 106                 key = toupper($1)
 107                 priv = toupper($3)
 108                 if (set[key] != "")
 109                         set[key] = set[key] ";"
 110                 set[key] = set[key] "\\\n\t\tPRIV_ASSERT((set), " priv ")"
 111         } else {
 112                 priv = toupper($2);
 113         }
 114         privs[npriv] = tolower(substr(priv, 6));
 115         inset = 0
 116         inpriv = 1
 117 
 118         privind[npriv] = privbytes;
 119 
 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)
 124 
 125         npriv++
 126         next
 127 }
 128 
 129 #
 130 # Set strings are represented as strings with an initial cap;


 232                 print "#include <sys/priv.h>" > cfile
 233                 print "#include <sys/sysmacros.h>" > cfile
 234                 print "\n" > cfile
 235                 #
 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
 239                 # many places.
 240                 #
 241                 print \
 242                     "static struct _info {\n" \
 243                     "   priv_impl_info_t        impl_info;\n" \
 244                     "   priv_info_t             settype;\n" \
 245                     "   int                     nsets;\n" \
 246                     "   const char              sets[" setbytes "];\n" \
 247                     "   priv_info_t             privtype;\n" \
 248                     "   int                     nprivs;\n" \
 249                     "   char                    privs[" maxprivbytes "];\n" \
 250                     "   priv_info_t             sysset;\n" \
 251                     "   priv_set_t              basicset;\n" \


 252                     "} info = {\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
 260 
 261                 sep = "\t\""
 262                 len = 9;
 263                 for (i = 0; i < nset; i++) {
 264                         if (len + length(sets[i]) > 80) {
 265                                 sep = "\\0\"\n\t\""
 266                                 len = 9
 267                         }
 268                         printf sep sets[i]  > cfile
 269                         len += length(sets[i]) + length(sep);
 270                         sep = "\\0"
 271                 }
 272                 print "\\0\"," > cfile
 273 
 274                 print "\t{ PRIV_INFO_PRIVNAMES,\n\t    " \
 275                         "offsetof(struct _info, sysset) - " \
 276                         "offsetof(struct _info, privtype)},\n\t" npriv "," \
 277                         > cfile
 278 
 279                 sep = "\t\""
 280                 len = 9;
 281                 for (i = 0; i < npriv; i++) {
 282                         if (len + length(privs[i]) > 80) {
 283                                 sep = "\\0\"\n\t\""
 284                                 len = 9
 285                         }
 286                         printf sep privs[i]  > cfile
 287                         len += length(privs[i]) + length(sep);
 288                         sep = "\\0"
 289                 }
 290                 print "\\0\"," > cfile
 291 
 292                 print "\t{ PRIV_INFO_BASICPRIVS, sizeof (info) - " \
 293                         "offsetof(struct _info, sysset)},"  > cfile



 294 
 295                 print "};\n" > cfile
 296 
 297                 print "\nconst char *priv_names[" maxnpriv "] =\n{" > cfile
 298                 for (i = 0; i < npriv; i++)
 299                         print "\t&info.privs[" privind[i] "]," > cfile
 300 
 301                 print "};\n" > cfile
 302 
 303                 print "\nconst char *priv_setnames[" nset "] =\n{" > cfile
 304                 for (i = 0; i < nset; i++)
 305                         print "\t&info.sets[" setind[i] "]," > cfile
 306 
 307                 print "};\n" > cfile
 308 
 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
 318                 close(cfile)
 319         }
 320 
 321         # Kernel private
 322         if (privhfile) {
 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
 328 
 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
 336 
 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
 345 
 346                 print "\n/* Privileges */" > privhfile
 347                  
 348                 for (i = 0; i < npriv; i++)
 349                         print pdef[i] sprintf("%3d", i) > privhfile
 350 
 351                 print "\n/* Privilege sets */" > privhfile
 352                 for (i = 0; i < nset; i++)
 353                         print sdef[i] sprintf("%3d", i) > privhfile
 354 
 355                 print "\n#define\tMAX_PRIVILEGE\t\t\t "  setsize * 32 \
 356                         > privhfile
 357 
 358                 # Special privilege categories.
 359                 for (s in set)
 360                         print "\n#define\tPRIV_" s "_ASSERT(set)" set[s] \
 361                                 > privhfile
 362 
 363                 print "\n#endif /* _KERNEL */" > privhfile
 364                 print "\n#ifdef __cplusplus\n}\n#endif" > privhfile
 365                 print "\n#endif /* _SYS_PRIV_CONST_H */" > privhfile
 366                 close(privhfile)
 367         }
 368 
 369         if (pubhfile) {
 370                 cast="((const char *)"
 371                 print "#ifndef _SYS_PRIV_NAMES_H" > pubhfile
 372                 print "#define\t_SYS_PRIV_NAMES_H\n" > pubhfile
 373 
 374                 print pragma "\n" > pubhfile
 375                 print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > pubhfile
 376 
 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




  90         pnamescmt = \
  91         "#\n" \
  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" \
  97         "#\n"
  98 }
  99 
 100 #
 101 # Privilege strings are represented as lower case strings;
 102 # PRIV_ is stripped from the strings.
 103 #
 104 /^([A-Za-z]* )?privilege / {
 105         if (NF == 3) {
 106                 key = toupper($1)
 107                 priv = toupper($3)
 108                 if (set[key] != "")
 109                         set[key] = set[key] ";"
 110                 set[key] = set[key] "\\\n\t\tPRIV_ADDSET((set), " priv ")"
 111         } else {
 112                 priv = toupper($2);
 113         }
 114         privs[npriv] = tolower(substr(priv, 6));
 115         inset = 0
 116         inpriv = 1
 117 
 118         privind[npriv] = privbytes;
 119 
 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)
 124 
 125         npriv++
 126         next
 127 }
 128 
 129 #
 130 # Set strings are represented as strings with an initial cap;


 232                 print "#include <sys/priv.h>" > cfile
 233                 print "#include <sys/sysmacros.h>" > cfile
 234                 print "\n" > cfile
 235                 #
 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
 239                 # many places.
 240                 #
 241                 print \
 242                     "static struct _info {\n" \
 243                     "   priv_impl_info_t        impl_info;\n" \
 244                     "   priv_info_t             settype;\n" \
 245                     "   int                     nsets;\n" \
 246                     "   const char              sets[" setbytes "];\n" \
 247                     "   priv_info_t             privtype;\n" \
 248                     "   int                     nprivs;\n" \
 249                     "   char                    privs[" maxprivbytes "];\n" \
 250                     "   priv_info_t             sysset;\n" \
 251                     "   priv_set_t              basicset;\n" \
 252                     "   priv_info_t             defset;\n" \
 253                     "   priv_set_t              defaultset;\n" \
 254                     "} info = {\n" \
 255                     "   { sizeof (priv_impl_info_t), 0, PRIV_NSET, " \
 256                         "PRIV_SETSIZE, " npriv ",\n" \
 257                         "\t\tsizeof (priv_info_uint_t),\n" \
 258                         "\t\tsizeof (info) - sizeof (info.impl_info)},\n" \
 259                     "   { PRIV_INFO_SETNAMES,\n" \
 260                     "       offsetof(struct _info, privtype) - " \
 261                     "offsetof(struct _info, settype)},\n\tPRIV_NSET," > cfile
 262 
 263                 sep = "\t\""
 264                 len = 9;
 265                 for (i = 0; i < nset; i++) {
 266                         if (len + length(sets[i]) > 80) {
 267                                 sep = "\\0\"\n\t\""
 268                                 len = 9
 269                         }
 270                         printf sep sets[i]  > cfile
 271                         len += length(sets[i]) + length(sep);
 272                         sep = "\\0"
 273                 }
 274                 print "\\0\"," > cfile
 275 
 276                 print "\t{ PRIV_INFO_PRIVNAMES,\n\t    " \
 277                         "offsetof(struct _info, sysset) - " \
 278                         "offsetof(struct _info, privtype)},\n\t" npriv "," \
 279                         > cfile
 280 
 281                 sep = "\t\""
 282                 len = 9;
 283                 for (i = 0; i < npriv; i++) {
 284                         if (len + length(privs[i]) > 80) {
 285                                 sep = "\\0\"\n\t\""
 286                                 len = 9
 287                         }
 288                         printf sep privs[i]  > cfile
 289                         len += length(privs[i]) + length(sep);
 290                         sep = "\\0"
 291                 }
 292                 print "\\0\"," > cfile
 293 
 294                 print "\t{ PRIV_INFO_BASICPRIVS, offsetof (struct _info, defset) - " \
 295                     "offsetof(struct _info, sysset)},"  > cfile
 296                 print "\t{ 0 },\n" > cfile
 297                 print "\t{ PRIV_INFO_DEFAULTPRIVS, sizeof (info) - " \
 298                     "offsetof(struct _info, defset)}" > cfile
 299 
 300                 print "};\n" > cfile
 301 
 302                 print "\nconst char *priv_names[" maxnpriv "] =\n{" > cfile
 303                 for (i = 0; i < npriv; i++)
 304                         print "\t&info.privs[" privind[i] "]," > cfile
 305 
 306                 print "};\n" > cfile
 307 
 308                 print "\nconst char *priv_setnames[" nset "] =\n{" > cfile
 309                 for (i = 0; i < nset; i++)
 310                         print "\t&info.sets[" setind[i] "]," > cfile
 311 
 312                 print "};\n" > cfile
 313 
 314                 print "int nprivs = " npriv ";" > cfile
 315                 print "int privbytes = " privbytes ";" > cfile
 316                 print "int maxprivbytes = " maxprivbytes ";" > cfile
 317                 print "size_t privinfosize = sizeof (info);" > cfile
 318                 print "char *priv_str = info.privs;" > cfile
 319                 print "priv_set_t *priv_basic = &info.basicset;" > cfile
 320                 print "priv_set_t *priv_default = &info.defaultset;" > cfile
 321                 print "priv_impl_info_t *priv_info = &info.impl_info;" > cfile
 322                 print "priv_info_names_t *priv_ninfo = " \
 323                         "(priv_info_names_t *)&info.privtype;" > cfile
 324                 close(cfile)
 325         }
 326 
 327         # Kernel private
 328         if (privhfile) {
 329                 print "#ifndef _SYS_PRIV_CONST_H" > privhfile
 330                 print "#define\t_SYS_PRIV_CONST_H\n" > privhfile
 331                 print pragma "\n"> privhfile
 332                 print "\n#include <sys/types.h>\n\n" > privhfile
 333                 print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > privhfile
 334 
 335                 print "#if defined(_KERNEL) || defined(_KMEMUSER)" > privhfile
 336                 print "#define\tPRIV_NSET\t\t\t  " nset > privhfile
 337                 print "#define\tPRIV_SETSIZE\t\t\t  " setsize > privhfile
 338                 print "#endif\n\n#ifdef _KERNEL" > privhfile
 339                 print "#define\t__PRIV_CONST_IMPL\n" > privhfile
 340                 print "extern const char *priv_names[];" > privhfile
 341                 print "extern const char *priv_setnames[];" > privhfile
 342 
 343                 print "extern int nprivs;" > privhfile
 344                 print "extern int privbytes;" > privhfile
 345                 print "extern int maxprivbytes;" > privhfile
 346                 print "extern size_t privinfosize;" > privhfile
 347                 print "extern char *priv_str;" > privhfile
 348                 print "extern struct priv_set *priv_basic;" > privhfile
 349                 print "extern struct priv_set *priv_default;" > privhfile
 350                 print "extern struct priv_impl_info *priv_info;" > privhfile
 351                 print "extern struct priv_info_names *priv_ninfo;" > privhfile
 352 
 353                 print "\n/* Privileges */" > privhfile
 354                  
 355                 for (i = 0; i < npriv; i++)
 356                         print pdef[i] sprintf("%3d", i) > privhfile
 357 
 358                 print "\n/* Privilege sets */" > privhfile
 359                 for (i = 0; i < nset; i++)
 360                         print sdef[i] sprintf("%3d", i) > privhfile
 361 
 362                 print "\n#define\tMAX_PRIVILEGE\t\t\t "  setsize * 32 \
 363                         > privhfile
 364 
 365                 # Special privilege categories.
 366                 for (s in set)
 367                         print "\n#define\tPRIV_" s "_ADDSET(set)" set[s] \
 368                                 > privhfile
 369 
 370                 print "\n#endif /* _KERNEL */" > privhfile
 371                 print "\n#ifdef __cplusplus\n}\n#endif" > privhfile
 372                 print "\n#endif /* _SYS_PRIV_CONST_H */" > privhfile
 373                 close(privhfile)
 374         }
 375 
 376         if (pubhfile) {
 377                 cast="((const char *)"
 378                 print "#ifndef _SYS_PRIV_NAMES_H" > pubhfile
 379                 print "#define\t_SYS_PRIV_NAMES_H\n" > pubhfile
 380 
 381                 print pragma "\n" > pubhfile
 382                 print "#ifdef __cplusplus\nextern \"C\" {\n#endif\n" > pubhfile
 383 
 384                 print "#ifndef __PRIV_CONST_IMPL" > pubhfile
 385                 print "/*\n * Privilege names\n */" > pubhfile
 386                 for (i = 0; i < npriv; i++) {
 387                         print "/*\n" privcmt[i] " */" > pubhfile