]> git.pld-linux.org Git - packages/eggdrop.git/blob - eggdrop-ssl.patch
- updated as:
[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  2004-03-27 06:50:00.000000000 +0000
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)
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    2004-03-27 06:50:00.000000000 +0000
346 +++ src/mod/module.h    2004-03-27 06:50:00.000000000 +0000
347 @@ -472,6 +472,16 @@
348  /* IPv6 leftovers: 286 */
349  /* IPv6 leftovers: 287 */
350  /* 288 - 291 */
351 +#ifdef EGG_SSL_EXT
352 +#define net_switch_to_ssl ((int (*)(int))global[289])
353 +#define ssl_use (*(int *)global[290])
354 +#define strip_mirc_codes ((void (*)(int, char *))global[291])
355 +#define check_ansi ((int (*) (char *))global[292])
356 +#define oatoi ((int (*) (const char *))global[293])
357 +/* 292 - 295 */
358 +#define str_isdigit ((int (*) (const char *))global[294])
359 +#define remove_crlf ((void (*)(char **))global[295])
360 +#else
361  /* IPv6 leftovers: 288 */
362  #define strip_mirc_codes ((void (*)(int, char *))global[289])
363  #define check_ansi ((int (*) (char *))global[290])
364 @@ -479,6 +489,7 @@
365  /* 292 - 295 */
366  #define str_isdigit ((int (*) (const char *))global[292])
367  #define remove_crlf ((void (*) (char **))global[293])
368 +#endif
369  #define addr_match ((int (*)(const char *, const char *, int, int))global[294])
370  #define mask_match ((int (*)(const char *, const char *))global[295])
371  /* 296 - 299 */
372 --- src/mod/server.mod/servmsg.c        2004-03-27 06:50:00.000000000 +0000
373 +++ src/mod/server.mod/servmsg.c        2004-03-27 06:50:00.000000000 +0000
374 @@ -1360,6 +1360,14 @@
375        fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
376    } else {
377      dcc[servidx].sock = serv;
378 +       #ifdef EGG_SSL_EXT
379 +       if (ssl_use) {
380 +               if (net_switch_to_ssl(serv)==0) {
381 +                       putlog(LOG_SERV, "*", "SSL %s %s (Error while switching to SSL)", IRC_FAILEDCONNECT, dcc[servidx].host);
382 +                       lostdcc(servidx);    
383 +               }
384 +       }    
385 +       #endif
386      /* Queue standard login */
387      dcc[servidx].timeval = now;
388      SERVER_SOCKET.timeout_val = &server_timeout;
389 --- src/modules.c       2004-03-27 06:50:00.000000000 +0000
390 +++ src/modules.c       2004-03-27 06:50:00.000000000 +0000
391 @@ -29,9 +29,17 @@
392  #include "main.h"
393  #include "modules.h"
394  #include "tandem.h"
395 +
396 +#ifndef EGG_SSL_EXT
397  #include "md5/md5.h"
398 +#else
399 +#include "openssl/md5.h"
400 +#endif
401 +
402  #include "users.h"
403  
404 +#include "net.h"
405 +
406  #ifndef STATIC
407  #  ifdef MOD_USE_SHL
408  #    include <dl.h>
409 @@ -94,6 +102,10 @@
410             password_timeout, force_expire, protect_readonly, reserved_port_min,
411             reserved_port_max, copy_to_tmp, quiet_reject;
412  
413 +#ifdef EGG_SSL_EXT
414 +extern int      ssl_use;
415 +#endif
416 +
417  extern party_t *party;
418  extern time_t now, online_since;
419  extern tand_t *tandbot;
420 @@ -128,6 +140,10 @@
421  }
422  #endif /* STATIC */
423  
424 +#ifdef EGG_SSL_EXT
425 +int net_switch_to_ssl(int);
426 +#endif
427 +
428  
429  /* The null functions */
430  void null_func()
431 @@ -564,7 +580,13 @@
432    (Function) 0,                   /* IPv6 leftovers: 286                 */
433    (Function) 0,                   /* IPv6 leftovers: 287                 */
434    /* 288 - 291 */
435 +#ifdef EGG_SSL_EXT
436    (Function) 0,                   /* IPv6 leftovers: 288                 */
437 +  (Function) net_switch_to_ssl,
438 +  (Function) & ssl_use,
439 +#else
440 +  (Function) 0,                   /* IPv6 leftovers: 288                 */
441 +#endif
442    (Function) strip_mirc_codes,
443    (Function) check_ansi,
444    (Function) oatoi,
445 --- src/net.c   2004-03-27 06:50:00.000000000 +0000
446 +++ src/net.c   2004-03-27 06:50:00.000000000 +0000
447 @@ -52,6 +52,18 @@
448  #  endif
449  #endif
450  
451 +#ifdef EGG_SSL_EXT
452 +#  ifndef EGG_SSL_INCS
453 +#    include <openssl/ssl.h>
454 +#    include <openssl/err.h>
455 +#    include <openssl/rand.h>
456 +#    define EGG_SSL_INCS 1
457 +#  endif
458 +#endif
459 +
460 +#include "net.h"
461 +
462 +
463  extern struct dcc_t *dcc;
464  extern int backgrd, use_stderr, resolve_timeout, dcc_total;
465  extern unsigned long otraffic_irc_today, otraffic_bn_today, otraffic_dcc_today,
466 @@ -64,7 +76,11 @@
467  int firewallport = 1080;      /* Default port of socks 4/5 firewalls.         */
468  char botuser[21] = "eggdrop"; /* Username of the user running the bot.        */
469  int dcc_sanitycheck = 0;      /* Do some sanity checking on dcc connections.  */
470 -
471 +#ifdef EGG_SSL_EXT
472 +SSL_CTX *ssl_ctx=NULL;
473 +char   *tls_rand_file = NULL;
474 +int     ssl_use = 0;
475 +#endif
476  sock_list *socklist = NULL;   /* Enough to be safe.                           */
477  sigjmp_buf alarmret;          /* Env buffer for alarm() returns.              */
478  
479 @@ -87,6 +103,73 @@
480    return ret;
481  }
482  
483 +#ifdef EGG_SSL_EXT
484 +int seed_PRNG(void)
485 +{
486 +    char stackdata[1024];
487 +    static char rand_file[300];
488 +    FILE *fh;
489 +
490 +#if OPENSSL_VERSION_NUMBER >= 0x00905100
491 +    if (RAND_status())
492 +      return 0;     /* PRNG already good seeded */
493 +#endif
494 +    /* if the device '/dev/urandom' is present, OpenSSL uses it by default.
495 +     * check if it's present, else we have to make random data ourselfs.
496 +     */
497 +    if ((fh = fopen("/dev/urandom", "r"))) {
498 +      fclose(fh);
499 +      return 0;
500 +    }
501 +    if (RAND_file_name(rand_file, sizeof(rand_file)))
502 +      tls_rand_file = rand_file;
503 +    else
504 +      return 1;
505 +    if (!RAND_load_file(rand_file, 1024)) {
506 +      /* no .rnd file found, create new seed */
507 +      unsigned int c;
508 +      c = time(NULL);
509 +      RAND_seed(&c, sizeof(c));
510 +      c = getpid();
511 +      RAND_seed(&c, sizeof(c));
512 +      RAND_seed(stackdata, sizeof(stackdata));
513 +    }
514 +#if OPENSSL_VERSION_NUMBER >= 0x00905100
515 +    if (!RAND_status())
516 +      return 2;   /* PRNG still badly seeded */
517 +#endif
518 +    return 0;
519 +}
520 +
521 +void init_ssl()
522 +{
523 +  int i;
524 +  struct threaddata *td = threaddata();
525
526 +  for (i = 0; i < td->MAXSOCKS; i++) {
527 +    td->socklist[i].ssl = NULL;
528 +  }
529 +
530 +  SSL_load_error_strings();
531 +  OpenSSL_add_ssl_algorithms();
532 +  ssl_ctx=SSL_CTX_new(SSLv23_client_method());
533 +  if (!ssl_ctx)
534 +  fatal("SSL_CTX_new() failed",0);
535 +  if (seed_PRNG())
536 +    fatal("Wasn't able to properly seed the PRNG!",0);
537 +}
538 +
539 +int clean_ssl() {
540 +   if (ssl_ctx) {
541 +      SSL_CTX_free(ssl_ctx);
542 +      ssl_ctx = NULL;
543 +  }
544 +  if (tls_rand_file)
545 +      RAND_write_file(tls_rand_file);
546 + return 0;
547 +}
548 +#endif
549 +
550  int expmem_net()
551  {
552    int i, tot = 0;
553 @@ -249,6 +332,7 @@
554        td->socklist[i].handler.sock.outbuflen = 0;
555        td->socklist[i].flags = options;
556        td->socklist[i].sock = sock;
557 +      td->socklist[i].ssl = NULL;
558        return i;
559      }
560    }
561 @@ -345,6 +429,13 @@
562  
563    for (i = 0; i < td->MAXSOCKS; i++) {
564      if ((td->socklist[i].sock == sock) && !(td->socklist[i].flags & SOCK_UNUSED)) {
565 +#ifdef EGG_SSL_EXT
566 +      if (td->socklist[i].ssl) {
567 +        SSL_shutdown(td->socklist[i].ssl);
568 +        SSL_free(td->socklist[i].ssl);
569 +        td->socklist[i].ssl = NULL;
570 +      }
571 +#endif
572        if (!(td->socklist[i].flags & SOCK_TCL)) { /* nothing to free for tclsocks */
573          close(td->socklist[i].sock);
574          if (td->socklist[i].handler.sock.inbuf != NULL) {
575 @@ -508,6 +599,65 @@
576    return sock;
577  }
578  
579 +#ifdef EGG_SSL_EXT
580 +int net_switch_to_ssl(int sock) {
581 +int err;
582 +int i=0;
583 +struct threaddata *td = threaddata();
584 +
585 +    debug0("net_switch_to_ssl()");
586 +    while (i < td->MAXSOCKS) {
587 +     if (td->socklist[i].sock==sock) {
588 +      break;
589 +     }
590 +     i++;
591 +    }
592 +    if (i == td->MAXSOCKS) {
593 +        debug0("Error while swithing to SSL - sock not found in list");
594 +       return 0;
595 +    }
596 +
597 +    if (td->socklist[i].ssl) {
598 +        debug0("Error while swithing to SSL - already in ssl");
599 +       return 0;
600 +    }
601 +    td->socklist[i].ssl = SSL_new(ssl_ctx);
602 +    if (!td->socklist[i].ssl) {
603 +        debug0("Error while swithing to SSL - SSL_new() error");
604 +       return 0;
605 +    }
606 +
607 +     SSL_set_fd(td->socklist[i].ssl, td->socklist[i].sock);
608 +     err = SSL_connect(td->socklist[i].ssl);
609 +   
610 +     while (err <= 0) {
611 +        int errs;
612 +        errs=SSL_get_error(td->socklist[i].ssl,err);
613 +        if ((errs!=SSL_ERROR_WANT_READ)&&(errs!=SSL_ERROR_WANT_WRITE)&&
614 +               (errs!=SSL_ERROR_WANT_X509_LOOKUP)) {
615 +               putlog(LOG_DEBUG,"*", "SSL_connect() = %d, %s", err,
616 +                       (char *)ERR_error_string(ERR_get_error(), NULL));
617 +               SSL_shutdown(td->socklist[i].ssl);
618 +               SSL_free(td->socklist[i].ssl);
619 +               td->socklist[i].ssl = NULL;
620 +               return 0;           
621 +        }
622 +        usleep(1000);
623 +        err = SSL_connect(td->socklist[i].ssl);
624 +     }
625 +
626 +     if (err==1) {
627 +      debug0("SSL_connect() success"); 
628 +      return 1;
629 +     }
630 +     debug0("Error while SSL_connect()"); 
631 +     SSL_shutdown(td->socklist[i].ssl);
632 +     SSL_free(td->socklist[i].ssl); 
633 +     td->socklist[i].ssl = NULL;
634 +     return 0;
635 +}
636 +#endif
637 +
638  /* Ordinary non-binary connection attempt */
639  int open_telnet(char *server, int port)
640  {
641 @@ -715,6 +865,9 @@
642      for (i = 0; i < slistmax; i++) {
643        if (!tclonly && ((!(slist[i].flags & (SOCK_UNUSED | SOCK_TCL))) &&
644            ((FD_ISSET(slist[i].sock, &fdr)) ||
645 +#ifdef EGG_SSL_EXT
646 +          ((slist[i].ssl)&&(SSL_pending(slist[i].ssl))) ||
647 +#endif
648            ((slist[i].sock == STDOUT) && (!backgrd) &&
649            (FD_ISSET(STDIN, &fdr)))))) {
650          if (slist[i].flags & (SOCK_LISTEN | SOCK_CONNECT)) {
651 @@ -739,7 +892,33 @@
652          if ((slist[i].sock == STDOUT) && !backgrd)
653            x = read(STDIN, s, grab);
654          else
655 -          x = read(slist[i].sock, s, grab);
656 +#ifdef EGG_SSL_EXT
657 +        {
658 +          if (slist[i].ssl) {
659 +            x = SSL_read(slist[i].ssl, s, grab);
660 +
661 +            if (x < 0) {
662 +              int err = SSL_get_error(slist[i].ssl, x);
663 +              x = -1;
664 +
665 +              switch (err) {
666 +                case SSL_ERROR_WANT_READ:
667 +                  errno = EAGAIN;
668 +                  break;
669 +                case SSL_ERROR_WANT_WRITE:
670 +                  errno = EAGAIN;
671 +                  break;
672 +                case SSL_ERROR_WANT_X509_LOOKUP:
673 +                  errno = EAGAIN;
674 +                  break;
675 +              }
676 +            }
677 +          } else
678 +            x = read(slist[i].sock, s, grab);
679 +        }
680 +#else
681 +        x = read(slist[i].sock, s, grab);
682 +#endif
683          if (x <= 0) {           /* eof */
684            if (errno != EAGAIN) { /* EAGAIN happens when the operation would
685                                    * block on a non-blocking socket, if the
686 @@ -1046,6 +1225,26 @@
687          socklist[i].handler.sock.outbuflen += len;
688          return;
689        }
690 +#ifdef EGG_SSL_EXT
691 +      if (socklist[i].ssl) {
692 +       x=SSL_write(socklist[i].ssl,s,len);
693 +          if (x < 0) {
694 +           int err = SSL_get_error(socklist[i].ssl, x);
695 +           x = -1;
696 +           switch (err) {
697 +               case SSL_ERROR_WANT_READ:
698 +                       errno = EAGAIN;
699 +                   break;
700 +               case SSL_ERROR_WANT_WRITE:
701 +                   errno = EAGAIN;
702 +                   break;
703 +               case SSL_ERROR_WANT_X509_LOOKUP:
704 +                   errno = EAGAIN;
705 +                   break;
706 +               }
707 +          }
708 +      } else
709 +#endif      
710        /* Try. */
711        x = write(z, s, len);
712        if (x == -1)
713 @@ -1113,6 +1312,29 @@
714          (socklist[i].handler.sock.outbuf != NULL) && (FD_ISSET(socklist[i].sock, &wfds))) {
715        /* Trick tputs into doing the work */
716        errno = 0;
717 +#ifdef EGG_SSL_EXT
718 +      if (socklist[i].ssl) {
719 +         x = write(socklist[i].sock, socklist[i].handler.sock.outbuf,
720 +              socklist[i].handler.sock.outbuflen);
721 +
722 +         if (x < 0) {
723 +           int err = SSL_get_error(socklist[i].ssl, x);
724 +           x = -1;
725 +
726 +           switch (err) {
727 +             case SSL_ERROR_WANT_READ:
728 +               errno = EAGAIN;
729 +               break;
730 +             case SSL_ERROR_WANT_WRITE:
731 +               errno = EAGAIN;
732 +               break;
733 +             case SSL_ERROR_WANT_X509_LOOKUP:
734 +               errno = EAGAIN;
735 +               break;
736 +             }
737 +          }
738 +       } else
739 +#endif
740        x = write(socklist[i].sock, socklist[i].handler.sock.outbuf, socklist[i].handler.sock.outbuflen);
741        if ((x < 0) && (errno != EAGAIN)
742  #ifdef EBADSLT
743 --- src/net.h   1970-01-01 01:00:00.000000000 +0100
744 +++ src/net.h   2004-03-27 06:50:00.000000000 +0000
745 @@ -0,0 +1,26 @@
746 +#ifndef _EGG_NET_H
747 +#define _EGG_NET_H
748 +#ifdef EGG_SSL_EXT
749 +# ifndef EGG_SSL_INCS
750 +#  include <openssl/ssl.h>
751 +#  include <openssl/err.h>
752 +#  include <openssl/rand.h>
753 +#  define EGG_SSL_INCS 1
754 +# endif
755 +#endif
756 +
757 +/* This is used by the net module to keep track of sockets and what's
758 + * queued on them
759 + */
760 +typedef struct sock_list {
761 +  int sock;
762 +#ifdef EGG_SSL_EXT
763 +  SSL *ssl;
764 +#endif
765 +  short flags;
766 +  union {
767 +    struct sock_handler sock;
768 +    struct tclsock_handler tclsock;
769 +  } handler;
770 +} sock_list;
771 +#endif                         /* _EGG_NET_H */
772 --- src/patch.h 2004-03-27 06:50:00.000000000 +0000
773 +++ src/patch.h 2004-03-27 06:50:00.000000000 +0000
774 @@ -36,7 +36,9 @@
775   *
776   *
777   */
778 -/* PATCH GOES HERE */
779 +#ifdef EGG_SSL_EXT
780 +  patch("SSL");
781 +#endif
782  /*
783   *
784   *
785 --- src/proto.h 2004-03-27 06:50:00.000000000 +0000
786 +++ src/proto.h 2004-03-27 06:50:00.000000000 +0000
787 @@ -33,6 +33,7 @@
788  
789  #include "lush.h"
790  #include "misc_file.h"
791 +#include "net.h"
792  
793  #define dprintf dprintf_eggdrop
794  
795 --- src/tcl.c   2004-03-27 06:50:00.000000000 +0000
796 +++ src/tcl.c   2004-03-27 06:50:00.000000000 +0000
797 @@ -44,6 +44,9 @@
798  
799  
800  extern time_t online_since;
801 +#ifdef EGG_SSL_EXT
802 +extern int      ssl_use;
803 +#endif
804  
805  extern char origbotname[], botuser[], motdfile[], admin[], userfile[],
806              firewall[], helpdir[], notify_new[], hostname[], myip[], moddir[],
807 @@ -553,6 +556,9 @@
808    {"enable-simul",          &enable_simul,         0}, /* compat */
809    {"debug-output",          &debug_output,         0}, /* compat */
810    {"use-console-r",         &use_console_r,        0}, /* compat */
811 +#ifdef EGG_SSL_EXT
812 +  {"use-ssl",                  &ssl_use,               0},
813 +#endif
814    {NULL,                    NULL,                  0}
815  };
816  
817 --- src/tclhash.h       2004-03-27 06:50:00.000000000 +0000
818 +++ src/tclhash.h       2004-03-27 06:50:00.000000000 +0000
819 @@ -25,6 +25,7 @@
820  #ifndef _EGG_TCLHASH_H
821  #define _EGG_TCLHASH_H
822  
823 +#include "net.h"
824  
825  #define TC_DELETED   0x0001     /* This command/trigger was deleted. */
826  
827 --- src/tclmisc.c       2004-03-27 06:50:00.000000000 +0000
828 +++ src/tclmisc.c       2004-03-27 06:50:00.000000000 +0000
829 @@ -26,7 +26,12 @@
830  #include "main.h"
831  #include "modules.h"
832  #include "tandem.h"
833 +
834 +#ifndef EGG_SSL_EXT
835  #include "md5/md5.h"
836 +#else
837 +#include "openssl/md5.h"
838 +#endif
839  
840  #ifdef TIME_WITH_SYS_TIME
841  #  include <sys/time.h>
This page took 0.15063 seconds and 4 git commands to generate.