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
38 #define ZIPSTATS_TIME 60
40 static void collect_zipstats(void *unused
);
41 static void ssl_read_ctl(rb_fde_t
* F
, void *data
);
42 static int ssld_count
;
44 static char tmpbuf
[READBUF_SIZE
];
45 static char nul
= '\0';
49 typedef struct _ssl_ctl_buf
54 rb_fde_t
*F
[MAXPASSFD
];
73 static void ssld_update_config_one(ssl_ctl_t
*ctl
);
74 static void send_new_ssl_certs_one(ssl_ctl_t
* ctl
);
75 static void send_certfp_method(ssl_ctl_t
*ctl
);
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
);
177 start_ssldaemon(ServerInfo
.ssld_count
);
183 rb_dlink_node
*ptr
, *next
;
185 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
193 rb_kill(ctl
->pid
, SIGKILL
);
195 free_ssl_daemon(ctl
);
200 ssl_dead(ssl_ctl_t
* ctl
)
206 rb_kill(ctl
->pid
, SIGKILL
); /* make sure the process is really gone */
211 ilog(L_MAIN
, "ssld helper died - attempting to restart");
212 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "ssld helper died - attempting to restart");
218 ssl_do_pipe(rb_fde_t
* F
, void *data
)
221 ssl_ctl_t
*ctl
= data
;
222 retlen
= rb_write(F
, "0", 1);
223 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
228 rb_setselect(F
, RB_SELECT_READ
, ssl_do_pipe
, data
);
232 restart_ssld_event(void *unused
)
237 if(ServerInfo
.ssld_count
> get_ssld_count())
239 int start
= ServerInfo
.ssld_count
- get_ssld_count();
240 ilog(L_MAIN
, "Attempting to restart ssld processes");
241 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Attempt to restart ssld processes");
242 start_ssldaemon(start
);
247 start_ssldaemon(int count
)
252 const char *suffix
= ".exe";
254 const char *suffix
= "";
257 char fullpath
[PATH_MAX
+ 1];
268 if(ssld_spin_count
> 20 && (rb_current_time() - last_spin
< 5))
270 ilog(L_MAIN
, "ssld helper is spinning - will attempt to restart in 1 minute");
271 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
272 "ssld helper is spinning - will attempt to restart in 1 minute");
273 rb_event_add("restart_ssld_event", restart_ssld_event
, NULL
, 60);
279 last_spin
= rb_current_time();
281 if(ssld_path
== NULL
)
283 snprintf(fullpath
, sizeof(fullpath
), "%s%cssld%s", ircd_paths
[IRCD_PATH_LIBEXEC
], RB_PATH_SEPARATOR
, suffix
);
285 if(access(fullpath
, X_OK
) == -1)
287 snprintf(fullpath
, sizeof(fullpath
), "%s%cbin%cssld%s",
288 ConfigFileEntry
.dpath
, RB_PATH_SEPARATOR
, RB_PATH_SEPARATOR
, suffix
);
289 if(access(fullpath
, X_OK
) == -1)
292 "Unable to execute ssld%s in %s or %s/bin",
293 suffix
, ircd_paths
[IRCD_PATH_LIBEXEC
], ConfigFileEntry
.dpath
);
297 ssld_path
= rb_strdup(fullpath
);
299 rb_strlcpy(buf
, "-ircd ssld daemon", sizeof(buf
));
303 for(i
= 0; i
< count
; i
++)
306 if(rb_socketpair(AF_UNIX
, SOCK_DGRAM
, 0, &F1
, &F2
, "SSL/TLS handle passing socket") == -1)
308 ilog(L_MAIN
, "Unable to create ssld - rb_socketpair failed: %s", strerror(errno
));
312 rb_set_buffers(F1
, READBUF_SIZE
);
313 rb_set_buffers(F2
, READBUF_SIZE
);
314 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(F2
));
315 rb_setenv("CTL_FD", fdarg
, 1);
316 if(rb_pipe(&P1
, &P2
, "SSL/TLS pipe") == -1)
318 ilog(L_MAIN
, "Unable to create ssld - rb_pipe failed: %s", strerror(errno
));
321 snprintf(fdarg
, sizeof(fdarg
), "%d", rb_get_fd(P1
));
322 rb_setenv("CTL_PIPE", fdarg
, 1);
323 snprintf(s_pid
, sizeof(s_pid
), "%d", (int)getpid());
324 rb_setenv("CTL_PPID", s_pid
, 1);
326 SetHandleInformation((HANDLE
) rb_get_fd(F2
), HANDLE_FLAG_INHERIT
, 1);
327 SetHandleInformation((HANDLE
) rb_get_fd(P1
), HANDLE_FLAG_INHERIT
, 1);
330 pid
= rb_spawn_process(ssld_path
, (const char **) parv
);
333 ilog(L_MAIN
, "Unable to create ssld: %s\n", strerror(errno
));
343 ctl
= allocate_ssl_daemon(F1
, P2
, pid
);
345 ssld_update_config_one(ctl
);
346 ssl_read_ctl(ctl
->F
, ctl
);
347 ssl_do_pipe(P2
, ctl
);
354 ssl_process_zipstats(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
356 struct Client
*server
;
357 struct ZipStats
*zips
;
359 int parc
= rb_string_to_array(ctl_buf
->buf
, parv
, sizeof(parv
));
361 if (parc
< sizeof(parv
))
364 server
= find_server(NULL
, parv
[1]);
365 if(server
== NULL
|| server
->localClient
== NULL
|| !IsCapable(server
, CAP_ZIP
))
367 if(server
->localClient
->zipstats
== NULL
)
368 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
370 zips
= server
->localClient
->zipstats
;
372 zips
->in
+= strtoull(parv
[2], NULL
, 10);
373 zips
->in_wire
+= strtoull(parv
[3], NULL
, 10);
374 zips
->out
+= strtoull(parv
[4], NULL
, 10);
375 zips
->out_wire
+= strtoull(parv
[5], NULL
, 10);
378 zips
->in_ratio
= ((double) (zips
->in
- zips
->in_wire
) / (double) zips
->in
) * 100.00;
383 zips
->out_ratio
= ((double) (zips
->out
- zips
->out_wire
) / (double) zips
->out
) * 100.00;
389 ssl_process_open_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
391 struct Client
*client_p
;
394 if(ctl_buf
->buflen
< 5)
395 return; /* bogus message..drop it.. XXX should warn here */
397 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
398 client_p
= find_cli_connid_hash(fd
);
399 if(client_p
== NULL
|| client_p
->localClient
== NULL
)
402 if(client_p
->localClient
->ssl_callback
)
404 SSL_OPEN_CB
*hdl
= client_p
->localClient
->ssl_callback
;
406 client_p
->localClient
->ssl_callback
= NULL
;
408 hdl(client_p
, RB_OK
);
413 ssl_process_dead_fd(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
415 struct Client
*client_p
;
419 if(ctl_buf
->buflen
< 6)
420 return; /* bogus message..drop it.. XXX should warn here */
422 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
423 rb_strlcpy(reason
, &ctl_buf
->buf
[5], sizeof(reason
));
424 client_p
= find_cli_connid_hash(fd
);
425 if(client_p
== NULL
|| client_p
->localClient
== NULL
)
428 if(IsAnyServer(client_p
))
430 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
);
431 ilog(L_SERVER
, "ssld error for %s: %s", log_client_name(client_p
, SHOW_IP
), reason
);
434 /* if there is still a pending callback, call it now */
435 if(client_p
->localClient
->ssl_callback
)
437 SSL_OPEN_CB
*hdl
= client_p
->localClient
->ssl_callback
;
439 client_p
->localClient
->ssl_callback
= NULL
;
441 if (hdl(client_p
, RB_ERROR_SSL
))
443 /* the callback has exited the client */
448 if(IsAnyServer(client_p
) || IsRegistered(client_p
))
450 /* read any last moment ERROR, QUIT or the like -- jilles */
451 if (!strcmp(reason
, "Remote host closed the connection"))
452 read_packet(client_p
->localClient
->F
, client_p
);
453 if (IsAnyDead(client_p
))
456 exit_client(client_p
, client_p
, &me
, reason
);
461 ssl_process_cipher_string(ssl_ctl_t
*ctl
, ssl_ctl_buf_t
*ctl_buf
)
463 struct Client
*client_p
;
467 if(ctl_buf
->buflen
< 6)
468 return; /* bogus message..drop it.. XXX should warn here */
470 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
471 cstring
= (const char *)&ctl_buf
->buf
[5];
473 if(EmptyString(cstring
))
476 client_p
= find_cli_connid_hash(fd
);
477 if(client_p
!= NULL
&& client_p
->localClient
!= NULL
)
479 rb_free(client_p
->localClient
->cipher_string
);
480 client_p
->localClient
->cipher_string
= rb_strdup(cstring
);
486 ssl_process_certfp(ssl_ctl_t
* ctl
, ssl_ctl_buf_t
* ctl_buf
)
488 struct Client
*client_p
;
490 uint32_t certfp_method
;
494 const char *method_string
;
497 if(ctl_buf
->buflen
> 13 + RB_SSL_CERTFP_LEN
)
498 return; /* bogus message..drop it.. XXX should warn here */
500 fd
= buf_to_uint32(&ctl_buf
->buf
[1]);
501 certfp_method
= buf_to_uint32(&ctl_buf
->buf
[5]);
502 len
= buf_to_uint32(&ctl_buf
->buf
[9]);
503 certfp
= (uint8_t *)&ctl_buf
->buf
[13];
504 client_p
= find_cli_connid_hash(fd
);
508 switch (certfp_method
) {
509 case RB_SSL_CERTFP_METH_CERT_SHA1
:
510 method_string
= CERTFP_PREFIX_CERT_SHA1
;
512 case RB_SSL_CERTFP_METH_CERT_SHA256
:
513 method_string
= CERTFP_PREFIX_CERT_SHA256
;
515 case RB_SSL_CERTFP_METH_CERT_SHA512
:
516 method_string
= CERTFP_PREFIX_CERT_SHA512
;
518 case RB_SSL_CERTFP_METH_SPKI_SHA256
:
519 method_string
= CERTFP_PREFIX_SPKI_SHA256
;
521 case RB_SSL_CERTFP_METH_SPKI_SHA512
:
522 method_string
= CERTFP_PREFIX_SPKI_SHA512
;
527 method_len
= strlen(method_string
);
529 rb_free(client_p
->certfp
);
530 certfp_string
= rb_malloc(method_len
+ len
* 2 + 1);
531 rb_strlcpy(certfp_string
, method_string
, method_len
+ len
* 2 + 1);
532 for(uint32_t i
= 0; i
< len
; i
++)
533 snprintf(certfp_string
+ method_len
+ 2 * i
, 3, "%02x",
535 client_p
->certfp
= certfp_string
;
539 ssl_process_cmd_recv(ssl_ctl_t
* ctl
)
541 static const char *cannot_setup_ssl
= "ssld cannot setup ssl, check your certificates and private key";
542 static const char *no_ssl_or_zlib
= "ssld has neither SSL/TLS or zlib support killing all sslds";
543 rb_dlink_node
*ptr
, *next
;
544 ssl_ctl_buf_t
*ctl_buf
;
550 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->readq
.head
)
553 switch (*ctl_buf
->buf
)
556 ircd_ssl_ok
= false; /* ssld says it can't do ssl/tls */
559 ssl_process_open_fd(ctl
, ctl_buf
);
562 ssl_process_dead_fd(ctl
, ctl_buf
);
565 ssl_process_cipher_string(ctl
, ctl_buf
);
568 ssl_process_certfp(ctl
, ctl_buf
);
571 ssl_process_zipstats(ctl
, ctl_buf
);
575 ilog(L_MAIN
, "%s", cannot_setup_ssl
);
576 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", cannot_setup_ssl
);
581 ilog(L_MAIN
, "%s", no_ssl_or_zlib
);
582 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "%s", no_ssl_or_zlib
);
586 len
= ctl_buf
->buflen
- 1;
587 if (len
> sizeof(ctl
->version
) - 1)
588 len
= sizeof(ctl
->version
) - 1;
589 strncpy(ctl
->version
, &ctl_buf
->buf
[1], len
);
594 ilog(L_MAIN
, "Received invalid command from ssld: %s", ctl_buf
->buf
);
595 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Received invalid command from ssld");
598 rb_dlinkDelete(ptr
, &ctl
->readq
);
599 rb_free(ctl_buf
->buf
);
607 ssl_read_ctl(rb_fde_t
* F
, void *data
)
609 ssl_ctl_buf_t
*ctl_buf
;
610 ssl_ctl_t
*ctl
= data
;
617 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
618 ctl_buf
->buf
= rb_malloc(READSIZE
);
619 retlen
= rb_recv_fd_buf(ctl
->F
, ctl_buf
->buf
, READSIZE
, ctl_buf
->F
, 4);
620 ctl_buf
->buflen
= retlen
;
623 rb_free(ctl_buf
->buf
);
627 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->readq
);
631 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
636 ssl_process_cmd_recv(ctl
);
637 rb_setselect(ctl
->F
, RB_SELECT_READ
, ssl_read_ctl
, ctl
);
643 ssl_ctl_t
*ctl
, *lowest
= NULL
;
646 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
658 if(ctl
->cli_count
< lowest
->cli_count
)
665 ssl_write_ctl(rb_fde_t
* F
, void *data
)
667 ssl_ctl_t
*ctl
= data
;
668 ssl_ctl_buf_t
*ctl_buf
;
669 rb_dlink_node
*ptr
, *next
;
675 RB_DLINK_FOREACH_SAFE(ptr
, next
, ctl
->writeq
.head
)
678 /* in theory unix sock_dgram shouldn't ever short write this.. */
679 retlen
= rb_send_fd_buf(ctl
->F
, ctl_buf
->F
, ctl_buf
->nfds
, ctl_buf
->buf
, ctl_buf
->buflen
, ctl
->pid
);
682 rb_dlinkDelete(ptr
, &ctl
->writeq
);
683 for(x
= 0; x
< ctl_buf
->nfds
; x
++)
684 rb_close(ctl_buf
->F
[x
]);
685 rb_free(ctl_buf
->buf
);
689 if(retlen
== 0 || (retlen
< 0 && !rb_ignore_errno(errno
)))
696 rb_setselect(ctl
->F
, RB_SELECT_WRITE
, ssl_write_ctl
, ctl
);
702 ssl_cmd_write_queue(ssl_ctl_t
* ctl
, rb_fde_t
** F
, int count
, const void *buf
, size_t buflen
)
704 ssl_ctl_buf_t
*ctl_buf
;
711 ctl_buf
= rb_malloc(sizeof(ssl_ctl_buf_t
));
712 ctl_buf
->buf
= rb_malloc(buflen
);
713 memcpy(ctl_buf
->buf
, buf
, buflen
);
714 ctl_buf
->buflen
= buflen
;
716 for(x
= 0; x
< count
&& x
< MAXPASSFD
; x
++)
718 ctl_buf
->F
[x
] = F
[x
];
720 ctl_buf
->nfds
= count
;
721 rb_dlinkAddTail(ctl_buf
, &ctl_buf
->node
, &ctl
->writeq
);
722 ssl_write_ctl(ctl
->F
, ctl
);
727 send_new_ssl_certs_one(ssl_ctl_t
* ctl
)
731 if(ServerInfo
.ssl_cert
)
732 len
+= strlen(ServerInfo
.ssl_cert
);
736 if(ServerInfo
.ssl_private_key
)
737 len
+= strlen(ServerInfo
.ssl_private_key
);
739 if(ServerInfo
.ssl_dh_params
)
740 len
+= strlen(ServerInfo
.ssl_dh_params
);
742 if(ServerInfo
.ssl_cipher_list
)
743 len
+= strlen(ServerInfo
.ssl_cipher_list
);
745 if(len
> sizeof(tmpbuf
))
747 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
748 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
749 len
, sizeof(tmpbuf
));
751 "Parameters for send_new_ssl_certs_one too long (%zu > %zu) to pass to ssld, not sending...",
752 len
, sizeof(tmpbuf
));
756 int ret
= snprintf(tmpbuf
, sizeof(tmpbuf
), "K%c%s%c%s%c%s%c%s%c", nul
,
757 ServerInfo
.ssl_cert
, nul
,
758 ServerInfo
.ssl_private_key
!= NULL
? ServerInfo
.ssl_private_key
: "", nul
,
759 ServerInfo
.ssl_dh_params
!= NULL
? ServerInfo
.ssl_dh_params
: "", nul
,
760 ServerInfo
.ssl_cipher_list
!= NULL
? ServerInfo
.ssl_cipher_list
: "", nul
);
763 ssl_cmd_write_queue(ctl
, NULL
, 0, tmpbuf
, (size_t) ret
);
767 send_certfp_method(ssl_ctl_t
*ctl
)
772 uint32_to_buf(&buf
[1], ConfigFileEntry
.certfp_method
);
773 ssl_cmd_write_queue(ctl
, NULL
, 0, buf
, sizeof(buf
));
777 ssld_update_config_one(ssl_ctl_t
*ctl
)
779 send_certfp_method(ctl
);
780 send_new_ssl_certs_one(ctl
);
784 ssld_update_config(void)
788 RB_DLINK_FOREACH(ptr
, ssl_daemons
.head
)
790 ssl_ctl_t
*ctl
= ptr
->data
;
792 if (ctl
->dead
|| ctl
->shutdown
)
795 ssld_update_config_one(ctl
);
800 start_ssld_accept(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
809 uint32_to_buf(&buf
[1], id
);
814 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
819 start_ssld_connect(rb_fde_t
* sslF
, rb_fde_t
* plainF
, uint32_t id
)
828 uint32_to_buf(&buf
[1], id
);
834 ssl_cmd_write_queue(ctl
, F
, 2, buf
, sizeof(buf
));
839 ssld_decrement_clicount(ssl_ctl_t
* ctl
)
845 if(ctl
->shutdown
&& !ctl
->cli_count
)
848 rb_kill(ctl
->pid
, SIGKILL
);
850 if(ctl
->dead
&& !ctl
->cli_count
)
852 free_ssl_daemon(ctl
);
857 * what we end up sending to the ssld process for ziplinks is the following
858 * Z[ourfd][level][RECVQ]
859 * Z = ziplinks command = buf[0]
860 * ourfd = Our end of the socketpair = buf[1..4]
861 * level = zip level buf[5]
862 * recvqlen = our recvq len = buf[6-7]
863 * recvq = any data we read prior to starting ziplinks
866 start_zlib_session(void *data
)
868 struct Client
*server
= (struct Client
*) data
;
878 size_t hdr
= (sizeof(uint8_t) * 2) + sizeof(uint32_t);
882 server
->localClient
->event
= NULL
;
884 recvqlen
= rb_linebuf_len(&server
->localClient
->buf_recvq
);
886 len
= recvqlen
+ hdr
;
888 if(len
> READBUF_SIZE
)
890 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
891 "ssld - attempted to pass message of %zd len, max len %d, giving up",
893 ilog(L_MAIN
, "ssld - attempted to pass message of %zd len, max len %d, giving up", len
, READBUF_SIZE
);
894 exit_client(server
, server
, server
, "ssld readbuf exceeded");
898 buf
= rb_malloc(len
);
899 level
= ConfigFileEntry
.compression_level
;
901 uint32_to_buf(&buf
[1], rb_get_fd(server
->localClient
->F
));
902 buf
[5] = (char) level
;
904 recvq_start
= &buf
[6];
905 server
->localClient
->zipstats
= rb_malloc(sizeof(struct ZipStats
));
912 cpylen
= rb_linebuf_get(&server
->localClient
->buf_recvq
, xbuf
, left
, LINEBUF_PARTIAL
, LINEBUF_RAW
);
914 xbuf
= (void *) (((uintptr_t) xbuf
) + cpylen
);
918 /* Pass the socket to ssld. */
920 if(rb_socketpair(AF_UNIX
, SOCK_STREAM
, 0, &xF1
, &xF2
, "Initial zlib socketpairs") == -1)
922 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Error creating zlib socketpair - %s", strerror(errno
));
923 ilog(L_MAIN
, "Error creating zlib socketpairs - %s", strerror(errno
));
924 exit_client(server
, server
, server
, "Error creating zlib socketpair");
929 F
[0] = server
->localClient
->F
;
931 server
->localClient
->F
= xF2
;
932 /* need to redo as what we did before isn't valid now */
933 uint32_to_buf(&buf
[1], connid_get(server
));
935 server
->localClient
->z_ctl
= which_ssld();
936 if(!server
->localClient
->z_ctl
)
938 exit_client(server
, server
, server
, "Error finding available ssld");
942 server
->localClient
->z_ctl
->cli_count
++;
943 ssl_cmd_write_queue(server
->localClient
->z_ctl
, F
, 2, buf
, len
);
948 collect_zipstats(void *unused
)
951 struct Client
*target_p
;
952 char buf
[sizeof(uint8_t) + sizeof(uint32_t) + HOSTLEN
];
958 odata
= buf
+ sizeof(uint8_t) + sizeof(uint32_t);
960 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
962 target_p
= ptr
->data
;
963 if(IsCapable(target_p
, CAP_ZIP
))
965 len
= sizeof(uint8_t) + sizeof(uint32_t);
967 id
= rb_get_fd(target_p
->localClient
->F
);
968 uint32_to_buf(&buf
[1], id
);
969 rb_strlcpy(odata
, target_p
->name
, (sizeof(buf
) - len
));
970 len
+= strlen(odata
) + 1; /* Get the \0 as well */
971 ssl_cmd_write_queue(target_p
->localClient
->z_ctl
, NULL
, 0, buf
, len
);
977 cleanup_dead_ssl(void *unused
)
979 rb_dlink_node
*ptr
, *next
;
981 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
984 if(ctl
->dead
&& !ctl
->cli_count
)
986 free_ssl_daemon(ctl
);
998 ssld_foreach_info(void (*func
)(void *data
, pid_t pid
, int cli_count
, enum ssld_status status
, const char *version
), void *data
)
1000 rb_dlink_node
*ptr
, *next
;
1002 RB_DLINK_FOREACH_SAFE(ptr
, next
, ssl_daemons
.head
)
1005 func(data
, ctl
->pid
, ctl
->cli_count
,
1006 ctl
->dead
? SSLD_DEAD
:
1007 (ctl
->shutdown
? SSLD_SHUTDOWN
: SSLD_ACTIVE
),
1015 rb_event_addish("collect_zipstats", collect_zipstats
, NULL
, ZIPSTATS_TIME
);
1016 rb_event_addish("cleanup_dead_ssld", cleanup_dead_ssl
, NULL
, 60);