From 178bfaa5fa524b2affaff45383cb6ebfac81d11a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 3 Jun 2010 10:26:42 -0400 Subject: [PATCH] Use numeric registers to handle conditionals instead of trying to do it all with text processing. --HG-- branch : 1.7 --- configure | 12 ++++++------ configure.in | 12 ++++++------ sudo.man.pl | 35 ++++++++++++++++++++++------------- sudoers.man.pl | 42 ++++++++++++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 39 deletions(-) diff --git a/configure b/configure index 1976af33b..b3d9112e4 100755 --- a/configure +++ b/configure @@ -2801,9 +2801,9 @@ PROGS="sudo visudo" DEV="#" LDAP="#" REPLAY="#" -BAMAN='.\" ' -LCMAN='.\" ' -SEMAN='.\" ' +BAMAN=0 +LCMAN=0 +SEMAN=0 ZLIB= AUTH_OBJS= AUTH_REG= @@ -5358,7 +5358,7 @@ if test "${with_selinux+set}" = set; then : SUDO_LIBS="${SUDO_LIBS} -lselinux" SUDO_OBJS="${SUDO_OBJS} selinux.o" PROGS="${PROGS} sesh" - SEMAN="" + SEMAN=1 ;; no) ;; *) as_fn_error "\"--with-selinux does not take an argument.\"" "$LINENO" 5 @@ -13905,7 +13905,7 @@ if test "x$ac_cv_header_login_cap_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LOGIN_CAP_H 1 _ACEOF - LOGINCAP_USAGE='[-c class|-] '; LCMAN="" + LOGINCAP_USAGE='[-c class|-] '; LCMAN=1 case "$OS" in freebsd|netbsd) SUDO_LIBS="${SUDO_LIBS} -lutil" ;; @@ -16070,7 +16070,7 @@ if test "x$ac_cv_header_bsd_auth_h" = x""yes; then : AUTH_OBJS="$AUTH_OBJS bsdauth.o" BSDAUTH_USAGE='[-a auth_type] ' - AUTH_EXCL=BSD_AUTH; BAMAN="" + AUTH_EXCL=BSD_AUTH; BAMAN=1 else as_fn_error "BSD authentication was specified but bsd_auth.h could not be found" "$LINENO" 5 fi diff --git a/configure.in b/configure.in index 66c1b98e1..447e63614 100644 --- a/configure.in +++ b/configure.in @@ -131,9 +131,9 @@ PROGS="sudo visudo" DEV="#" LDAP="#" REPLAY="#" -BAMAN='.\" ' -LCMAN='.\" ' -SEMAN='.\" ' +BAMAN=0 +LCMAN=0 +SEMAN=0 ZLIB= AUTH_OBJS= AUTH_REG= @@ -1235,7 +1235,7 @@ AC_ARG_WITH(selinux, [AS_HELP_STRING([--with-selinux], [enable SELinux support]) SUDO_LIBS="${SUDO_LIBS} -lselinux" SUDO_OBJS="${SUDO_OBJS} selinux.o" PROGS="${PROGS} sesh" - SEMAN="" + SEMAN=1 ;; no) ;; *) AC_MSG_ERROR(["--with-selinux does not take an argument."]) @@ -1808,7 +1808,7 @@ else AC_CHECK_HEADERS(termio.h) fi if test ${with_logincap-'no'} != "no"; then - AC_CHECK_HEADERS(login_cap.h, [LOGINCAP_USAGE='[[-c class|-]] '; LCMAN="" + AC_CHECK_HEADERS(login_cap.h, [LOGINCAP_USAGE='[[-c class|-]] '; LCMAN=1 case "$OS" in freebsd|netbsd) SUDO_LIBS="${SUDO_LIBS} -lutil" ;; @@ -2104,7 +2104,7 @@ if test ${with_bsdauth-'no'} != "no"; then AC_CHECK_HEADER(bsd_auth.h, AC_DEFINE(HAVE_BSD_AUTH_H) [AUTH_OBJS="$AUTH_OBJS bsdauth.o"] [BSDAUTH_USAGE='[[-a auth_type]] '] - [AUTH_EXCL=BSD_AUTH; BAMAN=""], + [AUTH_EXCL=BSD_AUTH; BAMAN=1], [AC_MSG_ERROR([BSD authentication was specified but bsd_auth.h could not be found])]) fi diff --git a/sudo.man.pl b/sudo.man.pl index 4d23fbde2..2306c7c0f 100644 --- a/sudo.man.pl +++ b/sudo.man.pl @@ -1,23 +1,32 @@ #!/usr/bin/perl -p BEGIN { - %tags = ( 'a', '@BAMAN@', 'c', '@LCMAN@', 'r', '@SEMAN@', 't', '@SEMAN@'); - $t = undef; + %tags = ( 'a', 'BA', 'c', 'LC', 'r', 'SL', 't', 'SL'); + $cond = -1; } -if (/^\.IP(.*-([acrt]))?/) { - $t = $1 ? $tags{$2} : undef; -} elsif (/-a.*auth_type/) { - $_ = $tags{'a'} . $_; + +# Initialize the numeric register we use for conditionals +if ($cond == -1) { + $_ = ".nr SL \@SEMAN\@\n.nr BA \@BAMAN\@\n.nr LC \@LCMAN\@\n.\\\"\n$_"; + $cond = 0; +} + +# Add conditionals +if (/^\.IP.*-([acrt])/) { + $_ = ".if \\n($tags{$1} \\{\\\n$_"; + $cond = 1; +} elsif ($cond && /^\.(Sh|SS|IP|PP)/) { + $_ = "\\}\n$_"; + $cond = 0; +} + +if (/-a.*auth_type/) { + $_ = ".if \\n($tags{'a'} $_"; } elsif (/(-c.*class.*\||login_cap)/) { - $_ = $tags{'c'} . $_; + $_ = ".if \\n($tags{'c'} $_"; } elsif (/-r.*role.*-t.*type/) { - $_ = $tags{'r'} . $_; + $_ = ".if \\n($tags{'r'} $_"; } # Fix up broken pod2man formatting of F<@foo@/bar> s/\\fI\\f(\(C)?I\@([^\@]*)\\fI\@/\\fI\@$2\@/g; - -# comment out Compile-time-specific lines in DESCRIPTION -if ($t) { - $_ = $t . $_; -} diff --git a/sudoers.man.pl b/sudoers.man.pl index 9ee210a44..6e5da2c28 100644 --- a/sudoers.man.pl +++ b/sudoers.man.pl @@ -1,25 +1,39 @@ #!/usr/bin/perl -p BEGIN { - $t = undef; + $cond = -1; } -if (/^\./) { - if (/^\.I[PX].*use_loginclass/) { - $t = '@LCMAN@'; - } elsif (/^\.I[PX].*(role|type)/) { - $t = '@SEMAN@'; - } else { - $t = undef; - } +# Initialize the numeric register we use for conditionals +if ($cond == -1) { + $_ = ".nr SL \@SEMAN\@\n.nr BA \@BAMAN\@\n.nr LC \@LCMAN\@\n.\\\"\n$_"; + $cond = 0; +} + +# Make SELinux_Spec conditional +if (/(.*)SELinux_Spec\? (.*)$/) { + $_ = ".ie \\n(SL $_.el $1$2\n"; +} elsif (/^(.*SELinux_Spec ::=)/) { + $_ = ".if \\n(SL \\{\\\n$_"; +} elsif (/^(.*Tag_Spec ::=)/) { + $_ = "\\}\n$_"; +} + +if (/^\.S[Sh] "SELinux_Spec"/) { + $_ = ".if \\n(SL \\{\\\n$_"; + $cond = 1; +} elsif (/^\.IP "(role|type)"/) { + $_ = ".if \\n(SL \\{\\\n$_"; + $cond = 1; +} elsif (/^\.IP "use_loginclass"/) { + $_ = ".if \\n(LC \\{\\\n$_"; + $cond = 1; +} elsif ($cond && /^\.(Sh|SS|IP|PP)/) { + $_ = "\\}\n$_"; + $cond = 0; } # Fix up broken pod2man formatting of F<@foo@/bar> s/\\fI\\f(\(C)?I\@([^\@]*)\\fI\@/\\fI\@$2\@/g; s/\\f\(\CW\@([^\@]*)\\fR\@/\@$1\@/g; #\f(CW@secure_path\fR@ - -# Comment out Compile-time-specific lines in DESCRIPTION -if ($t) { - $_ = $t . $_; -} -- 2.40.0