Date: Wed, 4 Sep 2002 16:30:06 -0700 (PDT) From: Juan Salaverria <rael@vectorstar.net> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/41817: pw groupshow doesn't include the login group Message-ID: <200209042330.g84NU6JG059347@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/41817; it has been noted by GNATS. From: Juan Salaverria <rael@vectorstar.net> To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: Re: misc/41817: pw groupshow doesn't include the login group Date: 04 Sep 2002 20:42:08 -0300 Hi Steve, I spent some time at weekend and made a patch to deal with this problem. Please take a look at it, I tested it with few users and it's working. If you found any problem just tell me and I'll work on it. Cheers, Juan diff -ruN usr.sbin/pw.ori/pw_group.c usr.sbin/pw/pw_group.c --- usr.sbin/pw.ori/pw_group.c Wed Jun 28 16:19:04 2000 +++ usr.sbin/pw/pw_group.c Mon Sep 2 09:10:20 2002 @@ -38,6 +38,7 @@ #include "bitmap.h" +static int chk_usrname(char ** mem, char * usr); static int print_group(struct group * grp, int pretty); static gid_t gr_gidpolicy(struct userconf * cnf, struct cargs * args); @@ -51,6 +52,12 @@ struct group *grp = NULL; int grmembers = 0; char **members = NULL; + int pwmembers = 0; + int idx = 0; + int idx_gr_mem = 0; + int last_gr_mem= 0; + struct passwd *usr_pass=NULL; + char **pass_mem= NULL; static struct group fakegroup = { @@ -95,6 +102,33 @@ } grp = (a_name != NULL) ? GETGRNAM(a_name->val) : GETGRGID((gid_t) atoi(a_gid->val)); + /* This is to take care of the initial groups defined in the passwd file */ + if (grp != NULL) { + extendarray(&pass_mem, &pwmembers, 200); + while (grp->gr_mem[idx] != NULL) ++idx; + last_gr_mem = idx; + + SETPWENT(); + idx = 0; + while ((usr_pass= GETPWENT()) != NULL) { + + if ( (gid_t) usr_pass->pw_gid == (gid_t) grp->gr_gid ) { + if (extendarray(&pass_mem, &pwmembers, idx + 2) != -1) { + pass_mem[idx] = malloc(strlen(usr_pass->pw_name)+1); + strcpy(pass_mem[idx], usr_pass->pw_name); + if (!chk_usrname(grp->gr_mem, pass_mem[idx])) { + grp->gr_mem[last_gr_mem+idx_gr_mem] = pass_mem[idx]; + idx_gr_mem++; + } + idx++; + } + } + } + pass_mem[idx] = NULL; + grp->gr_mem[last_gr_mem+idx_gr_mem] = NULL; + ENDPWENT(); + } + if (mode == M_UPDATE || mode == M_DELETE || mode == M_PRINT) { if (a_name == NULL && grp == NULL) /* Try harder */ grp = GETGRGID(atoi(a_gid->val)); @@ -349,4 +383,18 @@ fputs("\n\n", stdout); } return EXIT_SUCCESS; +} + +static int +chk_usrname(char ** mem, char * usr) +{ +int u = 0; + + while (mem[u] != NULL) { + if(!strcmp(mem[u],usr)) + return 1; + u++; + } + +return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209042330.g84NU6JG059347>