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 7, 2013 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 19The 20.Fn openpam_readword 21function reads the next word from a file, and 22returns it in a NUL-terminated buffer allocated with 23.Xr malloc 3 . 24.Pp 25A word is a sequence of non-whitespace characters. 26However, whitespace characters can be included in a word if quoted or 27escaped according to the following rules: 28.Bl -bullet 29.It 30An unescaped single or double quote introduces a quoted string, 31which ends when the same quote character is encountered a second 32time. 33The quotes themselves are stripped. 34.It 35Within a single- or double-quoted string, all whitespace characters, 36including the newline character, are preserved as-is. 37.It 38Outside a quoted string, a backslash escapes the next character, 39which is preserved as-is, unless that character is a newline, in 40which case it is discarded and reading continues at the beginning of 41the next line as if the backslash and newline had not been there. 42In all cases, the backslash itself is discarded. 43.It 44Within a single-quoted string, double quotes and backslashes are 45preserved as-is. 46.It 47Within a double-quoted string, a single quote is preserved as-is, 48and a backslash is preserved as-is unless used to escape a double 49quote. 50.El 51.Pp 52In addition, if the first non-whitespace character on the line is a 53hash character (#), the rest of the line is discarded. 54If a hash character occurs within a word, however, it is preserved 55as-is. 56A backslash at the end of a comment does cause line continuation. 57.Pp 58If 59.Fa lineno 60is not 61.Dv NULL , 62the integer variable it points to is 63incremented every time a quoted or escaped newline character is read. 64.Pp 65If 66.Fa lenp 67is not 68.Dv NULL , 69the length of the word (after quotes and 70backslashes have been removed) is stored in the variable it points to. 71.Sh RETURN VALUES 72If successful, the 73.Fn openpam_readword 74function returns a pointer to a 75dynamically allocated NUL-terminated string containing the first word 76encountered on the line. 77.Pp 78The caller is responsible for releasing the returned buffer by passing 79it to 80.Xr free 3 . 81.Pp 82If 83.Fn openpam_readword 84reaches the end of the line or file before any 85characters are copied to the word, it returns 86.Dv NULL . 87In the former 88case, the newline is pushed back to the file. 89.Pp 90If 91.Fn openpam_readword 92reaches the end of the file while a quote or 93backslash escape is in effect, it sets 94.Va errno 95to 96.Dv EINVAL 97and returns 98.Dv NULL . 99.Sh IMPLEMENTATION NOTES 100The parsing rules are intended to be equivalent to the normal POSIX 101shell quoting rules. 102Any discrepancy is a bug and should be reported to the author along 103with 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 110The 111.Fn openpam_readword 112function is an OpenPAM extension. 113.Sh AUTHORS 114The 115.Fn openpam_readword 116function and this manual page were 117developed by 118.An Dag-Erling Sm\(/orgrav Aq des@des.no . 119