From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8c9b,67fdbb330a498fa7 X-Google-Attributes: gidf8c9b,public X-Google-Thread: 151c03,67fdbb330a498fa7 X-Google-Attributes: gid151c03,public X-Google-Thread: fee84,67fdbb330a498fa7 X-Google-Attributes: gidfee84,public X-Google-Thread: 115614,67fdbb330a498fa7 X-Google-Attributes: gid115614,public X-Google-ArrivalTime: 1994-09-10 06:57:52 PST Newsgroups: comp.unix.questions,comp.unix.utlrix,comp.unix.aix,comp.unix.osf.osf1 Path: nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!newsfeed.ACO.net!swidir.switch.ch!univ-lyon1.fr!jussieu.fr!math.ohio-state.edu!howland.reston.ans.net!EU.net!sun4nl!ideta.nl!hildo From: hildo@ideta.nl (Hildo den Breejen) Subject: Re: setuid confusion Reply-To: Hildo.den-Breejen@ideta.nl Organization: Ideta bv Date: Fri, 9 Sep 1994 14:17:53 GMT Message-ID: References: <1994Sep9.052738.18360@lugb.latrobe.edu.au> Xref: nntp.gmd.de comp.unix.questions:38977 comp.unix.aix:38711 comp.unix.osf.osf1:5271 ccvj@misty.latrobe.edu.au (Vicki Jordan) writes: >Could someone please tell me how to change a process's uid the right way? >I need to start as root, change to the uid of the person allocated the >process and then change back to root. This contrived code illustrates >the problem and the output my confusion! Running suid root, I get >different behaviour across Ultrix, AIX and OSF1. It would seem to me >that AIX and OSF1 are "correct" when run as an individual user, but only >OSF1 correct when run as root. In partilcuar, I need to get the same >result from AIX as OSF1 in both the run as user and root cases. >Is there anyone who doesn't confuse as easily as I do?? If so, please >enlighten me! >Thanks. >-------- >#include >#include >main() >{ > printf("Start - uid is %d and euid is %d \n", getuid(), geteuid()); >/* Change to uid 203 */ > seteuid(203); > printf("Call seteuid(203) - uid is %d and euid is %d \n", getuid(),geteuid()); > setuid(203); > printf("Call setuid(203) - uid is %d and euid is %d \n", getuid(),geteuid()); >/* Change back to initial uid 0 */ > seteuid(0); > printf("Call seteuid(0) - uid is %d and euid is %d \n", getuid(),geteuid()); > setuid(0); > printf("Call setuid(0) - uid is %d and euid is %d \n", getuid(),geteuid()); >} >File is suid root. >Ultrix - run as user 203: >Start - uid is 203 and euid is 0 >Call seteuid(203) - uid is 203 and euid is 203 >Call setuid(203) - uid is 203 and euid is 203 >Call seteuid(0) - uid is 203 and euid is 203 Obviously, ultrix does not have saved-set-UID (Posix optional) there's no way you cab regain root privileges. >Call setuid(0) - uid is 203 and euid is 203 Nope. You don't get root back. >Aix - run as user 203: >Start - uid is 203 and euid is 0 >Call seteuid(203) - uid is 203 and euid is 203 >Call setuid(203) - uid is 203 and euid is 203 >Call seteuid(0) - uid is 203 and euid is 0 So AIX does have saved-set-UID. You can retrieve your root privs. >Call setuid(0) - uid is 0 and euid is 0 Check. You're effectively root now. root can do anything. >OSF1 - run as user 203 >Start - uid is 203 and euid is 0 >Call seteuid(203) - uid is 203 and euid is 203 >Call setuid(203) - uid is 203 and euid is 203 >Call seteuid(0) - uid is 203 and euid is 0 >Call setuid(0) - uid is 0 and euid is 0 Obviously, OSF has saved-set-UID too. >Ultrix/AIX - run as root: >Start - uid is 0 and euid is 0 >Call seteuid(203) - uid is 0 and euid is 0 >Call setuid(203) - uid is 203 and euid is 203 >Call seteuid(0) - uid is 203 and euid is 203 >Call setuid(0) - uid is 203 and euid is 203 AIX obviously does not have'em. >OSF1 - run as root: >Start - uid is 0 and euid is 0 >Call seteuid(203) - uid is 0 and euid is 203 >Call setuid(203) - uid is 0 and euid is 203 >Call seteuid(0) - uid is 0 and euid is 0 >Call setuid(0) - uid is 0 and euid is 0 Apparently, OSF1 has saved-set-UID's, but considders root not to have 'appropriate privileges': a setuid root process can only do what any user can: make euid equal to uid or make euid equal to saved-set-UID. It cannot change it's real UID. (It can in BSD, using setreuid()). >-- >Vicki Jordan V.Jordan@latrobe.edu.au >Computing Services phone: +61 03 479 1500 >La Trobe University fax: +61 03 479 1999 >Bundoora Vic 3083 Australia I am into the UID business myself these days, so I read Posix and Xopen on this subject. Both use the phrase 'appropriate privilege', where I would say 'root'. Their must be some subtle difference. Perhaps someone can explain. To make it even more complicated: every process in SCO has a login-uid. Set by the login process, and from that moment on immutable. It's used for the audit subsystem: every process can be traced back to an account. Hope this helps... -- Hildo den Breejen Ideta, 6 Frankemaheerd, 1102 AN Amsterdam, the Netherlands My opinions are my own, not necessarily my boss's. Everything's relative - absolutely.