summaryrefslogtreecommitdiffstats
path: root/lib/sgetspent.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:36 +0000
commit6c3ea4f47ea280811a7fe53a22f7832e4533c9ec (patch)
tree3d7ed5da23b5dbf6f9e450dfb61642832249c31e /lib/sgetspent.c
parentAdding upstream version 1:4.13+dfsg1. (diff)
downloadshadow-6c3ea4f47ea280811a7fe53a22f7832e4533c9ec.tar.xz
shadow-6c3ea4f47ea280811a7fe53a22f7832e4533c9ec.zip
Adding upstream version 1:4.15.2.upstream/1%4.15.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/sgetspent.c')
-rw-r--r--lib/sgetspent.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/lib/sgetspent.c b/lib/sgetspent.c
index f1d4b20..bd2ef8b 100644
--- a/lib/sgetspent.c
+++ b/lib/sgetspent.c
@@ -14,17 +14,26 @@
#ident "$Id$"
+#include <stddef.h>
+#include <stdio.h>
#include <sys/types.h>
+#include <string.h>
+
+#include "atoi/str2i.h"
#include "prototypes.h"
#include "shadowlog_internal.h"
#include "defines.h"
-#include <stdio.h>
+
+
#define FIELDS 9
#define OFIELDS 5
+
+
/*
* sgetspent - convert string in shadow file format to (struct spwd *)
*/
-struct spwd *sgetspent (const char *string)
+struct spwd *
+sgetspent(const char *string)
{
static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
static struct spwd spwd;
@@ -41,7 +50,7 @@ struct spwd *sgetspent (const char *string)
fprintf (shadow_logfd,
"%s: Too long passwd entry encountered, file corruption?\n",
shadow_progname);
- return 0; /* fail if too long */
+ return NULL; /* fail if too long */
}
strcpy (spwbuf, string);
@@ -57,9 +66,7 @@ struct spwd *sgetspent (const char *string)
for (cp = spwbuf, i = 0; ('\0' != *cp) && (i < FIELDS); i++) {
fields[i] = cp;
- while (('\0' != *cp) && (':' != *cp)) {
- cp++;
- }
+ cp = strchrnul(cp, ':');
if ('\0' != *cp) {
*cp = '\0';
@@ -67,13 +74,12 @@ struct spwd *sgetspent (const char *string)
}
}
- if (i == (FIELDS - 1)) {
- fields[i++] = cp;
- }
+ if (i == (FIELDS - 1))
+ fields[i++] = "";
if ( ((NULL != cp) && ('\0' != *cp)) ||
((i != FIELDS) && (i != OFIELDS)) ) {
- return 0;
+ return NULL;
}
/*
@@ -92,9 +98,9 @@ struct spwd *sgetspent (const char *string)
if (fields[2][0] == '\0') {
spwd.sp_lstchg = -1;
- } else if ( (getlong (fields[2], &spwd.sp_lstchg) == 0)
+ } else if ( (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
|| (spwd.sp_lstchg < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -103,9 +109,9 @@ struct spwd *sgetspent (const char *string)
if (fields[3][0] == '\0') {
spwd.sp_min = -1;
- } else if ( (getlong (fields[3], &spwd.sp_min) == 0)
+ } else if ( (str2sl(&spwd.sp_min, fields[3]) == -1)
|| (spwd.sp_min < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -114,9 +120,9 @@ struct spwd *sgetspent (const char *string)
if (fields[4][0] == '\0') {
spwd.sp_max = -1;
- } else if ( (getlong (fields[4], &spwd.sp_max) == 0)
+ } else if ( (str2sl(&spwd.sp_max, fields[4]) == -1)
|| (spwd.sp_max < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -139,9 +145,9 @@ struct spwd *sgetspent (const char *string)
if (fields[5][0] == '\0') {
spwd.sp_warn = -1;
- } else if ( (getlong (fields[5], &spwd.sp_warn) == 0)
+ } else if ( (str2sl(&spwd.sp_warn, fields[5]) == -1)
|| (spwd.sp_warn < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -151,9 +157,9 @@ struct spwd *sgetspent (const char *string)
if (fields[6][0] == '\0') {
spwd.sp_inact = -1;
- } else if ( (getlong (fields[6], &spwd.sp_inact) == 0)
+ } else if ( (str2sl(&spwd.sp_inact, fields[6]) == -1)
|| (spwd.sp_inact < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -163,9 +169,9 @@ struct spwd *sgetspent (const char *string)
if (fields[7][0] == '\0') {
spwd.sp_expire = -1;
- } else if ( (getlong (fields[7], &spwd.sp_expire) == 0)
+ } else if ( (str2sl(&spwd.sp_expire, fields[7]) == -1)
|| (spwd.sp_expire < 0)) {
- return 0;
+ return NULL;
}
/*
@@ -175,13 +181,12 @@ struct spwd *sgetspent (const char *string)
if (fields[8][0] == '\0') {
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
- } else if (getulong (fields[8], &spwd.sp_flag) == 0) {
- return 0;
+ } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
+ return NULL;
}
return (&spwd);
}
#else
-extern int errno; /* warning: ANSI C forbids an empty source file */
+extern int ISO_C_forbids_an_empty_translation_unit;
#endif
-