2 * sslproc.c: An interface to ssld
3 * Copyright (C) 2007 Aaron Sethman <androsyn@ratbox.org>
4 * Copyright (C) 2007 ircd-ratbox development team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24 #include <ratbox_lib.h>
39 #define ZIPSTATS_TIME 60
41 static void collect_zipstats(void *unused
);
42 static void ssl_read_ctl(rb_fde_t
* F
, void *data
);
43 static int ssld_count
;
45 static char tmpbuf
[READBUF_SIZE
];
46 static char nul
= '\0';
50 typedef struct _ssl_ctl_buf
55 rb_fde_t
*F
[MAXPASSFD
];
73 static void send_new_ssl_certs_one(ssl_ctl_t
* ctl
, const char *ssl_cert
,
74 const char *ssl_private_key
, const char *ssl_dh_params
,
75 const char *ssl_cipher_list
);
76 static void send_init_prng(ssl_ctl_t
* ctl
, prng_seed_t seedtype
, const char *path
);
77 static void send_certfp_method(ssl_ctl_t
*ctl
, int method
);
80 static rb_dlink_list ssl_daemons
;
82 static inline uint32_t
83 buf_to_uint32(char *buf
)
86 memcpy(&x
, buf
, sizeof(x
));
91 uint32_to_buf(char *buf
, uint32_t x
)
93 memcpy(buf
, &x
, sizeof(x
));
98 allocate_ssl_daemon(rb_fde_t
* F
, rb_fde_t
* P
, int pid
)
102 if(F
== NULL
|| pid
< 0)
104 ctl
= rb_malloc(sizeof(ssl_ctl_t
));
109 rb_dlinkAdd(ctl
, &ctl
->node
, &ssl_daemons
);
114 free_ssl_daemon(ssl_ctl_t
* ctl
)
117 ssl_ctl_buf_t
*ctl_buf
;
122 RB_DLINK_FOREACH(ptr
, ctl
->readq
.head
)
125 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
126 rb_close(ctl_buf
->F
[x
]);
128 rb_free(ctl_buf
->buf
);
132 RB_DLINK_FOREACH(ptr
, ctl
->writeq
.head
)
135 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
136 rb_close(ctl_buf
->F
[x
]);
138 rb_free(ctl_buf
->buf
);
143 rb_dlinkDelete(&ctl
->node
, &ssl_daemons
);
147 static char *ssld_path
;
149 static int ssld_spin_count
= 0;
150 static time_t last_spin
;
151 static int ssld_wait
= 0;
157 rb_dlink_node
*ptr
, *next
;
160 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
171 rb_kill(ctl
->pid
, SIGKILL
);
172 free_ssl_daemon(ctl
);
176 start_ssldaemon(ServerInfo
.ssld_count
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
182 rb_dlink_node
*ptr
, *next
;
184 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
192 rb_kill(ctl
->pid
, SIGKILL
);
194 free_ssl_daemon(ctl
);
199 ssl_dead(ssl_ctl_t
* ctl
)
205 rb_kill(ctl
->pid
, SIGKILL
); /* make sure the process is really gone */
210 ilog(L_MAIN
, "ssld helper died - attempting to restart");
211 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "ssld helper died - attempting to restart");
212 start_ssldaemon(1, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
217 ssl_do_pipe(rb_fde_t
* F
, void *data
)
220 ssl_ctl_t
*ctl
= data
;
221 retlen
= rb_write(F
, "0", 1);
222 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
227 rb_setselect(F
, RB_SELECT_READ
, ssl_do_pipe
, data
);
231 restart_ssld_event(void *unused
)
236 if(ServerInfo
.ssld_count
> get_ssld_count())
238 int start
= ServerInfo
.ssld_count
- get_ssld_count();
239 ilog(L_MAIN
, "Attempting to restart ssld processes");
240 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Attempt to restart ssld processes");
241 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
246 start_ssldaemon(int count
, const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
251 const char *suffix
= ".exe";
253 const char *suffix
= "";
256 char fullpath
[PATH_MAX
+ 1];
267 if(ssld_spin_count
> 20 && (rb_current_time() - last_spin
< 5))
269 ilog(L_MAIN
, "ssld helper is spinning - will attempt to restart in 1 minute");
270 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
271 "ssld helper is spinning - will attempt to restart in 1 minute");
272 rb_event_add("restart_ssld_event", restart_ssld_event
, NULL
, 60);
278 last_spin
= rb_current_time();
280 if(ssld_path
== NULL
)
282 snprintf(fullpath
, sizeof(fullpath
), "%s/ssld%s", PKGLIBEXECDIR
, suffix
);
284 if(access(fullpath
, X_OK
) == -1)
286 snprintf(fullpath
, sizeof(fullpath
), "%s/bin/ssld%s",
287 ConfigFileEntry
.dpath
, suffix
);
288 if(access(fullpath
, X_OK
) == -1)
291 "Unable to execute ssld%s in %s or %s/bin",
292 suffix
, PKGLIBEXECDIR
, ConfigFileEntry
.dpath
);
296 ssld_path
= rb_strdup(fullpath
);
298 rb_strlcpy(buf
, "-ircd ssld daemon", sizeof(buf
));
302 for(i
= 0; i
< count
; i
++)
305 if(rb_socketpair(AF_UNIX
, SOCK_DGRAM
, 0, &F1
, &F2
, "SSL/TLS handle passing socket") == -1)
307 ilog(L_MAIN
, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno
));
311 rb_set_buffers(F1
, READBUF_SIZE
);
312 rb_set_buffers(F2
, READBUF_SIZE
);
313 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(F2
));
314 rb_setenv("CTL_FD", fdarg
, 1);
315 if(rb_pipe(&P1
, &P2
, "SSL/TLS pipe") == -1)
317 ilog(L_MAIN
, "Unable to create ssld - rb_pipe failed: %s", strerror(errno
));
320 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(P1
));
321 rb_setenv("CTL_PIPE", fdarg
, 1);
322 snprintf(s_pid
, sizeof(s_pid
), "%d", (int)getpid());
323 rb_setenv("CTL_PPID", s_pid
, 1);
325 SetHandleInformation((HANDLE
) rb_get_fd(F2
), HANDLE_FLAG_INHERIT
, 1);
326 SetHandleInformation((HANDLE
) rb_get_fd(P1
), HANDLE_FLAG_INHERIT
, 1);
329 pid
= rb_spawn_process(ssld_path
, (const char **) parv
);
332 ilog(L_MAIN
, "Unable to create ssld: %s\n", strerror(errno
));
342 ctl
= allocate_ssl_daemon(F1
, P2
, pid
);
345 send_init_prng(ctl
, RB_PRNG_DEFAULT
, NULL
);
346 send_certfp_method(ctl
, ConfigFileEntry
.certfp_method
);
348 if(ssl_cert
!= NULL
&& ssl_private_key
!= NULL
)
349 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
,
350 ssl_dh_params
!= NULL
? ssl_dh_params
: "",
351 ssl_cipher_list
!= NULL
? ssl_cipher_list
: "");
353 ssl_read_ctl(ctl
->F
, ctl
);
354 ssl_do_pipe(P2
, ctl
);
361 ssl_process_zipstats(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
363 struct Client
*server
;
364 struct ZipStats
*zips
;
366 (void) rb_string_to_array(ctl_buf
->buf
, parv
, 6);
367 server
= find_server(NULL
, parv
[1]);
368 if(server
== NULL
|| server
->localClient
== NULL
|| !IsCapable(server
, CAP_ZIP
))
370 if(server
->localClient
->zipstats
== NULL
)
371 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
373 zips
= server
->localClient
->zipstats
;
375 zips
->in
+= strtoull(parv
[2], NULL
, 10);
376 zips
->in_wire
+= strtoull(parv
[3], NULL
, 10);
377 zips
->out
+= strtoull(parv
[4], NULL
, 10);
378 zips
->out_wire
+= strtoull(parv
[5], NULL
, 10);
381 zips
->in_ratio
= ((double) (zips
->in
- zips
->in_wire
) / (double) zips
->in
) * 100.00;
386 zips
->out_ratio
= ((double) (zips
->out
- zips
->out_wire
) / (double) zips
->out
) * 100.00;
392 ssl_process_dead_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
394 struct Client
*client_p
;
398 if(ctl_buf
->buflen
< 6)
399 return; /* bogus message..drop it.. XXX should warn here */
401 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
402 rb_strlcpy(reason
, &ctl_buf
->buf
[5], sizeof(reason
));
403 client_p
= find_cli_connid_hash(fd
);
406 if(IsAnyServer(client_p
) || IsRegistered(client_p
))
408 /* read any last moment ERROR, QUIT or the like -- jilles */
409 if (!strcmp(reason
, "Remote host closed the connection"))
410 read_packet(client_p
->localClient
->F
, client_p
);
411 if (IsAnyDead(client_p
))
414 if(IsAnyServer(client_p
))
416 sendto_realops_snomask(SNO_GENERAL
, is_remote_connect(client_p
) && !IsServer(client_p
) ? L_NETWIDE
: L_ALL
, "ssld error for %s: %s", client_p
->name
, reason
);
417 ilog(L_SERVER
, "ssld error for %s: %s", log_client_name(client_p
, SHOW_IP
), reason
);
419 exit_client(client_p
, client_p
, &me
, reason
);
424 ssl_process_cipher_string(ssl_ctl_t
*ctl
, ssl_ctl_buf_t
*ctl_buf
)
426 struct Client
*client_p
;
430 if(ctl_buf
->buflen
< 6)
431 return; /* bogus message..drop it.. XXX should warn here */
433 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
434 cstring
= (const char *)&ctl_buf
->buf
[5];
436 if(EmptyString(cstring
))
439 client_p
= find_cli_connid_hash(fd
);
440 if(client_p
!= NULL
&& client_p
->localClient
!= NULL
)
442 rb_free(client_p
->localClient
->cipher_string
);
443 client_p
->localClient
->cipher_string
= rb_strdup(cstring
);
449 ssl_process_certfp(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
451 struct Client
*client_p
;
458 if(ctl_buf
->buflen
> 5 + RB_SSL_CERTFP_LEN
)
459 return; /* bogus message..drop it.. XXX should warn here */
461 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
462 len
= buf_to_uint32(&ctl_buf
->buf
[5]);
463 certfp
= (uint8_t *)&ctl_buf
->buf
[9];
464 client_p
= find_cli_connid_hash(fd
);
467 rb_free(client_p
->certfp
);
468 certfp_string
= rb_malloc(len
* 2 + 1);
469 for(i
= 0; i
< len
; i
++)
470 snprintf(certfp_string
+ 2 * i
, 3, "%02x",
472 client_p
->certfp
= certfp_string
;
476 ssl_process_cmd_recv(ssl_ctl_t
* ctl
)
478 static const char *cannot_setup_ssl
= "ssld cannot setup ssl, check your certificates and private key";
479 static const char *no_ssl_or_zlib
= "ssld has neither SSL/TLS or zlib support killing all sslds";
480 rb_dlink_node
*ptr
, *next
;
481 ssl_ctl_buf_t
*ctl_buf
;
484 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->readq
.head
)
487 switch (*ctl_buf
->buf
)
490 ssl_ok
= 0; /* ssld says it can't do ssl/tls */
493 ssl_process_dead_fd(ctl
, ctl_buf
);
496 ssl_process_cipher_string(ctl
, ctl_buf
);
499 ssl_process_certfp(ctl
, ctl_buf
);
502 ssl_process_zipstats(ctl
, ctl_buf
);
506 ilog(L_MAIN
, "%s", cannot_setup_ssl
);
507 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", cannot_setup_ssl
);
512 ilog(L_MAIN
, "%s", no_ssl_or_zlib
);
513 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", no_ssl_or_zlib
);
520 ilog(L_MAIN
, "Received invalid command from ssld: %s", ctl_buf
->buf
);
521 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Received invalid command from ssld");
524 rb_dlinkDelete(ptr
, &ctl
->readq
);
525 rb_free(ctl_buf
->buf
);
533 ssl_read_ctl(rb_fde_t
* F
, void *data
)
535 ssl_ctl_buf_t
*ctl_buf
;
536 ssl_ctl_t
*ctl
= data
;
543 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
544 ctl_buf
->buf
= rb_malloc(READSIZE
);
545 retlen
= rb_recv_fd_buf(ctl
->F
, ctl_buf
->buf
, READSIZE
, ctl_buf
->F
, 4);
546 ctl_buf
->buflen
= retlen
;
549 rb_free(ctl_buf
->buf
);
553 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->readq
);
557 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
562 ssl_process_cmd_recv(ctl
);
563 rb_setselect(ctl
->F
, RB_SELECT_READ
, ssl_read_ctl
, ctl
);
569 ssl_ctl_t
*ctl
, *lowest
= NULL
;
572 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
584 if(ctl
->cli_count
< lowest
->cli_count
)
591 ssl_write_ctl(rb_fde_t
* F
, void *data
)
593 ssl_ctl_t
*ctl
= data
;
594 ssl_ctl_buf_t
*ctl_buf
;
595 rb_dlink_node
*ptr
, *next
;
601 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->writeq
.head
)
604 /* in theory unix sock_dgram shouldn't ever short write this.. */
605 retlen
= rb_send_fd_buf(ctl
->F
, ctl_buf
->F
, ctl_buf
->nfds
, ctl_buf
->buf
, ctl_buf
->buflen
, ctl
->pid
);
608 rb_dlinkDelete(ptr
, &ctl
->writeq
);
609 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
610 rb_close(ctl_buf
->F
[x
]);
611 rb_free(ctl_buf
->buf
);
615 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
622 rb_setselect(ctl
->F
, RB_SELECT_WRITE
, ssl_write_ctl
, ctl
);
628 ssl_cmd_write_queue(ssl_ctl_t
* ctl
, rb_fde_t
** F
, int count
, const void *buf
, size_t buflen
)
630 ssl_ctl_buf_t
*ctl_buf
;
637 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
638 ctl_buf
->buf
= rb_malloc(buflen
);
639 memcpy(ctl_buf
->buf
, buf
, buflen
);
640 ctl_buf
->buflen
= buflen
;
642 for(x
= 0; x
< count
&& x
< MAXPASSFD
; x
++)
644 ctl_buf
->F
[x
] = F
[x
];
646 ctl_buf
->nfds
= count
;
647 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->writeq
);
648 ssl_write_ctl(ctl
->F
, ctl
);
653 send_new_ssl_certs_one(ssl_ctl_t
* ctl
, const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
657 len
= strlen(ssl_cert
) + strlen(ssl_private_key
) + strlen(ssl_dh_params
) + 5;
658 if(len
> sizeof(tmpbuf
))
660 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
661 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
662 len
, sizeof(tmpbuf
));
664 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
665 len
, sizeof(tmpbuf
));
668 len
= snprintf(tmpbuf
, sizeof(tmpbuf
), "K%c%s%c%s%c%s%c%s%c", nul
, ssl_cert
, nul
,
669 ssl_private_key
, nul
, ssl_dh_params
, nul
,
670 ssl_cipher_list
!= NULL
? ssl_cipher_list
: "", nul
);
671 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, len
);
675 send_init_prng(ssl_ctl_t
* ctl
, prng_seed_t seedtype
, const char *path
)
679 uint8_t seed
= (uint8_t) seedtype
;
687 if(len
> sizeof(tmpbuf
))
689 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
690 "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
691 len
, sizeof(tmpbuf
));
693 "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
694 len
, sizeof(tmpbuf
));
698 len
= snprintf(tmpbuf
, sizeof(tmpbuf
), "I%c%s%c", seed
, s
, nul
);
699 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, len
);
703 send_certfp_method(ssl_ctl_t
*ctl
, int method
)
708 uint32_to_buf(&buf
[1], method
);
709 ssl_cmd_write_queue(ctl
, NULL
, 0, buf
, sizeof(buf
));
713 send_new_ssl_certs(const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
716 if(ssl_cert
== NULL
|| ssl_private_key
== NULL
|| ssl_dh_params
== NULL
)
721 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
723 ssl_ctl_t
*ctl
= ptr
->data
;
724 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
, ssl_dh_params
, ssl_cipher_list
);
730 start_ssld_accept(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
739 uint32_to_buf(&buf
[1], id
);
744 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
749 start_ssld_connect(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
758 uint32_to_buf(&buf
[1], id
);
764 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
769 ssld_decrement_clicount(ssl_ctl_t
* ctl
)
775 if(ctl
->shutdown
&& !ctl
->cli_count
)
778 rb_kill(ctl
->pid
, SIGKILL
);
780 if(ctl
->dead
&& !ctl
->cli_count
)
782 free_ssl_daemon(ctl
);
787 * what we end up sending to the ssld process for ziplinks is the following
788 * Z[ourfd][level][RECVQ]
789 * Z = ziplinks command = buf[0]
790 * ourfd = Our end of the socketpair = buf[1..4]
791 * level = zip level buf[5]
792 * recvqlen = our recvq len = buf[6-7]
793 * recvq = any data we read prior to starting ziplinks
796 start_zlib_session(void *data
)
798 struct Client
*server
= (struct Client
*) data
;
809 size_t hdr
= (sizeof(uint8_t) * 2) + sizeof(uint32_t);
813 server
->localClient
->event
= NULL
;
815 recvqlen
= rb_linebuf_len(&server
->localClient
->buf_recvq
);
817 len
= recvqlen
+ hdr
;
819 if(len
> READBUF_SIZE
)
821 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
822 "ssld - attempted to pass message of %zd len, max len %d, giving up",
824 ilog(L_MAIN
, "ssld - attempted to pass message of %zd len, max len %d, giving up", len
, READBUF_SIZE
);
825 exit_client(server
, server
, server
, "ssld readbuf exceeded");
829 buf
= rb_malloc(len
);
830 level
= ConfigFileEntry
.compression_level
;
832 uint32_to_buf(&buf
[1], rb_get_fd(server
->localClient
->F
));
833 buf
[5] = (char) level
;
835 recvq_start
= &buf
[6];
836 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
843 cpylen
= rb_linebuf_get(&server
->localClient
->buf_recvq
, xbuf
, left
, LINEBUF_PARTIAL
, LINEBUF_RAW
);
845 xbuf
= (void *) (((uintptr_t) xbuf
) + cpylen
);
849 /* Pass the socket to ssld. */
851 if(rb_socketpair(AF_UNIX
, SOCK_STREAM
, 0, &xF1
, &xF2
, "Initial zlib socketpairs") == -1)
853 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Error creating zlib socketpair - %s", strerror(errno
));
854 ilog(L_MAIN
, "Error creating zlib socketpairs - %s", strerror(errno
));
855 exit_client(server
, server
, server
, "Error creating zlib socketpair");
862 /* tell ssld the new connid for the ssl part*/
864 uint32_to_buf(&buf2
[1], rb_get_fd(server
->localClient
->F
));
865 uint32_to_buf(&buf2
[5], rb_get_fd(xF2
));
866 ssl_cmd_write_queue(server
->localClient
->ssl_ctl
, NULL
, 0, buf2
, sizeof(buf2
));
870 F
[0] = server
->localClient
->F
;
872 del_from_cli_connid_hash(server
);
873 server
->localClient
->F
= xF2
;
874 /* need to redo as what we did before isn't valid now */
875 uint32_to_buf(&buf
[1], rb_get_fd(server
->localClient
->F
));
876 add_to_cli_connid_hash(server
);
878 server
->localClient
->z_ctl
= which_ssld();
879 if(!server
->localClient
->z_ctl
)
881 exit_client(server
, server
, server
, "Error finding available ssld");
885 server
->localClient
->z_ctl
->cli_count
++;
886 ssl_cmd_write_queue(server
->localClient
->z_ctl
, F
, 2, buf
, len
);
891 collect_zipstats(void *unused
)
894 struct Client
*target_p
;
895 char buf
[sizeof(uint8_t) + sizeof(uint32_t) + HOSTLEN
];
901 odata
= buf
+ sizeof(uint8_t) + sizeof(uint32_t);
903 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
905 target_p
= ptr
->data
;
906 if(IsCapable(target_p
, CAP_ZIP
))
908 len
= sizeof(uint8_t) + sizeof(uint32_t);
910 id
= rb_get_fd(target_p
->localClient
->F
);
911 uint32_to_buf(&buf
[1], id
);
912 rb_strlcpy(odata
, target_p
->name
, (sizeof(buf
) - len
));
913 len
+= strlen(odata
) + 1; /* Get the \0 as well */
914 ssl_cmd_write_queue(target_p
->localClient
->z_ctl
, NULL
, 0, buf
, len
);
920 cleanup_dead_ssl(void *unused
)
922 rb_dlink_node
*ptr
, *next
;
924 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
927 if(ctl
->dead
&& !ctl
->cli_count
)
929 free_ssl_daemon(ctl
);
941 ssld_foreach_info(void (*func
)(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
), void *data
)
943 rb_dlink_node
*ptr
, *next
;
945 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
948 func(data
, ctl
->pid
, ctl
->cli_count
,
949 ctl
->dead
? SSLD_DEAD
:
950 (ctl
->shutdown
? SSLD_SHUTDOWN
: SSLD_ACTIVE
));
957 rb_event_addish("collect_zipstats", collect_zipstats
, NULL
, ZIPSTATS_TIME
);
958 rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl
, NULL
, 60);