pam_modutil.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2001-2002 Andrew Morgan <morgan@kernel.org>
  3. *
  4. * <security/pam_modutil.h>
  5. *
  6. * This file is a list of handy libc wrappers that attempt to provide some
  7. * thread-safe and other convenient functionality to modules in a common form.
  8. *
  9. * A number of these functions reserve space in a pam_[sg]et_data item.
  10. * In all cases, the name of the item is prefixed with "pam_modutil_*".
  11. *
  12. * On systems that simply can't support thread safe programming, these
  13. * functions don't support it either - sorry.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, and the entire permission notice in its entirety,
  20. * including the disclaimer of warranties.
  21. * 2. Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * 3. The name of the author may not be used to endorse or promote
  25. * products derived from this software without specific prior
  26. * written permission.
  27. *
  28. * ALTERNATIVELY, this product may be distributed under the terms of
  29. * the GNU Public License, in which case the provisions of the GPL are
  30. * required INSTEAD OF the above restrictions. (This clause is
  31. * necessary due to a potential bad interaction between the GPL and
  32. * the restrictions contained in a BSD-style copyright.)
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  35. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  36. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  39. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  40. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  44. * OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. #ifndef _SECURITY__PAM_MODUTIL_H
  47. #define _SECURITY__PAM_MODUTIL_H
  48. #include <sys/types.h>
  49. #include <pwd.h>
  50. #include <grp.h>
  51. #include <shadow.h>
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #include <security/_pam_types.h>
  56. extern int PAM_NONNULL((1,2))
  57. pam_modutil_check_user_in_passwd(pam_handle_t *pamh,
  58. const char *user_name,
  59. const char *file_name);
  60. extern struct passwd * PAM_NONNULL((1,2))
  61. pam_modutil_getpwnam(pam_handle_t *pamh, const char *user);
  62. extern struct passwd * PAM_NONNULL((1))
  63. pam_modutil_getpwuid(pam_handle_t *pamh, uid_t uid);
  64. extern struct group * PAM_NONNULL((1,2))
  65. pam_modutil_getgrnam(pam_handle_t *pamh, const char *group);
  66. extern struct group * PAM_NONNULL((1))
  67. pam_modutil_getgrgid(pam_handle_t *pamh, gid_t gid);
  68. extern struct spwd * PAM_NONNULL((1,2))
  69. pam_modutil_getspnam(pam_handle_t *pamh, const char *user);
  70. extern int PAM_NONNULL((1,2,3))
  71. pam_modutil_user_in_group_nam_nam(pam_handle_t *pamh,
  72. const char *user,
  73. const char *group);
  74. extern int PAM_NONNULL((1,2))
  75. pam_modutil_user_in_group_nam_gid(pam_handle_t *pamh,
  76. const char *user,
  77. gid_t group);
  78. extern int PAM_NONNULL((1,3))
  79. pam_modutil_user_in_group_uid_nam(pam_handle_t *pamh,
  80. uid_t user,
  81. const char *group);
  82. extern int PAM_NONNULL((1))
  83. pam_modutil_user_in_group_uid_gid(pam_handle_t *pamh,
  84. uid_t user,
  85. gid_t group);
  86. extern const char * PAM_NONNULL((1))
  87. pam_modutil_getlogin(pam_handle_t *pamh);
  88. extern int
  89. pam_modutil_read(int fd, char *buffer, int count);
  90. extern int
  91. pam_modutil_write(int fd, const char *buffer, int count);
  92. extern int PAM_NONNULL((1,3))
  93. pam_modutil_audit_write(pam_handle_t *pamh, int type,
  94. const char *message, int retval);
  95. struct pam_modutil_privs {
  96. gid_t *grplist;
  97. int number_of_groups;
  98. int allocated;
  99. gid_t old_gid;
  100. uid_t old_uid;
  101. int is_dropped;
  102. };
  103. #define PAM_MODUTIL_NGROUPS 64
  104. #define PAM_MODUTIL_DEF_PRIVS(n) \
  105. gid_t n##_grplist[PAM_MODUTIL_NGROUPS]; \
  106. struct pam_modutil_privs n = { n##_grplist, PAM_MODUTIL_NGROUPS, 0, -1, -1, 0 }
  107. extern int PAM_NONNULL((1,2,3))
  108. pam_modutil_drop_priv(pam_handle_t *pamh,
  109. struct pam_modutil_privs *p,
  110. const struct passwd *pw);
  111. extern int PAM_NONNULL((1,2))
  112. pam_modutil_regain_priv(pam_handle_t *pamh,
  113. struct pam_modutil_privs *p);
  114. enum pam_modutil_redirect_fd {
  115. PAM_MODUTIL_IGNORE_FD, /* do not redirect */
  116. PAM_MODUTIL_PIPE_FD, /* redirect to a pipe */
  117. PAM_MODUTIL_NULL_FD, /* redirect to /dev/null */
  118. };
  119. /* redirect standard descriptors, close all other descriptors. */
  120. extern int PAM_NONNULL((1))
  121. pam_modutil_sanitize_helper_fds(pam_handle_t *pamh,
  122. enum pam_modutil_redirect_fd redirect_stdin,
  123. enum pam_modutil_redirect_fd redirect_stdout,
  124. enum pam_modutil_redirect_fd redirect_stderr);
  125. /* lookup a value for key in login.defs file or similar key value format */
  126. extern char * PAM_NONNULL((1,2,3))
  127. pam_modutil_search_key(pam_handle_t *pamh,
  128. const char *file_name,
  129. const char *key);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* _SECURITY__PAM_MODUTIL_H */