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