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.
This commit is contained in:
parent
008ff22c41
commit
b897ddafe5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=15069
@ -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
|
||||
|
@ -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 @@ install(from_name, to_name, fset, flags)
|
||||
* 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;
|
||||
|
Loading…
Reference in New Issue
Block a user