changemode.c: Change file permissions using rwxr-xr-x

Jeff Beadles jeff at quark.WV.TEK.COM
Tue Aug 15 08:10:40 AEST 1989



This changes strings like 'r-xr-xr-x' and changes it to 0555.
It works for setuid/setgid, and save text bits also.  To use it:

changemod rwxr-xr-x file1 file2.

I wrote this a while back as a joke for /r$ a while back and "found" it again.

	-Jeff
--
Jeff Beadles		Utek Engineering, Tektronix Inc.
jeff at quark.WV.TEK.COM


#--------------------------------CUT HERE-------------------------------------
#! /bin/sh
#
# This is a shell archive.  Save this into a file, edit it
# and delete all lines above this comment.  Then give this
# file to sh by executing the command "sh file".  The files
# will be extracted into the current directory owned by
# you with default permissions.
#
# The files contained herein are:
#
# -rw-------  1 jeff         1448 Jun  2 21:10 changemod.c
#
echo 'x - changemod.c'
if test -f changemod.c; then echo 'shar: not overwriting changemod.c'; else
sed 's/^X//' << '________This_Is_The_END________' > changemod.c
X/*
X *	This is a farce.  If you can't think of an easier way, then
X *	Maybe it's time to take up VMS... :-) :-) :-)
X *
X *	Tossed together by Jeff Beadles	jeff at quark.WV.TEK.COM
X *
X *	I make (nor desire :-)  any rights or claims to this.
X *	If you sell it for big bucks, then good for you.
X *
X *	Notice that this is the only comment.  This is planned.
X *
X * To compile: type 'cc -o changemod changemod.c'
X */
X
X#include <stdio.h>
Xextern char getbits();
Xextern char getstbits();
Xextern char *malloc();
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X	int loop;
X	char *newargv[4096], *cp;
X
X	if ( argc < 3) 
X		err();
X	if ( strlen(argv[1]) != 9)
X		err();
X
X	if ( (newargv[0]=malloc(6)) == NULL)
X		err();
X	if ( (cp=newargv[1]=malloc(6)) == NULL)
X		err();
X
X	strcpy(newargv[0],"chmod");
X
X	for(loop=2; loop < argc; loop++)
X		newargv[loop]=argv[loop];
X
X	newargv[loop] = NULL;
X	*(cp++)   = getstbits(argv[1]);
X	*(cp++)   = getbits( argv[1] + 0 );
X	*(cp++)   = getbits( argv[1] + 3 );
X	*(cp++)   = getbits( argv[1] + 6 );
X	*cp     = '\0';
X
X	execv( "/bin/chmod" , newargv);
X	err();
X}
Xerr()
X{
X	fprintf(stderr,"Error\n");
X	exit(1);
X}
X
Xchar getstbits(str)
Xchar *str;
X{
X	int ret=0;
X	if (str[2]=='s')	ret += 4;
X	if (str[5]=='s')	ret += 2;
X	if (str[8]=='t')	ret += 1;
X	return('0' + ret);
X}
Xchar getbits(str)
Xchar *str;
X{
X	int ret=0;
X	if (str[0]=='r')	ret += 4;
X	if (str[1]=='w')	ret += 2;
X	if( (str[2]=='x') || (str[2]=='s') || (str[2]=='t'))
X		ret += 1;
X	return('0' + ret);
X}
________This_Is_The_END________
if test `wc -c < changemod.c` -ne 1448; then
	echo 'shar: changemod.c was damaged during transit (should have been 1448 bytes)'
fi
fi		; : end of overwriting check
exit 0



More information about the Alt.sources mailing list