From cefb826cebf59a7a1464c681e48aeea1b33d4e8e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 14 Dec 2007 16:25:59 +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/branches/Branch-2.2@6067 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/AUTHORS | 7 ++++++- bacula/src/lib/lex.c | 40 ++++++++++++++++++++++++++++++++++++++++ bacula/src/lib/lex.h | 1 + bacula/technotes-2.1 | 4 ++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 582c2538e6..f188694af8 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -11,6 +11,7 @@ Contributors: Adam Thorton Adrew J. Millar Adrian Close +Aitor Matilla Aleksandar Milivojevic Alexander Bergolth Alexandre Baron @@ -20,6 +21,7 @@ Arno Lehmann Attila Fülöp Bernd Frick Bill Moran +Bastian Friedrich Carlos A. Molina G Carsten Paeth Chris Lee @@ -53,14 +55,16 @@ Karl Cunningham Kern Sibbald Landon Fuller Luca Berra +Lucas B. Cohen Lucas Di Pentima Ludovic Strappazon Marc Cousin Marc Schiffbauer Martin Simmons Meno Abels -Michael -buk- Scherer Michael Renner +Michael -buk- Scherer +Michael Stapelberg Michel Meyers Morgan Nic Bellamy @@ -76,6 +80,7 @@ Robert Nelson Rudolf Cejka Russel Howe Sergey Svishchev +Thomas Glatthor Thorsten Enge Tim Oberfoell Tomas Cameron 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.1 b/bacula/technotes-2.1 index fbbd28fcee..c731de8e57 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -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 Skip leading | when lex input comes from a pipe as suggested by Michael Stapelberg . 13Dec07 -- 2.39.5