diff options
author | jsorg71 <jay.sorg@gmail.com> | 2014-07-23 19:54:55 -0700 |
---|---|---|
committer | jsorg71 <jay.sorg@gmail.com> | 2014-07-23 19:54:55 -0700 |
commit | a4721e8c7ce94f49ba1730784a651275e430fd9b (patch) | |
tree | 5dda767c72daf9dd9e202331139935693266d970 /common/trans.c | |
parent | fde7be5151f7db096610cb59ca964e22e6af79fb (diff) | |
parent | 16929efb059e1e29c826388e5d57be82014d241b (diff) | |
download | xrdp-proprietary-a4721e8c7ce94f49ba1730784a651275e430fd9b.tar.gz xrdp-proprietary-a4721e8c7ce94f49ba1730784a651275e430fd9b.zip |
Merge pull request #156 from speidy/devel
work on TLS security mode
Diffstat (limited to 'common/trans.c')
-rw-r--r-- | common/trans.c | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/common/trans.c b/common/trans.c index 6fd5a9d8..e13cd420 100644 --- a/common/trans.c +++ b/common/trans.c @@ -38,6 +38,10 @@ trans_create(int mode, int in_size, int out_size) make_stream(self->out_s); init_stream(self->out_s, out_size); self->mode = mode; + self->tls = 0; + /* assign tcp functions */ + self->trans_read_call = trans_tcp_force_read_s; + self->trans_write_call = trans_tcp_force_write_s; } return self; @@ -68,6 +72,11 @@ trans_delete(struct trans *self) g_free(self->listen_filename); } + if (self->tls != 0) + { + xrdp_tls_delete(self->tls); + } + g_free(self); } @@ -248,7 +257,7 @@ trans_check_wait_objs(struct trans *self) if (to_read > 0) { - read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0); + read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0); if (read_bytes == -1) { @@ -299,11 +308,16 @@ trans_check_wait_objs(struct trans *self) return rv; } - /*****************************************************************************/ int APP_CC trans_force_read_s(struct trans *self, struct stream *in_s, int size) { + return self->trans_read_call(self, in_s, size); +} +/*****************************************************************************/ +int APP_CC +trans_tcp_force_read_s(struct trans *self, struct stream *in_s, int size) +{ int rcvd; if (self->status != TRANS_STATUS_UP) @@ -318,7 +332,9 @@ trans_force_read_s(struct trans *self, struct stream *in_s, int size) { return 1; } + rcvd = g_tcp_recv(self->sck, in_s->end, size, 0); + if (rcvd == -1) { if (g_tcp_last_error_would_block(self->sck)) @@ -371,6 +387,12 @@ trans_force_read(struct trans *self, int size) int APP_CC trans_force_write_s(struct trans *self, struct stream *out_s) { + return self->trans_write_call(self, out_s); +} +/*****************************************************************************/ +int APP_CC +trans_tcp_force_write_s(struct trans *self, struct stream *out_s) +{ int size; int total; int sent; @@ -391,7 +413,7 @@ trans_force_write_s(struct trans *self, struct stream *out_s) while (total < size) { - sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0); + sent = g_tcp_send(self->sck, out_s->data + total, size - total, 0); if (sent == -1) { @@ -628,3 +650,42 @@ trans_get_out_s(struct trans *self, int size) return rv; } +/*****************************************************************************/ +/* returns error */ +int APP_CC +trans_set_tls_mode(struct trans *self, const char *key, const char *cert) +{ + self->tls = xrdp_tls_create(self, key, cert); + if (self->tls == NULL) + { + g_writeln("trans_set_tls_mode: xrdp_tls_create malloc error"); + return 1; + } + + if (xrdp_tls_accept(self->tls) != 0) + { + g_writeln("trans_set_tls_mode: xrdp_tls_accept failed"); + return 1; + } + + /* assign tls functions */ + self->trans_read_call = xrdp_tls_force_read_s; + self->trans_write_call = xrdp_tls_force_write_s; + + return 0; +} +/*****************************************************************************/ +/* returns error */ +int APP_CC +trans_shutdown_tls_mode(struct trans *self) +{ + if (self->tls != NULL) + { + return xrdp_tls_disconnect(self->tls); + } + + /* set callback back to tcp */ + self->trans_read_call = trans_tcp_force_read_s; + self->trans_write_call = trans_tcp_force_write_s; + return 0; +} |