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