X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Flex.c;h=03b64ac0d23498426259807bbc5a9c9bd7756be5;hb=2df589363f0c60f94ca9d5e856dfaf7cc5fcb178;hp=adbab02198bf30b969d184a6f8e3b691c5a4905b;hpb=9a656a099eb63f7fde30c28e543c51b704208e80;p=bacula%2Fbacula diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index adbab02198..03b64ac0d2 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Bacula® is a registered trademark of John Walker. + Bacula® is a registered trademark of Kern Sibbald. The licensor of Bacula is the Free Software Foundation Europe (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. @@ -174,7 +174,7 @@ LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error) if (fname[0] == '|') { - if ((bpipe = open_bpipe(fname, 0, "rb")) == NULL) { + if ((bpipe = open_bpipe(fname+1, 0, "rb")) == NULL) { free(fname); return NULL; } @@ -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 "??????"; @@ -349,6 +351,23 @@ static uint32_t scan_pint(LEX *lf, char *str) return (uint32_t)val; } +static uint64_t scan_pint64(LEX *lf, char *str) +{ + uint64_t val = 0; + if (!is_a_number(str)) { + scan_err1(lf, _("expected a positive integer number, got: %s"), str); + /* NOT REACHED */ + } else { + errno = 0; + val = str_to_uint64(str); + if (errno != 0) { + scan_err1(lf, _("expected a positive integer number, got: %s"), str); + /* NOT REACHED */ + } + } + return val; +} + /* * * Get the next token from the input @@ -567,11 +586,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. */ @@ -689,6 +746,26 @@ lex_get_token(LEX *lf, int expect) } break; + case T_PINT64_RANGE: + if (token == T_NUMBER) { + lf->pint64_val = scan_pint64(lf, lf->str); + lf->pint64_val2 = lf->pint64_val; + token = T_PINT64; + } else { + char *p = strchr(lf->str, '-'); + if (!p) { + scan_err2(lf, _("expected an integer or a range, got %s: %s"), + lex_tok_to_str(token), lf->str); + token = T_ERROR; + break; + } + *p++ = 0; /* terminate first half of range */ + lf->pint64_val = scan_pint64(lf, lf->str); + lf->pint64_val2 = scan_pint64(lf, p); + token = T_PINT64_RANGE; + } + break; + case T_NAME: if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) { scan_err2(lf, _("expected a name, got %s: %s"),