]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/openpam/doc/man/openpam_readword.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / openpam / doc / man / openpam_readword.3
1 .\"-
2 .\" Copyright (c) 2001-2003 Networks Associates Technology, Inc.
3 .\" Copyright (c) 2004-2011 Dag-Erling Smørgrav
4 .\" All rights reserved.
5 .\"
6 .\" This software was developed for the FreeBSD Project by ThinkSec AS and
7 .\" Network Associates Laboratories, the Security Research Division of
8 .\" Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
9 .\" ("CBOSS"), as part of the DARPA CHATS research program.
10 .\"
11 .\" Redistribution and use in source and binary forms, with or without
12 .\" modification, are permitted provided that the following conditions
13 .\" are met:
14 .\" 1. Redistributions of source code must retain the above copyright
15 .\"    notice, this list of conditions and the following disclaimer.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\"    notice, this list of conditions and the following disclaimer in the
18 .\"    documentation and/or other materials provided with the distribution.
19 .\" 3. The name of the author may not be used to endorse or promote
20 .\"    products derived from this software without specific prior written
21 .\"    permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\" $Id$
36 .\"
37 .Dd May 26, 2012
38 .Dt OPENPAM_READWORD 3
39 .Os
40 .Sh NAME
41 .Nm openpam_readword
42 .Nd read a word from a file, respecting shell quoting rules
43 .Sh LIBRARY
44 .Lb libpam
45 .Sh SYNOPSIS
46 .In sys/types.h
47 .In stdio.h
48 .In security/pam_appl.h
49 .In security/openpam.h
50 .Ft "char *"
51 .Fn openpam_readword "FILE *f" "int *lineno" "size_t *lenp"
52 .Sh DESCRIPTION
53 The
54 .Fn openpam_readword
55 function reads the next word from a file, and
56 returns it in a NUL-terminated buffer allocated with
57 .Xr malloc 3 .
58 .Pp
59 A word is a sequence of non-whitespace characters.
60 However, whitespace characters can be included in a word if quoted or
61 escaped according to the following rules:
62 .Bl -bullet
63 .It
64 An unescaped single or double quote introduces a quoted string,
65 which ends when the same quote character is encountered a second
66 time.
67 The quotes themselves are stripped.
68 .It
69 Within a single- or double-quoted string, all whitespace characters,
70 including the newline character, are preserved as-is.
71 .It
72 Outside a quoted string, a backslash escapes the next character,
73 which is preserved as-is, unless that character is a newline, in
74 which case it is discarded and reading continues at the beginning of
75 the next line as if the backslash and newline had not been there.
76 In all cases, the backslash itself is discarded.
77 .It
78 Within a single-quoted string, double quotes and backslashes are
79 preserved as-is.
80 .It
81 Within a double-quoted string, a single quote is preserved as-is,
82 and a backslash is preserved as-is unless used to escape a double
83 quote.
84 .El
85 .Pp
86 In addition, if the first non-whitespace character on the line is a
87 hash character (#), the rest of the line is discarded.
88 If a hash character occurs within a word, however, it is preserved
89 as-is.
90 A backslash at the end of a comment does cause line continuation.
91 .Pp
92 If
93 .Fa lineno
94 is not
95 .Dv NULL ,
96 the integer variable it points to is
97 incremented every time a quoted or escaped newline character is read.
98 .Pp
99 If
100 .Fa lenp
101 is not
102 .Dv NULL ,
103 the length of the word (after quotes and
104 backslashes have been removed) is stored in the variable it points to.
105 .Sh RETURN VALUES
106 If successful, the
107 .Fn openpam_readword
108 function returns a pointer to a
109 dynamically allocated NUL-terminated string containing the first word
110 encountered on the line.
111 .Pp
112 The caller is responsible for releasing the returned buffer by passing
113 it to
114 .Xr free 3 .
115 .Pp
116 If
117 .Fn openpam_readword
118 reaches the end of the line or file before any
119 characters are copied to the word, it returns
120 .Dv NULL .
121 In the former
122 case, the newline is pushed back to the file.
123 .Pp
124 If
125 .Fn openpam_readword
126 reaches the end of the file while a quote or
127 backslash escape is in effect, it sets
128 .Va errno
129 to
130 .Dv EINVAL
131 and returns
132 .Dv NULL .
133 .Sh IMPLEMENTATION NOTES
134 The parsing rules are intended to be equivalent to the normal POSIX
135 shell quoting rules.
136 Any discrepancy is a bug and should be reported to the author along
137 with sample input that can be used to reproduce the error.
138 .Pp
139 .Sh SEE ALSO
140 .Xr openpam_readline 3 ,
141 .Xr openpam_readlinev 3 ,
142 .Xr pam 3
143 .Sh STANDARDS
144 The
145 .Fn openpam_readword
146 function is an OpenPAM extension.
147 .Sh AUTHORS
148 The
149 .Fn openpam_readword
150 function and this manual page were
151 developed by
152 .An Dag-Erling Sm\(/orgrav Aq des@des.no .