mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-29 08:07:24 +00:00
update(userspace/falco): utilities to detect unix socket prefix in string
Signed-off-by: Lorenzo Fontana <lo@linux.com>
This commit is contained in:
parent
d1c9aae881
commit
86b473e224
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "utils.h"
|
||||
#include "banned.h" // This raises a compilation error when certain functions are used
|
||||
|
||||
@ -33,3 +35,15 @@ void falco::utils::read(const std::string& filename, std::string& data)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool falco::utils::starts_with(const std::string& text, const std::string& prefix)
|
||||
{
|
||||
return prefix.empty() ||
|
||||
(text.size() >= prefix.size() &&
|
||||
std::memcmp(text.data(), prefix.data(), prefix.size()) == 0);
|
||||
}
|
||||
|
||||
bool falco::utils::network::url_is_unix_scheme(const std::string& url)
|
||||
{
|
||||
return starts_with(url, UNIX_SCHEME);
|
||||
}
|
||||
|
@ -26,5 +26,12 @@ namespace falco
|
||||
namespace utils
|
||||
{
|
||||
void read(const std::string& filename, std::string& data);
|
||||
bool starts_with(const std::string& text, const std::string& prefix);
|
||||
|
||||
namespace network
|
||||
{
|
||||
static const std::string UNIX_SCHEME{"unix://"};
|
||||
bool url_is_unix_scheme(const std::string& url);
|
||||
} // namespace network
|
||||
} // namespace utils
|
||||
} // namespace falco
|
||||
|
Loading…
Reference in New Issue
Block a user