From owner-svn-src-projects@FreeBSD.ORG Fri Dec 28 21:25:50 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 74CB186B; Fri, 28 Dec 2012 21:25:50 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4EEDC8FC0A; Fri, 28 Dec 2012 21:25:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBSLPoZm006481; Fri, 28 Dec 2012 21:25:50 GMT (envelope-from brooks@svn.freebsd.org) Received: (from brooks@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBSLPnFr006478; Fri, 28 Dec 2012 21:25:49 GMT (envelope-from brooks@svn.freebsd.org) Message-Id: <201212282125.qBSLPnFr006478@svn.freebsd.org> From: Brooks Davis Date: Fri, 28 Dec 2012 21:25:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r244785 - projects/mtree/usr.bin/xinstall X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Dec 2012 21:25:50 -0000 Author: brooks Date: Fri Dec 28 21:25:49 2012 New Revision: 244785 URL: http://svnweb.freebsd.org/changeset/base/244785 Log: Implement the -N dbdir option to allow an alternative passwd file to be used. Obtained from: NetBSD Modified: projects/mtree/usr.bin/xinstall/Makefile projects/mtree/usr.bin/xinstall/install.1 projects/mtree/usr.bin/xinstall/xinstall.c Modified: projects/mtree/usr.bin/xinstall/Makefile ============================================================================== --- projects/mtree/usr.bin/xinstall/Makefile Fri Dec 28 21:20:32 2012 (r244784) +++ projects/mtree/usr.bin/xinstall/Makefile Fri Dec 28 21:25:49 2012 (r244785) @@ -3,6 +3,14 @@ PROG= xinstall PROGNAME= install +SRCS= xinstall.c getid.c MAN= install.1 +.PATH: ${.CURDIR}/../../contrib/mtree +CFLAGS+= -I${.CURDIR}/../../contrib/mtree +CFLAGS+= -I${.CURDIR}/../../lib/libnetbsd + +DPADD+= ${LIBUTIL} +LDADD+= -lutil + .include Modified: projects/mtree/usr.bin/xinstall/install.1 ============================================================================== --- projects/mtree/usr.bin/xinstall/install.1 Fri Dec 28 21:20:32 2012 (r244784) +++ projects/mtree/usr.bin/xinstall/install.1 Fri Dec 28 21:25:49 2012 (r244785) @@ -41,6 +41,7 @@ .Op Fl f Ar flags .Op Fl g Ar group .Op Fl m Ar mode +.Op Fl N Ar dbdir .Op Fl o Ar owner .Ar file1 file2 .Nm @@ -49,6 +50,7 @@ .Op Fl f Ar flags .Op Fl g Ar group .Op Fl m Ar mode +.Op Fl N Ar dbdir .Op Fl o Ar owner .Ar file1 ... fileN directory .Nm @@ -56,6 +58,7 @@ .Op Fl v .Op Fl g Ar group .Op Fl m Ar mode +.Op Fl N Ar dbdir .Op Fl o Ar owner .Ar directory ... .Sh DESCRIPTION @@ -124,6 +127,18 @@ The default mode is set to rwxr-xr-x (07 The specified mode may be either an octal or symbolic value; see .Xr chmod 1 for a description of possible mode values. +.It Fl N +Use the user database text file +.Pa master.passwd +and group database text file +.Pa group +from +.Ar dbdir , +rather than using the results from the system's +.Xr getpwnam 3 +and +.Xr getgrnam 3 +(and related) library calls. .It Fl o Specify an owner. A numeric UID is allowed. @@ -234,6 +249,8 @@ The default was changed to copy in .Xr mv 1 , .Xr strip 1 , .Xr mmap 2 , +.Xr getgrnam 3 , +.Xr getpwnam 3 , .Xr chown 8 .Sh HISTORY The Modified: projects/mtree/usr.bin/xinstall/xinstall.c ============================================================================== --- projects/mtree/usr.bin/xinstall/xinstall.c Fri Dec 28 21:20:32 2012 (r244784) +++ projects/mtree/usr.bin/xinstall/xinstall.c Fri Dec 28 21:25:49 2012 (r244785) @@ -62,6 +62,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include "mtree.h" + /* Bootstrap aid - this doesn't exist in most older releases */ #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) /* from */ @@ -74,8 +76,6 @@ __FBSDID("$FreeBSD$"); #define NOCHANGEBITS (UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND) #define BACKUP_SUFFIX ".old" -static struct passwd *pp; -static struct group *gp; static gid_t gid; static uid_t uid; static int dobackup, docompare, dodir, dopreserve, dostrip, dounpriv, @@ -89,7 +89,7 @@ static int create_newfile(const char *, static int create_tempfile(const char *, char *, size_t); static void install(const char *, const char *, u_long, u_int); static void install_dir(char *); -static u_long numeric_id(const char *, const char *); +static int parseid(const char *, id_t *); static void strip(const char *); static int trymmap(int); static void usage(void); @@ -108,7 +108,7 @@ main(int argc, char *argv[]) flags = NULL; iflags = 0; group = owner = NULL; - while ((ch = getopt(argc, argv, "B:bCcdf:g:Mm:o:pSsUv")) != -1) + while ((ch = getopt(argc, argv, "B:bCcdf:g:Mm:N:o:pSsUv")) != -1) switch((char)ch) { case 'B': suffix = optarg; @@ -141,6 +141,11 @@ main(int argc, char *argv[]) mode = getmode(set, 0); free(set); break; + case 'N': + if (!setup_getid(optarg)) + err(1, "Unable to use user and group " + "databases in `%s'", optarg); + break; case 'o': owner = optarg; break; @@ -187,18 +192,22 @@ main(int argc, char *argv[]) /* get group and owner id's */ if (group != NULL && !dounpriv) { - if ((gp = getgrnam(group)) != NULL) - gid = gp->gr_gid; - else - gid = (gid_t)numeric_id(group, "group"); + if (gid_from_group(group, &gid) == -1) { + id_t id; + if (!parseid(group, &id)) + errx(1, "unknown group %s", group); + gid = id; + } } else gid = (gid_t)-1; if (owner != NULL && !dounpriv) { - if ((pp = getpwnam(owner)) != NULL) - uid = pp->pw_uid; - else - uid = (uid_t)numeric_id(owner, "user"); + if (uid_from_user(owner, &uid) == -1) { + id_t id; + if (!parseid(owner, &id)) + errx(1, "unknown user %s", owner); + uid = id; + } } else uid = (uid_t)-1; @@ -251,23 +260,19 @@ main(int argc, char *argv[]) /* NOTREACHED */ } -static u_long -numeric_id(const char *name, const char *type) +/* + * parseid -- + * parse uid or gid from arg into id, returning non-zero if successful + */ +static int +parseid(const char *name, id_t *id) { - u_long val; - char *ep; - - /* - * XXX - * We know that uid_t's and gid_t's are unsigned longs. - */ + char *ep; errno = 0; - val = strtoul(name, &ep, 10); - if (errno) - err(EX_NOUSER, "%s", name); - if (*ep != '\0') - errx(EX_NOUSER, "unknown %s %s", type, name); - return (val); + *id = (id_t)strtoul(name, &ep, 10); + if (errno || *ep != '\0') + return (0); + return (1); } /* @@ -800,10 +805,11 @@ usage(void) { (void)fprintf(stderr, "usage: install [-bCcMpSsUv] [-B suffix] [-f flags] [-g group] [-m mode]\n" -" [-o owner] file1 file2\n" +" [-N dbdir] [-o owner] file1 file2\n" " install [-bCcMpSsUv] [-B suffix] [-f flags] [-g group] [-m mode]\n" -" [-o owner] file1 ... fileN directory\n" -" install -dU [-vU] [-g group] [-m mode] [-o owner] directory ...\n"); +" [-N dbdir] [-o owner] file1 ... fileN directory\n" +" install -dU [-vU] [-g group] [-m mode] [-N dbdir] [-o owner]\n" +" directory ...\n"); exit(EX_USAGE); /* NOTREACHED */ }