Merge pull request #726 from theopolis/perms

Move lsperms into filesystem
This commit is contained in:
Teddy Reed 2015-02-10 08:34:25 -08:00
commit 46b288a744
4 changed files with 17 additions and 13 deletions

View File

@ -155,6 +155,9 @@ Status isDirectory(const boost::filesystem::path& path);
*/
std::vector<boost::filesystem::path> getHomeDirectories();
/// Return bit-mask-style permissions.
std::string lsperms(int mode);
#ifdef __APPLE__
/**
* @brief Parse a property list on disk into a property tree.

View File

@ -485,4 +485,15 @@ std::vector<fs::path> getHomeDirectories() {
}
return results;
}
std::string lsperms(int mode) {
static const char rwx[] = {'0', '1', '2', '3', '4', '5', '6', '7'};
std::string bits;
bits += rwx[(mode >> 9) & 7];
bits += rwx[(mode >> 6) & 7];
bits += rwx[(mode >> 3) & 7];
bits += rwx[(mode >> 0) & 7];
return bits;
}
}

View File

@ -12,6 +12,7 @@
#include <pwd.h>
#include <osquery/core.h>
#include <osquery/filesystem.h>
#include <osquery/logger.h>
#include <osquery/tables.h>
@ -71,7 +72,7 @@ QueryData genSharedMemory(QueryContext &context) {
r["dtime"] = BIGINT(shmseg.shm_dtime);
r["ctime"] = BIGINT(shmseg.shm_ctime);
r["permissions"] = INTEGER(ipcp->mode);
r["permissions"] = lsperms(ipcp->mode);
r["size"] = BIGINT(shmseg.shm_segsz);
r["attached"] = INTEGER(shmseg.shm_nattch);
r["status"] = (ipcp->mode & SHM_DEST) ? "dest" : "";

View File

@ -18,17 +18,6 @@
namespace osquery {
namespace tables {
inline std::string lsperms(int mode) {
static const char rwx[] = {'0', '1', '2', '3', '4', '5', '6', '7'};
std::string bits;
bits += rwx[(mode >> 9) & 7];
bits += rwx[(mode >> 6) & 7];
bits += rwx[(mode >> 3) & 7];
bits += rwx[(mode >> 0) & 7];
return bits;
}
QueryData genFile(QueryContext& context) {
QueryData results;
@ -50,7 +39,7 @@ QueryData genFile(QueryContext& context) {
r["inode"] = BIGINT(file_stat.st_ino);
r["uid"] = BIGINT(file_stat.st_uid);
r["gid"] = BIGINT(file_stat.st_gid);
r["mode"] = std::string(lsperms(file_stat.st_mode));
r["mode"] = lsperms(file_stat.st_mode);
r["device"] = BIGINT(file_stat.st_rdev);
r["size"] = BIGINT(file_stat.st_size);
r["block_size"] = INTEGER(file_stat.st_blksize);