summaryrefslogtreecommitdiffstats
path: root/lib/network/nfs.pm
blob: b2889757e43fa2559e5ac795100994404a6ad6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package network::nfs;

use strict;
use lib qw(/usr/lib/libDrakX);   # helps perl_checker
use common;

sub read_nfs_ports() {
    my $statd_port = 4001;
    my $statd_outgoing_port;
    my $lockd_tcp_port = 4002;
    my $lockd_udp_port = 4002;
    my $rpc_mountd_port = 4003;
    my $rpc_rquotad_port = 4004;
    if (-f "$::prefix/etc/sysconfig/nfs") {
            foreach (cat_("$::prefix/etc/sysconfig/nfs")) {
                /^STATDARGS=.*(--port|-p) (\d+)/ and $statd_port = $2;
                /^STATDARGS=.*(--outgoing-port|-o) (\d+)/ and $statd_outgoing_port = $2;
                /^LOCKD_TCPPORT=(\d+)/ and $lockd_tcp_port = $1;
                /^LOCKD_UDPPORT=(\d+)/ and $lockd_udp_port = $1;
        }
    }
    if (-f "$::prefix/etc/sysconfig/nfs") {
        foreach (cat_("$::prefix/etc/sysconfig/nfs")) {
            /^RPCMOUNTDARGS=.*(--port|-p) (\d+)/ and $rpc_mountd_port = $2;
            /^RPCRQUOTADARGS=.*(--port|-p) (\d+)/ and $rpc_rquotad_port = $2;
        }
    }

    my $ports = { statd_port => $statd_port,
        lockd_tcp_port => $lockd_tcp_port,
        lockd_udp_port => $lockd_udp_port,
        rpc_mountd_port => $rpc_mountd_port,
        rpc_rquotad_port => $rpc_rquotad_port,
    };
    if (defined $statd_outgoing_port) {
        $ports->{statd_outgoing_port} = $statd_outgoing_port;
    }
    $ports;
}

sub list_nfs_ports() {
    my $ports = read_nfs_ports();

    my $portlist = $ports->{lockd_tcp_port} . "/tcp " . $ports->{lockd_udp_port} . "/udp";
    if (defined $ports->{statd_outgoing_port} && $ports->{statd_outgoing_port} ne $ports->{statd_port}) {
        $portlist .= " " . $ports->{statd_outgoing_port} . "/tcp " . $ports->{statd_outgoing_port} . "/udp";
    }
    foreach (qw(statd_port rpc_mountd_port rpc_rquotad_port)) {
        my $port = $ports->{$_};
        $portlist .= " $port/tcp $port/udp";
    }
    # list of ports in shorewall format
    $portlist;
}

sub write_nfs_ports {
    my ($ports) = @_;
    # enabling fixed ports for NFS services
    my $lockd_options="";
    substInFile {
        if ($ports->{statd_port}) {
            my $port = $ports->{statd_port};
            s/^(STATDARGS)=""$/$1="--port $port"/;
            s/^(STATDARGS)="(.*)(--port \d+)(.*)"$/$1="$2--port $port$4"/;
            s/^(STATDARGS)="(.*)(-p \d+)(.*)"$/$1="$2--port $port$4"/;
        }
        if ($ports->{lockd_tcp_port}) {
            my $port = $ports->{lockd_tcp_port};
            s/^LOCKD_TCPPORT=.*/LOCKD_TCPPORT=$port/;
        }
        if ($ports->{lockd_udp_port}) {
            my $port = $ports->{lockd_udp_port};
            s/^LOCKD_UDPPORT=.*/LOCKD_UDPPORT=$port/;
	}
        if ($ports->{rpc_mountd_port}) {
            my $port = $ports->{rpc_mountd_port};
            s/^(RPCMOUNTDARGS)=""$/$1="--port $port"/;
            s/^(RPCMOUNTDARGS)="(.*)(--port \d+)(.*)"$/$1="$2--port $port$4"/;
            s/^(RPCMOUNTDARGS)="(.*)(-p \d+)(.*)"$/$1="$2--port $port$4"/;
        }
        if ($ports->{rpc_rquotad_port}) {
            my $port = $ports->{rpc_rquotad_port};
            s/^(RPCRQUOTADARGS)=""$/$1="--port $port"/;
            s/^(RPCRQUOTADARGS)="(.*)(--port \d+)(.*)"$/$1="$2--port $port$4"/;
            s/^(RPCRQUOTADARGS)="(.*)(-p \d+)(.*)"$/$1="$2--port $port$4"/;
        }
    } "$::prefix/etc/sysconfig/nfs";
    # kernel-side configuration of nlockmgr
    $lockd_options .= " nlm_tcpport=$ports->{lockd_tcp_port}" if $ports->{lockd_tcp_port};
    $lockd_options .= " nlm_udpport=$ports->{lockd_udp_port}" if $ports->{lockd_udp_port};
    if ($lockd_options ne "") {
        output("$::prefix/etc/modprobe.d/lockd.drakx.conf", "options lockd $lockd_options\n");
    }
}

1;