Index: stable/11/contrib/mtree/create.c =================================================================== --- stable/11/contrib/mtree/create.c (revision 356532) +++ stable/11/contrib/mtree/create.c (revision 356533) @@ -1,477 +1,477 @@ /* $NetBSD: create.c,v 1.73 2014/04/24 17:22:41 christos Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if HAVE_NBTOOL_CONFIG_H #include "nbtool_config.h" #endif #include #if defined(__RCSID) && !defined(lint) #if 0 static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; #else __RCSID("$NetBSD: create.c,v 1.73 2014/04/24 17:22:41 christos Exp $"); #endif #endif /* not lint */ #include #include #if ! HAVE_NBTOOL_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #ifndef NO_MD5 #include #endif #ifndef NO_RMD160 #include #endif #ifndef NO_SHA1 #include #endif #ifndef NO_SHA2 #include #endif #include "extern.h" #define INDENTNAMELEN 15 #define MAXLINELEN 80 static gid_t gid; static uid_t uid; static mode_t mode; static u_long flags; #ifdef __FreeBSD__ #define FTS_CONST const #else #define FTS_CONST #endif static int dcmp(const FTSENT *FTS_CONST *, const FTSENT *FTS_CONST *); static void output(FILE *, int, int *, const char *, ...) __printflike(4, 5); static int statd(FILE *, FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *); static void statf(FILE *, int, FTSENT *); void cwalk(FILE *fp) { FTS *t; FTSENT *p; time_t clocktime; char host[MAXHOSTNAMELEN + 1]; const char *user; char *argv[2]; char dot[] = "."; int indent = 0; argv[0] = dot; argv[1] = NULL; time(&clocktime); gethostname(host, sizeof(host)); host[sizeof(host) - 1] = '\0'; if ((user = getlogin()) == NULL) { struct passwd *pw; - user = (pw = getpwuid(getuid())) == NULL ? pw->pw_name : + user = (pw = getpwuid(getuid())) != NULL ? pw->pw_name : ""; } if (!nflag) fprintf(fp, "#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n" "#\t date: %s", user, host, fullpath, ctime(&clocktime)); if ((t = fts_open(argv, ftsoptions, dcmp)) == NULL) mtree_err("fts_open: %s", strerror(errno)); while ((p = fts_read(t)) != NULL) { if (jflag) indent = p->fts_level * 4; if (check_excludes(p->fts_name, p->fts_path)) { fts_set(t, p, FTS_SKIP); continue; } if (!find_only(p->fts_path)) { fts_set(t, p, FTS_SKIP); continue; } switch(p->fts_info) { case FTS_D: if (!bflag) fprintf(fp, "\n"); if (!nflag) fprintf(fp, "# %s\n", p->fts_path); statd(fp, t, p, &uid, &gid, &mode, &flags); statf(fp, indent, p); break; case FTS_DP: if (p->fts_level > 0) if (!nflag) fprintf(fp, "%*s# %s\n", indent, "", p->fts_path); if (p->fts_level > 0 || flavor == F_FREEBSD9) { fprintf(fp, "%*s..\n", indent, ""); if (!bflag) fprintf(fp, "\n"); } break; case FTS_DNR: case FTS_ERR: case FTS_NS: mtree_err("%s: %s", p->fts_path, strerror(p->fts_errno)); break; default: if (!dflag) statf(fp, indent, p); break; } } fts_close(t); if (sflag && keys & F_CKSUM) mtree_err("%s checksum: %u", fullpath, crc_total); } static void statf(FILE *fp, int indent, FTSENT *p) { u_int32_t len, val; int fd, offset; const char *name = NULL; #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) char *digestbuf; #endif offset = fprintf(fp, "%*s%s%s", indent, "", S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name)); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; else offset += fprintf(fp, "%*s", (INDENTNAMELEN + indent) - offset, ""); if (!S_ISREG(p->fts_statp->st_mode) && (flavor == F_NETBSD6 || !dflag)) output(fp, indent, &offset, "type=%s", inotype(p->fts_statp->st_mode)); if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) { if (keys & F_UNAME && (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL) output(fp, indent, &offset, "uname=%s", name); if (keys & F_UID || (keys & F_UNAME && name == NULL)) output(fp, indent, &offset, "uid=%u", p->fts_statp->st_uid); } if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) { if (keys & F_GNAME && (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL) output(fp, indent, &offset, "gname=%s", name); if (keys & F_GID || (keys & F_GNAME && name == NULL)) output(fp, indent, &offset, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(fp, indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_DEV && (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode))) output(fp, indent, &offset, "device=%#jx", (uintmax_t)p->fts_statp->st_rdev); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(fp, indent, &offset, "nlink=%ju", (uintmax_t)p->fts_statp->st_nlink); if (keys & F_SIZE && (flavor == F_FREEBSD9 || S_ISREG(p->fts_statp->st_mode))) output(fp, indent, &offset, "size=%ju", (uintmax_t)p->fts_statp->st_size); if (keys & F_TIME) #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) output(fp, indent, &offset, "time=%jd.%09ld", (intmax_t)p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); #else output(fp, indent, &offset, "time=%jd.%09ld", (intmax_t)p->fts_statp->st_mtime, (long)0); #endif if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) mtree_err("%s: %s", p->fts_accpath, strerror(errno)); close(fd); output(fp, indent, &offset, "cksum=%lu", (long)val); } #ifndef NO_MD5 if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: MD5File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", MD5KEY, digestbuf); free(digestbuf); } #endif /* ! NO_MD5 */ #ifndef NO_RMD160 if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: RMD160File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", RMD160KEY, digestbuf); free(digestbuf); } #endif /* ! NO_RMD160 */ #ifndef NO_SHA1 if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA1File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", SHA1KEY, digestbuf); free(digestbuf); } #endif /* ! NO_SHA1 */ #ifndef NO_SHA2 if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA256_File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", SHA256KEY, digestbuf); free(digestbuf); } #ifdef SHA384_BLOCK_LENGTH if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA384_File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", SHA384KEY, digestbuf); free(digestbuf); } #endif if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA512_File failed: %s", p->fts_accpath, strerror(errno)); output(fp, indent, &offset, "%s=%s", SHA512KEY, digestbuf); free(digestbuf); } #endif /* ! NO_SHA2 */ if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) output(fp, indent, &offset, "link=%s", vispath(rlink(p->fts_accpath))); #if HAVE_STRUCT_STAT_ST_FLAGS if (keys & F_FLAGS && p->fts_statp->st_flags != flags) { char *str = flags_to_string(p->fts_statp->st_flags, "none"); output(fp, indent, &offset, "flags=%s", str); free(str); } #endif putchar('\n'); } /* XXX * FLAGS2INDEX will fail once the user and system settable bits need more * than one byte, respectively. */ #define FLAGS2INDEX(x) (((x >> 8) & 0x0000ff00) | (x & 0x000000ff)) #define MTREE_MAXGID 5000 #define MTREE_MAXUID 5000 #define MTREE_MAXMODE (MBITS + 1) #if HAVE_STRUCT_STAT_ST_FLAGS #define MTREE_MAXFLAGS (FLAGS2INDEX(CH_MASK) + 1) /* 1808 */ #else #define MTREE_MAXFLAGS 1 #endif #define MTREE_MAXS 16 static int statd(FILE *fp, FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode, u_long *pflags) { FTSENT *p; gid_t sgid; uid_t suid; mode_t smode; u_long sflags = 0; const char *name = NULL; gid_t savegid; uid_t saveuid; mode_t savemode; u_long saveflags; u_short maxgid, maxuid, maxmode, maxflags; u_short g[MTREE_MAXGID], u[MTREE_MAXUID], m[MTREE_MAXMODE], f[MTREE_MAXFLAGS]; static int first = 1; savegid = *pgid; saveuid = *puid; savemode = *pmode; saveflags = *pflags; if ((p = fts_children(t, 0)) == NULL) { if (errno) mtree_err("%s: %s", RP(parent), strerror(errno)); return (1); } memset(g, 0, sizeof(g)); memset(u, 0, sizeof(u)); memset(m, 0, sizeof(m)); memset(f, 0, sizeof(f)); maxuid = maxgid = maxmode = maxflags = 0; for (; p; p = p->fts_link) { if (flavor == F_NETBSD6 || !dflag || (dflag && S_ISDIR(p->fts_statp->st_mode))) { smode = p->fts_statp->st_mode & MBITS; if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) { savemode = smode; maxmode = m[smode]; } sgid = p->fts_statp->st_gid; if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) { savegid = sgid; maxgid = g[sgid]; } suid = p->fts_statp->st_uid; if (suid < MTREE_MAXUID && ++u[suid] > maxuid) { saveuid = suid; maxuid = u[suid]; } #if HAVE_STRUCT_STAT_ST_FLAGS sflags = FLAGS2INDEX(p->fts_statp->st_flags); if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) { saveflags = p->fts_statp->st_flags; maxflags = f[sflags]; } #endif } } /* * If the /set record is the same as the last one we do not need to * output a new one. So first we check to see if anything changed. * Note that we always output a /set record for the first directory. */ if (((keys & (F_UNAME | F_UID)) && (*puid != saveuid)) || ((keys & (F_GNAME | F_GID)) && (*pgid != savegid)) || ((keys & F_MODE) && (*pmode != savemode)) || ((keys & F_FLAGS) && (*pflags != saveflags)) || first) { first = 0; if (flavor != F_NETBSD6 && dflag) fprintf(fp, "/set type=dir"); else fprintf(fp, "/set type=file"); if (keys & (F_UID | F_UNAME)) { if (keys & F_UNAME && (name = user_from_uid(saveuid, 1)) != NULL) fprintf(fp, " uname=%s", name); if (keys & F_UID || (keys & F_UNAME && name == NULL)) fprintf(fp, " uid=%lu", (u_long)saveuid); } if (keys & (F_GID | F_GNAME)) { if (keys & F_GNAME && (name = group_from_gid(savegid, 1)) != NULL) fprintf(fp, " gname=%s", name); if (keys & F_GID || (keys & F_GNAME && name == NULL)) fprintf(fp, " gid=%lu", (u_long)savegid); } if (keys & F_MODE) fprintf(fp, " mode=%#lo", (u_long)savemode); if (keys & F_NLINK) fprintf(fp, " nlink=1"); if (keys & F_FLAGS) { char *str = flags_to_string(saveflags, "none"); fprintf(fp, " flags=%s", str); free(str); } fprintf(fp, "\n"); *puid = saveuid; *pgid = savegid; *pmode = savemode; *pflags = saveflags; } return (0); } /* * dcmp -- * used as a comparison function passed to fts_open() to control * the order in which fts_read() returns results. We make * directories sort after non-directories, but otherwise sort in * strcmp() order. * * Keep this in sync with nodecmp() in spec.c. */ static int dcmp(const FTSENT *FTS_CONST *a, const FTSENT *FTS_CONST *b) { if (S_ISDIR((*a)->fts_statp->st_mode)) { if (!S_ISDIR((*b)->fts_statp->st_mode)) return (1); } else if (S_ISDIR((*b)->fts_statp->st_mode)) return (-1); return (strcmp((*a)->fts_name, (*b)->fts_name)); } void output(FILE *fp, int indent, int *offset, const char *fmt, ...) { va_list ap; char buf[1024]; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (*offset + strlen(buf) > MAXLINELEN - 3) { fprintf(fp, " \\\n%*s", INDENTNAMELEN + indent, ""); *offset = INDENTNAMELEN + indent; } *offset += fprintf(fp, " %s", buf) + 1; } Index: stable/11/contrib/mtree/only.c =================================================================== --- stable/11/contrib/mtree/only.c (revision 356532) +++ stable/11/contrib/mtree/only.c (revision 356533) @@ -1,152 +1,153 @@ -/* $NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $ */ +/* $NetBSD: only.c,v 1.3 2017/09/07 04:04:13 nakayama Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_NBTOOL_CONFIG_H #include "nbtool_config.h" #endif #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $"); +__RCSID("$NetBSD: only.c,v 1.3 2017/09/07 04:04:13 nakayama Exp $"); #endif #include #include #include #include #include #include #include #include #include "extern.h" struct hentry { char *str; uint32_t hash; struct hentry *next; }; static struct hentry *table[1024]; static bool loaded; static uint32_t hash_str(const char *str) { const uint8_t *s = (const uint8_t *)str; uint8_t c; uint32_t hash = 0; while ((c = *s++) != '\0') hash = hash * 33 + c; /* "perl": k=33, r=r+r/32 */ return hash + (hash >> 5); } static bool hash_find(const char *str, uint32_t *h) { struct hentry *e; *h = hash_str(str) % __arraycount(table); for (e = table[*h]; e; e = e->next) if (e->hash == *h && strcmp(e->str, str) == 0) return true; return false; } static void hash_insert(char *str, uint32_t h) { struct hentry *e; + char *x; if ((e = malloc(sizeof(*e))) == NULL) mtree_err("memory allocation error"); + if ((x = strdup(str)) == NULL) + mtree_err("memory allocation error"); - e->str = str; + e->str = x; e->hash = h; e->next = table[h]; table[h] = e; } static void fill(char *str) { uint32_t h; char *ptr = strrchr(str, '/'); if (ptr == NULL) return; *ptr = '\0'; if (!hash_find(str, &h)) { - char *x = strdup(str); - if (x == NULL) - mtree_err("memory allocation error"); - hash_insert(x, h); + hash_insert(str, h); fill(str); } *ptr = '/'; } void load_only(const char *fname) { FILE *fp; char *line; size_t len, lineno; if ((fp = fopen(fname, "r")) == NULL) err(1, "Cannot open `%s'", fname); while ((line = fparseln(fp, &len, &lineno, NULL, FPARSELN_UNESCALL))) { uint32_t h; if (hash_find(line, &h)) err(1, "Duplicate entry %s", line); hash_insert(line, h); fill(line); + free(line); } fclose(fp); loaded = true; } bool find_only(const char *path) { uint32_t h; if (!loaded) return true; return hash_find(path, &h); } Index: stable/11/contrib/mtree/specspec.c =================================================================== --- stable/11/contrib/mtree/specspec.c (revision 356532) +++ stable/11/contrib/mtree/specspec.c (revision 356533) @@ -1,273 +1,273 @@ /* $NetBSD: specspec.c,v 1.2 2012/10/05 01:27:29 christos Exp $ */ /*- * Copyright (c) 2003 Poul-Henning Kamp * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if HAVE_NBTOOL_CONFIG_H #include "nbtool_config.h" #endif #include __RCSID("$NetBSD: specspec.c,v 1.2 2012/10/05 01:27:29 christos Exp $"); #include #include #include #include #include #include #include #include #include #include "mtree.h" #include "extern.h" #define FF(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && ((a)->d) != ((b)->d)) #define FS(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && strcmp((a)->d,(b)->d)) #define FM(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && memcmp(&(a)->d,&(b)->d, sizeof (a)->d)) static void shownode(NODE *n, int f, char const *path) { struct group *gr; struct passwd *pw; printf("%s%s %s", path, n->name, inotype(nodetoino(n->type))); if (f & F_CKSUM) printf(" cksum=%lu", n->cksum); 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 (f & F_MODE) printf(" mode=%o", n->st_mode); if (f & F_NLINK) printf(" nlink=%ju", (uintmax_t)n->st_nlink); if (f & F_SIZE) printf(" size=%jd", (intmax_t)n->st_size); 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 (f & F_MD5) printf(" %s=%s", MD5KEY, n->md5digest); if (f & F_SHA1) printf(" %s=%s", SHA1KEY, n->sha1digest); if (f & F_RMD160) printf(" %s=%s", RMD160KEY, n->rmd160digest); if (f & F_SHA256) printf(" %s=%s", SHA256KEY, n->sha256digest); if (f & F_SHA384) printf(" %s=%s", SHA384KEY, n->sha384digest); if (f & F_SHA512) printf(" %s=%s", SHA512KEY, n->sha512digest); if (f & F_FLAGS) printf(" flags=%s", flags_to_string(n->st_flags, "none")); printf("\n"); } static int mismatch(NODE *n1, NODE *n2, int differ, char const *path) { if (n2 == NULL) { shownode(n1, differ, path); return (1); } if (n1 == NULL) { printf("\t"); shownode(n2, differ, path); return (1); } if (!(differ & keys)) return(0); printf("\t\t"); shownode(n1, differ, path); printf("\t\t"); shownode(n2, differ, path); return (1); } static int compare_nodes(NODE *n1, NODE *n2, char const *path) { int differs; if (n1 != NULL && n1->type == F_LINK) n1->flags &= ~F_MODE; if (n2 != NULL && n2->type == F_LINK) n2->flags &= ~F_MODE; differs = 0; if (n1 == NULL && n2 != NULL) { differs = n2->flags; mismatch(n1, n2, differs, path); return (1); } if (n1 != NULL && n2 == NULL) { differs = n1->flags; mismatch(n1, n2, differs, path); return (1); } if (n1->type != n2->type) { - differs = 0; + differs = F_TYPE; mismatch(n1, n2, differs, path); return (1); } if (FF(n1, n2, F_CKSUM, cksum)) differs |= F_CKSUM; if (FF(n1, n2, F_GID, st_gid)) differs |= F_GID; if (FF(n1, n2, F_GNAME, st_gid)) differs |= F_GNAME; if (FF(n1, n2, F_MODE, st_mode)) differs |= F_MODE; if (FF(n1, n2, F_NLINK, st_nlink)) differs |= F_NLINK; if (FF(n1, n2, F_SIZE, st_size)) differs |= F_SIZE; if (FS(n1, n2, F_SLINK, slink)) differs |= F_SLINK; if (FM(n1, n2, F_TIME, st_mtimespec)) differs |= F_TIME; if (FF(n1, n2, F_UID, st_uid)) differs |= F_UID; if (FF(n1, n2, F_UNAME, st_uid)) differs |= F_UNAME; if (FS(n1, n2, F_MD5, md5digest)) differs |= F_MD5; if (FS(n1, n2, F_SHA1, sha1digest)) differs |= F_SHA1; if (FS(n1, n2, F_RMD160, rmd160digest)) differs |= F_RMD160; if (FS(n1, n2, F_SHA256, sha256digest)) differs |= F_SHA256; if (FS(n1, n2, F_SHA384, sha384digest)) differs |= F_SHA384; if (FS(n1, n2, F_SHA512, sha512digest)) differs |= F_SHA512; if (FF(n1, n2, F_FLAGS, st_flags)) differs |= F_FLAGS; if (differs) { mismatch(n1, n2, differs, path); return (1); } return (0); } static int walk_in_the_forest(NODE *t1, NODE *t2, char const *path) { int r, i; NODE *c1, *c2, *n1, *n2; char *np; r = 0; if (t1 != NULL) c1 = t1->child; else c1 = NULL; if (t2 != NULL) c2 = t2->child; else c2 = NULL; while (c1 != NULL || c2 != NULL) { n1 = n2 = NULL; if (c1 != NULL) n1 = c1->next; if (c2 != NULL) n2 = c2->next; if (c1 != NULL && c2 != NULL) { if (c1->type != F_DIR && c2->type == F_DIR) { n2 = c2; c2 = NULL; } else if (c1->type == F_DIR && c2->type != F_DIR) { n1 = c1; c1 = NULL; } else { i = strcmp(c1->name, c2->name); if (i > 0) { n1 = c1; c1 = NULL; } else if (i < 0) { n2 = c2; c2 = NULL; } } } if (c1 == NULL && c2->type == F_DIR) { asprintf(&np, "%s%s/", path, c2->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else if (c2 == NULL && c1->type == F_DIR) { asprintf(&np, "%s%s/", path, c1->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else if (c1 == NULL || c2 == NULL) { i = compare_nodes(c1, c2, path); } else if (c1->type == F_DIR && c2->type == F_DIR) { asprintf(&np, "%s%s/", path, c1->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else { i = compare_nodes(c1, c2, path); } r += i; c1 = n1; c2 = n2; } return (r); } int mtree_specspec(FILE *fi, FILE *fj) { int rval; NODE *root1, *root2; root1 = spec(fi); root2 = spec(fj); rval = walk_in_the_forest(root1, root2, ""); rval += compare_nodes(root1, root2, ""); if (rval > 0) return (MISMATCHEXIT); return (0); } Index: stable/11/contrib/netbsd-tests/usr.sbin/mtree/t_mtree.sh =================================================================== --- stable/11/contrib/netbsd-tests/usr.sbin/mtree/t_mtree.sh (revision 356532) +++ stable/11/contrib/netbsd-tests/usr.sbin/mtree/t_mtree.sh (revision 356533) @@ -1,436 +1,472 @@ # $NetBSD: t_mtree.sh,v 1.7 2017/01/14 20:45:16 christos Exp $ # # Copyright (c) 2009, 2012 The NetBSD Foundation, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Postprocess mtree output, canonicalising portions that # are expected to differ from one run to another. # h_postprocess() { sed -e ' /^# user: /s/:.*/: x/ /^# machine: /s/:.*/: x/ /^# tree: /s/:.*/: x/ /^# date: /s/:.*/: x/ ' \ -e '/type=dir/s/ size=[0-9]*//' } h_check() { diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ" } atf_test_case mtree_create atf_test_case netbsd6_create create_head() { atf_set "descr" "Create a specfile describing a directory tree" } create_setup() { # create some directories rm -fr create mkdir -p create/a/1 create/a/2 create/b # create some files for file in create/top.file.1 \ create/a/a.file.1 \ create/a/a.file.2 \ create/a/1/a1.file.1 \ create/b/b.file.1 \ create/b/b.file.2 do echo "$file" >$file done # hard link to file in same dir ln create/b/b.file.1 create/b/b.hardlink.1 # hard link to file in another dir ln create/b/b.file.2 create/a/a.hardlink.b2 # symlink to file ln -s a.file.1 create/a.symlink.1 # symlink to dir ln -s b create/top.symlink.b # dangling symlink ln -s nonexistent create/top.dangling } create_body() { create_setup # run mtree and check output ( cd create && mtree -F ${FLAVOR} -c -k type,nlink,link,size,sha256 ) >output.raw \ || atf_fail "mtree exit status $?" h_postprocess output h_check "$(atf_get_srcdir)/${FLAVOR}_d_create.out" output } mtree_create_head() { FLAVOR=mtree create_head } netbsd6_create_head() { FLAVOR=netbsd6 create_head } mtree_create_body() { FLAVOR=mtree create_body } netbsd6_create_body() { FLAVOR=netbsd6 create_body } atf_test_case mtree_check atf_test_case netbsd6_check check_head() { atf_set "descr" "Check a directory tree against a specfile" } check_body() { # we use the same directory tree and specfile as in the "create" test create_setup # run mtree and check output ( cd create && mtree -F ${FLAVOR} ) <"$(atf_get_srcdir)/${FLAVOR}_d_create.out" >output \ || atf_fail "mtree exit status $?" h_check /dev/null output } mtree_check_head() { FLAVOR=mtree check_head } netbsd6_check_head() { FLAVOR=netbsd6 check_head } mtree_check_body() { FLAVOR=mtree check_body } netbsd6_check_body() { FLAVOR=netbsd6 check_body } atf_test_case mtree_convert_C atf_test_case netbsd6_convert_C convert_C_head() { atf_set "descr" "Convert a specfile to mtree -C format, unsorted" } convert_C_body() { mtree -F ${FLAVOR} -C -K all <"$(atf_get_srcdir)/d_convert.in" >output h_check "$(atf_get_srcdir)/d_convert_C.out" output } mtree_convert_C_head() { FLAVOR=mtree convert_C_head } netbsd6_convert_C_head() { FLAVOR=netbsd6 convert_C_head } mtree_convert_C_body() { FLAVOR=mtree convert_C_body } netbsd6_convert_C_body() { FLAVOR=netbsd6 convert_C_body } atf_test_case mtree_convert_C_S atf_test_case netbsd6_convert_C_S convert_C_S_head() { atf_set "descr" "Convert a specfile to mtree -C format, sorted" } convert_C_S_body() { mtree -F ${FLAVOR} -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output h_check "$(atf_get_srcdir)/d_convert_C_S.out" output } mtree_convert_C_S_head() { FLAVOR=mtree convert_C_S_head } netbsd6_convert_C_S_head() { FLAVOR=netbsd6 convert_C_S_head } mtree_convert_C_S_body() { FLAVOR=mtree convert_C_S_body } netbsd6_convert_C_S_body() { FLAVOR=netbsd6 convert_C_S_body } atf_test_case mtree_convert_D atf_test_case netbsd6_convert_D convert_D_head() { atf_set "descr" "Convert a specfile to mtree -D format, unsorted" } convert_D_body() { mtree -F ${FLAVOR} -D -K all <"$(atf_get_srcdir)/d_convert.in" >output h_check "$(atf_get_srcdir)/d_convert_D.out" output } mtree_convert_D_head() { FLAVOR=mtree convert_D_head } netbsd6_convert_D_head() { FLAVOR=netbsd6 convert_D_head } mtree_convert_D_body() { FLAVOR=mtree convert_D_body } netbsd6_convert_D_body() { FLAVOR=netbsd6 convert_D_body } atf_test_case mtree_convert_D_S atf_test_case netbsd6_convert_D_S convert_D_S_head() { atf_set "descr" "Convert a specfile to mtree -D format, sorted" } convert_D_S_body() { mtree -F ${FLAVOR} -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output h_check "$(atf_get_srcdir)/d_convert_D_S.out" output } mtree_convert_D_S_head() { FLAVOR=mtree convert_D_S_head } netbsd6_convert_D_S_head() { FLAVOR=netbsd6 convert_D_S_head } mtree_convert_D_S_body() { FLAVOR=mtree convert_D_S_body } netbsd6_convert_D_S_body() { FLAVOR=netbsd6 convert_D_S_body } atf_test_case mtree_ignore atf_test_case netbs6_ignore ignore_head() { atf_set "descr" "Test that -d ignores symlinks (PR bin/41061)" } ignore_body() { # Kyua 0.11 and above point TMPDIR to our work directory and atf-check # generates a temporary file, which confuses mtree. Put the mtree files # into a subdirectory. # # See https://github.com/jmmv/kyua/issues/133 for details. mkdir root && cd root mkdir newdir mtree -F ${FLAVOR} -c | mtree -F ${FLAVOR} -Ck uid,gid,mode > mtree.spec ln -s newdir otherdir # This yields "extra: otherdir" even with -d. # (PR bin/41061) atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec" # Delete the symlink and re-verify. # rm otherdir atf_check -s ignore -o empty -e empty -x "mtree -F ${FLAVOR} -d < mtree.spec" } mtree_ignore_head() { FLAVOR=mtree ignore_head } netbsd6_ignore_head() { FLAVOR=netbsd6 ignore_head } mtree_ignore_body() { FLAVOR=mtree ignore_body } netbsd6_ignore_body() { # Kyua 0.11 and above point TMPDIR to our work directory and atf-check # generates a temporary file, which confuses mtree. Put the mtree files # into a subdirectory. # # See https://github.com/jmmv/kyua/issues/133 for details. mkdir root && cd root FLAVOR=netbsd6 ignore_body } atf_test_case mtree_merge atf_test_case netbsd6_merge merge_head() { atf_set "descr" "Merge records of different type" } merge_body() { mtree -F ${FLAVOR} -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output h_check "$(atf_get_srcdir)/d_merge_C_M.out" output # same again, with sorting mtree -F ${FLAVOR} -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output } mtree_merge_head() { FLAVOR=mtree merge_head } netbsd6_merge_head() { FLAVOR=netbsd6 merge_head } mtree_merge_body() { FLAVOR=mtree merge_body } netbsd6_merge_body() { FLAVOR=netbsd6 merge_body } atf_test_case mtree_nonemptydir atf_test_case netbsd6_nonemptydir nonemptydir_head() { atf_set "descr" "Test that new non-empty " \ "directories are recorded (PR bin/25693)" } nonemptydir_body() { mkdir testdir cd testdir mtree -F ${FLAVOR} -c > mtree.spec if [ ! -f mtree.spec ]; then atf_fail "mtree failed" fi touch bar atf_check -s ignore -o save:output -x "mtree -F ${FLAVOR} -f mtree.spec" if [ ! -n "$(egrep "extra: bar" output)" ]; then atf_fail "mtree did not record changes (PR bin/25693)" fi } mtree_nonemptydir_head() { FLAVOR=mtree nonemptydir_head } netbsd6_nonemptydir_head() { FLAVOR=netbsd6 nonemptydir_head } mtree_nonemptydir_body() { FLAVOR=mtree nonemptydir_body } netbsd6_nonemptydir_body() { FLAVOR=netbsd6 nonemptydir_body } +atf_test_case mtree_specspec_type +mtree_specspec_type_head() +{ + atf_set "descr" "Test that spec comparisons detect type changes" +} +mtree_specspec_type_body() +{ + mkdir testdir + + touch testdir/bar + mtree -c -p testdir > mtree1.spec + + if [ ! -f mtree1.spec ]; then + atf_fail "mtree failed" + fi + + rm -f testdir/bar + ln -s foo testdir/bar + # uid change is expected to be ignored as done in -C + chown -h operator testdir/bar + mtree -c -p testdir > mtree2.spec + + if [ ! -f mtree2.spec ]; then + atf_fail "mtree failed" + fi + + atf_check -s ignore -o save:output \ + -x "mtree -f mtree1.spec -f mtree2.spec" + + if ! cut -f 3 output | egrep -q "bar file" || \ + ! cut -f 3 output | egrep -q "bar link"; then + atf_fail "mtree did not detect type change" + fi +} + atf_init_test_cases() { atf_add_test_case mtree_create atf_add_test_case mtree_check atf_add_test_case mtree_convert_C atf_add_test_case mtree_convert_C_S atf_add_test_case mtree_convert_D atf_add_test_case mtree_convert_D_S atf_add_test_case mtree_ignore atf_add_test_case mtree_merge atf_add_test_case mtree_nonemptydir + atf_add_test_case mtree_specspec_type atf_add_test_case netbsd6_create atf_add_test_case netbsd6_check atf_add_test_case netbsd6_convert_C atf_add_test_case netbsd6_convert_C_S atf_add_test_case netbsd6_convert_D atf_add_test_case netbsd6_convert_D_S atf_add_test_case netbsd6_ignore atf_add_test_case netbsd6_merge atf_add_test_case netbsd6_nonemptydir } Index: stable/11/usr.sbin/fmtree/specspec.c =================================================================== --- stable/11/usr.sbin/fmtree/specspec.c (revision 356532) +++ stable/11/usr.sbin/fmtree/specspec.c (revision 356533) @@ -1,256 +1,256 @@ /*- * Copyright (c) 2003 Poul-Henning Kamp * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include "mtree.h" #include "extern.h" #define FF(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && ((a)->d) != ((b)->d)) #define FS(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && strcmp((a)->d,(b)->d)) #define FM(a, b, c, d) \ (((a)->flags & (c)) && ((b)->flags & (c)) && memcmp(&(a)->d,&(b)->d, sizeof (a)->d)) static void shownode(NODE *n, int f, char const *path) { struct group *gr; struct passwd *pw; printf("%s%s %s", path, n->name, ftype(n->type)); if (f & F_CKSUM) printf(" cksum=%lu", n->cksum); 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 (f & F_MODE) printf(" mode=%o", n->st_mode); if (f & F_NLINK) printf(" nlink=%ju", (uintmax_t)n->st_nlink); if (f & F_SIZE) printf(" size=%jd", (intmax_t)n->st_size); 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 (f & F_MD5) printf(" md5digest=%s", n->md5digest); if (f & F_SHA1) printf(" sha1digest=%s", n->sha1digest); if (f & F_RMD160) printf(" rmd160digest=%s", n->rmd160digest); if (f & F_SHA256) printf(" sha256digest=%s", n->sha256digest); if (f & F_FLAGS) printf(" flags=%s", flags_to_string(n->st_flags)); printf("\n"); } static int mismatch(NODE *n1, NODE *n2, int differ, char const *path) { if (n2 == NULL) { shownode(n1, differ, path); return (1); } if (n1 == NULL) { printf("\t"); shownode(n2, differ, path); return (1); } if (!(differ & keys)) return(0); printf("\t\t"); shownode(n1, differ, path); printf("\t\t"); shownode(n2, differ, path); return (1); } static int compare_nodes(NODE *n1, NODE *n2, char const *path) { int differs; if (n1 != NULL && n1->type == F_LINK) n1->flags &= ~F_MODE; if (n2 != NULL && n2->type == F_LINK) n2->flags &= ~F_MODE; differs = 0; if (n1 == NULL && n2 != NULL) { differs = n2->flags; mismatch(n1, n2, differs, path); return (1); } if (n1 != NULL && n2 == NULL) { differs = n1->flags; mismatch(n1, n2, differs, path); return (1); } if (n1->type != n2->type) { - differs = 0; + differs = F_TYPE; mismatch(n1, n2, differs, path); return (1); } if (FF(n1, n2, F_CKSUM, cksum)) differs |= F_CKSUM; if (FF(n1, n2, F_GID, st_gid)) differs |= F_GID; if (FF(n1, n2, F_GNAME, st_gid)) differs |= F_GNAME; if (FF(n1, n2, F_MODE, st_mode)) differs |= F_MODE; if (FF(n1, n2, F_NLINK, st_nlink)) differs |= F_NLINK; if (FF(n1, n2, F_SIZE, st_size)) differs |= F_SIZE; if (FS(n1, n2, F_SLINK, slink)) differs |= F_SLINK; if (FM(n1, n2, F_TIME, st_mtimespec)) differs |= F_TIME; if (FF(n1, n2, F_UID, st_uid)) differs |= F_UID; if (FF(n1, n2, F_UNAME, st_uid)) differs |= F_UNAME; if (FS(n1, n2, F_MD5, md5digest)) differs |= F_MD5; if (FS(n1, n2, F_SHA1, sha1digest)) differs |= F_SHA1; if (FS(n1, n2, F_RMD160, rmd160digest)) differs |= F_RMD160; if (FS(n1, n2, F_SHA256, sha256digest)) differs |= F_SHA256; if (FF(n1, n2, F_FLAGS, st_flags)) differs |= F_FLAGS; if (differs) { mismatch(n1, n2, differs, path); return (1); } return (0); } static int walk_in_the_forest(NODE *t1, NODE *t2, char const *path) { int r, i; NODE *c1, *c2, *n1, *n2; char *np; r = 0; if (t1 != NULL) c1 = t1->child; else c1 = NULL; if (t2 != NULL) c2 = t2->child; else c2 = NULL; while (c1 != NULL || c2 != NULL) { n1 = n2 = NULL; if (c1 != NULL) n1 = c1->next; if (c2 != NULL) n2 = c2->next; if (c1 != NULL && c2 != NULL) { if (c1->type != F_DIR && c2->type == F_DIR) { n2 = c2; c2 = NULL; } else if (c1->type == F_DIR && c2->type != F_DIR) { n1 = c1; c1 = NULL; } else { i = strcmp(c1->name, c2->name); if (i > 0) { n1 = c1; c1 = NULL; } else if (i < 0) { n2 = c2; c2 = NULL; } } } if (c1 == NULL && c2->type == F_DIR) { asprintf(&np, "%s%s/", path, c2->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else if (c2 == NULL && c1->type == F_DIR) { asprintf(&np, "%s%s/", path, c1->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else if (c1 == NULL || c2 == NULL) { i = compare_nodes(c1, c2, path); } else if (c1->type == F_DIR && c2->type == F_DIR) { asprintf(&np, "%s%s/", path, c1->name); i = walk_in_the_forest(c1, c2, np); free(np); i += compare_nodes(c1, c2, path); } else { i = compare_nodes(c1, c2, path); } r += i; c1 = n1; c2 = n2; } return (r); } int mtree_specspec(FILE *fi, FILE *fj) { int rval; NODE *root1, *root2; root1 = mtree_readspec(fi); root2 = mtree_readspec(fj); rval = walk_in_the_forest(root1, root2, ""); rval += compare_nodes(root1, root2, ""); if (rval > 0) return (MISMATCHEXIT); return (0); } Index: stable/11 =================================================================== --- stable/11 (revision 356532) +++ stable/11 (revision 356533) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r352261-352262,352265