Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Apr 1996 13:14:44 -0800 (PST)
From:      Julian Elischer <julian>
To:        hackers
Subject:   comments please
Message-ID:  <199604052114.NAA11662@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

These small changes to xinstall are needed by a company using FreeBSD within
a product. They are in my opinion useful and non intrusive.

The patch allows 'install' to use a numeric GID or UID in the same way that
chgrp (et al)  do.
The code comes from chgrp and I was genuinely surprised that 
install didn't do this anyway..



I will commit this today unless there are many people violently opposed.
cvs diff: Diffing .
Index: install.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/xinstall/install.1,v
retrieving revision 1.4
diff -c -r1.4 install.1
*** install.1	1996/03/11 03:31:51	1.4
--- install.1	1996/04/05 21:07:16
***************
*** 97,103 ****
  .Xr chflags 1
  for a list of possible flags and their meanings.)
  .It Fl g
! Specify a group.
  .It Fl m
  Specify an alternate mode.
  The default mode is set to rwxr-xr-x (0755).
--- 97,103 ----
  .Xr chflags 1
  for a list of possible flags and their meanings.)
  .It Fl g
! Specify a group. A numeric GID can be used.
  .It Fl m
  Specify an alternate mode.
  The default mode is set to rwxr-xr-x (0755).
***************
*** 105,111 ****
  .Xr chmod  1
  for a description of possible mode values.
  .It Fl o
! Specify an owner.
  .It Fl p
  Preserve the modification time.
  Copy the file, as if the
--- 105,111 ----
  .Xr chmod  1
  for a description of possible mode values.
  .It Fl o
! Specify an owner. A numeric value can be used for the UID.
  .It Fl p
  Preserve the modification time.
  Copy the file, as if the
Index: xinstall.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/xinstall/xinstall.c,v
retrieving revision 1.5
diff -c -r1.5 xinstall.c
*** xinstall.c	1996/02/08 06:17:50	1.5
--- xinstall.c	1996/04/05 21:05:07
***************
*** 79,86 ****
  
  #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];
--- 79,84 ----
***************
*** 98,103 ****
--- 96,117 ----
  void	strip __P((char *));
  void	usage __P((void));
  
+ #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,166 ****
--- 169,189 ----
  	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,209 ****
--- 227,276 ----
  	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
+ 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,366 ****
--- 427,437 ----
  	 * 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604052114.NAA11662>