[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: Bug in the deluser applet
From:       Laszlo Papp <lpapp () kde ! org>
Date:       2015-03-03 13:13:50
Message-ID: CAOMwXhN68vsOGYP3-mZT820H7SCHUQNXK51XLZ5sfpkPD0ZQuA () mail ! gmail ! com
[Download RAW message or body]

Denys, any feedback about this bugfix?

On Thu, Feb 19, 2015 at 6:16 PM, Laszlo Papp <lpapp@kde.org> wrote:
> From b03ad793d1188148953fa280dda672229b9a6524 Mon Sep 17 00:00:00 2001
> From: Laszlo Papp <laszlo.papp@polatis.com>
> Date: Wed, 18 Feb 2015 15:20:58 +0000
> Subject: [PATCH] Delete the user from all the groups for user deletion
>
> ---
>  libbb/update_passwd.c | 57 +++++++++++++++++++++++++++++++++++----------------
>  loginutils/deluser.c  |  4 +++-
>  2 files changed, 42 insertions(+), 19 deletions(-)
>
> diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c
> index a30af6f..df544f0 100644
> --- a/libbb/update_passwd.c
> +++ b/libbb/update_passwd.c
> @@ -62,6 +62,8 @@ static void check_selinux_update_passwd(const char *username)
>      only if CONFIG_PASSWD=y and applet_name[0] == 'p' like in passwd
>      or if CONFIG_CHPASSWD=y and applet_name[0] == 'c' like in chpasswd
>
> + 8) delete a user from all groups : update_passwd(FILE, NULL, NULL, MEMBER)
> +
>   This function does not validate the arguments fed to it
>   so the calling program should take care of that.
>
> @@ -81,7 +83,7 @@ int FAST_FUNC update_passwd(const char *filename,
>         FILE *new_fp;
>         char *fnamesfx;
>         char *sfx_char;
> -       char *name_colon;
> +       char *name_colon = 0;
>         unsigned user_len;
>         int old_fd;
>         int new_fd;
> @@ -99,13 +101,15 @@ int FAST_FUNC update_passwd(const char *filename,
>         if (filename == NULL)
>                 return ret;
>
> -       check_selinux_update_passwd(name);
> +       if (name) check_selinux_update_passwd(name);
>
>         /* New passwd file, "/etc/passwd+" for now */
>         fnamesfx = xasprintf("%s+", filename);
>         sfx_char = &fnamesfx[strlen(fnamesfx)-1];
> -       name_colon = xasprintf("%s:", name);
> -       user_len = strlen(name_colon);
> +    if (name) {
> +        name_colon = xasprintf("%s:", name);
> +        user_len = strlen(name_colon);
> +    }
>
>         if (shadow)
>                 old_fp = fopen(filename, "r+");
> @@ -162,21 +166,38 @@ int FAST_FUNC update_passwd(const char *filename,
>         /* Read current password file, write updated /etc/passwd+ */
>         changed_lines = 0;
>         while (1) {
> -               char *cp, *line;
> -
> -               line = xmalloc_fgetline(old_fp);
> -               if (!line) /* EOF/error */
> -                       break;
> -               if (strncmp(name_colon, line, user_len) != 0) {
> -                       fprintf(new_fp, "%s\n", line);
> -                       goto next;
> -               }
> -
> -               /* We have a match with "name:"... */
> -               cp = line + user_len; /* move past name: */
> +        char *cp, *line;
> +        if (!name && member) {
> +            struct group* g;
> +            if ((g = getgrent())) {
> +                char gline[LINE_MAX];
> +                char **s= g->gr_mem;
> +                bool sep = false;
> +                snprintf(gline, sizeof(gline), "%s:%s:%i:",
> g->gr_name, g->gr_passwd, g->gr_gid);
> +                while (*s) {
> +                    if (strcmp(*s, member)) { if (sep) strcat(gline,
> ","); else sep = true; strcat(gline, *s); }
> +                    ++s;
> +                }
> +                fprintf(new_fp, "%s\n", gline);
> +                continue;
> +            } else {
> +                break;
> +            }
> +        } else {
> +            line = xmalloc_fgetline(old_fp);
> +            if (!line) /* EOF/error */
> +                break;
> +            if (!name_colon || strncmp(name_colon, line, user_len) != 0) {
> +                fprintf(new_fp, "%s\n", line);
> +                goto next;
> +            }
> +
> +            /* We have a match with "name:"... */
> +            cp = line + user_len; /* move past name: */
> +        }
>
>  #if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
> -               if (member) {
> +               if (name && member) {
>                         /* It's actually /etc/group+, not /etc/passwd+ */
>                         if (ENABLE_FEATURE_ADDUSER_TO_GROUP
>                          && applet_name[0] == 'a'
> @@ -240,7 +261,7 @@ int FAST_FUNC update_passwd(const char *filename,
>
>         if (changed_lines == 0) {
>  #if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
> -               if (member) {
> +               if (name && member) {
>                         if (ENABLE_ADDGROUP && applet_name[0] == 'a')
>                                 bb_error_msg("can't find %s in %s",
> name, filename);
>                         if (ENABLE_DELGROUP && applet_name[0] == 'd')
> diff --git a/loginutils/deluser.c b/loginutils/deluser.c
> index 01a9386..a3f5f3a 100644
> --- a/loginutils/deluser.c
> +++ b/loginutils/deluser.c
> @@ -82,6 +82,9 @@ int deluser_main(int argc, char **argv)
>   do_delgroup:
>                         /* "delgroup GROUP" or "delgroup USER GROUP" */
>                         if (do_deluser < 0) { /* delgroup after deluser? */
> +                pfile = bb_path_group_file;
> +                if (update_passwd(pfile, NULL, NULL, name) == -1)
> +                    return EXIT_FAILURE;
>                                 gr = getgrnam(name);
>                                 if (!gr)
>                                         return EXIT_SUCCESS;
> @@ -99,7 +102,6 @@ int deluser_main(int argc, char **argv)
>                                 }
>                                 //endpwent();
>                         }
> -                       pfile = bb_path_group_file;
>                         if (ENABLE_FEATURE_SHADOWPASSWDS)
>                                 sfile = bb_path_gshadow_file;
>                 }
> --
> 2.3.0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic