diff --git a/contrib/mtree/mtree.h b/contrib/mtree/mtree.h --- a/contrib/mtree/mtree.h +++ b/contrib/mtree/mtree.h @@ -46,7 +46,9 @@ struct timespec st_mtimespec; /* last modification time */ char *slink; /* symbolic link reference */ uid_t st_uid; /* uid */ + char *uname; gid_t st_gid; /* gid */ + char *gname; #define MBITS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) mode_t st_mode; /* mode */ dev_t st_rdev; /* device type */ diff --git a/contrib/mtree/spec.c b/contrib/mtree/spec.c --- a/contrib/mtree/spec.c +++ b/contrib/mtree/spec.c @@ -342,7 +342,8 @@ nodetype(cur->type)); if (MATCHFLAG(F_UID | F_UNAME)) { if (keys & F_UNAME && - (name = user_from_uid(cur->st_uid, 1)) != NULL) + (name = cur->uname ? cur->uname : + user_from_uid(cur->st_uid, 1)) != NULL) appendfield(fp, pathlast, "uname=%s", name); else appendfield(fp, pathlast, "uid=%u", @@ -350,7 +351,8 @@ } if (MATCHFLAG(F_GID | F_GNAME)) { if (keys & F_GNAME && - (name = group_from_gid(cur->st_gid, 1)) != NULL) + (name = cur->gname ? cur->gname : + group_from_gid(cur->st_gid, 1)) != NULL) appendfield(fp, pathlast, "gname=%s", name); else appendfield(fp, pathlast, "gid=%u", @@ -582,9 +584,12 @@ case F_GNAME: if (mtree_Wflag) /* don't parse if whacking */ break; - if (gid_from_group(val, &gid) == -1) - mtree_err("unknown group `%s'", val); - ip->st_gid = gid; + if (gid_from_group(val, &gid) == -1) { + // mtree_err("unknown group `%s'", val); + ip->uname = strdup(val); + } else { + ip->st_gid = gid; + } break; case F_MD5: if (val[0]=='0' && val[1]=='x') @@ -660,9 +665,12 @@ case F_UNAME: if (mtree_Wflag) /* don't parse if whacking */ break; - if (uid_from_user(val, &uid) == -1) - mtree_err("unknown user `%s'", val); - ip->st_uid = uid; + if (uid_from_user(val, &uid) == -1) { + //mtree_err("unknown user `%s'", val); + ip->uname = strdup(val); + } else { + ip->st_uid = uid; + } break; case F_SHA256: if (val[0]=='0' && val[1]=='x') diff --git a/contrib/mtree/specspec.c b/contrib/mtree/specspec.c --- a/contrib/mtree/specspec.c +++ b/contrib/mtree/specspec.c @@ -64,11 +64,15 @@ if (f & F_GID) printf(" gid=%d", n->st_gid); if (f & F_GNAME) { - gr = getgrgid(n->st_gid); - if (gr == NULL) - printf(" gid=%d", n->st_gid); - else - printf(" gname=%s", gr->gr_name); + if (n->gname != NULL) { + printf(" gname=%s", n->gname); + } else { + gr = getgrgid(n->st_gid); + if (gr == NULL) + printf(" gid=%d", n->st_gid); + else + printf(" gname=%s", gr->gr_name); + } } if (f & F_MODE) printf(" mode=%o", n->st_mode); @@ -79,11 +83,15 @@ if (f & F_UID) printf(" uid=%d", n->st_uid); if (f & F_UNAME) { - pw = getpwuid(n->st_uid); - if (pw == NULL) - printf(" uid=%d", n->st_uid); - else - printf(" uname=%s", pw->pw_name); + if (n->uname != NULL) { + printf(" uname=%s", n->uname); + } else { + pw = getpwuid(n->st_uid); + if (pw == NULL) + printf(" uid=%d", n->st_uid); + else + printf(" uname=%s", pw->pw_name); + } } if (f & F_MD5) printf(" %s=%s", MD5KEY, n->md5digest);