0026-Handle-missing-gshadow.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From ec519727bb1ceda6e7787ccf86237a6aad07137c Mon Sep 17 00:00:00 2001
  2. From: Alex Kiernan <alex.kiernan@gmail.com>
  3. Date: Tue, 10 Mar 2020 11:05:20 +0000
  4. Subject: [PATCH] Handle missing gshadow
  5. gshadow usage is now present in the userdb code. Mask all uses of it to
  6. allow compilation on musl
  7. Upstream-Status: Inappropriate [musl specific]
  8. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
  9. [Rebased for v247]
  10. Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
  11. ---
  12. src/shared/user-record-nss.c | 20 ++++++++++++++++++++
  13. src/shared/user-record-nss.h | 4 ++++
  14. src/shared/userdb.c | 7 ++++++-
  15. 3 files changed, 30 insertions(+), 1 deletion(-)
  16. --- a/src/shared/user-record-nss.c
  17. +++ b/src/shared/user-record-nss.c
  18. @@ -331,8 +331,10 @@ int nss_group_to_group_record(
  19. if (isempty(grp->gr_name))
  20. return -EINVAL;
  21. +#if ENABLE_GSHADOW
  22. if (sgrp && !streq_ptr(sgrp->sg_namp, grp->gr_name))
  23. return -EINVAL;
  24. +#endif
  25. g = group_record_new();
  26. if (!g)
  27. @@ -348,6 +350,7 @@ int nss_group_to_group_record(
  28. g->gid = grp->gr_gid;
  29. +#if ENABLE_GSHADOW
  30. if (sgrp) {
  31. if (looks_like_hashed_password(utf8_only(sgrp->sg_passwd))) {
  32. g->hashed_password = strv_new(sgrp->sg_passwd);
  33. @@ -363,6 +366,7 @@ int nss_group_to_group_record(
  34. if (r < 0)
  35. return r;
  36. }
  37. +#endif
  38. r = json_build(&g->json, JSON_BUILD_OBJECT(
  39. JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(g->group_name)),
  40. @@ -388,6 +392,7 @@ int nss_sgrp_for_group(const struct grou
  41. assert(ret_sgrp);
  42. assert(ret_buffer);
  43. +#if ENABLE_GSHADOW
  44. for (;;) {
  45. _cleanup_free_ char *buf = NULL;
  46. struct sgrp sgrp, *result;
  47. @@ -416,6 +421,9 @@ int nss_sgrp_for_group(const struct grou
  48. buflen *= 2;
  49. buf = mfree(buf);
  50. }
  51. +#else
  52. + return -ESRCH;
  53. +#endif
  54. }
  55. int nss_group_record_by_name(
  56. @@ -427,7 +435,9 @@ int nss_group_record_by_name(
  57. struct group grp, *result;
  58. bool incomplete = false;
  59. size_t buflen = 4096;
  60. +#if ENABLE_GSHADOW
  61. struct sgrp sgrp, *sresult = NULL;
  62. +#endif
  63. int r;
  64. assert(name);
  65. @@ -457,6 +467,7 @@ int nss_group_record_by_name(
  66. buf = mfree(buf);
  67. }
  68. +#if ENABLE_GSHADOW
  69. if (with_shadow) {
  70. r = nss_sgrp_for_group(result, &sgrp, &sbuf);
  71. if (r < 0) {
  72. @@ -468,6 +479,9 @@ int nss_group_record_by_name(
  73. incomplete = true;
  74. r = nss_group_to_group_record(result, sresult, ret);
  75. +#else
  76. + r = nss_group_to_group_record(result, NULL, ret);
  77. +#endif
  78. if (r < 0)
  79. return r;
  80. @@ -484,7 +498,9 @@ int nss_group_record_by_gid(
  81. struct group grp, *result;
  82. bool incomplete = false;
  83. size_t buflen = 4096;
  84. +#if ENABLE_GSHADOW
  85. struct sgrp sgrp, *sresult = NULL;
  86. +#endif
  87. int r;
  88. assert(ret);
  89. @@ -512,6 +528,7 @@ int nss_group_record_by_gid(
  90. buf = mfree(buf);
  91. }
  92. +#if ENABLE_GSHADOW
  93. if (with_shadow) {
  94. r = nss_sgrp_for_group(result, &sgrp, &sbuf);
  95. if (r < 0) {
  96. @@ -523,6 +540,9 @@ int nss_group_record_by_gid(
  97. incomplete = true;
  98. r = nss_group_to_group_record(result, sresult, ret);
  99. +#else
  100. + r = nss_group_to_group_record(result, NULL, ret);
  101. +#endif
  102. if (r < 0)
  103. return r;
  104. --- a/src/shared/user-record-nss.h
  105. +++ b/src/shared/user-record-nss.h
  106. @@ -2,7 +2,11 @@
  107. #pragma once
  108. #include <grp.h>
  109. +#if ENABLE_GSHADOW
  110. #include <gshadow.h>
  111. +#else
  112. +struct sgrp;
  113. +#endif
  114. #include <pwd.h>
  115. #include <shadow.h>
  116. --- a/src/shared/userdb.c
  117. +++ b/src/shared/userdb.c
  118. @@ -1044,13 +1044,15 @@ int groupdb_iterator_get(UserDBIterator
  119. if (gr) {
  120. _cleanup_free_ char *buffer = NULL;
  121. bool incomplete = false;
  122. +#if ENABLE_GSHADOW
  123. struct sgrp sgrp;
  124. -
  125. +#endif
  126. if (streq_ptr(gr->gr_name, "root"))
  127. iterator->synthesize_root = false;
  128. if (gr->gr_gid == GID_NOBODY)
  129. iterator->synthesize_nobody = false;
  130. +#if ENABLE_GSHADOW
  131. if (!FLAGS_SET(iterator->flags, USERDB_SUPPRESS_SHADOW)) {
  132. r = nss_sgrp_for_group(gr, &sgrp, &buffer);
  133. if (r < 0) {
  134. @@ -1063,6 +1065,9 @@ int groupdb_iterator_get(UserDBIterator
  135. }
  136. r = nss_group_to_group_record(gr, r >= 0 ? &sgrp : NULL, ret);
  137. +#else
  138. + r = nss_group_to_group_record(gr, NULL, ret);
  139. +#endif
  140. if (r < 0)
  141. return r;