Re: pppd en root seulement !
On 2005-07-31 23:52:44 +0400, Stephane wrote:
> >Le groupe, c'est dip.
> >
> fait aussi ... marche pas :(
Moi j'ai bêtement écrit un script Perl setuid root qui lance pppd
et fait quelques petites autres choses. J'attache ce script ppp-on
(ainsi que le ppp-off qui va avec).
Si je me souviens bien, j'avais écrit ces scripts à l'origine pour
une autre distrib Linux.
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
#!/usr/bin/perl -T
# Note: this script should be setuid and setgid root.
use strict;
use warnings;
my $RCSID = '$Id: ppp-on 3059 2004-04-17 12:03:20Z lefevre $';
my ($proc) = $RCSID =~ /^.Id: (\S+) / or die;
$ENV{'PATH'} = '/usr/sbin:/usr/bin:/sbin:/bin';
@ARGV == 1 and my ($isp) = $ARGV[0] =~ /^([-0-9A-Za-z_]+)$/
or die "Usage: $proc <ISP>\n";
$< = $>; # set real to effective uid
$( = $); # set real to effective gid
system '/sbin/ifconfig', 'eth0', 'down';
my $mf = '/var/log/messages';
my $s1 = (stat $mf)[7];
system '/usr/sbin/pppd', 'call', $isp and die;
my $s2 = $s1;
while (1)
{
my $s3;
while (($s3 = (stat $mf)[7]) == $s2)
{ sleep 1; }
$s2 = $s3;
open FILE, $mf or die "$proc: can't open $mf\n";
seek FILE, $s1, 0 or die "$proc: can't seek $mf\n";
while (<FILE>)
{
if (/ pppd\[\d+\]: Exit\./)
{ print "Failed!\n";
exit; }
if (/ pppd\[\d+\]: local IP address (\d+\.\d+\.\d+\.\d+)$/)
{ print "Connected (local IP address = $1).\n";
&getdate;
exit; }
}
close FILE;
}
sub getdate
{
open NTPSERVER, '/etc/ntp/step-tickers' or return;
my ($server) = <NTPSERVER> =~ /^([a-z][-a-z0-9.]*)$/;
close NTPSERVER;
$server ne '' or return;
print "Updating the system and hardware clocks ($server)...\n";
system qw( /usr/sbin/ntpdate -s -b -p 8 -u ), $server;
system '/sbin/hwclock', '--systohc';
}
#!/usr/bin/perl -T
# Note: this script should be setuid and setgid root.
use strict;
use warnings;
my $RCSID = '$Id: ppp-off 3059 2004-04-17 12:03:20Z lefevre $';
my ($proc) = $RCSID =~ /^.Id: (\S+) / or die;
$ENV{'PATH'} = '/usr/sbin:/usr/bin:/sbin:/bin';
$< = $>; # set real to effective uid
$( = $); # set real to effective gid
my $device = 'ppp0';
my $pidf = "/var/run/$device.pid";
if (-e $pidf)
{
unless (&killproc($pidf, 'INT'))
{ print "Removing stale $device pid file.\n";
unlink $pidf;
exit 1; }
print "$device link terminated.\n";
}
else
{
print "$device link is not active.\n";
exit 1;
}
sub killproc
{
open PIDF, $_[0] or return 0;
my $ok;
<PIDF> =~ /^\s*(\d+)\s*$/ and $ok = kill $_[1], $1;
close PIDF;
return $ok;
}
Reply to: