mirror of
https://github.com/shadow-maint/shadow.git
synced 2024-11-27 03:53:59 +08:00
lib/port.c: getportent(): Use strsep(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
882db57f24
commit
cee79c215a
36
lib/port.c
36
lib/port.c
@ -100,7 +100,7 @@ getportent(void)
|
||||
int dtime;
|
||||
int i, j;
|
||||
int saveerr;
|
||||
char *cp;
|
||||
char *cp, *field;
|
||||
|
||||
static char buf[BUFSIZ];
|
||||
static char *ttys[PORT_TTY + 1];
|
||||
@ -144,6 +144,8 @@ next:
|
||||
|
||||
stpcpy(strchrnul(buf, '\n'), "");
|
||||
|
||||
field = buf;
|
||||
|
||||
/*
|
||||
* Get the name of the TTY device. It is the first colon
|
||||
* separated field, and is the name of the TTY with no
|
||||
@ -151,24 +153,20 @@ next:
|
||||
* TTY devices.
|
||||
*/
|
||||
|
||||
if (strchr(buf, ':') == NULL)
|
||||
cp = strsep(&field, ":");
|
||||
if (field == NULL)
|
||||
goto next;
|
||||
|
||||
port.pt_names = ttys;
|
||||
for (cp = buf, j = 0; j < PORT_TTY; j++) {
|
||||
port.pt_names[j] = cp;
|
||||
cp = strpbrk(cp, ":,");
|
||||
if (':' == *cp)
|
||||
for (j = 0; j < PORT_TTY; j++) {
|
||||
port.pt_names[j] = strsep(&cp, ",");
|
||||
if (cp == NULL)
|
||||
break;
|
||||
if (',' == *cp)
|
||||
stpcpy(cp++, "");
|
||||
}
|
||||
port.pt_names[j] = NULL;
|
||||
if (':' != *cp)
|
||||
if (cp != NULL)
|
||||
goto next;
|
||||
|
||||
stpcpy(cp++, "");
|
||||
|
||||
/*
|
||||
* Get the list of user names. It is the second colon
|
||||
* separated field, and is a comma separated list of user
|
||||
@ -176,24 +174,20 @@ next:
|
||||
* The last entry in the list is a NULL pointer.
|
||||
*/
|
||||
|
||||
if (strchr(cp, ':') == NULL)
|
||||
cp = strsep(&field, ":");
|
||||
if (field == NULL)
|
||||
goto next;
|
||||
|
||||
port.pt_users = users;
|
||||
for (j = 0; j < PORT_IDS; j++) {
|
||||
port.pt_users[j] = cp;
|
||||
cp = strpbrk(cp, ":,");
|
||||
if (':' == *cp)
|
||||
port.pt_users[j] = strsep(&cp, ",");
|
||||
if (cp == NULL)
|
||||
break;
|
||||
if (',' == *cp)
|
||||
stpcpy(cp++, "");
|
||||
}
|
||||
port.pt_users[j] = NULL;
|
||||
if (':' != *cp)
|
||||
if (cp != NULL)
|
||||
goto next;
|
||||
|
||||
stpcpy(cp++, "");
|
||||
|
||||
/*
|
||||
* Get the list of valid times. The times field is the third
|
||||
* colon separated field and is a list of days of the week and
|
||||
@ -207,6 +201,8 @@ next:
|
||||
* the starting time. Days are presumed to wrap at 0000.
|
||||
*/
|
||||
|
||||
cp = field;
|
||||
|
||||
if ('\0' == *cp) {
|
||||
port.pt_times = 0;
|
||||
return &port;
|
||||
|
Loading…
Reference in New Issue
Block a user