/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)pw_scan.c 8.3 (Berkeley) 4/2/94";
-#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
+__SCCSID("@(#)pw_scan.c 8.3 (Berkeley) 4/2/94");
__FBSDID("$FreeBSD$");
/*
#include <err.h>
#include <errno.h>
-#include <fcntl.h>
#include <pwd.h>
-#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
*
* If pw_big_ids_warning is -1 on entry to pw_scan(), it will be set based
* on the existence of PW_SCAN_BIG_IDS in the environment.
+ *
+ * It is believed all baseline system software that can not handle the
+ * normal ID sizes is now gone so pw_big_ids_warning is disabled for now.
+ * But the code has been left in place in case end-users want to re-enable
+ * it and/or for the next time the ID sizes get bigger but pieces of the
+ * system lag behind.
*/
-static int pw_big_ids_warning = -1;
+static int pw_big_ids_warning = 0;
int
__pw_scan(char *bp, struct passwd *pw, int flags)
uid_t id;
int root;
char *ep, *p, *sh;
+ unsigned long temp;
if (pw_big_ids_warning == -1)
pw_big_ids_warning = getenv("PW_SCAN_BIG_IDS") == NULL ? 1 : 0;
return (0);
}
}
- id = strtoul(p, &ep, 10);
- if (errno == ERANGE) {
+ errno = 0;
+ temp = strtoul(p, &ep, 10);
+ if ((temp == ULONG_MAX && errno == ERANGE) || temp > UID_MAX) {
if (flags & _PWSCAN_WARN)
- warnx("%s > max uid value (%lu)", p, ULONG_MAX);
+ warnx("%s > max uid value (%u)", p, UID_MAX);
return (0);
}
+ id = temp;
if (*ep != '\0') {
if (flags & _PWSCAN_WARN)
warnx("%s uid is incorrect", p);
return (0);
}
}
- id = strtoul(p, &ep, 10);
- if (errno == ERANGE) {
+ errno = 0;
+ temp = strtoul(p, &ep, 10);
+ if ((temp == ULONG_MAX && errno == ERANGE) || temp > GID_MAX) {
if (flags & _PWSCAN_WARN)
- warnx("%s > max gid value (%lu)", p, ULONG_MAX);
+ warnx("%s > max gid value (%u)", p, GID_MAX);
return (0);
}
+ id = temp;
if (*ep != '\0') {
if (flags & _PWSCAN_WARN)
warnx("%s gid is incorrect", p);
if (p[0])
pw->pw_fields |= _PWF_EXPIRE;
pw->pw_expire = atol(p);
- }
+ } else
+ pw->pw_class = NULL;
if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */
goto fmt;
if (pw->pw_gecos[0])