MSWSP: add two more Property Sets
[wireshark-wip.git] / tools / setuid-root.pl.in
blob066702533b48da3046cbcd698b840386c4f91352
1 #!/usr/bin/perl -w
3 # setuid-root - Enable/disable setuid for tshark and dumpcap.
5 # $Id$
7 # Copyright 2007, Luis Ontanon and Gerald Combs
9 # Wireshark - Network traffic analyzer
10 # By Gerald Combs <gerald@wireshark.org>
11 # Copyright 1998 Gerald Combs
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 sub usage() {
28 die <<FIN
29 Usage: $0 {enable|disable} [revert owner]
31 Examples:
32 $0 enable # Changes owner to root and enables setuid
33 $0 disable # Changes owner to \$SUDO_USER and disables setuid
34 $0 disable kurtv # Changes owner to kurtv and disables setuid
35 FIN
38 $< == 0 or die "only root can run this script";
40 $bin_prefix = "@BIN_PREFIX@";
42 if ($#ARGV < 0) { usage(); }
44 $command = shift;
45 $command =~ tr/A-Z/a-z/;
47 $tshark_bin = "@TSHARK_BIN@";
48 $dumpcap_bin = "@DUMPCAP_BIN@";
50 die "Don't know prefix path" if length($bin_prefix) < 1;
51 die "Don't know tshark binary name" if length($tshark_bin) < 1;
52 die "Don't know dumpcap binary name" if length($dumpcap_bin) < 1;
54 $revert_owner = "";
55 if ($#ARGV >= 0) {
56 $revert_owner = shift;
59 if (length($revert_owner) < 1 && length($ENV{SUDO_USER}) > 0) {
60 $revert_owner = $ENV{SUDO_USER};
63 if ($command eq "enable") {
64 system("chown root $bin_prefix/$tshark_bin");
65 system("chown root $bin_prefix/$dumpcap_bin");
66 system("chmod ug+s $bin_prefix/$tshark_bin");
67 system("chmod ug+s $bin_prefix/$dumpcap_bin");
68 exit 0;
71 if ($command eq "disable"){
72 system("chmod ug-s $bin_prefix/$tshark_bin");
73 system("chmod ug-s $bin_prefix/$dumpcap_bin");
74 die "Can't revert owner" if length($revert_owner) < 1;
75 system("chown $revert_owner $bin_prefix/$tshark_bin");
76 system("chown $revert_owner $bin_prefix/$dumpcap_bin");
77 exit(0);
80 usage();