From 61b3d1e1e26466559dd6f879008828f28e950412 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 14 Dec 2007 16:10:52 +0000 Subject: [PATCH] Apply patch from Michael Stapelberg that implements double quoting include names in conf files, and also allows piping input by having the first character be a vertical bar (|). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6066 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/AUTHORS | 3 ++- bacula/src/lib/lex.c | 40 ++++++++++++++++++++++++++++++++++++++++ bacula/src/lib/lex.h | 1 + bacula/technotes-2.3 | 4 ++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 6a013edcd6..f188694af8 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -62,8 +62,9 @@ Marc Cousin Marc Schiffbauer Martin Simmons Meno Abels -Michael -buk- Scherer Michael Renner +Michael -buk- Scherer +Michael Stapelberg Michel Meyers Morgan Nic Bellamy diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index 3a4262ed22..d70c0d8061 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -297,6 +297,8 @@ static const char *lex_state_to_str(int state) case lex_identifier: return _("identifier"); case lex_string: return _("string"); case lex_quoted_string: return _("quoted_string"); + case lex_include: return _("include"); + case lex_include_quoted_string: return _("include_quoted_string"); case lex_utf8_bom: return _("UTF-8 Byte Order Mark"); case lex_utf16_le_bom: return _("UTF-16le Byte Order Mark"); default: return "??????"; @@ -567,11 +569,49 @@ lex_get_token(LEX *lf, int expect) } add_str(lf, ch); break; + case lex_include_quoted_string: + if (ch == L_EOF) { + token = T_ERROR; + break; + } + if (esc_next) { + add_str(lf, ch); + esc_next = false; + break; + } + if (ch == '\\') { + esc_next = true; + break; + } + if (ch == '"') { + /* Keep the original LEX so we can print an error if the included file can't be opened. */ + LEX* lfori = lf; + /* Skip the double quote when restarting parsing */ + lex_get_char(lf); + + lf->state = lex_none; + lf = lex_open_file(lf, lf->str, lf->scan_error); + if (lf == NULL) { + berrno be; + scan_err2(lfori, _("Cannot open included config file %s: %s\n"), + lfori->str, be.bstrerror()); + return T_ERROR; + } + break; + } + add_str(lf, ch); + break; case lex_include: /* scanning a filename */ if (ch == L_EOF) { token = T_ERROR; break; } + if (ch == '"') { + lf->state = lex_include_quoted_string; + break; + } + + if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' || ch == ';' || ch == ',' || ch == '"' || ch == '#') { /* Keep the original LEX so we can print an error if the included file can't be opened. */ diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h index 513ad6188d..25544b568f 100644 --- a/bacula/src/lib/lex.h +++ b/bacula/src/lib/lex.h @@ -85,6 +85,7 @@ enum lex_state { lex_identifier, lex_string, lex_quoted_string, + lex_include_quoted_string, lex_include, lex_utf8_bom, /* we are parsing out a utf8 byte order mark */ lex_utf16_le_bom /* we are parsing out a utf-16 (little endian) byte order mark */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index de4d9708af..65c1f273e1 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,10 @@ General: 14Dec07 +kes Apply patch from Michael Stapelberg + that implements double quoting include names in conf files, + and also allows piping input by having the first character + be a vertical bar (|). kes Apply patch from Bastian Friedrich that implement %f in RunScripts to pass the FileSet name. kes Skip leading | when lex input comes from a pipe as suggested -- 2.39.5