[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

PCMCIA & pppd: a (little) hack

Hi *,

	I wrote a short suid perl script to resolve the problem of
PCMCIA adding a default route that prevents pppd to add its own.
It simply saves and then removes the old route before starting pppd.
When pppd is stopped, it puts back the old default route. I don't
know very much about shell programming and maybe someone wants to
rewrite this in bash... to use it simply call "proute remove" before
pppd (you can hack pon to do that) and "proute restore" after pppd
has finished (again you can change poff a little bit to do it).

Have a nice connection,

Federico Di Gregorio                    {Friend of Penguins}
Debian GNU/Linux Developer                    fog@debian.org
Debian Italian Press Contact             press-it@debian.org
                "Best friends are often failed lovers" -- Me
#!/usr/bin/perl -Tw
# proute - kills or saves back the default route

use strict;

my $runfile = '/var/run/proute';
my $route = '/sbin/route';
my $tempfile = '/bin/tempfile';

# de-taints paths, etc...
$ENV{'PATH'} = '/bin:/usr/bin:/sbin:/usr/sbin';

# we are picky on the argument line
die "usage: proute remove|restore" if @ARGV != 1;

# remove saves the default route and then removes it
if ($ARGV[0] eq 'remove') {
    my $tmpfile = `$tempfile`;
    if ($tmpfile =~ /(.*)/) {$tmpfile = $1};
    if (system("$route -n >$tmpfile") & 0xff00) { 
	die "proute: can't run command $route";
    open(ROUTE, "$tmpfile") or die "proute: can't open $tmpfile for reading";
    while (<ROUTE>) {
	if (/^\s+(\d+\.\d+\.\d+\.\d+)\s+(\d+\.\d+\.\d+\.\d+)/) {
	    open(SAVE, ">$runfile") or 
		die "proute: can't open $runfile for writing";
	    printf SAVE "$1 $2\n";
	    close SAVE;
	    if (system("$route del default") & 0xff00) {
		die "proute: can't remove default route";
    close ROUTE;
    unlink $tmpfile;

# restore use the saved data to restore the old default route
elsif ($ARGV[0] eq 'restore') {
    open(SAVE, "$runfile") or die "proute: can't open $runfile for reading";
    my $savedroute = <SAVE>;
    close SAVE;
    if ($savedroute =~ /(.+)\s(.+)/) {
	if (system("$route add default netmask $2 gw $1") & 0xff00) { 
	    die "proute: can't restore default route";
    else {
	die "proute: can't find the right information in $runfile";
    unlink $runfile;

Reply to: