summaryrefslogtreecommitdiffstats
path: root/contrib/openpam/lib/openpam_readline.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/openpam/lib/openpam_readline.c')
-rw-r--r--contrib/openpam/lib/openpam_readline.c52
1 files changed, 18 insertions, 34 deletions
diff --git a/contrib/openpam/lib/openpam_readline.c b/contrib/openpam/lib/openpam_readline.c
index 9cc8cc1..014acfb 100644
--- a/contrib/openpam/lib/openpam_readline.c
+++ b/contrib/openpam/lib/openpam_readline.c
@@ -32,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: openpam_readline.c 473 2011-11-03 10:48:25Z des $
+ * $Id: openpam_readline.c 596 2012-04-14 14:52:40Z des $
*/
#ifdef HAVE_CONFIG_H
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <security/pam_appl.h>
+
#include "openpam_impl.h"
#define MIN_LINE_LENGTH 128
@@ -61,22 +62,11 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp)
size_t len, size;
int ch;
- if ((line = malloc(MIN_LINE_LENGTH)) == NULL)
+ if ((line = malloc(size = MIN_LINE_LENGTH)) == NULL) {
+ openpam_log(PAM_LOG_ERROR, "malloc(): %m");
return (NULL);
- size = MIN_LINE_LENGTH;
+ }
len = 0;
-
-#define line_putch(ch) do { \
- if (len >= size - 1) { \
- char *tmp = realloc(line, size *= 2); \
- if (tmp == NULL) \
- goto fail; \
- line = tmp; \
- } \
- line[len++] = ch; \
- line[len] = '\0'; \
-} while (0)
-
for (;;) {
ch = fgetc(f);
/* strip comment */
@@ -105,26 +95,15 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp)
/* done */
break;
}
- /* whitespace */
- if (isspace(ch)) {
- /* ignore leading whitespace */
- /* collapse linear whitespace */
- if (len > 0 && line[len - 1] != ' ')
- line_putch(' ');
- continue;
- }
/* anything else */
- line_putch(ch);
+ if (openpam_straddch(&line, &size, &len, ch) != 0)
+ goto fail;
}
-
- /* remove trailing whitespace */
- while (len > 0 && isspace((unsigned char)line[len - 1]))
- --len;
- line[len] = '\0';
if (len == 0)
goto fail;
if (lenp != NULL)
*lenp = len;
+ openpam_log(PAM_LOG_LIBDEBUG, "returning '%s'", line);
return (line);
fail:
FREE(line);
@@ -132,16 +111,18 @@ fail:
}
/**
+ * DEPRECATED openpam_readlinev
+ *
* The =openpam_readline function reads a line from a file, and returns it
- * in a NUL-terminated buffer allocated with =malloc.
+ * in a NUL-terminated buffer allocated with =!malloc.
*
* The =openpam_readline function performs a certain amount of processing
* on the data it reads:
*
- * - Comments (introduced by a hash sign) are stripped, as is leading and
- * trailing whitespace.
- * - Any amount of linear whitespace is collapsed to a single space.
+ * - Comments (introduced by a hash sign) are stripped.
+ *
* - Blank lines are ignored.
+ *
* - If a line ends in a backslash, the backslash is stripped and the
* next line is appended.
*
@@ -152,5 +133,8 @@ fail:
* terminating NUL character) is stored in the variable it points to.
*
* The caller is responsible for releasing the returned buffer by passing
- * it to =free.
+ * it to =!free.
+ *
+ * >openpam_readlinev
+ * >openpam_readword
*/
OpenPOWER on IntegriCloud