diff options
author | ilsimo <ilsimo> | 2008-07-30 10:58:30 +0000 |
---|---|---|
committer | ilsimo <ilsimo> | 2008-07-30 10:58:30 +0000 |
commit | d14b076a700e1ad87048549945f0f1e658db6cd5 (patch) | |
tree | cba23a5e8d2175796912e738164c26da4ce345b6 /sesman/libscp | |
parent | a8a2f0a0b0749fa0d7376d2322b05f3984356e29 (diff) | |
download | xrdp-proprietary-d14b076a700e1ad87048549945f0f1e658db6cd5.tar.gz xrdp-proprietary-d14b076a700e1ad87048549945f0f1e658db6cd5.zip |
still more work on logging
libscp makefile fix
Diffstat (limited to 'sesman/libscp')
-rw-r--r-- | sesman/libscp/Makefile | 5 | ||||
-rw-r--r-- | sesman/libscp/libscp_connection.c | 3 | ||||
-rw-r--r-- | sesman/libscp/libscp_init.c | 4 | ||||
-rw-r--r-- | sesman/libscp/libscp_session.c | 106 | ||||
-rw-r--r-- | sesman/libscp/libscp_session.h | 2 | ||||
-rw-r--r-- | sesman/libscp/libscp_tcp.c | 8 | ||||
-rw-r--r-- | sesman/libscp/libscp_types.h | 34 | ||||
-rw-r--r-- | sesman/libscp/libscp_v0.c | 99 | ||||
-rw-r--r-- | sesman/libscp/libscp_v1c.c | 19 | ||||
-rw-r--r-- | sesman/libscp/libscp_v1s.c | 178 |
10 files changed, 331 insertions, 127 deletions
diff --git a/sesman/libscp/Makefile b/sesman/libscp/Makefile index be53aff9..03779f92 100644 --- a/sesman/libscp/Makefile +++ b/sesman/libscp/Makefile @@ -3,7 +3,8 @@ LIBSCPOBJ = libscp_vX.o libscp_v0.o \ libscp_v1s.o libscp_v1c.o \ libscp_init.o libscp_lock.o libscp_tcp.o \ libscp_session.o libscp_connection.o \ - os_calls.o + os_calls.o \ +# libscp_v1s_mng.o libscp_v1c_mng.o CFGDIR = /etc/xrdp PIDDIR = /var/run @@ -34,7 +35,7 @@ clean: rm -f $(LIBSCPOBJ) $(LIBSCPFNAME) $(LIBSCPLNAME) install: - install $(LIBSCPFNAME) $(LIBDIR)/$(LIBSCPFNAME) + install -D $(LIBSCPFNAME) $(LIBDIR)/$(LIBSCPFNAME) ln -f -s $(LIBSCPFNAME) $(LIBDIR)/$(LIBSCPLNAME) os_calls.o: ../../common/os_calls.c diff --git a/sesman/libscp/libscp_connection.c b/sesman/libscp/libscp_connection.c index 06010a5b..7f6569d1 100644 --- a/sesman/libscp/libscp_connection.c +++ b/sesman/libscp/libscp_connection.c @@ -27,6 +27,8 @@ #include "libscp_connection.h" +extern struct log_config* s_log; + struct SCP_CONNECTION* scp_connection_create(int sck) { @@ -36,6 +38,7 @@ scp_connection_create(int sck) if (0 == conn) { + log_message(s_log, LOG_LEVEL_WARNING, "[connection:%d] connection create: malloc error", __LINE__); return 0; } diff --git a/sesman/libscp/libscp_init.c b/sesman/libscp/libscp_init.c index 4f54f6cc..899fd6c9 100644 --- a/sesman/libscp/libscp_init.c +++ b/sesman/libscp/libscp_init.c @@ -27,7 +27,7 @@ #include "libscp_init.h" -static struct log_config* s_log; +struct log_config* s_log; /* server API */ int DEFAULT_CC @@ -42,6 +42,8 @@ scp_init(struct log_config* log) scp_lock_init(); + log_message(s_log, LOG_LEVEL_WARNING, "[init:%d] libscp initialized", __LINE__); + return 0; } diff --git a/sesman/libscp/libscp_session.c b/sesman/libscp/libscp_session.c index 916424d9..a7b3397c 100644 --- a/sesman/libscp/libscp_session.c +++ b/sesman/libscp/libscp_session.c @@ -27,6 +27,12 @@ #include "libscp_session.h" +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> + +extern struct log_config* s_log; + struct SCP_SESSION* scp_session_create() { @@ -36,14 +42,15 @@ scp_session_create() if (0 == s) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__); return 0; } - s->username=0; - s->password=0; - s->hostname=0; - s->errstr=0; -#warning FIXME use scp_session_set* to init session + s->username = 0; + s->password = 0; + s->hostname = 0; + s->errstr = 0; + s->locale[0]='\0'; return s; } @@ -60,7 +67,11 @@ scp_session_set_type(struct SCP_SESSION* s, tui8 type) case SCP_SESSION_TYPE_XRDP: s->type = SCP_SESSION_TYPE_XRDP; break; + case SCP_SESSION_TYPE_MANAGE: + s->type = SCP_SESSION_TYPE_MANAGE; + break; default: + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__); return 1; } return 0; @@ -79,6 +90,7 @@ scp_session_set_version(struct SCP_SESSION* s, tui32 version) s->version = 1; break; default: + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__); return 1; } return 0; @@ -137,6 +149,8 @@ scp_session_set_locale(struct SCP_SESSION* s, char* str) { if (0 == str) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__); + s->locale[0]='\0'; return 1; } g_strncpy(s->locale, str, 17); @@ -150,13 +164,19 @@ scp_session_set_username(struct SCP_SESSION* s, char* str) { if (0 == str) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__); return 1; } - if (0 != s->username) + if (0 != s->username) { g_free(s->username); } s->username = g_strdup(str); + if (0 == s->username) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__); + return 1; + } return 0; } @@ -166,13 +186,19 @@ scp_session_set_password(struct SCP_SESSION* s, char* str) { if (0 == str) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__); return 1; } - if (0 != s->password) + if (0 != s->password) { g_free(s->password); } s->password = g_strdup(str); + if (0 == s->password) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__); + return 1; + } return 0; } @@ -180,15 +206,21 @@ scp_session_set_password(struct SCP_SESSION* s, char* str) int scp_session_set_hostname(struct SCP_SESSION* s, char* str) { - if (0 == str) + if (0 == str) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__); return 1; } - if (0 != s->hostname) + if (0 != s->hostname) { g_free(s->hostname); } s->hostname = g_strdup(str); + if (0 == s->hostname) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__); + return 1; + } return 0; } @@ -196,15 +228,21 @@ scp_session_set_hostname(struct SCP_SESSION* s, char* str) int scp_session_set_errstr(struct SCP_SESSION* s, char* str) { - if (0 == str) + if (0 == str) { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__); return 1; } - if (0 != s->errstr) + if (0 != s->errstr) { g_free(s->errstr); } s->errstr = g_strdup(str); + if (0 == s->errstr) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__); + return 1; + } return 0; } @@ -212,16 +250,54 @@ scp_session_set_errstr(struct SCP_SESSION* s, char* str) int scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display) { - s->display=display; + s->display = display; return 0; } /*******************************************************************/ int -scp_session_set_addr(struct SCP_SESSION* s, int type, char* addr) +scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr) { -#warning FIXME managing addresses - return 1; + struct in_addr ip4; + struct in6_addr ip6; + int ret; + + switch (type) + { + case SCP_ADDRESS_TYPE_IPV4: + /* convert from char to 32bit*/ + ret = inet_pton(AF_INET, addr, &ip4); + if (0 == ret) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__); + inet_pton(AF_INET, "127.0.0.1", &ip4); + g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4); + return 1; + } + g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4); + break; + case SCP_ADDRESS_TYPE_IPV6: + /* convert from char to 128bit*/ + ret = inet_pton(AF_INET6, addr, &ip6); + if (0 == ret) + { + log_message(s_log, LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__); + inet_pton(AF_INET, "::1", &ip6); + g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16); + return 1; + } + g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16); + break; + case SCP_ADDRESS_TYPE_IPV4_BIN: + g_memcpy(&(s->ipv4addr), addr, 4); + break; + case SCP_ADDRESS_TYPE_IPV6_BIN: + g_memcpy(s->ipv6addr, addr, 16); + break; + default: + return 1; + } + return 0; } /*******************************************************************/ diff --git a/sesman/libscp/libscp_session.h b/sesman/libscp/libscp_session.h index be783ea3..aefeb201 100644 --- a/sesman/libscp/libscp_session.h +++ b/sesman/libscp/libscp_session.h @@ -72,7 +72,7 @@ int scp_session_set_hostname(struct SCP_SESSION* s, char* str); int -scp_session_set_addr(struct SCP_SESSION* s, int type, char* addr); +scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr); int scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display); diff --git a/sesman/libscp/libscp_tcp.c b/sesman/libscp/libscp_tcp.c index 37aa7eac..0181f50c 100644 --- a/sesman/libscp/libscp_tcp.c +++ b/sesman/libscp/libscp_tcp.c @@ -33,13 +33,16 @@ #include <stdlib.h> #include <string.h> +extern struct log_config* s_log; + /*****************************************************************************/ int DEFAULT_CC scp_tcp_force_recv(int sck, char* data, int len) { int rcvd; int block; - + + LOG_DBG(s_log, "scp_tcp_force_recv()"); block = scp_lock_fork_critical_section_start(); while (len > 0) @@ -80,7 +83,8 @@ scp_tcp_force_send(int sck, char* data, int len) { int sent; int block; - + + LOG_DBG(s_log, "scp_tcp_force_send()"); block = scp_lock_fork_critical_section_start(); while (len > 0) diff --git a/sesman/libscp/libscp_types.h b/sesman/libscp/libscp_types.h index 991d855b..b8b5d6bd 100644 --- a/sesman/libscp/libscp_types.h +++ b/sesman/libscp/libscp_types.h @@ -31,7 +31,7 @@ #include "os_calls.h" #include "parse.h" #include "arch.h" -//#include "log.h" +#include "log.h" #define SCP_SID tui32 #define SCP_DISPLAY tui16 @@ -39,12 +39,17 @@ #define SCP_RESOURCE_SHARING_REQUEST_YES 0x01 #define SCP_RESOURCE_SHARING_REQUEST_NO 0x00 -#define SCP_SESSION_TYPE_XVNC 0x00 -#define SCP_SESSION_TYPE_XRDP 0x01 +#define SCP_SESSION_TYPE_XVNC 0x00 +#define SCP_SESSION_TYPE_XRDP 0x01 +#define SCP_SESSION_TYPE_MANAGE 0x02 #define SCP_ADDRESS_TYPE_IPV4 0x00 #define SCP_ADDRESS_TYPE_IPV6 0x01 +/* used in scp_session_set_addr() */ +#define SCP_ADDRESS_TYPE_IPV4_BIN 0x80 +#define SCP_ADDRESS_TYPE_IPV6_BIN 0x81 + #define SCP_COMMAND_SET_DEFAULT 0x0000 #define SCP_COMMAND_SET_MANAGE 0x0001 #define SCP_COMMAND_SET_RSR 0x0002 @@ -62,19 +67,19 @@ struct SCP_CONNECTION struct SCP_SESSION { - tui8 type; + tui8 type; tui32 version; tui16 height; tui16 width; - tui8 bpp; - tui8 rsr; - char locale[18]; + tui8 bpp; + tui8 rsr; + char locale[18]; char* username; char* password; char* hostname; - tui8 addr_type; - tui32 ipv4addr; //htons - tui32 ipv6addr; //should be 128bit + tui8 addr_type; + tui32 ipv4addr; + tui8 ipv6addr[16]; tui16 display; char* errstr; }; @@ -83,12 +88,21 @@ struct SCP_DISCONNECTED_SESSION { tui32 SID; tui8 type; + tui8 status; tui16 height; tui16 width; tui8 bpp; tui8 idle_days; tui8 idle_hours; tui8 idle_minutes; + tui16 conn_year; + tui8 conn_month; + tui8 conn_day; + tui8 conn_hour; + tui8 conn_minute; + tui8 addr_type; + tui32 ipv4addr; + tui8 ipv6addr[16]; }; enum SCP_CLIENT_STATES_E diff --git a/sesman/libscp/libscp_v0.c b/sesman/libscp/libscp_v0.c index 6c948b73..bd94146a 100644 --- a/sesman/libscp/libscp_v0.c +++ b/sesman/libscp/libscp_v0.c @@ -28,6 +28,9 @@ #include "libscp_v0.h" #include "os_calls.h" + +extern struct log_config* s_log; + /* client API */ /******************************************************************************/ enum SCP_CLIENT_STATES_E scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s) @@ -39,20 +42,23 @@ enum SCP_CLIENT_STATES_E scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SE init_stream(c->in_s, c->in_s->size); init_stream(c->out_s, c->in_s->size); + LOG_DBG(s_log, "[v0:%d] starting connection", __LINE__); g_tcp_set_non_blocking(c->in_sck); g_tcp_set_no_delay(c->in_sck); s_push_layer(c->out_s, channel_hdr, 8); - if (s->type==SCP_SESSION_TYPE_XVNC) + /* code */ + if (s->type == SCP_SESSION_TYPE_XVNC) { - out_uint16_be(c->out_s, 0); // code + out_uint16_be(c->out_s, 0); } - else if (s->type==SCP_SESSION_TYPE_XRDP) + else if (s->type == SCP_SESSION_TYPE_XRDP) { - out_uint16_be(c->out_s, 10); // code + out_uint16_be(c->out_s, 10); } else { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_CLIENT_STATE_INTERNAL_ERR; } sz = g_strlen(s->username); @@ -69,52 +75,65 @@ enum SCP_CLIENT_STATES_E scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SE s_mark_end(c->out_s); s_pop_layer(c->out_s, channel_hdr); - out_uint32_be(c->out_s, 0); // version - out_uint32_be(c->out_s, c->out_s->end - c->out_s->data); // size + /* version */ + out_uint32_be(c->out_s, 0); + /* size */ + out_uint32_be(c->out_s, c->out_s->end - c->out_s->data); if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_CLIENT_STATE_NETWORK_ERR; } if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_CLIENT_STATE_NETWORK_ERR; } in_uint32_be(c->in_s, version); if (0 != version) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); return SCP_CLIENT_STATE_VERSION_ERR; } in_uint32_be(c->in_s, size); if (size < 14) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: packet size error", __LINE__); return SCP_CLIENT_STATE_SIZE_ERR; } + /* getting payload */ init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_CLIENT_STATE_NETWORK_ERR; } + /* check code */ in_uint16_be(c->in_s, sz); - if (3!=sz) + if (3 != sz) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__); return SCP_CLIENT_STATE_SEQUENCE_ERR; } + /* message payload */ in_uint16_be(c->in_s, sz); - if (1!=sz) + if (1 != sz) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: connection denied", __LINE__); return SCP_CLIENT_STATE_CONNECTION_DENIED; } in_uint16_be(c->in_s, sz); - s->display=sz; + s->display = sz; + LOG_DBG(s_log, "[v0:%d] connection terminated", __LINE__); return SCP_CLIENT_STATE_END; } @@ -122,24 +141,28 @@ enum SCP_CLIENT_STATES_E scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SE /******************************************************************************/ enum SCP_SERVER_STATES_E scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk) { - tui32 version=0; + tui32 version = 0; tui32 size; - struct SCP_SESSION* session=0; + struct SCP_SESSION* session = 0; tui16 sz; - tui32 code=0; + tui32 code = 0; + char buf[257]; if (!skipVchk) { + LOG_DBG(s_log, "[v0:%d] starting connection", __LINE__); if (0==scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { in_uint32_be(c->in_s, version); if (version != 0) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); return SCP_SERVER_STATE_VERSION_ERR; } } else { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } } @@ -149,6 +172,7 @@ enum SCP_SERVER_STATES_E scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SES init_stream(c->in_s, 8196); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, size-8)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } @@ -156,53 +180,58 @@ enum SCP_SERVER_STATES_E scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SES if (code == 0 || code == 10) { - session = g_malloc(sizeof(struct SCP_SESSION),1); + session = scp_session_create(); if (0 == session) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->version=version; - + scp_session_set_version(session, version); if (code == 0) { - session->type=SCP_SESSION_TYPE_XVNC; + scp_session_set_type(session, SCP_SESSION_TYPE_XVNC); } else { - session->type=SCP_SESSION_TYPE_XRDP; + scp_session_set_type(session, SCP_SESSION_TYPE_XRDP); } /* reading username */ in_uint16_be(c->in_s, sz); - session->username=g_malloc(sz+1,0); - if (0==session->username) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_username(session, buf)) { - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->username[sz]='\0'; - in_uint8a(c->in_s, session->username, sz); /* reading password */ in_uint16_be(c->in_s, sz); - session->password=g_malloc(sz+1,0); - if (0==session->password) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_password(session, buf)) { - g_free(session->username); - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->password[sz]='\0'; - in_uint8a(c->in_s, session->password, sz); - in_uint16_be(c->in_s, session->width); - in_uint16_be(c->in_s, session->height); + /* width */ + in_uint16_be(c->in_s, sz); + scp_session_set_width(session, sz); + /* height */ in_uint16_be(c->in_s, sz); - session->bpp=(unsigned char)sz; + scp_session_set_height(session, sz); + /* bpp */ + in_uint16_be(c->in_s, sz); + scp_session_set_bpp(session, (tui8)sz); } else { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } @@ -220,11 +249,13 @@ enum SCP_SERVER_STATES_E scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_ out_uint16_be(c->out_s, d); /* data */ s_mark_end(c->out_s); - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } + LOG_DBG(s_log, "[v0:%d] connection terminated (allowed)", __LINE__); return SCP_SERVER_STATE_OK; } @@ -238,10 +269,12 @@ enum SCP_SERVER_STATES_E scp_v0s_deny_connection(struct SCP_CONNECTION* c) out_uint16_be(c->out_s, 0); /* data */ s_mark_end(c->out_s); - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } + LOG_DBG(s_log, "[v0:%d] connection terminated (denied)", __LINE__); return SCP_SERVER_STATE_OK; } diff --git a/sesman/libscp/libscp_v1c.c b/sesman/libscp/libscp_v1c.c index f29e7e36..c3f4ce97 100644 --- a/sesman/libscp/libscp_v1c.c +++ b/sesman/libscp/libscp_v1c.c @@ -76,9 +76,9 @@ scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s) { out_uint32_be(c->out_s, s->ipv4addr); } - else + else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6) { - #warning ipv6 address needed + out_uint8p(c->out_s, s->ipv6addr, 16); } sz = g_strlen(s->hostname); @@ -241,6 +241,21 @@ scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, in_uint8(c->in_s, (ds[totalcnt]).idle_days); in_uint8(c->in_s, (ds[totalcnt]).idle_hours); in_uint8(c->in_s, (ds[totalcnt]).idle_minutes); + + in_uint16_be(c->in_s, (ds[totalcnt]).conn_year); + in_uint8(c->in_s, (ds[totalcnt]).conn_month); + in_uint8(c->in_s, (ds[totalcnt]).conn_day); + in_uint8(c->in_s, (ds[totalcnt]).conn_hour); + in_uint8(c->in_s, (ds[totalcnt]).conn_minute); + in_uint8(c->in_s, (ds[totalcnt]).addr_type); + if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4) + { + in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr); + } + else if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6) + { + in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16); + } totalcnt++; } } diff --git a/sesman/libscp/libscp_v1s.c b/sesman/libscp/libscp_v1s.c index 192567a3..74ce187d 100644 --- a/sesman/libscp/libscp_v1s.c +++ b/sesman/libscp/libscp_v1s.c @@ -30,6 +30,8 @@ #include "libscp_v1s.h" +extern struct log_config* s_log; + /* server API */ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk) { @@ -39,6 +41,7 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SES tui16 cmdset; tui16 cmd; tui8 sz; + char buf[257]; if (!skipVchk) { @@ -48,28 +51,32 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SES in_uint32_be(c->in_s, version); if (version != 1) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); return SCP_SERVER_STATE_VERSION_ERR; } } else { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } } else { - version=1; + version = 1; } in_uint32_be(c->in_s, size); - if (size<12) + if (size < 12) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); return SCP_SERVER_STATE_SIZE_ERR; } init_stream(c->in_s, c->in_s->size); - if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8))) + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8))) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } @@ -77,14 +84,16 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SES in_uint16_be(c->in_s, cmdset); /* if we are starting a management session */ - if (cmdset==SCP_COMMAND_SET_MANAGE) + if (cmdset == SCP_COMMAND_SET_MANAGE) { + log_message(s_log, LOG_LEVEL_DEBUG, "[v1s:%d] requested management connection", __LINE__); return SCP_SERVER_STATE_START_MANAGE; } /* if we started with resource sharing... */ - if (cmdset==SCP_COMMAND_SET_RSR) + if (cmdset == SCP_COMMAND_SET_RSR) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } @@ -92,75 +101,84 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SES in_uint16_be(c->in_s, cmd); if (cmd != 1) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } - session = g_malloc(sizeof(struct SCP_SESSION),1); + session = scp_session_create(); if (0 == session) { - return SCP_SERVER_STATE_INTERNAL_ERR; + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (malloc returned NULL)", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; } - session->version=1; + scp_session_set_version(session, 1); - in_uint8(c->in_s, session->type); - if ((session->type != SCP_SESSION_TYPE_XVNC) && (session->type != SCP_SESSION_TYPE_XRDP)) + in_uint8(c->in_s, sz); + if ((sz != SCP_SESSION_TYPE_XVNC) && (sz != SCP_SESSION_TYPE_XRDP)) { - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: unknown session type", __LINE__); return SCP_SERVER_STATE_SESSION_TYPE_ERR; } + scp_session_set_type(session, sz); - in_uint16_be(c->in_s,session->height); - in_uint16_be(c->in_s, session->width); - in_uint8(c->in_s, session->bpp); - in_uint8(c->in_s, session->rsr); - in_uint8a(c->in_s, session->locale, 17); - session->locale[17]='\0'; + in_uint16_be(c->in_s, cmd); + scp_session_set_height(session, cmd); + in_uint16_be(c->in_s, cmd); + scp_session_set_height(session, cmd); + in_uint8(c->in_s, sz); + scp_session_set_bpp(session, sz); + in_uint8(c->in_s, sz); + scp_session_set_rsr(session, sz); + in_uint8a(c->in_s, buf, 17); + buf[17]='\0'; + scp_session_set_locale(session, buf); - in_uint8(c->in_s, session->addr_type); - if (session->addr_type==SCP_ADDRESS_TYPE_IPV4) + in_uint8(c->in_s, sz); + if (sz == SCP_ADDRESS_TYPE_IPV4) { - in_uint32_be(c->in_s, session->ipv4addr); + in_uint32_be(c->in_s, size); + scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &size); } - else if (session->addr_type==SCP_ADDRESS_TYPE_IPV6) + else if (sz == SCP_ADDRESS_TYPE_IPV6) { - #warning how to handle ipv6 addresses? + in_uint8a(c->in_s, buf, 16); + scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf); } + buf[256] = '\0'; /* reading hostname */ in_uint8(c->in_s, sz); - session->hostname=g_malloc(sz+1,1); - if (0==session->hostname) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_hostname(session, buf)) { - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->hostname[sz]='\0'; - in_uint8a(c->in_s, session->hostname, sz); /* reading username */ in_uint8(c->in_s, sz); - session->username=g_malloc(sz+1,1); - if (0==session->username) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_username(session, buf)) { - g_free(session->hostname); - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->username[sz]='\0'; - in_uint8a(c->in_s, session->username, sz); /* reading password */ in_uint8(c->in_s, sz); - session->password=g_malloc(sz+1,1); - if (0==session->password) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_password(session, buf)) { - g_free(session->username); - g_free(session->hostname); - g_free(session); + scp_session_destroy(session); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - session->password[sz]='\0'; - in_uint8a(c->in_s, session->password, sz); /* returning the struct */ (*s)=session; @@ -193,6 +211,7 @@ scp_v1s_deny_connection(struct SCP_CONNECTION* c, char* reason) if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } @@ -203,13 +222,12 @@ enum SCP_SERVER_STATES_E scp_v1s_request_password(struct SCP_CONNECTION* c, struct SCP_SESSION* s, char* reason) { tui8 sz; - char *ubuf; - char *pbuf; tui32 version; tui32 size; tui16 cmdset; tui16 cmd; int rlen; + char buf[257]; init_stream(c->in_s, c->in_s->size); init_stream(c->out_s, c->out_s->size); @@ -237,71 +255,74 @@ scp_v1s_request_password(struct SCP_CONNECTION* c, struct SCP_SESSION* s, char* if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14+rlen)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } /* receive password & username */ if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint32_be(c->in_s, version); if (version!=1) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); return SCP_SERVER_STATE_VERSION_ERR; } in_uint32_be(c->in_s, size); if (size<12) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); return SCP_SERVER_STATE_SIZE_ERR; } init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8))) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint16_be(c->in_s, cmdset); if (cmdset != SCP_COMMAND_SET_DEFAULT) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } in_uint16_be(c->in_s, cmd); if (cmd != 4) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } + buf[256] = '\0'; /* reading username */ in_uint8(c->in_s, sz); - ubuf=g_malloc(sz+1,1); - if (0==ubuf) + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_username(s, buf)) { + scp_session_destroy(s); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - ubuf[sz]='\0'; - in_uint8a(c->in_s, ubuf, sz); /* reading password */ in_uint8(c->in_s, sz); - pbuf=g_malloc(sz+1,1); - if (0==pbuf) + buf[sz]='\0'; + in_uint8a(c->in_s, buf, sz); + if (0 != scp_session_set_password(s, buf)) { - g_free(ubuf); + scp_session_destroy(s); + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); return SCP_SERVER_STATE_INTERNAL_ERR; } - pbuf[sz]='\0'; - in_uint8a(c->in_s, pbuf, sz); - - /* replacing username and password */ - g_free(s->username); - g_free(s->password); - s->username=ubuf; - s->password=pbuf; return SCP_SERVER_STATE_OK; } @@ -340,6 +361,7 @@ scp_v1s_connect_new_session(struct SCP_CONNECTION* c, SCP_DISPLAY d) if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } @@ -377,6 +399,7 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } @@ -386,36 +409,42 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint32_be(c->in_s, version); if (version!=1) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); return SCP_SERVER_STATE_VERSION_ERR; } in_uint32_be(c->in_s, size); if (size<12) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); return SCP_SERVER_STATE_SIZE_ERR; } init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8))) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint16_be(c->in_s, cmd); if (cmd != SCP_COMMAND_SET_DEFAULT) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } in_uint16_be(c->in_s, cmd); if (cmd != 41) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } @@ -474,16 +503,35 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC out_uint8(c->out_s, cds->idle_days); out_uint8(c->out_s, cds->idle_hours); out_uint8(c->out_s, cds->idle_minutes); + size += 13; + + out_uint16_be(c->out_s, cds->conn_year); + out_uint8(c->out_s, cds->conn_month); + out_uint8(c->out_s, cds->conn_day); + out_uint8(c->out_s, cds->conn_hour); + out_uint8(c->out_s, cds->conn_minute); + out_uint8(c->out_s, cds->addr_type); + size += 7; - size = size + 13; + if (cds->addr_type == SCP_ADDRESS_TYPE_IPV4) + { + in_uint32_be(c->out_s, cds->ipv4addr); + size += 4; + } + else if (cds->addr_type == SCP_ADDRESS_TYPE_IPV6) + { + in_uint8a(c->out_s, cds->ipv6addr, 16); + size += 16; + } } s_pop_layer(c->out_s, channel_hdr); out_uint32_be(c->out_s, version); out_uint32_be(c->out_s, size); - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } } @@ -492,18 +540,21 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (8))) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint32_be(c->in_s, version); - if (version!=1) + if (version != 1) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); return SCP_SERVER_STATE_VERSION_ERR; } in_uint32_be(c->in_s, size); - if (size<12) + if (size < 12) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); return SCP_SERVER_STATE_SIZE_ERR; } @@ -511,12 +562,14 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC init_stream(c->in_s, c->in_s->size); if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8))) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } in_uint16_be(c->in_s, cmd); if (cmd != SCP_COMMAND_SET_DEFAULT) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } @@ -539,6 +592,7 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC /* if we got here, the requested sid wasn't one from the list we sent */ /* we should kill the connection */ + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (no such session in list)", __LINE__); return SCP_CLIENT_STATE_INTERNAL_ERR; } else if (cmd == 44) @@ -554,6 +608,7 @@ scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNEC else { /* wrong response */ + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; } @@ -590,6 +645,7 @@ scp_v1s_reconnect_session(struct SCP_CONNECTION* c, SCP_DISPLAY d) if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) { + log_message(s_log, LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); return SCP_SERVER_STATE_NETWORK_ERR; } |