logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

0002-su-login-Introduce-PREVENT_NO_AUTH.patch (2939B)


  1. From b52ef69b3b8442a77eeb18b7bf8f9b47148d6c34 Mon Sep 17 00:00:00 2001
  2. From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
  3. Date: Mon, 15 Mar 2021 10:25:50 +0100
  4. Subject: [PATCH 2/2] su & login: Introduce PREVENT_NO_AUTH
  5. ---
  6. etc/login.defs | 9 +++++++++
  7. lib/getdef.c | 1 +
  8. src/login.c | 13 +++++++++++--
  9. src/su.c | 20 +++++++++++++++-----
  10. 4 files changed, 36 insertions(+), 7 deletions(-)
  11. diff --git a/etc/login.defs b/etc/login.defs
  12. index a2f8cd50..f6b613a1 100644
  13. --- a/etc/login.defs
  14. +++ b/etc/login.defs
  15. @@ -428,3 +428,12 @@ USERGROUPS_ENAB yes
  16. # missing.
  17. #
  18. #FORCE_SHADOW yes
  19. +
  20. +#
  21. +# Prevents an empty password field to be interpreted as "no authentication
  22. +# required".
  23. +# Set to "yes" to prevent for all accounts
  24. +# Set to "superuser" to prevent for UID 0 / root (default)
  25. +# Set to "no" to not prevent for any account (dangerous, historical default)
  26. +
  27. +PREVENT_NO_AUTH yes
  28. diff --git a/lib/getdef.c b/lib/getdef.c
  29. index 00f6abfe..d25d13f4 100644
  30. --- a/lib/getdef.c
  31. +++ b/lib/getdef.c
  32. @@ -149,6 +149,7 @@ static struct itemdef def_table[] = {
  33. {"USE_TCB", NULL},
  34. #endif
  35. {"FORCE_SHADOW", NULL},
  36. + {"PREVENT_NO_AUTH", NULL},
  37. {NULL, NULL}
  38. };
  39. diff --git a/src/login.c b/src/login.c
  40. index 0c0b5c86..be84a884 100644
  41. --- a/src/login.c
  42. +++ b/src/login.c
  43. @@ -978,9 +978,18 @@ int main (int argc, char **argv)
  44. || ('*' == user_passwd[0])) {
  45. failed = true;
  46. }
  47. - /* Treat empty password field as invalid */
  48. +
  49. if (strcmp (user_passwd, "") == 0) {
  50. - failed = true;
  51. + char *prevent_no_auth = getdef_str("PREVENT_NO_AUTH");
  52. + if(prevent_no_auth == NULL) {
  53. + prevent_no_auth = "superuser";
  54. + }
  55. + if(strcmp(prevent_no_auth, "yes") == 0) {
  56. + failed = true;
  57. + } else if( (pwd->pw_uid == 0)
  58. + && (strcmp(prevent_no_auth, "superuser") == 0)) {
  59. + failed = true;
  60. + }
  61. }
  62. }
  63. diff --git a/src/su.c b/src/su.c
  64. index 638f533f..9cae4b2f 100644
  65. --- a/src/su.c
  66. +++ b/src/su.c
  67. @@ -499,15 +499,25 @@ static void check_perms_nopam (const struct passwd *pw)
  68. /*@observer@*/const char *password = pw->pw_passwd;
  69. RETSIGTYPE (*oldsig) (int);
  70. - if (strcmp (pw->pw_passwd, "") == 0) {
  71. - fprintf(stderr, _("Password field is empty, this is invalid.\n"));
  72. - exit(1);
  73. - }
  74. -
  75. if (caller_is_root) {
  76. return;
  77. }
  78. + if (strcmp (pw->pw_passwd, "") == 0) {
  79. + char *prevent_no_auth = getdef_str("PREVENT_NO_AUTH");
  80. + if(prevent_no_auth == NULL) {
  81. + prevent_no_auth = "superuser";
  82. + }
  83. + if(strcmp(prevent_no_auth, "yes") == 0) {
  84. + fprintf(stderr, _("Password field is empty, this is forbidden for all accounts.\n"));
  85. + exit(1);
  86. + } else if( (pw->pw_uid == 0)
  87. + && (strcmp(prevent_no_auth, "superuser") == 0)) {
  88. + fprintf(stderr, _("Password field is empty, this is forbidden for super-user.\n"));
  89. + exit(1);
  90. + }
  91. + }
  92. +
  93. /*
  94. * BSD systems only allow "wheel" to SU to root. USG systems don't,
  95. * so we make this a configurable option.
  96. --
  97. 2.26.3