97 lines
2.4 KiB
C++
97 lines
2.4 KiB
C++
|
|
#include <sys/types.h>
|
|
#include <sys/acl.h>
|
|
#include "../acl.hpp"
|
|
|
|
#include <cruft/util/bitwise.hpp>
|
|
#include <cruft/util/posix/except.hpp>
|
|
#include <cruft/util/posix/util.hpp>
|
|
#include <cruft/util/posix/ostream.hpp>
|
|
#include <cruft/util/string.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/xattr.h>
|
|
#include <unistd.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void do_xattr (char const *path)
|
|
{
|
|
std::cout << ", xattr: ";
|
|
|
|
{
|
|
std::cout << "{ ";
|
|
|
|
std::string attr_list (1024, '\0');
|
|
{
|
|
auto res = listxattr (path, attr_list.data (), attr_list.size ());
|
|
if (res < 0)
|
|
cruft::posix::error::throw_code ();
|
|
attr_list.resize (res);
|
|
}
|
|
|
|
std::string keybuffer (64, '\0');
|
|
std::string val (128, '\0');
|
|
cruft::view<char const*> attr_view { attr_list.data (), attr_list.size () };
|
|
for (auto const &key: cruft::tokeniser (attr_view, '\0')) {
|
|
keybuffer.resize (0);
|
|
std::copy (std::begin (key), std::end (key), std::back_inserter (keybuffer));
|
|
|
|
while (true) {
|
|
auto const res = getxattr (path, keybuffer.c_str (), val.data (), val.size ());
|
|
if (res < 0 && errno == E2BIG) {
|
|
val = "___E2BIG";
|
|
break;
|
|
}
|
|
|
|
if (res < 0 && errno == ERANGE) {
|
|
val.resize (val.size () * 2);
|
|
continue;
|
|
}
|
|
|
|
if (res < 0)
|
|
cruft::posix::error::throw_code ();
|
|
|
|
val.resize (res);
|
|
break;
|
|
}
|
|
|
|
std::cout << keybuffer << ": " << val << ", ";
|
|
}
|
|
|
|
std::cout << "}";
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void do_acl (char const *path)
|
|
{
|
|
std::cout << cruft::acl (path, ACL_TYPE_ACCESS) << '\n';
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
int main (int argc, char **argv)
|
|
{
|
|
if (argc < 2) {
|
|
std::cerr << argv[0] << " <target> ...\n";
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
std::cout << "{ stat: ";
|
|
|
|
char const *path = argv[i];
|
|
std::cout << cruft::posix::stat (path);
|
|
do_xattr (path);
|
|
do_acl (path);
|
|
|
|
std::cout << '\n';
|
|
}
|
|
} |