diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-09-28 15:10:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-09-28 15:10:52 +0000 |
commit | b2ce21d7e22822255c394cc618c029fdcd31be4d (patch) | |
tree | ba0dcff50d70b05985ecb9590c0bf828c151a021 /usr.bin/sudo/mkdefaults | |
parent | 6d2330fc528f6b282a6ed3bff15e92d30ee98805 (diff) |
Update to sudo 1.6.8p1
Diffstat (limited to 'usr.bin/sudo/mkdefaults')
-rw-r--r-- | usr.bin/sudo/mkdefaults | 122 |
1 files changed, 97 insertions, 25 deletions
diff --git a/usr.bin/sudo/mkdefaults b/usr.bin/sudo/mkdefaults index 82ef6bdfd7f..856890050c9 100644 --- a/usr.bin/sudo/mkdefaults +++ b/usr.bin/sudo/mkdefaults @@ -7,6 +7,7 @@ # var_name # TYPE # description (or NULL) +# array of struct def_values if TYPE == T_TUPLE # Deal with optional -o (output) argument if ($#ARGV > 0 && $ARGV[0] eq "-o") { @@ -15,7 +16,7 @@ if ($#ARGV > 0 && $ARGV[0] eq "-o") { $header .= '.h'; $cfile .= '.c'; } -die "usage: $0 input_file" unless $#ARGV == 0; +die "usage: $0 input_file\n" unless $#ARGV == 0; $infile = $ARGV[0]; if (!defined($header)) { @@ -31,51 +32,122 @@ open(IN, "<$infile") || die "$0: can't open $infile: $!\n"; open(HEADER, ">$header") || die "$0: can't open $header: $!\n"; open(CFILE, ">$cfile") || die "$0: can't open $cfile: $!\n"; -print CFILE "struct sudo_defs_types sudo_defs_table[] = {\n {\n"; - -$count = -1; +$count = 0; +@tuple_values = ( "never" ); +@records = (); while(<IN>) { chomp; + s/\s*#.*$//; next if /^\s*$/; - next if /^\s*#/; if (/^\S/) { - # Print last record - &print_record() if defined($var); + # Store previous record and begin new one + $records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var); $var = $_; - ($type, $desc) = (undef, undef); - $count++; + $type = ''; + $desc = undef; + $values = undef; + $callback = undef; + $field = 0; } else { + $field++; s/^\s+//; s/\s+$//; - die "$0: syntax error near line $.\n" if - defined($type) && defined($desc); - next if /^NULL$/; - if (defined($type)) { - # Strip leading and trailing double quote and escape the rest - s/^"//; - s/"$//; - s/"/\\"/g; - $desc = "\"$_\""; - } else { + if ($field == 1) { + # type $type = $_; + } elsif ($field == 2) { + # description + if ($_ eq "NULL") { + $desc = "NULL"; + } else { + # Strip leading and trailing double quote and escape the rest + s/^"//; + s/"$//; + s/"/\\"/g; + $desc = "\"$_\""; + } + } elsif ($field == 3 || $field == 4) { + if (s/^\*//) { + $callback = $_; + } else { + die "$0: syntax error near line $.\n" if $type !~ /^T_TUPLE/; + $values = [ split ]; + foreach $v (@$values) { + push(@tuple_values, $v) unless grep(/^$v$/, @tuple_values); + } + } + } else { + die "$0: syntax error near line $.\n"; } } } -&print_record(); +$records[$count++] = [$var, $type, $desc, $values, $callback] if defined($var); + +# Print out value arrays +for ($i = 0; $i < $count; $i++) { + if (defined($records[$i]->[3])) { + die "Values list specified for non-tupple\n" unless + $records[$i]->[1] =~ /^T_TUPLE/; + printf CFILE "static struct def_values def_data_%s[] = {\n", $records[$i]->[0]; + foreach (@{$records[$i]->[3]}) { + print CFILE " { \"$_\", $_ },\n"; + } + print CFILE " { NULL, 0 },\n"; + print CFILE "};\n\n"; + } +} + +# Print each record +print CFILE "struct sudo_defs_types sudo_defs_table[] = {\n {\n"; +for ($i = 0; $i < $count; $i++) { + &print_record($records[$i], $i); +} print CFILE "\tNULL, 0, NULL\n }\n};\n"; +# Print out def_tuple +if (@tuple_values) { + print HEADER "\nenum def_tupple {\n"; + foreach (@tuple_values) { + print HEADER "\t$_,\n"; + } + print HEADER "};\n"; +} + close(IN); close(HEADER); close(CFILE); sub print_record { - $defname = "I_" . uc($var); - printf HEADER "#define %-24s%d", $defname, $count; - #print HEADER "\t/* $desc */" if defined($desc); + my ($rec, $recnum) = @_; + my ($i, $v, $defname); + # each variable gets a macro to access its value + for ($rec->[1]) { + if (/^T_U?INT/) { $v = "ival"; } + elsif (/^T_STR/) { $v = "str"; } + elsif (/^T_FLAG/) { $v = "flag"; } + elsif (/^T_MODE/) { $v = "mode"; } + elsif (/^T_LIST/) { $v = "list"; } + elsif (/^T_LOGFAC/) { $v = "ival"; } + elsif (/^T_LOGPRI/) { $v = "ival"; } + elsif (/^T_TUPLE/) { $v = "tuple"; } + else { die "$0: unknown defaults type: $type\n"; } + } + printf HEADER "#define %-23s (sudo_defs_table[$recnum].sd_un.${v})\n", + "def_$rec->[0]"; + + $defname = "I_" . uc($rec->[0]); + printf HEADER "#define %-24s%d", $defname, $recnum; + #print HEADER "\t/* $rec->[2] */" if defined($rec->[2]); print HEADER "\n"; - $desc = "NULL" unless defined($desc); - print CFILE "\t\"$var\", $type,\n\t$desc\n }, {\n"; + print CFILE "\t\"$rec->[0]\", $rec->[1],\n\t$rec->[2],\n"; + if (defined($rec->[3])) { + printf CFILE "\tdef_data_$rec->[0],\n"; + } else { + printf CFILE "\tNULL,\n"; + } + printf CFILE "\t$rec->[4],\n" if defined($rec->[4]); + print CFILE " }, {\n"; } |