summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarry T. Williams <garry@zvolve.com>2000-09-04 08:09:44 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2000-11-01 20:56:34 +0000
commita043a68546f5b73797216edaeee5d9ddb364c19a (patch)
tree1adac73aaa089abb5b9dffc4afb47c6994909b03
parente093bcf0cf7ac8078690b5226007992e026a34d0 (diff)
downloadperl-a043a68546f5b73797216edaeee5d9ddb364c19a.tar.gz
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
-rw-r--r--ext/POSIX/POSIX.pm10
-rw-r--r--ext/POSIX/POSIX.pod16
-rw-r--r--ext/POSIX/POSIX.xs24
-rw-r--r--ext/POSIX/typemap4
-rw-r--r--pod/perlvar.pod12
5 files changed, 41 insertions, 25 deletions
diff --git a/ext/POSIX/POSIX.pm b/ext/POSIX/POSIX.pm
index 252e5bbad1..e1e6b28e40 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 314147cb2b..e93fb742da 100644
--- a/ext/POSIX/POSIX.pod
+++ b/ext/POSIX/POSIX.pod
@@ -1008,9 +1008,12 @@ see L<perlre>.
=item setgid
-Sets the real group identifier for this process.
-Identical to assigning a value to the Perl's builtin C<$)> variable,
-see L<perlvar/$UID>.
+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<perlvar/$GID>, 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<lt>> variable,
-see L<perlvar/$UID>.
+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<lt>> variable, see L<perlvar/$UID>, 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 a536671afc..c5d169a9f2 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -65,7 +65,7 @@
# include <lib$routines.h> /* prototype for lib$ediv() */
# include <starlet.h> /* 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 baf9bfc051..c94df7a4b9 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 83f4d9cd9e..49cdcb273e 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<from>,
-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<to>, 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<not> 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<group> things. The real gid is the
group you I<left>, 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<group> things. The effective gid
is the group that's I<right> for you, if you're running setgid.)