From 40ef73a9f6454eb3eafb4c3c5672b20380757b61 Mon Sep 17 00:00:00 2001 From: brian Date: Thu, 11 Aug 2005 15:43:55 +0000 Subject: 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 --- usr.sbin/mtree/verify.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'usr.sbin/mtree') 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", -- cgit v1.1