0005-Fix-builds-without-PAM-Issue-5283.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. From 570933a6a3597371bae1beeb754ee8711d6305ab Mon Sep 17 00:00:00 2001
  2. From: Michael R Sweet <michael.r.sweet@gmail.com>
  3. Date: Mon, 2 Apr 2018 20:05:13 -0400
  4. Subject: [PATCH] Fix builds without PAM (Issue #5283)
  5. [baruch: drop CHANGES.md hunk]
  6. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
  7. ---
  8. Upstream status: commit 570933a6a3
  9. CHANGES.md | 8 ++-
  10. scheduler/auth.c | 134 ++---------------------------------------------
  11. 2 files changed, 11 insertions(+), 131 deletions(-)
  12. diff --git a/scheduler/auth.c b/scheduler/auth.c
  13. index 8b134b5d7257..fa4e2715de34 100644
  14. --- a/scheduler/auth.c
  15. +++ b/scheduler/auth.c
  16. @@ -1,8 +1,8 @@
  17. /*
  18. * Authorization routines for the CUPS scheduler.
  19. *
  20. - * Copyright 2007-2016 by Apple Inc.
  21. - * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  22. + * Copyright © 2007-2018 by Apple Inc.
  23. + * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  24. *
  25. * This file contains Kerberos support code, copyright 2006 by
  26. * Jelmer Vernooij.
  27. @@ -71,9 +71,6 @@ static int check_authref(cupsd_client_t *con, const char *right);
  28. static int compare_locations(cupsd_location_t *a,
  29. cupsd_location_t *b);
  30. static cupsd_authmask_t *copy_authmask(cupsd_authmask_t *am, void *data);
  31. -#if !HAVE_LIBPAM
  32. -static char *cups_crypt(const char *pw, const char *salt);
  33. -#endif /* !HAVE_LIBPAM */
  34. static void free_authmask(cupsd_authmask_t *am, void *data);
  35. #if HAVE_LIBPAM
  36. static int pam_func(int, const struct pam_message **,
  37. @@ -694,14 +691,14 @@ cupsdAuthorize(cupsd_client_t *con) /* I - Client connection */
  38. * client...
  39. */
  40. - pass = cups_crypt(password, pw->pw_passwd);
  41. + pass = crypt(password, pw->pw_passwd);
  42. if (!pass || strcmp(pw->pw_passwd, pass))
  43. {
  44. # ifdef HAVE_SHADOW_H
  45. if (spw)
  46. {
  47. - pass = cups_crypt(password, spw->sp_pwdp);
  48. + pass = crypt(password, spw->sp_pwdp);
  49. if (pass == NULL || strcmp(spw->sp_pwdp, pass))
  50. {
  51. @@ -1995,129 +1992,6 @@ copy_authmask(cupsd_authmask_t *mask, /* I - Existing auth mask */
  52. }
  53. -#if !HAVE_LIBPAM
  54. -/*
  55. - * 'cups_crypt()' - Encrypt the password using the DES or MD5 algorithms,
  56. - * as needed.
  57. - */
  58. -
  59. -static char * /* O - Encrypted password */
  60. -cups_crypt(const char *pw, /* I - Password string */
  61. - const char *salt) /* I - Salt (key) string */
  62. -{
  63. - if (!strncmp(salt, "$1$", 3))
  64. - {
  65. - /*
  66. - * Use MD5 passwords without the benefit of PAM; this is for
  67. - * Slackware Linux, and the algorithm was taken from the
  68. - * old shadow-19990827/lib/md5crypt.c source code... :(
  69. - */
  70. -
  71. - int i; /* Looping var */
  72. - unsigned long n; /* Output number */
  73. - int pwlen; /* Length of password string */
  74. - const char *salt_end; /* End of "salt" data for MD5 */
  75. - char *ptr; /* Pointer into result string */
  76. - _cups_md5_state_t state; /* Primary MD5 state info */
  77. - _cups_md5_state_t state2; /* Secondary MD5 state info */
  78. - unsigned char digest[16]; /* MD5 digest result */
  79. - static char result[120]; /* Final password string */
  80. -
  81. -
  82. - /*
  83. - * Get the salt data between dollar signs, e.g. $1$saltdata$md5.
  84. - * Get a maximum of 8 characters of salt data after $1$...
  85. - */
  86. -
  87. - for (salt_end = salt + 3; *salt_end && (salt_end - salt) < 11; salt_end ++)
  88. - if (*salt_end == '$')
  89. - break;
  90. -
  91. - /*
  92. - * Compute the MD5 sum we need...
  93. - */
  94. -
  95. - pwlen = strlen(pw);
  96. -
  97. - _cupsMD5Init(&state);
  98. - _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
  99. - _cupsMD5Append(&state, (unsigned char *)salt, salt_end - salt);
  100. -
  101. - _cupsMD5Init(&state2);
  102. - _cupsMD5Append(&state2, (unsigned char *)pw, pwlen);
  103. - _cupsMD5Append(&state2, (unsigned char *)salt + 3, salt_end - salt - 3);
  104. - _cupsMD5Append(&state2, (unsigned char *)pw, pwlen);
  105. - _cupsMD5Finish(&state2, digest);
  106. -
  107. - for (i = pwlen; i > 0; i -= 16)
  108. - _cupsMD5Append(&state, digest, i > 16 ? 16 : i);
  109. -
  110. - for (i = pwlen; i > 0; i >>= 1)
  111. - _cupsMD5Append(&state, (unsigned char *)((i & 1) ? "" : pw), 1);
  112. -
  113. - _cupsMD5Finish(&state, digest);
  114. -
  115. - for (i = 0; i < 1000; i ++)
  116. - {
  117. - _cupsMD5Init(&state);
  118. -
  119. - if (i & 1)
  120. - _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
  121. - else
  122. - _cupsMD5Append(&state, digest, 16);
  123. -
  124. - if (i % 3)
  125. - _cupsMD5Append(&state, (unsigned char *)salt + 3, salt_end - salt - 3);
  126. -
  127. - if (i % 7)
  128. - _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
  129. -
  130. - if (i & 1)
  131. - _cupsMD5Append(&state, digest, 16);
  132. - else
  133. - _cupsMD5Append(&state, (unsigned char *)pw, pwlen);
  134. -
  135. - _cupsMD5Finish(&state, digest);
  136. - }
  137. -
  138. - /*
  139. - * Copy the final sum to the result string and return...
  140. - */
  141. -
  142. - memcpy(result, salt, (size_t)(salt_end - salt));
  143. - ptr = result + (salt_end - salt);
  144. - *ptr++ = '$';
  145. -
  146. - for (i = 0; i < 5; i ++, ptr += 4)
  147. - {
  148. - n = ((((unsigned)digest[i] << 8) | (unsigned)digest[i + 6]) << 8);
  149. -
  150. - if (i < 4)
  151. - n |= (unsigned)digest[i + 12];
  152. - else
  153. - n |= (unsigned)digest[5];
  154. -
  155. - to64(ptr, n, 4);
  156. - }
  157. -
  158. - to64(ptr, (unsigned)digest[11], 2);
  159. - ptr += 2;
  160. - *ptr = '\0';
  161. -
  162. - return (result);
  163. - }
  164. - else
  165. - {
  166. - /*
  167. - * Use the standard crypt() function...
  168. - */
  169. -
  170. - return (crypt(pw, salt));
  171. - }
  172. -}
  173. -#endif /* !HAVE_LIBPAM */
  174. -
  175. -
  176. /*
  177. * 'free_authmask()' - Free function for auth masks.
  178. */
  179. --
  180. 2.17.0