summaryrefslogtreecommitdiffstats
path: root/usr.bin/catman
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2009-06-19 15:52:35 +0000
committerbrooks <brooks@FreeBSD.org>2009-06-19 15:52:35 +0000
commit384550a3864abef16c80a82c2fb12d9726aab2d1 (patch)
tree9401e3261148e3626d76925165c3bfacadb21dc2 /usr.bin/catman
parentc6677455d56812ea110b3ba54e183644a474a8c4 (diff)
downloadFreeBSD-src-384550a3864abef16c80a82c2fb12d9726aab2d1.zip
FreeBSD-src-384550a3864abef16c80a82c2fb12d9726aab2d1.tar.gz
When checking if we can write to a file, use access() instead of a
manual permission check based on stat output. Also, get rid of the executability check since it is not used. MFC after: 2 weeks
Diffstat (limited to 'usr.bin/catman')
-rw-r--r--usr.bin/catman/catman.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c
index ced6ae6..347e008 100644
--- a/usr.bin/catman/catman.c
+++ b/usr.bin/catman/catman.c
@@ -57,7 +57,6 @@ __FBSDID("$FreeBSD$");
#define TEST_FILE 0x04
#define TEST_READABLE 0x08
#define TEST_WRITABLE 0x10
-#define TEST_EXECUTABLE 0x20
static int verbose; /* -v flag: be verbose with warnings */
static int pretend; /* -n, -p flags: print out what would be done
@@ -92,9 +91,6 @@ static const char *locale_device[] = {
#define GZCAT_CMD "z"
enum Ziptype {NONE, BZIP, GZIP};
-static uid_t uid;
-static gid_t gids[NGROUPS_MAX];
-static int ngids;
static int starting_dir;
static char tmp_file[MAXPATHLEN];
struct stat test_st;
@@ -320,23 +316,10 @@ test_path(char *name, time_t *mod_time)
result |= TEST_DIR;
else if (S_ISREG(test_st.st_mode))
result |= TEST_FILE;
- if (test_st.st_uid == uid) {
- test_st.st_mode >>= 6;
- } else {
- int i;
- for (i = 0; i < ngids; i++) {
- if (test_st.st_gid == gids[i]) {
- test_st.st_mode >>= 3;
- break;
- }
- }
- }
- if (test_st.st_mode & S_IROTH)
+ if (access(name, R_OK))
result |= TEST_READABLE;
- if (test_st.st_mode & S_IWOTH)
+ if (access(name, W_OK))
result |= TEST_WRITABLE;
- if (test_st.st_mode & S_IXOTH)
- result |= TEST_EXECUTABLE;
return result;
}
@@ -759,14 +742,6 @@ main(int argc, char **argv)
{
int opt;
- if ((uid = getuid()) == 0) {
- fprintf(stderr, "don't run %s as root, use:\n echo", argv[0]);
- for (optind = 0; optind < argc; optind++) {
- fprintf(stderr, " %s", argv[optind]);
- }
- fprintf(stderr, " | nice -5 su -m man\n");
- exit(1);
- }
while ((opt = getopt(argc, argv, "vnfLrh")) != -1) {
switch (opt) {
case 'f':
@@ -789,7 +764,6 @@ main(int argc, char **argv)
/* NOTREACHED */
}
}
- ngids = getgroups(NGROUPS_MAX, gids);
if ((starting_dir = open(".", 0)) < 0) {
err(1, ".");
}
OpenPOWER on IntegriCloud