_SECURE_PATH(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸŽ€ NAME πŸŽ€

_secure_path β€” determine if a file appears to be secure

okay bestie, this is the _SECURE_PATH(3) page from the Library Functions Manual ✨ it’s giving β€œshould I trust this file or nah?” energy, and honestly that is such a mood.

πŸ“š LIBRARY πŸ“š

System Utilities Library (libutil, -lutil) 🫢

✨ SYNOPSIS ✨

#include <sys/types.h>
#include <libutil.h>

int
_secure_path(const char *path, uid_t uid, gid_t gid);

πŸ’… DESCRIPTION πŸ’…

so _secure_path() does some basic security checking on a path. It’s meant for processes running with root privileges so they can decide whether or not to trust the contents of a given file. It uses a method often used to detect system compromise πŸ‘€

A file is considered β€œsecure” if it meets these conditions:

  1. The file exists, and is a regular file (not a symlink, device special or named pipe, etc.) πŸš«πŸ”—
  2. It is not world writable. 🌍❌
  3. It is owned by the given uid or uid 0, if uid is not -1 πŸ‘‘
  4. It is not group writable or it has group ownership by the given gid, if gid is not -1 πŸ‘―

🌈 RETURN VALUES 🌈

  • zero if the file exists and may be considered secure βœ…
  • -2 if the file does not exist 😭
  • -1 otherwise to indicate a security failure πŸ’€

The syslog(3) function is used to log any failure of this function, including the reason, at LOG_ERR priority πŸ“

πŸ”Ž SEE ALSO πŸ”Ž

πŸ¦‹ HISTORY πŸ¦‹

Code from which this function was derived was contributed to the FreeBSD project by Berkeley Software Design, Inc. The function _secure_path() first appeared in FreeBSD 2.2.5 πŸŽ€

πŸ’€ BUGS πŸ’€

⚠️ bestie, the checks carried out are rudimentary and no attempt is made to eliminate race conditions between use of this function and access to the file referenced. so like… it’s not a full-body security scan, okay? 😭

xoxo, this page is brought to you by Debian, dated May 10, 2020 πŸ’–

πŸ“¦ where this page comes from