char *project)
{
fs_project_t *prj;
- prid_t prid;
+ unsigned long prid_long;
char *sp;
/*
* Allow either a full numeric or a valid projectname, even
* if it starts with a digit.
*/
- prid = (prid_t)strtoul(project, &sp, 10);
- if (*project != '\0' && *sp == '\0')
- return prid;
+ prid_long = strtoul(project, &sp, 10);
+ if (*project != '\0' && *sp == '\0') {
+ if ((prid_long == ULONG_MAX && errno == ERANGE)
+ || (prid_long > (prid_t)-1))
+ return -1;
+ return (prid_t)prid_long;
+ }
prj = getprnam(project);
if (prj)
return prj->pr_prid;
char *user)
{
struct passwd *pwd;
- uid_t uid;
+ unsigned long uid_long;
char *sp;
- uid = (uid_t)strtoul(user, &sp, 10);
- if (sp != user)
- return uid;
+ uid_long = strtoul(user, &sp, 10);
+ if (sp != user) {
+ if ((uid_long == ULONG_MAX && errno == ERANGE)
+ || (uid_long > (uid_t)-1))
+ return -1;
+ return (uid_t)uid_long;
+ }
pwd = getpwnam(user);
if (pwd)
return pwd->pw_uid;
char *group)
{
struct group *grp;
- gid_t gid;
+ unsigned long gid_long;
char *sp;
- gid = (gid_t)strtoul(group, &sp, 10);
- if (sp != group)
- return gid;
+ gid_long = strtoul(group, &sp, 10);
+ if (sp != group) {
+ if ((gid_long == ULONG_MAX && errno == ERANGE)
+ || (gid_long > (gid_t)-1))
+ return -1;
+ return (gid_t)gid_long;
+ }
grp = getgrnam(group);
if (grp)
return grp->gr_gid;
count++;
}
- printf(_("Processed %d (%s and cmdline) paths for project %s with recursion depth %s (%d).\n"),
+ printf(_("Processed %d (%s and cmdline) paths for project %s with "
+ "recursion depth %s (%d).\n"),
count, projects_file, project,
recurse_depth < 0 ? _("infinite") : _("limited"), recurse_depth);
}
if (ispath && argc - optind > 1) {
exitcode = 1;
- fprintf(stderr, _("%s: only one projid/name can be specified when using -p <path>, %d found.\n"),
- progname, argc - optind);
+ fprintf(stderr, _("%s: only one projid/name can be specified "
+ "when using -p <path>, %d found.\n"),
+ progname, argc - optind);
return 0;
}
prid = prid_from_string(argv[optind]);
if (prid == -1) {
exitcode = 1;
- fprintf(stderr, _("%s - no such project in %s\n"),
+ fprintf(stderr, _("%s - no such project in %s "
+ "or invalid project number\n"),
argv[optind], projects_file);
} else
project(argv[optind], type);