/usr/sbin/addtcpquota is in tcpquota 1.6.15-13.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | #!/usr/bin/perl -w
######################################################################
#
# Allowe or disallowe users to tcp quota...
#
#
# 1996-09-15 turbo: begun
# 1996-09-16 turbo: changed so that database 'tcpquota' contain all info
# 1996-09-23 turbo: adding 0 quota in the database when adding a NEW user
#
# $Header: /us/usr/lib/tcpquota/cvs/root/tcpquota/addtcpquota,v 1.13 1998/08/01 19:57:50 turbo Exp $
#
# $Log: addtcpquota,v $
# Revision 1.13 1998/08/01 19:57:50 turbo
# * First quick port to use the generic database interface 'DBI' instead of
# the 'Msql' interface. This is so that we can go from using mSQL as
# database, to use the much quicker mySQL server. But by using this generic
# interface, we can have both... More or less :)
# # Any reference to the Msql function 'query' had to be replaced with, first
# a 'prepare' then a 'execute'. If the execute fails, then die, or log, or
# what evere takes us fancy...
# * Any reference to the Msql functions 'fetchrow' and 'numrows', had to be
# replaced with 'fetchrow_array' and 'rows'.
# * Found a 'open_sql_server()' function in the 'tcp_masq_openfw' script. Move
# that to the library, so that we can reuse the function all over the board.
# # Added a lot of '&' to the call of our own functions... They glow with such
# a pretty blue color in X... :)
#
# Revision 1.12 1998/05/24 19:46:48 turbo
# Do all checking of the command line in a couple of elsif's, to minimize
# the chance of an error...
#
# Revision 1.11 1998/05/24 15:52:45 turbo
# Help more conformant with the other programs in the package...
#
# Revision 1.10 1998/03/31 12:16:02 turbo
# Make sure we search and opens the correct config file,
# set by the variables '{lib|conf}_dir' at the top...
#
# Revision 1.9 1997/12/03 10:14:55 turbo
# * Removed some fucked up CVS header lines...
# * Rewrote the command line handling a little, more GNU like...
# * Double check that we have the arguments required, before accessing the
# database.
# * Moved the 'list_dbase()' to the library file, it was (practicaly) used
# by the 'chktcpquota' script to...
# * If the user exist in the database, output/exit with 1, otherwise 0.
# * Added a 'help()' function, which describes the usage...
#
# Revision 1.8 1997/11/26 21:29:54 turbo
# Removed a lot of config file variables, that could possibly confuse a new
# user/admin of the package... We asume that whoever chooses to install the
# package, use our default... If not, they can go in and change the stuff
# themselvs!!
#
# Revision 1.7 1997/11/04 14:53:32 turbo
# We should require '/usr/lib/tcpquota/tcpquota.pl' instead of 'lib/tcpquota.pl'...
#
# Revision 1.6 1997/09/26 15:52:57 turbo
# * Forgot the $DEBUG variable... Perl complained...
# * Better looking output if started without parameters... We have to understand
# that the 'lst' param takes param <user>... ('[lst <user>]' instead of
# '[lst] <user>')
#
# Revision 1.5 1997/08/17 17:19:19 turbo
# * Added the cvs Header and Log
# * Removed a lot of config file variables, that could possibly confuse a new
# * user/admin of the package... We asume that whoever chooses to install the
# * package, use our default... If not, they can go in and change the stuff
# * themselvs!!
#
# * Moved some functions to the library file.
# * Deleted some variables, they exists in the config file.
#
#
# Include some magic...
use DBI;
#use Getopt::Long;
$lib_dir = "/usr/lib/tcpquota";
$conf_dir = "/etc/tcpquota";
require "$lib_dir/tcpquota.pl";
$ADD = 0; $REM = 0; $CHK = 0; $LST = 0;
$dummy = 0;
# Does we have any arguments?
if( $ARGV[0] ) {
# Ohh yes.... Process it...
foreach $arg (@ARGV) {
# Help?
if( $arg eq '--help' || $arg eq '?' || $arg eq '-h' ) {
&help();
} elsif( $arg eq 'all' || $arg eq '--all' || $arg eq '-A' ) {
# Check if user exist...
$CHK = 1;
} elsif( $arg eq 'add' || $arg eq '--add' || $arg eq '-a' ) {
# Add user?
$ADD = 1;
} elsif( $arg eq 'rem' || $arg eq '--rem' || $arg eq '-r' ) {
# Remove user?
$REM = 1;
} elsif( $arg eq 'lst' || $arg eq '--lst' || $arg eq '-l' ) {
# List?
$LST = 1;
}
}
} else {
&help();
}
if( $LST != 1 ) {
$USER = $ARGV[1];
}
######################################################################
#
# configuration parameters
#
$PROG="addtcpquota";
$CF_FILE="tcpquota.cf";
%cf=(); # config array.
&readconfig("$conf_dir/$CF_FILE",$PROG);
######################################################################
#
# initializing stuff
#
# Open up the database connection...
&open_sql_server();
######################################################################
#
# main loop
#
if( $ADD == 1 ) {
if( $USER ) {
&write_dbase($USER,'add');
} else {
printf("Use $0 add <user>\n");
}
exit(0);
}
if( $REM == 1 ) {
if( $USER ) {
&write_dbase($USER,'rem');
} else {
printf("Use $0 rem <user>\n");
}
exit(0);
}
if( $CHK == 1 ) {
if( $USER ) {
&read_dbase($USER);
} else {
printf("Use $0 all <user>\n");
}
exit(0);
}
if( $LST == 1 ) {
&list_dbase("allowed");
exit(0);
}
######################################################################
#
# write_dbase( $user )
#
# Add the user to the database...
#
sub write_dbase {
local($user,$action) = @_;
# Add the user in the allowed database...
if( $action eq 'add' ) {
$query = "insert into allowed (name) values ('$user')";
} else {
$query = "delete from allowed where name like '$user'";
}
$sth = $dbh->prepare($query);
$sth->execute || die "Could not execute query: $sth->errstr";
# Add 0 in the quota database (if he/she doesn't exist there already)
if( $action eq 'add' ) {
# Check if the user already exist in the database...
$sth = $dbh->prepare("select * from tcptab where name like '$user'");
$sth->execute || die "Could not execute query: $sth->errstr";
($dummy,$sec) = $sth->fetchrow_array;
if(!$sec) {
$sth = $dbh->prepare("insert into tcptab (name,quota) values ('$user',0)");
$sth->execute || die "Could not execute query: $sth->errstr";
}
}
# Print some info about the actions...
if( $action eq 'add' ) {
print "Added user `$user'...\n";
} else {
print "Removed user `$user'...\n";
}
}
######################################################################
#
# read_dbase( $user )
#
# Check if the user is in the database...
#
sub read_dbase {
local($user) = @_;
# Query the database.
$sth = $dbh->prepare("select * from allowed where name like '$user'");
$sth->execute || &terminate( "Error when query..." );
($name) = $sth->fetchrow_array;
if( $name ) {
# User is allowed...
print "1";
exit 1;
} else {
# User is not allowed...
print "0";
exit 0;
}
}
######################################################################
#
# help( void )
#
# Print out some help and then exit
#
sub help {
print "Usage: addtcpquota [OPTION] [<user>]\n";
print " Where OPTIONS could be:\n";
print " --all, all, -A Check if a user is allowed to use the TCP link\n";
print " --add, add, -a Allow a user to use the TCP link\n";
print " --rem, rem, -r Dissallow a user to use the TCP link\n";
print " --lst, lst, -l List users allowed to use the TCP link\n";
exit 0;
}
|