Skip to content

Commit

Permalink
Merge pull request #352 from bareos/dev/sduehr/master/fix-restoreobje…
Browse files Browse the repository at this point in the history
…cts-sqlite

Fix restore objects with sqlite
  • Loading branch information
arogge committed Nov 29, 2019
2 parents 545153f + 58bab11 commit 4eb5c96
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 10 deletions.
15 changes: 8 additions & 7 deletions core/src/cats/cats.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -206,12 +206,9 @@ void BareosDb::EscapeString(JobControlRecord* jcr,
*/
char* BareosDb::EscapeObject(JobControlRecord* jcr, char* old, int len)
{
int length;
int MaxLength;

MaxLength = (len * 4) / 3;
const int MaxLength = Base64LengthUnpadded(len) + 1;
esc_obj = CheckPoolMemorySize(esc_obj, MaxLength + 1);
length = BinToBase64(esc_obj, MaxLength, old, len, true);
const int length = BinToBase64(esc_obj, MaxLength, old, len, true);
esc_obj[length] = '\0';

return esc_obj;
Expand All @@ -234,7 +231,11 @@ void BareosDb::UnescapeObject(JobControlRecord* jcr,
}

dest = CheckPoolMemorySize(dest, expected_len + 1);
Base64ToBin(dest, expected_len + 1, from, strlen(from));
/*
* Note: Base64ToBin() does not check the expected length correctly,
* so we must add 2 to make sure it works.
*/
Base64ToBin(dest, expected_len + 2, from, strlen(from));
*dest_len = expected_len;
dest[expected_len] = '\0';
}
Expand Down
21 changes: 20 additions & 1 deletion core/src/lib/base64.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
Copyright (C) 2016-2016 Bareos GmbH & Co. KG
Copyright (C) 2016-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -219,3 +219,22 @@ int Base64ToBin(char* dest, int dest_size, char* src, int srclen)

return (bufout - (uint8_t*)dest);
}

/**
* Calculate the correct unpadded base64 length for a given length
* of an unencoded string
*
* Returns: Length of unpadded base64
*/
int Base64LengthUnpadded(int source_length)
{
if (source_length == 0) { return 0; }

int quotient = source_length / 3;
const int remainder = source_length % 3;
if (remainder > 0) { ++quotient; }
int unpadded_length = 4 * quotient;
if (remainder > 0) { unpadded_length -= (3 - remainder); }

return unpadded_length;
}
3 changes: 2 additions & 1 deletion core/src/lib/base64.h
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
Copyright (C) 2016-2016 Bareos GmbH & Co. KG
Copyright (C) 2016-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -36,3 +36,4 @@ int ToBase64(int64_t value, char* where);
int FromBase64(int64_t* value, char* where);
int BinToBase64(char* buf, int buflen, char* bin, int binlen, bool compatible);
int Base64ToBin(char* dest, int destlen, char* src, int srclen);
int Base64LengthUnpadded(int source_length);
Expand Up @@ -5,6 +5,6 @@ FileSet {
Options {
signature = MD5
}
Plugin = "python:module_path=@python_plugin_module_src_dir@/filed:module_name=bareos-fd-local-fileset:filename=@tmpdir@/file-list"
Plugin = "python:module_path=@python_plugin_module_src_test_dir@:module_name=bareos-fd-local-fileset-with-restoreobjects:filename=@tmpdir@/file-list"
}
}

0 comments on commit 4eb5c96

Please sign in to comment.