3 # setuid-root - Enable/disable setuid for tshark and dumpcap.
5 # Copyright 2007, Luis Ontanon and Gerald Combs
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 1998 Gerald Combs
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.
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.
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.
27 Usage: $0 {enable|disable} [revert owner]
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
36 $< == 0 or die "only root can run this script";
38 $bin_prefix = "@BIN_PREFIX@";
40 if ($#ARGV < 0) { usage(); }
43 $command =~ tr/A-Z/a-z/;
45 $tshark_bin = "@TSHARK_BIN@";
46 $dumpcap_bin = "@DUMPCAP_BIN@";
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;
54 $revert_owner = shift;
57 if (length($revert_owner) < 1 && length($ENV{SUDO_USER}) > 0) {
58 $revert_owner = $ENV{SUDO_USER};
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");
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");