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