11553Srgrimes/*- 21553Srgrimes * Copyright (c) 1991, 1993 31553Srgrimes * The Regents of the University of California. All rights reserved. 41553Srgrimes * 51553Srgrimes * Redistribution and use in source and binary forms, with or without 61553Srgrimes * modification, are permitted provided that the following conditions 71553Srgrimes * are met: 81553Srgrimes * 1. Redistributions of source code must retain the above copyright 91553Srgrimes * notice, this list of conditions and the following disclaimer. 101553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111553Srgrimes * notice, this list of conditions and the following disclaimer in the 121553Srgrimes * documentation and/or other materials provided with the distribution. 13121300Sphk * 3. Neither the name of the University nor the names of its contributors 141553Srgrimes * may be used to endorse or promote products derived from this software 151553Srgrimes * without specific prior written permission. 161553Srgrimes * 171553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271553Srgrimes * SUCH DAMAGE. 281553Srgrimes */ 291553Srgrimes 30114601Sobrien#if 0 3130027Scharnier#ifndef lint 3230027Scharnierstatic char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; 33114601Sobrien#endif /*not lint */ 3430027Scharnier#endif 35114601Sobrien#include <sys/cdefs.h> 36114601Sobrien__FBSDID("$FreeBSD$"); 3730027Scharnier 381553Srgrimes#include <sys/types.h> 391553Srgrimes#include <sys/stat.h> 4030027Scharnier#include <err.h> 411553Srgrimes#include <fts.h> 421553Srgrimes#include <stdio.h> 4361749Sjoe#include <unistd.h> 441553Srgrimes#include "mtree.h" 451553Srgrimes#include "extern.h" 461553Srgrimes 471553Srgrimestypedef struct _key { 4899802Salfred const char *name; /* key name */ 491553Srgrimes u_int val; /* value */ 501553Srgrimes 511553Srgrimes#define NEEDVALUE 0x01 521553Srgrimes u_int flags; 531553Srgrimes} KEY; 541553Srgrimes 551553Srgrimes/* NB: the following table must be sorted lexically. */ 561553Srgrimesstatic KEY keylist[] = { 572860Srgrimes {"cksum", F_CKSUM, NEEDVALUE}, 5854375Sjoe {"flags", F_FLAGS, NEEDVALUE}, 592860Srgrimes {"gid", F_GID, NEEDVALUE}, 602860Srgrimes {"gname", F_GNAME, NEEDVALUE}, 612860Srgrimes {"ignore", F_IGN, 0}, 622860Srgrimes {"link", F_SLINK, NEEDVALUE}, 6344303Swollman#ifdef MD5 646286Swollman {"md5digest", F_MD5, NEEDVALUE}, 6544303Swollman#endif 662860Srgrimes {"mode", F_MODE, NEEDVALUE}, 672860Srgrimes {"nlink", F_NLINK, NEEDVALUE}, 6836670Speter {"nochange", F_NOCHANGE, 0}, 69160083Smaxim {"optional", F_OPT, 0}, 7044303Swollman#ifdef RMD160 7144303Swollman {"ripemd160digest", F_RMD160, NEEDVALUE}, 7244303Swollman#endif 7344303Swollman#ifdef SHA1 7444303Swollman {"sha1digest", F_SHA1, NEEDVALUE}, 7544303Swollman#endif 76144295Stobez#ifdef SHA256 77144295Stobez {"sha256digest", F_SHA256, NEEDVALUE}, 78144295Stobez#endif 792860Srgrimes {"size", F_SIZE, NEEDVALUE}, 802860Srgrimes {"time", F_TIME, NEEDVALUE}, 812860Srgrimes {"type", F_TYPE, NEEDVALUE}, 822860Srgrimes {"uid", F_UID, NEEDVALUE}, 832860Srgrimes {"uname", F_UNAME, NEEDVALUE}, 841553Srgrimes}; 851553Srgrimes 8699802Salfredint keycompare(const void *, const void *); 8799802Salfred 881553Srgrimesu_int 89121299Sphkparsekey(char *name, int *needvaluep) 901553Srgrimes{ 911553Srgrimes KEY *k, tmp; 921553Srgrimes 931553Srgrimes tmp.name = name; 941553Srgrimes k = (KEY *)bsearch(&tmp, keylist, sizeof(keylist) / sizeof(KEY), 951553Srgrimes sizeof(KEY), keycompare); 961553Srgrimes if (k == NULL) 9730027Scharnier errx(1, "line %d: unknown keyword %s", lineno, name); 981553Srgrimes 991553Srgrimes if (needvaluep) 1001553Srgrimes *needvaluep = k->flags & NEEDVALUE ? 1 : 0; 1011553Srgrimes return (k->val); 1021553Srgrimes} 1031553Srgrimes 1041553Srgrimesint 105121299Sphkkeycompare(const void *a, const void *b) 1061553Srgrimes{ 10799802Salfred return (strcmp(((const KEY *)a)->name, ((const KEY *)b)->name)); 1081553Srgrimes} 10961749Sjoe 11061749Sjoechar * 111121299Sphkflags_to_string(u_long fflags) 11261749Sjoe{ 11361749Sjoe char *string; 11461749Sjoe 11561749Sjoe string = fflagstostr(fflags); 11661749Sjoe if (string != NULL && *string == '\0') { 11761749Sjoe free(string); 11861749Sjoe string = strdup("none"); 11961749Sjoe } 12061749Sjoe if (string == NULL) 12161749Sjoe err(1, NULL); 12261749Sjoe 12361749Sjoe return string; 12461749Sjoe} 125