Make ``wall -g'' really DTRT.
Reviewed by: imp, markm
This commit is contained in:
parent
c2e6dd76ce
commit
2cfec5ade4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83082
@ -87,18 +87,16 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
struct utmp utmp;
|
struct utmp utmp;
|
||||||
gid_t grps[NGROUPS_MAX];
|
|
||||||
int ch;
|
int ch;
|
||||||
int ingroup, ngrps, i;
|
int ingroup;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct wallgroup *g;
|
struct wallgroup *g;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
char *p;
|
char *p, **np;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
char line[sizeof(utmp.ut_line) + 1];
|
char line[sizeof(utmp.ut_line) + 1];
|
||||||
char username[sizeof(utmp.ut_name) + 1];
|
char username[sizeof(utmp.ut_name) + 1];
|
||||||
|
|
||||||
ingroup = 0;
|
|
||||||
(void)setlocale(LC_CTYPE, "");
|
(void)setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "g:n")) != -1)
|
while ((ch = getopt(argc, argv, "g:n")) != -1)
|
||||||
@ -144,19 +142,24 @@ main(int argc, char *argv[])
|
|||||||
!strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name)))
|
!strncmp(utmp.ut_name, IGNOREUSER, sizeof(utmp.ut_name)))
|
||||||
continue;
|
continue;
|
||||||
if (grouplist) {
|
if (grouplist) {
|
||||||
|
ingroup = 0;
|
||||||
strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name));
|
strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name));
|
||||||
pw = getpwnam(username);
|
pw = getpwnam(username);
|
||||||
if (!pw)
|
if (!pw)
|
||||||
continue;
|
continue;
|
||||||
ngrps = getgroups(pw->pw_gid, grps);
|
|
||||||
for (g = grouplist; g && ingroup == 0; g = g->next) {
|
for (g = grouplist; g && ingroup == 0; g = g->next) {
|
||||||
if (g->gid == -1)
|
if (g->gid == -1)
|
||||||
continue;
|
continue;
|
||||||
if (g->gid == pw->pw_gid)
|
if (g->gid == pw->pw_gid)
|
||||||
ingroup = 1;
|
ingroup = 1;
|
||||||
for (i = 0; i < ngrps && ingroup == 0; i++)
|
else if ((grp = getgrgid(g->gid)) != NULL) {
|
||||||
if (g->gid == grps[i])
|
for (np = grp->gr_mem; *np; np++) {
|
||||||
ingroup = 1;
|
if (strcmp(*np, username) == 0) {
|
||||||
|
ingroup = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ingroup == 0)
|
if (ingroup == 0)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user