/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2018-2020] SUSE LLC
+ * Copyright (c) [2018-2023] SUSE LLC
*
* All Rights Reserved.
*
#include "config.h"
-#include <string.h>
+#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <stddef.h>
#include <dirent.h>
#include <unistd.h>
-#include <errno.h>
+#include <cerrno>
#include <stdlib.h>
-#include <assert.h>
-#ifdef ENABLE_SELINUX
-#include <selinux/selinux.h>
-#endif
+#include <cassert>
#include <algorithm>
#include "snapper/FileUtils.h"
{
char *src_con = NULL;
- int fd = ::openat(dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME
- | O_NONBLOCK | O_CLOEXEC);
+ int fd = ::openat(dirfd, name.c_str(), O_RDONLY | O_NOFOLLOW | O_NOATIME | O_NONBLOCK | O_CLOEXEC);
if (fd < 0)
{
// symlink, detached dev node?
y2deb("setting new SELinux context on " << fullname() << "/" << name);
if (lsetfilecon(name.c_str(), con))
{
- y2err("lsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno << " (" << stringerror(errno) << ")");
+ y2err("lsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno <<
+ " (" << stringerror(errno) << ")");
retval = false;
}
}
y2deb("setting new SELinux context on " << fullname() << "/" << name);
if (::fsetfilecon(fd, con))
{
- y2err("fsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno << " (" << stringerror(errno) << ")");
+ y2err("fsetfilecon on " << fullname() << "/" << name << " failed errno: " << errno <<
+ " (" << stringerror(errno) << ")");
retval = false;
}
}
freecon(src_con);
}
#endif
+
return retval;
}
bool
- SDir::restorecon(const string& name, SelinuxLabelHandle* sh) const
+ SDir::restorecon(const string& name, SelinuxLabelHandle* selabel_handle) const
{
assert(name.find('/') == string::npos);
assert(name != "..");
bool retval = true;
+
#ifdef ENABLE_SELINUX
if (_is_selinux_enabled())
{
- assert(sh);
+ assert(selabel_handle);
struct stat buf;
if (stat(name, &buf, AT_SYMLINK_NOFOLLOW))
return false;
}
- char* con = sh->selabel_lookup(fullname() + "/" + name, buf.st_mode);
+ char* con = selabel_handle->selabel_lookup(fullname() + "/" + name, buf.st_mode);
if (con)
{
retval = fsetfilecon(name, con);
freecon(con);
}
#endif
+
return retval;
}
freecon(src_con);
}
#endif
+
return retval;
}
bool
- SDir::restorecon(SelinuxLabelHandle* sh) const
+ SDir::restorecon(SelinuxLabelHandle* selabel_handle) const
{
bool retval = true;
+
#ifdef ENABLE_SELINUX
if (_is_selinux_enabled())
{
- assert(sh);
+ assert(selabel_handle);
struct stat buf;
return false;
}
- char* con = sh->selabel_lookup(fullname(), buf.st_mode);
+ char* con = selabel_handle->selabel_lookup(fullname(), buf.st_mode);
if (con)
{
retval = fsetfilecon(con);
freecon(con);
}
#endif
+
return retval;
}
dir.fsetfilecon(name, con);
}
+
void
- SFile::restorecon(SelinuxLabelHandle* sh) const
+ SFile::restorecon(SelinuxLabelHandle* selabel_handle) const
{
- dir.restorecon(name, sh);
+ dir.restorecon(name, selabel_handle);
}
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) 2020 SUSE LLC
+ * Copyright (c) [2020-2023] SUSE LLC
*
* All Rights Reserved.
*
bool fsetfilecon(const string& name, const char* con) const;
bool fsetfilecon(const char* con) const;
- bool restorecon(SelinuxLabelHandle* sh) const;
- bool restorecon(const string& name, SelinuxLabelHandle* sh) const;
+ bool restorecon(SelinuxLabelHandle* selabel_handle) const;
+ bool restorecon(const string& name, SelinuxLabelHandle* selabel_handle) const;
private:
ssize_t getxattr(const char* name, void* value, size_t size) const;
void fsetfilecon(const char* con) const;
- void restorecon(SelinuxLabelHandle* sh) const;
+ void restorecon(SelinuxLabelHandle* selabel_handle) const;
private:
#include "config.h"
-#include <string.h>
+#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
-#include <errno.h>
+#include <cerrno>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
Lvm::Lvm(const string& subvolume, const string& root_prefix, const string& mount_type)
: Filesystem(subvolume, root_prefix), mount_type(mount_type),
caps(LvmCapabilities::get_lvm_capabilities()),
- cache(LvmCache::get_lvm_cache()), sh(NULL)
+ cache(LvmCache::get_lvm_cache())
{
if (access(LVCREATEBIN, X_OK) != 0)
{
#ifdef ENABLE_SELINUX
try
{
- sh = SelinuxLabelHandle::get_selinux_handle();
+ selabel_handle = SelinuxLabelHandle::get_selinux_handle();
}
catch (const SelinuxException& e)
{
#ifdef ENABLE_SELINUX
if (_is_selinux_enabled())
{
- assert(sh);
+ assert(selabel_handle);
char* con = NULL;
{
string path(subvolume_dir.fullname() + "/.snapshots");
- con = sh->selabel_lookup(path, mode);
+ con = selabel_handle->selabel_lookup(path, mode);
if (con)
{
// race free mkdir with correct Selinux context preset