Some patches from Todd C. Miller:
1. Use REG_NEWLINE, rather than matching "\n". 2. Fix a bug where rm_user_from_groups would mangle group entries in /etc/group when the user to be removed is the only member of the group, by using substring matches.
This commit is contained in:
parent
52e8cddd9b
commit
65feb98718
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $ */
|
/* $NetBSD: user.c,v 1.70 2003/06/12 17:00:53 agc Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
|
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__COPYRIGHT("@(#) Copyright (c) 1999 \
|
__COPYRIGHT("@(#) Copyright (c) 1999 \
|
||||||
The NetBSD Foundation, Inc. All rights reserved.");
|
The NetBSD Foundation, Inc. All rights reserved.");
|
||||||
__RCSID("$NetBSD: user.c,v 1.69 2003/04/14 17:40:07 agc Exp $");
|
__RCSID("$NetBSD: user.c,v 1.70 2003/06/12 17:00:53 agc Exp $");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -1149,8 +1149,8 @@ rm_user_from_groups(char *login_name)
|
||||||
int cc;
|
int cc;
|
||||||
int sc;
|
int sc;
|
||||||
|
|
||||||
(void) snprintf(line, sizeof(line), "(:|,)%s(,|\n|$)", login_name);
|
(void) snprintf(line, sizeof(line), "(:|,)(%s)(,|$)", login_name);
|
||||||
if (regcomp(&r, line, REG_EXTENDED) != 0) {
|
if (regcomp(&r, line, REG_EXTENDED|REG_NEWLINE) != 0) {
|
||||||
warn("can't compile regular expression `%s'", line);
|
warn("can't compile regular expression `%s'", line);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1178,14 +1178,15 @@ rm_user_from_groups(char *login_name)
|
||||||
while (fgets(buf, sizeof(buf), from) > 0) {
|
while (fgets(buf, sizeof(buf), from) > 0) {
|
||||||
cc = strlen(buf);
|
cc = strlen(buf);
|
||||||
if (regexec(&r, buf, 10, matchv, 0) == 0) {
|
if (regexec(&r, buf, 10, matchv, 0) == 0) {
|
||||||
cc -= (int)(matchv[0].rm_eo);
|
if (buf[(int)matchv[1].rm_so] == ',') {
|
||||||
sc = (int) matchv[0].rm_so;
|
matchv[2].rm_so = matchv[1].rm_so;
|
||||||
if (cc > 0) {
|
} else if (matchv[2].rm_eo != matchv[3].rm_eo) {
|
||||||
sc += 1;
|
matchv[2].rm_eo = matchv[3].rm_eo;
|
||||||
}
|
}
|
||||||
|
cc -= (int) matchv[2].rm_eo;
|
||||||
|
sc = (int) matchv[2].rm_so;
|
||||||
if (fwrite(buf, sizeof(char), sc, to) != sc ||
|
if (fwrite(buf, sizeof(char), sc, to) != sc ||
|
||||||
fwrite(&buf[(int)matchv[0].rm_eo], sizeof(char), cc, to) != cc ||
|
fwrite(&buf[(int)matchv[2].rm_eo], sizeof(char), cc, to) != cc) {
|
||||||
(buf[(int)matchv[0].rm_eo - 1] != ',' && fwrite("\n", sizeof(char), 1, to) != 1)) {
|
|
||||||
(void) fclose(from);
|
(void) fclose(from);
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
(void) unlink(f);
|
(void) unlink(f);
|
||||||
|
|
Loading…
Reference in New Issue