File: list_exports.cgi

package info (click to toggle)
usermin-contrib 1.110-3
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 1,280 kB
  • ctags: 980
  • sloc: java: 5,979; perl: 1,408; makefile: 106; sh: 4
file content (95 lines) | stat: -rwxr-xr-x 2,386 bytes parent folder | download | duplicates (2)
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
#!/usr/local/bin/perl
# list_exports.cgi
# Output info about NFS exports

require './file-lib.pl';
print "Content-type: text/plain\n\n";
if ($access{'uid'}) {
	# User has no access to NFS
	print "0\n";
	exit;
	}

&read_acl(\%acl, undef);
%einfo = &get_module_info("exports");
%dinfo = &get_module_info("dfsadmin");
#%binfo = &get_module_info("bsdexports");	# too hard

if (%einfo && &check_os_support(\%einfo)) {
	# Linux NFS exports
	&module_check("exports");
	if (!&has_command("rpc.nfsd") && !&has_command("nfsd")) {
		print "0\n";
		exit;
		}
	print "1\n";
	&foreign_require("exports", "exports-lib.pl");
	foreach $e (&foreign_call("exports", "list_exports")) {
		push(@{$exp{$e->{'dir'}}}, $e)
			if ($e->{'dir'} !~ /:/ && $e->{'host'} !~ /:/);
		}
	foreach $d (keys %exp) {
		local $host;
		foreach $e (@{$exp{$d}}) {
			local $o = $e->{'options'};
			$host .= sprintf ":%s:%d:%d",
				$e->{'host'} ? $e->{'host'} : '*',
				defined($o->{'ro'}),
				defined($o->{'all_squash'}) ? 0 :
				defined($o->{'no_root_squash'}) ? 2 : 1;
			}
		print &make_chroot($d),$host,"\n";
		}
	}
elsif (%dinfo && &check_os_support(\%dinfo)) {
	# Solaris NFS shares
	&module_check("dfsadmin");
	print "2\n";
	&foreign_require("dfsadmin", "dfs-lib.pl");
	foreach $s (&foreign_call("dfsadmin", "list_shares")) {
		$opts = &foreign_call("dfsadmin", "parse_options",$s->{'opts'});
		$opts->{'ro'} = '-' if (!defined($opts->{'ro'}));
		$opts->{'ro'} =~ s/:/ /g;
		$opts->{'rw'} = '-' if (!defined($opts->{'rw'}));
		$opts->{'rw'} =~ s/:/ /g;
		$opts->{'root'} = '-' if (!defined($opts->{'root'}));
		$opts->{'root'} =~ s/:/ /g;
		printf "%s:%s:%s:%s:%s\n",
			&make_chroot($s->{'dir'}), $opts->{'ro'}, $opts->{'rw'},
			$opts->{'root'}, $s->{'desc'};
		}
	}
elsif (%binfo && &check_os_support(\%binfo)) {
	# BSD NFS exports
	&module_check("bsdexports");
	print "3\n";
	&foreign_require("bsdexports", "bsdexports-lib.pl");
	foreach $e (&foreign_call("bsdexports", "list_exports")) {
		foreach $d (@{$e->{'dirs'}}) {
			printf "%s:%s", $d, $e->{'ro'} ? 1 : 0;
			if ($e->{'network'}) {
				printf ":%s/%s\n",
					$e->{'network'}, $e->{'mask'};
				}
			else {
				foreach $h (@{$e->{'hosts'}}) {
					print ":$h";
					}
				print "\n";
				}
			}
		}
	}
else {
	# No NFS modules installed or supported
	print "0\n";
	}

sub module_check
{
if (!$acl{$base_remote_user,$_[0]}) {
	print "0\n";
	exit;
	}
}