Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/chown/chown.c
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <fts.h> | #include <fts.h> | ||||
#include <grp.h> | #include <grp.h> | ||||
#include <libgen.h> | #include <libgen.h> | ||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stddef.h> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
static void a_gid(const char *); | static void a_gid(const char *); | ||||
static void a_uid(const char *); | static void a_uid(const char *); | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | a_uid(const char *s) | ||||
if (*s == '\0') /* Argument was "[:.]gid". */ | if (*s == '\0') /* Argument was "[:.]gid". */ | ||||
return; | return; | ||||
uid = ((pw = getpwnam(s)) != NULL) ? pw->pw_uid : id(s, "user"); | uid = ((pw = getpwnam(s)) != NULL) ? pw->pw_uid : id(s, "user"); | ||||
} | } | ||||
static uid_t | static uid_t | ||||
id(const char *name, const char *type) | id(const char *name, const char *type) | ||||
{ | { | ||||
uid_t val; | unsigned long val; | ||||
char *ep; | char *ep; | ||||
/* | |||||
* XXX | |||||
* We know that uid_t's and gid_t's are unsigned longs. | |||||
*/ | |||||
errno = 0; | errno = 0; | ||||
val = strtoul(name, &ep, 10); | val = strtoul(name, &ep, 10); | ||||
if (errno || *ep != '\0') | _Static_assert(UID_MAX >= GID_MAX, "UID MAX less than GID MAX"); | ||||
if (errno || *ep != '\0' || val > UID_MAX) | |||||
errx(1, "%s: illegal %s name", name, type); | errx(1, "%s: illegal %s name", name, type); | ||||
return (val); | return (val); | ||||
} | } | ||||
static void | static void | ||||
chownerr(const char *file) | chownerr(const char *file) | ||||
{ | { | ||||
static uid_t euid = -1; | static uid_t euid = -1; | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |