secutil.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef VSF_SECUTIL_H
  2. #define VSF_SECUTIL_H
  3. struct mystr;
  4. /* vsf_secutil_change_credentials()
  5. * PURPOSE
  6. * This function securely switches process credentials to the user specified.
  7. * There are options to enter a chroot() jail, and supplementary groups may
  8. * or may not be activated.
  9. * PARAMETERS
  10. * p_user_str - the name of the user to become
  11. * p_dir_str - the directory to chdir() and possibly chroot() to.
  12. * (if NULL, the user's home directory is used)
  13. * p_ext_dir_str - the directory to chdir() and possibly chroot() to,
  14. * applied in addition to the directory calculated by
  15. * p_user_str and p_dir_str.
  16. * caps - bitmap of capabilities to adopt. NOTE, if the underlying
  17. * OS does not support capabilities as a non-root user, and
  18. * the capability bitset is non-empty, then root privileges
  19. * will have to be retained.
  20. * options - see bitmask definitions below
  21. */
  22. /* chroot() the user into the new directory */
  23. #define VSF_SECUTIL_OPTION_CHROOT 1
  24. /* Activate any supplementary groups the user may have */
  25. #define VSF_SECUTIL_OPTION_USE_GROUPS 2
  26. /* Do the chdir() as the effective userid of the target user */
  27. #define VSF_SECUTIL_OPTION_CHANGE_EUID 4
  28. /* Use RLIMIT_NOFILE to prevent the opening of new fds */
  29. #define VSF_SECUTIL_OPTION_NO_FDS 8
  30. /* Use RLIMIT_NPROC to prevent the launching of new processes */
  31. #define VSF_SECUTIL_OPTION_NO_PROCS 16
  32. /* Permit a writeable chroot() root */
  33. #define VSF_SECUTIL_OPTION_ALLOW_WRITEABLE_ROOT 32
  34. void vsf_secutil_change_credentials(const struct mystr* p_user_str,
  35. const struct mystr* p_dir_str,
  36. const struct mystr* p_ext_dir_str,
  37. unsigned int caps, unsigned int options);
  38. #endif /* VSF_SECUTIL_H */