From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,98ed4c903b49b67 X-Google-Attributes: gid1164f8,public X-Google-Thread: 10b612,a1b11d8064c15fe X-Google-Attributes: gid10b612,public X-Google-ArrivalTime: 1992-07-07 03:36:02 PST Xref: sparky comp.sys.dec:3911 comp.unix.ultrix:5507 Newsgroups: comp.sys.dec,comp.unix.ultrix Path: sparky!uunet!news.univie.ac.at!email!hp From: hp@vmars.tuwien.ac.at (Peter Holzer) Subject: Re: Why is SCCS broken under Ultrix 4.2[ABC] and is there a fix? Message-ID: <1992Jul7.153106.12177@email.tuwien.ac.at> Sender: news@email.tuwien.ac.at Nntp-Posting-Host: quasi.vmars.tuwien.ac.at Organization: Technical University Vienna, Dept. for Realtime Systems, AUSTRIA References: <7712@sirius.ucs.adelaide.edu.au> <1992Jul6.120717.1341@ircam.fr> Date: Tue, 7 Jul 1992 15:31:06 GMT fingerhu@ircam.fr (Michel Fingerhut) writes: >>-> chown sccs SCCS >Indeed, but how does a vanilla non superuser do this? I know that the >suggestion somewhere in the manuals is that each "group" have its sccs >etc... but if you don't want it that way, but just the plain ole unix >way? Remove the suid bit? Use RCS? Each is probably a good idea. But if you can't do either for some reason (too many existing projects on SCCS basis with too many users in different groups, ...) I wrote a suid program `mkSCCS' to create an SCCS directory with the proper permissions. Unfortunately it grew longer and longer as people discovered security flaws in it. It has now been stable for more than half a year, so I dare to send it out. (Code is public domain. If you find bugs or improve the program I'd like to know) #! /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 'Makefile' <<'END_OF_FILE' X# Makefile for mkSCCS X# X# @(#) Makefile 1.4 10/10/91 hp@vmars.tuwien.ac.at X CFLAGS = -Wall -g CC = gcc X mkSCCS: mkSCCS.o X $(CC) mkSCCS.o -o mkSCCS X install: mkSCCS mkSCCS.1 X install -s -o root -m 4711 mkSCCS /usr/local/bin/mkSCCS X install -c mkSCCS.1 /usr/local/man/man1/mkSCCS.1 END_OF_FILE if test 280 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'mkSCCS.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mkSCCS.c'\" else echo shar: Extracting \"'mkSCCS.c'\" \(4110 characters\) sed "s/^X//" >'mkSCCS.c' <<'END_OF_FILE' X/* X * mkSCCS -- create a SCCS directory with proper owner X * X * I hope this cannot be used to breach system security. X * Hackers, have a go on it :-) X */ X char mkSCCS_sid [] = "@(#) mkSCCS.c 1.3 10/10/91 hp@vmars.tuwien.ac.at"; X X#include X#include X#include X#include X X#include X#include X#include X#include X#include X extern int getopt (int argc, char ** argv, char * options); X X#define SCCS "SCCS" /* name of SCCS directory */ X#define PERM 0755 /* perms for " " */ X#define SCCSACC "sccs" /* name of SCCS account */ X char buffer [BUFSIZ]; /* should be big enough for a filename :-) */ char * scratchdir; X X void error ( X int status, X char const * fmt, ... X){ X va_list ap; X va_start (ap, fmt); X vfprintf (stderr, fmt, ap); X va_end (ap); X perror (""); X switch (status) { X case 3: X rename (SCCS, "../" SCCS); X case 2: X chdir (".."); X case 1: X rmdir (scratchdir) ; X case 0: X break; X } X exit (1); X} X X X int main ( X int argc, X char ** argv X){ X int user; /* who called me ? */ X int euser; /* effective uid of program (should be root) */ X int sccs; /* uid of sccs */ X struct stat sb; X struct passwd * pwe; X int fd; X int renflag = 0; X int paranoid = 0; X int oldumask; X int c, m; X X while ((c = getopt (argc, argv, "p")) != EOF) { X switch (c) { X case 'p': X paranoid = 1; X break; X default: X fprintf (stderr, "Usage: %s [-p]\n", argv [0]); X exit (1); X } X } X X /* get necessary uids X */ X user = getuid (); X euser = geteuid (); X if ((pwe = getpwnam (SCCSACC)) == NULL) error (0, "%s: %s has no account: ", argv [0], SCCS); X sccs = pwe->pw_uid; X X oldumask = umask (022); X X if (setuid (euser) == -1) error (0, "%s: cannot setuid to %d: ", argv [0], euser); X X /* set effective uid to that of the user X * while making the directory. X * This prevents the user from making SCCS subdirectories X * in directories where he does not have write permissions. X */ X X if (seteuid (user) == -1) error (0, "%s: cannot seteuid to %d: ", argv [0], user); X X if (stat (".", &sb) < 0) error (0, "%s: cannot stat .: %s ", argv [0]); X if (((sb.st_mode & 0222) >> 1) != (sb.st_mode & 0111)) { X if (paranoid) { X if (chmod (".", ((m = sb.st_mode & 0222) | (m << 1) | (m >> 1)) & sb.st_mode) < 0) { X error (0, "%s: cannot chmod .: ", argv [0]); X } X } else { X fprintf (stderr, X "%s: Warning: mode %o of \".\" allows editing without write permission\n", X argv [0], sb.st_mode); X } X } X X if ((scratchdir = tempnam (".", SCCS)) == NULL) error (0, "%s: cannot create scratch directory: ", argv [0]); X if (mkdir (scratchdir, 0700) < 0) error (0, "%s: cannot mkdir %s: ", argv [0], SCCS); X X /* Ok. I now have a private directory in the CWD X * So I do the rest as root. X */ X if (seteuid (euser) == -1) error (1, "%s: cannot seteuid to %d: ", argv [0], user); X /* Set the directory so that only root can do something in it X */ X if (chown (scratchdir, 0, 0) < 0) error (1, "%s: cannot chown %s: ", argv [0], scratchdir); X /* and set up the SCCS dir in this scratch dir X */ X if (chdir (scratchdir) < 0) error (1, "%s: cannot chdir to %s: ", argv [0], SCCS); X /* try to use existing SCCS dir X */ X if (rename ("../" SCCS, SCCS) < 0) { X if (mkdir (SCCS, PERM) < 0) error (2, "%s: cannot mkdir %s: ", argv [0], SCCS); X } else { X renflag = 1; X } X X /* check if everything is ok X */ X if (stat (SCCS, &sb) < 0) error (3, "%s: cannot stat %s: ", argv [0], SCCS); X if (! (sb.st_mode & S_IFDIR)) error (3, "%s: %s is not a directory\n", argv [0], SCCS); X if (renflag && sb.st_uid != user) error (3, "%s: Not owner of %s\n", argv [0], SCCS); X /* give dir to sccs X */ X if (chown (SCCS, sccs, sb.st_gid) < 0) error (3, "%s: cannot chown %s: ", argv [0], SCCS); X /* now move it back where it belongs X */ X if (rename (SCCS, "../" SCCS) < 0) error (2, "%s: cannot rename %s to %s: ", argv [0], SCCS, "../" SCCS); X /* and erase all traces X */ X if (chdir ("..") < 0) error (0, "%s: cannot chdir to ..: ", argv [0]); X if (rmdir (scratchdir) < 0) error (0, "%s: cannot rmdir %s: ", argv [0], scratchdir); X return 0; X close (fd); X} END_OF_FILE if test 4110 -ne `wc -c <'mkSCCS.c'`; then echo shar: \"'mkSCCS.c'\" unpacked with wrong size! fi # end of 'mkSCCS.c' fi if test -f 'mkSCCS.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mkSCCS.1'\" else echo shar: Extracting \"'mkSCCS.1'\" \(978 characters\) sed "s/^X//" >'mkSCCS.1' <<'END_OF_FILE' X.\= @(#) mkSCCS.1 1.3 10/10/91 hp@vmars.tuwien.ac.at X.TH mkSCCS 1 "10/10/91" X.SH NAME mkSCCS \- make SCCS directory with owner sccs X.SH SYNOPSIS X\fImkSCCS\fR [\fI-p\fR] X.SH DESCRIPTION X\fImkSCCS\fR creates a directory SCCS with owner sccs and mode 0755 in the current directory. If the directory does already exist and is owned by the user its owner is just changed to sccs. This program allows users without root privileges to create SCCS directories. Because any user who has access to the SCCS directory can add new deltas, mkSCCS warns if the search permissions of the current directory are less strict than the write permissions. X.SH OPTIONS X.IP -p X(Paranoid) changes the read and execute permissions of the current directory to match the write permissions. X.SH NOTES Care has been taken to eliminate all possible security holes a setuid program opens. If you find any left, please report them to me. X.SH AUTHOR Peter J. Holzer (hp@vmars.tuwien.ac.at) X.SH SEE ALSO sccs(1) END_OF_FILE if test 978 -ne `wc -c <'mkSCCS.1'`; then echo shar: \"'mkSCCS.1'\" unpacked with wrong size! fi # end of 'mkSCCS.1' fi echo shar: End of shell archive. exit 0 -- | _ | Peter J. Holzer | Think of it | | |_|_) | Technical University Vienna | as evolution | | | | | Dept. for Real-Time Systems | in action! | | __/ | hp@vmars.tuwien.ac.at | Tony Rand |