From: Kern Sibbald Date: Fri, 22 Dec 2006 15:40:16 +0000 (+0000) Subject: kes Fix code to check for two resources of same name. It forgot X-Git-Tag: Release-2.0.0~74 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cf7670cd92ef9af2ccb0fa113390f647afcf3427;p=bacula%2Fbacula kes Fix code to check for two resources of same name. It forgot to check the last entry. Fixes bug #734. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3843 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index 125a2a7ec6..a65dfb841d 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -310,15 +310,16 @@ void save_resource(int type, RES_ITEM *items, int pass) if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { - RES *next; - for (next=res_head[rindex]; next->next; next=next->next) { + RES *next, *last; + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->res_dir.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_dir.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.hdr.name); } diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 74db53766c..b32c412208 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -1375,7 +1375,7 @@ void save_resource(int type, RES_ITEM *items, int pass) error = true; break; default: - printf(_("Unknown resource type %d in save_resrouce.\n"), type); + printf(_("Unknown resource type %d in save_resource.\n"), type); error = true; break; } @@ -1388,20 +1388,21 @@ void save_resource(int type, RES_ITEM *items, int pass) Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type), res->res_dir.hdr.name, rindex); } else { - RES *next; + RES *next, *last; if (res->res_dir.hdr.name == NULL) { Emsg1(M_ERROR_TERM, 0, _("Name item is required in %s resource, but not found.\n"), resources[rindex]); } /* Add new res to end of chain */ - for (next=res_head[rindex]; next->next; next=next->next) { + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->res_dir.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_dir.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg4(900, _("Inserting %s res: %s index=%d pass=%d\n"), res_to_str(type), res->res_dir.hdr.name, rindex, pass); } diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 0bcb3129ce..416f9ecc84 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -423,16 +423,17 @@ void save_resource(int type, RES_ITEM *items, int pass) if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { - RES *next; + RES *next, *last; /* Add new res to end of chain */ - for (next=res_head[rindex]; next->next; next=next->next) { + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->res_dir.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_dir.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.hdr.name); } diff --git a/bacula/src/gnome2-console/console_conf.c b/bacula/src/gnome2-console/console_conf.c index 32fa0ea98b..e8c442a051 100644 --- a/bacula/src/gnome2-console/console_conf.c +++ b/bacula/src/gnome2-console/console_conf.c @@ -319,16 +319,17 @@ void save_resource(int type, RES_ITEM *items, int pass) if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { - RES *next; + RES *next, *last; /* Add new res to end of chain */ - for (next=res_head[rindex]; next->next; next=next->next) { + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->dir_res.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->dir_res.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->dir_res.hdr.name); } diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 80dd822092..ec5632a41a 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -659,16 +659,17 @@ void save_resource(int type, RES_ITEM *items, int pass) if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { - RES *next; + RES *next, *last; /* Add new res to end of chain */ - for (next=res_head[rindex]; next->next; next=next->next) { + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->res_dir.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second \"%s\" resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_dir.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.hdr.name); } diff --git a/bacula/src/tray-monitor/tray_conf.c b/bacula/src/tray-monitor/tray_conf.c index b87dbe9129..0623f29bf7 100644 --- a/bacula/src/tray-monitor/tray_conf.c +++ b/bacula/src/tray-monitor/tray_conf.c @@ -327,7 +327,7 @@ void save_resource(int type, RES_ITEM *items, int pass) size = sizeof(STORE); break; default: - printf(_("Unknown resource type %d in save_resrouce.\n"), type); + printf(_("Unknown resource type %d in save_resource.\n"), type); error = 1; size = 1; break; @@ -337,20 +337,21 @@ void save_resource(int type, RES_ITEM *items, int pass) res = (URES *)malloc(size); memcpy(res, &res_all, size); if (!res_head[rindex]) { - res_head[rindex] = (RES *)res; /* store first entry */ + res_head[rindex] = (RES *)res; /* store first entry */ Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type), res->res_monitor.hdr.name, rindex); } else { - RES *next; - /* Add new res to end of chain */ - for (next=res_head[rindex]; next->next; next=next->next) { - if (strcmp(next->name, res->res_monitor.hdr.name) == 0) { - Emsg2(M_ERROR_TERM, 0, + RES *next, *last; + /* Add new res to end of chain */ + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; + if (strcmp(next->name, res->res_monitor.hdr.name) == 0) { + Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), - resources[rindex].name, res->res_monitor.hdr.name); - } - } - next->next = (RES *)res; + resources[rindex].name, res->res_monitor.hdr.name); + } + } + last->next = (RES *)res; Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type), res->res_monitor.hdr.name, rindex, pass); } diff --git a/bacula/src/wx-console/console_conf.c b/bacula/src/wx-console/console_conf.c index 82bb8842d8..976794b231 100644 --- a/bacula/src/wx-console/console_conf.c +++ b/bacula/src/wx-console/console_conf.c @@ -320,15 +320,16 @@ void save_resource(int type, RES_ITEM *items, int pass) if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { - RES *next; - for (next=res_head[rindex]; next->next; next=next->next) { + RES *next, *last; + for (last=next=res_head[rindex]; next; next=next->next) { + last = next; if (strcmp(next->name, res->res_dir.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, wxString(_("Attempt to define second %s resource named \"%s\" is not permitted.\n")).mb_str(*wxConvCurrent), resources[rindex].name, res->res_dir.hdr.name); } } - next->next = (RES *)res; + last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.hdr.name); } diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index dfc635a9b7..e247791827 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -2,6 +2,8 @@ General: 22Dec06 +kes Fix code to check for two resources of same name. It forgot + to check the last entry. Fixes bug #734. kes Apply scanvolume patch from Richard Mortimer that fixes bug #738. kes Apply Eric's patch for recycling the Scratch pool.