osquery-1/include/osquery/filesystem.h

131 lines
4.2 KiB
C
Raw Normal View History

2014-08-02 18:28:38 +00:00
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
2014-08-02 18:28:38 +00:00
#include <map>
2014-08-02 18:28:38 +00:00
#include <string>
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include "osquery/status.h"
2014-08-02 18:28:38 +00:00
2014-08-15 07:25:30 +00:00
namespace osquery {
2014-08-02 18:28:38 +00:00
/**
* @brief Read a file from disk.
2014-09-15 19:47:00 +00:00
*
* @param path the path of the file that you would like to read
* @param content a reference to a string which will be populated with the
* contents of the path indicated by the path parameter
2014-09-15 19:47:00 +00:00
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation.
2014-09-15 19:47:00 +00:00
*/
2014-10-06 21:23:26 +00:00
Status readFile(const std::string& path, std::string& content);
2014-08-02 18:28:38 +00:00
/**
* @brief A helper to check if a path exists on disk or not.
2014-09-15 19:47:00 +00:00
*
* @param path the path on disk which you would like to check the existance of
2014-09-15 19:47:00 +00:00
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation. Specifically, the code of the Status instance
* will be -1 if no input was supplied, assuming the caller is not aware of how
* to check path-getter results. The code will be 0 if the path does not exist
* on disk and 1 if the path does exist on disk.
2014-09-15 19:47:00 +00:00
*/
2014-10-06 21:23:26 +00:00
Status pathExists(const std::string& path);
/**
* @brief List all of the files in a specific directory, non-recursively.
2014-09-15 19:47:00 +00:00
*
* @param path the path which you would like to list.
* @param results a non-const reference to a vector which will be populated
* with the directory listing of the path param, assuming that all operations
* completed successfully.
2014-09-15 19:47:00 +00:00
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation.
2014-09-15 19:47:00 +00:00
*/
2014-10-06 21:23:26 +00:00
Status listFilesInDirectory(const std::string& path,
2014-08-15 07:25:30 +00:00
std::vector<std::string>& results);
2014-08-14 23:27:20 +00:00
2014-10-06 21:23:26 +00:00
/**
* @brief Get directory portion of a path.
*
* @param path The input path, either a filename or directory.
* @param dirpath a non-const reference to a resultant directory portion.
*
* @return If the input path was a directory this will indicate failure. One
* should use `isDirectory` before.
*/
Status getDirectory(const std::string& path, std::string& dirpath);
/**
* @brief Check if an input path is a directory.
*
* @param path The input path, either a filename or directory.
*
* @return If the input path was a directory.
*/
Status isDirectory(const std::string& path);
/**
* @brief Parse the users out of a tomcat user config from disk
*
* @param path A string which represents the path of the tomcat user config
* @param a vector of pairs which represent all of the users which were found
* in the supplied file. pair.first is the username and pair.second is the
* password.
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation
*/
2014-10-06 21:23:26 +00:00
Status parseTomcatUserConfigFromDisk(
const std::string& path,
std::vector<std::pair<std::string, std::string> >& credentials);
/**
2014-10-01 02:54:44 +00:00
* @brief Parse the users out of a tomcat user config
*
* @param content A string which represents the content of the file to parse
2014-10-01 02:54:44 +00:00
* @param a vector of pairs which represent all of the users which were found
* in the supplied file. pair.first is the username and pair.second is the
* password.
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation
*/
2014-10-06 21:23:26 +00:00
Status parseTomcatUserConfig(
const std::string& content,
std::vector<std::pair<std::string, std::string> >& credentials);
#ifdef __APPLE__
/**
* @brief Parse a property list on disk into a property tree.
2014-09-15 19:47:00 +00:00
*
* @param path the path of the propery list which you'd like to read
* @param tree a non-const reference to a Boost property tree, which will be
* populated with the results of the property list
2014-09-15 19:47:00 +00:00
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation.
2014-09-15 19:47:00 +00:00
*/
2014-10-06 21:23:26 +00:00
Status parsePlist(const std::string& path,
2014-08-15 07:25:30 +00:00
boost::property_tree::ptree& tree);
/**
* @brief Parse property list content into a property tree.
2014-09-15 19:47:00 +00:00
*
* @param fileContent a string reference to the content of a plist
* @param tree a non-const reference to a Boost property tree, which will be
* populated with the results of the property list
2014-09-15 19:47:00 +00:00
*
2014-10-06 21:23:26 +00:00
* @return an instance of Status, indicating the success or failure
* of the operation.
2014-09-15 19:47:00 +00:00
*/
2014-10-06 21:23:26 +00:00
Status parsePlistContent(const std::string& fileContent,
2014-08-15 07:25:30 +00:00
boost::property_tree::ptree& tree);
#endif
2014-08-15 07:25:30 +00:00
}