1 /*
2  * h_ccc.c
3  *
4  * (C)1998-2011 by Marc Huber <Marc.Huber@web.de>
5  * All rights reserved.
6  *
7  * $Id: h_ccc.c,v 1.7 2015/03/14 06:11:25 marc Exp marc $
8  *
9  */
10 
11 #include "headers.h"
12 
13 static const char rcsid[] __attribute__ ((used)) = "$Id: h_ccc.c,v 1.7 2015/03/14 06:11:25 marc Exp marc $";
14 
do_shutdown(struct context * ctx,int cur)15 static void do_shutdown(struct context *ctx, int cur)
16 {
17     Debug((DEBUG_PROC, "do_shutdown\n"));
18 
19     if (io_SSL_shutdown(ctx->ssl_c, ctx->io, cur, (void *) do_shutdown)
20 	< 0 && errno == EAGAIN)
21 	return;
22 
23     io_clr_i(ctx->io, cur);
24     io_clr_o(ctx->io, cur);
25 
26     SSL_free(ctx->ssl_c);
27     ctx->ssl_c = NULL;
28 
29     io_set_cb_e(ctx->io, cur, (void *) cleanup_control);
30     io_set_cb_h(ctx->io, cur, (void *) cleanup_control);
31 }
32 
desslify(struct context * ctx,int cur)33 static void desslify(struct context *ctx, int cur)
34 {
35     if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset)
36 	control2socket(ctx, cur);
37     if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset)
38 	io_set_cb_o(ctx->io, cur, (void *) do_shutdown);
39     else {
40 	io_clr_i(ctx->io, cur);
41 	io_clr_o(ctx->io, cur);
42 	do_shutdown(ctx, cur);
43     }
44 }
45 
h_ccc(struct context * ctx,char * arg)46 void h_ccc(struct context *ctx, char *arg __attribute__ ((unused)))
47 {
48     DebugIn(DEBUG_COMMAND);
49 
50     if (!ctx->ssl_c || ctx->use_tls_c)	/* no TLS or implicit TLS via port */
51 	reply(ctx, ctx->use_tls_c ? MSG_534_Denied : MSG_533_Denied);
52     else {
53 	reply(ctx, MSG_200_Done);
54 	desslify(ctx, ctx->cfn);
55     }
56 
57     DebugOut(DEBUG_COMMAND);
58 }
59