diff options
author | brian <brian@FreeBSD.org> | 2005-08-11 15:43:55 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2005-08-11 15:43:55 +0000 |
commit | 40ef73a9f6454eb3eafb4c3c5672b20380757b61 (patch) | |
tree | 039837d987097567dddb325e601f7421c20ad58d /usr.sbin/mtree | |
parent | 46873ef8115cee6e503e945addc66ab8e1457692 (diff) | |
download | FreeBSD-src-40ef73a9f6454eb3eafb4c3c5672b20380757b61.zip FreeBSD-src-40ef73a9f6454eb3eafb4c3c5672b20380757b61.tar.gz |
If we fail in chown(2), try to just change the group and continue on to
change the permissions. Failures are still recorded.
This allows mtree to do a generally better job of things when uid != 0.
Sponsored by: ActiveState/Sophos
Partially submitted by: neilw at ActiveState dot com
Reviewed by: neilw at ActiveState dot com
MFC after: 3 weeks
Diffstat (limited to 'usr.sbin/mtree')
-rw-r--r-- | usr.sbin/mtree/verify.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c index 7f2cf8db..cc31ea4 100644 --- a/usr.sbin/mtree/verify.c +++ b/usr.sbin/mtree/verify.c @@ -154,7 +154,8 @@ miss(NODE *p, char *tail) { int create; char *tp; - const char *type; + const char *type, *what; + int serr; for (; p; p = p->next) { if (p->type != F_DIR && (dflag || p->flags & F_VISIT)) @@ -191,9 +192,20 @@ miss(NODE *p, char *tail) strerror(errno)); else (void)printf(" (created)\n"); - if (lchown(path, p->st_uid, p->st_gid)) - (void)printf("%s: user/group not modified: %s\n", - path, strerror(errno)); + if (lchown(path, p->st_uid, p->st_gid) == -1) { + serr = errno; + if (p->st_uid == (uid_t)-1) + what = "group"; + else if (lchown(path, (uid_t)-1, + p->st_gid) == -1) + what = "user & group"; + else { + what = "user"; + errno = serr; + } + (void)printf("%s: %s not modified: %s" + "\n", path, what, strerror(errno)); + } continue; } else if (!(p->flags & F_MODE)) (void)printf(" (directory not created: mode not specified)"); @@ -215,12 +227,18 @@ miss(NODE *p, char *tail) if (!create) continue; - if (chown(path, p->st_uid, p->st_gid)) { - (void)printf("%s: user/group/mode not modified: %s\n", - path, strerror(errno)); - (void)printf("%s: warning: file mode %snot set\n", path, - (p->flags & F_FLAGS) ? "and file flags " : ""); - continue; + if (chown(path, p->st_uid, p->st_gid) == -1) { + serr = errno; + if (p->st_uid == (uid_t)-1) + what = "group"; + else if (chown(path, (uid_t)-1, p->st_gid) == -1) + what = "user & group"; + else { + what = "user"; + errno = serr; + } + (void)printf("%s: %s not modified: %s\n", + path, what, strerror(errno)); } if (chmod(path, p->st_mode)) (void)printf("%s: permissions not set: %s\n", |