xref: /freebsd/contrib/openpam/doc/man/openpam_readword.3 (revision 3ba4c8c81a28de3e00ccf6d7f92c6f8e58bef456)
1ce77a8d6SDag-Erling Smørgrav.\" Generated from openpam_readword.c by gendoc.pl
2*3ba4c8c8SDag-Erling Smørgrav.Dd June 27, 2023
32f3ed619SDag-Erling Smørgrav.Dt OPENPAM_READWORD 3
42f3ed619SDag-Erling Smørgrav.Os
52f3ed619SDag-Erling Smørgrav.Sh NAME
62f3ed619SDag-Erling Smørgrav.Nm openpam_readword
72f3ed619SDag-Erling Smørgrav.Nd read a word from a file, respecting shell quoting rules
82f3ed619SDag-Erling Smørgrav.Sh SYNOPSIS
92f3ed619SDag-Erling Smørgrav.In sys/types.h
102f3ed619SDag-Erling Smørgrav.In stdio.h
112f3ed619SDag-Erling Smørgrav.In security/pam_appl.h
122f3ed619SDag-Erling Smørgrav.In security/openpam.h
132f3ed619SDag-Erling Smørgrav.Ft "char *"
142f3ed619SDag-Erling Smørgrav.Fn openpam_readword "FILE *f" "int *lineno" "size_t *lenp"
152f3ed619SDag-Erling Smørgrav.Sh DESCRIPTION
162f3ed619SDag-Erling SmørgravThe
172f3ed619SDag-Erling Smørgrav.Fn openpam_readword
182f3ed619SDag-Erling Smørgravfunction reads the next word from a file, and
192f3ed619SDag-Erling Smørgravreturns it in a NUL-terminated buffer allocated with
202f3ed619SDag-Erling Smørgrav.Xr malloc 3 .
212f3ed619SDag-Erling Smørgrav.Pp
222f3ed619SDag-Erling SmørgravA word is a sequence of non-whitespace characters.
232f3ed619SDag-Erling SmørgravHowever, whitespace characters can be included in a word if quoted or
242f3ed619SDag-Erling Smørgravescaped according to the following rules:
252f3ed619SDag-Erling Smørgrav.Bl -bullet
262f3ed619SDag-Erling Smørgrav.It
272f3ed619SDag-Erling SmørgravAn unescaped single or double quote introduces a quoted string,
282f3ed619SDag-Erling Smørgravwhich ends when the same quote character is encountered a second
292f3ed619SDag-Erling Smørgravtime.
302f3ed619SDag-Erling SmørgravThe quotes themselves are stripped.
312f3ed619SDag-Erling Smørgrav.It
322f3ed619SDag-Erling SmørgravWithin a single- or double-quoted string, all whitespace characters,
332f3ed619SDag-Erling Smørgravincluding the newline character, are preserved as-is.
342f3ed619SDag-Erling Smørgrav.It
352f3ed619SDag-Erling SmørgravOutside a quoted string, a backslash escapes the next character,
362f3ed619SDag-Erling Smørgravwhich is preserved as-is, unless that character is a newline, in
372f3ed619SDag-Erling Smørgravwhich case it is discarded and reading continues at the beginning of
382f3ed619SDag-Erling Smørgravthe next line as if the backslash and newline had not been there.
392f3ed619SDag-Erling SmørgravIn all cases, the backslash itself is discarded.
402f3ed619SDag-Erling Smørgrav.It
412f3ed619SDag-Erling SmørgravWithin a single-quoted string, double quotes and backslashes are
422f3ed619SDag-Erling Smørgravpreserved as-is.
432f3ed619SDag-Erling Smørgrav.It
442f3ed619SDag-Erling SmørgravWithin a double-quoted string, a single quote is preserved as-is,
452f3ed619SDag-Erling Smørgravand a backslash is preserved as-is unless used to escape a double
462f3ed619SDag-Erling Smørgravquote.
472f3ed619SDag-Erling Smørgrav.El
482f3ed619SDag-Erling Smørgrav.Pp
492f3ed619SDag-Erling SmørgravIn addition, if the first non-whitespace character on the line is a
502f3ed619SDag-Erling Smørgravhash character (#), the rest of the line is discarded.
512f3ed619SDag-Erling SmørgravIf a hash character occurs within a word, however, it is preserved
522f3ed619SDag-Erling Smørgravas-is.
532f3ed619SDag-Erling SmørgravA backslash at the end of a comment does cause line continuation.
542f3ed619SDag-Erling Smørgrav.Pp
552f3ed619SDag-Erling SmørgravIf
562f3ed619SDag-Erling Smørgrav.Fa lineno
572f3ed619SDag-Erling Smørgravis not
582f3ed619SDag-Erling Smørgrav.Dv NULL ,
592f3ed619SDag-Erling Smørgravthe integer variable it points to is
602f3ed619SDag-Erling Smørgravincremented every time a quoted or escaped newline character is read.
612f3ed619SDag-Erling Smørgrav.Pp
622f3ed619SDag-Erling SmørgravIf
632f3ed619SDag-Erling Smørgrav.Fa lenp
642f3ed619SDag-Erling Smørgravis not
652f3ed619SDag-Erling Smørgrav.Dv NULL ,
662f3ed619SDag-Erling Smørgravthe length of the word (after quotes and
672f3ed619SDag-Erling Smørgravbackslashes have been removed) is stored in the variable it points to.
682f3ed619SDag-Erling Smørgrav.Sh RETURN VALUES
692f3ed619SDag-Erling SmørgravIf successful, the
702f3ed619SDag-Erling Smørgrav.Fn openpam_readword
712f3ed619SDag-Erling Smørgravfunction returns a pointer to a
722f3ed619SDag-Erling Smørgravdynamically allocated NUL-terminated string containing the first word
732f3ed619SDag-Erling Smørgravencountered on the line.
742f3ed619SDag-Erling Smørgrav.Pp
752f3ed619SDag-Erling SmørgravThe caller is responsible for releasing the returned buffer by passing
762f3ed619SDag-Erling Smørgravit to
772f3ed619SDag-Erling Smørgrav.Xr free 3 .
782f3ed619SDag-Erling Smørgrav.Pp
792f3ed619SDag-Erling SmørgravIf
802f3ed619SDag-Erling Smørgrav.Fn openpam_readword
812f3ed619SDag-Erling Smørgravreaches the end of the line or file before any
822f3ed619SDag-Erling Smørgravcharacters are copied to the word, it returns
832f3ed619SDag-Erling Smørgrav.Dv NULL .
842f3ed619SDag-Erling SmørgravIn the former
852f3ed619SDag-Erling Smørgravcase, the newline is pushed back to the file.
862f3ed619SDag-Erling Smørgrav.Pp
872f3ed619SDag-Erling SmørgravIf
882f3ed619SDag-Erling Smørgrav.Fn openpam_readword
892f3ed619SDag-Erling Smørgravreaches the end of the file while a quote or
902f3ed619SDag-Erling Smørgravbackslash escape is in effect, it sets
912f3ed619SDag-Erling Smørgrav.Va errno
922f3ed619SDag-Erling Smørgravto
932f3ed619SDag-Erling Smørgrav.Dv EINVAL
942f3ed619SDag-Erling Smørgravand returns
952f3ed619SDag-Erling Smørgrav.Dv NULL .
962f3ed619SDag-Erling Smørgrav.Sh IMPLEMENTATION NOTES
972f3ed619SDag-Erling SmørgravThe parsing rules are intended to be equivalent to the normal POSIX
982f3ed619SDag-Erling Smørgravshell quoting rules.
992f3ed619SDag-Erling SmørgravAny discrepancy is a bug and should be reported to the author along
1002f3ed619SDag-Erling Smørgravwith sample input that can be used to reproduce the error.
1012f3ed619SDag-Erling Smørgrav.Pp
1022f3ed619SDag-Erling Smørgrav.Sh SEE ALSO
1032f3ed619SDag-Erling Smørgrav.Xr openpam_readline 3 ,
1042f3ed619SDag-Erling Smørgrav.Xr openpam_readlinev 3 ,
1052f3ed619SDag-Erling Smørgrav.Xr pam 3
1062f3ed619SDag-Erling Smørgrav.Sh STANDARDS
1072f3ed619SDag-Erling SmørgravThe
1082f3ed619SDag-Erling Smørgrav.Fn openpam_readword
1092f3ed619SDag-Erling Smørgravfunction is an OpenPAM extension.
1102f3ed619SDag-Erling Smørgrav.Sh AUTHORS
1112f3ed619SDag-Erling SmørgravThe
1122f3ed619SDag-Erling Smørgrav.Fn openpam_readword
1132f3ed619SDag-Erling Smørgravfunction and this manual page were
1142f3ed619SDag-Erling Smørgravdeveloped by
115f3b0ac34SDag-Erling Smørgrav.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no .
116