blob: 2cbdd6c74c585e092d712dfba07825dea8c747e2 [file] [log] [blame]
Andrew Geissler87f5cff2022-09-30 13:13:31 -05001Do not use fgetpwent_r
2
3fgetpwent_r does not exist on musl
4
5Source: https://git.alpinelinux.org/aports/tree/community/libpwquality/0001-fix-musl-build.patch
6Upstream-Status: Pending
7Signed-off-by: Khem Raj <raj.khem@gmail.com>
8--- a/src/pam_pwquality.c
9+++ b/src/pam_pwquality.c
10@@ -19,6 +19,7 @@
11 #include <stdio.h>
12 #include <pwd.h>
13 #include <errno.h>
14+#include <security/pam_modutil.h>
15 #include "pwquality.h"
16
17 /*
18@@ -43,8 +44,6 @@ struct module_options {
19
20 #define CO_RETRY_TIMES 1
21
22-#define PATH_PASSWD "/etc/passwd"
23-
24 static int
25 _pam_parse (pam_handle_t *pamh, struct module_options *opt,
26 int argc, const char **argv)
27@@ -98,44 +97,7 @@ static int
28 check_local_user (pam_handle_t *pamh,
29 const char *user)
30 {
31- struct passwd pw, *pwp;
32- char buf[4096];
33- int found = 0;
34- FILE *fp;
35- int errn;
36-
37- fp = fopen(PATH_PASSWD, "r");
38- if (fp == NULL) {
39- pam_syslog(pamh, LOG_ERR, "unable to open %s: %s",
40- PATH_PASSWD, pam_strerror(pamh, errno));
41- return -1;
42- }
43-
44- for (;;) {
45- errn = fgetpwent_r(fp, &pw, buf, sizeof (buf), &pwp);
46- if (errn == ERANGE) {
47- pam_syslog(pamh, LOG_WARNING, "%s contains very long lines; corrupted?",
48- PATH_PASSWD);
49- /* we can continue here as next call will read further */
50- continue;
51- }
52- if (errn != 0)
53- break;
54- if (strcmp(pwp->pw_name, user) == 0) {
55- found = 1;
56- break;
57- }
58- }
59-
60- fclose (fp);
61-
62- if (errn != 0 && errn != ENOENT) {
63- pam_syslog(pamh, LOG_ERR, "unable to enumerate local accounts: %s",
64- pam_strerror(pamh, errn));
65- return -1;
66- } else {
67- return found;
68- }
69+ return pam_modutil_check_user_in_passwd(pamh, user, NULL) == PAM_SUCCESS;
70 }
71
72 PAM_EXTERN int