1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/usr/bin/perl
#
# Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use strict;
use warnings;
my @obsolete = qw(
d2i_PBEPARAM d2i_PBE2PARAM d2i_PBKDF2PARAM
i2d_PBEPARAM i2d_PBE2PARAM i2d_PBKDF2PARAM
PBEPARAM PBEPARAM_free PBEPARAM_new
PBE2PARAM PBE2PARAM_free PBE2PARAM_new
PBKDF2PARAM PBKDF2PARAM_free PBKDF2PARAM_new
PKCS5_pbe_set PKCS5_pbe_set0_algor
PKCS5_pbe2_set PKCS5_pbe2_set_iv
PKCS5_pbkdf2_set
X509_EX_V_INIT
X509_EXT_PACK_STRING X509_EXT_PACK_UNKNOWN
);
my $MANW = 'man -M /usr/share/man -w';
my $srcdir = '/usr/src/lib/libcrypto/man';
my $hfile = '/usr/include/openssl';
my $in_cplusplus = 0;
my $in_comment = 0;
my $in_define = 0;
my $in_function = 0;
my $in_struct = 0;
my $in_typedef_struct = 0;
my $verbose = 0;
if (defined $ARGV[0] && $ARGV[0] eq '-v') {
$verbose = 1;
shift @ARGV;
}
$#ARGV == 0 or die "usage: $0 [-v] headername";
$hfile .= "/$ARGV[0].h";
open my $in_fh, '<', $hfile or die "$hfile: $!";
while (<$in_fh>) {
try_again:
chomp;
my $line = $_;
# C language comments.
if ($in_comment) {
unless (s/.*?\*\///) {
print "-- $line\n" if $verbose;
next;
}
$in_comment = 0;
}
while (/\/\*/) {
s/\/\*.*?\*\/// and next;
s/\/\*.*// and $in_comment = 1;
}
# End C++ stuff.
if ($in_cplusplus) {
/^#endif$/ and $in_cplusplus = 0;
print "-- $line\n" if $verbose;
next;
}
# End declarations of structs.
if ($in_struct) {
unless (s/^\s*\}//) {
print "-s $line\n" if $verbose;
next;
}
$in_struct = 0;
unless ($in_typedef_struct) {
/^\s*;$/ or die "at end of struct: $_";
print "-s $line\n" if $verbose;
next;
}
$in_typedef_struct = 0;
my ($id) = /^\s*(\w+);$/
or die "at end of typedef struct: $_";
unless (system "$MANW -k Vt=$id > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
if ($id =~ /NETSCAPE/) {
print "V- $line\n" if $verbose;
next;
}
if (grep { $_ eq $id } @obsolete) {
print "V- $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: typedef struct $id";
}
next;
}
# End macro definitions.
if ($in_define) {
/\\$/ or $in_define = 0;
print "-d $line\n" if $verbose;
next;
}
# End function declarations.
if ($in_function) {
/^\s/ or die "function arguments not indented: $_";
/\);$/ and $in_function = 0;
print "-f $line\n" if $verbose;
next;
}
# Begin C++ stuff.
if (/^#ifdef\s+__cplusplus$/) {
$in_cplusplus = 1;
print "-- $line\n" if $verbose;
next;
}
# Uninteresting lines.
if (/^\s*$/ ||
/^DECLARE_STACK_OF\(\w+\)$/ ||
/^#define HEADER_\w+_H$/ ||
/^#endif$/ ||
/^extern\s+const\s+ASN1_ITEM\s+\w+_it;$/ ||
/^#include\s/ ||
/^#ifn?def\s/) {
print "-- $line\n" if $verbose;
next;
}
# Begin declarations of structs.
if (/^(typedef )?(?:struct|enum)(?: \w+)? \{$/) {
$in_struct = 1;
$1 and $in_typedef_struct = 1;
print "-s $line\n" if $verbose;
next;
}
if (my ($id) = /^#define\s+(\w+)\s+\S/) {
/\\$/ and $in_define = 1;
unless (system "$MANW -k Dv=$id > /dev/null 2>&1") {
print "Dv $line\n" if $verbose;
next;
}
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" ' . $id . '\>',
"$srcdir/") {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /NETSCAPE/) {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^X509_[FR]_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if ($id =~ /^X509_V_ERR_\w+$/) {
print "D- $line\n" if $verbose;
next;
}
if (grep { $_ eq $id } @obsolete) {
print "D- $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: #define $id";
}
next;
}
if (my ($id) = /^#define\s+(\w+)\(/) {
/\\$/ and $in_define = 1;
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" .*' . $id . '(3)',
"$srcdir/") {
print "F- $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: #define $id()";
}
next;
}
if (/^typedef\s+(?:struct\s+)?\S+\s+(\w+);$/) {
unless (system "$MANW -k Vt=$1 > /dev/null 2>&1") {
print "Vt $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: typedef $1";
}
next;
}
if (/^\w+(?:\(\w+\))?(?:\s+\w+)?(?:\s+|\s*\(?\*\s*)(\w+)\s*\(/) {
my $id = $1;
/\);$/ or $in_function = 1;
unless (system "$MANW $id > /dev/null 2>&1") {
print "Fn $line\n" if $verbose;
next;
}
if ($id =~ /NETSCAPE/) {
print "F- $line\n" if $verbose;
next;
}
unless (system qw/grep -qR/, '^\.\\\\" .*' . $id . '\>',
"$srcdir/") {
print "F- $line\n" if $verbose;
next;
}
if (grep { $_ eq $id } @obsolete) {
print "F- $line\n" if $verbose;
next;
}
if ($verbose) {
print "XX $line\n";
} else {
warn "not found: function $id()";
}
next;
}
if (/ \*$/) {
$_ .= <$in_fh>;
goto try_again;
}
die "parse error: $_";
}
close $in_fh;
exit 0;
|