|
From: <gi...@ba...> - 2012-12-02 10:19:32
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Bacula Community source".
The branch, Branch-5.2 has been updated
via 3df9346e17b58d8641c746f10c407a977b6c4aca (commit)
via f8cd721155b677fbc28d40379119a36595e18cb2 (commit)
via 3610a0b0d8f3c83fffa3340da22aeef885fec898 (commit)
via 28143b646f758a0605a4d849c7eb5901633a7e4f (commit)
via 613a8e66be6e504fd032e39f3476a1b58cdc5d68 (commit)
from 4ee36079993d5c7ea0c268004110a3f59a01624f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3df9346e17b58d8641c746f10c407a977b6c4aca
Author: Eric Bollengier <er...@ba...>
Date: Mon Nov 12 14:59:00 2012 +0100
Tweak debug message in ua_label
commit f8cd721155b677fbc28d40379119a36595e18cb2
Author: Kern Sibbald <ke...@si...>
Date: Sat Nov 17 09:11:32 2012 +0100
Avoid seg fault by checking for NULL client -- reported by Arno
commit 3610a0b0d8f3c83fffa3340da22aeef885fec898
Author: Kern Sibbald <ke...@si...>
Date: Wed Nov 21 13:38:35 2012 +0100
Allow conf file quoted strings to be used in a list
commit 28143b646f758a0605a4d849c7eb5901633a7e4f
Author: Kern Sibbald <ke...@si...>
Date: Wed Nov 21 18:26:37 2012 +0100
Make bfgets handle very long lines
commit 613a8e66be6e504fd032e39f3476a1b58cdc5d68
Author: Marco van Wieringen <mv...@pl...>
Date: Thu Nov 29 18:40:46 2012 +0100
Fix bug #1959 input validation on delete of jobs.
The current code doesn't check on delete of a Job if the given JobId is
a number. Things changed are:
- Use str_to_uint64 casted to uint32_t to match JobId_t
- Validate all tokens parsed to be a valid number.
- Check the range to be increasing.
- Ask for confirmation when the range is more then 25 jobs.
- Reindented some wrongly indented code (2 vs 3 spaces)
-----------------------------------------------------------------------
Summary of changes:
diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c
index ba33029..d4cdf53 100644
--- a/bacula/src/dird/ua_cmds.c
+++ b/bacula/src/dird/ua_cmds.c
@@ -1310,7 +1310,7 @@ static int delete_cmd(UAContext *ua, const char *cmd)
return 1;
case 2:
int i;
- while ((i=find_arg(ua, "jobid")) > 0) {
+ while ((i = find_arg(ua, "jobid")) > 0) {
delete_job(ua);
*ua->argk[i] = 0; /* zap keyword already visited */
}
@@ -1340,52 +1340,66 @@ static int delete_cmd(UAContext *ua, const char *cmd)
return 1;
}
-
/*
- * delete_job has been modified to parse JobID lists like the
- * following:
+ * delete_job has been modified to parse JobID lists like the following:
* delete JobID=3,4,6,7-11,14
*
* Thanks to Phil Stracchino for the above addition.
*/
-
static void delete_job(UAContext *ua)
{
+ int i;
JobId_t JobId;
- char *s,*sep,*tok;
+ char *s, *sep, *tok;
- int i = find_arg_with_value(ua, NT_("jobid"));
+ i = find_arg_with_value(ua, NT_("jobid"));
if (i >= 0) {
- if (strchr(ua->argv[i], ',') != NULL || strchr(ua->argv[i], '-') != NULL) {
- s = bstrdup(ua->argv[i]);
- tok = s;
- /*
- * We could use strtok() here. But we're not going to, because:
- * (a) strtok() is deprecated, having been replaced by strsep();
- * (b) strtok() is broken in significant ways.
- * we could use strsep() instead, but it's not universally available.
- * so we grow our own using strchr().
- */
- sep = strchr(tok, ',');
- while (sep != NULL) {
- *sep = '\0';
- if (!delete_job_id_range(ua, tok)) {
- JobId = str_to_int64(tok);
- do_job_delete(ua, JobId);
- }
- tok = ++sep;
- sep = strchr(tok, ',');
- }
- /* pick up the last token */
- if (!delete_job_id_range(ua, tok)) {
- JobId = str_to_int64(tok);
- do_job_delete(ua, JobId);
- }
+ if (strchr(ua->argv[i], ',') || strchr(ua->argv[i], '-')) {
+ s = bstrdup(ua->argv[i]);
+ tok = s;
+
+ /*
+ * We could use strtok() here. But we're not going to, because:
+ * (a) strtok() is deprecated, having been replaced by strsep();
+ * (b) strtok() is broken in significant ways.
+ * we could use strsep() instead, but it's not universally available.
+ * so we grow our own using strchr().
+ */
+ sep = strchr(tok, ',');
+ while (sep != NULL) {
+ *sep = '\0';
+ if (!delete_job_id_range(ua, tok)) {
+ if (is_a_number(tok)) {
+ JobId = (JobId_t)str_to_uint64(tok);
+ do_job_delete(ua, JobId);
+ } else {
+ ua->warning_msg(_("Illegal JobId %s ignored\n"), tok);
+ }
+ }
+ tok = ++sep;
+ sep = strchr(tok, ',');
+ }
+
+ /*
+ * Pick up the last token
+ */
+ if (!delete_job_id_range(ua, tok)) {
+ if (is_a_number(tok)) {
+ JobId = (JobId_t)str_to_uint64(tok);
+ do_job_delete(ua, JobId);
+ } else {
+ ua->warning_msg(_("Illegal JobId %s ignored\n"), tok);
+ }
+ }
free(s);
} else {
- JobId = str_to_int64(ua->argv[i]);
- do_job_delete(ua, JobId);
+ if (is_a_number(ua->argv[i])) {
+ JobId = (JobId_t)str_to_uint64(ua->argv[i]);
+ do_job_delete(ua, JobId);
+ } else {
+ ua->warning_msg(_("Illegal JobId %s ignored\n"), ua->argv[i]);
+ }
}
} else if (!get_pint(ua, _("Enter JobId to delete: "))) {
return;
@@ -1396,24 +1410,50 @@ static void delete_job(UAContext *ua)
}
/*
- * we call delete_job_id_range to parse range tokens and iterate over ranges
+ * We call delete_job_id_range to parse range tokens and iterate over ranges
*/
static bool delete_job_id_range(UAContext *ua, char *tok)
{
+ char buf[64];
char *tok2;
- JobId_t j,j1,j2;
+ JobId_t j, j1, j2;
tok2 = strchr(tok, '-');
if (!tok2) {
return false;
}
+
*tok2 = '\0';
tok2++;
- j1 = str_to_int64(tok);
- j2 = str_to_int64(tok2);
- for (j=j1; j<=j2; j++) {
- do_job_delete(ua, j);
+
+ if (is_a_number(tok) && is_a_number(tok2)) {
+ j1 = (JobId_t)str_to_uint64(tok);
+ j2 = (JobId_t)str_to_uint64(tok2);
+
+ if (j1 > j2) {
+ /*
+ * See if the range is big if more then 25 Jobs are deleted
+ * ask the user for confirmation.
+ */
+ if ((j2 - j1) > 25) {
+ bsnprintf(buf, sizeof(buf),
+ _("Are you sure you want to delete %d JobIds ? (yes/no): "),
+ j2 - j1);
+ if (!get_yesno(ua, buf)) {
+ return true;
+ }
+ }
+ for (j = j1; j <= j2; j++) {
+ do_job_delete(ua, j);
+ }
+ } else {
+ ua->warning_msg(_("Illegal JobId range %s - %s should define increasing JobIds, ignored\n"),
+ tok, tok2);
+ }
+ } else {
+ ua->warning_msg(_("Illegal JobId range %s - %s, ignored\n"), tok, tok2);
}
+
return true;
}
@@ -1426,7 +1466,7 @@ static void do_job_delete(UAContext *ua, JobId_t JobId)
edit_int64(JobId, ed1);
purge_jobs_from_catalog(ua, ed1);
- ua->send_msg(_("Job %s and associated records deleted from the catalog.\n"), ed1);
+ ua->send_msg(_("Jobid %s and associated records deleted from the catalog.\n"), ed1);
}
/*
diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c
index 7dd1ecf..aa008f0 100644
--- a/bacula/src/dird/ua_label.c
+++ b/bacula/src/dird/ua_label.c
@@ -147,10 +147,12 @@ static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
slot_list[i] = 1;
}
}
- Dmsg0(100, "Slots turned on:\n");
- for (i=1; i <= num_slots; i++) {
- if (slot_list[i]) {
- Dmsg1(100, "%d\n", i);
+ if (debug_level >= 100) {
+ Dmsg0(100, "Slots turned on:\n");
+ for (i=1; i <= num_slots; i++) {
+ if (slot_list[i]) {
+ Dmsg1(100, "%d\n", i);
+ }
}
}
return true;
diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c
index a993edb..68c747c 100644
--- a/bacula/src/dird/ua_prune.c
+++ b/bacula/src/dird/ua_prune.c
@@ -129,7 +129,9 @@ int prunecmd(UAContext *ua, const char *cmd)
switch (kw) {
case 0: /* prune files */
- client = get_client_resource(ua);
+ if (!(client = get_client_resource(ua))) {
+ return false;
+ }
if (find_arg_with_value(ua, "pool") >= 0) {
pool = get_pool_resource(ua);
} else {
@@ -140,13 +142,15 @@ int prunecmd(UAContext *ua, const char *cmd)
if (!confirm_retention(ua, &pool->FileRetention, "File")) {
return false;
}
- } else if (!client || !confirm_retention(ua, &client->FileRetention, "File")) {
+ } else if (!confirm_retention(ua, &client->FileRetention, "File")) {
return false;
}
prune_files(ua, client, pool);
return true;
case 1: /* prune jobs */
- client = get_client_resource(ua);
+ if (!(client = get_client_resource(ua))) {
+ return false;
+ }
if (find_arg_with_value(ua, "pool") >= 0) {
pool = get_pool_resource(ua);
} else {
@@ -157,7 +161,7 @@ int prunecmd(UAContext *ua, const char *cmd)
if (!confirm_retention(ua, &pool->JobRetention, "Job")) {
return false;
}
- } else if (!client || !confirm_retention(ua, &client->JobRetention, "Job")) {
+ } else if (!confirm_retention(ua, &client->JobRetention, "Job")) {
return false;
}
/* ****FIXME**** allow user to select JobType */
diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c
index fdee8f6..7900e3c 100644
--- a/bacula/src/lib/bsys.c
+++ b/bacula/src/lib/bsys.c
@@ -690,6 +690,57 @@ char *bfgets(char *s, int size, FILE *fd)
}
/*
+ * Bacula's implementation of fgets(). The difference is that it handles
+ * being interrupted by a signal (e.g. a SIGCHLD) and it has a
+ * different calling sequence which implements input lines of
+ * up to a million characters.
+ */
+char *bfgets(POOLMEM *&s, FILE *fd)
+{
+ int ch;
+ int soft_max;
+ int i = 0;
+
+ s[0] = 0;
+ soft_max = sizeof_pool_memory(s) - 10;
+ for ( ;; ) {
+ do {
+ errno = 0;
+ ch = fgetc(fd);
+ } while (ch == EOF && ferror(fd) && (errno == EINTR || errno == EAGAIN));
+ if (ch == EOF) {
+ if (i == 0) {
+ return NULL;
+ } else {
+ return s;
+ }
+ }
+ if (i > soft_max) {
+ /* Insanity check */
+ if (soft_max > 1000000) {
+ return s;
+ }
+ s = check_pool_memory_size(s, soft_max+10000);
+ soft_max = sizeof_pool_memory(s) - 10;
+ }
+ s[i++] = ch;
+ s[i] = 0;
+ if (ch == '\r') { /* Support for Mac/Windows file format */
+ ch = fgetc(fd);
+ if (ch != '\n') { /* Mac (\r only) */
+ (void)ungetc(ch, fd); /* Push next character back to fd */
+ }
+ s[i-1] = '\n';
+ break;
+ }
+ if (ch == '\n') {
+ break;
+ }
+ }
+ return s;
+}
+
+/*
* Make a "unique" filename. It is important that if
* called again with the same "what" that the result
* will be identical. This allows us to use the file
diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c
index 4e2558a..c4c78d6 100644
--- a/bacula/src/lib/lex.c
+++ b/bacula/src/lib/lex.c
@@ -139,6 +139,8 @@ LEX *lex_close_file(LEX *lf)
}
Dmsg1(dbglvl, "Close cfg file %s\n", lf->fname);
free(lf->fname);
+ free_memory(lf->line);
+ lf->line = NULL;
if (of) {
of->options = lf->options; /* preserve options */
memcpy(lf, of, sizeof(LEX));
@@ -170,7 +172,6 @@ LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error)
BPIPE *bpipe = NULL;
char *fname = bstrdup(filename);
-
if (fname[0] == '|') {
if ((bpipe = open_bpipe(fname+1, 0, "rb")) == NULL) {
free(fname);
@@ -206,6 +207,7 @@ LEX *lex_open_file(LEX *lf, const char *filename, LEX_ERROR_HANDLER *scan_error)
lf->fd = fd;
lf->bpipe = bpipe;
lf->fname = fname;
+ lf->line = get_memory(5000);
lf->state = lex_none;
lf->ch = L_EOL;
Dmsg1(dbglvl, "Return lex=%x\n", lf);
@@ -225,7 +227,7 @@ int lex_get_char(LEX *lf)
" You may have a open double quote without the closing double quote.\n"));
}
if (lf->ch == L_EOL) {
- if (bfgets(lf->line, MAXSTRING, lf->fd) == NULL) {
+ if (bfgets(lf->line, lf->fd) == NULL) {
lf->ch = L_EOF;
if (lf->next) {
lex_close_file(lf);
@@ -253,7 +255,6 @@ void lex_unget_char(LEX *lf)
} else {
lf->col_no--; /* Backup to re-read char */
}
-
}
@@ -585,6 +586,13 @@ lex_get_token(LEX *lf, int expect)
}
if (ch == '"') {
token = T_QUOTED_STRING;
+ /*
+ * Since we may be scanning a quoted list of names,
+ * we get the next character (a comma indicates another
+ * one), then we put it back for rescanning.
+ */
+ lex_get_char(lf);
+ lex_unget_char(lf);
lf->state = lex_none;
break;
}
diff --git a/bacula/src/lib/lex.h b/bacula/src/lib/lex.h
index 115a60a..b2a55c5 100644
--- a/bacula/src/lib/lex.h
+++ b/bacula/src/lib/lex.h
@@ -1,7 +1,7 @@
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 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.
@@ -32,8 +32,6 @@
*
* Kern Sibbald, MM
*
- * Version $Id$
- *
*/
#ifndef _LEX_H
@@ -106,7 +104,7 @@ typedef struct s_lex_context {
int options; /* scan options */
char *fname; /* filename */
FILE *fd; /* file descriptor */
- char line[MAXSTRING]; /* input line */
+ POOLMEM *line; /* input line */
char str[MAXSTRING]; /* string being scanned */
int str_len; /* length of string */
int line_no; /* file line number */
diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h
index 548799f..d04c847 100644
--- a/bacula/src/lib/protos.h
+++ b/bacula/src/lib/protos.h
@@ -1,7 +1,7 @@
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 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.
@@ -72,6 +72,7 @@ int delete_pid_file (char *dir, const char *progname, int port);
void drop (char *uid, char *gid, bool keep_readall_caps);
int bmicrosleep (int32_t sec, int32_t usec);
char *bfgets (char *s, int size, FILE *fd);
+char *bfgets (POOLMEM *&s, FILE *fd);
void make_unique_filename (POOLMEM **name, int Id, char *what);
#ifndef HAVE_STRTOLL
long long int strtoll (const char *ptr, char **endptr, int base);
hooks/post-receive
--
Bacula Community source
|