}
+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)
XConfigInfo
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);
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <snapper/AsciiFile.h>
#include <snapper/SystemCmd.h>
#include <snapper/SnapperDefines.h>
+#include <snapper/XAttributes.h>
#include "utils/text.h"
#include "utils/Table.h"
#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;
}
+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()
{
#ifdef ENABLE_XATTRS
+
void
help_xa_diff()
{
}
}
}
+
#endif
help_list_configs();
help_create_config();
help_delete_config();
+ help_get_config();
+ help_set_config();
help_list();
help_create();
help_modify();
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;
method ListConfigs
method GetConfig config-name
+method SetConfig config-name configdata
method CreateConfig config-name subvolume fstype template-name
</listitem>
</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>
+-------------------------------------------------------------------
+Thu Jul 25 14:40:31 CEST 2013 - aschnell@suse.de
+
+- allow to change config via DBus and with command line tool
+
-------------------------------------------------------------------
Tue Jul 09 14:00:16 CEST 2013 - aschnell@suse.de
" <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"
" <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"
}
+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::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);
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);
}
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);
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"))
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);
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);
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);
}
-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))
{
}
-MetaSnapper::~MetaSnapper()
-{
- delete snapper;
-}
-
-
Snapper*
MetaSnapper::getSnapper()
{
{
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);
{
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;
private:
+ void set_permissions();
+
+ ConfigInfo config_info;
+
Snapper* snapper;
};
}
+ void
+ SysconfigFile::save()
+ {
+ if (modified && AsciiFile::save())
+ modified = false;
+ }
+
+
void
SysconfigFile::setValue(const string& key, bool value)
{
/*
- * Copyright (c) [2004-2012] Novell, Inc.
+ * Copyright (c) [2004-2013] Novell, Inc.
*
* All Rights Reserved.
*
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;
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() {}