diff options
Diffstat (limited to 'sesman/libscp')
27 files changed, 2834 insertions, 2691 deletions
diff --git a/sesman/libscp/libscp.h b/sesman/libscp/libscp.h index e06803cf..ed73380f 100644 --- a/sesman/libscp/libscp.h +++ b/sesman/libscp/libscp.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_commands.h b/sesman/libscp/libscp_commands.h index 8745c6bf..8c8d5f08 100644 --- a/sesman/libscp/libscp_commands.h +++ b/sesman/libscp/libscp_commands.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_commands_mng.h b/sesman/libscp/libscp_commands_mng.h index 78dffcf4..e1d6ba7c 100644 --- a/sesman/libscp/libscp_commands_mng.h +++ b/sesman/libscp/libscp_commands_mng.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_connection.c b/sesman/libscp/libscp_connection.c index bf49fb84..6366d51a 100644 --- a/sesman/libscp/libscp_connection.c +++ b/sesman/libscp/libscp_connection.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -29,32 +28,32 @@ //extern struct log_config* s_log; -struct SCP_CONNECTION* +struct SCP_CONNECTION * scp_connection_create(int sck) { - struct SCP_CONNECTION* conn; + struct SCP_CONNECTION *conn; - conn = g_malloc(sizeof(struct SCP_CONNECTION), 0); + conn = g_malloc(sizeof(struct SCP_CONNECTION), 0); - if (0 == conn) - { - log_message(LOG_LEVEL_WARNING, "[connection:%d] connection create: malloc error", __LINE__); - return 0; - } + if (0 == conn) + { + log_message(LOG_LEVEL_WARNING, "[connection:%d] connection create: malloc error", __LINE__); + return 0; + } - conn->in_sck=sck; - make_stream(conn->in_s); - init_stream(conn->in_s, 8196); - make_stream(conn->out_s); - init_stream(conn->out_s, 8196); + conn->in_sck = sck; + make_stream(conn->in_s); + init_stream(conn->in_s, 8196); + make_stream(conn->out_s); + init_stream(conn->out_s, 8196); - return conn; + return conn; } void -scp_connection_destroy(struct SCP_CONNECTION* c) +scp_connection_destroy(struct SCP_CONNECTION *c) { - free_stream(c->in_s); - free_stream(c->out_s); - g_free(c); + free_stream(c->in_s); + free_stream(c->out_s); + g_free(c); } diff --git a/sesman/libscp/libscp_connection.h b/sesman/libscp/libscp_connection.h index ba94f429..e5bdbe27 100644 --- a/sesman/libscp/libscp_connection.h +++ b/sesman/libscp/libscp_connection.h @@ -1,28 +1,27 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * * @file libscp_connection.h * @brief SCP_CONNECTION handling code * @author Simone Fedele - * + * */ #ifndef LIBSCP_CONNECTION_H @@ -37,7 +36,7 @@ * * @return a struct SCP_CONNECTION* object on success, NULL otherwise * - */ + */ struct SCP_CONNECTION* scp_connection_create(int sck); @@ -45,10 +44,9 @@ scp_connection_create(int sck); * * @brief destroys a struct SCP_CONNECTION* object * @param c the object to be destroyed - * + * */ void scp_connection_destroy(struct SCP_CONNECTION* c); #endif - diff --git a/sesman/libscp/libscp_init.c b/sesman/libscp/libscp_init.c index 4c48fb1f..eae57c6e 100644 --- a/sesman/libscp/libscp_init.c +++ b/sesman/libscp/libscp_init.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -33,19 +32,18 @@ int DEFAULT_CC scp_init() { -/* - if (0 == log) - { - return 1; - } -*/ + /* + if (0 == log) + { + return 1; + } + */ - //s_log = log; + //s_log = log; - scp_lock_init(); + scp_lock_init(); - log_message(LOG_LEVEL_WARNING, "[init:%d] libscp initialized", __LINE__); + log_message(LOG_LEVEL_WARNING, "[init:%d] libscp initialized", __LINE__); - return 0; + return 0; } - diff --git a/sesman/libscp/libscp_init.h b/sesman/libscp/libscp_init.h index 92dbc659..20a75857 100644 --- a/sesman/libscp/libscp_init.h +++ b/sesman/libscp/libscp_init.h @@ -1,28 +1,27 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * * @file libscp_init.h * @brief libscp initialization code header * @author Simone Fedele - * + * */ #ifndef LIBSCP_INIT_H @@ -41,8 +40,7 @@ * It this memory needs to be g_free()d * */ -int DEFAULT_CC +int DEFAULT_CC scp_init(); #endif - diff --git a/sesman/libscp/libscp_lock.c b/sesman/libscp/libscp_lock.c index 9556b872..4db05422 100644 --- a/sesman/libscp/libscp_lock.c +++ b/sesman/libscp/libscp_lock.c @@ -1,25 +1,23 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 - - session manager - linux only - -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * session manager + * linux only + */ #include "libscp_lock.h" @@ -37,110 +35,114 @@ int lock_fork_waiting_count; /* threads suspended until the fork finish void DEFAULT_CC scp_lock_init(void) { - /* initializing fork lock */ - pthread_mutexattr_init(&lock_fork_attr); - pthread_mutex_init(&lock_fork, &lock_fork_attr); - sem_init(&lock_fork_req, 0, 0); - sem_init(&lock_fork_wait, 0, 0); - - /* here we don't use locking because lock_init() should be called BEFORE */ - /* any thread is created */ - lock_fork_blockers_count=0; - lock_fork_waiting_count=0; - lock_fork_forkers_count=0; + /* initializing fork lock */ + pthread_mutexattr_init(&lock_fork_attr); + pthread_mutex_init(&lock_fork, &lock_fork_attr); + sem_init(&lock_fork_req, 0, 0); + sem_init(&lock_fork_wait, 0, 0); + + /* here we don't use locking because lock_init() should be called BEFORE */ + /* any thread is created */ + lock_fork_blockers_count = 0; + lock_fork_waiting_count = 0; + lock_fork_forkers_count = 0; } /******************************************************************************/ void DEFAULT_CC scp_lock_fork_request(void) { - /* lock mutex */ - pthread_mutex_lock(&lock_fork); - if (lock_fork_blockers_count == 0) - { - /* if noone is blocking fork(), then we're allowed to fork */ - sem_post(&lock_fork_req); - } - lock_fork_forkers_count++; - pthread_mutex_unlock(&lock_fork); - - /* we wait to be allowed to fork() */ - sem_wait(&lock_fork_req); + /* lock mutex */ + pthread_mutex_lock(&lock_fork); + + if (lock_fork_blockers_count == 0) + { + /* if noone is blocking fork(), then we're allowed to fork */ + sem_post(&lock_fork_req); + } + + lock_fork_forkers_count++; + pthread_mutex_unlock(&lock_fork); + + /* we wait to be allowed to fork() */ + sem_wait(&lock_fork_req); } /******************************************************************************/ void DEFAULT_CC scp_lock_fork_release(void) { - pthread_mutex_lock(&lock_fork); - lock_fork_forkers_count--; - - /* if there's someone else that want to fork, we let him fork() */ - if (lock_fork_forkers_count > 0) - { - sem_post(&lock_fork_req); - } - - for (;lock_fork_waiting_count > 0; lock_fork_waiting_count--) - { - /* waking up the other processes */ - sem_post(&lock_fork_wait); - } - pthread_mutex_unlock(&lock_fork); + pthread_mutex_lock(&lock_fork); + lock_fork_forkers_count--; + + /* if there's someone else that want to fork, we let him fork() */ + if (lock_fork_forkers_count > 0) + { + sem_post(&lock_fork_req); + } + + for (; lock_fork_waiting_count > 0; lock_fork_waiting_count--) + { + /* waking up the other processes */ + sem_post(&lock_fork_wait); + } + + pthread_mutex_unlock(&lock_fork); } /******************************************************************************/ void DEFAULT_CC scp_lock_fork_critical_section_end(int blocking) { - //LOG_DBG("lock_fork_critical_secection_end()",0); - /* lock mutex */ - pthread_mutex_lock(&lock_fork); - - if (blocking == LIBSCP_LOCK_FORK_BLOCKER) - { - lock_fork_blockers_count--; - } - - /* if there's someone who wants to fork and we're the last blocking */ - /* then we let him go */ - if ((lock_fork_blockers_count == 0) && (lock_fork_forkers_count>0)) - { - sem_post(&lock_fork_req); - } - pthread_mutex_unlock(&lock_fork); + //LOG_DBG("lock_fork_critical_secection_end()",0); + /* lock mutex */ + pthread_mutex_lock(&lock_fork); + + if (blocking == LIBSCP_LOCK_FORK_BLOCKER) + { + lock_fork_blockers_count--; + } + + /* if there's someone who wants to fork and we're the last blocking */ + /* then we let him go */ + if ((lock_fork_blockers_count == 0) && (lock_fork_forkers_count > 0)) + { + sem_post(&lock_fork_req); + } + + pthread_mutex_unlock(&lock_fork); } /******************************************************************************/ int DEFAULT_CC scp_lock_fork_critical_section_start(void) { - //LOG_DBG("lock_fork_critical_secection_start()",0); - do - { - pthread_mutex_lock(&lock_fork); - - /* someone requested to fork */ - if (lock_fork_forkers_count > 0) + //LOG_DBG("lock_fork_critical_secection_start()",0); + do { - lock_fork_waiting_count++; - pthread_mutex_unlock(&lock_fork); - - /* we wait until the fork finishes */ - sem_wait(&lock_fork_wait); - + pthread_mutex_lock(&lock_fork); + + /* someone requested to fork */ + if (lock_fork_forkers_count > 0) + { + lock_fork_waiting_count++; + pthread_mutex_unlock(&lock_fork); + + /* we wait until the fork finishes */ + sem_wait(&lock_fork_wait); + + } + else + { + /* no fork, so we can go on... */ + lock_fork_blockers_count++; + pthread_mutex_unlock(&lock_fork); + + return LIBSCP_LOCK_FORK_BLOCKER; + } } - else - { - /* no fork, so we can go on... */ - lock_fork_blockers_count++; - pthread_mutex_unlock(&lock_fork); - - return LIBSCP_LOCK_FORK_BLOCKER; - } - } while (1); + while (1); - /* we'll never get here */ - return LIBSCP_LOCK_FORK_WAITING; + /* we'll never get here */ + return LIBSCP_LOCK_FORK_WAITING; } - diff --git a/sesman/libscp/libscp_lock.h b/sesman/libscp/libscp_lock.h index 5c96cc5b..b4e93c52 100644 --- a/sesman/libscp/libscp_lock.h +++ b/sesman/libscp/libscp_lock.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef LIBSCP_LOCK_H #define LIBSCP_LOCK_H @@ -72,4 +71,3 @@ void DEFAULT_CC scp_lock_fork_critical_section_end(int blocking); #endif - diff --git a/sesman/libscp/libscp_session.c b/sesman/libscp/libscp_session.c index 3ed5070a..4c389655 100644 --- a/sesman/libscp/libscp_session.c +++ b/sesman/libscp/libscp_session.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -34,379 +33,425 @@ //extern struct log_config* s_log; /*******************************************************************/ -struct SCP_SESSION* +struct SCP_SESSION * scp_session_create() { - struct SCP_SESSION* s; + struct SCP_SESSION *s; - s = (struct SCP_SESSION*)g_malloc(sizeof(struct SCP_SESSION), 1); - if (0 == s) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__); - return 0; - } - return s; + s = (struct SCP_SESSION *)g_malloc(sizeof(struct SCP_SESSION), 1); + + if (0 == s) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] session create: malloc error", __LINE__); + return 0; + } + + return s; } /*******************************************************************/ int -scp_session_set_type(struct SCP_SESSION* s, tui8 type) +scp_session_set_type(struct SCP_SESSION *s, tui8 type) { - switch (type) - { - case SCP_SESSION_TYPE_XVNC: - s->type = SCP_SESSION_TYPE_XVNC; - break; - case SCP_SESSION_TYPE_XRDP: - s->type = SCP_SESSION_TYPE_XRDP; - break; - case SCP_GW_AUTHENTICATION: - s->type = SCP_GW_AUTHENTICATION; - break; - case SCP_SESSION_TYPE_MANAGE: - s->type = SCP_SESSION_TYPE_MANAGE; - s->mng = (struct SCP_MNG_DATA*)g_malloc(sizeof(struct SCP_MNG_DATA), 1); - if (NULL == s->mng) - { - log_message(LOG_LEVEL_ERROR, "[session:%d] set_type: internal error", __LINE__); - return 1; - } - break; - default: - log_message(LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__); - return 1; - } - return 0; + switch (type) + { + case SCP_SESSION_TYPE_XVNC: + s->type = SCP_SESSION_TYPE_XVNC; + break; + case SCP_SESSION_TYPE_XRDP: + s->type = SCP_SESSION_TYPE_XRDP; + break; + case SCP_GW_AUTHENTICATION: + s->type = SCP_GW_AUTHENTICATION; + break; + case SCP_SESSION_TYPE_MANAGE: + s->type = SCP_SESSION_TYPE_MANAGE; + s->mng = (struct SCP_MNG_DATA *)g_malloc(sizeof(struct SCP_MNG_DATA), 1); + + if (NULL == s->mng) + { + log_message(LOG_LEVEL_ERROR, "[session:%d] set_type: internal error", __LINE__); + return 1; + } + + break; + default: + log_message(LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_version(struct SCP_SESSION* s, tui32 version) +scp_session_set_version(struct SCP_SESSION *s, tui32 version) { - switch (version) - { - case 0: - s->version = 0; - break; - case 1: - s->version = 1; - break; - default: - log_message(LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__); - return 1; - } - return 0; + switch (version) + { + case 0: + s->version = 0; + break; + case 1: + s->version = 1; + break; + default: + log_message(LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_height(struct SCP_SESSION* s, tui16 h) +scp_session_set_height(struct SCP_SESSION *s, tui16 h) { - s->height = h; - return 0; + s->height = h; + return 0; } /*******************************************************************/ int -scp_session_set_width(struct SCP_SESSION* s, tui16 w) +scp_session_set_width(struct SCP_SESSION *s, tui16 w) { - s->width = w; - return 0; + s->width = w; + return 0; } /*******************************************************************/ int -scp_session_set_bpp(struct SCP_SESSION* s, tui8 bpp) +scp_session_set_bpp(struct SCP_SESSION *s, tui8 bpp) { - switch (bpp) - { - case 8: - case 15: - case 16: - case 24: - s->bpp = bpp; - default: - return 1; - } - return 0; + switch (bpp) + { + case 8: + case 15: + case 16: + case 24: + s->bpp = bpp; + default: + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_rsr(struct SCP_SESSION* s, tui8 rsr) +scp_session_set_rsr(struct SCP_SESSION *s, tui8 rsr) { - if (s->rsr) - { - s->rsr = 1; - } - else - { - s->rsr = 0; - } - return 0; + if (s->rsr) + { + s->rsr = 1; + } + else + { + s->rsr = 0; + } + + return 0; } /*******************************************************************/ int -scp_session_set_locale(struct SCP_SESSION* s, char* str) +scp_session_set_locale(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__); - s->locale[0]='\0'; - return 1; - } - g_strncpy(s->locale, str, 17); - s->locale[17]='\0'; - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__); + s->locale[0] = '\0'; + return 1; + } + + g_strncpy(s->locale, str, 17); + s->locale[17] = '\0'; + return 0; } /*******************************************************************/ int -scp_session_set_username(struct SCP_SESSION* s, char* str) +scp_session_set_username(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__); - return 1; - } - if (0 != s->username) - { - g_free(s->username); - } - s->username = g_strdup(str); - if (0 == s->username) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__); + return 1; + } + + if (0 != s->username) + { + g_free(s->username); + } + + s->username = g_strdup(str); + + if (0 == s->username) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_password(struct SCP_SESSION* s, char* str) +scp_session_set_password(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__); - return 1; - } - if (0 != s->password) - { - g_free(s->password); - } - s->password = g_strdup(str); - if (0 == s->password) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__); + return 1; + } + + if (0 != s->password) + { + g_free(s->password); + } + + s->password = g_strdup(str); + + if (0 == s->password) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_domain(struct SCP_SESSION* s, char* str) +scp_session_set_domain(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: null domain", __LINE__); - return 1; - } - if (0 != s->domain) - { - g_free(s->domain); - } - s->domain = g_strdup(str); - if (0 == s->domain) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: null domain", __LINE__); + return 1; + } + + if (0 != s->domain) + { + g_free(s->domain); + } + + s->domain = g_strdup(str); + + if (0 == s->domain) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_domain: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_program(struct SCP_SESSION* s, char* str) +scp_session_set_program(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: null program", __LINE__); - return 1; - } - if (0 != s->program) - { - g_free(s->program); - } - s->program = g_strdup(str); - if (0 == s->program) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: null program", __LINE__); + return 1; + } + + if (0 != s->program) + { + g_free(s->program); + } + + s->program = g_strdup(str); + + if (0 == s->program) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_program: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_directory(struct SCP_SESSION* s, char* str) +scp_session_set_directory(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: null directory", __LINE__); - return 1; - } - if (0 != s->directory) - { - g_free(s->directory); - } - s->directory = g_strdup(str); - if (0 == s->directory) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: null directory", __LINE__); + return 1; + } + + if (0 != s->directory) + { + g_free(s->directory); + } + + s->directory = g_strdup(str); + + if (0 == s->directory) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_directory: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_client_ip(struct SCP_SESSION* s, char* str) +scp_session_set_client_ip(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: null ip", __LINE__); - return 1; - } - if (0 != s->client_ip) - { - g_free(s->client_ip); - } - s->client_ip = g_strdup(str); - if (0 == s->client_ip) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: null ip", __LINE__); + return 1; + } + + if (0 != s->client_ip) + { + g_free(s->client_ip); + } + + s->client_ip = g_strdup(str); + + if (0 == s->client_ip) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_client_ip: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_hostname(struct SCP_SESSION* s, char* str) +scp_session_set_hostname(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__); - return 1; - } - if (0 != s->hostname) - { - g_free(s->hostname); - } - s->hostname = g_strdup(str); - if (0 == s->hostname) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__); + return 1; + } + + if (0 != s->hostname) + { + g_free(s->hostname); + } + + s->hostname = g_strdup(str); + + if (0 == s->hostname) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_errstr(struct SCP_SESSION* s, char* str) +scp_session_set_errstr(struct SCP_SESSION *s, char *str) { - if (0 == str) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__); - return 1; - } - if (0 != s->errstr) - { - g_free(s->errstr); - } - s->errstr = g_strdup(str); - if (0 == s->errstr) - { - log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__); - return 1; - } - return 0; + if (0 == str) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__); + return 1; + } + + if (0 != s->errstr) + { + g_free(s->errstr); + } + + s->errstr = g_strdup(str); + + if (0 == s->errstr) + { + log_message(LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__); + return 1; + } + + return 0; } /*******************************************************************/ int -scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display) +scp_session_set_display(struct SCP_SESSION *s, SCP_DISPLAY display) { - s->display = display; - return 0; + s->display = display; + return 0; } /*******************************************************************/ int -scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr) +scp_session_set_addr(struct SCP_SESSION *s, int type, void *addr) { - struct in_addr ip4; + struct in_addr ip4; #ifdef IN6ADDR_ANY_INIT - struct in6_addr ip6; + struct in6_addr ip6; #endif - int ret; - - switch (type) - { - case SCP_ADDRESS_TYPE_IPV4: - /* convert from char to 32bit*/ - ret = inet_pton(AF_INET, addr, &ip4); - if (ret == 0) - { - log_message(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_IPV4_BIN: - g_memcpy(&(s->ipv4addr), addr, 4); - break; + int ret; + + switch (type) + { + case SCP_ADDRESS_TYPE_IPV4: + /* convert from char to 32bit*/ + ret = inet_pton(AF_INET, addr, &ip4); + + if (ret == 0) + { + log_message(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_IPV4_BIN: + g_memcpy(&(s->ipv4addr), addr, 4); + break; #ifdef IN6ADDR_ANY_INIT - case SCP_ADDRESS_TYPE_IPV6: - /* convert from char to 128bit*/ - ret = inet_pton(AF_INET6, addr, &ip6); - if (ret == 0) - { - log_message(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_IPV6_BIN: - g_memcpy(s->ipv6addr, addr, 16); - break; + case SCP_ADDRESS_TYPE_IPV6: + /* convert from char to 128bit*/ + ret = inet_pton(AF_INET6, addr, &ip6); + + if (ret == 0) + { + log_message(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_IPV6_BIN: + g_memcpy(s->ipv6addr, addr, 16); + break; #endif - default: - return 1; - } - return 0; + default: + return 1; + } + + return 0; } /*******************************************************************/ void -scp_session_destroy(struct SCP_SESSION* s) +scp_session_destroy(struct SCP_SESSION *s) { - g_free(s->username); - g_free(s->password); - g_free(s->hostname); - g_free(s->domain); - g_free(s->program); - g_free(s->directory); - g_free(s->client_ip); - g_free(s->errstr); - g_free(s->mng); - g_free(s); + g_free(s->username); + g_free(s->password); + g_free(s->hostname); + g_free(s->domain); + g_free(s->program); + g_free(s->directory); + g_free(s->client_ip); + g_free(s->errstr); + g_free(s->mng); + g_free(s); } diff --git a/sesman/libscp/libscp_session.h b/sesman/libscp/libscp_session.h index f5fe413e..b545af9e 100644 --- a/sesman/libscp/libscp_session.h +++ b/sesman/libscp/libscp_session.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_tcp.c b/sesman/libscp/libscp_tcp.c index 459992fe..29870563 100644 --- a/sesman/libscp/libscp_tcp.c +++ b/sesman/libscp/libscp_tcp.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -33,102 +32,103 @@ #include <stdlib.h> #include <string.h> -extern struct log_config* s_log; +extern struct log_config *s_log; /*****************************************************************************/ int DEFAULT_CC -scp_tcp_force_recv(int sck, char* data, int len) +scp_tcp_force_recv(int sck, char *data, int len) { - int rcvd; - int block; + int rcvd; + int block; - LOG_DBG("scp_tcp_force_recv()"); - block = scp_lock_fork_critical_section_start(); + LOG_DBG("scp_tcp_force_recv()"); + block = scp_lock_fork_critical_section_start(); - while (len > 0) - { - rcvd = g_tcp_recv(sck, data, len, 0); - if (rcvd == -1) + while (len > 0) { - if (g_tcp_last_error_would_block(sck)) - { - g_sleep(1); - } - else - { - scp_lock_fork_critical_section_end(block); - return 1; - } + rcvd = g_tcp_recv(sck, data, len, 0); + + if (rcvd == -1) + { + if (g_tcp_last_error_would_block(sck)) + { + g_sleep(1); + } + else + { + scp_lock_fork_critical_section_end(block); + return 1; + } + } + else if (rcvd == 0) + { + scp_lock_fork_critical_section_end(block); + return 1; + } + else + { + data += rcvd; + len -= rcvd; + } } - else if (rcvd == 0) - { - scp_lock_fork_critical_section_end(block); - return 1; - } - else - { - data += rcvd; - len -= rcvd; - } - } - scp_lock_fork_critical_section_end(block); + scp_lock_fork_critical_section_end(block); - return 0; + return 0; } /*****************************************************************************/ int DEFAULT_CC -scp_tcp_force_send(int sck, char* data, int len) +scp_tcp_force_send(int sck, char *data, int len) { - int sent; - int block; + int sent; + int block; - LOG_DBG("scp_tcp_force_send()"); - block = scp_lock_fork_critical_section_start(); + LOG_DBG("scp_tcp_force_send()"); + block = scp_lock_fork_critical_section_start(); - while (len > 0) - { - sent = g_tcp_send(sck, data, len, 0); - if (sent == -1) + while (len > 0) { - if (g_tcp_last_error_would_block(sck)) - { - g_sleep(1); - } - else - { - scp_lock_fork_critical_section_end(block); - return 1; - } + sent = g_tcp_send(sck, data, len, 0); + + if (sent == -1) + { + if (g_tcp_last_error_would_block(sck)) + { + g_sleep(1); + } + else + { + scp_lock_fork_critical_section_end(block); + return 1; + } + } + else if (sent == 0) + { + scp_lock_fork_critical_section_end(block); + return 1; + } + else + { + data += sent; + len -= sent; + } } - else if (sent == 0) - { - scp_lock_fork_critical_section_end(block); - return 1; - } - else - { - data += sent; - len -= sent; - } - } - scp_lock_fork_critical_section_end(block); + scp_lock_fork_critical_section_end(block); - return 0; + return 0; } /*****************************************************************************/ int DEFAULT_CC -scp_tcp_bind(int sck, char* addr, char* port) +scp_tcp_bind(int sck, char *addr, char *port) { - struct sockaddr_in s; + struct sockaddr_in s; - memset(&s, 0, sizeof(struct sockaddr_in)); - s.sin_family = AF_INET; - s.sin_port = htons(atoi(port)); - s.sin_addr.s_addr = inet_addr(addr); - return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in)); + memset(&s, 0, sizeof(struct sockaddr_in)); + s.sin_family = AF_INET; + s.sin_port = htons(atoi(port)); + s.sin_addr.s_addr = inet_addr(addr); + return bind(sck, (struct sockaddr *)&s, sizeof(struct sockaddr_in)); } - diff --git a/sesman/libscp/libscp_tcp.h b/sesman/libscp/libscp_tcp.h index 985984dc..1db70797 100644 --- a/sesman/libscp/libscp_tcp.h +++ b/sesman/libscp/libscp_tcp.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_types.h b/sesman/libscp/libscp_types.h index e6521741..2140eced 100644 --- a/sesman/libscp/libscp_types.h +++ b/sesman/libscp/libscp_types.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -43,7 +42,7 @@ #define SCP_SESSION_TYPE_XRDP 0x01 #define SCP_SESSION_TYPE_MANAGE 0x02 /* SCP_GW_AUTHENTICATION can be used when XRDP + sesman act as a gateway - * XRDP sends this command to let sesman verify if the user is allowed + * XRDP sends this command to let sesman verify if the user is allowed * to use the gateway */ #define SCP_GW_AUTHENTICATION 0x04 diff --git a/sesman/libscp/libscp_types_mng.h b/sesman/libscp/libscp_types_mng.h index e34dd413..e0edad55 100644 --- a/sesman/libscp/libscp_types_mng.h +++ b/sesman/libscp/libscp_types_mng.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_v0.c b/sesman/libscp/libscp_v0.c index f8b5a9d6..afa09bd8 100644 --- a/sesman/libscp/libscp_v0.c +++ b/sesman/libscp/libscp_v0.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -29,361 +28,386 @@ #include "os_calls.h" -extern struct log_config* s_log; +extern struct log_config *s_log; /* client API */ /******************************************************************************/ enum SCP_CLIENT_STATES_E -scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +scp_v0c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui32 version; - tui32 size; - tui16 sz; - - init_stream(c->in_s, c->in_s->size); - init_stream(c->out_s, c->in_s->size); - - LOG_DBG("[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); - - /* code */ - if (s->type == SCP_SESSION_TYPE_XVNC) - { - out_uint16_be(c->out_s, 0); - } - else if (s->type == SCP_SESSION_TYPE_XRDP) - { - out_uint16_be(c->out_s, 10); - } - else - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_INTERNAL_ERR; - } - sz = g_strlen(s->username); - out_uint16_be(c->out_s, sz); - out_uint8a(c->out_s, s->username, sz); - - sz = g_strlen(s->password); - out_uint16_be(c->out_s,sz); - out_uint8a(c->out_s, s->password, sz); - out_uint16_be(c->out_s, s->width); - out_uint16_be(c->out_s, s->height); - out_uint16_be(c->out_s, s->bpp); - - s_mark_end(c->out_s); - s_pop_layer(c->out_s, channel_hdr); - - /* 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(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(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(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(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(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) - { - log_message(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) - { - log_message(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; - - LOG_DBG("[v0:%d] connection terminated", __LINE__); - return SCP_CLIENT_STATE_END; -} + tui32 version; + tui32 size; + tui16 sz; + + init_stream(c->in_s, c->in_s->size); + init_stream(c->out_s, c->in_s->size); -/* server API */ -/******************************************************************************/ -enum SCP_SERVER_STATES_E -scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk) -{ - tui32 version = 0; - tui32 size; - struct SCP_SESSION* session = 0; - tui16 sz; - tui32 code = 0; - char buf[257]; - - if (!skipVchk) - { LOG_DBG("[v0:%d] starting connection", __LINE__); - if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + 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); + + /* code */ + if (s->type == SCP_SESSION_TYPE_XVNC) { - c->in_s->end = c->in_s->data + 8; - in_uint32_be(c->in_s, version); - if (version != 0) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); - return SCP_SERVER_STATE_VERSION_ERR; - } + out_uint16_be(c->out_s, 0); + } + else if (s->type == SCP_SESSION_TYPE_XRDP) + { + out_uint16_be(c->out_s, 10); } else { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_INTERNAL_ERR; } - } - in_uint32_be(c->in_s, size); + sz = g_strlen(s->username); + out_uint16_be(c->out_s, sz); + out_uint8a(c->out_s, s->username, sz); + + sz = g_strlen(s->password); + out_uint16_be(c->out_s, sz); + out_uint8a(c->out_s, s->password, sz); + out_uint16_be(c->out_s, s->width); + out_uint16_be(c->out_s, s->height); + out_uint16_be(c->out_s, s->bpp); - init_stream(c->in_s, 8196); - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - c->in_s->end = c->in_s->data + (size - 8); + s_mark_end(c->out_s); + s_pop_layer(c->out_s, channel_hdr); - in_uint16_be(c->in_s, code); + /* version */ + out_uint32_be(c->out_s, 0); + /* size */ + out_uint32_be(c->out_s, c->out_s->end - c->out_s->data); - if (code == 0 || code == 10) - { - session = scp_session_create(); - if (0 == session) + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data)) { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; } - scp_session_set_version(session, version); - if (code == 0) + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { - scp_session_set_type(session, SCP_SESSION_TYPE_XVNC); + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; } - else + + in_uint32_be(c->in_s, version); + + if (0 != version) { - scp_session_set_type(session, SCP_SESSION_TYPE_XRDP); + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); + return SCP_CLIENT_STATE_VERSION_ERR; } - /* reading username */ - in_uint16_be(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_username(session, buf)) + in_uint32_be(c->in_s, size); + + if (size < 14) { - scp_session_destroy(session); - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: packet size error", __LINE__); + return SCP_CLIENT_STATE_SIZE_ERR; } - /* reading password */ - in_uint16_be(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_password(session, buf)) + /* 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)) { - scp_session_destroy(session); - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; } - /* width */ + /* check code */ in_uint16_be(c->in_s, sz); - scp_session_set_width(session, sz); - /* height */ + + if (3 != sz) + { + log_message(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); - scp_session_set_height(session, sz); - /* bpp */ + + if (1 != sz) + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: connection denied", __LINE__); + return SCP_CLIENT_STATE_CONNECTION_DENIED; + } + in_uint16_be(c->in_s, sz); - scp_session_set_bpp(session, (tui8)sz); - if (s_check_rem(c->in_s, 2)) + s->display = sz; + + LOG_DBG("[v0:%d] connection terminated", __LINE__); + return SCP_CLIENT_STATE_END; +} + +/* server API */ +/******************************************************************************/ +enum SCP_SERVER_STATES_E +scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) +{ + tui32 version = 0; + tui32 size; + struct SCP_SESSION *session = 0; + tui16 sz; + tui32 code = 0; + char buf[257]; + + if (!skipVchk) { - /* reading domain */ - in_uint16_be(c->in_s, sz); - if (sz > 0) - { - in_uint8a(c->in_s, buf, sz); - buf[sz] = '\0'; - scp_session_set_domain(session, buf); - } + LOG_DBG("[v0:%d] starting connection", __LINE__); + + if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + c->in_s->end = c->in_s->data + 8; + in_uint32_be(c->in_s, version); + + if (version != 0) + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__); + return SCP_SERVER_STATE_VERSION_ERR; + } + } + else + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } } - if (s_check_rem(c->in_s, 2)) + + in_uint32_be(c->in_s, size); + + init_stream(c->in_s, 8196); + + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) { - /* reading program */ - in_uint16_be(c->in_s, sz); - if (sz > 0) - { - in_uint8a(c->in_s, buf, sz); - buf[sz] = '\0'; - scp_session_set_program(session, buf); - } + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; } - if (s_check_rem(c->in_s, 2)) + + c->in_s->end = c->in_s->data + (size - 8); + + in_uint16_be(c->in_s, code); + + if (code == 0 || code == 10) { - /* reading directory */ - in_uint16_be(c->in_s, sz); - if (sz > 0) - { + session = scp_session_create(); + + if (0 == session) + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, version); + + if (code == 0) + { + scp_session_set_type(session, SCP_SESSION_TYPE_XVNC); + } + else + { + scp_session_set_type(session, SCP_SESSION_TYPE_XRDP); + } + + /* reading username */ + in_uint16_be(c->in_s, sz); + buf[sz] = '\0'; in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + in_uint16_be(c->in_s, sz); buf[sz] = '\0'; - scp_session_set_directory(session, buf); - } + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* width */ + in_uint16_be(c->in_s, sz); + scp_session_set_width(session, sz); + /* height */ + in_uint16_be(c->in_s, sz); + scp_session_set_height(session, sz); + /* bpp */ + in_uint16_be(c->in_s, sz); + scp_session_set_bpp(session, (tui8)sz); + + if (s_check_rem(c->in_s, 2)) + { + /* reading domain */ + in_uint16_be(c->in_s, sz); + + if (sz > 0) + { + in_uint8a(c->in_s, buf, sz); + buf[sz] = '\0'; + scp_session_set_domain(session, buf); + } + } + + if (s_check_rem(c->in_s, 2)) + { + /* reading program */ + in_uint16_be(c->in_s, sz); + + if (sz > 0) + { + in_uint8a(c->in_s, buf, sz); + buf[sz] = '\0'; + scp_session_set_program(session, buf); + } + } + + if (s_check_rem(c->in_s, 2)) + { + /* reading directory */ + in_uint16_be(c->in_s, sz); + + if (sz > 0) + { + in_uint8a(c->in_s, buf, sz); + buf[sz] = '\0'; + scp_session_set_directory(session, buf); + } + } + + if (s_check_rem(c->in_s, 2)) + { + /* reading client IP address */ + in_uint16_be(c->in_s, sz); + + if (sz > 0) + { + in_uint8a(c->in_s, buf, sz); + buf[sz] = '\0'; + scp_session_set_client_ip(session, buf); + } + } } - if (s_check_rem(c->in_s, 2)) + else if (code == SCP_GW_AUTHENTICATION) { - /* reading client IP address */ - in_uint16_be(c->in_s, sz); - if (sz > 0) - { + /* g_writeln("Command is SCP_GW_AUTHENTICATION"); */ + session = scp_session_create(); + + if (0 == session) + { + /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);*/ + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, version); + scp_session_set_type(session, SCP_GW_AUTHENTICATION); + /* reading username */ + in_uint16_be(c->in_s, sz); + buf[sz] = '\0'; in_uint8a(c->in_s, buf, sz); + + /* g_writeln("Received user name: %s",buf); */ + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);*/ + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + in_uint16_be(c->in_s, sz); buf[sz] = '\0'; - scp_session_set_client_ip(session, buf); - } - } - } - else if (code == SCP_GW_AUTHENTICATION) - { - /* g_writeln("Command is SCP_GW_AUTHENTICATION"); */ - session = scp_session_create(); - if (0 == session) - { - /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);*/ - return SCP_SERVER_STATE_INTERNAL_ERR; - } + in_uint8a(c->in_s, buf, sz); - scp_session_set_version(session, version); - scp_session_set_type(session, SCP_GW_AUTHENTICATION); - /* reading username */ - in_uint16_be(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - /* g_writeln("Received user name: %s",buf); */ - if (0 != scp_session_set_username(session, buf)) - { - scp_session_destroy(session); - /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);*/ - return SCP_SERVER_STATE_INTERNAL_ERR; + /* g_writeln("Received password: %s",buf); */ + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */ + return SCP_SERVER_STATE_INTERNAL_ERR; + } } - - /* reading password */ - in_uint16_be(c->in_s, sz); - buf[sz] = '\0'; - in_uint8a(c->in_s, buf, sz); - /* g_writeln("Received password: %s",buf); */ - if (0 != scp_session_set_password(session, buf)) + else { - scp_session_destroy(session); - /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */ - return SCP_SERVER_STATE_INTERNAL_ERR; + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; } - } - else - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - (*s)=session; - return SCP_SERVER_STATE_OK; + + (*s) = session; + return SCP_SERVER_STATE_OK; } /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_DISPLAY d) +scp_v0s_allow_connection(struct SCP_CONNECTION *c, SCP_DISPLAY d) { - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, 14); /* size */ - out_uint16_be(c->out_s, 3); /* cmd */ - out_uint16_be(c->out_s, 1); /* data */ - 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)) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__); - return SCP_SERVER_STATE_OK; + out_uint32_be(c->out_s, 0); /* version */ + out_uint32_be(c->out_s, 14); /* size */ + out_uint16_be(c->out_s, 3); /* cmd */ + out_uint16_be(c->out_s, 1); /* data */ + 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)) + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__); + return SCP_SERVER_STATE_OK; } /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_deny_connection(struct SCP_CONNECTION* c) +scp_v0s_deny_connection(struct SCP_CONNECTION *c) { - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, 14); /* size */ - out_uint16_be(c->out_s, 3); /* cmd */ - out_uint16_be(c->out_s, 0); /* data = 0 - means NOT ok*/ - out_uint16_be(c->out_s, 0); /* reserved for display number*/ - 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)) - { - log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__); - return SCP_SERVER_STATE_OK; + out_uint32_be(c->out_s, 0); /* version */ + out_uint32_be(c->out_s, 14); /* size */ + out_uint16_be(c->out_s, 3); /* cmd */ + out_uint16_be(c->out_s, 0); /* data = 0 - means NOT ok*/ + out_uint16_be(c->out_s, 0); /* reserved for display number*/ + 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)) + { + log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__); + return SCP_SERVER_STATE_OK; } /******************************************************************************/ enum SCP_SERVER_STATES_E -scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value) +scp_v0s_replyauthentication(struct SCP_CONNECTION *c, unsigned short int value) { - out_uint32_be(c->out_s, 0); /* version */ - out_uint32_be(c->out_s, 14); /* size */ - /* cmd SCP_GW_AUTHENTICATION means authentication reply */ - out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION); - out_uint16_be(c->out_s, value); /* reply code */ - out_uint16_be(c->out_s, 0); /* dummy data */ - s_mark_end(c->out_s); - - /* g_writeln("Total number of bytes that will be sent %d",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)) - { - /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */ - return SCP_SERVER_STATE_NETWORK_ERR; - } - - /* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/ - return SCP_SERVER_STATE_OK; + out_uint32_be(c->out_s, 0); /* version */ + out_uint32_be(c->out_s, 14); /* size */ + /* cmd SCP_GW_AUTHENTICATION means authentication reply */ + out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION); + out_uint16_be(c->out_s, value); /* reply code */ + out_uint16_be(c->out_s, 0); /* dummy data */ + s_mark_end(c->out_s); + + /* g_writeln("Total number of bytes that will be sent %d",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)) + { + /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */ + return SCP_SERVER_STATE_NETWORK_ERR; + } + + /* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/ + return SCP_SERVER_STATE_OK; } diff --git a/sesman/libscp/libscp_v0.h b/sesman/libscp/libscp_v0.h index 92b835f0..16e49e05 100644 --- a/sesman/libscp/libscp_v0.h +++ b/sesman/libscp/libscp_v0.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -39,7 +38,7 @@ * @param d display * */ -enum SCP_CLIENT_STATES_E +enum SCP_CLIENT_STATES_E scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s); /* server API */ @@ -52,7 +51,7 @@ scp_v0c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s); * scp_vXs_accept() ) * */ -enum SCP_SERVER_STATES_E +enum SCP_SERVER_STATES_E scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk); /** @@ -61,7 +60,7 @@ scp_v0s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk); * @param c connection descriptor * */ -enum SCP_SERVER_STATES_E +enum SCP_SERVER_STATES_E scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_DISPLAY d); /** @@ -70,17 +69,16 @@ scp_v0s_allow_connection(struct SCP_CONNECTION* c, SCP_DISPLAY d); * @param c connection descriptor * */ -enum SCP_SERVER_STATES_E +enum SCP_SERVER_STATES_E scp_v0s_deny_connection(struct SCP_CONNECTION* c); /** * @brief send reply to an authentication request * @param c connection descriptor * @param value the reply code 0 means ok - * @return + * @return */ enum SCP_SERVER_STATES_E scp_v0s_replyauthentication(struct SCP_CONNECTION* c, unsigned short int value); #endif - diff --git a/sesman/libscp/libscp_v1c.c b/sesman/libscp/libscp_v1c.c index 6e1c3b8a..7d1b9db8 100644 --- a/sesman/libscp/libscp_v1c.c +++ b/sesman/libscp/libscp_v1c.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -31,443 +30,477 @@ #include <stdio.h> static enum SCP_CLIENT_STATES_E -_scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +_scp_v1c_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s); /* client API */ /* 001 */ enum SCP_CLIENT_STATES_E -scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +scp_v1c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui8 sz; - tui32 size; - - init_stream(c->out_s, c->out_s->size); - init_stream(c->in_s, c->in_s->size); - - size = 19 + 17 + 4 + g_strlen(s->hostname) + g_strlen(s->username) + - g_strlen(s->password); - if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) - { - size = size + 4; - } - else - { - size = size + 16; - } - - /* sending request */ - - /* header */ - out_uint32_be(c->out_s, 1); /* version */ - out_uint32_be(c->out_s, size); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, 1); - - /* body */ - out_uint8(c->out_s, s->type); - out_uint16_be(c->out_s, s->height); - out_uint16_be(c->out_s, s->width); - out_uint8(c->out_s, s->bpp); - out_uint8(c->out_s, s->rsr); - out_uint8p(c->out_s, s->locale, 17); - out_uint8(c->out_s, s->addr_type); - - if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) - { - out_uint32_be(c->out_s, s->ipv4addr); - } - else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6) - { - out_uint8p(c->out_s, s->ipv6addr, 16); - } - - sz = g_strlen(s->hostname); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->hostname, sz); - sz = g_strlen(s->username); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->username, sz); - sz = g_strlen(s->password); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->password, sz); - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - /* wait for response */ - return _scp_v1c_check_response(c, s); + tui8 sz; + tui32 size; + + init_stream(c->out_s, c->out_s->size); + init_stream(c->in_s, c->in_s->size); + + size = 19 + 17 + 4 + g_strlen(s->hostname) + g_strlen(s->username) + + g_strlen(s->password); + + if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) + { + size = size + 4; + } + else + { + size = size + 16; + } + + /* sending request */ + + /* header */ + out_uint32_be(c->out_s, 1); /* version */ + out_uint32_be(c->out_s, size); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, 1); + + /* body */ + out_uint8(c->out_s, s->type); + out_uint16_be(c->out_s, s->height); + out_uint16_be(c->out_s, s->width); + out_uint8(c->out_s, s->bpp); + out_uint8(c->out_s, s->rsr); + out_uint8p(c->out_s, s->locale, 17); + out_uint8(c->out_s, s->addr_type); + + if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) + { + out_uint32_be(c->out_s, s->ipv4addr); + } + else if (s->addr_type == SCP_ADDRESS_TYPE_IPV6) + { + out_uint8p(c->out_s, s->ipv6addr, 16); + } + + sz = g_strlen(s->hostname); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->hostname, sz); + sz = g_strlen(s->username); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->username, sz); + sz = g_strlen(s->password); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->password, sz); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + /* wait for response */ + return _scp_v1c_check_response(c, s); } /* 004 */ enum SCP_CLIENT_STATES_E -scp_v1c_resend_credentials(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +scp_v1c_resend_credentials(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui8 sz; - tui32 size; - - init_stream(c->out_s, c->out_s->size); - init_stream(c->in_s, c->in_s->size); - - size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password); - - /* sending request */ - /* header */ - out_uint32_be(c->out_s, 1); /* version */ - out_uint32_be(c->out_s, size); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, 4); - - /* body */ - sz = g_strlen(s->username); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->username, sz); - sz = g_strlen(s->password); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->password, sz); - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - /* wait for response */ - return _scp_v1c_check_response(c, s); + tui8 sz; + tui32 size; + + init_stream(c->out_s, c->out_s->size); + init_stream(c->in_s, c->in_s->size); + + size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password); + + /* sending request */ + /* header */ + out_uint32_be(c->out_s, 1); /* version */ + out_uint32_be(c->out_s, size); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, 4); + + /* body */ + sz = g_strlen(s->username); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->username, sz); + sz = g_strlen(s->password); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->password, sz); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + /* wait for response */ + return _scp_v1c_check_response(c, s); } /* 021 */ enum SCP_CLIENT_STATES_E -scp_v1c_pwd_change(struct SCP_CONNECTION* c, char* newpass); +scp_v1c_pwd_change(struct SCP_CONNECTION *c, char *newpass); /* 022 */ enum SCP_CLIENT_STATES_E -scp_v1c_pwd_change_cancel(struct SCP_CONNECTION* c); +scp_v1c_pwd_change_cancel(struct SCP_CONNECTION *c); /* 041 */ enum SCP_CLIENT_STATES_E -scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, - struct SCP_DISCONNECTED_SESSION** s) +scp_v1c_get_session_list(struct SCP_CONNECTION *c, int *scount, + struct SCP_DISCONNECTED_SESSION **s) +{ + tui32 version = 1; + tui32 size = 12; + tui16 cmd = 41; + tui32 sescnt = 0; /* total session number */ + tui32 sestmp = 0; /* additional total session number */ + tui8 pktcnt = 0; /* packet session count */ + tui32 totalcnt = 0; /* session counter */ + tui8 continued = 0; /* continue flag */ + int firstpkt = 1; /* "first packet" flag */ + int idx; + struct SCP_DISCONNECTED_SESSION *ds = 0; + + init_stream(c->out_s, c->out_s->size); + + /* we request session list */ + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + do + { + /* then we wait for server response */ + init_stream(c->in_s, c->in_s->size); + + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + in_uint32_be(c->in_s, version); + + if (version != 1) + { + return SCP_CLIENT_STATE_VERSION_ERR; + } + + in_uint32_be(c->in_s, size); + + if (size < 12) + { + return SCP_CLIENT_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)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + in_uint16_be(c->in_s, cmd); + + if (cmd != SCP_COMMAND_SET_DEFAULT) + { + return SCP_CLIENT_STATE_SEQUENCE_ERR; + } + + in_uint16_be(c->in_s, cmd); + + if (cmd != 42) + { + return SCP_CLIENT_STATE_SEQUENCE_ERR; + } + + if (firstpkt) + { + firstpkt = 0; + in_uint32_be(c->in_s, sescnt); + sestmp = sescnt; + + ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0); + + if (ds == 0) + { + return SCP_CLIENT_STATE_INTERNAL_ERR; + } + } + else + { + in_uint32_be(c->in_s, sestmp); + } + + in_uint8(c->in_s, continued); + in_uint8(c->in_s, pktcnt); + + for (idx = 0; idx < pktcnt; idx++) + { + in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */ + in_uint8(c->in_s, (ds[totalcnt]).type); + in_uint16_be(c->in_s, (ds[totalcnt]).height); + in_uint16_be(c->in_s, (ds[totalcnt]).width); + in_uint8(c->in_s, (ds[totalcnt]).bpp); + 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++; + } + } + while (continued); + + printf("fine\n"); + /* return data... */ + (*scount) = sescnt; + (*s) = ds; + + return SCP_CLIENT_STATE_LIST_OK; +} + +/* 043 */ +enum SCP_CLIENT_STATES_E +scp_v1c_select_session(struct SCP_CONNECTION *c, struct SCP_SESSION *s, + SCP_SID sid) { - tui32 version = 1; - tui32 size = 12; - tui16 cmd = 41; - tui32 sescnt = 0; /* total session number */ - tui32 sestmp = 0; /* additional total session number */ - tui8 pktcnt = 0; /* packet session count */ - tui32 totalcnt = 0; /* session counter */ - tui8 continued = 0; /* continue flag */ - int firstpkt = 1; /* "first packet" flag */ - int idx; - struct SCP_DISCONNECTED_SESSION* ds = 0; - - init_stream(c->out_s, c->out_s->size); - - /* we request session list */ - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - do - { - /* then we wait for server response */ + tui32 version = 1; + tui32 size = 16; + tui16 cmd = 43; + + init_stream(c->out_s, c->out_s->size); + + /* sending our selection */ + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + out_uint32_be(c->out_s, sid); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + /* waiting for response.... */ init_stream(c->in_s, c->in_s->size); + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { - return SCP_CLIENT_STATE_NETWORK_ERR; + return SCP_CLIENT_STATE_NETWORK_ERR; } in_uint32_be(c->in_s, version); + if (version != 1) { - return SCP_CLIENT_STATE_VERSION_ERR; + return SCP_CLIENT_STATE_VERSION_ERR; } in_uint32_be(c->in_s, size); + if (size < 12) { - return SCP_CLIENT_STATE_SIZE_ERR; + return SCP_CLIENT_STATE_SIZE_ERR; } init_stream(c->in_s, c->in_s->size); + + /* read the rest of the packet */ if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) { - return SCP_CLIENT_STATE_NETWORK_ERR; + return SCP_CLIENT_STATE_NETWORK_ERR; } in_uint16_be(c->in_s, cmd); + if (cmd != SCP_COMMAND_SET_DEFAULT) { - return SCP_CLIENT_STATE_SEQUENCE_ERR; + return SCP_CLIENT_STATE_SEQUENCE_ERR; } in_uint16_be(c->in_s, cmd); - if (cmd != 42) - { - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } - - if (firstpkt) - { - firstpkt = 0; - in_uint32_be(c->in_s, sescnt); - sestmp = sescnt; - - ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0); - if (ds == 0) - { - return SCP_CLIENT_STATE_INTERNAL_ERR; - } - } - else - { - in_uint32_be(c->in_s, sestmp); - } - in_uint8(c->in_s, continued); - in_uint8(c->in_s, pktcnt); - for (idx = 0; idx < pktcnt; idx++) + if (cmd != 46) { - in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */ - in_uint8(c->in_s, (ds[totalcnt]).type); - in_uint16_be(c->in_s, (ds[totalcnt]).height); - in_uint16_be(c->in_s, (ds[totalcnt]).width); - in_uint8(c->in_s, (ds[totalcnt]).bpp); - 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++; + return SCP_CLIENT_STATE_SEQUENCE_ERR; } - } - while (continued); - printf("fine\n"); - /* return data... */ - (*scount) = sescnt; - (*s) = ds; + /* session display */ + in_uint16_be(c->in_s, (s->display)); + /*we don't need to return any data other than the display */ + /*because we already sent that */ - return SCP_CLIENT_STATE_LIST_OK; + return SCP_CLIENT_STATE_OK; } -/* 043 */ +/* 044 */ enum SCP_CLIENT_STATES_E -scp_v1c_select_session(struct SCP_CONNECTION* c, struct SCP_SESSION* s, - SCP_SID sid) +scp_v1c_select_session_cancel(struct SCP_CONNECTION *c) { - tui32 version = 1; - tui32 size = 16; - tui16 cmd = 43; - - init_stream(c->out_s, c->out_s->size); - - /* sending our selection */ - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ - - out_uint32_be(c->out_s, sid); - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - /* waiting for response.... */ - init_stream(c->in_s, c->in_s->size); - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - in_uint32_be(c->in_s, version); - if (version != 1) - { - return SCP_CLIENT_STATE_VERSION_ERR; - } - - in_uint32_be(c->in_s, size); - if (size < 12) - { - return SCP_CLIENT_STATE_SIZE_ERR; - } - - init_stream(c->in_s, c->in_s->size); - /* read the rest of the packet */ - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_COMMAND_SET_DEFAULT) - { - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } + tui32 version = 1; + tui32 size = 12; + tui16 cmd = 44; - in_uint16_be(c->in_s, cmd); - if (cmd != 46) - { - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } + init_stream(c->out_s, c->out_s->size); - /* session display */ - in_uint16_be(c->in_s, (s->display)); - /*we don't need to return any data other than the display */ - /*because we already sent that */ + /* sending our selection */ + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } - return SCP_CLIENT_STATE_OK; + return SCP_CLIENT_STATE_END; } -/* 044 */ -enum SCP_CLIENT_STATES_E -scp_v1c_select_session_cancel(struct SCP_CONNECTION* c) +static enum SCP_CLIENT_STATES_E +_scp_v1c_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui32 version = 1; - tui32 size = 12; - tui16 cmd = 44; + tui32 version; + tui32 size; + tui16 cmd; + tui16 dim; - init_stream(c->out_s, c->out_s->size); + init_stream(c->in_s, c->in_s->size); - /* sending our selection */ - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } + in_uint32_be(c->in_s, version); - return SCP_CLIENT_STATE_END; -} + if (version != 1) + { + return SCP_CLIENT_STATE_VERSION_ERR; + } -static enum SCP_CLIENT_STATES_E -_scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s) -{ - tui32 version; - tui32 size; - tui16 cmd; - tui16 dim; - - init_stream(c->in_s, c->in_s->size); - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - in_uint32_be(c->in_s, version); - if (version != 1) - { - return SCP_CLIENT_STATE_VERSION_ERR; - } - - in_uint32_be(c->in_s, size); - - init_stream(c->in_s, c->in_s->size); - /* read the rest of the packet */ - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - return SCP_CLIENT_STATE_NETWORK_ERR; - } - - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_COMMAND_SET_DEFAULT) - { - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } + in_uint32_be(c->in_s, size); + + init_stream(c->in_s, c->in_s->size); + + /* read the rest of the packet */ + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) + { + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + in_uint16_be(c->in_s, cmd); - in_uint16_be(c->in_s, cmd); - if (cmd == 2) /* connection denied */ - { - in_uint16_be(c->in_s, dim); - if (s->errstr != 0) + if (cmd != SCP_COMMAND_SET_DEFAULT) { - g_free(s->errstr); + return SCP_CLIENT_STATE_SEQUENCE_ERR; } - s->errstr = g_malloc(dim + 1, 0); - if (s->errstr == 0) + + in_uint16_be(c->in_s, cmd); + + if (cmd == 2) /* connection denied */ { - return SCP_CLIENT_STATE_INTERNAL_ERR; + in_uint16_be(c->in_s, dim); + + if (s->errstr != 0) + { + g_free(s->errstr); + } + + s->errstr = g_malloc(dim + 1, 0); + + if (s->errstr == 0) + { + return SCP_CLIENT_STATE_INTERNAL_ERR; + } + + in_uint8a(c->in_s, s->errstr, dim); + (s->errstr)[dim] = '\0'; + + return SCP_CLIENT_STATE_CONNECTION_DENIED; } - in_uint8a(c->in_s, s->errstr, dim); - (s->errstr)[dim] = '\0'; - - return SCP_CLIENT_STATE_CONNECTION_DENIED; - } - else if (cmd == 3) /* resend usr/pwd */ - { - in_uint16_be(c->in_s, dim); - if (s->errstr != 0) + else if (cmd == 3) /* resend usr/pwd */ { - g_free(s->errstr); + in_uint16_be(c->in_s, dim); + + if (s->errstr != 0) + { + g_free(s->errstr); + } + + s->errstr = g_malloc(dim + 1, 0); + + if (s->errstr == 0) + { + return SCP_CLIENT_STATE_INTERNAL_ERR; + } + + in_uint8a(c->in_s, s->errstr, dim); + (s->errstr)[dim] = '\0'; + + return SCP_CLIENT_STATE_RESEND_CREDENTIALS; } - s->errstr = g_malloc(dim + 1, 0); - if (s->errstr == 0) + else if (cmd == 20) /* password change */ { - return SCP_CLIENT_STATE_INTERNAL_ERR; + in_uint16_be(c->in_s, dim); + + if (s->errstr != 0) + { + g_free(s->errstr); + } + + s->errstr = g_malloc(dim + 1, 0); + + if (s->errstr == 0) + { + return SCP_CLIENT_STATE_INTERNAL_ERR; + } + + in_uint8a(c->in_s, s->errstr, dim); + (s->errstr)[dim] = '\0'; + + return SCP_CLIENT_STATE_PWD_CHANGE_REQ; } - in_uint8a(c->in_s, s->errstr, dim); - (s->errstr)[dim] = '\0'; - - return SCP_CLIENT_STATE_RESEND_CREDENTIALS; - } - else if (cmd == 20) /* password change */ - { - in_uint16_be(c->in_s, dim); - if (s->errstr != 0) + else if (cmd == 30) /* display */ { - g_free(s->errstr); + in_uint16_be(c->in_s, s->display); + + return SCP_CLIENT_STATE_OK; } - s->errstr = g_malloc(dim + 1, 0); - if (s->errstr == 0) + //else if (cmd == 31) /* there's a disconnected session */ + //{ + // return SCP_CLIENT_STATE_RECONNECT_SINGLE; + //} + //else if (cmd == 33) /* display of a disconnected session */ + //{ + // return SCP_CLIENT_STATE_RECONNECT; + //} + else if (cmd == 40) /* session list */ { - return SCP_CLIENT_STATE_INTERNAL_ERR; + return SCP_CLIENT_STATE_SESSION_LIST; } - in_uint8a(c->in_s, s->errstr, dim); - (s->errstr)[dim] = '\0'; - - return SCP_CLIENT_STATE_PWD_CHANGE_REQ; - } - else if (cmd == 30) /* display */ - { - in_uint16_be(c->in_s, s->display); - return SCP_CLIENT_STATE_OK; - } - //else if (cmd == 31) /* there's a disconnected session */ - //{ - // return SCP_CLIENT_STATE_RECONNECT_SINGLE; - //} - //else if (cmd == 33) /* display of a disconnected session */ - //{ - // return SCP_CLIENT_STATE_RECONNECT; - //} - else if (cmd == 40) /* session list */ - { - return SCP_CLIENT_STATE_SESSION_LIST; - } - - return SCP_CLIENT_STATE_SEQUENCE_ERR; + return SCP_CLIENT_STATE_SEQUENCE_ERR; } diff --git a/sesman/libscp/libscp_v1c.h b/sesman/libscp/libscp_v1c.h index f6fd4492..ef5a06cb 100644 --- a/sesman/libscp/libscp_v1c.h +++ b/sesman/libscp/libscp_v1c.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_v1c_mng.c b/sesman/libscp/libscp_v1c_mng.c index 88f86f4f..59762e36 100644 --- a/sesman/libscp/libscp_v1c_mng.c +++ b/sesman/libscp/libscp_v1c_mng.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -33,215 +32,228 @@ //extern struct log_config* s_log; static enum SCP_CLIENT_STATES_E -_scp_v1c_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +_scp_v1c_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s); /* client API */ /* 001 */ enum SCP_CLIENT_STATES_E -scp_v1c_mng_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +scp_v1c_mng_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui8 sz; - tui32 size; - - init_stream(c->out_s, c->out_s->size); - init_stream(c->in_s, c->in_s->size); + tui8 sz; + tui32 size; - size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) + - g_strlen(s->password); - if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) - { - size = size + 4; - } - else - { - size = size + 16; - } - - /* sending request */ - - /* header */ - out_uint32_be(c->out_s, 1); /* version */ - out_uint32_be(c->out_s, size); - out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); - out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN); - - /* data */ - sz = g_strlen(s->username); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->username, sz); - sz = g_strlen(s->password); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->password, sz); - - /* address */ - out_uint8(c->out_s, s->addr_type); - if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) - { - out_uint32_be(c->out_s, s->ipv4addr); - } - else - { - out_uint8p(c->out_s, s->ipv6addr, 16); - } - - /* hostname */ - sz = g_strlen(s->hostname); - out_uint8(c->out_s, sz); - out_uint8p(c->out_s, s->hostname, sz); - - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + init_stream(c->out_s, c->out_s->size); + init_stream(c->in_s, c->in_s->size); - /* wait for response */ - return _scp_v1c_mng_check_response(c, s); -} + size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) + + g_strlen(s->password); -/* 004 */ -enum SCP_CLIENT_STATES_E -scp_v1c_mng_get_session_list(struct SCP_CONNECTION* c, int* scount, - struct SCP_DISCONNECTED_SESSION** s) -{ - tui32 version = 1; - tui32 size = 12; - tui16 cmd = SCP_CMD_MNG_LIST_REQ; /* request session list */ - tui32 sescnt = 0; /* total session number */ - tui32 sestmp = 0; /* additional total session number */ - tui8 pktcnt = 0; /* packet session count */ - tui32 totalcnt = 0; /* session counter */ - tui8 continued = 0; /* continue flag */ - int firstpkt = 1; /* "first packet" flag */ - int idx; - struct SCP_DISCONNECTED_SESSION* ds = 0; -// tui8 addr[16]; + if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) + { + size = size + 4; + } + else + { + size = size + 16; + } - init_stream(c->out_s, c->out_s->size); + /* sending request */ - /* we request session list */ - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ + /* header */ + out_uint32_be(c->out_s, 1); /* version */ + out_uint32_be(c->out_s, size); + out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); + out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN); - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + /* data */ + sz = g_strlen(s->username); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->username, sz); + sz = g_strlen(s->password); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->password, sz); - do - { - /* then we wait for server response */ - 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(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + /* address */ + out_uint8(c->out_s, s->addr_type); - in_uint32_be(c->in_s, version); - if (version != 1) + if (s->addr_type == SCP_ADDRESS_TYPE_IPV4) { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__); - return SCP_CLIENT_STATE_VERSION_ERR; + out_uint32_be(c->out_s, s->ipv4addr); } - - in_uint32_be(c->in_s, size); - if (size < 12) + else { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: size error", __LINE__); - return SCP_CLIENT_STATE_SIZE_ERR; + out_uint8p(c->out_s, s->ipv6addr, 16); } - 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(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + /* hostname */ + sz = g_strlen(s->hostname); + out_uint8(c->out_s, sz); + out_uint8p(c->out_s, s->hostname, sz); - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_COMMAND_SET_MANAGE) + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); - return SCP_CLIENT_STATE_SEQUENCE_ERR; + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; } - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_CMD_MNG_LIST) /* session list */ - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } + /* wait for response */ + return _scp_v1c_mng_check_response(c, s); +} - if (firstpkt) - { - firstpkt = 0; - in_uint32_be(c->in_s, sescnt); - sestmp = sescnt; - - if (0 == sescnt) - { - /* return data... */ - (*scount) = sescnt; - (*s) = NULL; - - LOG_DBG("[v1c_mng] end list - no session on TS"); - return SCP_CLIENT_STATE_LIST_OK; - } - - ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0); - if (ds == 0) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: internal error", __LINE__); - return SCP_CLIENT_STATE_INTERNAL_ERR; - } - } - else +/* 004 */ +enum SCP_CLIENT_STATES_E +scp_v1c_mng_get_session_list(struct SCP_CONNECTION *c, int *scount, + struct SCP_DISCONNECTED_SESSION **s) +{ + tui32 version = 1; + tui32 size = 12; + tui16 cmd = SCP_CMD_MNG_LIST_REQ; /* request session list */ + tui32 sescnt = 0; /* total session number */ + tui32 sestmp = 0; /* additional total session number */ + tui8 pktcnt = 0; /* packet session count */ + tui32 totalcnt = 0; /* session counter */ + tui8 continued = 0; /* continue flag */ + int firstpkt = 1; /* "first packet" flag */ + int idx; + struct SCP_DISCONNECTED_SESSION *ds = 0; + // tui8 addr[16]; + + init_stream(c->out_s, c->out_s->size); + + /* we request session list */ + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) { - in_uint32_be(c->in_s, sestmp); + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; } - in_uint8(c->in_s, continued); - in_uint8(c->in_s, pktcnt); - for (idx = 0; idx < pktcnt; idx++) + do { - in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */ - in_uint8(c->in_s, (ds[totalcnt]).type); - in_uint16_be(c->in_s, (ds[totalcnt]).height); - in_uint16_be(c->in_s, (ds[totalcnt]).width); - in_uint8(c->in_s, (ds[totalcnt]).bpp); - 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); - } - if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6) - { - in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16); - } - totalcnt++; + /* then we wait for server response */ + 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(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + in_uint32_be(c->in_s, version); + + if (version != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__); + return SCP_CLIENT_STATE_VERSION_ERR; + } + + in_uint32_be(c->in_s, size); + + if (size < 12) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: size error", __LINE__); + return SCP_CLIENT_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(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; + } + + in_uint16_be(c->in_s, cmd); + + if (cmd != SCP_COMMAND_SET_MANAGE) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); + return SCP_CLIENT_STATE_SEQUENCE_ERR; + } + + in_uint16_be(c->in_s, cmd); + + if (cmd != SCP_CMD_MNG_LIST) /* session list */ + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); + return SCP_CLIENT_STATE_SEQUENCE_ERR; + } + + if (firstpkt) + { + firstpkt = 0; + in_uint32_be(c->in_s, sescnt); + sestmp = sescnt; + + if (0 == sescnt) + { + /* return data... */ + (*scount) = sescnt; + (*s) = NULL; + + LOG_DBG("[v1c_mng] end list - no session on TS"); + return SCP_CLIENT_STATE_LIST_OK; + } + + ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0); + + if (ds == 0) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: internal error", __LINE__); + return SCP_CLIENT_STATE_INTERNAL_ERR; + } + } + else + { + in_uint32_be(c->in_s, sestmp); + } + + in_uint8(c->in_s, continued); + in_uint8(c->in_s, pktcnt); + + for (idx = 0; idx < pktcnt; idx++) + { + in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */ + in_uint8(c->in_s, (ds[totalcnt]).type); + in_uint16_be(c->in_s, (ds[totalcnt]).height); + in_uint16_be(c->in_s, (ds[totalcnt]).width); + in_uint8(c->in_s, (ds[totalcnt]).bpp); + 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); + } + + if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6) + { + in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16); + } + + totalcnt++; + } } - } - while (continued); + while (continued); - /* return data... */ - (*scount) = sescnt; - (*s) = ds; + /* return data... */ + (*scount) = sescnt; + (*s) = ds; - LOG_DBG("[v1c_mng] end list"); - return SCP_CLIENT_STATE_LIST_OK; + LOG_DBG("[v1c_mng] end list"); + return SCP_CLIENT_STATE_LIST_OK; } /* 043 * / @@ -339,62 +351,67 @@ scp_v1c_select_session_cancel(struct SCP_CONNECTION* c) }*/ static enum SCP_CLIENT_STATES_E -_scp_v1c_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +_scp_v1c_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - tui32 version; - tui32 size; - tui16 cmd; - tui8 dim; - char buf[257]; + tui32 version; + tui32 size; + tui16 cmd; + tui8 dim; + char buf[257]; - 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(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + init_stream(c->in_s, c->in_s->size); - in_uint32_be(c->in_s, version); - if (version != 1) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__); - return SCP_CLIENT_STATE_VERSION_ERR; - } + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; + } - in_uint32_be(c->in_s, size); + in_uint32_be(c->in_s, version); - init_stream(c->in_s, c->in_s->size); - /* read the rest of the packet */ - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); - return SCP_CLIENT_STATE_NETWORK_ERR; - } + if (version != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__); + return SCP_CLIENT_STATE_VERSION_ERR; + } - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_COMMAND_SET_MANAGE) - { - log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); - return SCP_CLIENT_STATE_SEQUENCE_ERR; - } + in_uint32_be(c->in_s, size); - in_uint16_be(c->in_s, cmd); - if (cmd == SCP_CMD_MNG_LOGIN_ALLOW) /* connection ok */ - { - log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection ok", __LINE__); - return SCP_CLIENT_STATE_OK; - } - else if (cmd == SCP_CMD_MNG_LOGIN_DENY) /* connection denied */ - { - in_uint8(c->in_s, dim); - buf[dim]='\0'; - in_uint8a(c->in_s, buf, dim); - scp_session_set_errstr(s, buf); + init_stream(c->in_s, c->in_s->size); - log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection denied: %s", __LINE__ , s->errstr); - return SCP_CLIENT_STATE_CONNECTION_DENIED; - } + /* read the rest of the packet */ + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__); + return SCP_CLIENT_STATE_NETWORK_ERR; + } - log_message(LOG_LEVEL_WARNING, "[v1c-mng:%d] connection aborted: sequence error", __LINE__); - return SCP_CLIENT_STATE_SEQUENCE_ERR; + in_uint16_be(c->in_s, cmd); + + if (cmd != SCP_COMMAND_SET_MANAGE) + { + log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__); + return SCP_CLIENT_STATE_SEQUENCE_ERR; + } + + in_uint16_be(c->in_s, cmd); + + if (cmd == SCP_CMD_MNG_LOGIN_ALLOW) /* connection ok */ + { + log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection ok", __LINE__); + return SCP_CLIENT_STATE_OK; + } + else if (cmd == SCP_CMD_MNG_LOGIN_DENY) /* connection denied */ + { + in_uint8(c->in_s, dim); + buf[dim] = '\0'; + in_uint8a(c->in_s, buf, dim); + scp_session_set_errstr(s, buf); + + log_message(LOG_LEVEL_INFO, "[v1c_mng:%d] connection denied: %s", __LINE__ , s->errstr); + return SCP_CLIENT_STATE_CONNECTION_DENIED; + } + + log_message(LOG_LEVEL_WARNING, "[v1c-mng:%d] connection aborted: sequence error", __LINE__); + return SCP_CLIENT_STATE_SEQUENCE_ERR; } diff --git a/sesman/libscp/libscp_v1c_mng.h b/sesman/libscp/libscp_v1c_mng.h index f030d4bf..126c9113 100644 --- a/sesman/libscp/libscp_v1c_mng.h +++ b/sesman/libscp/libscp_v1c_mng.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_v1s.c b/sesman/libscp/libscp_v1s.c index e10af26c..69997ab2 100644 --- a/sesman/libscp/libscp_v1s.c +++ b/sesman/libscp/libscp_v1s.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -33,634 +32,668 @@ //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) +enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk) { - struct SCP_SESSION* session; - tui32 version; - tui32 size; - tui16 cmdset; - tui16 cmd; - tui8 sz; - char buf[257]; - - if (!skipVchk) - { - - if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) - { - in_uint32_be(c->in_s, version); - if (version != 1) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); - return SCP_SERVER_STATE_VERSION_ERR; - } - } - else + struct SCP_SESSION *session; + tui32 version; + tui32 size; + tui16 cmdset; + tui16 cmd; + tui8 sz; + char buf[257]; + + if (!skipVchk) { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - } - - in_uint32_be(c->in_s, size); - if (size < 12) - { - log_message(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - /* reading command set */ - in_uint16_be(c->in_s, cmdset); - - /* if we are starting a management session */ - if (cmdset == SCP_COMMAND_SET_MANAGE) - { - log_message(LOG_LEVEL_DEBUG, "[v1s:%d] requested management connection", __LINE__); - /* should return SCP_SERVER_STATE_START_MANAGE */ - return scp_v1s_mng_accept(c, s); - } - - /* if we started with resource sharing... */ - if (cmdset == SCP_COMMAND_SET_RSR) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - /* reading command */ - in_uint16_be(c->in_s, cmd); - if (cmd != 1) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - session = scp_session_create(); - if (0 == session) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (malloc returned NULL)", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - scp_session_set_version(session, 1); - - in_uint8(c->in_s, sz); - if ((sz != SCP_SESSION_TYPE_XVNC) && (sz != SCP_SESSION_TYPE_XRDP)) - { - scp_session_destroy(session); - log_message(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, 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, sz); - if (sz == SCP_ADDRESS_TYPE_IPV4) - { + + if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + in_uint32_be(c->in_s, version); + + if (version != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); + return SCP_SERVER_STATE_VERSION_ERR; + } + } + else + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + } + in_uint32_be(c->in_s, size); - scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &size); - } - else if (sz == SCP_ADDRESS_TYPE_IPV6) - { - 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); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_hostname(session, buf)) - { - scp_session_destroy(session); - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* reading username */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_username(session, buf)) - { - scp_session_destroy(session); - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* reading password */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_password(session, buf)) - { - scp_session_destroy(session); - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - /* returning the struct */ - (*s)=session; + if (size < 12) + { + log_message(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + /* reading command set */ + in_uint16_be(c->in_s, cmdset); + + /* if we are starting a management session */ + if (cmdset == SCP_COMMAND_SET_MANAGE) + { + log_message(LOG_LEVEL_DEBUG, "[v1s:%d] requested management connection", __LINE__); + /* should return SCP_SERVER_STATE_START_MANAGE */ + return scp_v1s_mng_accept(c, s); + } + + /* if we started with resource sharing... */ + if (cmdset == SCP_COMMAND_SET_RSR) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + /* reading command */ + in_uint16_be(c->in_s, cmd); + + if (cmd != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + session = scp_session_create(); + + if (0 == session) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (malloc returned NULL)", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, 1); - return SCP_SERVER_STATE_OK; + in_uint8(c->in_s, sz); + + if ((sz != SCP_SESSION_TYPE_XVNC) && (sz != SCP_SESSION_TYPE_XRDP)) + { + scp_session_destroy(session); + log_message(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, 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, sz); + + if (sz == SCP_ADDRESS_TYPE_IPV4) + { + in_uint32_be(c->in_s, size); + scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &size); + } + else if (sz == SCP_ADDRESS_TYPE_IPV6) + { + 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); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_hostname(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading username */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* returning the struct */ + (*s) = session; + + return SCP_SERVER_STATE_OK; } enum SCP_SERVER_STATES_E -scp_v1s_deny_connection(struct SCP_CONNECTION* c, char* reason) +scp_v1s_deny_connection(struct SCP_CONNECTION *c, char *reason) { - int rlen; - - init_stream(c->out_s,c->out_s->size); - - /* forcing message not to exceed 64k */ - rlen = g_strlen(reason); - if (rlen > 65535) - { - rlen = 65535; - } - - out_uint32_be(c->out_s, 1); - /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/ - /* version + size + cmdset + cmd + msglen + msg */ - out_uint32_be(c->out_s, rlen+14); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, 2); - out_uint16_be(c->out_s, rlen); - out_uint8p(c->out_s, reason, rlen); - - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14)) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - return SCP_SERVER_STATE_END; + int rlen; + + init_stream(c->out_s, c->out_s->size); + + /* forcing message not to exceed 64k */ + rlen = g_strlen(reason); + + if (rlen > 65535) + { + rlen = 65535; + } + + out_uint32_be(c->out_s, 1); + /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/ + /* version + size + cmdset + cmd + msglen + msg */ + out_uint32_be(c->out_s, rlen + 14); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, 2); + out_uint16_be(c->out_s, rlen); + out_uint8p(c->out_s, reason, rlen); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, rlen + 14)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + return SCP_SERVER_STATE_END; } enum SCP_SERVER_STATES_E -scp_v1s_request_password(struct SCP_CONNECTION* c, struct SCP_SESSION* s, char* reason) +scp_v1s_request_password(struct SCP_CONNECTION *c, struct SCP_SESSION *s, char *reason) { - tui8 sz; - 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); - - /* forcing message not to exceed 64k */ - rlen = g_strlen(reason); - if (rlen > 65535) - { - rlen = 65535; - } - - /* send password request */ - version=1; - cmd=3; - - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, 14+rlen); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ - - out_uint16_be(c->out_s, rlen); - out_uint8p(c->out_s, reason, rlen); - - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14+rlen)) - { - log_message(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(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(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(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(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(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(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); - buf[sz] = '\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_username(s, buf)) - { - scp_session_destroy(s); - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* reading password */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_password(s, buf)) - { - scp_session_destroy(s); - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); - return SCP_SERVER_STATE_INTERNAL_ERR; - } + tui8 sz; + 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); + + /* forcing message not to exceed 64k */ + rlen = g_strlen(reason); + + if (rlen > 65535) + { + rlen = 65535; + } + + /* send password request */ + version = 1; + cmd = 3; + + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, 14 + rlen); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + out_uint16_be(c->out_s, rlen); + out_uint8p(c->out_s, reason, rlen); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 14 + rlen)) + { + log_message(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(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(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(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + in_uint16_be(c->in_s, cmdset); - return SCP_SERVER_STATE_OK; + if (cmdset != SCP_COMMAND_SET_DEFAULT) + { + log_message(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(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); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_username(s, buf)) + { + scp_session_destroy(s); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_password(s, buf)) + { + scp_session_destroy(s); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + return SCP_SERVER_STATE_OK; } /* 020 */ enum SCP_SERVER_STATES_E -scp_v1s_request_pwd_change(struct SCP_CONNECTION* c, char* reason, char* npw) +scp_v1s_request_pwd_change(struct SCP_CONNECTION *c, char *reason, char *npw) { - return SCP_SERVER_STATE_INTERNAL_ERR; + return SCP_SERVER_STATE_INTERNAL_ERR; } /* 023 */ enum SCP_SERVER_STATES_E -scp_v1s_pwd_change_error(struct SCP_CONNECTION* c, char* error, int retry, char* npw) +scp_v1s_pwd_change_error(struct SCP_CONNECTION *c, char *error, int retry, char *npw) { - return SCP_SERVER_STATE_INTERNAL_ERR; + return SCP_SERVER_STATE_INTERNAL_ERR; } /* 030 */ enum SCP_SERVER_STATES_E -scp_v1s_connect_new_session(struct SCP_CONNECTION* c, SCP_DISPLAY d) +scp_v1s_connect_new_session(struct SCP_CONNECTION *c, SCP_DISPLAY d) { - /* send password request */ - tui32 version=1; - tui32 size=14; - tui16 cmd=30; + /* send password request */ + tui32 version = 1; + tui32 size = 14; + tui16 cmd = 30; - init_stream(c->out_s, c->out_s->size); + init_stream(c->out_s, c->out_s->size); - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ - out_uint16_be(c->out_s, d); /* display */ + out_uint16_be(c->out_s, d); /* display */ - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14)) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 14)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } - return SCP_SERVER_STATE_OK; + return SCP_SERVER_STATE_OK; } /* 032 */ enum SCP_SERVER_STATES_E -scp_v1s_connection_error(struct SCP_CONNECTION* c, char* error) +scp_v1s_connection_error(struct SCP_CONNECTION *c, char *error) { - tui16 len; + tui16 len; - len = g_strlen(error); - init_stream(c->out_s,c->out_s->size); + len = g_strlen(error); + init_stream(c->out_s, c->out_s->size); - out_uint32_be(c->out_s, 1); - /* packet size: 4 + 4 + 2 + 2 + len */ - /* version + size + cmdset + cmd */ - out_uint32_be(c->out_s, (12 + len)); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, SCP_CMD_CONN_ERROR); + out_uint32_be(c->out_s, 1); + /* packet size: 4 + 4 + 2 + 2 + len */ + /* version + size + cmdset + cmd */ + out_uint32_be(c->out_s, (12 + len)); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, SCP_CMD_CONN_ERROR); - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, (12 + len))) - { - return SCP_SERVER_STATE_NETWORK_ERR; - } + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, (12 + len))) + { + return SCP_SERVER_STATE_NETWORK_ERR; + } - return SCP_SERVER_STATE_END; + return SCP_SERVER_STATE_END; } /* 040 */ enum SCP_SERVER_STATES_E -scp_v1s_list_sessions(struct SCP_CONNECTION* c, int sescnt, struct SCP_DISCONNECTED_SESSION* ds, SCP_SID* sid) +scp_v1s_list_sessions(struct SCP_CONNECTION *c, int sescnt, struct SCP_DISCONNECTED_SESSION *ds, SCP_SID *sid) { - tui32 version=1; - tui32 size=12; - tui16 cmd=40; - int pktcnt; - int idx; - int sidx; - int pidx; - struct SCP_DISCONNECTED_SESSION* cds; - - /* first we send a notice that we have some disconnected sessions */ - init_stream(c->out_s, c->out_s->size); - - out_uint32_be(c->out_s, version); /* version */ - out_uint32_be(c->out_s, size); /* size */ - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ - out_uint16_be(c->out_s, cmd); /* cmd */ - - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - /* then we wait for client ack */ + tui32 version = 1; + tui32 size = 12; + tui16 cmd = 40; + int pktcnt; + int idx; + int sidx; + int pidx; + struct SCP_DISCONNECTED_SESSION *cds; + + /* first we send a notice that we have some disconnected sessions */ + init_stream(c->out_s, c->out_s->size); + + out_uint32_be(c->out_s, version); /* version */ + out_uint32_be(c->out_s, size); /* size */ + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset */ + out_uint16_be(c->out_s, cmd); /* cmd */ + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + /* then we wait for client ack */ #warning maybe this message could say if the session should be resized on #warning server side or client side - 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(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(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(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(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(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - /* calculating the number of packets to send */ - pktcnt=sescnt/SCP_SERVER_MAX_LIST_SIZE; - if ((sescnt%SCP_SERVER_MAX_LIST_SIZE)!=0) - { - pktcnt++; - } - - for (idx=0; idx<pktcnt; idx++) - { - /* ok, we send session session list */ - init_stream(c->out_s, c->out_s->size); + init_stream(c->in_s, c->in_s->size); - /* size: ver+size+cmdset+cmd+sescnt+continue+count */ - size=4+4+2+2+4+1+1; + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } - /* header */ - cmd=42; - s_push_layer(c->out_s, channel_hdr, 8); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, cmd); + in_uint32_be(c->in_s, version); - /* session count */ - out_uint32_be(c->out_s, sescnt); + if (version != 1) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__); + return SCP_SERVER_STATE_VERSION_ERR; + } - /* setting the continue flag */ - if ((idx+1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt) + in_uint32_be(c->in_s, size); + + if (size < 12) { - out_uint8(c->out_s, 0); - /* setting session count for this packet */ - pidx=sescnt-(idx*SCP_SERVER_MAX_LIST_SIZE); - out_uint8(c->out_s, pidx); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); + return SCP_SERVER_STATE_SIZE_ERR; } - else + + init_stream(c->in_s, c->in_s->size); + + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, (size - 8))) { - out_uint8(c->out_s, 1); - /* setting session count for this packet */ - pidx=SCP_SERVER_MAX_LIST_SIZE; - out_uint8(c->out_s, pidx); - } - - /* adding session descriptors */ - for (sidx=0; sidx<pidx; sidx++) - { - /* shortcut to the current session to send */ - cds=ds+((idx)*SCP_SERVER_MAX_LIST_SIZE)+sidx; - - /* session data */ - out_uint32_be(c->out_s, cds->SID); /* session id */ - out_uint8(c->out_s, cds->type); - out_uint16_be(c->out_s, cds->height); - out_uint16_be(c->out_s, cds->width); - out_uint8(c->out_s, cds->bpp); - 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; - - 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); + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + in_uint16_be(c->in_s, cmd); + + if (cmd != SCP_COMMAND_SET_DEFAULT) + { + log_message(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - } - - /* we get the response */ - 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(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(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); - return SCP_SERVER_STATE_SIZE_ERR; - } - - /* rest of the packet */ - 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(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(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 == 43) - { - /* select session */ - in_uint32_be(c->in_s, (*sid)); - - /* checking sid value */ - for (idx=0; idx<sescnt; idx++) - { - /* the sid is valid */ - if (ds[idx].SID==(*sid)) - { - /* ok, session selected */ - return SCP_SERVER_STATE_OK; - } - } - - /* if we got here, the requested sid wasn't one from the list we sent */ - /* we should kill the connection */ - log_message(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) - { - /* cancel connection */ - return SCP_SERVER_STATE_SELECTION_CANCEL; - } -// else if (cmd == 45) -// { -// /* force new connection */ -// return SCP_SERVER_STATE_FORCE_NEW; -// } - else - { - /* wrong response */ - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - return SCP_SERVER_STATE_OK; + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + /* calculating the number of packets to send */ + pktcnt = sescnt / SCP_SERVER_MAX_LIST_SIZE; + + if ((sescnt % SCP_SERVER_MAX_LIST_SIZE) != 0) + { + pktcnt++; + } + + for (idx = 0; idx < pktcnt; idx++) + { + /* ok, we send session session list */ + init_stream(c->out_s, c->out_s->size); + + /* size: ver+size+cmdset+cmd+sescnt+continue+count */ + size = 4 + 4 + 2 + 2 + 4 + 1 + 1; + + /* header */ + cmd = 42; + s_push_layer(c->out_s, channel_hdr, 8); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, cmd); + + /* session count */ + out_uint32_be(c->out_s, sescnt); + + /* setting the continue flag */ + if ((idx + 1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt) + { + out_uint8(c->out_s, 0); + /* setting session count for this packet */ + pidx = sescnt - (idx * SCP_SERVER_MAX_LIST_SIZE); + out_uint8(c->out_s, pidx); + } + else + { + out_uint8(c->out_s, 1); + /* setting session count for this packet */ + pidx = SCP_SERVER_MAX_LIST_SIZE; + out_uint8(c->out_s, pidx); + } + + /* adding session descriptors */ + for (sidx = 0; sidx < pidx; sidx++) + { + /* shortcut to the current session to send */ + cds = ds + ((idx) * SCP_SERVER_MAX_LIST_SIZE) + sidx; + + /* session data */ + out_uint32_be(c->out_s, cds->SID); /* session id */ + out_uint8(c->out_s, cds->type); + out_uint16_be(c->out_s, cds->height); + out_uint16_be(c->out_s, cds->width); + out_uint8(c->out_s, cds->bpp); + 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; + + 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)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + } + + /* we get the response */ + 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(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(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(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__); + return SCP_SERVER_STATE_SIZE_ERR; + } + + /* rest of the packet */ + 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(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(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 == 43) + { + /* select session */ + in_uint32_be(c->in_s, (*sid)); + + /* checking sid value */ + for (idx = 0; idx < sescnt; idx++) + { + /* the sid is valid */ + if (ds[idx].SID == (*sid)) + { + /* ok, session selected */ + return SCP_SERVER_STATE_OK; + } + } + + /* if we got here, the requested sid wasn't one from the list we sent */ + /* we should kill the connection */ + log_message(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) + { + /* cancel connection */ + return SCP_SERVER_STATE_SELECTION_CANCEL; + } + // else if (cmd == 45) + // { + // /* force new connection */ + // return SCP_SERVER_STATE_FORCE_NEW; + // } + else + { + /* wrong response */ + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + return SCP_SERVER_STATE_OK; } /* 046 was: 031 struct SCP_DISCONNECTED_SESSION* ds, */ enum SCP_SERVER_STATES_E -scp_v1s_reconnect_session(struct SCP_CONNECTION* c, SCP_DISPLAY d) +scp_v1s_reconnect_session(struct SCP_CONNECTION *c, SCP_DISPLAY d) { - tui32 version = 1; - tui32 size = 14; - tui16 cmd = 46; - - /* ok, we send session data and display */ - init_stream(c->out_s, c->out_s->size); - - /* header */ - out_uint32_be(c->out_s, version); - out_uint32_be(c->out_s, size); - out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); - out_uint16_be(c->out_s, cmd); - - /* session data */ - out_uint16_be(c->out_s, d); /* session display */ - /*out_uint8(c->out_s, ds->type); - out_uint16_be(c->out_s, ds->height); - out_uint16_be(c->out_s, ds->width); - out_uint8(c->out_s, ds->bpp); - out_uint8(c->out_s, ds->idle_days); - out_uint8(c->out_s, ds->idle_hours); - out_uint8(c->out_s, ds->idle_minutes);*/ - /* these last three are not really needed... */ - - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) - { - log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - return SCP_SERVER_STATE_OK; + tui32 version = 1; + tui32 size = 14; + tui16 cmd = 46; + + /* ok, we send session data and display */ + init_stream(c->out_s, c->out_s->size); + + /* header */ + out_uint32_be(c->out_s, version); + out_uint32_be(c->out_s, size); + out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); + out_uint16_be(c->out_s, cmd); + + /* session data */ + out_uint16_be(c->out_s, d); /* session display */ + /*out_uint8(c->out_s, ds->type); + out_uint16_be(c->out_s, ds->height); + out_uint16_be(c->out_s, ds->width); + out_uint8(c->out_s, ds->bpp); + out_uint8(c->out_s, ds->idle_days); + out_uint8(c->out_s, ds->idle_hours); + out_uint8(c->out_s, ds->idle_minutes);*/ + /* these last three are not really needed... */ + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + { + log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + + return SCP_SERVER_STATE_OK; } #endif diff --git a/sesman/libscp/libscp_v1s.h b/sesman/libscp/libscp_v1s.h index 32de0bba..5e3ec980 100644 --- a/sesman/libscp/libscp_v1s.h +++ b/sesman/libscp/libscp_v1s.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_v1s_mng.c b/sesman/libscp/libscp_v1s_mng.c index 599545ab..24553429 100644 --- a/sesman/libscp/libscp_v1s_mng.c +++ b/sesman/libscp/libscp_v1s_mng.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -33,309 +32,323 @@ //extern struct log_config* s_log; static enum SCP_SERVER_STATES_E -_scp_v1s_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s); +_scp_v1s_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s); /* server API */ enum SCP_SERVER_STATES_E -scp_v1s_mng_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s) +scp_v1s_mng_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s) { - struct SCP_SESSION* session; - tui32 ipaddr; - tui16 cmd; - tui8 sz; - char buf[257]; - - /* reading command */ - in_uint16_be(c->in_s, cmd); - if (cmd != 1) /* manager login */ - { - return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - session = scp_session_create(); - if (0 == session) - { - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - scp_session_set_version(session, 1); - scp_session_set_type(session, SCP_SESSION_TYPE_MANAGE); - - /* reading username */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_username(session, buf)) - { - scp_session_destroy(session); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* reading password */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_password(session, buf)) - { - scp_session_destroy(session); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* reading remote address */ - in_uint8(c->in_s, sz); - if (sz == SCP_ADDRESS_TYPE_IPV4) - { - in_uint32_be(c->in_s, ipaddr); - scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &ipaddr); - } - else if (sz == SCP_ADDRESS_TYPE_IPV6) - { - in_uint8a(c->in_s, buf, 16); - scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf); - } - - /* reading hostname */ - in_uint8(c->in_s, sz); - buf[sz]='\0'; - in_uint8a(c->in_s, buf, sz); - if (0 != scp_session_set_hostname(session, buf)) - { - scp_session_destroy(session); - return SCP_SERVER_STATE_INTERNAL_ERR; - } - - /* returning the struct */ - (*s)=session; - - return SCP_SERVER_STATE_START_MANAGE; + struct SCP_SESSION *session; + tui32 ipaddr; + tui16 cmd; + tui8 sz; + char buf[257]; + + /* reading command */ + in_uint16_be(c->in_s, cmd); + + if (cmd != 1) /* manager login */ + { + return SCP_SERVER_STATE_SEQUENCE_ERR; + } + + session = scp_session_create(); + + if (0 == session) + { + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + scp_session_set_version(session, 1); + scp_session_set_type(session, SCP_SESSION_TYPE_MANAGE); + + /* reading username */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_username(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading password */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_password(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* reading remote address */ + in_uint8(c->in_s, sz); + + if (sz == SCP_ADDRESS_TYPE_IPV4) + { + in_uint32_be(c->in_s, ipaddr); + scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &ipaddr); + } + else if (sz == SCP_ADDRESS_TYPE_IPV6) + { + in_uint8a(c->in_s, buf, 16); + scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf); + } + + /* reading hostname */ + in_uint8(c->in_s, sz); + buf[sz] = '\0'; + in_uint8a(c->in_s, buf, sz); + + if (0 != scp_session_set_hostname(session, buf)) + { + scp_session_destroy(session); + return SCP_SERVER_STATE_INTERNAL_ERR; + } + + /* returning the struct */ + (*s) = session; + + return SCP_SERVER_STATE_START_MANAGE; } /* 002 */ enum SCP_SERVER_STATES_E -scp_v1s_mng_allow_connection(struct SCP_CONNECTION* c, struct SCP_SESSION* s) +scp_v1s_mng_allow_connection(struct SCP_CONNECTION *c, struct SCP_SESSION *s) { - init_stream(c->out_s,c->out_s->size); + init_stream(c->out_s, c->out_s->size); - out_uint32_be(c->out_s, 1); - /* packet size: 4 + 4 + 2 + 2 */ - /* version + size + cmdset + cmd */ - out_uint32_be(c->out_s, 12); - out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); - out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_ALLOW); + out_uint32_be(c->out_s, 1); + /* packet size: 4 + 4 + 2 + 2 */ + /* version + size + cmdset + cmd */ + out_uint32_be(c->out_s, 12); + out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); + out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_ALLOW); - if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 12)) - { - return SCP_SERVER_STATE_NETWORK_ERR; - } + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 12)) + { + return SCP_SERVER_STATE_NETWORK_ERR; + } - return _scp_v1s_mng_check_response(c, s); + return _scp_v1s_mng_check_response(c, s); } /* 003 */ enum SCP_SERVER_STATES_E -scp_v1s_mng_deny_connection(struct SCP_CONNECTION* c, char* reason) +scp_v1s_mng_deny_connection(struct SCP_CONNECTION *c, char *reason) { - int rlen; - - init_stream(c->out_s,c->out_s->size); - - /* forcing message not to exceed 64k */ - rlen = g_strlen(reason); - if (rlen > 65535) - { - rlen = 65535; - } - - out_uint32_be(c->out_s, 1); - /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/ - /* version + size + cmdset + cmd + msglen + msg */ - out_uint32_be(c->out_s, rlen+14); - out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); - out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY); - out_uint16_be(c->out_s, rlen); - out_uint8p(c->out_s, reason, rlen); - - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14)) - { - return SCP_SERVER_STATE_NETWORK_ERR; - } - - return SCP_SERVER_STATE_END; + int rlen; + + init_stream(c->out_s, c->out_s->size); + + /* forcing message not to exceed 64k */ + rlen = g_strlen(reason); + + if (rlen > 65535) + { + rlen = 65535; + } + + out_uint32_be(c->out_s, 1); + /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/ + /* version + size + cmdset + cmd + msglen + msg */ + out_uint32_be(c->out_s, rlen + 14); + out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); + out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY); + out_uint16_be(c->out_s, rlen); + out_uint8p(c->out_s, reason, rlen); + + if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, rlen + 14)) + { + return SCP_SERVER_STATE_NETWORK_ERR; + } + + return SCP_SERVER_STATE_END; } /* 006 */ enum SCP_SERVER_STATES_E -scp_v1s_mng_list_sessions(struct SCP_CONNECTION* c, struct SCP_SESSION* s, - int sescnt, struct SCP_DISCONNECTED_SESSION* ds) +scp_v1s_mng_list_sessions(struct SCP_CONNECTION *c, struct SCP_SESSION *s, + int sescnt, struct SCP_DISCONNECTED_SESSION *ds) { - tui32 version = 1; - tui32 size = 12; - tui16 cmd = SCP_CMD_MNG_LIST; - int pktcnt; - int idx; - int sidx; - int pidx; - struct SCP_DISCONNECTED_SESSION* cds; - - /* calculating the number of packets to send */ - pktcnt=sescnt/SCP_SERVER_MAX_LIST_SIZE; - if ((sescnt%SCP_SERVER_MAX_LIST_SIZE)!=0) - { - pktcnt++; - } - - for (idx=0; idx<pktcnt; idx++) - { - /* ok, we send session session list */ - init_stream(c->out_s, c->out_s->size); + tui32 version = 1; + tui32 size = 12; + tui16 cmd = SCP_CMD_MNG_LIST; + int pktcnt; + int idx; + int sidx; + int pidx; + struct SCP_DISCONNECTED_SESSION *cds; + + /* calculating the number of packets to send */ + pktcnt = sescnt / SCP_SERVER_MAX_LIST_SIZE; + + if ((sescnt % SCP_SERVER_MAX_LIST_SIZE) != 0) + { + pktcnt++; + } - /* size: ver+size+cmdset+cmd+sescnt+continue+count */ - size=4+4+2+2+4+1+1; + for (idx = 0; idx < pktcnt; idx++) + { + /* ok, we send session session list */ + init_stream(c->out_s, c->out_s->size); + + /* size: ver+size+cmdset+cmd+sescnt+continue+count */ + size = 4 + 4 + 2 + 2 + 4 + 1 + 1; + + /* header */ + s_push_layer(c->out_s, channel_hdr, 8); + out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); + out_uint16_be(c->out_s, cmd); + + /* session count */ + out_uint32_be(c->out_s, sescnt); + + /* setting the continue flag */ + if ((idx + 1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt) + { + out_uint8(c->out_s, 0); + /* setting session count for this packet */ + pidx = sescnt - (idx * SCP_SERVER_MAX_LIST_SIZE); + out_uint8(c->out_s, pidx); + } + else + { + out_uint8(c->out_s, 1); + /* setting session count for this packet */ + pidx = SCP_SERVER_MAX_LIST_SIZE; + out_uint8(c->out_s, pidx); + } + + /* adding session descriptors */ + for (sidx = 0; sidx < pidx; sidx++) + { + /* shortcut to the current session to send */ + cds = ds + ((idx) * SCP_SERVER_MAX_LIST_SIZE) + sidx; + + /* session data */ + out_uint32_be(c->out_s, cds->SID); /* session id */ + out_uint8(c->out_s, cds->type); + out_uint16_be(c->out_s, cds->height); + out_uint16_be(c->out_s, cds->width); + out_uint8(c->out_s, cds->bpp); + 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; + + 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)) + { + log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; + } + } - /* header */ - s_push_layer(c->out_s, channel_hdr, 8); - out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); - out_uint16_be(c->out_s, cmd); + return _scp_v1s_mng_check_response(c, s); +} - /* session count */ - out_uint32_be(c->out_s, sescnt); +static enum SCP_SERVER_STATES_E +_scp_v1s_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s) +{ + tui32 version; + tui32 size; + tui16 cmd; + // tui8 dim; + // char buf[257]; + + init_stream(c->in_s, c->in_s->size); - /* setting the continue flag */ - if ((idx+1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt) + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) { - out_uint8(c->out_s, 0); - /* setting session count for this packet */ - pidx=sescnt-(idx*SCP_SERVER_MAX_LIST_SIZE); - out_uint8(c->out_s, pidx); + log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; } - else + + in_uint32_be(c->in_s, version); + + if (version != 1) { - out_uint8(c->out_s, 1); - /* setting session count for this packet */ - pidx=SCP_SERVER_MAX_LIST_SIZE; - out_uint8(c->out_s, pidx); + log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: version error", __LINE__); + return SCP_SERVER_STATE_VERSION_ERR; } - /* adding session descriptors */ - for (sidx=0; sidx<pidx; sidx++) + in_uint32_be(c->in_s, size); + + init_stream(c->in_s, c->in_s->size); + + /* read the rest of the packet */ + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) { - /* shortcut to the current session to send */ - cds=ds+((idx)*SCP_SERVER_MAX_LIST_SIZE)+sidx; - - /* session data */ - out_uint32_be(c->out_s, cds->SID); /* session id */ - out_uint8(c->out_s, cds->type); - out_uint16_be(c->out_s, cds->height); - out_uint16_be(c->out_s, cds->width); - out_uint8(c->out_s, cds->bpp); - 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; - - 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; - } + log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); + return SCP_SERVER_STATE_NETWORK_ERR; } - s_pop_layer(c->out_s, channel_hdr); - out_uint32_be(c->out_s, version); - out_uint32_be(c->out_s, size); + in_uint16_be(c->in_s, cmd); - if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size)) + if (cmd != SCP_COMMAND_SET_MANAGE) { - log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; + log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__); + return SCP_SERVER_STATE_SEQUENCE_ERR; } - } - return _scp_v1s_mng_check_response(c, s); -} + in_uint16_be(c->in_s, cmd); + + if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */ + { + log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__); + return SCP_SERVER_STATE_MNG_LISTREQ; + } + else if (cmd == SCP_CMD_MNG_ACTION) /* execute an action */ + { + /*in_uint8(c->in_s, dim); + buf[dim]='\0'; + in_uint8a(c->in_s, buf, dim); + scp_session_set_errstr(s, buf);*/ + + log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] action request", __LINE__); + return SCP_SERVER_STATE_MNG_ACTION; + } + + /* else if (cmd == 20) / * password change * / + { + in_uint16_be(c->in_s, s->display); + + return SCP_SERVER_STATE_OK; + } + else if (cmd == 40) / * session list * / + { + return SCP_SERVER_STATE_SESSION_LIST; + }*/ -static enum SCP_SERVER_STATES_E -_scp_v1s_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s) -{ - tui32 version; - tui32 size; - tui16 cmd; -// tui8 dim; -// char buf[257]; - - 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(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - in_uint32_be(c->in_s, version); - if (version != 1) - { - log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: version error", __LINE__); - return SCP_SERVER_STATE_VERSION_ERR; - } - - in_uint32_be(c->in_s, size); - - init_stream(c->in_s, c->in_s->size); - /* read the rest of the packet */ - if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8)) - { - log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__); - return SCP_SERVER_STATE_NETWORK_ERR; - } - - in_uint16_be(c->in_s, cmd); - if (cmd != SCP_COMMAND_SET_MANAGE) - { log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__); return SCP_SERVER_STATE_SEQUENCE_ERR; - } - - in_uint16_be(c->in_s, cmd); - if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */ - { - log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__); - return SCP_SERVER_STATE_MNG_LISTREQ; - } - else if (cmd == SCP_CMD_MNG_ACTION) /* execute an action */ - { - /*in_uint8(c->in_s, dim); - buf[dim]='\0'; - in_uint8a(c->in_s, buf, dim); - scp_session_set_errstr(s, buf);*/ - - log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] action request", __LINE__); - return SCP_SERVER_STATE_MNG_ACTION; - } - /* else if (cmd == 20) / * password change * / - { - in_uint16_be(c->in_s, s->display); - - return SCP_SERVER_STATE_OK; - } - else if (cmd == 40) / * session list * / - { - return SCP_SERVER_STATE_SESSION_LIST; - }*/ - - log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__); - return SCP_SERVER_STATE_SEQUENCE_ERR; } #endif diff --git a/sesman/libscp/libscp_v1s_mng.h b/sesman/libscp/libscp_v1s_mng.h index ab296632..72df9fa6 100644 --- a/sesman/libscp/libscp_v1s_mng.h +++ b/sesman/libscp/libscp_v1s_mng.h @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * diff --git a/sesman/libscp/libscp_vX.c b/sesman/libscp/libscp_vX.c index b121da2d..e590fe73 100644 --- a/sesman/libscp/libscp_vX.c +++ b/sesman/libscp/libscp_vX.c @@ -1,21 +1,20 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * @@ -28,26 +27,26 @@ #include "libscp_vX.h" /* server API */ -enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s) +enum SCP_SERVER_STATES_E scp_vXs_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s) { - tui32 version; - - /* reading version and packet size */ - if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) - { - return SCP_SERVER_STATE_NETWORK_ERR; - } - - in_uint32_be(c->in_s, version); - - if (version == 0) - { - return scp_v0s_accept(c, s, 1); - } - else if (version == 1) - { - return scp_v1s_accept(c, s, 1); - } - - return SCP_SERVER_STATE_VERSION_ERR; + tui32 version; + + /* reading version and packet size */ + if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8)) + { + return SCP_SERVER_STATE_NETWORK_ERR; + } + + in_uint32_be(c->in_s, version); + + if (version == 0) + { + return scp_v0s_accept(c, s, 1); + } + else if (version == 1) + { + return scp_v1s_accept(c, s, 1); + } + + return SCP_SERVER_STATE_VERSION_ERR; } diff --git a/sesman/libscp/libscp_vX.h b/sesman/libscp/libscp_vX.h index c59bc1af..a68a9ede 100644 --- a/sesman/libscp/libscp_vX.h +++ b/sesman/libscp/libscp_vX.h @@ -1,28 +1,27 @@ -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2005-2010 -*/ +/** + * xrdp: A Remote Desktop Protocol server. + * + * Copyright (C) Jay Sorg 2004-2012 + * + * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * * @file libscp_vX.h * @brief libscp version neutral code header * @author Simone Fedele - * + * */ #ifndef LIBSCP_VX_H |
