1.\" $NetBSD: openpam_readword.3,v 1.3 2013/12/27 20:10:20 christos Exp $ 2.\" 3.\" Generated from openpam_readword.c by gendoc.pl 4.\" Id: openpam_readword.c 648 2013-03-05 17:54:27Z des 5.Dd September 7, 2013 6.Dt OPENPAM_READWORD 3 7.Os 8.Sh NAME 9.Nm openpam_readword 10.Nd read a word from a file, respecting shell quoting rules 11.Sh LIBRARY 12.Lb libpam 13.Sh SYNOPSIS 14.In sys/types.h 15.In stdio.h 16.In security/pam_appl.h 17.In security/openpam.h 18.Ft "char *" 19.Fn openpam_readword "FILE *f" "int *lineno" "size_t *lenp" 20.Sh DESCRIPTION 21The 22.Fn openpam_readword 23function reads the next word from a file, and 24returns it in a NUL-terminated buffer allocated with 25.Xr malloc 3 . 26.Pp 27A word is a sequence of non-whitespace characters. 28However, whitespace characters can be included in a word if quoted or 29escaped according to the following rules: 30.Bl -bullet 31.It 32An unescaped single or double quote introduces a quoted string, 33which ends when the same quote character is encountered a second 34time. 35The quotes themselves are stripped. 36.It 37Within a single- or double-quoted string, all whitespace characters, 38including the newline character, are preserved as-is. 39.It 40Outside a quoted string, a backslash escapes the next character, 41which is preserved as-is, unless that character is a newline, in 42which case it is discarded and reading continues at the beginning of 43the next line as if the backslash and newline had not been there. 44In all cases, the backslash itself is discarded. 45.It 46Within a single-quoted string, double quotes and backslashes are 47preserved as-is. 48.It 49Within a double-quoted string, a single quote is preserved as-is, 50and a backslash is preserved as-is unless used to escape a double 51quote. 52.El 53.Pp 54In addition, if the first non-whitespace character on the line is a 55hash character (#), the rest of the line is discarded. 56If a hash character occurs within a word, however, it is preserved 57as-is. 58A backslash at the end of a comment does cause line continuation. 59.Pp 60If 61.Fa lineno 62is not 63.Dv NULL , 64the integer variable it points to is 65incremented every time a quoted or escaped newline character is read. 66.Pp 67If 68.Fa lenp 69is not 70.Dv NULL , 71the length of the word (after quotes and 72backslashes have been removed) is stored in the variable it points to. 73.Sh RETURN VALUES 74If successful, the 75.Fn openpam_readword 76function returns a pointer to a 77dynamically allocated NUL-terminated string containing the first word 78encountered on the line. 79.Pp 80The caller is responsible for releasing the returned buffer by passing 81it to 82.Xr free 3 . 83.Pp 84If 85.Fn openpam_readword 86reaches the end of the line or file before any 87characters are copied to the word, it returns 88.Dv NULL . 89In the former 90case, the newline is pushed back to the file. 91.Pp 92If 93.Fn openpam_readword 94reaches the end of the file while a quote or 95backslash escape is in effect, it sets 96.Va errno 97to 98.Dv EINVAL 99and returns 100.Dv NULL . 101.Sh IMPLEMENTATION NOTES 102The parsing rules are intended to be equivalent to the normal POSIX 103shell quoting rules. 104Any discrepancy is a bug and should be reported to the author along 105with sample input that can be used to reproduce the error. 106.Pp 107.Sh SEE ALSO 108.Xr openpam_readline 3 , 109.Xr openpam_readlinev 3 , 110.Xr pam 3 111.Sh STANDARDS 112The 113.Fn openpam_readword 114function is an OpenPAM extension. 115.Sh AUTHORS 116The 117.Fn openpam_readword 118function and this manual page were 119developed by 120.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . 121