1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
From f47fa75ef19a43848dedb4a2bff79368878362bf Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 22 Apr 2014 12:41:20 +0000
Subject: [PATCH] linedit, deluser: use POSIX getpwent instead of getpwent_r
This fixes building with musl libc.
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
libbb/lineedit.c | 11 ++++-------
loginutils/deluser.c | 11 +++++------
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 8564307..99e6e2c 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -672,20 +672,17 @@ static char *username_path_completion(char *ud)
*/
static NOINLINE unsigned complete_username(const char *ud)
{
- /* Using _r function to avoid pulling in static buffers */
- char line_buff[256];
- struct passwd pwd;
- struct passwd *result;
+ struct passwd *pw;
unsigned userlen;
ud++; /* skip ~ */
userlen = strlen(ud);
setpwent();
- while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) {
+ while ((pw = getpwent())) {
/* Null usernames should result in all users as possible completions. */
- if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) {
- add_match(xasprintf("~%s/", pwd.pw_name));
+ if (/*!userlen || */ strncmp(ud, pw->pw_name, userlen) == 0) {
+ add_match(xasprintf("~%s/", pw->pw_name));
}
}
endpwent();
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index e39ac55..d7d9b24 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -73,14 +73,13 @@ int deluser_main(int argc, char **argv)
if (!member) {
/* "delgroup GROUP" */
struct passwd *pw;
- struct passwd pwent;
/* Check if the group is in use */
-#define passwd_buf bb_common_bufsiz1
- while (!getpwent_r(&pwent, passwd_buf, sizeof(passwd_buf), &pw)) {
- if (pwent.pw_gid == gr->gr_gid)
- bb_error_msg_and_die("'%s' still has '%s' as their primary group!", pwent.pw_name, name);
+ setpwent();
+ while ((pw = getpwent())) {
+ if (pw->pw_gid == gr->gr_gid)
+ bb_error_msg_and_die("'%s' still has '%s' as their primary group!", pw->pw_name, name);
}
- //endpwent();
+ endpwent();
}
pfile = bb_path_group_file;
if (ENABLE_FEATURE_SHADOWPASSWDS)
--
1.9.2
|