summaryrefslogtreecommitdiffstats
path: root/usr.bin/xinstall
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1996-04-06 01:50:40 +0000
committerjulian <julian@FreeBSD.org>1996-04-06 01:50:40 +0000
commitdf817724e46921c40fc3cfb84b344b41ca53d250 (patch)
tree751a9ea4775ae38bdf1f36aec274e6155b62ac43 /usr.bin/xinstall
parenta0b8fdd90a8c168ef0fb82fe094a29efc130a4ae (diff)
downloadFreeBSD-src-df817724e46921c40fc3cfb84b344b41ca53d250.zip
FreeBSD-src-df817724e46921c40fc3cfb84b344b41ca53d250.tar.gz
Submitted by: archie@tribe.com
allow the user to install using a Numeric GID or UID. this brings it in to line with chgrp and chown, ans is required by some people using FreeBSD in a product.
Diffstat (limited to 'usr.bin/xinstall')
-rw-r--r--usr.bin/xinstall/install.16
-rw-r--r--usr.bin/xinstall/xinstall.c78
2 files changed, 78 insertions, 6 deletions
diff --git a/usr.bin/xinstall/install.1 b/usr.bin/xinstall/install.1
index e223ef8..8236011 100644
--- a/usr.bin/xinstall/install.1
+++ b/usr.bin/xinstall/install.1
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)install.1 8.1 (Berkeley) 6/6/93
-.\" $Id: install.1,v 1.3 1996/01/30 13:52:33 mpp Exp $
+.\" $Id: install.1,v 1.4 1996/03/11 03:31:51 mpp Exp $
.\"
.Dd October 9, 1995
.Dt INSTALL 1
@@ -97,7 +97,7 @@ Specify the target's file flags.
.Xr chflags 1
for a list of possible flags and their meanings.)
.It Fl g
-Specify a group.
+Specify a group. A numeric GID is allowed.
.It Fl m
Specify an alternate mode.
The default mode is set to rwxr-xr-x (0755).
@@ -105,7 +105,7 @@ The specified mode may be either an octal or symbolic value; see
.Xr chmod 1
for a description of possible mode values.
.It Fl o
-Specify an owner.
+Specify an owner. A numeric UID is allowed.
.It Fl p
Preserve the modification time.
Copy the file, as if the
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c
index 24ed628..d14ae11 100644
--- a/usr.bin/xinstall/xinstall.c
+++ b/usr.bin/xinstall/xinstall.c
@@ -40,7 +40,7 @@ static const char copyright[] =
#ifndef lint
/*static char sccsid[] = "From: @(#)xinstall.c 8.1 (Berkeley) 7/21/93";*/
static const char rcsid[] =
- "$Id: xinstall.c,v 1.4 1995/10/09 07:21:00 bde Exp $";
+ "$Id: xinstall.c,v 1.5 1996/02/08 06:17:50 pst Exp $";
#endif /* not lint */
/*-
@@ -79,8 +79,6 @@ static const char rcsid[] =
#include "pathnames.h"
-struct passwd *pp;
-struct group *gp;
int debug, docompare, docopy, dopreserve, dostrip;
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
char *group, *owner, pathbuf[MAXPATHLEN];
@@ -98,6 +96,23 @@ u_long string_to_flags __P((char **, u_long *, u_long *));
void strip __P((char *));
void usage __P((void));
+#define ALLOW_NUMERIC_IDS 1
+#ifdef ALLOW_NUMERIC_IDS
+
+uid_t uid;
+gid_t gid;
+
+uid_t resolve_uid __P((char *));
+gid_t resolve_gid __P((char *));
+u_long numeric_id __P((char *, char *));
+
+#else
+
+struct passwd *pp;
+struct group *gp;
+
+#endif /* ALLOW_NUMERIC_IDS */
+
int
main(argc, argv)
int argc;
@@ -155,12 +170,21 @@ main(argc, argv)
if (argc < 2)
usage();
+#ifdef ALLOW_NUMERIC_IDS
+
+ uid = resolve_uid(owner);
+ gid = resolve_gid(group);
+
+#else
+
/* get group and owner id's */
if (owner && !(pp = getpwnam(owner)))
errx(EX_NOUSER, "unknown user %s", owner);
if (group && !(gp = getgrnam(group)))
errx(EX_NOUSER, "unknown group %s", group);
+#endif /* ALLOW_NUMERIC_IDS */
+
no_target = stat(to_name = argv[argc - 1], &to_sb);
if (!no_target && (to_sb.st_mode & S_IFMT) == S_IFDIR) {
for (; *argv != to_name; ++argv)
@@ -204,6 +228,50 @@ main(argc, argv)
exit(0);
}
+#ifdef ALLOW_NUMERIC_IDS
+
+uid_t
+resolve_uid(s)
+ char *s;
+{
+ struct passwd *pw;
+
+ return ((pw = getpwnam(s)) == NULL) ?
+ (uid_t) numeric_id(s, "user") : pw->pw_uid;
+}
+
+gid_t
+resolve_gid(s)
+ char *s;
+{
+ struct group *gr;
+
+ return ((gr = getgrnam(s)) == NULL) ?
+ (gid_t) numeric_id(s, "group") : gr->gr_gid;
+}
+
+u_long
+numeric_id(name, type)
+ char *name, *type;
+{
+ u_long val;
+ char *ep;
+
+ /*
+ * XXX
+ * We know that uid_t's and gid_t's are unsigned longs.
+ */
+ 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);
+}
+
+#endif /* ALLOW_NUMERIC_IDS */
+
/*
* install --
* build a path name and install the file
@@ -360,7 +428,11 @@ moveit:
* chown may lose the setuid bits.
*/
if ((group || owner) &&
+#ifdef ALLOW_NUMERIC_IDS
+ fchown(to_fd, owner ? uid : -1, group ? gid : -1)) {
+#else
fchown(to_fd, owner ? pp->pw_uid : -1, group ? gp->gr_gid : -1)) {
+#endif
serrno = errno;
(void)unlink(to_name);
errno = serrno;
OpenPOWER on IntegriCloud