🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #340

Problems with setuid(), SVr2v2 - (nf)

#340
From: tim
Date: Mon, 22 Sep 1986 20:23
77 lines
2369 bytes
The setuid() system call under SVr2v2 (on a 3B2) doesn't seem to do
one thing which the manual claims it does :

> If the effective user id of the calling process is not super-user,
> but the saved set-user (group) ID from exec(2) is equal to uid (gid),
> the effective user (group) ID is set to uid (gid).

I'm using a process which has set-uid to root; first I want to
change my id's to a project id to read project data, and then
back to those of the caller (to read his files). On BSD this
works fine - you toggle real and eff. via setre(g/u)id. But I
can't for the life of me get any effect on SVr2v2 which would
approximate to what the manual claims is possible.

HELP !!!!!! (I've got a deadline for this stuff ...)

Repeat-by :
Compile this short test program, install it set-uid to root,
and run it. Play around with the calls to reset to the users id's.

------------ 8< -------------------8< ----------------

#include <stdio.h>
main()
{
int c_uid, c_gid;

c_uid = getuid() ;
c_gid = getgid() ;

printf("Real uid = %d\n",getuid()) ;
printf("Eff. uid = %d\n",geteuid()) ;
printf("Real gid = %d\n",getgid()) ;
printf("Eff. gid = %d\n",getegid()) ;

/* Set other id's */
if (setgid(555) != 0)
   {
   printf("setgid proj\n") ;
   exit(0) ;
   }
else ;
if (setuid(555) != 0)
   {
   printf("setuid proj\n") ;
   exit(0) ;
   }
else ;

printf("Real uid = %d\n",getuid()) ;
printf("Eff. uid = %d\n",geteuid()) ;
printf("Real gid = %d\n",getgid()) ;
printf("Eff. gid = %d\n",getegid()) ;

/* Reset caller's id's */
if (setuid(0) != 0)    /* THIS WAS set-user ID from exec ??? */
   {
   printf("setuid 0\n") ;
   exit(0) ;
   }
else ;
if (setgid(c_gid) != 0)
   {
   printf("setgid user\n") ;
   exit(0) ;
   }
else ;
if (setuid(c_uid) != 0)
   {
   printf("setuid user\n") ;
   exit(0) ;
   }
else ;

exit(0) ;
}
Technical Details
Message-ID: <4100002@siedap.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!unido!siedap!tim

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!unido!siedap!tim
From: tim@siedap.UUCP
Newsgroups: net.bugs.usg
Subject: Problems with setuid(), SVr2v2 - (nf)
Message-ID: <4100002@siedap.UUCP>
Date: Mon, 22-Sep-86 16:23:00 EDT
Article-I.D.: siedap.4100002
Posted: Mon Sep 22 16:23:00 1986
Date-Received: Thu, 25-Sep-86 03:47:42 EDT
Lines: 77
Nf-ID: #N:siedap:4100002:000:1819
Nf-From: siedap!tim    Sep 22 21:23:00 1986