src/suauth.c: check_su_auth(): Use stpsep() to simplify

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-07-03 23:41:16 +02:00
committed by Serge Hallyn
parent 64409c28b7
commit 8714ac0cd6

View File

@@ -13,11 +13,13 @@
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "defines.h"
#include "prototypes.h"
#include "string/strchr/strrspn.h"
#include "string/strtok/stpsep.h"
#ifndef SUAUTHFILE
@@ -45,7 +47,7 @@ int check_su_auth (const char *actual_id,
const char *wanted_id,
bool su_to_root)
{
int posn, endline;
int posn;
const char field[] = ":";
FILE *authfile_fd;
char temp[1024];
@@ -72,23 +74,21 @@ int check_su_auth (const char *actual_id,
while (fgets (temp, sizeof (temp), authfile_fd) != NULL) {
lines++;
endline = strlen(temp) - 1;
if (temp[0] == '\0' || temp[endline] != '\n') {
if (stpsep(temp, "\n") == NULL) {
SYSLOG ((LOG_ERR,
"%s, line %d: line too long or missing newline",
SUAUTHFILE, lines));
continue;
}
stpcpy(strrspn(temp, " \t\n"), "");
stpcpy(strrspn(temp, " \t"), "");
posn = 0;
while (temp[posn] == ' ' || temp[posn] == '\t')
posn++;
if (temp[posn] == '\n' || temp[posn] == '#'
|| temp[posn] == '\0') {
if (temp[posn] == '#' || temp[posn] == '\0') {
continue;
}
if (!(to_users = strtok (temp + posn, field))