Bacula-users

Re: [Bacula-users] atoi and volume name/media name ambiguity (Was: Re: Bug / RFE)

2009-02-06 13:15:37
Subject: Re: [Bacula-users] atoi and volume name/media name ambiguity (Was: Re: Bug / RFE)
From: Josh Fisher <jfisher AT pvct DOT com>
To: "Bailey, Scott" <scott.bailey AT eds DOT com>
Date: Fri, 06 Feb 2009 13:13:18 -0500
Bailey, Scott wrote:
> I second the notion that numeric volume labels are in widespread use.
> Maybe those barcode manufacturers gave special discounts to people who
> ordered ranges without alphabetic characters in them. :-)
>
> My suggested kludge actually would be the opposite of what others have
> suggested; namely, I would assume first that user input actually is a
> literal label and consider it as a potential MediaId only if no match is
> found.
>   

First, note that Bacula does not use the atoi() function to convert the 
string, but rather its own str_to_int64() function. I would imagine this 
is in order to handle the input of 64-bit values on 32-bit machines.

Since it is possible to have a numeric VolumeLabel, it simply is not 
possible to distinguish between MediaId and VolumeLabel when given a 
string. For example, VolumeLabel "1234" and MediaId 1234 are 
indistinguishable given the string "1234". When using strictly numeric 
VolumeLabels, it is very likely that a volume with VolumeLabel "1234" 
and a different volume with MediaId 1234 both exist at the same time. 
One way to deal with this would be to allow quoting for a VolumeLabel 
entry. Another way is to force the user to include a leading '+' when 
entering a MediaId and considering strings that do not begin with a '+' 
to be a VolumeLabel. Neither way is foolproof when using strictly 
numeric volume labels. Both ways are more cumbersome, break existing 
scripts (or anything that invokes bconsole to send commands to Dir), and 
likely are not needed by the majority of people.

Forcing a leading '+' is a simple one line change. I would in no way 
consider this a bug fix, but for those who want to consider a numeric 
string a VolumeLabel unless a leading '+' is entered, a patch against 
the ua_select.c in trunk (as of today) is below.

--- bacula/src/dird/ua_select.c 2009-02-06 09:19:28.000000000 -0500
+++ ua_select.c 2009-02-06 11:57:22.000000000 -0500
@@ -573,7 +573,7 @@
       if (!get_cmd(ua, _("Enter MediaId or Volume name: "))) {
          return 0;
       }
-      if (is_a_number(ua->cmd)) {
+      if (ua->cmd[0] == '+' && is_a_number(ua->cmd)) {
          mr->MediaId = str_to_int64(ua->cmd);
       } else {
          bstrncpy(mr->VolumeName, ua->cmd, sizeof(mr->VolumeName));

Cheers,

Josh Fisher

> Further, although you can't do much for existing installations, we could
> reduce ambiguity by starting with MediaId 1000000 (rather than 1) -- so
> that valid MediaIds cannot be encoded in a six-character ANSI label.
> That's not a total cure, I've not seen longer labels in our
> environments.
>
> Actually, suitably desperate individuals probably could perform some SQL
> magic on their database now to renumber MediaIds to a less dangerous
> range, and avoid the risk of bacula doing something you did not intend.
> That's still no fix for mangling your input and refusing to do what you
> really wanted. ;-)
>
> Cheers,
>
> Scott Bailey
> scott.bailey AT eds DOT com
>
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> _______________________________________________
> Bacula-users mailing list
> Bacula-users AT lists.sourceforge DOT net
> https://lists.sourceforge.net/lists/listinfo/bacula-users
>   

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>