Add stub SSL socket.
This commit is contained in:
parent
aa68f2df21
commit
bb74730629
@ -44,11 +44,17 @@ man_MANS = man/guacd.8
|
||||
noinst_HEADERS = client.h log.h
|
||||
guacd_SOURCES = daemon.c client.c log.c
|
||||
guacd_LDADD = @LIBGUAC_LTLIB@
|
||||
guacd_LDFLAGS = @PTHREAD_LIBS@
|
||||
guacd_LDFLAGS = @PTHREAD_LIBS@ @SSL_LIBS@
|
||||
|
||||
EXTRA_DIST = init.d/guacd.in man/guacd.8
|
||||
CLEANFILES = $(init_SCRIPTS)
|
||||
|
||||
# SSL support
|
||||
if ENABLE_SSL
|
||||
noinst_HEADERS += socket-ssl.h
|
||||
guacd_SOURCES += socket-ssl.c
|
||||
endif
|
||||
|
||||
# Init script
|
||||
if ENABLE_INIT
|
||||
initdir = @init_dir@
|
||||
|
142
src/guacd/socket-ssl.c
Normal file
142
src/guacd/socket-ssl.c
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is guacd.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <guacamole/socket.h>
|
||||
#include <guacamole/error.h>
|
||||
|
||||
#include "socket-ssl.h"
|
||||
|
||||
|
||||
static ssize_t __guac_socket_ssl_read_handler(guac_socket* socket,
|
||||
void* buf, size_t count) {
|
||||
|
||||
/* Read from socket */
|
||||
guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
|
||||
int retval = 0; /* STUB */
|
||||
|
||||
/* Record errors in guac_error */
|
||||
if (retval < 0) {
|
||||
guac_error = GUAC_STATUS_SEE_ERRNO;
|
||||
guac_error_message = "Error reading data from secure socket";
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
static ssize_t __guac_socket_ssl_write_handler(guac_socket* socket,
|
||||
const void* buf, size_t count) {
|
||||
|
||||
/* Write data to socket */
|
||||
guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
|
||||
int retval = 0; /* STUB */
|
||||
|
||||
/* Record errors in guac_error */
|
||||
if (retval < 0) {
|
||||
guac_error = GUAC_STATUS_SEE_ERRNO;
|
||||
guac_error_message = "Error writing data to secure socket";
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int __guac_socket_ssl_select_handler(guac_socket* socket, int usec_timeout) {
|
||||
|
||||
guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
|
||||
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
int retval;
|
||||
|
||||
/* No timeout if usec_timeout is negative */
|
||||
if (usec_timeout < 0)
|
||||
retval = select(data->fd + 1, &fds, NULL, NULL, NULL);
|
||||
|
||||
/* Handle timeout if specified */
|
||||
else {
|
||||
timeout.tv_sec = usec_timeout/1000000;
|
||||
timeout.tv_usec = usec_timeout%1000000;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(data->fd, &fds);
|
||||
|
||||
retval = select(data->fd + 1, &fds, NULL, NULL, &timeout);
|
||||
}
|
||||
|
||||
/* Properly set guac_error */
|
||||
if (retval < 0) {
|
||||
guac_error = GUAC_STATUS_SEE_ERRNO;
|
||||
guac_error_message = "Error while waiting for data on secure socket";
|
||||
}
|
||||
|
||||
if (retval == 0) {
|
||||
guac_error = GUAC_STATUS_INPUT_TIMEOUT;
|
||||
guac_error_message = "Timeout while waiting for data on secure socket";
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
static int __guac_socket_ssl_free_handler(guac_socket* socket) {
|
||||
free(socket->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
guac_socket* guac_socket_open_secure(int fd) {
|
||||
|
||||
/* Allocate socket and associated data */
|
||||
guac_socket* socket = guac_socket_alloc();
|
||||
guac_socket_ssl_data* data = malloc(sizeof(guac_socket_ssl_data));
|
||||
|
||||
/* Store file descriptor as socket data */
|
||||
data->fd = fd;
|
||||
socket->data = data;
|
||||
|
||||
/* Set read/write handlers */
|
||||
socket->read_handler = __guac_socket_ssl_read_handler;
|
||||
socket->write_handler = __guac_socket_ssl_write_handler;
|
||||
socket->select_handler = __guac_socket_ssl_select_handler;
|
||||
socket->free_handler = __guac_socket_ssl_free_handler;
|
||||
|
||||
return socket;
|
||||
|
||||
}
|
||||
|
60
src/guacd/socket-ssl.h
Normal file
60
src/guacd/socket-ssl.h
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is guacd.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Michael Jumper.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __GUACD_SOCKET_SSL_H
|
||||
#define __GUACD_SOCKET_SSL_H
|
||||
|
||||
/**
|
||||
* SSL socket-specific data.
|
||||
*/
|
||||
typedef struct guac_socket_ssl_data {
|
||||
|
||||
/**
|
||||
* The file descriptor that SSL communication will take place
|
||||
* over.
|
||||
*/
|
||||
int fd;
|
||||
|
||||
} guac_socket_ssl_data;
|
||||
|
||||
/**
|
||||
* Creates a new guac_socket which will use SSL for all communication.
|
||||
*/
|
||||
guac_socket* guac_socket_open_secure(int fd);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user