"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/spnego_asn1.pl" (7 Sep 2020, 5916 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "spnego_asn1.pl" see the Fossies "Dox" file reference documentation.

    1 #!/bin/bin/perl -w
    2 #
    3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    4 #
    5 # This Source Code Form is subject to the terms of the Mozilla Public
    6 # License, v. 2.0. If a copy of the MPL was not distributed with this
    7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
    8 #
    9 # See the COPYRIGHT file distributed with this work for additional
   10 # information regarding copyright ownership.
   11 
   12 # Our SPNEGO implementation uses some functions generated by the
   13 # Heimdal ASN.1 compiler, which this script then whacks a bit to make
   14 # them work properly in this stripped down implementation.  We don't
   15 # want to require our users to have a copy of the compiler, so we ship
   16 # the output of this script, but we need to keep the script around in
   17 # any case to cope with future changes to the SPNEGO ASN.1 code, so we
   18 # might as well supply the script for users who want it.
   19 
   20 # Overall plan: run the ASN.1 compiler, run each of its output files
   21 # through indent, fix up symbols and whack everything to be static.
   22 # We use indent for two reasons: (1) to whack the Heimdal compiler's
   23 # output into something closer to ISC's coding standard, and (2) to
   24 # make it easier for this script to parse the result.
   25 
   26 # Output from this script is C code which we expect to be #included
   27 # into another C file, which is why everything generated by this
   28 # script is marked "static".  The intent is to minimize the number of
   29 # extern symbols exported by the SPNEGO implementation, to avoid
   30 # potential conflicts with the GSSAPI libraries.
   31 
   32 ###
   33 
   34 # Filename of the ASN.1 specification.  Hardcoded for the moment
   35 # since this script is intended for compiling exactly one module.
   36 
   37 my $asn1_source = $ENV{ASN1_SOURCE} || "spnego.asn1";
   38 
   39 # Heimdal ASN.1 compiler.  This script was written using the version
   40 # from Heimdal 0.7.1.  To build this, download a copy of
   41 # heimdal-0.7.1.tar.gz, configure and build with the default options,
   42 # then look for the compiler in heimdal-0.7.1/lib/asn1/asn1_compile.
   43 
   44 my $asn1_compile = $ENV{ASN1_COMPILE} || "asn1_compile";
   45 
   46 # BSD indent program.  This script was written using the version of
   47 # indent that comes with FreeBSD 4.11-STABLE.  The GNU project, as
   48 # usual, couldn't resist the temptation to monkey with indent's
   49 # command line syntax, so this probably won't work with GNU indent.
   50 
   51 my $indent = $ENV{INDENT} || "indent";
   52 
   53 ###
   54 
   55 # Step 1: run the compiler.  Input is the ASN.1 file.  Outputs are a
   56 # header file (name specified on command line without the .h suffix),
   57 # a file called "asn1_files" listing the names of the other output
   58 # files, and a set of files containing C code generated by the
   59 # compiler for each data type that the compiler found.
   60 
   61 if (! -r $asn1_source || system($asn1_compile, $asn1_source, "asn1")) {
   62     die("Couldn't compile ASN.1 source file $asn1_source\n");
   63 }
   64 
   65 my @files = ("asn1.h");
   66 
   67 open(F, "asn1_files")
   68     or die("Couldn't open asn1_files: $!\n");
   69 push(@files, split)
   70     while (<F>);
   71 close(F);
   72 
   73 unlink("asn1_files");
   74 
   75 ###
   76 
   77 # Step 2: generate header block.
   78 
   79 print(q~/*
   80  * Copyright (C) 2006  Internet Systems Consortium, Inc. ("ISC")
   81  *
   82  * Permission to use, copy, modify, and distribute this software for any
   83  * purpose with or without fee is hereby granted, provided that the above
   84  * copyright notice and this permission notice appear in all copies.
   85  *
   86  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
   87  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
   88  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
   89  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
   90  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
   91  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
   92  * PERFORMANCE OF THIS SOFTWARE.
   93  */
   94 
   95 /* $Id: spnego_asn1.pl,v 1.4 2007/06/19 23:47:16 tbox Exp $ */
   96 
   97 /*! \file
   98  * \brief Method routines generated from SPNEGO ASN.1 module.
   99  * See spnego_asn1.pl for details.  Do not edit.
  100  */
  101 
  102 ~);
  103 
  104 ###
  105 
  106 # Step 3: read and process each generated file, then delete it.
  107 
  108 my $output;
  109 
  110 for my $file (@files) {
  111 
  112     my $is_static = 0;
  113 
  114     system($indent, "-di1", "-ldi1", $file) == 0
  115     or die("Couldn't indent $file");
  116 
  117     unlink("$file.BAK");
  118 
  119     open(F, $file)
  120     or die("Couldn't open $file: $!");
  121 
  122     while (<F>) {
  123 
  124     # Symbol name fixups
  125 
  126     s/heim_general_string/general_string/g;
  127     s/heim_octet_string/octet_string/g;
  128     s/heim_oid/oid/g;
  129     s/heim_utf8_string/utf8_string/g;
  130 
  131     # Convert all externs to statics
  132 
  133     if (/^static/) {
  134         $is_static = 1;
  135     }
  136 
  137     if (!/^typedef/ &&
  138         !$is_static &&
  139         /^[A-Za-z_][0-9A-Za-z_]*[ \t]*($|[^:0-9A-Za-z_])/) {
  140         $_ = "static " . $_;
  141         $is_static = 1;
  142     }
  143 
  144     if (/[{};]/) {
  145         $is_static = 0;
  146     }
  147 
  148     # Suppress file inclusion, pass anything else through
  149 
  150     if (!/#include/) {
  151         $output .= $_;
  152     }
  153     }
  154 
  155     close(F);
  156     unlink($file);
  157 }
  158 
  159 # Step 4: Delete unused stuff to avoid code bloat and compiler warnings.
  160 
  161 my @unused_functions = qw(ContextFlags2int
  162               int2ContextFlags
  163               asn1_ContextFlags_units
  164               length_NegTokenInit
  165               copy_NegTokenInit
  166               length_NegTokenResp
  167               copy_NegTokenResp
  168               length_MechTypeList
  169               length_MechType
  170               copy_MechTypeList
  171               length_ContextFlags
  172               copy_ContextFlags
  173               copy_MechType);
  174 
  175 $output =~ s<^static [^\n]+\n$_\(.+?^}></* unused function: $_ */\n>ms
  176     foreach (@unused_functions);
  177 
  178 $output =~ s<^static .+$_\(.*\);$></* unused declaration: $_ */>m
  179     foreach (@unused_functions);
  180 
  181 $output =~ s<^static struct units ContextFlags_units\[\].+?^};>
  182             </* unused variable: ContextFlags_units */>ms;
  183 
  184 $output =~ s<^static int asn1_NegotiationToken_dummy_holder = 1;>
  185             </* unused variable: asn1_NegotiationToken_dummy_holder */>ms;
  186 
  187 $output =~ s<^static void\nfree_ContextFlags\(ContextFlags \* data\)\n{\n>
  188             <$&\t(void)data;\n>ms;
  189 
  190 # Step 5: Write the result.
  191 
  192 print($output);
  193