Browse Source

add a run-time wrapper which allows ircII to speak IRC-over-SSL via stunnel(1)

Ralf S. Engelschall 20 years ago
parent
commit
815ef22fcb
2 changed files with 128 additions and 8 deletions
  1. 115 0
      ircii/ircii.pl
  2. 13 8
      ircii/ircii.spec

+ 115 - 0
ircii/ircii.pl

@@ -0,0 +1,115 @@
+#!@l_prefix@/bin/perl
+##
+##  ircii.pl -- ircII command line wrapper (for optional SSL support)
+##
+
+require 5.008;
+use strict;
+use warnings;
+use IO::File;
+use Getopt::Long;
+use File::Temp qw(tempfile tempdir);
+
+#   external programs
+my $irc     = '@l_prefix@/libexec/ircii/irc';
+my $stunnel = '@l_prefix@/sbin/stunnel';
+
+#   define command line options
+my $opt = {};
+my %options = (
+    #   standard ircII options
+    'c=s'  => \$opt->{-c},
+    'p=s'  => \$opt->{-p},
+    'P=s'  => \$opt->{-P},
+    'f'    => \$opt->{-f},
+    'F'    => \$opt->{-F},
+    'r'    => \$opt->{-r},
+    's'    => \$opt->{-s},
+    'S'    => \$opt->{-S},
+    'h=s'  => \$opt->{-h},
+    'H=s'  => \$opt->{-H},
+    'd'    => \$opt->{-d},
+    'q'    => \$opt->{-q},
+    'a'    => \$opt->{-a},
+    'b'    => \$opt->{-b},
+    'l=s'  => \$opt->{-l},
+    'I=s'  => \$opt->{-I},
+    't'    => \$opt->{-t},
+    'T'    => \$opt->{-T},
+    'i=s'  => \$opt->{-i},
+    'help' => \$opt->{-help},
+    #   add-on wrapper options
+    'ssl'  => \$opt->{-ssl},
+);
+
+#   parse command line options
+{
+    local @ARGV = @ARGV;
+    my $p = new Getopt::Long::Parser;
+    $p->configure("bundling");
+    $p->getoptions(%options) || die "option parsing failed";
+}
+
+#   remove add-on option
+if (defined($opt->{-ssl})) {
+    for (my $i = 0; $i < @ARGV; $i++) {
+        if ($ARGV[$i] eq '--ssl') {
+            splice(@ARGV, $i, 1);
+            last;
+        }
+    }
+}
+
+if (defined($opt->{-ssl})) {
+    #   encrypted IRC-over-SSL connection
+    if (not -x $stunnel) {
+        print STDERR "irc:ERROR: stunnel(1) required -- please install \"stunnel\" package.\n";
+        exit(1);
+    }
+
+    #   determine parameters
+    srand(time() ^ $$);
+    my $lhost = $opt->{-h};
+    my $lport = 60000 + int(rand() * 1000);
+    my $rhost = ((defined($ARGV[-1]) and $ARGV[-1] !~ m|^-|) ? $ARGV[-1] : "irc");
+    my $rport = ($opt->{-p} || 6667);
+
+    #   start an SSL tunnel
+    my $tmpdir = tempdir("/tmp/ircII-XXXXXX", CLEANUP => 1);
+    my $pidfile = "$tmpdir/stunnel.pid";
+    my $logfile = "$tmpdir/stunnel.log";
+    my $cfgfile = "$tmpdir/stunnel.cfg";
+    my $io = new IO::File ">$cfgfile" || die;
+    $io->print(
+        "client  = yes\n" .
+        "pid     = $pidfile\n" .
+        "output  = $logfile\n" .
+        "[ircs]\n" .
+        (defined($lhost) ?
+        "local   = $lhost\n" : "") .
+        "accept  = localhost:$lport\n" .
+        "connect = $rhost:$rport\n"
+    );
+    $io->close();
+    system $stunnel, $cfgfile;
+    sleep(1);
+
+    #   manipulate ircII command line arguments
+    unshift(@ARGV, "-p", $lport);
+    $ARGV[-1] = "localhost";
+
+    #   start ircII through SSL tunnel
+    my $rc = system $irc, @ARGV;
+
+    #   shutdown SSL tunnel
+    system("kill `cat $pidfile 2>/dev/null`");
+    undef $tmpdir;
+
+    #   exit with ircII return code
+    exit($rc);
+}
+else {
+    #   unencrypted IRC connection
+    exec $irc, @ARGV;
+}
+

+ 13 - 8
ircii/ircii.spec

@@ -33,16 +33,17 @@ Class:        BASE
 Group:        Network
 License:      BSD
 Version:      20040820
-Release:      20040820
+Release:      20050413
 
 #   list of sources
 Source0:      ftp://ircii.warped.com/pub/ircII/ircii-%{version}.tar.gz
+Source1:      ircii.pl
 
 #   build information
 Prefix:       %{l_prefix}
 BuildRoot:    %{l_buildroot}
 BuildPreReq:  OpenPKG, openpkg >= 20040130, gcc
-PreReq:       OpenPKG, openpkg >= 20040130
+PreReq:       OpenPKG, openpkg >= 20040130, perl
 AutoReq:      no
 AutoReqProv:  no
 
@@ -75,12 +76,16 @@ AutoReqProv:  no
 %install
     rm -rf $RPM_BUILD_ROOT
     %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
-    rm $RPM_BUILD_ROOT%{l_prefix}/bin/irc
-    mv $RPM_BUILD_ROOT%{l_prefix}/bin/irc-%{version} \
-       $RPM_BUILD_ROOT%{l_prefix}/bin/irc
-    mv $RPM_BUILD_ROOT%{l_prefix}/man/man1/ircII.1 \
-       $RPM_BUILD_ROOT%{l_prefix}/man/man1/irc.1
-    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true
+    rm  $RPM_BUILD_ROOT%{l_prefix}/bin/irc
+    %{l_shtool} mkdir -f -p -m 755 \
+        $RPM_BUILD_ROOT%{l_prefix}/libexec/ircii
+    mv  $RPM_BUILD_ROOT%{l_prefix}/bin/irc-%{version} \
+        $RPM_BUILD_ROOT%{l_prefix}/libexec/ircii/irc
+    strip $RPM_BUILD_ROOT%{l_prefix}/libexec/ircii/irc
+    mv  $RPM_BUILD_ROOT%{l_prefix}/man/man1/ircII.1 \
+        $RPM_BUILD_ROOT%{l_prefix}/man/man1/irc.1
+    %{l_shtool} install -c -m 755 %{l_value -s -a} \
+        %{SOURCE ircii.pl} $RPM_BUILD_ROOT%{l_prefix}/bin/irc
     rm -f "$RPM_BUILD_ROOT%{l_prefix}/share/irc/help/!"
     rm -f "$RPM_BUILD_ROOT%{l_prefix}/share/irc/help/:"
     %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}