support.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * $Id$
  3. */
  4. #ifndef _PAM_UNIX_SUPPORT_H
  5. #define _PAM_UNIX_SUPPORT_H
  6. #include <pwd.h>
  7. /*
  8. * File to read value of ENCRYPT_METHOD from.
  9. */
  10. #define LOGIN_DEFS "/etc/login.defs"
  11. /*
  12. * here is the string to inform the user that the new passwords they
  13. * typed were not the same.
  14. */
  15. /* type definition for the control options */
  16. typedef struct {
  17. const char *token;
  18. unsigned long long mask; /* shall assume 64 bits of flags */
  19. unsigned long long flag;
  20. unsigned int is_hash_algo;
  21. } UNIX_Ctrls;
  22. /*
  23. * macro to determine if a given flag is on
  24. */
  25. #define on(x,ctrl) (unix_args[x].flag & ctrl)
  26. /*
  27. * macro to determine that a given flag is NOT on
  28. */
  29. #define off(x,ctrl) (!on(x,ctrl))
  30. /*
  31. * macro to turn on/off a ctrl flag manually
  32. */
  33. #define set(x,ctrl) (ctrl = ((ctrl)&unix_args[x].mask)|unix_args[x].flag)
  34. #define unset(x,ctrl) (ctrl &= ~(unix_args[x].flag))
  35. /* the generic mask */
  36. #define _ALL_ON_ (~0ULL)
  37. /* end of macro definitions definitions for the control flags */
  38. /* ****************************************************************** *
  39. * ctrl flags proper..
  40. */
  41. /*
  42. * here are the various options recognized by the unix module. They
  43. * are enumerated here and then defined below. Internal arguments are
  44. * given NULL tokens.
  45. */
  46. #define UNIX__OLD_PASSWD 0 /* internal */
  47. #define UNIX__VERIFY_PASSWD 1 /* internal */
  48. #define UNIX__IAMROOT 2 /* internal */
  49. #define UNIX_AUDIT 3 /* print more things than debug..
  50. some information may be sensitive */
  51. #define UNIX_USE_FIRST_PASS 4
  52. #define UNIX_TRY_FIRST_PASS 5
  53. #define UNIX_AUTHTOK_TYPE 6 /* TYPE for pam_get_authtok() */
  54. #define UNIX__PRELIM 7 /* internal */
  55. #define UNIX__UPDATE 8 /* internal */
  56. #define UNIX__NONULL 9 /* internal */
  57. #define UNIX__QUIET 10 /* internal */
  58. #define UNIX_USE_AUTHTOK 11 /* insist on reading PAM_AUTHTOK */
  59. #define UNIX_SHADOW 12 /* signal shadow on */
  60. #define UNIX_MD5_PASS 13 /* force the use of MD5 passwords */
  61. #define UNIX__NULLOK 14 /* Null token ok */
  62. #define UNIX_DEBUG 15 /* send more info to syslog(3) */
  63. #define UNIX_NODELAY 16 /* admin does not want a fail-delay */
  64. #define UNIX_NIS 17 /* wish to use NIS for pwd */
  65. #define UNIX_BIGCRYPT 18 /* use DEC-C2 crypt()^x function */
  66. #define UNIX_LIKE_AUTH 19 /* need to auth for setcred to work */
  67. #define UNIX_REMEMBER_PASSWD 20 /* Remember N previous passwords */
  68. #define UNIX_NOREAP 21 /* don't reap child process */
  69. #define UNIX_BROKEN_SHADOW 22 /* ignore errors reading password aging
  70. * information during acct management */
  71. #define UNIX_SHA256_PASS 23 /* new password hashes will use SHA256 */
  72. #define UNIX_SHA512_PASS 24 /* new password hashes will use SHA512 */
  73. #define UNIX_ALGO_ROUNDS 25 /* optional number of rounds for new
  74. password hash algorithms */
  75. #define UNIX_BLOWFISH_PASS 26 /* new password hashes will use blowfish */
  76. #define UNIX_MIN_PASS_LEN 27 /* min length for password */
  77. #define UNIX_QUIET 28 /* Don't print informational messages */
  78. #define UNIX_NO_PASS_EXPIRY 29 /* Don't check for password expiration if not used for authentication */
  79. #define UNIX_DES 30 /* DES, default */
  80. #define UNIX_GOST_YESCRYPT_PASS 31 /* new password hashes will use gost-yescrypt */
  81. #define UNIX_YESCRYPT_PASS 32 /* new password hashes will use yescrypt */
  82. #define UNIX_NULLRESETOK 33 /* allow empty password if password reset is enforced */
  83. /* -------------- */
  84. #define UNIX_CTRLS_ 34 /* number of ctrl arguments defined */
  85. #define UNIX_DES_CRYPT(ctrl) (off(UNIX_MD5_PASS,ctrl)&&off(UNIX_BIGCRYPT,ctrl)&&off(UNIX_SHA256_PASS,ctrl)&&off(UNIX_SHA512_PASS,ctrl)&&off(UNIX_BLOWFISH_PASS,ctrl)&&off(UNIX_GOST_YESCRYPT_PASS,ctrl)&&off(UNIX_YESCRYPT_PASS,ctrl))
  86. static const UNIX_Ctrls unix_args[UNIX_CTRLS_] =
  87. {
  88. /* symbol token name ctrl mask ctrl *
  89. * --------------------------- -------------------- ------------------------- ---------------- */
  90. /* UNIX__OLD_PASSWD */ {NULL, _ALL_ON_, 01, 0},
  91. /* UNIX__VERIFY_PASSWD */ {NULL, _ALL_ON_, 02, 0},
  92. /* UNIX__IAMROOT */ {NULL, _ALL_ON_, 04, 0},
  93. /* UNIX_AUDIT */ {"audit", _ALL_ON_, 010, 0},
  94. /* UNIX_USE_FIRST_PASS */ {"use_first_pass", _ALL_ON_^(060ULL), 020, 0},
  95. /* UNIX_TRY_FIRST_PASS */ {"try_first_pass", _ALL_ON_^(060ULL), 040, 0},
  96. /* UNIX_AUTHTOK_TYPE */ {"authtok_type=", _ALL_ON_, 0100, 0},
  97. /* UNIX__PRELIM */ {NULL, _ALL_ON_^(0600ULL), 0200, 0},
  98. /* UNIX__UPDATE */ {NULL, _ALL_ON_^(0600ULL), 0400, 0},
  99. /* UNIX__NONULL */ {NULL, _ALL_ON_, 01000, 0},
  100. /* UNIX__QUIET */ {NULL, _ALL_ON_, 02000, 0},
  101. /* UNIX_USE_AUTHTOK */ {"use_authtok", _ALL_ON_, 04000, 0},
  102. /* UNIX_SHADOW */ {"shadow", _ALL_ON_, 010000, 0},
  103. /* UNIX_MD5_PASS */ {"md5", _ALL_ON_^(015660420000ULL), 020000, 1},
  104. /* UNIX__NULLOK */ {"nullok", _ALL_ON_^(01000ULL), 0, 0},
  105. /* UNIX_DEBUG */ {"debug", _ALL_ON_, 040000, 0},
  106. /* UNIX_NODELAY */ {"nodelay", _ALL_ON_, 0100000, 0},
  107. /* UNIX_NIS */ {"nis", _ALL_ON_, 0200000, 0},
  108. /* UNIX_BIGCRYPT */ {"bigcrypt", _ALL_ON_^(015660420000ULL), 0400000, 1},
  109. /* UNIX_LIKE_AUTH */ {"likeauth", _ALL_ON_, 01000000, 0},
  110. /* UNIX_REMEMBER_PASSWD */ {"remember=", _ALL_ON_, 02000000, 0},
  111. /* UNIX_NOREAP */ {"noreap", _ALL_ON_, 04000000, 0},
  112. /* UNIX_BROKEN_SHADOW */ {"broken_shadow", _ALL_ON_, 010000000, 0},
  113. /* UNIX_SHA256_PASS */ {"sha256", _ALL_ON_^(015660420000ULL), 020000000, 1},
  114. /* UNIX_SHA512_PASS */ {"sha512", _ALL_ON_^(015660420000ULL), 040000000, 1},
  115. /* UNIX_ALGO_ROUNDS */ {"rounds=", _ALL_ON_, 0100000000, 0},
  116. /* UNIX_BLOWFISH_PASS */ {"blowfish", _ALL_ON_^(015660420000ULL), 0200000000, 1},
  117. /* UNIX_MIN_PASS_LEN */ {"minlen=", _ALL_ON_, 0400000000, 0},
  118. /* UNIX_QUIET */ {"quiet", _ALL_ON_, 01000000000, 0},
  119. /* UNIX_NO_PASS_EXPIRY */ {"no_pass_expiry", _ALL_ON_, 02000000000, 0},
  120. /* UNIX_DES */ {"des", _ALL_ON_^(015660420000ULL), 0, 1},
  121. /* UNIX_GOST_YESCRYPT_PASS */ {"gost_yescrypt", _ALL_ON_^(015660420000ULL), 04000000000, 1},
  122. /* UNIX_YESCRYPT_PASS */ {"yescrypt", _ALL_ON_^(015660420000ULL), 010000000000, 1},
  123. /* UNIX_NULLRESETOK */ {"nullresetok", _ALL_ON_, 020000000000, 0},
  124. };
  125. #define UNIX_DEFAULTS (unix_args[UNIX__NONULL].flag)
  126. /* use this to free strings. ESPECIALLY password strings */
  127. #define _pam_delete(xx) \
  128. { \
  129. _pam_overwrite(xx); \
  130. _pam_drop(xx); \
  131. }
  132. extern int _make_remark(pam_handle_t * pamh, unsigned long long ctrl,
  133. int type, const char *text);
  134. extern unsigned long long _set_ctrl(pam_handle_t * pamh, int flags,
  135. int *remember, int *rounds,
  136. int *pass_min_len,
  137. int argc, const char **argv);
  138. extern int _unix_getpwnam (pam_handle_t *pamh,
  139. const char *name, int files, int nis,
  140. struct passwd **ret);
  141. extern int _unix_comesfromsource (pam_handle_t *pamh,
  142. const char *name, int files, int nis);
  143. extern int _unix_blankpasswd(pam_handle_t *pamh, unsigned long long ctrl,
  144. const char *name);
  145. extern int _unix_verify_password(pam_handle_t * pamh, const char *name,
  146. const char *p, unsigned long long ctrl);
  147. extern int _unix_verify_user(pam_handle_t *pamh, unsigned long long ctrl,
  148. const char *name, int *daysleft);
  149. extern int _unix_run_verify_binary(pam_handle_t *pamh,
  150. unsigned long long ctrl,
  151. const char *user, int *daysleft);
  152. #endif /* _PAM_UNIX_SUPPORT_H */