-/* $OpenBSD: passwd.c,v 1.5 1996/12/06 01:55:33 deraadt Exp $ */
+/* $OpenBSD: passwd.c,v 1.6 1997/02/13 05:41:38 deraadt Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
* The Regents of the University of California. All rights reserved.
struct passwd *pw;
int *flags;
{
- long id;
+ u_long id;
int root;
- char *p, *sh;
+ char *p, *sh, *p2;
if (flags != (int *)NULL)
*flags = 0;
if (!(p = strsep(&bp, ":"))) /* uid */
goto fmt;
- id = atol(p);
+ id = strtoul(p, &p2, 10);
if (root && id) {
warnx("root uid should be 0");
return (0);
}
- if (id > USHRT_MAX) {
- warnx("%s > max uid value (%d)", p, USHRT_MAX);
+ if (*p2 != ':') {
+ warnx("illegal uid field");
return (0);
}
- pw->pw_uid = id;
+ if (id >= UINT_MAX) {
+ /* errno is set to ERANGE by strtoul(3) */
+ warnx("uid greater than %u", UINT_MAX-1);
+ return (0);
+ }
+ pw->pw_uid = (uid_t)id;
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOUID;
if (!(p = strsep(&bp, ":"))) /* gid */
goto fmt;
- id = atol(p);
- if (id > USHRT_MAX) {
- warnx("%s > max gid value (%d)", p, USHRT_MAX);
+ id = strtoul(p, &p2, 10);
+ if (*p2 != ':') {
+ warnx("illegal gid field");
+ return (0);
+ }
+ if (id > UINT_MAX) {
+ /* errno is set to ERANGE by strtoul(3) */
+ warnx("gid greater than %u", UINT_MAX-1);
return (0);
}
- pw->pw_gid = id;
+ pw->pw_gid = (gid_t)id;
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOGID;