-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SSL support via IO::Socket::SSL
Added P (port) lines to the configuration file Updated INTERNALS and README to reflect the above changes
- Loading branch information
Showing
7 changed files
with
93 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# | ||
# Connection.pm | ||
# Created: Tue Sep 15 14:26:26 1998 by [email protected] | ||
# Revised: Thu Mar 23 16:56:38 2000 by [email protected] | ||
# Revised: Tue Dec 12 18:13:47 2000 by [email protected] | ||
# Copyright 1998 Jay F. Kominek ([email protected]) | ||
# | ||
# Consult the file 'LICENSE' for the complete terms under which you | ||
|
@@ -29,8 +29,8 @@ sub new { | |
$this->{'server'} = shift; | ||
$this->{'connected'} = $this->{last_active} = time(); | ||
|
||
# print $this->{'socket'}; | ||
# print "\n"; | ||
$this->{'ssl'} = $this->{'socket'}->isa("IO::Socket::SSL"); | ||
|
||
my($port,$iaddr) = sockaddr_in(getpeername($this->{'socket'})); | ||
$this->{'host'} = gethostbyaddr($iaddr,AF_INET) || inet_ntoa($iaddr); | ||
$this->{'host_ip'} = inet_ntoa($iaddr); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# | ||
# LocalServer.pm | ||
# Created: Sat Sep 26 18:11:12 1998 by [email protected] | ||
# Revised: Sat Aug 19 23:10:44 2000 by [email protected] | ||
# Revised: Tue Dec 12 19:37:32 2000 by [email protected] | ||
# Copyright 1998 Jay F. Kominek ([email protected]) | ||
# | ||
# Consult the file 'LICENSE' for the complete terms under which you | ||
|
@@ -113,6 +113,17 @@ sub loadconffile { | |
$this->{'opers'}->{ $nick }->{'password'} = $password; | ||
next CONFPARSE; | ||
} | ||
# Port line | ||
if($line =~ /^P:([^:]+):([^:]+)$/) { | ||
if($2) { | ||
# SSL socket | ||
push @{ $this->{'sslports'} }, $1; | ||
} else { | ||
# Normal socket | ||
push @{ $this->{'ports'} }, $1; | ||
} | ||
next CONFPARSE; | ||
} | ||
# Kill Line | ||
if($line =~ /^K:([^:]+):([^:]+):([^.]+)$/) { | ||
my($mask,$reason,$usermask) = ($1,$2,$3); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# | ||
# User.pm | ||
# Created: Tue Sep 15 12:56:51 1998 by [email protected] | ||
# Revised: Thu Mar 23 16:55:47 2000 by [email protected] | ||
# Revised: Tue Dec 12 19:14:00 2000 by [email protected] | ||
# Copyright 1998 Jay F. Kominek ([email protected]) | ||
# | ||
# Consult the file 'LICENSE' for the complete terms under which you | ||
|
@@ -83,6 +83,7 @@ sub new { | |
$this->{'ircname'} = $connection->{'ircname'}; | ||
$this->{'server'} = $connection->{'server'}; | ||
$this->{'connected'} = $connection->{'connected'}; | ||
$this->{'ssl'} = $connection->{'ssl'}; | ||
$this->{'idle_base'} = | ||
$this->{'last_active'} = time(); | ||
$this->{'modes'} = { }; | ||
|
@@ -433,6 +434,9 @@ sub handle_whois { | |
if($user->islocal()) { | ||
$this->sendnumeric($this->server,317,($user->nick,time()-$user->{'idle_base'},$user->connected),"seconds idle, signon time"); | ||
} | ||
if($user->ssl()) { | ||
$this->sendnumeric($this->server,342,$user->nick." is connected via SSL"); | ||
} | ||
} else { | ||
$this->sendnumeric($this->server,401,$target,"No suck nick"); | ||
} | ||
|
@@ -1109,6 +1113,11 @@ sub away { | |
return $this->{awaymsg}; | ||
} | ||
|
||
sub ssl { | ||
my $this = shift; | ||
return $this->{'ssl'}; | ||
} | ||
|
||
# We don't want to ping someone we've already pung. | ||
sub ping_in_air { | ||
my $this = shift; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# | ||
# pircd | ||
# Created: Mon Sep 14 12:55:01 1998 by [email protected] | ||
# Revised: Wed Nov 22 11:07:48 2000 by [email protected] | ||
# Revised: Tue Dec 12 19:40:07 2000 by [email protected] | ||
# Copyright 1998 Jay F. Kominek ([email protected]) | ||
# | ||
# Consult the file 'LICENSE' for the complete terms under which you | ||
|
@@ -38,9 +38,13 @@ $| = 1; | |
# things breaking. | ||
my %connections = (); | ||
my %unfinished = (); | ||
my %serversocks = (); | ||
tie %connections, 'Tie::RefHash'; | ||
tie %unfinished, 'Tie::RefHash'; | ||
tie %serversocks, 'Tie::RefHash'; | ||
my $port = 6667; | ||
my $sslport = 36900; | ||
my $ssl = 0; | ||
my $backlog = 10; | ||
my $daemon = 0; | ||
my $conf = "server.conf"; | ||
|
@@ -49,9 +53,11 @@ my $logfile = "/var/log/pircd"; | |
# Parse the command line | ||
use Getopt::Std; | ||
my %opts; | ||
getopts('dhp:b:f:l:',\%opts) || &displayhelp; | ||
getopts('dhp:q:sb:f:l:',\%opts) || &displayhelp; | ||
if(defined($opts{'p'})) { $port = $opts{'p'}; } | ||
if(defined($opts{'p'})) { $sslport = $opts{'p'}; } | ||
if(defined($opts{'b'})) { $backlog = $opts{'b'}; } | ||
if(defined($opts{'s'})) { $ssl = 1; } | ||
if(defined($opts{'d'})) { $daemon = 1; } | ||
if(defined($opts{'f'})) { $conf = $opts{'f'}; } | ||
if(defined($opts{'h'})) { &displayhelp; } | ||
|
@@ -63,22 +69,41 @@ if($daemon) { | |
POSIX::setsid() || Utils::syslog('notice',"Cannot start a new session: $!"); | ||
} | ||
|
||
my $server = IO::Socket::INET->new(LocalPort => $port, | ||
Listen => $backlog, | ||
Reuse => 1, | ||
Proto => 'tcp'); | ||
if(!defined($server)) { | ||
# note that 5.004 Socket.pm's _error() spooges on $!, so we use $@ here | ||
Utils::syslog('err',"Failed to open listening socket on port $port: $@"); | ||
exit(-1); | ||
} | ||
|
||
my $tmp = LocalServer->new($conf); | ||
Utils::servers()->{$tmp->name()} = $Utils::thisserver = $tmp; | ||
$Utils::stats{highclients} = 0; | ||
$Utils::stats{highconnections} = 0; | ||
|
||
my $select = IO::Select->new($server); | ||
foreach my $tmpport ($port,@{ $tmp->{'ports'} }) { | ||
my $server = IO::Socket::INET->new(LocalPort => $tmpport, | ||
Listen => $backlog, | ||
Reuse => 1, | ||
Proto => 'tcp'); | ||
if(!defined($server)) { | ||
# note that 5.004 Socket.pm's _error() spooges on $!, so we use $@ here | ||
Utils::syslog('err',"Failed to open listening socket on port $tmpport: $@"); | ||
exit(-1); | ||
} | ||
$serversocks{$server} = 1; | ||
} | ||
|
||
if($ssl) { | ||
use IO::Socket::SSL; | ||
|
||
foreach my $tmpport ($sslport,@{ $tmp->{'sslports'} }) { | ||
my $sslserver = IO::Socket::SSL->new(LocalPort => $tmpport, | ||
Listen => $backlog, | ||
Reuse => 1, | ||
Proto => 'tcp'); | ||
if(!defined($sslserver)) { | ||
Utils::syslog('err',"Failed to open SSL listening socket on port $tmpport: $@"); | ||
exit(-1); | ||
} | ||
$serversocks{$sslserver} = 1; | ||
} | ||
} | ||
|
||
my $select = IO::Select->new(keys %serversocks); | ||
# While we key these on the $client's socket object, we | ||
# don't have to iterate over them in such as way that they | ||
# have to be RefHashes | ||
|
@@ -99,12 +124,11 @@ for(;;) { | |
my $time; | ||
|
||
foreach $client ($select->can_read(0.5)) { | ||
if($client == $server) { | ||
if($serversocks{$client}) { | ||
# Activity on the listening socket means we have a new | ||
# client attempting to connect. | ||
my($iaddr,$address,$port,$peer_host,$peer_ip); | ||
# Get ahold of the new socket, assign it to all the whatnot, etc | ||
$client = $server->accept; | ||
$client = $client->accept; | ||
$select->add($client); | ||
&setnonblocking($client); | ||
$connections{$client} = Connection->new($client, \%outbuffer, | ||
|
@@ -115,7 +139,7 @@ for(;;) { | |
$time = time(); | ||
$timer{$client} = $time if $timer{$client} < $time; | ||
my($data,$got); | ||
$got = $client->recv($data,POSIX::BUFSIZ,0); | ||
$got = $client->sysread($data,POSIX::BUFSIZ); | ||
unless(defined $got && length $data) { | ||
# Aww. We had an error reading from their socket, so we have | ||
# to cut them loose. | ||
|
@@ -212,7 +236,7 @@ for(;;) { | |
# Skip it if we don't have anything available to send it. | ||
next unless $outbuffer{$client}; | ||
# Actually attempt to send some of the data. | ||
my $sent = $client->send($outbuffer{$client},0); | ||
my $sent = $client->syswrite($outbuffer{$client},POSIX::BUFSIZ); | ||
if(!defined($sent)) { next; } | ||
# If we couldn't manage to send the whole thing, then trim what we | ||
# did manage to send them out of the out-going buffer so we don't | ||
|
@@ -302,6 +326,8 @@ sub setnonblocking { | |
sub displayhelp { | ||
print "Usage: pircd [OPTION]... | ||
-p Set default listening port [$port] | ||
-q Set default SSL port [$sslport] | ||
-s Enable SSL | ||
-b Set the max incoming backlog [$backlog] | ||
-f Server configuration file [$conf] | ||
-d Fork and daemonize | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters