On 10 Jun 2003 Vincent Lefevre <[EMAIL PROTECTED]> wrote:

> I have written a setuid/setgid-root Perl script that does the following:
>
> #!/usr/bin/suidperl -T
>
> use strict;
> use warnings;
>
> $ENV{'PATH'} = '/usr/sbin:/usr/bin:/sbin:/bin';
>
> @ARGV == 1 and my ($isp) = $ARGV[0] =~ /^([-0-9A-Za-z_]+)$/
>   or die "Usage: ppp-on <ISP>\n";
>
> $< = $>;  # set real to effective uid
>
> system '/sbin/ifconfig', 'eth0', 'down';
>
> system '/usr/sbin/pppd', 'call', $isp and die;
>
> [...]
>
> But when I execute it without doing anything special before, I get the
> following in /var/log/messages:
>
> Jun  9 16:48:23 ay pppd[1210]: pppd 2.4.1 started by root, uid 0
> Jun  9 16:48:23 ay pppd[1210]: Exit.
>
> i.e. it doesn't work. However, if I type
>
>  /usr/sbin/pppd call the_isp
>
> as root, there's no problem:
>
> [snip]
>
> and after disconnecting, I can reconnect using my Perl script ppp-on (that
> previously failed): I get similar log messages except the "ay kernel:"
> lines.
>
> Why doesn't my Perl script work before I connect directly from the root
> account?

I too do not immediately understand that. It looks like the 'and die' part
of the statement
  system '/usr/sbin/pppd', 'call', $isp and die;
is executed regardless of the real success or failure of the pppd call
when the script runs to set up a connection for the very first time,
but when it runs to reconnect, the 'die' is only done if needed
(or maybe: never!)

That would mean the return value of
  system '/usr/sbin/pppd', 'call', $isp
of an initial connect is different from the one for reconnects, and I don't
know why that would be the case. But I expect it can be instructive to
temporarily change the script in such a way that it explicitly reports the
return value ($?) of the system call to start pppd.

The book 'Perl in a Nutshell' on the return value of the system function:
"The return value is the exit status of the program as returned by the
wait(2) call. To get the actual exit value, divide by 256. (The lower eight
bits are set if the process died from a signal.)

Also take into account the quirk that to a shell an exit code value of 0
means succes and anything else failure, while Perl takes 0 as FALSE and
1 as TRUE. This often calls for 'counter-intuitive' code when using the
system function.

Ben

-- 

B.F.M. Kal
Anjelierstraat 1,   2014 TC Haarlem,  Netherlands
tel +31 23 5324909, [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to