1 /*
2 * h_rein.c
3 *
4 * (C)1998-2011 by Marc Huber <Marc.Huber@web.de>
5 * All rights reserved.
6 *
7 * $Id: h_rein.c,v 1.18 2015/03/14 06:11:26 marc Exp marc $
8 *
9 */
10
11 #include "headers.h"
12
13 static const char rcsid[] __attribute__ ((used)) = "$Id: h_rein.c,v 1.18 2015/03/14 06:11:26 marc Exp marc $";
14
15 #ifdef WITH_SSL
do_shutdown(struct context * ctx,int cur)16 static void do_shutdown(struct context *ctx, int cur)
17 {
18 Debug((DEBUG_PROC, "do_shutdown\n"));
19
20 if (io_SSL_shutdown(ctx->ssl_c, ctx->io, cur, (void *) do_shutdown)
21 < 0 && errno == EAGAIN)
22 return;
23
24 io_clr_i(ctx->io, cur);
25 io_clr_o(ctx->io, cur);
26
27 SSL_free(ctx->ssl_c);
28 ctx->ssl_c = NULL;
29
30 ctx->use_tls_d = 0;
31 ctx->protected_buffer_size = -1;
32
33 io_set_cb_e(ctx->io, cur, (void *) cleanup_control);
34 io_set_cb_h(ctx->io, cur, (void *) cleanup_control);
35
36 print_banner(ctx);
37 }
38
desslify(struct context * ctx,int cur)39 static void desslify(struct context *ctx, int cur)
40 {
41 if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset)
42 control2socket(ctx, cur);
43 if (ctx->cbufo && ctx->cbufo->length - ctx->cbufo->offset)
44 io_set_cb_o(ctx->io, cur, (void *) do_shutdown);
45 else {
46 io_clr_i(ctx->io, cur);
47 io_clr_o(ctx->io, cur);
48 do_shutdown(ctx, cur);
49 }
50 }
51 #endif /* WITH_SSL */
52
h_rein(struct context * ctx,char * arg)53 void h_rein(struct context *ctx, char *arg __attribute__ ((unused)))
54 {
55 DebugIn(DEBUG_COMMAND);
56 cleanup_file(ctx, ctx->ffn);
57 #ifdef WITH_SSL
58 if (ctx->ssl_d) {
59 SSL_free(ctx->ssl_d);
60 ctx->ssl_d = NULL;
61 }
62 #endif /* WITH_SSL */
63 cleanup_data(ctx, ctx->dfn);
64 Xfree(&ctx->user);
65 Xfree(&ctx->email);
66 Xfree(&ctx->vhost);
67 Xfree(&ctx->visited_dirs);
68 ctx->dbuf = buffer_free_all(ctx->dbuf);
69 if (ctx->incoming) {
70 regfree(ctx->incoming);
71 free(ctx->incoming);
72 ctx->incoming = NULL;
73 }
74
75 ctx->multiline_banners = 1;
76 ctx->real = ctx->anonymous = 0;
77 ctx->outgoing_data = ctx->use_ascii = 1;
78 ctx->io_offset = 0;
79 ctx->io_offset_start = 0;
80 ctx->io_offset_end = -1;
81 ctx->state = ST_conn;
82 ctx->uid = -1;
83 ctx->gid = -1;
84 ctx->mlst_facts = MLST_fact_size | MLST_fact_modify | MLST_fact_type | MLST_fact_unique | MLST_fact_perm;
85
86 ctx->pst_valid = 0;
87 ctx->mode = 's';
88
89 ctx->md_method_hash = ctx->md_method_checksum = md_method_find(md_methods, "SHA-1");
90 if (!ctx->md_method_hash)
91 ctx->md_method_hash = ctx->md_method_checksum = md_method_find(md_methods, "MD5");
92
93 acl_calc(ctx);
94
95 #ifdef WITH_SSL
96 if (!ctx->ssl_c || ctx->use_tls_c) /* no TLS or implicit TLS via port */
97 print_banner(ctx);
98 else
99 desslify(ctx, ctx->cfn);
100 #else /* WITH_SSL */
101 print_banner(ctx);
102 #endif /* WITH_SSL */
103
104 DebugOut(DEBUG_COMMAND);
105 }
106