aboutsummaryrefslogtreecommitdiff
path: root/libpam
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2024-01-05 18:24:31 +0100
committerDmitry V. Levin <ldv@strace.io>2024-01-05 23:36:44 +0000
commit9291f8b78f192bdd254ed751369760be61e6d2d8 (patch)
treeb4f1819bde4fadb77c6f1faecd7aaa0467798b7b /libpam
parenta226bcead7d5c6408708938e21c3efc94ba18f30 (diff)
downloadpam-9291f8b78f192bdd254ed751369760be61e6d2d8.tar.gz
pam-9291f8b78f192bdd254ed751369760be61e6d2d8.tar.bz2
pam-9291f8b78f192bdd254ed751369760be61e6d2d8.zip
libpam: allow custom escaped newline replacement
To use _pam_assemble_line in pam_env, we must be able to modify the replacement of an escaped newline. The PAM configuration replaces it with a blank, while pam_env fully removes it. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'libpam')
-rw-r--r--libpam/include/pam_assemble_line.h21
-rw-r--r--libpam/pam_handlers.c2
2 files changed, 14 insertions, 9 deletions
diff --git a/libpam/include/pam_assemble_line.h b/libpam/include/pam_assemble_line.h
index a460b9e1..e2d4d89f 100644
--- a/libpam/include/pam_assemble_line.h
+++ b/libpam/include/pam_assemble_line.h
@@ -138,12 +138,12 @@ static inline char *_pam_str_trim(char *str)
* by ending a line with a backslash (\).
*
* If an escaped newline is encountered, the backslash will be
- * replaced with a blank ' ' and the newline itself removed.
+ * replaced with "repl" and the newline itself removed.
* Then the variable "end" will point to the new end of line.
*
* Returns 0 if escaped newline was found and replaced, 1 otherwise.
*/
-static inline int _pam_str_unescnl(char *start, char **end)
+static inline int _pam_str_unescnl(char *start, char **end, char repl)
{
int ret = 1;
char *p = *end;
@@ -156,8 +156,10 @@ static inline int _pam_str_unescnl(char *start, char **end)
while (p > start && ((*--p == ' ') || (*p == '\t') || (*p == '\n')))
;
if (*p == '\\') {
- *p++ = ' '; /* replace backslash with ' ' */
- *p = '\0'; /* truncate the line here */
+ *p = repl; /* replace backslash with replacement char */
+ if (repl != '\0') {
+ *++p = '\0'; /* truncate the line here if repl is not NUL */
+ }
*end = p;
ret = 0;
}
@@ -175,14 +177,14 @@ static inline int _pam_str_unescnl(char *start, char **end)
* end of line is encountered.
*/
static inline int _pam_str_prepare(char *line, ssize_t len,
- char **start, char **end)
+ char **start, char **end, char repl)
{
int ret;
*start = line;
*end = line + len;
- ret = _pam_str_unescnl(*start, end) || strchr(*start, '#') != NULL;
+ ret = _pam_str_unescnl(*start, end, repl) || strchr(*start, '#') != NULL;
*start = _pam_str_trim(*start);
@@ -193,10 +195,13 @@ static inline int _pam_str_prepare(char *line, ssize_t len,
* This is where we read a line of the PAM config file. The line may be
* preceded by lines of comments and also extended with "\\\n"
*
+ * The "repl" argument is used as replacement char for the backslash used
+ * in newline escaping, i.e. in "\\\n".
+ *
* Returns 0 on EOF, 1 on successful line parsing, or -1 on error.
*/
-static int _pam_assemble_line(FILE *f, struct line_buffer *buffer)
+static int _pam_assemble_line(FILE *f, struct line_buffer *buffer, char repl)
{
int ret = 0;
@@ -222,7 +227,7 @@ static int _pam_assemble_line(FILE *f, struct line_buffer *buffer)
break;
}
- eol = _pam_str_prepare(buffer->chunk, n, &start, &end);
+ eol = _pam_str_prepare(buffer->chunk, n, &start, &end, repl);
if (eol) {
if (_pam_buffer_add_eol(buffer, start, end)) {
diff --git a/libpam/pam_handlers.c b/libpam/pam_handlers.c
index 28f82d73..879c4513 100644
--- a/libpam/pam_handlers.c
+++ b/libpam/pam_handlers.c
@@ -68,7 +68,7 @@ static int _pam_parse_conf_file(pam_handle_t *pamh, FILE *f
/*
* read a line from the configuration (FILE *) f
*/
- while ((x = _pam_assemble_line(f, &buffer)) > 0) {
+ while ((x = _pam_assemble_line(f, &buffer, ' ')) > 0) {
char *buf = buffer.assembled;
char *tok, *nexttok=NULL;
const char *this_service;