From: Garry T. Williams Date: Mon, 4 Sep 2000 12:09:44 +0000 (-0400) Subject: Make the POSIX::setuid and POSIX::setgid to really call setuid() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a043a68546f5b73797216edaeee5d9ddb364c19a;p=p5sagit%2Fp5-mst-13.2.git Make the POSIX::setuid and POSIX::setgid to really call setuid() and setgid() because they were just changing $< and $( which means only changing the real uid/gid, as opposed to changing both real and effective ids. (The alternative way could have been in POSIX.pm to change $> and $), too, but making a direct call to the C API feels cleaner.) Fixes the bug Subject: [ID 20000904.005] POSIX::setuid() Doesn't Call setuid() Message-Id: <200009041609.e84G9iN12155@ifr.inside.zvolve.net> p4raw-id: //depot/perl@7521 --- diff --git a/ext/POSIX/POSIX.pm b/ext/POSIX/POSIX.pm index 252e5bb..e1e6b28 100644 --- a/ext/POSIX/POSIX.pm +++ b/ext/POSIX/POSIX.pm @@ -734,16 +734,6 @@ sub setbuf { redef "IO::Handle::setbuf()"; } -sub setgid { - usage "setgid(gid)" if @_ != 1; - $( = $_[0]; -} - -sub setuid { - usage "setuid(uid)" if @_ != 1; - $< = $_[0]; -} - sub setvbuf { redef "IO::Handle::setvbuf()"; } diff --git a/ext/POSIX/POSIX.pod b/ext/POSIX/POSIX.pod index 314147c..e93fb74 100644 --- a/ext/POSIX/POSIX.pod +++ b/ext/POSIX/POSIX.pod @@ -1008,9 +1008,12 @@ see L. =item setgid -Sets the real group identifier for this process. -Identical to assigning a value to the Perl's builtin C<$)> variable, -see L. +Sets the real group identifier and the effective group identifier for +this process. Similar to assigning a value to the Perl's builtin +C<$)> variable, see L, except that the latter +will change only the real user identifier, and that the setgid() +uses only a single numeric argument, as opposed to a space-separated +list of numbers. =item setjmp @@ -1063,9 +1066,10 @@ setting the session identifier of the current process. =item setuid -Sets the real user identifier for this process. -Identical to assigning a value to the Perl's builtin C<$E> variable, -see L. +Sets the real user identifier and the effective user identifier for +this process. Similar to assigning a value to the Perl's builtin +C<$E> variable, see L, except that the latter +will change only the real user identifier. =item sigaction diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index a536671..c5d169a 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -65,7 +65,7 @@ # include /* prototype for lib$ediv() */ # include /* prototype for sys$gettim() */ # if DECC_VERSION < 50000000 -# define pid_t int /* old versions of DECC miss this in types.h */ +# define Pid_t int /* old versions of DECC miss this in types.h */ # endif # undef mkfifo @@ -117,7 +117,7 @@ # define mkfifo(a,b) not_here("mkfifo") # define ttyname(a) (char*)not_here("ttyname") # define sigset_t long -# define pid_t long +# define Pid_t long # ifdef __BORLANDC__ # define tzname _tzname # endif @@ -3545,20 +3545,20 @@ read(fd, buffer, nbytes) SysRet setpgid(pid, pgid) - pid_t pid - pid_t pgid + Pid_t pid + Pid_t pgid -pid_t +Pid_t setsid() -pid_t +Pid_t tcgetpgrp(fd) int fd SysRet tcsetpgrp(fd, pgrp_id) int fd - pid_t pgrp_id + Pid_t pgrp_id int uname() @@ -3940,6 +3940,14 @@ pathconf(filename, name) SysRet pause() +SysRet +setgid(gid) + Gid_t gid + +SysRet +setuid(uid) + Uid_t uid + SysRetLong sysconf(name) int name @@ -3947,3 +3955,5 @@ sysconf(name) char * ttyname(fd) int fd + + diff --git a/ext/POSIX/typemap b/ext/POSIX/typemap index baf9bfc..c94df7a 100644 --- a/ext/POSIX/typemap +++ b/ext/POSIX/typemap @@ -1,8 +1,10 @@ Mode_t T_NV -pid_t T_NV +Pid_t T_NV Uid_t T_NV Time_t T_NV Gid_t T_NV +Uid_t T_NV +Gid_t T_NV Off_t T_NV Dev_t T_NV NV T_NV diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 83f4d9c..49cdcb2 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -619,7 +619,8 @@ across fork() calls. (Mnemonic: same as shells.) =item $< The real uid of this process. (Mnemonic: it's the uid you came I, -if you're running setuid.) +if you're running setuid.) You can change both the real uid and +the effective uid at the same time by using POSIX::setuid(). =item $EFFECTIVE_USER_ID @@ -632,6 +633,9 @@ The effective uid of this process. Example: $< = $>; # set real to effective uid ($<,$>) = ($>,$<); # swap real and effective uid +You can change both the effective uid and the real uid at the same +time by using POSIX::setuid(). + (Mnemonic: it's the uid you went I, if you're running setuid.) C<< $< >> and C<< $> >> can be swapped only on machines supporting setreuid(). @@ -652,6 +656,9 @@ However, a value assigned to C<$(> must be a single number used to set the real gid. So the value given by C<$(> should I be assigned back to C<$(> without being forced numeric, such as by adding zero. +You can change both the real gid and the effective gid at the same +time by using POSIX::setgid(). + (Mnemonic: parentheses are used to I things. The real gid is the group you I, if you're running setgid.) @@ -674,6 +681,9 @@ empty list for setgroups(), just repeat the new effective gid; that is, to force an effective gid of 5 and an effectively empty setgroups() list, say C< $) = "5 5" >. +You can change both the effective gid and the real gid at the same +time by using POSIX::setgid() (use only a single numeric argument). + (Mnemonic: parentheses are used to I things. The effective gid is the group that's I for you, if you're running setgid.)