]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - crypto/openssl/util/mkerr.pl
Fix multiple OpenSSL vulnerabilities.
[FreeBSD/releng/9.3.git] / crypto / openssl / util / mkerr.pl
1 #!/usr/local/bin/perl -w
2
3 my $config = "crypto/err/openssl.ec";
4 my $debug = 0;
5 my $rebuild = 0;
6 my $static = 1;
7 my $recurse = 0;
8 my $reindex = 0;
9 my $dowrite = 0;
10 my $staticloader = "";
11
12 my $pack_errcode;
13 my $load_errcode;
14
15 while (@ARGV) {
16         my $arg = $ARGV[0];
17         if($arg eq "-conf") {
18                 shift @ARGV;
19                 $config = shift @ARGV;
20         } elsif($arg eq "-debug") {
21                 $debug = 1;
22                 shift @ARGV;
23         } elsif($arg eq "-rebuild") {
24                 $rebuild = 1;
25                 shift @ARGV;
26         } elsif($arg eq "-recurse") {
27                 $recurse = 1;
28                 shift @ARGV;
29         } elsif($arg eq "-reindex") {
30                 $reindex = 1;
31                 shift @ARGV;
32         } elsif($arg eq "-nostatic") {
33                 $static = 0;
34                 shift @ARGV;
35         } elsif($arg eq "-staticloader") {
36                 $staticloader = "static ";
37                 shift @ARGV;
38         } elsif($arg eq "-write") {
39                 $dowrite = 1;
40                 shift @ARGV;
41         } else {
42                 last;
43         }
44 }
45
46 if($recurse) {
47         @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>,
48                         <fips/*.c>, <fips/*/*.c>);
49 } else {
50         @source = @ARGV;
51 }
52
53 # Read in the config file
54
55 open(IN, "<$config") || die "Can't open config file $config";
56
57 # Parse config file
58
59 while(<IN>)
60 {
61         if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
62                 $hinc{$1} = $2;
63                 $libinc{$2} = $1;
64                 $cskip{$3} = $1;
65                 if($3 ne "NONE") {
66                         $csrc{$1} = $3;
67                         $fmax{$1} = 99;
68                         $rmax{$1} = 99;
69                         $fassigned{$1} = ":";
70                         $rassigned{$1} = ":";
71                         $fnew{$1} = 0;
72                         $rnew{$1} = 0;
73                 }
74         } elsif (/^F\s+(\S+)/) {
75         # Add extra function with $1
76         } elsif (/^R\s+(\S+)\s+(\S+)/) {
77                 $rextra{$1} = $2;
78                 $rcodes{$1} = $2;
79         }
80 }
81
82 close IN;
83
84 # Scan each header file in turn and make a list of error codes
85 # and function names
86
87 while (($hdr, $lib) = each %libinc)
88 {
89         next if($hdr eq "NONE");
90         print STDERR "Scanning header file $hdr\n" if $debug; 
91         my $line = "", $def= "", $linenr = 0, $gotfile = 0;
92         if (open(IN, "<$hdr")) {
93             $gotfile = 1;
94             while(<IN>) {
95                 $linenr++;
96                 print STDERR "line: $linenr\r" if $debug;
97
98                 last if(/BEGIN\s+ERROR\s+CODES/);
99                 if ($line ne '') {
100                     $_ = $line . $_;
101                     $line = '';
102                 }
103
104                 if (/\\$/) {
105                     $line = $_;
106                     next;
107                 }
108
109                 if(/\/\*/) {
110                     if (not /\*\//) {           # multiline comment...
111                         $line = $_;             # ... just accumulate
112                         next; 
113                     } else {
114                         s/\/\*.*?\*\///gs;      # wipe it
115                     }
116                 }
117
118                 if ($cpp) {
119                     $cpp++ if /^#\s*if/;
120                     $cpp-- if /^#\s*endif/;
121                     next;
122                 }
123                 $cpp = 1 if /^#.*ifdef.*cplusplus/;  # skip "C" declaration
124
125                 next if (/^\#/);                      # skip preprocessor directives
126
127                 s/{[^{}]*}//gs;                      # ignore {} blocks
128
129                 if (/\{|\/\*/) { # Add a } so editor works...
130                     $line = $_;
131                 } else {
132                     $def .= $_;
133                 }
134             }
135         }
136
137         print STDERR "                                  \r" if $debug;
138         $defnr = 0;
139         # Delete any DECLARE_ macros
140         $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
141         foreach (split /;/, $def) {
142             $defnr++;
143             print STDERR "def: $defnr\r" if $debug;
144
145             # The goal is to collect function names from function declarations.
146
147             s/^[\n\s]*//g;
148             s/[\n\s]*$//g;
149
150             # Skip over recognized non-function declarations
151             next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/);
152
153             # Remove STACK_OF(foo)
154             s/STACK_OF\(\w+\)/void/;
155
156             # Reduce argument lists to empty ()
157             # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {}
158             while(/\(.*\)/s) {
159                 s/\([^\(\)]+\)/\{\}/gs;
160                 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs;    #(*f{}) -> f
161             }
162             # pretend as we didn't use curly braces: {} -> ()
163             s/\{\}/\(\)/gs;
164
165             if (/(\w+)\s*\(\).*/s) {    # first token prior [first] () is
166                 my $name = $1;          # a function name!
167                 $name =~ tr/[a-z]/[A-Z]/;
168                 $ftrans{$name} = $1;
169             } elsif (/[\(\)]/ and not (/=/)) {
170                 print STDERR "Header $hdr: cannot parse: $_;\n";
171             }
172         }
173
174         print STDERR "                                  \r" if $debug;
175
176         next if $reindex;
177
178         # Scan function and reason codes and store them: keep a note of the
179         # maximum code used.
180
181         if ($gotfile) {
182           while(<IN>) {
183                 if(/^\#\s*define\s+(\S+)\s+(\S+)/) {
184                         $name = $1;
185                         $code = $2;
186                         next if $name =~ /^${lib}err/;
187                         unless($name =~ /^${lib}_([RF])_(\w+)$/) {
188                                 print STDERR "Invalid error code $name\n";
189                                 next;
190                         }
191                         if($1 eq "R") {
192                                 $rcodes{$name} = $code;
193                                 if ($rassigned{$lib} =~ /:$code:/) {
194                                         print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
195                                 }
196                                 $rassigned{$lib} .= "$code:";
197                                 if(!(exists $rextra{$name}) &&
198                                          ($code > $rmax{$lib}) ) {
199                                         $rmax{$lib} = $code;
200                                 }
201                         } else {
202                                 if ($fassigned{$lib} =~ /:$code:/) {
203                                         print STDERR "!! ERROR: $lib function code $code assigned twice\n";
204                                 }
205                                 $fassigned{$lib} .= "$code:";
206                                 if($code > $fmax{$lib}) {
207                                         $fmax{$lib} = $code;
208                                 }
209                                 $fcodes{$name} = $code;
210                         }
211                 }
212           }
213         }
214
215         if ($debug) {
216                 if (defined($fmax{$lib})) {
217                         print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
218                         $fassigned{$lib} =~ m/^:(.*):$/;
219                         @fassigned = sort {$a <=> $b} split(":", $1);
220                         print STDERR "  @fassigned\n";
221                 }
222                 if (defined($rmax{$lib})) {
223                         print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
224                         $rassigned{$lib} =~ m/^:(.*):$/;
225                         @rassigned = sort {$a <=> $b} split(":", $1);
226                         print STDERR "  @rassigned\n";
227                 }
228         }
229
230         if ($lib eq "SSL") {
231                 if ($rmax{$lib} >= 1000) {
232                         print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
233                         print STDERR "!!        Any new alerts must be added to $config.\n";
234                         print STDERR "\n";
235                 }
236         }
237         close IN;
238 }
239
240 # Scan each C source file and look for function and reason codes
241 # This is done by looking for strings that "look like" function or
242 # reason codes: basically anything consisting of all upper case and
243 # numerics which has _F_ or _R_ in it and which has the name of an
244 # error library at the start. This seems to work fine except for the
245 # oddly named structure BIO_F_CTX which needs to be ignored.
246 # If a code doesn't exist in list compiled from headers then mark it
247 # with the value "X" as a place holder to give it a value later.
248 # Store all function and reason codes found in %ufcodes and %urcodes
249 # so all those unreferenced can be printed out.
250
251
252 foreach $file (@source) {
253         # Don't parse the error source file.
254         next if exists $cskip{$file};
255         print STDERR "File loaded: ".$file."\r" if $debug;
256         open(IN, "<$file") || die "Can't open source file $file\n";
257         while(<IN>) {
258                 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
259                         next unless exists $csrc{$2};
260                         next if($1 eq "BIO_F_BUFFER_CTX");
261                         $ufcodes{$1} = 1;
262                         if(!exists $fcodes{$1}) {
263                                 $fcodes{$1} = "X";
264                                 $fnew{$2}++;
265                         }
266                         $notrans{$1} = 1 unless exists $ftrans{$3};
267                 }
268                 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
269                         next unless exists $csrc{$2};
270                         $urcodes{$1} = 1;
271                         if(!exists $rcodes{$1}) {
272                                 $rcodes{$1} = "X";
273                                 $rnew{$2}++;
274                         }
275                 } 
276         }
277         close IN;
278 }
279 print STDERR "                                  \n" if $debug;
280
281 # Now process each library in turn.
282
283 foreach $lib (keys %csrc)
284 {
285         my $hfile = $hinc{$lib};
286         my $cfile = $csrc{$lib};
287         if(!$fnew{$lib} && !$rnew{$lib}) {
288                 print STDERR "$lib:\t\tNo new error codes\n";
289                 next unless $rebuild;
290         } else {
291                 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
292                 print STDERR " $rnew{$lib} New Reasons.\n";
293                 next unless $dowrite;
294         }
295
296         # If we get here then we have some new error codes so we
297         # need to rebuild the header file and C file.
298
299         # Make a sorted list of error and reason codes for later use.
300
301         my @function = sort grep(/^${lib}_/,keys %fcodes);
302         my @reasons = sort grep(/^${lib}_/,keys %rcodes);
303
304         # Rewrite the header file
305
306         if (open(IN, "<$hfile")) {
307             # Copy across the old file
308             while(<IN>) {
309                 push @out, $_;
310                 last if (/BEGIN ERROR CODES/);
311             }
312             close IN;
313         } else {
314             push @out,
315 "/* ====================================================================\n",
316 " * Copyright (c) 2001-2011 The OpenSSL Project.  All rights reserved.\n",
317 " *\n",
318 " * Redistribution and use in source and binary forms, with or without\n",
319 " * modification, are permitted provided that the following conditions\n",
320 " * are met:\n",
321 " *\n",
322 " * 1. Redistributions of source code must retain the above copyright\n",
323 " *    notice, this list of conditions and the following disclaimer. \n",
324 " *\n",
325 " * 2. Redistributions in binary form must reproduce the above copyright\n",
326 " *    notice, this list of conditions and the following disclaimer in\n",
327 " *    the documentation and/or other materials provided with the\n",
328 " *    distribution.\n",
329 " *\n",
330 " * 3. All advertising materials mentioning features or use of this\n",
331 " *    software must display the following acknowledgment:\n",
332 " *    \"This product includes software developed by the OpenSSL Project\n",
333 " *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
334 " *\n",
335 " * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
336 " *    endorse or promote products derived from this software without\n",
337 " *    prior written permission. For written permission, please contact\n",
338 " *    openssl-core\@openssl.org.\n",
339 " *\n",
340 " * 5. Products derived from this software may not be called \"OpenSSL\"\n",
341 " *    nor may \"OpenSSL\" appear in their names without prior written\n",
342 " *    permission of the OpenSSL Project.\n",
343 " *\n",
344 " * 6. Redistributions of any form whatsoever must retain the following\n",
345 " *    acknowledgment:\n",
346 " *    \"This product includes software developed by the OpenSSL Project\n",
347 " *    for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
348 " *\n",
349 " * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
350 " * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
351 " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
352 " * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
353 " * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
354 " * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
355 " * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
356 " * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
357 " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
358 " * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
359 " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
360 " * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
361 " * ====================================================================\n",
362 " *\n",
363 " * This product includes cryptographic software written by Eric Young\n",
364 " * (eay\@cryptsoft.com).  This product includes software written by Tim\n",
365 " * Hudson (tjh\@cryptsoft.com).\n",
366 " *\n",
367 " */\n",
368 "\n",
369 "#ifndef HEADER_${lib}_ERR_H\n",
370 "#define HEADER_${lib}_ERR_H\n",
371 "\n",
372 "/* BEGIN ERROR CODES */\n";
373         }
374         open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
375
376         print OUT @out;
377         undef @out;
378         print OUT <<"EOF";
379 /*
380  * The following lines are auto generated by the script mkerr.pl. Any changes
381  * made after this point may be overwritten when the script is next run.
382  */
383 EOF
384         if($static) {
385                 print OUT <<"EOF";
386 ${staticloader}void ERR_load_${lib}_strings(void);
387
388 EOF
389         } else {
390                 print OUT <<"EOF";
391 ${staticloader}void ERR_load_${lib}_strings(void);
392 ${staticloader}void ERR_unload_${lib}_strings(void);
393 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
394 # define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
395
396 EOF
397         }
398         print OUT <<"EOF";
399 /* Error codes for the $lib functions. */
400
401 /* Function codes. */
402 EOF
403
404         foreach $i (@function) {
405                 $z=48 - length($i);
406                 if($fcodes{$i} eq "X") {
407                         $fassigned{$lib} =~ m/^:([^:]*):/;
408                         $findcode = $1;
409                         if (!defined($findcode)) {
410                                 $findcode = $fmax{$lib};
411                         }
412                         while ($fassigned{$lib} =~ m/:$findcode:/) {
413                                 $findcode++;
414                         }
415                         $fcodes{$i} = $findcode;
416                         $fassigned{$lib} .= "$findcode:";
417                         print STDERR "New Function code $i\n" if $debug;
418                 }
419                 printf OUT "# define $i%s $fcodes{$i}\n"," " x $z;
420         }
421
422         print OUT "\n/* Reason codes. */\n";
423
424         foreach $i (@reasons) {
425                 $z=48 - length($i);
426                 if($rcodes{$i} eq "X") {
427                         $rassigned{$lib} =~ m/^:([^:]*):/;
428                         $findcode = $1;
429                         if (!defined($findcode)) {
430                                 $findcode = $rmax{$lib};
431                         }
432                         while ($rassigned{$lib} =~ m/:$findcode:/) {
433                                 $findcode++;
434                         }
435                         $rcodes{$i} = $findcode;
436                         $rassigned{$lib} .= "$findcode:";
437                         print STDERR "New Reason code   $i\n" if $debug;
438                 }
439                 printf OUT "# define $i%s $rcodes{$i}\n"," " x $z;
440         }
441         print OUT <<"EOF";
442
443 #ifdef  __cplusplus
444 }
445 #endif
446 #endif
447 EOF
448         close OUT;
449
450         # Rewrite the C source file containing the error details.
451
452         # First, read any existing reason string definitions:
453         my %err_reason_strings;
454         if (open(IN,"<$cfile")) {
455                 my $line = "";
456                 while (<IN>) {
457                         chomp;
458                         $_ = $line . $_;
459                         $line = "";
460                         if (/{ERR_REASON\(/) {
461                                 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
462                                         $err_reason_strings{$1} = $2;
463                                 } else {
464                                         $line = $_;
465                                 }
466                         }
467                 }
468                 close(IN);
469         }
470
471         my $hincf;
472         if($static) {
473                 $hfile =~ /([^\/]+)$/;
474                 $hincf = "<openssl/$1>";
475         } else {
476                 $hincf = "\"$hfile\"";
477         }
478
479         # If static we know the error code at compile time so use it
480         # in error definitions.
481
482         if ($static)
483                 {
484                 $pack_errcode = "ERR_LIB_${lib}";
485                 $load_errcode = "0";
486                 }
487         else
488                 {
489                 $pack_errcode = "0";
490                 $load_errcode = "ERR_LIB_${lib}";
491                 }
492
493
494         open (OUT,">$cfile") || die "Can't open $cfile for writing";
495
496         print OUT <<"EOF";
497 /* $cfile */
498 /* ====================================================================
499  * Copyright (c) 1999-2011 The OpenSSL Project.  All rights reserved.
500  *
501  * Redistribution and use in source and binary forms, with or without
502  * modification, are permitted provided that the following conditions
503  * are met:
504  *
505  * 1. Redistributions of source code must retain the above copyright
506  *    notice, this list of conditions and the following disclaimer.
507  *
508  * 2. Redistributions in binary form must reproduce the above copyright
509  *    notice, this list of conditions and the following disclaimer in
510  *    the documentation and/or other materials provided with the
511  *    distribution.
512  *
513  * 3. All advertising materials mentioning features or use of this
514  *    software must display the following acknowledgment:
515  *    "This product includes software developed by the OpenSSL Project
516  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
517  *
518  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
519  *    endorse or promote products derived from this software without
520  *    prior written permission. For written permission, please contact
521  *    openssl-core\@OpenSSL.org.
522  *
523  * 5. Products derived from this software may not be called "OpenSSL"
524  *    nor may "OpenSSL" appear in their names without prior written
525  *    permission of the OpenSSL Project.
526  *
527  * 6. Redistributions of any form whatsoever must retain the following
528  *    acknowledgment:
529  *    "This product includes software developed by the OpenSSL Project
530  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
531  *
532  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
533  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
534  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
535  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
536  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
537  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
538  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
539  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
540  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
541  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
542  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
543  * OF THE POSSIBILITY OF SUCH DAMAGE.
544  * ====================================================================
545  *
546  * This product includes cryptographic software written by Eric Young
547  * (eay\@cryptsoft.com).  This product includes software written by Tim
548  * Hudson (tjh\@cryptsoft.com).
549  *
550  */
551
552 /*
553  * NOTE: this file was auto generated by the mkerr.pl script: any changes
554  * made to it will be overwritten when the script next updates this file,
555  * only reason strings will be preserved.
556  */
557
558 #include <stdio.h>
559 #include <openssl/err.h>
560 #include $hincf
561
562 /* BEGIN ERROR CODES */
563 #ifndef OPENSSL_NO_ERR
564
565 # define ERR_FUNC(func) ERR_PACK($pack_errcode,func,0)
566 # define ERR_REASON(reason) ERR_PACK($pack_errcode,0,reason)
567
568 static ERR_STRING_DATA ${lib}_str_functs[] = {
569 EOF
570         # Add each function code: if a function name is found then use it.
571         foreach $i (@function) {
572                 my $fn;
573                 $i =~ /^${lib}_F_(\S+)$/;
574                 $fn = $1;
575                 if(exists $ftrans{$fn}) {
576                         $fn = $ftrans{$fn};
577                 }
578 #               print OUT "{ERR_PACK($pack_errcode,$i,0),\t\"$fn\"},\n";
579                 if(length($i) + length($fn) > 58) {
580                         print OUT "    {ERR_FUNC($i),\n     \"$fn\"},\n";
581                 } else {
582                         print OUT "    {ERR_FUNC($i), \"$fn\"},\n";
583                 }
584         }
585         print OUT <<"EOF";
586     {0, NULL}
587 };
588
589 static ERR_STRING_DATA ${lib}_str_reasons[] = {
590 EOF
591         # Add each reason code.
592         foreach $i (@reasons) {
593                 my $rn;
594                 my $rstr = "ERR_REASON($i)";
595                 if (exists $err_reason_strings{$i}) {
596                         $rn = $err_reason_strings{$i};
597                 } else {
598                         $i =~ /^${lib}_R_(\S+)$/;
599                         $rn = $1;
600                         $rn =~ tr/_[A-Z]/ [a-z]/;
601                 }
602                 if(length($i) + length($rn) > 56) {
603                         print OUT "    {${rstr},\n     \"$rn\"},\n";
604                 } else {
605                         print OUT "    {${rstr}, \"$rn\"},\n";
606                 }
607         }
608 if($static) {
609         print OUT <<"EOF";
610     {0, NULL}
611 };
612
613 #endif
614
615 ${staticloader}void ERR_load_${lib}_strings(void)
616 {
617 #ifndef OPENSSL_NO_ERR
618
619     if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL) {
620         ERR_load_strings($load_errcode, ${lib}_str_functs);
621         ERR_load_strings($load_errcode, ${lib}_str_reasons);
622     }
623 #endif
624 }
625 EOF
626 } else {
627         print OUT <<"EOF";
628     {0, NULL}
629 };
630
631 #endif
632
633 #ifdef ${lib}_LIB_NAME
634 static ERR_STRING_DATA ${lib}_lib_name[] = {
635     {0, ${lib}_LIB_NAME},
636     {0, NULL}
637 };
638 #endif
639
640 static int ${lib}_lib_error_code = 0;
641 static int ${lib}_error_init = 1;
642
643 ${staticloader}void ERR_load_${lib}_strings(void)
644 {
645     if (${lib}_lib_error_code == 0)
646         ${lib}_lib_error_code = ERR_get_next_error_library();
647
648     if (${lib}_error_init) {
649         ${lib}_error_init = 0;
650 #ifndef OPENSSL_NO_ERR
651         ERR_load_strings(${lib}_lib_error_code, ${lib}_str_functs);
652         ERR_load_strings(${lib}_lib_error_code, ${lib}_str_reasons);
653 #endif
654
655 #ifdef ${lib}_LIB_NAME
656         ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code, 0, 0);
657         ERR_load_strings(0, ${lib}_lib_name);
658 #endif
659     }
660 }
661
662 ${staticloader}void ERR_unload_${lib}_strings(void)
663 {
664     if (${lib}_error_init == 0) {
665 #ifndef OPENSSL_NO_ERR
666         ERR_unload_strings(${lib}_lib_error_code, ${lib}_str_functs);
667         ERR_unload_strings(${lib}_lib_error_code, ${lib}_str_reasons);
668 #endif
669
670 #ifdef ${lib}_LIB_NAME
671         ERR_unload_strings(0, ${lib}_lib_name);
672 #endif
673         ${lib}_error_init = 1;
674     }
675 }
676
677 ${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
678 {
679     if (${lib}_lib_error_code == 0)
680         ${lib}_lib_error_code = ERR_get_next_error_library();
681     ERR_PUT_error(${lib}_lib_error_code, function, reason, file, line);
682 }
683 EOF
684
685 }
686
687         close OUT;
688         undef %err_reason_strings;
689 }
690
691 if($debug && %notrans) {
692         print STDERR "The following function codes were not translated:\n";
693         foreach(sort keys %notrans)
694         {
695                 print STDERR "$_\n";
696         }
697 }
698
699 # Make a list of unreferenced function and reason codes
700
701 foreach (keys %fcodes) {
702         push (@funref, $_) unless exists $ufcodes{$_};
703 }
704
705 foreach (keys %rcodes) {
706         push (@runref, $_) unless exists $urcodes{$_};
707 }
708
709 if($debug && @funref) {
710         print STDERR "The following function codes were not referenced:\n";
711         foreach(sort @funref)
712         {
713                 print STDERR "$_\n";
714         }
715 }
716
717 if($debug && @runref) {
718         print STDERR "The following reason codes were not referenced:\n";
719         foreach(sort @runref)
720         {
721                 print STDERR "$_\n";
722         }
723 }