PageRenderTime 127ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 1ms

/contrib/openpam/misc/gendoc.pl

https://bitbucket.org/freebsd/freebsd-head/
Perl | 706 lines | 612 code | 38 blank | 56 comment | 85 complexity | 04f8b7c87504fa6296e3fd3a88c7dcd8 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.0, LGPL-2.1, BSD-2-Clause, 0BSD, JSON, AGPL-1.0, GPL-2.0
  1. #!/usr/bin/perl -w
  2. #-
  3. # Copyright (c) 2002-2003 Networks Associates Technology, Inc.
  4. # Copyright (c) 2004-2011 Dag-Erling Smørgrav
  5. # All rights reserved.
  6. #
  7. # This software was developed for the FreeBSD Project by ThinkSec AS and
  8. # Network Associates Laboratories, the Security Research Division of
  9. # Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
  10. # ("CBOSS"), as part of the DARPA CHATS research program.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions
  14. # are met:
  15. # 1. Redistributions of source code must retain the above copyright
  16. # notice, this list of conditions and the following disclaimer.
  17. # 2. Redistributions in binary form must reproduce the above copyright
  18. # notice, this list of conditions and the following disclaimer in the
  19. # documentation and/or other materials provided with the distribution.
  20. # 3. The name of the author may not be used to endorse or promote
  21. # products derived from this software without specific prior written
  22. # permission.
  23. #
  24. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  25. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  28. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. # SUCH DAMAGE.
  35. #
  36. # $Id: gendoc.pl 599 2012-04-14 15:06:41Z des $
  37. #
  38. use strict;
  39. use locale;
  40. use Fcntl;
  41. use Getopt::Std;
  42. use POSIX qw(locale_h strftime);
  43. use vars qw($COPYRIGHT %AUTHORS $TODAY %FUNCTIONS %PAMERR);
  44. $COPYRIGHT = ".\\\"-
  45. .\\\" Copyright (c) 2001-2003 Networks Associates Technology, Inc.
  46. .\\\" Copyright (c) 2004-2011 Dag-Erling Smørgrav
  47. .\\\" All rights reserved.
  48. .\\\"
  49. .\\\" This software was developed for the FreeBSD Project by ThinkSec AS and
  50. .\\\" Network Associates Laboratories, the Security Research Division of
  51. .\\\" Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
  52. .\\\" (\"CBOSS\"), as part of the DARPA CHATS research program.
  53. .\\\"
  54. .\\\" Redistribution and use in source and binary forms, with or without
  55. .\\\" modification, are permitted provided that the following conditions
  56. .\\\" are met:
  57. .\\\" 1. Redistributions of source code must retain the above copyright
  58. .\\\" notice, this list of conditions and the following disclaimer.
  59. .\\\" 2. Redistributions in binary form must reproduce the above copyright
  60. .\\\" notice, this list of conditions and the following disclaimer in the
  61. .\\\" documentation and/or other materials provided with the distribution.
  62. .\\\" 3. The name of the author may not be used to endorse or promote
  63. .\\\" products derived from this software without specific prior written
  64. .\\\" permission.
  65. .\\\"
  66. .\\\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  67. .\\\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68. .\\\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  69. .\\\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  70. .\\\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  71. .\\\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  72. .\\\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  73. .\\\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74. .\\\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  75. .\\\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  76. .\\\" SUCH DAMAGE.
  77. .\\\"
  78. .\\\" \$" . "Id" . "\$
  79. .\\\"";
  80. %AUTHORS = (
  81. THINKSEC => "developed for the
  82. .Fx
  83. Project by ThinkSec AS and Network Associates Laboratories, the
  84. Security Research Division of Network Associates, Inc.\\& under
  85. DARPA/SPAWAR contract N66001-01-C-8035
  86. .Pq Dq CBOSS ,
  87. as part of the DARPA CHATS research program.",
  88. DES => "developed by
  89. .An Dag-Erling Sm\\(/orgrav Aq des\@des.no .",
  90. );
  91. %PAMERR = (
  92. PAM_SUCCESS => "Success",
  93. PAM_OPEN_ERR => "Failed to load module",
  94. PAM_SYMBOL_ERR => "Invalid symbol",
  95. PAM_SERVICE_ERR => "Error in service module",
  96. PAM_SYSTEM_ERR => "System error",
  97. PAM_BUF_ERR => "Memory buffer error",
  98. PAM_CONV_ERR => "Conversation failure",
  99. PAM_PERM_DENIED => "Permission denied",
  100. PAM_MAXTRIES => "Maximum number of tries exceeded",
  101. PAM_AUTH_ERR => "Authentication error",
  102. PAM_NEW_AUTHTOK_REQD => "New authentication token required",
  103. PAM_CRED_INSUFFICIENT => "Insufficient credentials",
  104. PAM_AUTHINFO_UNAVAIL => "Authentication information is unavailable",
  105. PAM_USER_UNKNOWN => "Unknown user",
  106. PAM_CRED_UNAVAIL => "Failed to retrieve user credentials",
  107. PAM_CRED_EXPIRED => "User credentials have expired",
  108. PAM_CRED_ERR => "Failed to set user credentials",
  109. PAM_ACCT_EXPIRED => "User account has expired",
  110. PAM_AUTHTOK_EXPIRED => "Password has expired",
  111. PAM_SESSION_ERR => "Session failure",
  112. PAM_AUTHTOK_ERR => "Authentication token failure",
  113. PAM_AUTHTOK_RECOVERY_ERR => "Failed to recover old authentication token",
  114. PAM_AUTHTOK_LOCK_BUSY => "Authentication token lock busy",
  115. PAM_AUTHTOK_DISABLE_AGING => "Authentication token aging disabled",
  116. PAM_NO_MODULE_DATA => "Module data not found",
  117. PAM_IGNORE => "Ignore this module",
  118. PAM_ABORT => "General failure",
  119. PAM_TRY_AGAIN => "Try again",
  120. PAM_MODULE_UNKNOWN => "Unknown module type",
  121. PAM_DOMAIN_UNKNOWN => "Unknown authentication domain",
  122. );
  123. sub parse_source($) {
  124. my $fn = shift;
  125. local *FILE;
  126. my $source;
  127. my $func;
  128. my $descr;
  129. my $type;
  130. my $args;
  131. my $argnames;
  132. my $man;
  133. my $inlist;
  134. my $intaglist;
  135. my $inliteral;
  136. my $customrv;
  137. my $deprecated;
  138. my $experimental;
  139. my %xref;
  140. my @errors;
  141. my $author;
  142. if ($fn !~ m,\.c$,) {
  143. warn("$fn: not C source, ignoring\n");
  144. return undef;
  145. }
  146. open(FILE, "<", "$fn")
  147. or die("$fn: open(): $!\n");
  148. $source = join('', <FILE>);
  149. close(FILE);
  150. return undef
  151. if ($source =~ m/^ \* NOPARSE\s*$/m);
  152. $author = 'THINKSEC';
  153. if ($source =~ s/^ \* AUTHOR\s+(\w*)\s*$//m) {
  154. $author = $1;
  155. }
  156. if ($source =~ s/^ \* DEPRECATED\s*(\w*)\s*$//m) {
  157. $deprecated = $1 // 0;
  158. }
  159. if ($source =~ s/^ \* EXPERIMENTAL\s*$//m) {
  160. $experimental = 1;
  161. }
  162. $func = $fn;
  163. $func =~ s,^(?:.*/)?([^/]+)\.c$,$1,;
  164. if ($source !~ m,\n \* ([\S ]+)\n \*/\n\n([\S ]+)\n$func\((.*?)\)\n\{,s) {
  165. warn("$fn: can't find $func\n");
  166. return undef;
  167. }
  168. ($descr, $type, $args) = ($1, $2, $3);
  169. $descr =~ s,^([A-Z][a-z]),lc($1),e;
  170. $descr =~ s,[\.\s]*$,,;
  171. while ($args =~ s/^((?:[^\(]|\([^\)]*\))*),\s*/$1\" \"/g) {
  172. # nothing
  173. }
  174. $args =~ s/,\s+/, /gs;
  175. $args = "\"$args\"";
  176. %xref = (
  177. 3 => { 'pam' => 1 },
  178. );
  179. if ($type eq "int") {
  180. foreach (split("\n", $source)) {
  181. next unless (m/^ \*\s+(!?PAM_[A-Z_]+|=[a-z_]+)\s*$/);
  182. push(@errors, $1);
  183. }
  184. ++$xref{3}->{'pam_strerror'};
  185. }
  186. $argnames = $args;
  187. # extract names of regular arguments
  188. $argnames =~ s/\"[^\"]+\*?\b(\w+)\"/\"$1\"/g;
  189. # extract names of function pointer arguments
  190. $argnames =~ s/\"([\w\s\*]+)\(\*?(\w+)\)\([^\)]+\)\"/\"$2\"/g;
  191. # escape metacharacters (there shouldn't be any, but...)
  192. $argnames =~ s/([\|\[\]\(\)\.\*\+\?])/\\$1/g;
  193. # separate argument names with |
  194. $argnames =~ s/\" \"/|/g;
  195. # and surround with ()
  196. $argnames =~ s/^\"(.*)\"$/$1/;
  197. # $argnames is now a regexp that matches argument names
  198. $inliteral = $inlist = $intaglist = 0;
  199. foreach (split("\n", $source)) {
  200. s/\s*$//;
  201. if (!defined($man)) {
  202. if (m/^\/\*\*$/) {
  203. $man = "";
  204. }
  205. next;
  206. }
  207. last if (m/^ \*\/$/);
  208. s/^ \* ?//;
  209. s/\\(.)/$1/gs;
  210. if (m/^$/) {
  211. # paragraph separator
  212. if ($inlist || $intaglist) {
  213. # either a blank line between list items, or a blank
  214. # line after the final list item. The latter case
  215. # will be handled further down.
  216. next;
  217. }
  218. if ($man =~ m/\n\.Sh [^\n]+\n$/s) {
  219. # a blank line after a section header
  220. next;
  221. }
  222. if ($man ne "" && $man !~ m/\.Pp\n$/s) {
  223. if ($inliteral) {
  224. $man .= "\0\n";
  225. } else {
  226. $man .= ".Pp\n";
  227. }
  228. }
  229. next;
  230. }
  231. if (m/^>(\w+)(\s+\d)?$/) {
  232. # "see also" cross-reference
  233. my ($page, $sect) = ($1, $2 ? int($2) : 3);
  234. ++$xref{$sect}->{$page};
  235. next;
  236. }
  237. if (s/^([A-Z][0-9A-Z -]+)$/.Sh $1/) {
  238. if ($1 eq "RETURN VALUES") {
  239. $customrv = $1;
  240. }
  241. $man =~ s/\n\.Pp$/\n/s;
  242. $man .= "$_\n";
  243. next;
  244. }
  245. if (s/^\s+-\s+//) {
  246. # item in bullet list
  247. if ($inliteral) {
  248. $man .= ".Ed\n";
  249. $inliteral = 0;
  250. }
  251. if ($intaglist) {
  252. $man .= ".El\n.Pp\n";
  253. $intaglist = 0;
  254. }
  255. if (!$inlist) {
  256. $man =~ s/\.Pp\n$//s;
  257. $man .= ".Bl -bullet\n";
  258. $inlist = 1;
  259. }
  260. $man .= ".It\n";
  261. # fall through
  262. } elsif (s/^\s+(\S+):\s*/.It $1/) {
  263. # item in tag list
  264. if ($inliteral) {
  265. $man .= ".Ed\n";
  266. $inliteral = 0;
  267. }
  268. if ($inlist) {
  269. $man .= ".El\n.Pp\n";
  270. $inlist = 0;
  271. }
  272. if (!$intaglist) {
  273. $man =~ s/\.Pp\n$//s;
  274. $man .= ".Bl -tag -width 18n\n";
  275. $intaglist = 1;
  276. }
  277. s/^\.It =([A-Z][A-Z_]+)$/.It Dv $1/gs;
  278. $man .= "$_\n";
  279. next;
  280. } elsif (($inlist || $intaglist) && m/^\S/) {
  281. # regular text after list
  282. $man .= ".El\n.Pp\n";
  283. $inlist = $intaglist = 0;
  284. } elsif ($inliteral && m/^\S/) {
  285. # regular text after literal section
  286. $man .= ".Ed\n";
  287. $inliteral = 0;
  288. } elsif ($inliteral) {
  289. # additional text within literal section
  290. $man .= "$_\n";
  291. next;
  292. } elsif ($inlist || $intaglist) {
  293. # additional text within list
  294. s/^\s+//;
  295. } elsif (m/^\s+/) {
  296. # new literal section
  297. $man .= ".Bd -literal\n";
  298. $inliteral = 1;
  299. $man .= "$_\n";
  300. next;
  301. }
  302. s/\s*=($func)\b\s*/\n.Fn $1\n/gs;
  303. s/\s*=($argnames)\b\s*/\n.Fa $1\n/gs;
  304. s/\s*=(struct \w+(?: \*)?)\b\s*/\n.Vt $1\n/gs;
  305. s/\s*:([a-z_]+)\b\s*/\n.Va $1\n/gs;
  306. s/\s*;([a-z_]+)\b\s*/\n.Dv $1\n/gs;
  307. s/\s*=!([a-z_]+)\b\s*/\n.Xr $1 3\n/gs;
  308. while (s/\s*=([a-z_]+)\b\s*/\n.Xr $1 3\n/s) {
  309. ++$xref{3}->{$1};
  310. }
  311. s/\s*\"(?=\w)/\n.Do\n/gs;
  312. s/\"(?!\w)\s*/\n.Dc\n/gs;
  313. s/\s*=([A-Z][A-Z_]+)\b\s*(?![\.,:;])/\n.Dv $1\n/gs;
  314. s/\s*=([A-Z][A-Z_]+)\b([\.,:;]+)\s*/\n.Dv $1 $2\n/gs;
  315. s/\s*{([A-Z][a-z] .*?)}\s*/\n.$1\n/gs;
  316. $man .= "$_\n";
  317. }
  318. if (defined($man)) {
  319. if ($inlist || $intaglist) {
  320. $man .= ".El\n";
  321. $inlist = $intaglist = 0;
  322. }
  323. if ($inliteral) {
  324. $man .= ".Ed\n";
  325. $inliteral = 0;
  326. }
  327. $man =~ s/\%/\\&\%/gs;
  328. $man =~ s/(\n\.[A-Z][a-z] [\w ]+)\n([.,:;-])\s+/$1 $2\n/gs;
  329. $man =~ s/\s*$/\n/gm;
  330. $man =~ s/\n+/\n/gs;
  331. $man =~ s/\0//gs;
  332. $man =~ s/\n\n\./\n\./gs;
  333. chomp($man);
  334. } else {
  335. $man = "No description available.";
  336. }
  337. $FUNCTIONS{$func} = {
  338. 'source' => $fn,
  339. 'name' => $func,
  340. 'descr' => $descr,
  341. 'type' => $type,
  342. 'args' => $args,
  343. 'man' => $man,
  344. 'xref' => \%xref,
  345. 'errors' => \@errors,
  346. 'author' => $author,
  347. 'customrv' => $customrv,
  348. 'deprecated' => $deprecated,
  349. 'experimental' => $experimental,
  350. };
  351. if ($source =~ m/^ \* NODOC\s*$/m) {
  352. $FUNCTIONS{$func}->{'nodoc'} = 1;
  353. }
  354. if ($source !~ m/^ \* XSSO \d/m) {
  355. $FUNCTIONS{$func}->{'openpam'} = 1;
  356. }
  357. expand_errors($FUNCTIONS{$func});
  358. return $FUNCTIONS{$func};
  359. }
  360. sub expand_errors($);
  361. sub expand_errors($) {
  362. my $func = shift; # Ref to function hash
  363. my %errors;
  364. my $ref;
  365. my $fn;
  366. if (defined($func->{'recursed'})) {
  367. warn("$func->{'name'}(): loop in error spec\n");
  368. return qw();
  369. }
  370. $func->{'recursed'} = 1;
  371. foreach (@{$func->{'errors'}}) {
  372. if (m/^(PAM_[A-Z_]+)$/) {
  373. if (!defined($PAMERR{$1})) {
  374. warn("$func->{'name'}(): unrecognized error: $1\n");
  375. next;
  376. }
  377. $errors{$1} = 1;
  378. } elsif (m/^!(PAM_[A-Z_]+)$/) {
  379. # treat negations separately
  380. } elsif (m/^=([a-z_]+)$/) {
  381. $ref = $1;
  382. if (!defined($FUNCTIONS{$ref})) {
  383. $fn = $func->{'source'};
  384. $fn =~ s/$func->{'name'}/$ref/;
  385. parse_source($fn);
  386. }
  387. if (!defined($FUNCTIONS{$ref})) {
  388. warn("$func->{'name'}(): reference to unknown $ref()\n");
  389. next;
  390. }
  391. foreach (@{$FUNCTIONS{$ref}->{'errors'}}) {
  392. $errors{$_} = 1;
  393. }
  394. } else {
  395. warn("$func->{'name'}(): invalid error specification: $_\n");
  396. }
  397. }
  398. foreach (@{$func->{'errors'}}) {
  399. if (m/^!(PAM_[A-Z_]+)$/) {
  400. delete($errors{$1});
  401. }
  402. }
  403. delete($func->{'recursed'});
  404. $func->{'errors'} = [ sort(keys(%errors)) ];
  405. }
  406. sub dictionary_order($$) {
  407. my ($a, $b) = @_;
  408. $a =~ s/[^[:alpha:]]//g;
  409. $b =~ s/[^[:alpha:]]//g;
  410. $a cmp $b;
  411. }
  412. sub genxref($) {
  413. my $xref = shift; # References
  414. my $mdoc = '';
  415. my @refs = ();
  416. foreach my $sect (sort(keys(%{$xref}))) {
  417. foreach my $page (sort(dictionary_order keys(%{$xref->{$sect}}))) {
  418. push(@refs, "$page $sect");
  419. }
  420. }
  421. while ($_ = shift(@refs)) {
  422. $mdoc .= ".Xr $_" .
  423. (@refs ? " ,\n" : "\n");
  424. }
  425. return $mdoc;
  426. }
  427. sub gendoc($) {
  428. my $func = shift; # Ref to function hash
  429. local *FILE;
  430. my $mdoc;
  431. my $fn;
  432. return if defined($func->{'nodoc'});
  433. $mdoc = "$COPYRIGHT
  434. .Dd $TODAY
  435. .Dt " . uc($func->{'name'}) . " 3
  436. .Os
  437. .Sh NAME
  438. .Nm $func->{'name'}
  439. .Nd $func->{'descr'}
  440. .Sh LIBRARY
  441. .Lb libpam
  442. .Sh SYNOPSIS
  443. .In sys/types.h
  444. ";
  445. if ($func->{'args'} =~ m/\bFILE \*\b/) {
  446. $mdoc .= ".In stdio.h\n";
  447. }
  448. $mdoc .= ".In security/pam_appl.h
  449. ";
  450. if ($func->{'name'} =~ m/_sm_/) {
  451. $mdoc .= ".In security/pam_modules.h\n";
  452. }
  453. if ($func->{'name'} =~ m/openpam/) {
  454. $mdoc .= ".In security/openpam.h\n";
  455. }
  456. $mdoc .= ".Ft \"$func->{'type'}\"
  457. .Fn $func->{'name'} $func->{'args'}
  458. .Sh DESCRIPTION
  459. ";
  460. if (defined($func->{'deprecated'})) {
  461. $mdoc .= ".Bf Sy\n" .
  462. "This function is deprecated and may be removed " .
  463. "in a future release without further warning.\n";
  464. if ($func->{'deprecated'}) {
  465. $mdoc .= "The\n.Fn $func->{'deprecated'}\nfunction " .
  466. "may be used to achieve similar results.\n";
  467. }
  468. $mdoc .= ".Ef\n.Pp\n";
  469. }
  470. if ($func->{'experimental'}) {
  471. $mdoc .= ".Bf Sy\n" .
  472. "This function is experimental and may be modified or removed " .
  473. "in a future release without further warning.\n";
  474. $mdoc .= ".Ef\n.Pp\n";
  475. }
  476. $mdoc .= "$func->{'man'}\n";
  477. my @errors = @{$func->{'errors'}};
  478. if ($func->{'customrv'}) {
  479. # leave it
  480. } elsif ($func->{'type'} eq "int" && @errors) {
  481. $mdoc .= ".Sh RETURN VALUES
  482. The
  483. .Fn $func->{'name'}
  484. function returns one of the following values:
  485. .Bl -tag -width 18n
  486. ";
  487. foreach (@errors) {
  488. $mdoc .= ".It Bq Er $_\n$PAMERR{$_}.\n";
  489. }
  490. $mdoc .= ".El\n";
  491. } elsif ($func->{'type'} eq "int") {
  492. $mdoc .= ".Sh RETURN VALUES
  493. The
  494. .Fn $func->{'name'}
  495. function returns 0 on success and -1 on failure.
  496. ";
  497. } elsif ($func->{'type'} =~ m/\*$/) {
  498. $mdoc .= ".Sh RETURN VALUES
  499. The
  500. .Fn $func->{'name'}
  501. function returns
  502. .Dv NULL
  503. on failure.
  504. ";
  505. } elsif ($func->{'type'} ne "void") {
  506. warn("$func->{'name'}(): no error specification\n");
  507. }
  508. $mdoc .= ".Sh SEE ALSO\n" . genxref($func->{'xref'});
  509. $mdoc .= ".Sh STANDARDS\n";
  510. if ($func->{'openpam'}) {
  511. $mdoc .= "The
  512. .Fn $func->{'name'}
  513. function is an OpenPAM extension.
  514. ";
  515. } else {
  516. $mdoc .= ".Rs
  517. .%T \"X/Open Single Sign-On Service (XSSO) - Pluggable Authentication Modules\"
  518. .%D \"June 1997\"
  519. .Re
  520. ";
  521. }
  522. $mdoc .= ".Sh AUTHORS
  523. The
  524. .Fn $func->{'name'}
  525. function and this manual page were\n";
  526. $mdoc .= $AUTHORS{$func->{'author'} // 'THINKSEC_DARPA'} . "\n";
  527. $fn = "$func->{'name'}.3";
  528. if (open(FILE, ">", $fn)) {
  529. print(FILE $mdoc);
  530. close(FILE);
  531. } else {
  532. warn("$fn: open(): $!\n");
  533. }
  534. }
  535. sub readproto($) {
  536. my $fn = shift; # File name
  537. local *FILE;
  538. my %func;
  539. open(FILE, "<", "$fn")
  540. or die("$fn: open(): $!\n");
  541. while (<FILE>) {
  542. if (m/^\.Nm ((?:open)?pam_.*?)\s*$/) {
  543. $func{'Nm'} = $func{'Nm'} || $1;
  544. } elsif (m/^\.Ft (\S.*?)\s*$/) {
  545. $func{'Ft'} = $func{'Ft'} || $1;
  546. } elsif (m/^\.Fn (\S.*?)\s*$/) {
  547. $func{'Fn'} = $func{'Fn'} || $1;
  548. }
  549. }
  550. close(FILE);
  551. if ($func{'Nm'}) {
  552. $FUNCTIONS{$func{'Nm'}} = \%func;
  553. } else {
  554. warn("No function found\n");
  555. }
  556. }
  557. sub gensummary($) {
  558. my $page = shift; # Which page to produce
  559. local *FILE;
  560. my $upage;
  561. my $func;
  562. my %xref;
  563. open(FILE, ">", "$page.3")
  564. or die("$page.3: $!\n");
  565. $page =~ m/(\w+)$/;
  566. $upage = uc($1);
  567. print FILE "$COPYRIGHT
  568. .Dd $TODAY
  569. .Dt $upage 3
  570. .Os
  571. .Sh NAME
  572. ";
  573. my @funcs = sort(keys(%FUNCTIONS));
  574. while ($func = shift(@funcs)) {
  575. print FILE ".Nm $FUNCTIONS{$func}->{'Nm'}";
  576. print FILE " ,"
  577. if (@funcs);
  578. print FILE "\n";
  579. }
  580. print FILE ".Nd Pluggable Authentication Modules Library
  581. .Sh LIBRARY
  582. .Lb libpam
  583. .Sh SYNOPSIS\n";
  584. if ($page eq 'pam') {
  585. print FILE ".In security/pam_appl.h\n";
  586. } else {
  587. print FILE ".In security/openpam.h\n";
  588. }
  589. foreach $func (sort(keys(%FUNCTIONS))) {
  590. print FILE ".Ft $FUNCTIONS{$func}->{'Ft'}\n";
  591. print FILE ".Fn $FUNCTIONS{$func}->{'Fn'}\n";
  592. }
  593. while (<STDIN>) {
  594. if (m/^\.Xr (\S+)\s*(\d)\s*$/) {
  595. ++$xref{int($2)}->{$1};
  596. }
  597. print FILE $_;
  598. }
  599. if ($page eq 'pam') {
  600. print FILE ".Sh RETURN VALUES
  601. The following return codes are defined by
  602. .In security/pam_constants.h :
  603. .Bl -tag -width 18n
  604. ";
  605. foreach (sort(keys(%PAMERR))) {
  606. print FILE ".It Bq Er $_\n$PAMERR{$_}.\n";
  607. }
  608. print FILE ".El\n";
  609. }
  610. print FILE ".Sh SEE ALSO
  611. ";
  612. if ($page eq 'pam') {
  613. ++$xref{3}->{'openpam'};
  614. }
  615. foreach $func (keys(%FUNCTIONS)) {
  616. ++$xref{3}->{$func};
  617. }
  618. print FILE genxref(\%xref);
  619. print FILE ".Sh STANDARDS
  620. .Rs
  621. .%T \"X/Open Single Sign-On Service (XSSO) - Pluggable Authentication Modules\"
  622. .%D \"June 1997\"
  623. .Re
  624. .Sh AUTHORS
  625. The OpenPAM library and this manual page were developed for the
  626. .Fx
  627. Project by ThinkSec AS and Network Associates Laboratories, the
  628. Security Research Division of Network Associates, Inc.\\& under
  629. DARPA/SPAWAR contract N66001-01-C-8035
  630. .Pq Dq CBOSS ,
  631. as part of the DARPA CHATS research program.
  632. .Pp
  633. The OpenPAM library is maintained by
  634. .An Dag-Erling Sm\\(/orgrav Aq des\@des.no .
  635. ";
  636. close(FILE);
  637. }
  638. sub usage() {
  639. print(STDERR "usage: gendoc [-op] source [...]\n");
  640. exit(1);
  641. }
  642. MAIN:{
  643. my %opts;
  644. usage()
  645. unless (@ARGV && getopts("op", \%opts));
  646. setlocale(LC_ALL, "en_US.UTF-8");
  647. $TODAY = strftime("%B %e, %Y", localtime(time()));
  648. $TODAY =~ s,\s+, ,g;
  649. if ($opts{'o'} || $opts{'p'}) {
  650. foreach my $fn (@ARGV) {
  651. readproto($fn);
  652. }
  653. gensummary('openpam')
  654. if ($opts{'o'});
  655. gensummary('pam')
  656. if ($opts{'p'});
  657. } else {
  658. foreach my $fn (@ARGV) {
  659. my $func = parse_source($fn);
  660. gendoc($func)
  661. if (defined($func));
  662. }
  663. }
  664. exit(0);
  665. }