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_certfp_method(ssl_ctl_t
*ctl
, int method
);
78 static rb_dlink_list ssl_daemons
;
80 static inline uint32_t
81 buf_to_uint32(char *buf
)
84 memcpy(&x
, buf
, sizeof(x
));
89 uint32_to_buf(char *buf
, uint32_t x
)
91 memcpy(buf
, &x
, sizeof(x
));
96 allocate_ssl_daemon(rb_fde_t
* F
, rb_fde_t
* P
, int pid
)
100 if(F
== NULL
|| pid
< 0)
102 ctl
= rb_malloc(sizeof(ssl_ctl_t
));
107 rb_dlinkAdd(ctl
, &ctl
->node
, &ssl_daemons
);
112 free_ssl_daemon(ssl_ctl_t
* ctl
)
115 ssl_ctl_buf_t
*ctl_buf
;
120 RB_DLINK_FOREACH(ptr
, ctl
->readq
.head
)
123 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
124 rb_close(ctl_buf
->F
[x
]);
126 rb_free(ctl_buf
->buf
);
130 RB_DLINK_FOREACH(ptr
, ctl
->writeq
.head
)
133 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
134 rb_close(ctl_buf
->F
[x
]);
136 rb_free(ctl_buf
->buf
);
141 rb_dlinkDelete(&ctl
->node
, &ssl_daemons
);
145 static char *ssld_path
;
147 static int ssld_spin_count
= 0;
148 static time_t last_spin
;
149 static int ssld_wait
= 0;
155 rb_dlink_node
*ptr
, *next
;
158 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
169 rb_kill(ctl
->pid
, SIGKILL
);
170 free_ssl_daemon(ctl
);
174 start_ssldaemon(ServerInfo
.ssld_count
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
180 rb_dlink_node
*ptr
, *next
;
182 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
190 rb_kill(ctl
->pid
, SIGKILL
);
192 free_ssl_daemon(ctl
);
197 ssl_dead(ssl_ctl_t
* ctl
)
203 rb_kill(ctl
->pid
, SIGKILL
); /* make sure the process is really gone */
208 ilog(L_MAIN
, "ssld helper died - attempting to restart");
209 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "ssld helper died - attempting to restart");
210 start_ssldaemon(1, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
215 ssl_do_pipe(rb_fde_t
* F
, void *data
)
218 ssl_ctl_t
*ctl
= data
;
219 retlen
= rb_write(F
, "0", 1);
220 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
225 rb_setselect(F
, RB_SELECT_READ
, ssl_do_pipe
, data
);
229 restart_ssld_event(void *unused
)
234 if(ServerInfo
.ssld_count
> get_ssld_count())
236 int start
= ServerInfo
.ssld_count
- get_ssld_count();
237 ilog(L_MAIN
, "Attempting to restart ssld processes");
238 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Attempt to restart ssld processes");
239 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
, ServerInfo
.ssl_cipher_list
);
244 start_ssldaemon(int count
, const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
249 const char *suffix
= ".exe";
251 const char *suffix
= "";
254 char fullpath
[PATH_MAX
+ 1];
265 if(ssld_spin_count
> 20 && (rb_current_time() - last_spin
< 5))
267 ilog(L_MAIN
, "ssld helper is spinning - will attempt to restart in 1 minute");
268 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
269 "ssld helper is spinning - will attempt to restart in 1 minute");
270 rb_event_add("restart_ssld_event", restart_ssld_event
, NULL
, 60);
276 last_spin
= rb_current_time();
278 if(ssld_path
== NULL
)
280 snprintf(fullpath
, sizeof(fullpath
), "%s%cssld%s", ircd_paths
[IRCD_PATH_LIBEXEC
], RB_PATH_SEPARATOR
, suffix
);
282 if(access(fullpath
, X_OK
) == -1)
284 snprintf(fullpath
, sizeof(fullpath
), "%s%cbin%cssld%s",
285 ConfigFileEntry
.dpath
, RB_PATH_SEPARATOR
, RB_PATH_SEPARATOR
, suffix
);
286 if(access(fullpath
, X_OK
) == -1)
289 "Unable to execute ssld%s in %s or %s/bin",
290 suffix
, ircd_paths
[IRCD_PATH_LIBEXEC
], ConfigFileEntry
.dpath
);
294 ssld_path
= rb_strdup(fullpath
);
296 rb_strlcpy(buf
, "-ircd ssld daemon", sizeof(buf
));
300 for(i
= 0; i
< count
; i
++)
303 if(rb_socketpair(AF_UNIX
, SOCK_DGRAM
, 0, &F1
, &F2
, "SSL/TLS handle passing socket") == -1)
305 ilog(L_MAIN
, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno
));
309 rb_set_buffers(F1
, READBUF_SIZE
);
310 rb_set_buffers(F2
, READBUF_SIZE
);
311 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(F2
));
312 rb_setenv("CTL_FD", fdarg
, 1);
313 if(rb_pipe(&P1
, &P2
, "SSL/TLS pipe") == -1)
315 ilog(L_MAIN
, "Unable to create ssld - rb_pipe failed: %s", strerror(errno
));
318 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(P1
));
319 rb_setenv("CTL_PIPE", fdarg
, 1);
320 snprintf(s_pid
, sizeof(s_pid
), "%d", (int)getpid());
321 rb_setenv("CTL_PPID", s_pid
, 1);
323 SetHandleInformation((HANDLE
) rb_get_fd(F2
), HANDLE_FLAG_INHERIT
, 1);
324 SetHandleInformation((HANDLE
) rb_get_fd(P1
), HANDLE_FLAG_INHERIT
, 1);
327 pid
= rb_spawn_process(ssld_path
, (const char **) parv
);
330 ilog(L_MAIN
, "Unable to create ssld: %s\n", strerror(errno
));
340 ctl
= allocate_ssl_daemon(F1
, P2
, pid
);
343 send_certfp_method(ctl
, ConfigFileEntry
.certfp_method
);
345 if(ssl_cert
!= NULL
&& ssl_private_key
!= NULL
)
346 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
,
347 ssl_dh_params
, ssl_cipher_list
);
349 ssl_read_ctl(ctl
->F
, ctl
);
350 ssl_do_pipe(P2
, ctl
);
357 ssl_process_zipstats(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
359 struct Client
*server
;
360 struct ZipStats
*zips
;
362 (void) rb_string_to_array(ctl_buf
->buf
, parv
, 6);
363 server
= find_server(NULL
, parv
[1]);
364 if(server
== NULL
|| server
->localClient
== NULL
|| !IsCapable(server
, CAP_ZIP
))
366 if(server
->localClient
->zipstats
== NULL
)
367 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
369 zips
= server
->localClient
->zipstats
;
371 zips
->in
+= strtoull(parv
[2], NULL
, 10);
372 zips
->in_wire
+= strtoull(parv
[3], NULL
, 10);
373 zips
->out
+= strtoull(parv
[4], NULL
, 10);
374 zips
->out_wire
+= strtoull(parv
[5], NULL
, 10);
377 zips
->in_ratio
= ((double) (zips
->in
- zips
->in_wire
) / (double) zips
->in
) * 100.00;
382 zips
->out_ratio
= ((double) (zips
->out
- zips
->out_wire
) / (double) zips
->out
) * 100.00;
388 ssl_process_open_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
390 struct Client
*client_p
;
393 if(ctl_buf
->buflen
< 5)
394 return; /* bogus message..drop it.. XXX should warn here */
396 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
397 client_p
= find_cli_connid_hash(fd
);
398 if(client_p
== NULL
|| client_p
->localClient
== NULL
)
401 if(client_p
->localClient
->ssl_callback
)
403 CNCB
*hdl
= client_p
->localClient
->ssl_callback
;
404 void *data
= client_p
->localClient
->ssl_data
;
406 client_p
->localClient
->ssl_callback
= NULL
;
407 client_p
->localClient
->ssl_data
= NULL
;
409 hdl(client_p
->localClient
->F
, RB_OK
, data
);
414 ssl_process_dead_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
416 struct Client
*client_p
;
420 if(ctl_buf
->buflen
< 6)
421 return; /* bogus message..drop it.. XXX should warn here */
423 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
424 rb_strlcpy(reason
, &ctl_buf
->buf
[5], sizeof(reason
));
425 client_p
= find_cli_connid_hash(fd
);
426 if(client_p
== NULL
|| client_p
->localClient
== NULL
)
429 if(IsAnyServer(client_p
))
431 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
);
432 ilog(L_SERVER
, "ssld error for %s: %s", log_client_name(client_p
, SHOW_IP
), reason
);
435 /* if there is still a pending callback, call it now */
436 if(client_p
->localClient
->ssl_callback
)
438 CNCB
*hdl
= client_p
->localClient
->ssl_callback
;
439 void *data
= client_p
->localClient
->ssl_data
;
441 client_p
->localClient
->ssl_callback
= NULL
;
442 client_p
->localClient
->ssl_data
= NULL
;
444 hdl(client_p
->localClient
->F
, RB_ERROR_SSL
, data
);
446 /* the callback should have exited the client */
450 if(IsAnyServer(client_p
) || IsRegistered(client_p
))
452 /* read any last moment ERROR, QUIT or the like -- jilles */
453 if (!strcmp(reason
, "Remote host closed the connection"))
454 read_packet(client_p
->localClient
->F
, client_p
);
455 if (IsAnyDead(client_p
))
458 exit_client(client_p
, client_p
, &me
, reason
);
463 ssl_process_cipher_string(ssl_ctl_t
*ctl
, ssl_ctl_buf_t
*ctl_buf
)
465 struct Client
*client_p
;
469 if(ctl_buf
->buflen
< 6)
470 return; /* bogus message..drop it.. XXX should warn here */
472 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
473 cstring
= (const char *)&ctl_buf
->buf
[5];
475 if(EmptyString(cstring
))
478 client_p
= find_cli_connid_hash(fd
);
479 if(client_p
!= NULL
&& client_p
->localClient
!= NULL
)
481 rb_free(client_p
->localClient
->cipher_string
);
482 client_p
->localClient
->cipher_string
= rb_strdup(cstring
);
488 ssl_process_certfp(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
490 struct Client
*client_p
;
496 if(ctl_buf
->buflen
> 9 + RB_SSL_CERTFP_LEN
)
497 return; /* bogus message..drop it.. XXX should warn here */
499 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
500 len
= buf_to_uint32(&ctl_buf
->buf
[5]);
501 certfp
= (uint8_t *)&ctl_buf
->buf
[9];
502 client_p
= find_cli_connid_hash(fd
);
505 rb_free(client_p
->certfp
);
506 certfp_string
= rb_malloc(len
* 2 + 1);
507 for(uint32_t i
= 0; i
< len
; i
++)
508 snprintf(certfp_string
+ 2 * i
, 3, "%02x",
510 client_p
->certfp
= certfp_string
;
514 ssl_process_cmd_recv(ssl_ctl_t
* ctl
)
516 static const char *cannot_setup_ssl
= "ssld cannot setup ssl, check your certificates and private key";
517 static const char *no_ssl_or_zlib
= "ssld has neither SSL/TLS or zlib support killing all sslds";
518 rb_dlink_node
*ptr
, *next
;
519 ssl_ctl_buf_t
*ctl_buf
;
525 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->readq
.head
)
528 switch (*ctl_buf
->buf
)
531 ircd_ssl_ok
= false; /* ssld says it can't do ssl/tls */
534 ssl_process_open_fd(ctl
, ctl_buf
);
537 ssl_process_dead_fd(ctl
, ctl_buf
);
540 ssl_process_cipher_string(ctl
, ctl_buf
);
543 ssl_process_certfp(ctl
, ctl_buf
);
546 ssl_process_zipstats(ctl
, ctl_buf
);
550 ilog(L_MAIN
, "%s", cannot_setup_ssl
);
551 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", cannot_setup_ssl
);
556 ilog(L_MAIN
, "%s", no_ssl_or_zlib
);
557 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", no_ssl_or_zlib
);
561 len
= ctl_buf
->buflen
- 1;
562 if (len
> sizeof(ctl
->version
) - 1)
563 len
= sizeof(ctl
->version
) - 1;
564 strncpy(ctl
->version
, &ctl_buf
->buf
[1], len
);
569 ilog(L_MAIN
, "Received invalid command from ssld: %s", ctl_buf
->buf
);
570 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Received invalid command from ssld");
573 rb_dlinkDelete(ptr
, &ctl
->readq
);
574 rb_free(ctl_buf
->buf
);
582 ssl_read_ctl(rb_fde_t
* F
, void *data
)
584 ssl_ctl_buf_t
*ctl_buf
;
585 ssl_ctl_t
*ctl
= data
;
592 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
593 ctl_buf
->buf
= rb_malloc(READSIZE
);
594 retlen
= rb_recv_fd_buf(ctl
->F
, ctl_buf
->buf
, READSIZE
, ctl_buf
->F
, 4);
595 ctl_buf
->buflen
= retlen
;
598 rb_free(ctl_buf
->buf
);
602 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->readq
);
606 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
611 ssl_process_cmd_recv(ctl
);
612 rb_setselect(ctl
->F
, RB_SELECT_READ
, ssl_read_ctl
, ctl
);
618 ssl_ctl_t
*ctl
, *lowest
= NULL
;
621 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
633 if(ctl
->cli_count
< lowest
->cli_count
)
640 ssl_write_ctl(rb_fde_t
* F
, void *data
)
642 ssl_ctl_t
*ctl
= data
;
643 ssl_ctl_buf_t
*ctl_buf
;
644 rb_dlink_node
*ptr
, *next
;
650 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->writeq
.head
)
653 /* in theory unix sock_dgram shouldn't ever short write this.. */
654 retlen
= rb_send_fd_buf(ctl
->F
, ctl_buf
->F
, ctl_buf
->nfds
, ctl_buf
->buf
, ctl_buf
->buflen
, ctl
->pid
);
657 rb_dlinkDelete(ptr
, &ctl
->writeq
);
658 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
659 rb_close(ctl_buf
->F
[x
]);
660 rb_free(ctl_buf
->buf
);
664 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
671 rb_setselect(ctl
->F
, RB_SELECT_WRITE
, ssl_write_ctl
, ctl
);
677 ssl_cmd_write_queue(ssl_ctl_t
* ctl
, rb_fde_t
** F
, int count
, const void *buf
, size_t buflen
)
679 ssl_ctl_buf_t
*ctl_buf
;
686 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
687 ctl_buf
->buf
= rb_malloc(buflen
);
688 memcpy(ctl_buf
->buf
, buf
, buflen
);
689 ctl_buf
->buflen
= buflen
;
691 for(x
= 0; x
< count
&& x
< MAXPASSFD
; x
++)
693 ctl_buf
->F
[x
] = F
[x
];
695 ctl_buf
->nfds
= count
;
696 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->writeq
);
697 ssl_write_ctl(ctl
->F
, ctl
);
702 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
)
706 len
= strlen(ssl_cert
) + strlen(ssl_private_key
) + 5;
708 len
+= strlen(ssl_dh_params
);
710 len
+= strlen(ssl_cipher_list
);
711 if(len
> sizeof(tmpbuf
))
713 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
714 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
715 len
, sizeof(tmpbuf
));
717 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
718 len
, sizeof(tmpbuf
));
721 len
= snprintf(tmpbuf
, sizeof(tmpbuf
), "K%c%s%c%s%c%s%c%s%c", nul
, ssl_cert
, nul
,
722 ssl_private_key
, nul
, ssl_dh_params
!= NULL
? ssl_dh_params
: "", nul
,
723 ssl_cipher_list
!= NULL
? ssl_cipher_list
: "", nul
);
724 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, len
);
728 send_certfp_method(ssl_ctl_t
*ctl
, int method
)
733 uint32_to_buf(&buf
[1], method
);
734 ssl_cmd_write_queue(ctl
, NULL
, 0, buf
, sizeof(buf
));
738 send_new_ssl_certs(const char *ssl_cert
, const char *ssl_private_key
, const char *ssl_dh_params
, const char *ssl_cipher_list
)
741 if(ssl_cert
== NULL
|| ssl_private_key
== NULL
|| ssl_dh_params
== NULL
)
746 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
748 ssl_ctl_t
*ctl
= ptr
->data
;
749 send_new_ssl_certs_one(ctl
, ssl_cert
, ssl_private_key
, ssl_dh_params
, ssl_cipher_list
);
755 start_ssld_accept(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
764 uint32_to_buf(&buf
[1], id
);
769 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
774 start_ssld_connect(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
783 uint32_to_buf(&buf
[1], id
);
789 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
794 ssld_decrement_clicount(ssl_ctl_t
* ctl
)
800 if(ctl
->shutdown
&& !ctl
->cli_count
)
803 rb_kill(ctl
->pid
, SIGKILL
);
805 if(ctl
->dead
&& !ctl
->cli_count
)
807 free_ssl_daemon(ctl
);
812 * what we end up sending to the ssld process for ziplinks is the following
813 * Z[ourfd][level][RECVQ]
814 * Z = ziplinks command = buf[0]
815 * ourfd = Our end of the socketpair = buf[1..4]
816 * level = zip level buf[5]
817 * recvqlen = our recvq len = buf[6-7]
818 * recvq = any data we read prior to starting ziplinks
821 start_zlib_session(void *data
)
823 struct Client
*server
= (struct Client
*) data
;
833 size_t hdr
= (sizeof(uint8_t) * 2) + sizeof(uint32_t);
837 server
->localClient
->event
= NULL
;
839 recvqlen
= rb_linebuf_len(&server
->localClient
->buf_recvq
);
841 len
= recvqlen
+ hdr
;
843 if(len
> READBUF_SIZE
)
845 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
846 "ssld - attempted to pass message of %zd len, max len %d, giving up",
848 ilog(L_MAIN
, "ssld - attempted to pass message of %zd len, max len %d, giving up", len
, READBUF_SIZE
);
849 exit_client(server
, server
, server
, "ssld readbuf exceeded");
853 buf
= rb_malloc(len
);
854 level
= ConfigFileEntry
.compression_level
;
856 uint32_to_buf(&buf
[1], rb_get_fd(server
->localClient
->F
));
857 buf
[5] = (char) level
;
859 recvq_start
= &buf
[6];
860 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
867 cpylen
= rb_linebuf_get(&server
->localClient
->buf_recvq
, xbuf
, left
, LINEBUF_PARTIAL
, LINEBUF_RAW
);
869 xbuf
= (void *) (((uintptr_t) xbuf
) + cpylen
);
873 /* Pass the socket to ssld. */
875 if(rb_socketpair(AF_UNIX
, SOCK_STREAM
, 0, &xF1
, &xF2
, "Initial zlib socketpairs") == -1)
877 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Error creating zlib socketpair - %s", strerror(errno
));
878 ilog(L_MAIN
, "Error creating zlib socketpairs - %s", strerror(errno
));
879 exit_client(server
, server
, server
, "Error creating zlib socketpair");
884 F
[0] = server
->localClient
->F
;
886 server
->localClient
->F
= xF2
;
887 /* need to redo as what we did before isn't valid now */
888 uint32_to_buf(&buf
[1], connid_get(server
));
890 server
->localClient
->z_ctl
= which_ssld();
891 if(!server
->localClient
->z_ctl
)
893 exit_client(server
, server
, server
, "Error finding available ssld");
897 server
->localClient
->z_ctl
->cli_count
++;
898 ssl_cmd_write_queue(server
->localClient
->z_ctl
, F
, 2, buf
, len
);
903 collect_zipstats(void *unused
)
906 struct Client
*target_p
;
907 char buf
[sizeof(uint8_t) + sizeof(uint32_t) + HOSTLEN
];
913 odata
= buf
+ sizeof(uint8_t) + sizeof(uint32_t);
915 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
917 target_p
= ptr
->data
;
918 if(IsCapable(target_p
, CAP_ZIP
))
920 len
= sizeof(uint8_t) + sizeof(uint32_t);
922 id
= rb_get_fd(target_p
->localClient
->F
);
923 uint32_to_buf(&buf
[1], id
);
924 rb_strlcpy(odata
, target_p
->name
, (sizeof(buf
) - len
));
925 len
+= strlen(odata
) + 1; /* Get the \0 as well */
926 ssl_cmd_write_queue(target_p
->localClient
->z_ctl
, NULL
, 0, buf
, len
);
932 cleanup_dead_ssl(void *unused
)
934 rb_dlink_node
*ptr
, *next
;
936 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
939 if(ctl
->dead
&& !ctl
->cli_count
)
941 free_ssl_daemon(ctl
);
953 ssld_foreach_info(void (*func
)(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
), void *data
)
955 rb_dlink_node
*ptr
, *next
;
957 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
960 func(data
, ctl
->pid
, ctl
->cli_count
,
961 ctl
->dead
? SSLD_DEAD
:
962 (ctl
->shutdown
? SSLD_SHUTDOWN
: SSLD_ACTIVE
),
970 rb_event_addish("collect_zipstats", collect_zipstats
, NULL
, ZIPSTATS_TIME
);
971 rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl
, NULL
, 60);