Skip to content

Commit

Permalink
libnss_mxshadow: Use sgetspent_
Browse files Browse the repository at this point in the history
Use sgetspent_r instead of own parsing.
  • Loading branch information
donald committed May 7, 2021
1 parent 6441fa8 commit 73c5ddd
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions libnss_mxshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
#include "get_shadow_line.h"
#include "common.h"

static long int atol_or_minus1(char *p) {
return *p == '\0' ? -1 : atol(p);
}

static unsigned long int atoul_or_minus1(char *p) {
return *p == '\0' ? (unsigned long int) -1 : strtoul(p, NULL, 10);
}

enum nss_status _nss_mxshadow_getspnam_r(const char *name, struct spwd *spwd, char *buffer, size_t buflen, int *errnop) {

char *line _cleanup_(free_string) = NULL;
Expand All @@ -31,30 +23,16 @@ enum nss_status _nss_mxshadow_getspnam_r(const char *name, struct spwd *spwd, ch
*errnop = errno;
return NSS_STATUS_UNAVAIL;
}
size_t len = strlen(line);
if (buflen < len+1) {
errno = ERANGE;
*errnop = errno;
return -1;
}
strcpy(buffer, line);

if (buffer[0] == '\0') {
if (line[0] == '\0') {
errno = ENOENT;
*errnop = errno;
return NSS_STATUS_NOTFOUND;
}

char *p;

p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_namp = p;
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_pwdp = p;
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_lstchg = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_min = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_max = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_warn = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_inact = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_expire = atol_or_minus1(p);
p = strsep(&buffer, ":"); if (p == NULL) return NSS_STATUS_NOTFOUND; spwd->sp_flag = atoul_or_minus1(p);
struct spwd *spbufp;
status = sgetspent_r(line, spwd, buffer, buflen, &spbufp);
if (status == -1) {
*errnop = errno;
return NSS_STATUS_UNAVAIL;
}
return NSS_STATUS_SUCCESS;
}

0 comments on commit 73c5ddd

Please sign in to comment.