]> git.pld-linux.org Git - packages/eggdrop.git/blob - eggdrop-ssl.patch
- rediff pathes, rebuild with openssl 3.0.0, rel 2
[packages/eggdrop.git] / eggdrop-ssl.patch
1 --- Makefile.in 2004-03-27 06:50:00.000000000 +0000
2 +++ Makefile.in 2004-03-27 06:50:00.000000000 +0000
3 @@ -62,6 +62,10 @@
4  INSTALL_DATA = @INSTALL_DATA@
5  INSTALL_SCRIPT = @INSTALL_SCRIPT@
6  
7 +# Stuff for SSL
8 +XSSL_LIBS = @SSL_LIBS@
9 +XSSL_INCLUDE = @SSL_INCLUDE@
10 +
11  # Stuff for Tcl
12  TCLLIB = @TCLLIB@
13  TCLLIBFN = @TCLLIBFN@
14 @@ -95,7 +99,8 @@
15  MAKE_MODEGG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(MOD_CC)' 'LD=$(MOD_LD)' \
16  'STRIP=$(MOD_STRIP)' 'RANLIB=$(RANLIB)' 'CFLGS=$(CFLGS)' \
17  'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
18 -'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(standard build)' 'MODOBJS='
19 +'XSSL_LIBS=$(XSSL_LIBS)' 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' \
20 +'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'EGGBUILD=' 'MODOBJS='
21  
22  MAKE_MODULES = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(SHLIB_CC)' 'LD=$(SHLIB_LD)' \
23  'STRIP=$(SHLIB_STRIP)' 'CFLGS=$(CFLGS)' 'XLIBS=$(XLIBS)' \
24 @@ -105,12 +110,13 @@
25  'STRIP=$(STRIP)' 'RANLIB=$(RANLIB)' 'CFLGS=$(CFLGS) -DSTATIC' \
26  'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
27  'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(static version)' \
28 -'MODOBJS=mod/*.o'
29 +'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'XSSL_LIBS=$(XSSL_LIBS)' 'MODOBJS=mod/*.o'
30  
31  MAKE_DEBEGG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(MOD_CC)' 'LD=$(MOD_LD)' \
32  'STRIP=touch' 'RANLIB=$(RANLIB)' 'CFLGS=$(DEBCFLGS) $(CFLGS)' \
33  'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' \
34 -'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(debug version)' 'MODOBJS='
35 +'XSSL_LIBS=$(XSSL_LIBS)' 'XLIBS=$(XLIBS)' 'EGGEXEC=$(EGGEXEC)' \
36 +'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'EGGBUILD=(debug version)' 'MODOBJS='
37  
38  MAKE_DEBMODULES = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(SHLIB_CC)' 'LD=$(SHLIB_LD)' \
39  'XLIBS=$(XLIBS)' 'STRIP=touch' 'CFLGS=$(DEBCFLGS) $(CFLGS)' \
40 @@ -119,7 +125,8 @@
41  MAKE_SDEBUG = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)' 'LD=$(LD)' \
42  'STRIP=touch' 'RANLIB=$(RANLIB)' 'CFLGS=$(DEBCFLGS) $(CFLGS) -DSTATIC' \
43  'TCLLIB=$(TCLLIB)' 'TCLLIBFN=$(TCLLIBFN)' 'XREQS=$(XREQS)' 'XLIBS=$(XLIBS)' \
44 -'EGGEXEC=$(EGGEXEC)' 'EGGBUILD=(static debug version)' 'MODOBJS=mod/*.o'
45 +'XSSL_INCLUDE=$(XSSL_INCLUDE)' 'XSSL_LIBS=$(XSSL_LIBS)' 'EGGEXEC=$(EGGEXEC)' \
46 +'EGGBUILD=(static and debug version)' 'MODOBJS=mod/*.o'
47  
48  MAKE_DEPEND = $(MAKE) 'MAKE=$(MAKE)' 'CC=$(CC)'
49  
50 --- aclocal.m4  2004-03-27 06:50:00.000000000 +0000
51 +++ aclocal.m4  2012-03-31 19:46:26.881862392 +0300
52 @@ -37,6 +37,64 @@
53  ])
54  
55  
56 +dnl  EGG_SSL_CRAP()
57 +dnl
58 +AC_DEFUN(EGG_SSL_CRAP, [dnl
59 +#ssl checks
60 +AC_MSG_CHECKING(whether to include SSL support)
61 +AC_ARG_WITH(ssl,
62 +[  --with-ssl[=PATH]         Include SSL support (DIR is OpenSSL's install dir).],
63 +[
64 +  case "$withval" in
65 +    no)
66 +      AC_MSG_RESULT(no) ;;
67 +    yes)
68 +      AC_MSG_RESULT(yes)
69 +      AC_CHECK_LIB(ssl,SSL_accept,[AC_DEFINE(EGG_SSL_EXT)
70 +      SSL_LIBS="-lssl -lcrypto"],[AC_MSG_ERROR([You requested SSL support, but OpenSSL was not found. Please supply a pathname to OpenSSL])],-lcrypto)
71 +      ;;
72 +    *)
73 +dnl A whole whack of possible places where this might be
74 +      test -f $withval/openssl/ssl.h && SSL_INCLUDE="$withval"
75 +      test -f $withval/include/openssl/ssl.h && SSL_INCLUDE="$withval/include"
76 +
77 +      test -f $withval/lib/libssl.a && SSL_LIB="$withval/lib"
78 +      test -f $withval/lib/ssl/libssl.a && SSL_LIB="$withval/lib/ssl"
79 +      test -f $withval/lib/openssl/libssl.a && SSL_LIB="$withval/lib/openssl/ssl"
80 +      test -f $withval/libssl.a && SSL_LIB="$withval"
81 +      test -f $withval/ssl/libssl.a && SSL_LIB="$withval/ssl"
82 +      test -f $withval/openssl/libssl.a && SSL_LIB="$withval/openssl"
83 +
84 +      test -f $withval/lib/libcrypto.a && CRYPTO_LIB="$withval/lib"
85 +      test -f $withval/lib/ssl/libcrypto.a && CRYPTO_LIB="$withval/lib/ssl"
86 +      test -f $withval/lib/openssl/libcrypto.a && CRYPTO_LIB="$withval/lib/openssl/ssl"
87 +      test -f $withval/libcrypto.a && CRYPTO_LIB="$withval"
88 +      test -f $withval/ssl/libcrypto.a && CRYPTO_LIB="$withval/ssl"
89 +      test -f $withval/openssl/libcrypto.a && CRYPTO_LIB="$withval/openssl"
90 +
91 +      if test -n "$SSL_INCLUDE" && test -n "$SSL_LIB" && test -n "$CRYPTO_LIB"; then
92 +        SSL_LIBS="-lssl -lcrypto -L$SSL_LIB -L$CRYPTO_LIB";
93 +        AC_DEFINE([EGG_SSL_EXT], [], [SSL support])
94 +        AC_MSG_RESULT(yes)
95 +      else
96 +        AC_MSG_RESULT(no)
97 +        AC_MSG_ERROR([You requested SSL support, but OpenSSL was not found. Please supply a pathname to OpenSSL])
98 +      fi ;;
99 +  esac
100 +],[
101 +    AC_MSG_RESULT(will try to find)
102 +    AC_CHECK_LIB(ssl,SSL_accept,[AC_DEFINE(EGG_SSL_EXT)
103 +     SSL_LIBS="-lssl -lcrypto"],[AC_MSG_ERROR([OpenSSL was not found. Please supply a pathname to OpenSSL])],-lcrypto)
104 +    AC_CHECK_HEADERS("openssl/ssl.h",,[AC_MSG_ERROR([OpenSSL was not found. Please supply a pathname to OpenSSL])],)
105 +
106 +    AC_SUBST(SSL_LIBS)dnl
107 +    AC_SUBST(SSL_INCLUDE)dnl
108 +])
109 +
110 +#end of ssl checks
111 +])dnl
112 +
113 +
114  dnl EGG_MSG_CONFIGURE_END()
115  dnl
116  AC_DEFUN([EGG_MSG_CONFIGURE_END],
117 --- config.h.in 2004-03-27 06:50:00.000000000 +0000
118 +++ config.h.in 2004-03-27 06:50:00.000000000 +0000
119 @@ -62,6 +62,9 @@
120     */
121  #undef HAVE_DECL_TZNAME
122  
123 +/* Defines ssl mode  */
124 +#undef EGG_SSL_EXT 
125 +
126  /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
127     */
128  #undef HAVE_DIRENT_H
129 --- configure.ac        2004-03-27 06:50:00.000000000 +0000
130 +++ configure.ac        2004-03-27 06:50:00.000000000 +0000
131 @@ -151,6 +151,7 @@
132                  /usr/local/pkgs/tcl/include /sys/include \
133                  /usr/pkg/lib /beos/system/include /beos/devel/include $HOME"
134  
135 +EGG_SSL_CRAP
136  
137  # We save the cache (if used) here to speed things up if we can't find Tcl.
138  AC_CACHE_SAVE
139 --- src/Makefile.in     2004-03-27 06:50:00.000000000 +0000
140 +++ src/Makefile.in     2004-03-27 06:50:00.000000000 +0000
141 @@ -11,6 +11,8 @@
142  INSTALL_PROGRAM = @INSTALL_PROGRAM@
143  INSTALL_DATA = @INSTALL_DATA@
144  INSTALL_SCRIPT = @INSTALL_SCRIPT@
145 +XSSL_LIBS = @SSL_LIBS@
146 +XSSL_INCLUDE = @SSL_INCLUDE@
147  
148  CC = @CC@
149  LD = @CC@
150 @@ -37,7 +39,7 @@
151         @echo "Linking eggdrop $(EGGBUILD)."
152         @echo ""
153         @touch mod/mod.xlibs
154 -       $(LD) -o ../$(EGGEXEC) $(eggdrop_objs) $(MODOBJS) $(XLIBS) md5/md5c.o compat/*.o `cat mod/mod.xlibs`
155 +       $(LD) -o ../$(EGGEXEC) $(eggdrop_objs) $(MODOBJS) $(XLIBS) md5/md5c.o compat/*.o `cat mod/mod.xlibs` $(XSSL_LIBS) $(XSSL_INCLUDE)
156         $(STRIP) ../$(EGGEXEC)
157         @echo ""
158         @echo "Successful compile: $(EGGEXEC)"
159 --- src/dcc.c   2004-03-27 06:50:00.000000000 +0000
160 +++ src/dcc.c   2004-03-27 06:50:00.000000000 +0000
161 @@ -32,7 +32,11 @@
162  #include "tandem.h"
163  
164  /* Includes for botnet md5 challenge/response code <cybah> */
165 +#ifndef EGG_SSL_EXT
166  #include "md5/md5.h"
167 +#else
168 +#include "openssl/md5.h"
169 +#endif
170  
171  extern struct userrec *userlist;
172  extern struct chanset_t *chanset;
173 --- src/dccutil.c       2004-03-27 06:50:00.000000000 +0000
174 +++ src/dccutil.c       2004-03-27 06:50:00.000000000 +0000
175 @@ -33,6 +33,7 @@
176  #include "chan.h"
177  #include "modules.h"
178  #include "tandem.h"
179 +#include "net.h"
180  
181  extern struct dcc_t *dcc;
182  extern int dcc_total, dcc_flood_thr, backgrd, copy_to_tmp, max_socks;
183 --- src/eggdrop.h       2004-03-27 06:50:00.000000000 +0000
184 +++ src/eggdrop.h       2004-03-27 06:50:00.000000000 +0000
185 @@ -678,15 +678,6 @@
186    ClientData cd;
187  };
188  
189 -typedef struct sock_list {
190 -  int sock;
191 -  short flags;
192 -  union {
193 -    struct sock_handler sock;
194 -    struct tclsock_handler tclsock;
195 -  } handler;
196 -} sock_list;
197 -
198  enum {
199    EGG_OPTION_SET = 1,           /* Set option(s).               */
200    EGG_OPTION_UNSET = 2          /* Unset option(s).             */
201 --- src/main.c  2004-03-27 06:50:00.000000000 +0000
202 +++ src/main.c  2004-03-27 06:50:00.000000000 +0000
203 @@ -164,6 +164,10 @@
204  int cx_ptr = 0;
205  #endif
206  
207 +#ifdef EGG_SSL_EXT
208 +void init_ssl();
209 +int clean_ssl();
210 +#endif
211  
212  void fatal(const char *s, int recoverable)
213  {
214 @@ -174,6 +178,9 @@
215    for (i = 0; i < dcc_total; i++)
216      if (dcc[i].sock >= 0)
217        killsock(dcc[i].sock);
218 +  #ifdef EGG_SSL_EXT
219 +  clean_ssl();
220 +  #endif
221    unlink(pid_file);
222    if (!recoverable) {
223      bg_send_quit(BG_ABORT);
224 @@ -1029,6 +1036,9 @@
225    init_userent();
226    init_misc();
227    init_bots();
228 +#ifdef EGG_SSL_EXT
229 +  init_ssl();
230 +#endif
231    init_modules();
232    if (backgrd)
233      bg_prepare_split();
234 --- src/md5/md5.h       2004-03-27 06:50:00.000000000 +0000
235 +++ src/md5/md5.h       2004-03-27 06:50:00.000000000 +0000
236 @@ -5,6 +5,9 @@
237   * Written by Solar Designer <solar@openwall.com> in 2001, and placed in
238   * the public domain.  See md5c.c for more information.
239   */
240 +#include "../config.h"
241 +#ifndef EGG_SSL_EXT
242 +
243  
244  #ifndef _MD5_H
245  #define _MD5_H
246 @@ -24,3 +27,4 @@
247  extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
248  
249  #endif
250 +#endif
251 --- src/md5/md5c.c      2004-03-27 06:50:00.000000000 +0000
252 +++ src/md5/md5c.c      2004-03-27 06:50:00.000000000 +0000
253 @@ -17,9 +17,23 @@
254  
255  #include <string.h>
256  
257 +#ifndef EGG_SSL_EXT
258  #include "md5.h"
259 +#else
260 +#include "openssl/md5.h"
261 +#endif
262 +
263  #include "compat/compat.h"
264  
265 +typedef unsigned long MD5_u32plus;
266 +
267 +typedef struct {
268 +       MD5_u32plus lo, hi;
269 +       MD5_u32plus a, b, c, d;
270 +       unsigned char buffer[64];
271 +       MD5_u32plus block[16];
272 +} MD5_CTX;
273 +
274  /*
275   * The basic MD5 functions.
276   *
277 --- src/mod/compress.mod/compress.c     2004-03-27 06:50:00.000000000 +0000
278 +++ src/mod/compress.mod/compress.c     2004-03-27 06:50:00.000000000 +0000
279 @@ -36,6 +36,8 @@
280  #include "src/mod/module.h"
281  #include "share.mod/share.h"
282  
283 +#include <zlib.h>
284 +
285  #ifdef HAVE_MMAP
286  #  undef panic
287  #  include <sys/types.h>
288 --- src/mod/irc.mod/chan.c      2004-03-27 06:50:00.000000000 +0000
289 +++ src/mod/irc.mod/chan.c      2004-03-27 06:50:00.000000000 +0000
290 @@ -991,10 +991,10 @@
291          q = strchr(p, ' ');
292          if (q != NULL) {
293            *q = 0;
294 -          set_key(chan, p);
295 +          set_keyegg(chan, p);
296            strcpy(p, q + 1);
297          } else {
298 -          set_key(chan, p);
299 +          set_keyegg(chan, p);
300            *p = 0;
301          }
302        }
303 --- src/mod/irc.mod/irc.c       2004-03-27 06:50:00.000000000 +0000
304 +++ src/mod/irc.mod/irc.c       2004-03-27 06:50:00.000000000 +0000
305 @@ -256,7 +256,7 @@
306  
307  /* Set the key.
308   */
309 -static void set_key(struct chanset_t *chan, char *k)
310 +static void set_keyegg(struct chanset_t *chan, char *k)
311  {
312    nfree(chan->channel.key);
313    if (k == NULL) {
314 --- src/mod/irc.mod/irc.h       2004-03-27 06:50:00.000000000 +0000
315 +++ src/mod/irc.mod/irc.h       2004-03-27 06:50:00.000000000 +0000
316 @@ -68,7 +68,7 @@
317  
318  static void reset_chan_info(struct chanset_t *, int);
319  static void recheck_channel(struct chanset_t *, int);
320 -static void set_key(struct chanset_t *, char *);
321 +static void set_keyegg(struct chanset_t *, char *);
322  static void maybe_revenge(struct chanset_t *, char *, char *, int);
323  static int detect_chan_flood(char *, char *, char *, struct chanset_t *, int,
324                               char *);
325 --- src/mod/irc.mod/mode.c      2004-03-27 06:50:00.000000000 +0000
326 +++ src/mod/irc.mod/mode.c      2004-03-27 06:50:00.000000000 +0000
327 @@ -1209,7 +1209,7 @@
328            if (!(chan = modebind_refresh(ch, from, &user, NULL, NULL)))
329              return 0;
330            if (ms2[0] == '+') {
331 -            set_key(chan, op);
332 +            set_keyegg(chan, op);
333              if (channel_active(chan))
334                got_key(chan, nick, from, op);
335            } else {
336 @@ -1220,7 +1220,7 @@
337                         !chan_master(user) && !match_my_nick(nick))
338                  add_mode(chan, '+', 'k', chan->key_prot);
339              }
340 -            set_key(chan, NULL);
341 +            set_keyegg(chan, NULL);
342            }
343            break;
344          case 'o':
345 --- src/mod/module.h~   2012-03-31 15:38:27.000000000 +0300
346 +++ src/mod/module.h    2012-03-31 15:44:10.254563119 +0300
347 @@ -473,8 +473,13 @@
348  /* 284 - 287 */
349  #define quiet_reject (*(int *)(global[284]))
350  #define file_readable ((int (*) (char *))global[285])
351 +#ifdef EGG_SSL_EXT
352 +#define net_switch_to_ssl ((int (*)(int))global[286])
353 +#define ssl_use (*(int *)global[287]) /* kyotou */
354 +#else
355  /* IPv6 leftovers: 286 */
356  /* IPv6 leftovers: 287 */
357 +#endif
358  /* 288 - 291 */
359  /* IPv6 leftovers: 288 */
360  #define strip_mirc_codes ((void (*)(int, char *))global[289])
361 --- src/mod/server.mod/servmsg.c        2004-03-27 06:50:00.000000000 +0000
362 +++ src/mod/server.mod/servmsg.c        2004-03-27 06:50:00.000000000 +0000
363 @@ -1360,6 +1360,14 @@
364        fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
365    } else {
366      dcc[servidx].sock = serv;
367 +       #ifdef EGG_SSL_EXT
368 +       if (ssl_use) {
369 +               if (net_switch_to_ssl(serv)==0) {
370 +                       putlog(LOG_SERV, "*", "SSL %s %s (Error while switching to SSL)", IRC_FAILEDCONNECT, dcc[servidx].host);
371 +                       lostdcc(servidx);    
372 +               }
373 +       }    
374 +       #endif
375      /* Queue standard login */
376      dcc[servidx].timeval = now;
377      SERVER_SOCKET.timeout_val = &server_timeout;
378 --- src/modules.c       2004-03-27 06:50:00.000000000 +0000
379 +++ src/modules.c       2004-03-27 06:50:00.000000000 +0000
380 @@ -29,9 +29,17 @@
381  #include "main.h"
382  #include "modules.h"
383  #include "tandem.h"
384 +
385 +#ifndef EGG_SSL_EXT
386  #include "md5/md5.h"
387 +#else
388 +#include "openssl/md5.h"
389 +#endif
390 +
391  #include "users.h"
392  
393 +#include "net.h"
394 +
395  #ifndef STATIC
396  #  ifdef MOD_USE_SHL
397  #    include <dl.h>
398 @@ -94,6 +102,10 @@
399             password_timeout, force_expire, protect_readonly, reserved_port_min,
400             reserved_port_max, copy_to_tmp, quiet_reject;
401  
402 +#ifdef EGG_SSL_EXT
403 +extern int      ssl_use;
404 +#endif
405 +
406  extern party_t *party;
407  extern time_t now, online_since;
408  extern tand_t *tandbot;
409 @@ -128,6 +140,10 @@
410  }
411  #endif /* STATIC */
412  
413 +#ifdef EGG_SSL_EXT
414 +int net_switch_to_ssl(int);
415 +#endif
416 +
417  
418  /* The null functions */
419  void null_func()
420 @@ -561,8 +576,13 @@
421    /* 284 - 287 */
422    (Function) & quiet_reject,      /* int                                 */
423    (Function) file_readable,
424 +#ifdef EGG_SSL_EXT
425 +  (Function) net_switch_to_ssl,   /* 286 */
426 +  (Function) &ssl_use,           /* 287 kyotou  */
427 +#else
428    (Function) 0,                   /* IPv6 leftovers: 286                 */
429    (Function) 0,                   /* IPv6 leftovers: 287                 */
430 +#endif
431    /* 288 - 291 */
432    (Function) 0,                   /* IPv6 leftovers: 288                 */
433    (Function) strip_mirc_codes,
434 --- src/net.c   2004-03-27 06:50:00.000000000 +0000
435 +++ src/net.c   2004-03-27 06:50:00.000000000 +0000
436 @@ -52,6 +52,18 @@
437  #  endif
438  #endif
439  
440 +#ifdef EGG_SSL_EXT
441 +#  ifndef EGG_SSL_INCS
442 +#    include <openssl/ssl.h>
443 +#    include <openssl/err.h>
444 +#    include <openssl/rand.h>
445 +#    define EGG_SSL_INCS 1
446 +#  endif
447 +#endif
448 +
449 +#include "net.h"
450 +
451 +
452  extern struct dcc_t *dcc;
453  extern int backgrd, use_stderr, resolve_timeout, dcc_total;
454  extern unsigned long otraffic_irc_today, otraffic_bn_today, otraffic_dcc_today,
455 @@ -64,7 +76,11 @@
456  int firewallport = 1080;      /* Default port of socks 4/5 firewalls.         */
457  char botuser[21] = "eggdrop"; /* Username of the user running the bot.        */
458  int dcc_sanitycheck = 0;      /* Do some sanity checking on dcc connections.  */
459 -
460 +#ifdef EGG_SSL_EXT
461 +SSL_CTX *ssl_ctx=NULL;
462 +char   *tls_rand_file = NULL;
463 +int     ssl_use = 0;
464 +#endif
465  sock_list *socklist = NULL;   /* Enough to be safe.                           */
466  sigjmp_buf alarmret;          /* Env buffer for alarm() returns.              */
467  
468 @@ -87,6 +103,73 @@
469    return ret;
470  }
471  
472 +#ifdef EGG_SSL_EXT
473 +int seed_PRNG(void)
474 +{
475 +    char stackdata[1024];
476 +    static char rand_file[300];
477 +    FILE *fh;
478 +
479 +#if OPENSSL_VERSION_NUMBER >= 0x00905100
480 +    if (RAND_status())
481 +      return 0;     /* PRNG already good seeded */
482 +#endif
483 +    /* if the device '/dev/urandom' is present, OpenSSL uses it by default.
484 +     * check if it's present, else we have to make random data ourselfs.
485 +     */
486 +    if ((fh = fopen("/dev/urandom", "r"))) {
487 +      fclose(fh);
488 +      return 0;
489 +    }
490 +    if (RAND_file_name(rand_file, sizeof(rand_file)))
491 +      tls_rand_file = rand_file;
492 +    else
493 +      return 1;
494 +    if (!RAND_load_file(rand_file, 1024)) {
495 +      /* no .rnd file found, create new seed */
496 +      unsigned int c;
497 +      c = time(NULL);
498 +      RAND_seed(&c, sizeof(c));
499 +      c = getpid();
500 +      RAND_seed(&c, sizeof(c));
501 +      RAND_seed(stackdata, sizeof(stackdata));
502 +    }
503 +#if OPENSSL_VERSION_NUMBER >= 0x00905100
504 +    if (!RAND_status())
505 +      return 2;   /* PRNG still badly seeded */
506 +#endif
507 +    return 0;
508 +}
509 +
510 +void init_ssl()
511 +{
512 +  int i;
513 +  struct threaddata *td = threaddata();
514
515 +  for (i = 0; i < td->MAXSOCKS; i++) {
516 +    td->socklist[i].ssl = NULL;
517 +  }
518 +
519 +  SSL_load_error_strings();
520 +  OpenSSL_add_ssl_algorithms();
521 +  ssl_ctx=SSL_CTX_new(SSLv23_client_method());
522 +  if (!ssl_ctx)
523 +  fatal("SSL_CTX_new() failed",0);
524 +  if (seed_PRNG())
525 +    fatal("Wasn't able to properly seed the PRNG!",0);
526 +}
527 +
528 +int clean_ssl() {
529 +   if (ssl_ctx) {
530 +      SSL_CTX_free(ssl_ctx);
531 +      ssl_ctx = NULL;
532 +  }
533 +  if (tls_rand_file)
534 +      RAND_write_file(tls_rand_file);
535 + return 0;
536 +}
537 +#endif
538 +
539  int expmem_net()
540  {
541    int i, tot = 0;
542 @@ -249,6 +332,7 @@
543        td->socklist[i].handler.sock.outbuflen = 0;
544        td->socklist[i].flags = options;
545        td->socklist[i].sock = sock;
546 +      td->socklist[i].ssl = NULL;
547        return i;
548      }
549    }
550 @@ -345,6 +429,13 @@
551  
552    for (i = 0; i < td->MAXSOCKS; i++) {
553      if ((td->socklist[i].sock == sock) && !(td->socklist[i].flags & SOCK_UNUSED)) {
554 +#ifdef EGG_SSL_EXT
555 +      if (td->socklist[i].ssl) {
556 +        SSL_shutdown(td->socklist[i].ssl);
557 +        SSL_free(td->socklist[i].ssl);
558 +        td->socklist[i].ssl = NULL;
559 +      }
560 +#endif
561        if (!(td->socklist[i].flags & SOCK_TCL)) { /* nothing to free for tclsocks */
562          close(td->socklist[i].sock);
563          if (td->socklist[i].handler.sock.inbuf != NULL) {
564 @@ -508,6 +599,65 @@
565    return sock;
566  }
567  
568 +#ifdef EGG_SSL_EXT
569 +int net_switch_to_ssl(int sock) {
570 +int err;
571 +int i=0;
572 +struct threaddata *td = threaddata();
573 +
574 +    debug0("net_switch_to_ssl()");
575 +    while (i < td->MAXSOCKS) {
576 +     if (td->socklist[i].sock==sock) {
577 +      break;
578 +     }
579 +     i++;
580 +    }
581 +    if (i == td->MAXSOCKS) {
582 +        debug0("Error while swithing to SSL - sock not found in list");
583 +       return 0;
584 +    }
585 +
586 +    if (td->socklist[i].ssl) {
587 +        debug0("Error while swithing to SSL - already in ssl");
588 +       return 0;
589 +    }
590 +    td->socklist[i].ssl = SSL_new(ssl_ctx);
591 +    if (!td->socklist[i].ssl) {
592 +        debug0("Error while swithing to SSL - SSL_new() error");
593 +       return 0;
594 +    }
595 +
596 +     SSL_set_fd(td->socklist[i].ssl, td->socklist[i].sock);
597 +     err = SSL_connect(td->socklist[i].ssl);
598 +   
599 +     while (err <= 0) {
600 +        int errs;
601 +        errs=SSL_get_error(td->socklist[i].ssl,err);
602 +        if ((errs!=SSL_ERROR_WANT_READ)&&(errs!=SSL_ERROR_WANT_WRITE)&&
603 +               (errs!=SSL_ERROR_WANT_X509_LOOKUP)) {
604 +               putlog(LOG_DEBUG,"*", "SSL_connect() = %d, %s", err,
605 +                       (char *)ERR_error_string(ERR_get_error(), NULL));
606 +               SSL_shutdown(td->socklist[i].ssl);
607 +               SSL_free(td->socklist[i].ssl);
608 +               td->socklist[i].ssl = NULL;
609 +               return 0;           
610 +        }
611 +        usleep(1000);
612 +        err = SSL_connect(td->socklist[i].ssl);
613 +     }
614 +
615 +     if (err==1) {
616 +      debug0("SSL_connect() success"); 
617 +      return 1;
618 +     }
619 +     debug0("Error while SSL_connect()"); 
620 +     SSL_shutdown(td->socklist[i].ssl);
621 +     SSL_free(td->socklist[i].ssl); 
622 +     td->socklist[i].ssl = NULL;
623 +     return 0;
624 +}
625 +#endif
626 +
627  /* Ordinary non-binary connection attempt */
628  int open_telnet(char *server, int port)
629  {
630 @@ -715,6 +865,9 @@
631      for (i = 0; i < slistmax; i++) {
632        if (!tclonly && ((!(slist[i].flags & (SOCK_UNUSED | SOCK_TCL))) &&
633            ((FD_ISSET(slist[i].sock, &fdr)) ||
634 +#ifdef EGG_SSL_EXT
635 +          ((slist[i].ssl)&&(SSL_pending(slist[i].ssl))) ||
636 +#endif
637            ((slist[i].sock == STDOUT) && (!backgrd) &&
638            (FD_ISSET(STDIN, &fdr)))))) {
639          if (slist[i].flags & (SOCK_LISTEN | SOCK_CONNECT)) {
640 @@ -739,7 +892,33 @@
641          if ((slist[i].sock == STDOUT) && !backgrd)
642            x = read(STDIN, s, grab);
643          else
644 -          x = read(slist[i].sock, s, grab);
645 +#ifdef EGG_SSL_EXT
646 +        {
647 +          if (slist[i].ssl) {
648 +            x = SSL_read(slist[i].ssl, s, grab);
649 +
650 +            if (x < 0) {
651 +              int err = SSL_get_error(slist[i].ssl, x);
652 +              x = -1;
653 +
654 +              switch (err) {
655 +                case SSL_ERROR_WANT_READ:
656 +                  errno = EAGAIN;
657 +                  break;
658 +                case SSL_ERROR_WANT_WRITE:
659 +                  errno = EAGAIN;
660 +                  break;
661 +                case SSL_ERROR_WANT_X509_LOOKUP:
662 +                  errno = EAGAIN;
663 +                  break;
664 +              }
665 +            }
666 +          } else
667 +            x = read(slist[i].sock, s, grab);
668 +        }
669 +#else
670 +        x = read(slist[i].sock, s, grab);
671 +#endif
672          if (x <= 0) {           /* eof */
673            if (errno != EAGAIN) { /* EAGAIN happens when the operation would
674                                    * block on a non-blocking socket, if the
675 @@ -1046,6 +1225,26 @@
676          socklist[i].handler.sock.outbuflen += len;
677          return;
678        }
679 +#ifdef EGG_SSL_EXT
680 +      if (socklist[i].ssl) {
681 +       x=SSL_write(socklist[i].ssl,s,len);
682 +          if (x < 0) {
683 +           int err = SSL_get_error(socklist[i].ssl, x);
684 +           x = -1;
685 +           switch (err) {
686 +               case SSL_ERROR_WANT_READ:
687 +                       errno = EAGAIN;
688 +                   break;
689 +               case SSL_ERROR_WANT_WRITE:
690 +                   errno = EAGAIN;
691 +                   break;
692 +               case SSL_ERROR_WANT_X509_LOOKUP:
693 +                   errno = EAGAIN;
694 +                   break;
695 +               }
696 +          }
697 +      } else
698 +#endif      
699        /* Try. */
700        x = write(z, s, len);
701        if (x == -1)
702 @@ -1113,6 +1312,29 @@
703          (socklist[i].handler.sock.outbuf != NULL) && (FD_ISSET(socklist[i].sock, &wfds))) {
704        /* Trick tputs into doing the work */
705        errno = 0;
706 +#ifdef EGG_SSL_EXT
707 +      if (socklist[i].ssl) {
708 +         x = write(socklist[i].sock, socklist[i].handler.sock.outbuf,
709 +              socklist[i].handler.sock.outbuflen);
710 +
711 +         if (x < 0) {
712 +           int err = SSL_get_error(socklist[i].ssl, x);
713 +           x = -1;
714 +
715 +           switch (err) {
716 +             case SSL_ERROR_WANT_READ:
717 +               errno = EAGAIN;
718 +               break;
719 +             case SSL_ERROR_WANT_WRITE:
720 +               errno = EAGAIN;
721 +               break;
722 +             case SSL_ERROR_WANT_X509_LOOKUP:
723 +               errno = EAGAIN;
724 +               break;
725 +             }
726 +          }
727 +       } else
728 +#endif
729        x = write(socklist[i].sock, socklist[i].handler.sock.outbuf, socklist[i].handler.sock.outbuflen);
730        if ((x < 0) && (errno != EAGAIN)
731  #ifdef EBADSLT
732 --- src/net.h   1970-01-01 01:00:00.000000000 +0100
733 +++ src/net.h   2004-03-27 06:50:00.000000000 +0000
734 @@ -0,0 +1,26 @@
735 +#ifndef _EGG_NET_H
736 +#define _EGG_NET_H
737 +#ifdef EGG_SSL_EXT
738 +# ifndef EGG_SSL_INCS
739 +#  include <openssl/ssl.h>
740 +#  include <openssl/err.h>
741 +#  include <openssl/rand.h>
742 +#  define EGG_SSL_INCS 1
743 +# endif
744 +#endif
745 +
746 +/* This is used by the net module to keep track of sockets and what's
747 + * queued on them
748 + */
749 +typedef struct sock_list {
750 +  int sock;
751 +#ifdef EGG_SSL_EXT
752 +  SSL *ssl;
753 +#endif
754 +  short flags;
755 +  union {
756 +    struct sock_handler sock;
757 +    struct tclsock_handler tclsock;
758 +  } handler;
759 +} sock_list;
760 +#endif                         /* _EGG_NET_H */
761 --- src/patch.h 2004-03-27 06:50:00.000000000 +0000
762 +++ src/patch.h 2004-03-27 06:50:00.000000000 +0000
763 @@ -36,7 +36,9 @@
764   *
765   *
766   */
767 -/* PATCH GOES HERE */
768 +#ifdef EGG_SSL_EXT
769 +  patch("SSL");
770 +#endif
771  /*
772   *
773   *
774 --- src/proto.h 2004-03-27 06:50:00.000000000 +0000
775 +++ src/proto.h 2004-03-27 06:50:00.000000000 +0000
776 @@ -33,6 +33,7 @@
777  
778  #include "lush.h"
779  #include "misc_file.h"
780 +#include "net.h"
781  
782  #define dprintf dprintf_eggdrop
783  
784 --- src/tcl.c   2004-03-27 06:50:00.000000000 +0000
785 +++ src/tcl.c   2004-03-27 06:50:00.000000000 +0000
786 @@ -44,6 +44,9 @@
787  
788  
789  extern time_t online_since;
790 +#ifdef EGG_SSL_EXT
791 +extern int      ssl_use;
792 +#endif
793  
794  extern char origbotname[], botuser[], motdfile[], admin[], userfile[],
795              firewall[], helpdir[], notify_new[], hostname[], myip[], moddir[],
796 @@ -553,6 +556,9 @@
797    {"enable-simul",          &enable_simul,         0}, /* compat */
798    {"debug-output",          &debug_output,         0}, /* compat */
799    {"use-console-r",         &use_console_r,        0}, /* compat */
800 +#ifdef EGG_SSL_EXT
801 +  {"use-ssl",                  &ssl_use,               0},
802 +#endif
803    {NULL,                    NULL,                  0}
804  };
805  
806 --- src/tclhash.h       2004-03-27 06:50:00.000000000 +0000
807 +++ src/tclhash.h       2004-03-27 06:50:00.000000000 +0000
808 @@ -25,6 +25,7 @@
809  #ifndef _EGG_TCLHASH_H
810  #define _EGG_TCLHASH_H
811  
812 +#include "net.h"
813  
814  #define TC_DELETED   0x0001     /* This command/trigger was deleted. */
815  
816 --- src/tclmisc.c       2004-03-27 06:50:00.000000000 +0000
817 +++ src/tclmisc.c       2004-03-27 06:50:00.000000000 +0000
818 @@ -26,7 +26,12 @@
819  #include "main.h"
820  #include "modules.h"
821  #include "tandem.h"
822 +
823 +#ifndef EGG_SSL_EXT
824  #include "md5/md5.h"
825 +#else
826 +#include "openssl/md5.h"
827 +#endif
828  
829  #ifdef TIME_WITH_SYS_TIME
830  #  include <sys/time.h>
This page took 0.097592 seconds and 3 git commands to generate.