svn commit: r244570 - projects/mtree/usr.bin/xinstall
Brooks Davis
brooks at FreeBSD.org
Fri Dec 21 23:12:35 UTC 2012
Author: brooks
Date: Fri Dec 21 23:12:34 2012
New Revision: 244570
URL: http://svnweb.freebsd.org/changeset/base/244570
Log:
Add the -U option to indicate that install is running unprivileged,
and that it should not try to change the owner, the group, or the
file flags of the destination.
Modified:
projects/mtree/usr.bin/xinstall/install.1
projects/mtree/usr.bin/xinstall/xinstall.c
Modified: projects/mtree/usr.bin/xinstall/install.1
==============================================================================
--- projects/mtree/usr.bin/xinstall/install.1 Fri Dec 21 22:48:12 2012 (r244569)
+++ projects/mtree/usr.bin/xinstall/install.1 Fri Dec 21 23:12:34 2012 (r244570)
@@ -156,6 +156,9 @@ number of systems and binary types.
See below for how
.Nm
can be instructed to use another program to strip binaries.
+.It Fl U
+Indicate that install is running unprivileged, and that it should not
+try to change the owner, the group, or the file flags of the destination.
.It Fl v
Cause
.Nm
Modified: projects/mtree/usr.bin/xinstall/xinstall.c
==============================================================================
--- projects/mtree/usr.bin/xinstall/xinstall.c Fri Dec 21 22:48:12 2012 (r244569)
+++ projects/mtree/usr.bin/xinstall/xinstall.c Fri Dec 21 23:12:34 2012 (r244570)
@@ -78,8 +78,8 @@ static struct passwd *pp;
static struct group *gp;
static gid_t gid;
static uid_t uid;
-static int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy,
- verbose;
+static int dobackup, docompare, dodir, dopreserve, dostrip, dounpriv,
+ nommap, safecopy, verbose;
static mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
static const char *suffix = BACKUP_SUFFIX;
@@ -107,7 +107,7 @@ main(int argc, char *argv[])
iflags = 0;
group = owner = NULL;
- while ((ch = getopt(argc, argv, "B:bCcdf:g:Mm:o:pSsv")) != -1)
+ while ((ch = getopt(argc, argv, "B:bCcdf:g:Mm:o:pSsUv")) != -1)
switch((char)ch) {
case 'B':
suffix = optarg;
@@ -126,9 +126,6 @@ main(int argc, char *argv[])
break;
case 'f':
flags = optarg;
- if (strtofflags(&flags, &fset, NULL))
- errx(EX_USAGE, "%s: invalid flag", flags);
- iflags |= SETFLAGS;
break;
case 'g':
group = optarg;
@@ -155,6 +152,9 @@ main(int argc, char *argv[])
case 's':
dostrip = 1;
break;
+ case 'U':
+ dounpriv = 1;
+ break;
case 'v':
verbose = 1;
break;
@@ -185,7 +185,7 @@ main(int argc, char *argv[])
safecopy = 1;
/* get group and owner id's */
- if (group != NULL) {
+ if (group != NULL && !dounpriv) {
if ((gp = getgrnam(group)) != NULL)
gid = gp->gr_gid;
else
@@ -193,7 +193,7 @@ main(int argc, char *argv[])
} else
gid = (gid_t)-1;
- if (owner != NULL) {
+ if (owner != NULL && !dounpriv) {
if ((pp = getpwnam(owner)) != NULL)
uid = pp->pw_uid;
else
@@ -201,6 +201,12 @@ main(int argc, char *argv[])
} else
uid = (uid_t)-1;
+ if (flags != NULL && !dounpriv) {
+ if (strtofflags(&flags, &fset, NULL))
+ errx(EX_USAGE, "%s: invalid flag", flags);
+ iflags |= SETFLAGS;
+ }
+
if (dodir) {
for (; *argv != NULL; ++argv)
install_dir(*argv);
@@ -464,15 +470,16 @@ install(const char *from_name, const cha
* Set owner, group, mode for target; do the chown first,
* chown may lose the setuid bits.
*/
- if ((gid != (gid_t)-1 && gid != to_sb.st_gid) ||
+ if (!dounpriv && ((gid != (gid_t)-1 && gid != to_sb.st_gid) ||
(uid != (uid_t)-1 && uid != to_sb.st_uid) ||
- (mode != (to_sb.st_mode & ALLPERMS))) {
+ (mode != (to_sb.st_mode & ALLPERMS)))) {
/* Try to turn off the immutable bits. */
if (to_sb.st_flags & NOCHANGEBITS)
(void)fchflags(to_fd, to_sb.st_flags & ~NOCHANGEBITS);
}
- if ((gid != (gid_t)-1 && gid != to_sb.st_gid) ||
+ if (!dounpriv &
+ (gid != (gid_t)-1 && gid != to_sb.st_gid) ||
(uid != (uid_t)-1 && uid != to_sb.st_uid))
if (fchown(to_fd, uid, gid) == -1) {
serrno = errno;
@@ -482,6 +489,8 @@ install(const char *from_name, const cha
}
if (mode != (to_sb.st_mode & ALLPERMS))
+ if (dounpriv)
+ mode &= S_IRWXU|S_IRWXG|S_IRWXO;
if (fchmod(to_fd, mode)) {
serrno = errno;
(void)unlink(to_name);
@@ -496,7 +505,7 @@ install(const char *from_name, const cha
* trying to turn off UF_NODUMP. If we're trying to set real flags,
* then warn if the fs doesn't support it, otherwise fail.
*/
- if (!devnull && (flags & SETFLAGS ||
+ if (!dounpriv & !devnull && (flags & SETFLAGS ||
(from_sb.st_flags & ~UF_NODUMP) != to_sb.st_flags) &&
fchflags(to_fd,
flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) {
@@ -771,10 +780,14 @@ install_dir(char *path)
break;
}
- if ((gid != (gid_t)-1 || uid != (uid_t)-1) && chown(path, uid, gid))
- warn("chown %u:%u %s", uid, gid, path);
- if (chmod(path, mode))
- warn("chmod %o %s", mode, path);
+ if (!dounpriv) {
+ if ((gid != (gid_t)-1 || uid != (uid_t)-1) &&
+ chown(path, uid, gid))
+ warn("chown %u:%u %s", uid, gid, path);
+ /* XXXBED: should we do the chmod in the dounpriv case? */
+ if (chmod(path, mode))
+ warn("chmod %o %s", mode, path);
+ }
}
/*
@@ -785,11 +798,11 @@ static void
usage(void)
{
(void)fprintf(stderr,
-"usage: install [-bCcMpSsv] [-B suffix] [-f flags] [-g group] [-m mode]\n"
+"usage: install [-bCcMpSsUv] [-B suffix] [-f flags] [-g group] [-m mode]\n"
" [-o owner] file1 file2\n"
-" install [-bCcMpSsv] [-B suffix] [-f flags] [-g group] [-m mode]\n"
+" install [-bCcMpSsUv] [-B suffix] [-f flags] [-g group] [-m mode]\n"
" [-o owner] file1 ... fileN directory\n"
-" install -d [-v] [-g group] [-m mode] [-o owner] directory ...\n");
+" install -dU [-vU] [-g group] [-m mode] [-o owner] directory ...\n");
exit(EX_USAGE);
/* NOTREACHED */
}
More information about the svn-src-projects
mailing list