bert@bebux.UUCP (Bert Reuling) (01/06/89)
[ This is a replacement for chown(1). As I didn't receive a
chgrp(1) with MINIX-ST, I wrote one myself. This resulted in
this program. This chown (chgrp) accepts decimal UID's
(GID's) as well as owner (group) names. ]
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive"
#
# Contents:
#
# README
# Makefile
# chown.c
#
# Wrapped by bert@tjilp on Thu Jan 5 13:46:16 1989
PATH=/bin:/usr/bin:/usr/local/bin ; export PATH
if test -f 'README' -a "${1}" != "-c"
then
echo "$0: Will not overwrite existing file: README"
else
echo "x - README (1074 characters)"
sed 's/^X//' <<\END_OF_SHAR >README
X
X
X chown(1),
X chgrp(1).
X
X Copyright (c) 1989
X
X Bert Reuling
X
X
X This program may be copied freely
X
X
X Chown(1) changes the owner of files to 'owner'. The 'owner'
X may be a decimal UID or a login name found in /etc/passwd.
X
X Chgrp(1) changes the group-ID of files to 'group'. The
X 'group' may be either a decimal GID or a group name found in
X /etc/group.
X
X Only the super-user can change owner or group. Note that
X chgrp(1) is a link to chown(1) rather than a separate
X program.
X
X Please send any suggestions, bug reports, etc,.. to:
X
X
X ...!hp4nl!bebux!bert
X
X
X / / Bert Reuling
X /-, ,--, ,-, /- p/a Radio Holland bv
X / / /--- / / Jan Rebelstraat 20
X `-' `-- ` `-- 1069 CC Amsterdam
X The Netherlands
X
X MINIX werkgroep UNIXgg/HCC
END_OF_SHAR
if test 1074 -ne `wc -c <'README'`
then
echo "$0: unpacked with wrong size: README"
fi
fi
if test -f 'Makefile' -a "${1}" != "-c"
then
echo "$0: Will not overwrite existing file: Makefile"
else
echo "x - Makefile (415 characters)"
sed 's/^X//' <<\END_OF_SHAR >Makefile
X#
X# chown, chgrp - change owner or group
X#
XINSTALLDIR=/usr/bin
XCFLAGS=-O
X#
Xchown: chown.c
X cc -o chown chown.c
X#
Xinstall: chown
X mv chown $(INSTALLDIR)/chown
X ln $(INSTALLDIR)/chown $(INSTALLDIR)/chgrp
X chmem =2000 $(INSTALLDIR)/chown
X chown bin $(INSTALLDIR)/chown
X chgrp bin $(INSTALLDIR)/chown
X chmod 755 $(INSTALLDIR)/chown
X#
Xclean:
X -rm -f core chown.o
X#
Xarchive:
X shar README Makefile chown.c >chown.shar
END_OF_SHAR
if test 415 -ne `wc -c <'Makefile'`
then
echo "$0: unpacked with wrong size: Makefile"
fi
fi
if test -f 'chown.c' -a "${1}" != "-c"
then
echo "$0: Will not overwrite existing file: chown.c"
else
echo "x - chown.c (1836 characters)"
sed 's/^X//' <<\END_OF_SHAR >chown.c
X/*
X * chown, chgrp - change owner or group. Author: Bert Reuling
X */
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <ctype.h>
X#include <pwd.h>
X#include <grp.h>
X
X#ifndef TRUE
X#define TRUE 1
X#define FALSE 0
X#endif
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X int i, uid, gid, owner, status = 0;
X struct passwd *pwd, *getpwuid(), *getpwnam();
X struct group *grp, *getgrgid(), *getgrnam();
X struct stat st;
X
X if (strcmp(argv[0], "chown") == 0)
X owner = TRUE;
X else if (strcmp(argv[0], "chgrp") == 0)
X owner = FALSE;
X else {
X fprintf(stderr, "%s: should be named \"chown\" or \"chgrp\"\n", argv[0]);
X exit(1);
X }
X
X if (argc < 3) {
X fprintf (stderr,"Usage: %s %s file ...\n", argv[0], (owner) ? "owner" : "group");
X exit(1);
X }
X
X if (isdigit(argv[1][0])) {
X if (owner)
X pwd = getpwuid(atoi(argv[1]));
X else
X grp = getgrgid(atoi(argv[1]));
X }
X else {
X if (owner)
X pwd = getpwnam(argv[1]);
X else
X grp = getgrnam(argv[1]);
X }
X
X if (owner && (pwd == NULL)) {
X fprintf(stderr, "%s: unknown user\n", argv[0]);
X exit(1);
X }
X if (!owner && (grp == NULL)) {
X fprintf(stderr, "%s: unknown group\n", argv[0]);
X exit(1);
X }
X for (i = 2; i < argc; i++) {
X if (stat(argv[i], &st) != -1) {
X if (owner) {
X uid = pwd->pw_uid; /* new owner */
X gid = st.st_gid; /* old group */
X }
X else {
X uid = st.st_uid; /* old owner */
X gid = grp->gr_gid; /* new group */
X }
X if (chown(argv[i], uid, gid) == -1) {
X fprintf(stderr,"%s: not changed\n", argv[i]);
X status++;
X }
X }
X else {
X perror(argv[i]);
X status++;
X }
X }
X exit(status);
X}
END_OF_SHAR
if test 1836 -ne `wc -c <'chown.c'`
then
echo "$0: unpacked with wrong size: chown.c"
fi
fi
echo "End of archive"
exit 0
#
#
#