+static uid_t
+parseuser (const char *id, const char *progname)
+{
+
+ struct passwd *pwd;
+
+ errno = 0;
+ pwd = getpwnam (id);
+
+ if (NULL == pwd) {
+ if (errno != 0) {
+ fprintf (stderr, "Error looking up user: %m\n");
+ exit (EXIT_FAILURE);
+ }
+
+ long val;
+ int err = xstrtol (id, NULL, 10, &val, "");
+ if (err != LONGINT_OK) {
+ fprintf (stderr, "%s is not a valid user name or uid\n", id);
+ usage (stderr, progname);
+ exit (EXIT_FAILURE);
+ }
+
+ return (uid_t) val;
+ }
+
+ return pwd->pw_uid;
+}
+
+static gid_t
+parsegroup (const char *id, const char *progname)
+{
+
+ struct group *grp;
+
+ errno = 0;
+ grp = getgrnam (id);
+
+ if (NULL == grp) {
+ if (errno != 0) {
+ fprintf (stderr, "Error looking up group: %m\n");
+ exit (EXIT_FAILURE);
+ }
+
+ long val;
+ int err = xstrtol (id, NULL, 10, &val, "");
+ if (err != LONGINT_OK) {
+ fprintf (stderr, "%s is not a valid group name or gid\n", id);
+ usage (stderr, progname);
+ exit (EXIT_FAILURE);
+ }
+
+ return (gid_t) val;
+ }
+
+ return grp->gr_gid;
+}
+