Hello community, here is the log from the commit of package snapper for openSUSE:Factory checked in at 2013-07-29 17:51:09 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/snapper (Old) and /work/SRC/openSUSE:Factory/.snapper.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "snapper" Changes: -------- --- /work/SRC/openSUSE:Factory/snapper/snapper.changes 2013-07-18 18:08:35.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.snapper.new/snapper.changes 2013-07-29 17:51:11.000000000 +0200 @@ -1,0 +2,5 @@ +Thu Jul 25 14:40:31 CEST 2013 - [email protected] + +- allow to change config via DBus and with command line tool + +------------------------------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ snapper-0.1.5.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/client/commands.cc new/snapper-0.1.5/client/commands.cc --- old/snapper-0.1.5/client/commands.cc 2013-01-22 11:46:31.000000000 +0100 +++ new/snapper-0.1.5/client/commands.cc 2013-07-25 15:41:50.000000000 +0200 @@ -64,6 +64,19 @@ void +command_set_xconfig(DBus::Connection& conn, const string& config_name, + const map<string, string>& raw) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "SetConfig"); + + DBus::Hoho hoho(call); + hoho << config_name << raw; + + conn.send_with_reply_and_block(call); +} + + +void command_create_xconfig(DBus::Connection& conn, const string& config_name, const string& subvolume, const string& fstype, const string& template_name) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/client/commands.h new/snapper-0.1.5/client/commands.h --- old/snapper-0.1.5/client/commands.h 2013-01-22 11:46:31.000000000 +0100 +++ new/snapper-0.1.5/client/commands.h 2013-07-25 15:41:50.000000000 +0200 @@ -40,6 +40,10 @@ command_get_xconfig(DBus::Connection& conn, const string& config_name); void +command_set_xconfig(DBus::Connection& conn, const string& config_name, + const map<string, string>& raw); + +void command_create_xconfig(DBus::Connection& conn, const string& config_name, const string& subvolume, const string& fstype, const string& template_name); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/client/snapper.cc new/snapper-0.1.5/client/snapper.cc --- old/snapper-0.1.5/client/snapper.cc 2013-04-19 14:50:39.000000000 +0200 +++ new/snapper-0.1.5/client/snapper.cc 2013-07-25 15:41:50.000000000 +0200 @@ -25,6 +25,8 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> #include <iostream> #include <boost/algorithm/string.hpp> @@ -34,6 +36,7 @@ #include <snapper/AsciiFile.h> #include <snapper/SystemCmd.h> #include <snapper/SnapperDefines.h> +#include <snapper/XAttributes.h> #include "utils/text.h" #include "utils/Table.h" @@ -42,13 +45,6 @@ #include "commands.h" #include "cleanup.h" -#ifdef ENABLE_XATTRS - #include <sys/types.h> - #include <sys/stat.h> - #include <fcntl.h> - - #include <snapper/XAttributes.h> -#endif using namespace snapper; using namespace std; @@ -325,6 +321,94 @@ void +help_get_config() +{ + cout << _(" Get config:") << endl + << _("\tsnapper get-config") << endl + << endl; +} + + +void +command_get_config(DBus::Connection& conn) +{ + getopts.parse("get-config", GetOpts::no_options); + if (getopts.hasArgs()) + { + cerr << _("Command 'get-config' does not take arguments.") << endl; + exit(EXIT_FAILURE); + } + + Table table; + + TableHeader header; + header.add(_("Key")); + header.add(_("Value")); + table.setHeader(header); + + XConfigInfo ci = command_get_xconfig(conn, config_name); + + for (map<string, string>::const_iterator it = ci.raw.begin(); it != ci.raw.end(); ++it) + { + TableRow row; + row.add(it->first); + row.add(it->second); + table.add(row); + } + + cout << table; +} + + +void +help_set_config() +{ + cout << _(" Set config:") << endl + << _("\tsnapper set-config <configdata>") << endl + << endl; +} + + +void +command_set_config(DBus::Connection& conn) +{ + getopts.parse("set-config", GetOpts::no_options); + if (!getopts.hasArgs()) + { + cerr << _("Command 'set-config' needs at least one argument.") << endl; + exit(EXIT_FAILURE); + } + + map<string, string> raw; + + while (getopts.hasArgs()) + { + string arg = getopts.popArg(); + + string::size_type pos = arg.find("="); + if (pos == string::npos) + { + cerr << _("Invalid configdata.") << endl; + exit(EXIT_FAILURE); + } + + string key = boost::trim_copy(arg.substr(0, pos)); + string value = boost::trim_copy(arg.substr(pos + 1)); + + if (key.empty()) + { + cerr << _("Invalid configdata.") << endl; + exit(EXIT_FAILURE); + } + + raw[key] = value; + } + + command_set_xconfig(conn, config_name, raw); +} + + +void help_list() { cout << _(" List snapshots:") << endl @@ -1114,6 +1198,7 @@ #ifdef ENABLE_XATTRS + void help_xa_diff() { @@ -1171,6 +1256,7 @@ } } } + #endif @@ -1225,6 +1311,8 @@ help_list_configs(); help_create_config(); help_delete_config(); + help_get_config(); + help_set_config(); help_list(); help_create(); help_modify(); @@ -1254,6 +1342,8 @@ cmds["list-configs"] = command_list_configs; cmds["create-config"] = command_create_config; cmds["delete-config"] = command_delete_config; + cmds["get-config"] = command_get_config; + cmds["set-config"] = command_set_config; cmds["list"] = command_list; cmds["create"] = command_create; cmds["modify"] = command_modify; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/doc/dbus-protocol.txt new/snapper-0.1.5/doc/dbus-protocol.txt --- old/snapper-0.1.5/doc/dbus-protocol.txt 2013-01-24 15:41:32.000000000 +0100 +++ new/snapper-0.1.5/doc/dbus-protocol.txt 2013-07-25 15:41:50.000000000 +0200 @@ -1,6 +1,7 @@ method ListConfigs method GetConfig config-name +method SetConfig config-name configdata method CreateConfig config-name subvolume fstype template-name diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/doc/snapper.xml.in new/snapper-0.1.5/doc/snapper.xml.in --- old/snapper-0.1.5/doc/snapper.xml.in 2013-07-09 14:33:52.000000000 +0200 +++ new/snapper-0.1.5/doc/snapper.xml.in 2013-07-25 15:41:50.000000000 +0200 @@ -262,6 +262,24 @@ </varlistentry> <varlistentry> + <term><option>get-config</option></term> + <listitem> + <para>Displays the settings of the configuration.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>set-config</option> <replaceable>configdata</replaceable></term> + <listitem> + <para>Changes the settings of the configuration. The settings + <replaceable>configdata</replaceable> are a list of key-value-pairs separated + by spaces and the key and value must be separated by an equal sign, + e.g. "NUMBER_CLEANUP=yes NUMBER_LIMIT=10". The value of SUBVOLUME and FSTYPE + cannot be changed.</para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>list [options]</option></term> <listitem> <para>List snapshots.</para> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/pam/pam_snapper.c new/snapper-0.1.5/pam/pam_snapper.c --- old/snapper-0.1.5/pam/pam_snapper.c 2013-06-25 09:15:53.000000000 +0200 +++ new/snapper-0.1.5/pam/pam_snapper.c 2013-07-26 11:06:49.000000000 +0200 @@ -27,7 +27,7 @@ * Add the following line to /etc/pam.d/common-session: * "session optional pam_snapper.so" * - * See "man pam_snapper" and "map snapper" for more information. + * See "man pam_snapper" and "man snapper" for more information. * * @section Related Projects * diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/server/Client.cc new/snapper-0.1.5/server/Client.cc --- old/snapper-0.1.5/server/Client.cc 2013-06-21 16:06:44.000000000 +0200 +++ new/snapper-0.1.5/server/Client.cc 2013-07-25 15:41:50.000000000 +0200 @@ -177,6 +177,10 @@ " <arg name='config-name' type='s'/>\n" " </signal>\n" + " <signal name='ConfigModified'>\n" + " <arg name='config-name' type='s'/>\n" + " </signal>\n" + " <signal name='ConfigDeleted'>\n" " <arg name='config-name' type='s'/>\n" " </signal>\n" @@ -205,6 +209,11 @@ " <arg name='data' type='(ssa{ss})' direction='out'/>\n" " </method>\n" + " <method name='SetConfig'>\n" + " <arg name='config-name' type='s' direction='in'/>\n" + " <arg name='data' type='(a{ss})' direction='in'/>\n" + " </method>\n" + " <method name='CreateConfig'>\n" " <arg name='config-name' type='s' direction='in'/>\n" " <arg name='subvolume' type='s' direction='in'/>\n" @@ -432,6 +441,18 @@ void +Client::signal_config_modified(DBus::Connection& conn, const string& config_name) +{ + DBus::MessageSignal msg(PATH, INTERFACE, "ConfigModified"); + + DBus::Hoho hoho(msg); + hoho << config_name; + + conn.send(msg); +} + + +void Client::signal_config_deleted(DBus::Connection& conn, const string& config_name) { DBus::MessageSignal msg(PATH, INTERFACE, "ConfigDeleted"); @@ -501,7 +522,7 @@ DBus::Hoho hoho(reply); hoho.open_array(DBus::TypeInfo<ConfigInfo>::signature); for (MetaSnappers::const_iterator it = meta_snappers.begin(); it != meta_snappers.end(); ++it) - hoho << it->config_info; + hoho << it->getConfigInfo(); hoho.close_array(); conn.send(reply); @@ -527,9 +548,36 @@ DBus::MessageMethodReturn reply(msg); DBus::Hoho hoho(reply); - hoho << it->config_info; + hoho << it->getConfigInfo(); + + conn.send(reply); +} + + +void +Client::set_config(DBus::Connection& conn, DBus::Message& msg) +{ + string config_name; + + DBus::Hihi hihi(msg); + map<string, string> raw; + hihi >> config_name >> raw; + + y2deb("SetConfig config_name:" << config_name << " raw:" << raw); + + boost::shared_lock<boost::shared_mutex> lock(big_mutex); + + MetaSnappers::iterator it = meta_snappers.find(config_name); + + check_permission(conn, msg); + + it->setConfigInfo(raw); + + DBus::MessageMethodReturn reply(msg); conn.send(reply); + + signal_config_modified(conn, config_name); } @@ -886,7 +934,7 @@ snap2->flushInfo(); bool tmp; - if (it->config_info.getValue("BACKGROUND_COMPARISON", tmp) && tmp) + if (it->getConfigInfo().getValue("BACKGROUND_COMPARISON", tmp) && tmp) backgrounds.add_task(it, snap1, snap2); DBus::MessageMethodReturn reply(msg); @@ -1222,6 +1270,8 @@ create_config(conn, msg); else if (msg.is_method_call(INTERFACE, "GetConfig")) get_config(conn, msg); + else if (msg.is_method_call(INTERFACE, "SetConfig")) + set_config(conn, msg); else if (msg.is_method_call(INTERFACE, "DeleteConfig")) delete_config(conn, msg); else if (msg.is_method_call(INTERFACE, "LockConfig")) @@ -1338,6 +1388,11 @@ DBus::MessageError reply(msg, "error.unknown_file", DBUS_ERROR_FAILED); conn.send(reply); } + catch (const InvalidConfigdataException& e) + { + DBus::MessageError reply(msg, "error.invalid_configdata", DBUS_ERROR_FAILED); + conn.send(reply); + } catch (const InvalidUserdataException& e) { DBus::MessageError reply(msg, "error.invalid_userdata", DBUS_ERROR_FAILED); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/server/Client.h new/snapper-0.1.5/server/Client.h --- old/snapper-0.1.5/server/Client.h 2013-02-20 11:36:31.000000000 +0100 +++ new/snapper-0.1.5/server/Client.h 2013-07-25 15:41:50.000000000 +0200 @@ -72,6 +72,7 @@ void check_snapshot_in_use(const MetaSnapper& meta_snapper, unsigned int number) const; void signal_config_created(DBus::Connection& conn, const string& config_name); + void signal_config_modified(DBus::Connection& conn, const string& config_name); void signal_config_deleted(DBus::Connection& conn, const string& config_name); void signal_snapshot_created(DBus::Connection& conn, const string& config_name, unsigned int num); @@ -82,6 +83,7 @@ void list_configs(DBus::Connection& conn, DBus::Message& msg); void get_config(DBus::Connection& conn, DBus::Message& msg); + void set_config(DBus::Connection& conn, DBus::Message& msg); void create_config(DBus::Connection& conn, DBus::Message& msg); void delete_config(DBus::Connection& conn, DBus::Message& msg); void lock_config(DBus::Connection& conn, DBus::Message& msg); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/server/MetaSnapper.cc new/snapper-0.1.5/server/MetaSnapper.cc --- old/snapper-0.1.5/server/MetaSnapper.cc 2013-06-21 16:06:44.000000000 +0200 +++ new/snapper-0.1.5/server/MetaSnapper.cc 2013-07-25 15:41:50.000000000 +0200 @@ -158,9 +158,40 @@ } -MetaSnapper::MetaSnapper(const ConfigInfo& config_info) +MetaSnapper::MetaSnapper(ConfigInfo& config_info) : config_info(config_info), snapper(NULL) { + set_permissions(); +} + + +MetaSnapper::~MetaSnapper() +{ + delete snapper; +} + + +void +MetaSnapper::setConfigInfo(const map<string, string>& raw) +{ + if (raw.find("SUBVOLUME") != raw.end() || raw.find("FSTYPE") != raw.end()) + throw InvalidConfigdataException(); + + for (map<string, string>::const_iterator it = raw.begin(); it != raw.end(); ++it) + config_info.setValue(it->first, it->second); + + config_info.save(); + + if (raw.find("ALLOW_USERS") != raw.end() || raw.find("ALLOW_GROUPS") != raw.end()) + set_permissions(); +} + + +void +MetaSnapper::set_permissions() +{ + uids.clear(); + vector<string> users; if (config_info.getValue("ALLOW_USERS", users)) { @@ -188,12 +219,6 @@ } -MetaSnapper::~MetaSnapper() -{ - delete snapper; -} - - Snapper* MetaSnapper::getSnapper() { @@ -229,7 +254,7 @@ { list<ConfigInfo> config_infos = Snapper::getConfigs(); - for (list<ConfigInfo>::const_iterator it = config_infos.begin(); it != config_infos.end(); ++it) + for (list<ConfigInfo>::iterator it = config_infos.begin(); it != config_infos.end(); ++it) { #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) entries.emplace_back(*it); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/server/MetaSnapper.h new/snapper-0.1.5/server/MetaSnapper.h --- old/snapper-0.1.5/server/MetaSnapper.h 2013-06-21 16:06:44.000000000 +0200 +++ new/snapper-0.1.5/server/MetaSnapper.h 2013-07-25 15:41:50.000000000 +0200 @@ -86,12 +86,13 @@ { public: - MetaSnapper(const ConfigInfo& config_info); + MetaSnapper(ConfigInfo& config_info); ~MetaSnapper(); const string& configName() const { return config_info.getConfigName(); } - const ConfigInfo config_info; + const ConfigInfo& getConfigInfo() const { return config_info; } + void setConfigInfo(const map<string, string>& raw); vector<uid_t> uids; @@ -103,6 +104,10 @@ private: + void set_permissions(); + + ConfigInfo config_info; + Snapper* snapper; }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/snapper/AsciiFile.cc new/snapper-0.1.5/snapper/AsciiFile.cc --- old/snapper-0.1.5/snapper/AsciiFile.cc 2013-06-21 16:06:44.000000000 +0200 +++ new/snapper-0.1.5/snapper/AsciiFile.cc 2013-07-25 15:41:50.000000000 +0200 @@ -161,6 +161,14 @@ void + SysconfigFile::save() + { + if (modified && AsciiFile::save()) + modified = false; + } + + + void SysconfigFile::setValue(const string& key, bool value) { setValue(key, value ? "yes" : "no"); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/snapper/AsciiFile.h new/snapper-0.1.5/snapper/AsciiFile.h --- old/snapper-0.1.5/snapper/AsciiFile.h 2013-06-21 10:49:06.000000000 +0200 +++ new/snapper-0.1.5/snapper/AsciiFile.h 2013-07-25 15:41:50.000000000 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) [2004-2012] Novell, Inc. + * Copyright (c) [2004-2013] Novell, Inc. * * All Rights Reserved. * @@ -94,6 +94,8 @@ SysconfigFile(const string& name) : AsciiFile(name), modified(false) {} ~SysconfigFile() { if (modified) save(); } + void save(); + void setValue(const string& key, bool value); bool getValue(const string& key, bool& value) const; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/snapper-0.1.5/snapper/Snapper.h new/snapper-0.1.5/snapper/Snapper.h --- old/snapper-0.1.5/snapper/Snapper.h 2013-06-21 16:06:44.000000000 +0200 +++ new/snapper-0.1.5/snapper/Snapper.h 2013-07-25 15:41:50.000000000 +0200 @@ -68,6 +68,12 @@ virtual const char* what() const throw() { return "invalid config"; } }; + struct InvalidConfigdataException : public SnapperException + { + explicit InvalidConfigdataException() throw() {} + virtual const char* what() const throw() { return "invalid configdata"; } + }; + struct InvalidUserdataException : public SnapperException { explicit InvalidUserdataException() throw() {} -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
