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