#! /bin/awk -f # # NOTE: need an awk interpreter which is able to print...>"/dev/stderr" # ## Generate struct security_operations for Linux Security Modules # ## Usage: lsm-genstruct.awk -vp=PREFIX [-vs=SUFFIX] \ # KERNEL_INC_PATH/linux/security.h # PREFIX: replace with the base name of the model # SUFFIX: override default suffix .h # KERNEL_INC_PATH: path to the header files of the kernel the module # is being developed for, may be "include" if you are # inside the kernel source tree. # ## GPL 2004 Manfred Waßmann http://www.berlinos.de/ ## # # Copyright (C) 2004 Manfred Waßmann http://www.berlinos.de/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2, # as published by the Free Software Foundation. # # lsm-genstruct.awk,v 1.9 2007-02-25 11:08:16 manolo Exp # BEGIN{if(!s){s="h"};o=p"_secops."s; #check args if(p){ P=toupper(p);} else{ print"Usage "ARGV[0]" -p <.../linux/security.h>\n">"/dev/stderr"; exit 1}; if((system("! test -e "o" || ln "o" "o"~"))){#Backup output file if existing printf"Error backing up output file "o" -- aborting!\n"; rc=69;exit(rc); } print"/*\n * This is a generated file! DO NOT EDIT !\n */\n\n"\ "#ifndef "P"_SECOPS_H\n#define "P"_SECOPS_H\n\n"\ "struct security_operations "p"_security_ops = {">o}; /^struct security_operations {/,/^};/{ match($1,"^#");if(RLENGTH>0)print$0>o; match($2,"^\(\*[0-9a-zA-Z_]+\)$");if(RLENGTH>0){h=substr($2,3,RLENGTH-3); print"\t."h" = "p"_"h",">o;};}; END{if(!rc){print"};\n\n#endif">o;print"Output written to "o}}