Fix various unsigned vs signed errors that caused problems with uids
and gids bigger than 16 bits. Added checks for uids and gids that are bigger than 32 bits. Approved by: jkh (partly, this fix is bigger than I first intended)
This commit is contained in:
parent
3c1124cfdf
commit
cd7b8d78c7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=57868
@ -47,6 +47,7 @@ static const char rcsid[] =
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -72,7 +73,7 @@ pw_scan(bp, pw)
|
|||||||
char *bp;
|
char *bp;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
{
|
{
|
||||||
long id;
|
uid_t id;
|
||||||
int root;
|
int root;
|
||||||
char *p, *sh;
|
char *p, *sh;
|
||||||
|
|
||||||
@ -100,13 +101,17 @@ pw_scan(bp, pw)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id = atol(p);
|
id = strtoul(p, (char **)NULL, 10);
|
||||||
|
if (errno == ERANGE) {
|
||||||
|
warnx("%s > max uid value (%u)", p, ULONG_MAX);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
if (root && id) {
|
if (root && id) {
|
||||||
warnx("root uid should be 0");
|
warnx("root uid should be 0");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||||
warnx("%s > max uid value (%u)", p, USHRT_MAX);
|
warnx("%s > recommended max uid value (%u)", p, USHRT_MAX);
|
||||||
/*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
|
/*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
|
||||||
}
|
}
|
||||||
pw->pw_uid = id;
|
pw->pw_uid = id;
|
||||||
@ -114,9 +119,13 @@ pw_scan(bp, pw)
|
|||||||
if (!(p = strsep(&bp, ":"))) /* gid */
|
if (!(p = strsep(&bp, ":"))) /* gid */
|
||||||
goto fmt;
|
goto fmt;
|
||||||
if(p[0]) pw->pw_fields |= _PWF_GID;
|
if(p[0]) pw->pw_fields |= _PWF_GID;
|
||||||
id = atol(p);
|
id = strtoul(p, (char **)NULL, 10);
|
||||||
|
if (errno == ERANGE) {
|
||||||
|
warnx("%s > max gid value (%u)", p, ULONG_MAX);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||||
warnx("%s > max gid value (%u)", p, USHRT_MAX);
|
warnx("%s > recommended max gid value (%u)", p, USHRT_MAX);
|
||||||
/* return (0); This should not be fatal! */
|
/* return (0); This should not be fatal! */
|
||||||
}
|
}
|
||||||
pw->pw_gid = id;
|
pw->pw_gid = id;
|
||||||
|
@ -47,6 +47,7 @@ static const char rcsid[] =
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -72,7 +73,7 @@ pw_scan(bp, pw)
|
|||||||
char *bp;
|
char *bp;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
{
|
{
|
||||||
long id;
|
uid_t id;
|
||||||
int root;
|
int root;
|
||||||
char *p, *sh;
|
char *p, *sh;
|
||||||
|
|
||||||
@ -100,13 +101,17 @@ pw_scan(bp, pw)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id = atol(p);
|
id = strtoul(p, (char **)NULL, 10);
|
||||||
|
if (errno == ERANGE) {
|
||||||
|
warnx("%s > max uid value (%u)", p, ULONG_MAX);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
if (root && id) {
|
if (root && id) {
|
||||||
warnx("root uid should be 0");
|
warnx("root uid should be 0");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||||
warnx("%s > max uid value (%u)", p, USHRT_MAX);
|
warnx("%s > recommended max uid value (%u)", p, USHRT_MAX);
|
||||||
/*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
|
/*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
|
||||||
}
|
}
|
||||||
pw->pw_uid = id;
|
pw->pw_uid = id;
|
||||||
@ -114,9 +119,13 @@ pw_scan(bp, pw)
|
|||||||
if (!(p = strsep(&bp, ":"))) /* gid */
|
if (!(p = strsep(&bp, ":"))) /* gid */
|
||||||
goto fmt;
|
goto fmt;
|
||||||
if(p[0]) pw->pw_fields |= _PWF_GID;
|
if(p[0]) pw->pw_fields |= _PWF_GID;
|
||||||
id = atol(p);
|
id = strtoul(p, (char **)NULL, 10);
|
||||||
|
if (errno == ERANGE) {
|
||||||
|
warnx("%s > max gid value (%u)", p, ULONG_MAX);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
if (pw_big_ids_warning && id > USHRT_MAX) {
|
if (pw_big_ids_warning && id > USHRT_MAX) {
|
||||||
warnx("%s > max gid value (%u)", p, USHRT_MAX);
|
warnx("%s > recommended max gid value (%u)", p, USHRT_MAX);
|
||||||
/* return (0); This should not be fatal! */
|
/* return (0); This should not be fatal! */
|
||||||
}
|
}
|
||||||
pw->pw_gid = id;
|
pw->pw_gid = id;
|
||||||
|
@ -320,9 +320,9 @@ main(argc, argv)
|
|||||||
p = buf;
|
p = buf;
|
||||||
COMPACT(pwd.pw_name);
|
COMPACT(pwd.pw_name);
|
||||||
COMPACT("*");
|
COMPACT("*");
|
||||||
memmove(p, &pwd.pw_uid, sizeof(int));
|
memmove(p, &pwd.pw_uid, sizeof(pwd.pw_uid));
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
memmove(p, &pwd.pw_gid, sizeof(int));
|
memmove(p, &pwd.pw_gid, sizeof(pwd.pw_gid));
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
memmove(p, &pwd.pw_change, sizeof(time_t));
|
memmove(p, &pwd.pw_change, sizeof(time_t));
|
||||||
p += sizeof(time_t);
|
p += sizeof(time_t);
|
||||||
@ -340,9 +340,9 @@ main(argc, argv)
|
|||||||
p = sbuf;
|
p = sbuf;
|
||||||
COMPACT(pwd.pw_name);
|
COMPACT(pwd.pw_name);
|
||||||
COMPACT(pwd.pw_passwd);
|
COMPACT(pwd.pw_passwd);
|
||||||
memmove(p, &pwd.pw_uid, sizeof(int));
|
memmove(p, &pwd.pw_uid, sizeof(pwd.pw_uid));
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
memmove(p, &pwd.pw_gid, sizeof(int));
|
memmove(p, &pwd.pw_gid, sizeof(pwd.pw_gid));
|
||||||
p += sizeof(int);
|
p += sizeof(int);
|
||||||
memmove(p, &pwd.pw_change, sizeof(time_t));
|
memmove(p, &pwd.pw_change, sizeof(time_t));
|
||||||
p += sizeof(time_t);
|
p += sizeof(time_t);
|
||||||
@ -420,8 +420,8 @@ main(argc, argv)
|
|||||||
char uidstr[20];
|
char uidstr[20];
|
||||||
char gidstr[20];
|
char gidstr[20];
|
||||||
|
|
||||||
snprintf(uidstr, sizeof(uidstr), "%d", pwd.pw_uid);
|
snprintf(uidstr, sizeof(uidstr), "%u", pwd.pw_uid);
|
||||||
snprintf(gidstr, sizeof(gidstr), "%d", pwd.pw_gid);
|
snprintf(gidstr, sizeof(gidstr), "%u", pwd.pw_gid);
|
||||||
|
|
||||||
if (fprintf(oldfp, "%s:*:%s:%s:%s:%s:%s\n",
|
if (fprintf(oldfp, "%s:*:%s:%s:%s:%s:%s\n",
|
||||||
pwd.pw_name, pwd.pw_fields & _PWF_UID ? uidstr : "",
|
pwd.pw_name, pwd.pw_fields & _PWF_UID ? uidstr : "",
|
||||||
|
Loading…
Reference in New Issue
Block a user