aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-09-19 17:18:43 +0000
committerRoy Marples <roy@marples.name>2007-09-19 17:18:43 +0000
commitc1cd1da59567d4f489d000cfdbc4faba31baf83b (patch)
treea5f3bcefeae7631462b7ad2f676d9e021984904e
parent50ea72ef4b7ab71823cd8421cc8fbaa63a4407e5 (diff)
Warn if file/directory mismatch
-rw-r--r--src/checkown.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/checkown.c b/src/checkown.c
index 7b96d128..9402b8af 100644
--- a/src/checkown.c
+++ b/src/checkown.c
@@ -25,13 +25,13 @@
static char *applet = NULL;
-static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, bool file)
+static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, int file)
{
- struct stat dirstat;
+ struct stat st;
- memset (&dirstat, 0, sizeof (dirstat));
+ memset (&st, 0, sizeof (struct stat));
- if (stat (path, &dirstat)) {
+ if (stat (path, &st)) {
if (file) {
int fd;
einfo ("%s: creating file", path);
@@ -50,9 +50,19 @@ static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, bool file)
}
mode = 0;
}
+ } else {
+ if ((file && S_ISDIR (st.st_mode)) ||
+ (! file && ! S_ISDIR (st.st_mode)))
+ {
+ if (file)
+ eerror ("%s: is a directory", path);
+ else
+ eerror ("%s: is a file", path);
+ return (-1);
+ }
}
- if (mode && (dirstat.st_mode & 0777) != mode) {
+ if (mode && (st.st_mode & 0777) != mode) {
einfo ("%s: correcting mode", applet);
if (chmod (path, mode)) {
eerror ("%s: chmod: %s", applet, strerror (errno));
@@ -60,8 +70,8 @@ static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, bool file)
}
}
- if (dirstat.st_uid != uid || dirstat.st_gid != gid) {
- if (dirstat.st_dev || dirstat.st_ino)
+ if (st.st_uid != uid || st.st_gid != gid) {
+ if (st.st_dev || st.st_ino)
einfo ("%s: correcting owner", path);
if (chown (path, uid, gid)) {
eerror ("%s: chown: %s", applet, strerror (errno));