xref: /netbsd-src/external/bsd/openpam/dist/doc/man/openpam_readword.3 (revision 0d9d0fd8a30be9a1924e715bbcf67a4a83efd262)
1.\"	$NetBSD: openpam_readword.3,v 1.8 2023/06/30 21:46:20 christos Exp $
2.\"
3.\" Generated from openpam_readword.c by gendoc.pl
4.Dd June 27, 2023
5.Dt OPENPAM_READWORD 3
6.Os
7.Sh NAME
8.Nm openpam_readword
9.Nd read a word from a file, respecting shell quoting rules
10.Sh SYNOPSIS
11.In sys/types.h
12.In stdio.h
13.In security/pam_appl.h
14.In security/openpam.h
15.Ft "char *"
16.Fn openpam_readword "FILE *f" "int *lineno" "size_t *lenp"
17.Sh DESCRIPTION
18The
19.Fn openpam_readword
20function reads the next word from a file, and
21returns it in a NUL-terminated buffer allocated with
22.Xr malloc 3 .
23.Pp
24A word is a sequence of non-whitespace characters.
25However, whitespace characters can be included in a word if quoted or
26escaped according to the following rules:
27.Bl -bullet
28.It
29An unescaped single or double quote introduces a quoted string,
30which ends when the same quote character is encountered a second
31time.
32The quotes themselves are stripped.
33.It
34Within a single- or double-quoted string, all whitespace characters,
35including the newline character, are preserved as-is.
36.It
37Outside a quoted string, a backslash escapes the next character,
38which is preserved as-is, unless that character is a newline, in
39which case it is discarded and reading continues at the beginning of
40the next line as if the backslash and newline had not been there.
41In all cases, the backslash itself is discarded.
42.It
43Within a single-quoted string, double quotes and backslashes are
44preserved as-is.
45.It
46Within a double-quoted string, a single quote is preserved as-is,
47and a backslash is preserved as-is unless used to escape a double
48quote.
49.El
50.Pp
51In addition, if the first non-whitespace character on the line is a
52hash character (#), the rest of the line is discarded.
53If a hash character occurs within a word, however, it is preserved
54as-is.
55A backslash at the end of a comment does cause line continuation.
56.Pp
57If
58.Fa lineno
59is not
60.Dv NULL ,
61the integer variable it points to is
62incremented every time a quoted or escaped newline character is read.
63.Pp
64If
65.Fa lenp
66is not
67.Dv NULL ,
68the length of the word (after quotes and
69backslashes have been removed) is stored in the variable it points to.
70.Sh RETURN VALUES
71If successful, the
72.Fn openpam_readword
73function returns a pointer to a
74dynamically allocated NUL-terminated string containing the first word
75encountered on the line.
76.Pp
77The caller is responsible for releasing the returned buffer by passing
78it to
79.Xr free 3 .
80.Pp
81If
82.Fn openpam_readword
83reaches the end of the line or file before any
84characters are copied to the word, it returns
85.Dv NULL .
86In the former
87case, the newline is pushed back to the file.
88.Pp
89If
90.Fn openpam_readword
91reaches the end of the file while a quote or
92backslash escape is in effect, it sets
93.Va errno
94to
95.Dv EINVAL
96and returns
97.Dv NULL .
98.Sh IMPLEMENTATION NOTES
99The parsing rules are intended to be equivalent to the normal POSIX
100shell quoting rules.
101Any discrepancy is a bug and should be reported to the author along
102with sample input that can be used to reproduce the error.
103.Pp
104.Sh SEE ALSO
105.Xr openpam_readline 3 ,
106.Xr openpam_readlinev 3 ,
107.Xr pam 3
108.Sh STANDARDS
109The
110.Fn openpam_readword
111function is an OpenPAM extension.
112.Sh AUTHORS
113The
114.Fn openpam_readword
115function and this manual page were
116developed by
117.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .
118