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