[comp.os.minix] MKDIR & MKNOD call in MINIX

japplega@csm9a.UUCP (Joe Applegate) (07/01/87)

Well, after much effort I applied the patches to make minix run on my Tandy
1000 as well as use my HD part. 2 as ROOT.... only to discover that the code
used to compile the original version of fs can not possibly be the code in
the book or on the fs directory.... case in point.... only uid 0 (root) can
call mknod()... that fits in well with the V7 doc... but mkdir.c calls mknod()
to create a directory!  Apparently mv does likewise when renaming or moving 
a directory... the end result is that if you recompile fs no one but the
super-user can mkdir or mv (directories).... UGGHH... now I will admit that
I am a full fledged novice at UNIX (my background is OS9 and MS-DOS) but it
appears to me that the published source was quietly hacked before compilation
(under PCIX I assume?) to allow all users to mknod()... when I removed the
check on line 9547:
	if (!super_user) return(EPERM);
the mkdir and mv programs worked fine.... now if I can get SU to work....
Does anyone have a suggestion for mkdir or mv that will allow the restriction
on mknod() to stay in effect???

All flames aside I am impressed with Minix.... it does most of what it is
supposed to do and with user support in time most of the bugs will fade....
I still remember the massive problems I had with early versions of OS9!
Minix shines by comparison.... it's biggest weakness is THAT C compiler!
A Coco under OS9 Level 1 compiles faster and with more highly optimised code!
I am impatiently awaiting a better (MSC???) compiler!!!!



    Joe Applegate - Colorado School of Mines Computing Center
            {seismo, hplabs}!hao!isis!csm9a!japplega
                              or
 SYSOP @ M.O.M. AI BBS - (303) 273-3989 - 300/1200/2400 8-N-1 24 hrs.

       *** UNIX is a philosophy, not an operating system ***
 *** BUT it is a registered trademark of AT&T, so get off my back ***
 

zemon@felix.UUCP (Art Zemon) (07/02/87)

The mkdir and mv commands should be "setuid root".  This
means that when they execute, the effective user ID (uid) is
set to root, allowing a normal user to create directories.
You do this with "chmod 755 /usr/bin/mv /usr/bin/mkdir"

Happy hacking
--
	-- Art Zemon
	   FileNet Corporation
	   Costa Mesa, California
	   ...!hplabs!felix!zemon

jr@amanue.UUCP (07/04/87)

In article <461@csm9a.UUCP>, japplega@csm9a.UUCP (Joe Applegate) writes:
> case in point.... only uid 0 (root) can
> call mknod()... that fits in well with the V7 doc... but mkdir.c calls mknod()
> to create a directory!  Apparently mv does likewise when renaming or moving 
> a directory... the end result is that if you recompile fs no one but the
> super-user can mkdir or mv (directories).... 

OK, I'm sure you will get a chorus of answers on this one.  If you recompile
mv or mkdir you must turn on what is called the setuid bit.  There is an
analogous mechanism in OS-9 but it's much more obscure, and if I tell you what
it is I'll probably garble it.  (Something related to making the uid in the
*module* be superuser.)  The UNIX file permission bits use three tuples of
three bits each, rwx, for user, group, and other.  But in addition there are
two special bits, with octal values 4000 and 2000.  These are called
respectively the *setuid* bit and *setgid* bit.  You turn them on and off with
the chmod command (see page 388 of the book, where it gives an example of
turning on the setuid bit.)  When an a.out file (is that still the right term
under MINIX?) is executed and the setuid bit is on, then the effective uid of
the process becomes *the owner of the file*.  If you're logged in as root and
you issue the command

chmod 4755 /bin/mkdir

then *anyone* executing the mkdir command will have effective uid root while
running that command.  It's standard behavior for the C compiler to turn off
the setuid bit when a program is recompiled, and it must be explicitly turned
back on.  The setgid bit is the same concept exactly, except that it sets the
gid rather than the uid.  "Setuid-root" programs are the way UNIX allows such
things as mail programs to be able to modify the recipient's mailbox file
without granting everyone write permission on that file.

Incidentally Dennis Ritchie has a patent on the concept of the setuid bit.
-- 
 Jim Rosenberg
     CIS: 71515,124                         decvax!idis! \
     WELL: jer                                   allegra! ---- pitt!amanue!jr
     BIX: jrosenberg                 seismo!cmcl2!cadre! /