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
37 #define ZIPSTATS_TIME 60
39 static void collect_zipstats(void *unused
);
40 static void ssl_read_ctl(rb_fde_t
* F
, void *data
);
41 static int ssld_count
;
43 static char tmpbuf
[READBUF_SIZE
];
44 static char nul
= '\0';
48 typedef struct _ssl_ctl_buf
53 rb_fde_t
*F
[MAXPASSFD
];
72 static void send_new_ssl_certs_one(ssl_ctl_t
* ctl
, const char *ssl_cert
,
73 const char *ssl_private_key
, const char *ssl_dh_params
,
74 const char *ssl_cipher_list
);
75 static void send_init_prng(ssl_ctl_t
* ctl
, prng_seed_t seedtype
, const char *path
);
76 static void send_certfp_method(ssl_ctl_t
*ctl
, int method
);
79 static rb_dlink_list ssl_daemons
;
81 static inline uint32_t
82 buf_to_uint32(char *buf
)
85 memcpy(&x
, buf
, sizeof(x
));
90 uint32_to_buf(char *buf
, uint32_t x
)
92 memcpy(buf
, &x
, sizeof(x
));
97 allocate_ssl_daemon(rb_fde_t
* F
, rb_fde_t
* P
, int pid
)
101 if(F
== NULL
|| pid
< 0)
103 ctl
= rb_malloc(sizeof(ssl_ctl_t
));
108 rb_dlinkAdd(ctl
, &ctl
->node
, &ssl_daemons
);
113 free_ssl_daemon(ssl_ctl_t
* ctl
)
116 ssl_ctl_buf_t
*ctl_buf
;
121 RB_DLINK_FOREACH(ptr
, ctl
->readq
.head
)
124 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
125 rb_close(ctl_buf
->F
[x
]);
127 rb_free(ctl_buf
->buf
);
131 RB_DLINK_FOREACH(ptr
, ctl
->writeq
.head
)
134 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
135 rb_close(ctl_buf
->F
[x
]);
137 rb_free(ctl_buf
->buf
);
142 rb_dlinkDelete(&ctl
->node
, &ssl_daemons
);
146 static char *ssld_path
;
148 static int ssld_spin_count
= 0;
149 static time_t last_spin
;
150 static int ssld_wait
= 0;
156 rb_dlink_node
*ptr
, *next
;
159 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
170 rb_kill(ctl
->pid
, SIGKILL
);
171 free_ssl_daemon(ctl
);
175 start_ssldaemon(ServerInfo
.ssld_count
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
181 rb_dlink_node
*ptr
, *next
;
183 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
191 rb_kill(ctl
->pid
, SIGKILL
);
193 free_ssl_daemon(ctl
);
198 ssl_dead(ssl_ctl_t
* ctl
)
204 rb_kill(ctl
->pid
, SIGKILL
); /* make sure the process is really gone */
209 ilog(L_MAIN
, "ssld helper died - attempting to restart");
210 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "ssld helper died - attempting to restart");
211 start_ssldaemon(1, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
216 ssl_do_pipe(rb_fde_t
* F
, void *data
)
219 ssl_ctl_t
*ctl
= data
;
220 retlen
= rb_write(F
, "0", 1);
221 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
226 rb_setselect(F
, RB_SELECT_READ
, ssl_do_pipe
, data
);
230 restart_ssld_event(void *unused
)
235 if(ServerInfo
.ssld_count
> get_ssld_count())
237 int start
= ServerInfo
.ssld_count
- get_ssld_count();
238 ilog(L_MAIN
, "Attempting to restart ssld processes");
239 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Attempt to restart ssld processes");
240 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
245 start_ssldaemon(int count
, const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
250 const char *suffix
= ".exe";
252 const char *suffix
= "";
255 char fullpath
[PATH_MAX
+ 1];
266 if(ssld_spin_count
> 20 && (rb_current_time() - last_spin
< 5))
268 ilog(L_MAIN
, "ssld helper is spinning - will attempt to restart in 1 minute");
269 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
270 "ssld helper is spinning - will attempt to restart in 1 minute");
271 rb_event_add("restart_ssld_event", restart_ssld_event
, NULL
, 60);
277 last_spin
= rb_current_time();
279 if(ssld_path
== NULL
)
281 snprintf(fullpath
, sizeof(fullpath
), "%s%cssld%s", ircd_paths
[IRCD_PATH_LIBEXEC
], RB_PATH_SEPARATOR
, suffix
);
283 if(access(fullpath
, X_OK
) == -1)
285 snprintf(fullpath
, sizeof(fullpath
), "%s%cbin%cssld%s",
286 ConfigFileEntry
.dpath
, RB_PATH_SEPARATOR
, RB_PATH_SEPARATOR
, suffix
);
287 if(access(fullpath
, X_OK
) == -1)
290 "Unable to execute ssld%s in %s or %s/bin",
291 suffix
, ircd_paths
[IRCD_PATH_LIBEXEC
], ConfigFileEntry
.dpath
);
295 ssld_path
= rb_strdup(fullpath
);
297 rb_strlcpy(buf
, "-ircd ssld daemon", sizeof(buf
));
301 for(i
= 0; i
< count
; i
++)
304 if(rb_socketpair(AF_UNIX
, SOCK_DGRAM
, 0, &F1
, &F2
, "SSL/TLS handle passing socket") == -1)
306 ilog(L_MAIN
, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno
));
310 rb_set_buffers(F1
, READBUF_SIZE
);
311 rb_set_buffers(F2
, READBUF_SIZE
);
312 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(F2
));
313 rb_setenv("CTL_FD", fdarg
, 1);
314 if(rb_pipe(&P1
, &P2
, "SSL/TLS pipe") == -1)
316 ilog(L_MAIN
, "Unable to create ssld - rb_pipe failed: %s", strerror(errno
));
319 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(P1
));
320 rb_setenv("CTL_PIPE", fdarg
, 1);
321 snprintf(s_pid
, sizeof(s_pid
), "%d", (int)getpid());
322 rb_setenv("CTL_PPID", s_pid
, 1);
324 SetHandleInformation((HANDLE
) rb_get_fd(F2
), HANDLE_FLAG_INHERIT
, 1);
325 SetHandleInformation((HANDLE
) rb_get_fd(P1
), HANDLE_FLAG_INHERIT
, 1);
328 pid
= rb_spawn_process(ssld_path
, (const char **) parv
);
331 ilog(L_MAIN
, "Unable to create ssld: %s\n", strerror(errno
));
341 ctl
= allocate_ssl_daemon(F1
, P2
, pid
);
344 send_init_prng(ctl
, RB_PRNG_DEFAULT
, NULL
);
345 send_certfp_method(ctl
, ConfigFileEntry
.certfp_method
);
347 if(ssl_cert
!= NULL
&& ssl_private_key
!= NULL
)
348 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
,
349 ssl_dh_params
!= NULL
? ssl_dh_params
: "",
350 ssl_cipher_list
!= NULL
? ssl_cipher_list
: "");
352 ssl_read_ctl(ctl
->F
, ctl
);
353 ssl_do_pipe(P2
, ctl
);
360 ssl_process_zipstats(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
362 struct Client
*server
;
363 struct ZipStats
*zips
;
365 (void) rb_string_to_array(ctl_buf
->buf
, parv
, 6);
366 server
= find_server(NULL
, parv
[1]);
367 if(server
== NULL
|| server
->localClient
== NULL
|| !IsCapable(server
, CAP_ZIP
))
369 if(server
->localClient
->zipstats
== NULL
)
370 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
372 zips
= server
->localClient
->zipstats
;
374 zips
->in
+= strtoull(parv
[2], NULL
, 10);
375 zips
->in_wire
+= strtoull(parv
[3], NULL
, 10);
376 zips
->out
+= strtoull(parv
[4], NULL
, 10);
377 zips
->out_wire
+= strtoull(parv
[5], NULL
, 10);
380 zips
->in_ratio
= ((double) (zips
->in
- zips
->in_wire
) / (double) zips
->in
) * 100.00;
385 zips
->out_ratio
= ((double) (zips
->out
- zips
->out_wire
) / (double) zips
->out
) * 100.00;
391 ssl_process_dead_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
393 struct Client
*client_p
;
397 if(ctl_buf
->buflen
< 6)
398 return; /* bogus message..drop it.. XXX should warn here */
400 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
401 rb_strlcpy(reason
, &ctl_buf
->buf
[5], sizeof(reason
));
402 client_p
= find_cli_connid_hash(fd
);
405 if(IsAnyServer(client_p
) || IsRegistered(client_p
))
407 /* read any last moment ERROR, QUIT or the like -- jilles */
408 if (!strcmp(reason
, "Remote host closed the connection"))
409 read_packet(client_p
->localClient
->F
, client_p
);
410 if (IsAnyDead(client_p
))
413 if(IsAnyServer(client_p
))
415 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
);
416 ilog(L_SERVER
, "ssld error for %s: %s", log_client_name(client_p
, SHOW_IP
), reason
);
418 exit_client(client_p
, client_p
, &me
, reason
);
423 ssl_process_cipher_string(ssl_ctl_t
*ctl
, ssl_ctl_buf_t
*ctl_buf
)
425 struct Client
*client_p
;
429 if(ctl_buf
->buflen
< 6)
430 return; /* bogus message..drop it.. XXX should warn here */
432 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
433 cstring
= (const char *)&ctl_buf
->buf
[5];
435 if(EmptyString(cstring
))
438 client_p
= find_cli_connid_hash(fd
);
439 if(client_p
!= NULL
&& client_p
->localClient
!= NULL
)
441 rb_free(client_p
->localClient
->cipher_string
);
442 client_p
->localClient
->cipher_string
= rb_strdup(cstring
);
448 ssl_process_certfp(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
450 struct Client
*client_p
;
456 if(ctl_buf
->buflen
> 9 + RB_SSL_CERTFP_LEN
)
457 return; /* bogus message..drop it.. XXX should warn here */
459 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
460 len
= buf_to_uint32(&ctl_buf
->buf
[5]);
461 certfp
= (uint8_t *)&ctl_buf
->buf
[9];
462 client_p
= find_cli_connid_hash(fd
);
465 rb_free(client_p
->certfp
);
466 certfp_string
= rb_malloc(len
* 2 + 1);
467 for(uint32_t i
= 0; i
< len
; i
++)
468 snprintf(certfp_string
+ 2 * i
, 3, "%02x",
470 client_p
->certfp
= certfp_string
;
474 ssl_process_cmd_recv(ssl_ctl_t
* ctl
)
476 static const char *cannot_setup_ssl
= "ssld cannot setup ssl, check your certificates and private key";
477 static const char *no_ssl_or_zlib
= "ssld has neither SSL/TLS or zlib support killing all sslds";
478 rb_dlink_node
*ptr
, *next
;
479 ssl_ctl_buf_t
*ctl_buf
;
485 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->readq
.head
)
488 switch (*ctl_buf
->buf
)
491 ircd_ssl_ok
= false; /* ssld says it can't do ssl/tls */
494 ssl_process_dead_fd(ctl
, ctl_buf
);
497 ssl_process_cipher_string(ctl
, ctl_buf
);
500 ssl_process_certfp(ctl
, ctl_buf
);
503 ssl_process_zipstats(ctl
, ctl_buf
);
507 ilog(L_MAIN
, "%s", cannot_setup_ssl
);
508 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", cannot_setup_ssl
);
513 ilog(L_MAIN
, "%s", no_ssl_or_zlib
);
514 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", no_ssl_or_zlib
);
518 len
= ctl_buf
->buflen
- 1;
519 if (len
> sizeof(ctl
->version
) - 1)
520 len
= sizeof(ctl
->version
) - 1;
521 strncpy(ctl
->version
, &ctl_buf
->buf
[1], len
);
526 ilog(L_MAIN
, "Received invalid command from ssld: %s", ctl_buf
->buf
);
527 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Received invalid command from ssld");
530 rb_dlinkDelete(ptr
, &ctl
->readq
);
531 rb_free(ctl_buf
->buf
);
539 ssl_read_ctl(rb_fde_t
* F
, void *data
)
541 ssl_ctl_buf_t
*ctl_buf
;
542 ssl_ctl_t
*ctl
= data
;
549 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
550 ctl_buf
->buf
= rb_malloc(READSIZE
);
551 retlen
= rb_recv_fd_buf(ctl
->F
, ctl_buf
->buf
, READSIZE
, ctl_buf
->F
, 4);
552 ctl_buf
->buflen
= retlen
;
555 rb_free(ctl_buf
->buf
);
559 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->readq
);
563 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
568 ssl_process_cmd_recv(ctl
);
569 rb_setselect(ctl
->F
, RB_SELECT_READ
, ssl_read_ctl
, ctl
);
575 ssl_ctl_t
*ctl
, *lowest
= NULL
;
578 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
590 if(ctl
->cli_count
< lowest
->cli_count
)
597 ssl_write_ctl(rb_fde_t
* F
, void *data
)
599 ssl_ctl_t
*ctl
= data
;
600 ssl_ctl_buf_t
*ctl_buf
;
601 rb_dlink_node
*ptr
, *next
;
607 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->writeq
.head
)
610 /* in theory unix sock_dgram shouldn't ever short write this.. */
611 retlen
= rb_send_fd_buf(ctl
->F
, ctl_buf
->F
, ctl_buf
->nfds
, ctl_buf
->buf
, ctl_buf
->buflen
, ctl
->pid
);
614 rb_dlinkDelete(ptr
, &ctl
->writeq
);
615 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
616 rb_close(ctl_buf
->F
[x
]);
617 rb_free(ctl_buf
->buf
);
621 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
628 rb_setselect(ctl
->F
, RB_SELECT_WRITE
, ssl_write_ctl
, ctl
);
634 ssl_cmd_write_queue(ssl_ctl_t
* ctl
, rb_fde_t
** F
, int count
, const void *buf
, size_t buflen
)
636 ssl_ctl_buf_t
*ctl_buf
;
643 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
644 ctl_buf
->buf
= rb_malloc(buflen
);
645 memcpy(ctl_buf
->buf
, buf
, buflen
);
646 ctl_buf
->buflen
= buflen
;
648 for(x
= 0; x
< count
&& x
< MAXPASSFD
; x
++)
650 ctl_buf
->F
[x
] = F
[x
];
652 ctl_buf
->nfds
= count
;
653 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->writeq
);
654 ssl_write_ctl(ctl
->F
, ctl
);
659 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
)
663 len
= strlen(ssl_cert
) + strlen(ssl_private_key
) + strlen(ssl_dh_params
) + 5;
664 if(len
> sizeof(tmpbuf
))
666 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
667 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
668 len
, sizeof(tmpbuf
));
670 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
671 len
, sizeof(tmpbuf
));
674 len
= snprintf(tmpbuf
, sizeof(tmpbuf
), "K%c%s%c%s%c%s%c%s%c", nul
, ssl_cert
, nul
,
675 ssl_private_key
, nul
, ssl_dh_params
, nul
,
676 ssl_cipher_list
!= NULL
? ssl_cipher_list
: "", nul
);
677 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, len
);
681 send_init_prng(ssl_ctl_t
* ctl
, prng_seed_t seedtype
, const char *path
)
685 uint8_t seed
= (uint8_t) seedtype
;
693 if(len
> sizeof(tmpbuf
))
695 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
696 "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
697 len
, sizeof(tmpbuf
));
699 "Parameters for send_init_prng too long (%zd > %zd) to pass to ssld, not sending...",
700 len
, sizeof(tmpbuf
));
704 len
= snprintf(tmpbuf
, sizeof(tmpbuf
), "I%c%s%c", seed
, s
, nul
);
705 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, len
);
709 send_certfp_method(ssl_ctl_t
*ctl
, int method
)
714 uint32_to_buf(&buf
[1], method
);
715 ssl_cmd_write_queue(ctl
, NULL
, 0, buf
, sizeof(buf
));
719 send_new_ssl_certs(const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
722 if(ssl_cert
== NULL
|| ssl_private_key
== NULL
|| ssl_dh_params
== NULL
)
727 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
729 ssl_ctl_t
*ctl
= ptr
->data
;
730 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
, ssl_dh_params
, ssl_cipher_list
);
736 start_ssld_accept(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
745 uint32_to_buf(&buf
[1], id
);
750 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
755 start_ssld_connect(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
764 uint32_to_buf(&buf
[1], id
);
770 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
775 ssld_decrement_clicount(ssl_ctl_t
* ctl
)
781 if(ctl
->shutdown
&& !ctl
->cli_count
)
784 rb_kill(ctl
->pid
, SIGKILL
);
786 if(ctl
->dead
&& !ctl
->cli_count
)
788 free_ssl_daemon(ctl
);
793 * what we end up sending to the ssld process for ziplinks is the following
794 * Z[ourfd][level][RECVQ]
795 * Z = ziplinks command = buf[0]
796 * ourfd = Our end of the socketpair = buf[1..4]
797 * level = zip level buf[5]
798 * recvqlen = our recvq len = buf[6-7]
799 * recvq = any data we read prior to starting ziplinks
802 start_zlib_session(void *data
)
804 struct Client
*server
= (struct Client
*) data
;
814 size_t hdr
= (sizeof(uint8_t) * 2) + sizeof(uint32_t);
818 server
->localClient
->event
= NULL
;
820 recvqlen
= rb_linebuf_len(&server
->localClient
->buf_recvq
);
822 len
= recvqlen
+ hdr
;
824 if(len
> READBUF_SIZE
)
826 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
827 "ssld - attempted to pass message of %zd len, max len %d, giving up",
829 ilog(L_MAIN
, "ssld - attempted to pass message of %zd len, max len %d, giving up", len
, READBUF_SIZE
);
830 exit_client(server
, server
, server
, "ssld readbuf exceeded");
834 buf
= rb_malloc(len
);
835 level
= ConfigFileEntry
.compression_level
;
837 uint32_to_buf(&buf
[1], rb_get_fd(server
->localClient
->F
));
838 buf
[5] = (char) level
;
840 recvq_start
= &buf
[6];
841 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
848 cpylen
= rb_linebuf_get(&server
->localClient
->buf_recvq
, xbuf
, left
, LINEBUF_PARTIAL
, LINEBUF_RAW
);
850 xbuf
= (void *) (((uintptr_t) xbuf
) + cpylen
);
854 /* Pass the socket to ssld. */
856 if(rb_socketpair(AF_UNIX
, SOCK_STREAM
, 0, &xF1
, &xF2
, "Initial zlib socketpairs") == -1)
858 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Error creating zlib socketpair - %s", strerror(errno
));
859 ilog(L_MAIN
, "Error creating zlib socketpairs - %s", strerror(errno
));
860 exit_client(server
, server
, server
, "Error creating zlib socketpair");
865 F
[0] = server
->localClient
->F
;
867 server
->localClient
->F
= xF2
;
868 /* need to redo as what we did before isn't valid now */
869 uint32_to_buf(&buf
[1], connid_get(server
));
871 server
->localClient
->z_ctl
= which_ssld();
872 if(!server
->localClient
->z_ctl
)
874 exit_client(server
, server
, server
, "Error finding available ssld");
878 server
->localClient
->z_ctl
->cli_count
++;
879 ssl_cmd_write_queue(server
->localClient
->z_ctl
, F
, 2, buf
, len
);
884 collect_zipstats(void *unused
)
887 struct Client
*target_p
;
888 char buf
[sizeof(uint8_t) + sizeof(uint32_t) + HOSTLEN
];
894 odata
= buf
+ sizeof(uint8_t) + sizeof(uint32_t);
896 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
898 target_p
= ptr
->data
;
899 if(IsCapable(target_p
, CAP_ZIP
))
901 len
= sizeof(uint8_t) + sizeof(uint32_t);
903 id
= rb_get_fd(target_p
->localClient
->F
);
904 uint32_to_buf(&buf
[1], id
);
905 rb_strlcpy(odata
, target_p
->name
, (sizeof(buf
) - len
));
906 len
+= strlen(odata
) + 1; /* Get the \0 as well */
907 ssl_cmd_write_queue(target_p
->localClient
->z_ctl
, NULL
, 0, buf
, len
);
913 cleanup_dead_ssl(void *unused
)
915 rb_dlink_node
*ptr
, *next
;
917 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
920 if(ctl
->dead
&& !ctl
->cli_count
)
922 free_ssl_daemon(ctl
);
934 ssld_foreach_info(void (*func
)(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
), void *data
)
936 rb_dlink_node
*ptr
, *next
;
938 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
941 func(data
, ctl
->pid
, ctl
->cli_count
,
942 ctl
->dead
? SSLD_DEAD
:
943 (ctl
->shutdown
? SSLD_SHUTDOWN
: SSLD_ACTIVE
),
951 rb_event_addish("collect_zipstats", collect_zipstats
, NULL
, ZIPSTATS_TIME
);
952 rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl
, NULL
, 60);