aboutsummaryrefslogtreecommitdiffstats
path: root/tools/setuid-root.pl.in
blob: 7efcf5762ee0af4575b55689a0fd3eb4ec57f6fc (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
#!/usr/bin/perl -w
#
# setuid-root - Enable/disable setuid for tshark and dumpcap.
#
# $Id$
#
# Copyright 2007, Luis Ontanon and Gerald Combs
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

sub usage() {
  die <<FIN
Usage: $0 {enable|disable} [revert owner]

Examples:
  $0 enable		# Changes owner to root and enables setuid
  $0 disable		# Changes owner to \$SUDO_USER and disables setuid
  $0 disable kurtv	# Changes owner to kurtv and disables setuid
FIN
}

$< == 0 or die "only root can run this script";

$bin_prefix = "@BIN_PREFIX@";

if ($#ARGV < 0) { usage(); }

$command = shift;
$command =~ tr/A-Z/a-z/;

$tshark_bin = "@TSHARK_BIN@";
$dumpcap_bin = "@DUMPCAP_BIN@";

die "Don't know prefix path" if length($bin_prefix) < 1;
die "Don't know tshark binary name" if length($tshark_bin) < 1;
die "Don't know dumpcap binary name" if length($dumpcap_bin) < 1;

$revert_owner = "";
if ($#ARGV >= 0) {
  $revert_owner = shift;
}

if (length($revert_owner) < 1 && length($ENV{SUDO_USER}) > 0) {
  $revert_owner = $ENV{SUDO_USER};
}

if ($command eq "enable") {
  system("chown root $bin_prefix/$tshark_bin");
  system("chown root $bin_prefix/$dumpcap_bin");
  system("chmod ug+s $bin_prefix/$tshark_bin");
  system("chmod ug+s $bin_prefix/$dumpcap_bin");
  exit 0;
} 

if ($command eq "disable"){
  system("chmod ug-s $bin_prefix/$tshark_bin");
  system("chmod ug-s $bin_prefix/$dumpcap_bin");
  die "Can't revert owner" if length($revert_owner) < 1;
  system("chown $revert_owner $bin_prefix/$tshark_bin");
  system("chown $revert_owner $bin_prefix/$dumpcap_bin");
  exit(0);
}

usage();