Prefer use POSIX getpwent over glibc extension getpwent_r. This fixes
building with musl libc with CONFIG_USE_BB_PWD_GRP disabled.

Signed-off-by: Natanael Copa <[email protected]>
---
 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

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to