/*
* Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) [2016-2021] SUSE LLC
+ * Copyright (c) [2016-2022] SUSE LLC
*
* All Rights Reserved.
*
boost::shared_mutex big_mutex;
-Client::Client(const string& name, const Clients& clients)
- : name(name), clients(clients)
+Client::Client(const string& name, uid_t uid, const Clients& clients)
+ : name(name), uid(uid), clients(clients)
{
}
void
Client::check_permission(DBus::Connection& conn, DBus::Message& msg) const
{
- unsigned long uid = conn.get_unix_userid(msg);
+ // Check if the uid of the dbus-user is root.
if (uid == 0)
return;
Client::check_permission(DBus::Connection& conn, DBus::Message& msg,
const MetaSnapper& meta_snapper) const
{
- unsigned long uid = conn.get_unix_userid(msg);
-
// Check if the uid of the dbus-user is root.
if (uid == 0)
return;
// Check if the uid of the dbus-user is included in the allowed uids.
- if (contains(meta_snapper.uids, uid))
+ if (contains(meta_snapper.get_allowed_uids(), uid))
return;
string username;
if (get_uid_username_gid(uid, username, gid))
{
// Check if the primary gid of the dbus-user is included in the allowed gids.
- if (contains(meta_snapper.gids, gid))
+ if (contains(meta_snapper.get_allowed_gids(), gid))
return;
vector<gid_t> gids = getgrouplist(username.c_str(), gid);
// Check if any (primary or secondary) gid of the dbus-user is included in the allowed
// gids.
for (vector<gid_t>::const_iterator it = gids.begin(); it != gids.end(); ++it)
- if (contains(meta_snapper.gids, *it))
+ if (contains(meta_snapper.get_allowed_gids(), *it))
return;
}
MetaSnappers::iterator it = meta_snappers.find(config_name);
check_permission(conn, msg, *it);
- scd.uid = conn.get_unix_userid(msg);
+ scd.uid = uid;
Snapper* snapper = it->getSnapper();
MetaSnappers::iterator it = meta_snappers.find(config_name);
check_permission(conn, msg, *it);
- scd.uid = conn.get_unix_userid(msg);
+ scd.uid = uid;
Snapper* snapper = it->getSnapper();
MetaSnappers::iterator it = meta_snappers.find(config_name);
check_permission(conn, msg, *it);
- scd.uid = conn.get_unix_userid(msg);
+ scd.uid = uid;
Snapper* snapper = it->getSnapper();
MetaSnappers::iterator it = meta_snappers.find(config_name);
check_permission(conn, msg, *it);
- scd.uid = conn.get_unix_userid(msg);
+ scd.uid = uid;
Snapper* snapper = it->getSnapper();
MetaSnappers::iterator it = meta_snappers.find(config_name);
check_permission(conn, msg, *it);
- scd.uid = conn.get_unix_userid(msg);
+ scd.uid = uid;
Snapper* snapper = it->getSnapper();
Snapshots& snapshots = snapper->getSnapshots();
for (Clients::const_iterator it = clients.begin(); it != clients.end(); ++it)
{
std::ostringstream s;
- s << " name:'" << it->name << "'";
+ s << " name:'" << it->name << "', uid:" << it->uid;
if (&*it == this)
s << ", myself";
if (it->zombie)
Clients::iterator
-Clients::add(const string& name)
+Clients::add(const string& name, uid_t uid)
{
assert(find(name) == entries.end());
- entries.emplace_back(name, *this);
+ entries.emplace_back(name, uid, *this);
return --entries.end();
}
/*
* Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) [2016,2018] SUSE LLC
+ * Copyright (c) [2016-2022] SUSE LLC
*
* All Rights Reserved.
*
void dispatch(DBus::Connection& conn, DBus::Message& msg);
- Client(const string& name, const Clients& clients);
+ Client(const string& name, uid_t uid, const Clients& clients);
~Client();
list<Comparison*>::iterator find_comparison(Snapper* snapper, unsigned int number1,
void remove_mount(const string& config_name, unsigned int number);
const string name;
+ const uid_t uid;
list<Comparison*> comparisons;
iterator find(const string& name);
- iterator add(const string& name);
+ iterator add(const string& name, uid_t uid);
+
void remove_zombies();
bool has_zombies() const;
/*
* Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) 2018 SUSE LLC
+ * Copyright (c) [2018-2022] SUSE LLC
*
* All Rights Reserved.
*
void
MetaSnapper::set_permissions()
{
- uids.clear();
+ allowed_uids.clear();
vector<string> users;
if (config_info.getValue(KEY_ALLOW_USERS, users))
{
- for (vector<string>::const_iterator it = users.begin(); it != users.end(); ++it)
+ for (const string& user : users)
{
uid_t tmp;
- if (get_user_uid(it->c_str(), tmp))
- uids.push_back(tmp);
+ if (get_user_uid(user.c_str(), tmp))
+ allowed_uids.push_back(tmp);
}
}
- sort(uids.begin(), uids.end());
- uids.erase(unique(uids.begin(), uids.end()), uids.end());
+ sort(allowed_uids.begin(), allowed_uids.end());
+ allowed_uids.erase(unique(allowed_uids.begin(), allowed_uids.end()), allowed_uids.end());
- gids.clear();
+ allowed_gids.clear();
vector<string> groups;
if (config_info.getValue(KEY_ALLOW_GROUPS, groups))
{
- for (vector<string>::const_iterator it = groups.begin(); it != groups.end(); ++it)
+ for (const string& group : groups)
{
gid_t tmp;
- if (get_group_gid(it->c_str(), tmp))
- gids.push_back(tmp);
+ if (get_group_gid(group.c_str(), tmp))
+ allowed_gids.push_back(tmp);
}
}
- sort(gids.begin(), gids.end());
- gids.erase(unique(gids.begin(), gids.end()), gids.end());
+ sort(allowed_gids.begin(), allowed_gids.end());
+ allowed_gids.erase(unique(allowed_gids.begin(), allowed_gids.end()), allowed_gids.end());
}
/*
* Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) 2018 SUSE LLC
+ * Copyright (c) [2018-2022] SUSE LLC
*
* All Rights Reserved.
*
const ConfigInfo& getConfigInfo() const { return config_info; }
void setConfigInfo(const map<string, string>& raw);
- vector<uid_t> uids;
- vector<gid_t> gids;
+ const vector<uid_t>& get_allowed_uids() const { return allowed_uids; }
+ const vector<gid_t>& get_allowed_gids() const { return allowed_gids; }
Snapper* getSnapper();
Snapper* snapper = nullptr;
+ vector<uid_t> allowed_uids;
+ vector<gid_t> allowed_gids;
+
};
/*
* Copyright (c) [2012-2015] Novell, Inc.
- * Copyright (c) [2018-2021] SUSE LLC
+ * Copyright (c) [2018-2022] SUSE LLC
*
* All Rights Reserved.
*
{
boost::unique_lock<boost::shared_mutex> lock(big_mutex);
- Clients::iterator client = clients.find(msg.get_sender());
+ const string name = msg.get_sender();
+
+ Clients::iterator client = clients.find(name);
if (client == clients.end())
{
- y2deb("client connected invisible '" << msg.get_sender() << "'");
- add_client_match(msg.get_sender());
- client = clients.add(msg.get_sender());
+ y2deb("client connected invisible '" << name << "'");
+ add_client_match(name);
+ client = clients.add(name, get_unix_userid(msg));
set_idle_timeout(seconds(-1));
}