Skip to content

Commit

Permalink
- allow whitespace in ALLOW_USERS and ALLOW_GROUPS
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Jun 21, 2013
1 parent 033edcf commit 81c7a5f
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

SUBDIRS = snapper examples dbus server client scripts pam data doc po \
testsuite-real testsuite-cmp
testsuite testsuite-real testsuite-cmp

AUTOMAKE_OPTIONS = foreign dist-bzip2 no-dist-gzip

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ AC_OUTPUT(
doc/snapperd.xml:doc/snapperd.xml.in
doc/pam_snapper.xml:doc/pam_snapper.xml.in
po/Makefile
testsuite/Makefile
testsuite-real/Makefile
testsuite-cmp/Makefile
package/snapper.spec:snapper.spec.in
Expand Down
5 changes: 5 additions & 0 deletions package/snapper.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Fri Jun 21 15:50:22 CEST 2013 - aschnell@suse.de

- allow whitespace in ALLOW_USERS and ALLOW_GROUPS

-------------------------------------------------------------------
Fri May 31 17:35:33 CEST 2013 - aschnell@suse.de

Expand Down
3 changes: 3 additions & 0 deletions snapper.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ install -D -m 644 data/sysconfig.snapper $RPM_BUILD_ROOT/etc/sysconfig/snapper

%{find_lang} snapper

%check
make check

%clean
rm -rf "$RPM_BUILD_ROOT"

Expand Down
40 changes: 34 additions & 6 deletions snapper/AsciiFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ AsciiFile::save()
void
SysconfigFile::setValue(const string& key, const vector<string>& values)
{
setValue(key, boost::join(values, " "));
string tmp;
for (vector<string>::const_iterator it = values.begin(); it != values.end(); ++it)
{
if (it != values.begin())
tmp.append(" ");
tmp.append(boost::replace_all_copy(*it, " ", "\\ "));
}
setValue(key, tmp);
}


Expand All @@ -224,12 +231,33 @@ AsciiFile::save()
if (!getValue(key, tmp))
return false;

boost::trim(tmp, locale::classic());
values.clear();

if (!tmp.empty())
boost::split(values, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
else
values.clear();
string buffer;

for (string::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
{
switch (*it)
{
case ' ':
if (!buffer.empty())
values.push_back(buffer);
buffer.clear();
continue;

case '\\':
if (++it == tmp.end())
return false;
if (*it != '\\' && *it != ' ')
return false;
break;
}

buffer.push_back(*it);
}

if (!buffer.empty())
values.push_back(buffer);

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions testsuite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
sysconfig-get1
21 changes: 21 additions & 0 deletions testsuite/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Makefile.am for snapper/testsuite
#

CXXFLAGS += -std=gnu++0x

INCLUDES = -I$(top_srcdir)

LDADD = ../snapper/libsnapper.la

noinst_SCRIPTS = run-all

noinst_PROGRAMS = sysconfig-get1

sysconfig_get1_SOURCES = sysconfig-get1.cc common.h

EXTRA_DIST = $(noinst_SCRIPTS) sysconfig-get1.txt

check:
./run-all

44 changes: 44 additions & 0 deletions testsuite/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#include <string>

using namespace std;


template <typename Type> void
check_failure(const char* str, Type actual, Type expected, const char* file,
int line, const char* func)
{
std::cerr << file << ":" << line << ": \"" << func << "\"" << std::endl;
std::cerr << "check \"" << str << "\"" << " failed. expected " << expected
<< ", actual " << actual << "." << std::endl;

exit(EXIT_FAILURE);
}


#define check_true(expr) \
do { \
bool actual = (expr); \
if (!actual) \
check_failure(#expr, actual, true, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
} while (0)


#define check_zero(expr) \
do { \
int actual = (expr); \
if (actual != 0) \
check_failure(#expr, actual, 0, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
} while (0)


#define check_equal(expr, expected) \
do { \
typeof (expected) actual = (expr); \
if (actual != expected) \
check_failure(#expr, actual, expected, __FILE__, __LINE__, \
__PRETTY_FUNCTION__); \
} while (0)

22 changes: 22 additions & 0 deletions testsuite/run-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash


function run()
{
cmd=$1

echo
echo "*** running $cmd ***"
echo

./$cmd

if [ $? != 0 ] ; then
echo "failed"
exit 1
fi
}


run sysconfig-get1

48 changes: 48 additions & 0 deletions testsuite/sysconfig-get1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

#include <stdlib.h>
#include <iostream>
#include <boost/algorithm/string.hpp>

#include "common.h"

#include <snapper/AsciiFile.h>

using namespace snapper;


int
main()
{
SysconfigFile s("sysconfig-get1.txt");

string tmp_string;

check_true(s.getValue("S1", tmp_string));
check_equal(tmp_string, string("hello"));

bool tmp_bool;

check_true(s.getValue("B1", tmp_bool));
check_equal(tmp_bool, true);

check_true(s.getValue("B2", tmp_bool));
check_equal(tmp_bool, false);

vector<string> tmp_vector;

check_true(s.getValue("V1", tmp_vector));
check_equal(boost::join(tmp_vector, "-"), string("one word"));

check_true(s.getValue("V2", tmp_vector));
check_equal(boost::join(tmp_vector, "-"), string("two-words"));

check_true(s.getValue("V3", tmp_vector));
check_equal(boost::join(tmp_vector, "-"), string("now-three-words"));

check_true(s.getValue("V4", tmp_vector));
check_equal(boost::join(tmp_vector, "-"), string("c:\\io.sys"));

check_true(!s.getValue("V5", tmp_vector));

exit(EXIT_SUCCESS);
}
12 changes: 12 additions & 0 deletions testsuite/sysconfig-get1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

S1="hello"

B1="yes"
B2="no"

V1="one\ word"
V2="two words"
V3=" now three words "
V4="c:\\io.sys"
V5="error\"

0 comments on commit 81c7a5f

Please sign in to comment.