2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-09-17 19:26:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file libscp_session.c
|
|
|
|
* @brief SCP_SESSION handling code
|
|
|
|
* @author Simone Fedele
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2007-09-17 19:26:23 +04:00
|
|
|
#include "libscp_session.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2007-09-17 19:26:23 +04:00
|
|
|
|
2008-07-30 14:58:30 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2012-05-27 19:17:39 +04:00
|
|
|
//extern struct log_config* s_log;
|
2008-07-30 14:58:30 +04:00
|
|
|
|
2009-08-24 22:09:19 +04:00
|
|
|
/*******************************************************************/
|
2012-09-20 07:51:34 +04:00
|
|
|
struct SCP_SESSION *
|
2016-12-23 20:52:22 +03:00
|
|
|
scp_session_create(void)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct SCP_SESSION *s;
|
2007-09-17 19:26:23 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s = (struct SCP_SESSION *)g_malloc(sizeof(struct SCP_SESSION), 1);
|
|
|
|
|
|
|
|
if (0 == s)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "[session:%d] session create: malloc error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_type(struct SCP_SESSION *s, tui8 type)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SCP_SESSION_TYPE_XVNC:
|
|
|
|
s->type = SCP_SESSION_TYPE_XVNC;
|
|
|
|
break;
|
2014-05-10 03:02:19 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
case SCP_SESSION_TYPE_XRDP:
|
|
|
|
s->type = SCP_SESSION_TYPE_XRDP;
|
|
|
|
break;
|
2014-05-10 03:02:19 +04:00
|
|
|
|
2014-03-09 04:41:37 +04:00
|
|
|
case SCP_SESSION_TYPE_XORG:
|
2014-05-10 03:02:19 +04:00
|
|
|
s->type = SCP_SESSION_TYPE_XORG;
|
|
|
|
break;
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
case SCP_GW_AUTHENTICATION:
|
|
|
|
s->type = SCP_GW_AUTHENTICATION;
|
|
|
|
break;
|
2014-05-10 03:02:19 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
case SCP_SESSION_TYPE_MANAGE:
|
|
|
|
s->type = SCP_SESSION_TYPE_MANAGE;
|
|
|
|
break;
|
2014-05-10 03:02:19 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_type: unknown type", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_version(struct SCP_SESSION *s, tui32 version)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
switch (version)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
s->version = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s->version = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_version: unknown version", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_height(struct SCP_SESSION *s, tui16 h)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
s->height = h;
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_width(struct SCP_SESSION *s, tui16 w)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
s->width = w;
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_bpp(struct SCP_SESSION *s, tui8 bpp)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
case 15:
|
|
|
|
case 16:
|
|
|
|
case 24:
|
2016-02-10 12:17:38 +03:00
|
|
|
case 32:
|
2012-09-20 07:51:34 +04:00
|
|
|
s->bpp = bpp;
|
2016-02-12 04:52:44 +03:00
|
|
|
break;
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_rsr(struct SCP_SESSION *s, tui8 rsr)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (s->rsr)
|
|
|
|
{
|
|
|
|
s->rsr = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s->rsr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_locale(struct SCP_SESSION *s, const char *str)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_locale: null locale", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
s->locale[0] = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strncpy(s->locale, str, 17);
|
|
|
|
s->locale[17] = '\0';
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_username(struct SCP_SESSION *s, const char *str)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_username: null username", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->username)
|
|
|
|
{
|
|
|
|
g_free(s->username);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->username = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->username)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_username: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_password(struct SCP_SESSION *s, const char *str)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_password: null password", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->password)
|
|
|
|
{
|
|
|
|
g_free(s->password);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->password = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->password)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_password: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
2009-08-19 11:27:35 +04:00
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_domain(struct SCP_SESSION *s, const char *str)
|
2009-08-19 11:27:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_domain: null domain", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->domain)
|
|
|
|
{
|
|
|
|
g_free(s->domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->domain = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->domain)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_domain: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-19 11:27:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_program(struct SCP_SESSION *s, const char *str)
|
2009-08-19 11:27:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_program: null program", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->program)
|
|
|
|
{
|
|
|
|
g_free(s->program);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->program = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->program)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_program: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-19 11:27:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_directory(struct SCP_SESSION *s, const char *str)
|
2009-08-19 11:27:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_directory: null directory", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->directory)
|
|
|
|
{
|
|
|
|
g_free(s->directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->directory = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->directory)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_directory: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-19 11:27:35 +04:00
|
|
|
}
|
|
|
|
|
2010-11-04 14:14:03 +03:00
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2021-08-27 14:14:52 +03:00
|
|
|
scp_session_set_connection_description(struct SCP_SESSION *s, const char *str)
|
2010-11-04 14:14:03 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2021-08-27 14:14:52 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_connection_description: null description", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-08-27 14:14:52 +03:00
|
|
|
if (0 != s->connection_description)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-08-27 14:14:52 +03:00
|
|
|
g_free(s->connection_description);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:14:52 +03:00
|
|
|
s->connection_description = g_strdup(str);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-08-27 14:14:52 +03:00
|
|
|
if (0 == s->connection_description)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-08-27 14:14:52 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_connection_description: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-11-04 14:14:03 +03:00
|
|
|
}
|
|
|
|
|
2007-09-17 19:26:23 +04:00
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_hostname(struct SCP_SESSION *s, const char *str)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_hostname: null hostname", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->hostname)
|
|
|
|
{
|
|
|
|
g_free(s->hostname);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->hostname = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->hostname)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_hostname: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_errstr(struct SCP_SESSION *s, const char *str)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (0 == str)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_errstr: null string", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != s->errstr)
|
|
|
|
{
|
|
|
|
g_free(s->errstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->errstr = g_strdup(str);
|
|
|
|
|
|
|
|
if (0 == s->errstr)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_errstr: strdup error", __LINE__);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_set_display(struct SCP_SESSION *s, SCP_DISPLAY display)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
s->display = display;
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2016-06-22 02:30:17 +03:00
|
|
|
scp_session_set_addr(struct SCP_SESSION *s, int type, const void *addr)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SCP_ADDRESS_TYPE_IPV4:
|
|
|
|
g_memcpy(&(s->ipv4addr), addr, 4);
|
|
|
|
break;
|
2008-08-12 11:11:05 +04:00
|
|
|
#ifdef IN6ADDR_ANY_INIT
|
2012-09-20 07:51:34 +04:00
|
|
|
case SCP_ADDRESS_TYPE_IPV6:
|
|
|
|
g_memcpy(s->ipv6addr, addr, 16);
|
|
|
|
break;
|
2008-08-12 11:11:05 +04:00
|
|
|
#endif
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|
|
|
|
|
2016-12-04 10:12:48 +03:00
|
|
|
/*******************************************************************/
|
|
|
|
int
|
2021-04-22 15:27:39 +03:00
|
|
|
scp_session_set_guid(struct SCP_SESSION *s, const struct guid *guid)
|
2016-12-04 10:12:48 +03:00
|
|
|
{
|
|
|
|
if (0 == guid)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "[session:%d] set_guid: null guid", __LINE__);
|
2016-12-04 10:12:48 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-04-22 15:27:39 +03:00
|
|
|
s->guid = *guid;
|
2016-12-04 10:12:48 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-28 13:42:14 +03:00
|
|
|
/*******************************************************************/
|
|
|
|
static void
|
|
|
|
clear_and_free_string(char *p)
|
|
|
|
{
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
for (cp = p ; *cp != '\0'; ++cp)
|
|
|
|
{
|
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
g_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 19:26:23 +04:00
|
|
|
/*******************************************************************/
|
|
|
|
void
|
2012-09-20 07:51:34 +04:00
|
|
|
scp_session_destroy(struct SCP_SESSION *s)
|
2007-09-17 19:26:23 +04:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
g_free(s->username);
|
2022-11-28 13:42:14 +03:00
|
|
|
clear_and_free_string(s->password);
|
2021-06-22 15:38:46 +03:00
|
|
|
g_free(s->hostname);
|
|
|
|
g_free(s->domain);
|
|
|
|
g_free(s->program);
|
|
|
|
g_free(s->directory);
|
2021-08-27 14:14:52 +03:00
|
|
|
g_free(s->connection_description);
|
2021-06-22 15:38:46 +03:00
|
|
|
g_free(s->errstr);
|
|
|
|
g_free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
struct SCP_SESSION *
|
|
|
|
scp_session_clone(const struct SCP_SESSION *s)
|
|
|
|
{
|
|
|
|
struct SCP_SESSION *result = NULL;
|
|
|
|
|
|
|
|
if (s != NULL && (result = g_new(struct SCP_SESSION, 1)) != NULL)
|
|
|
|
{
|
|
|
|
/* Duplicate all the scalar variables */
|
|
|
|
g_memcpy(result, s, sizeof(*s));
|
|
|
|
|
|
|
|
/* Now duplicate all the strings */
|
|
|
|
result->username = g_strdup(s->username);
|
|
|
|
result->password = g_strdup(s->password);
|
|
|
|
result->hostname = g_strdup(s->hostname);
|
|
|
|
result->errstr = g_strdup(s->errstr);
|
|
|
|
result->domain = g_strdup(s->domain);
|
|
|
|
result->program = g_strdup(s->program);
|
|
|
|
result->directory = g_strdup(s->directory);
|
2021-08-27 14:14:52 +03:00
|
|
|
result->connection_description = g_strdup(s->connection_description);
|
2021-06-22 15:38:46 +03:00
|
|
|
|
|
|
|
/* Did all the string copies succeed? */
|
|
|
|
if ((s->username != NULL && result->username == NULL) ||
|
|
|
|
(s->password != NULL && result->password == NULL) ||
|
|
|
|
(s->hostname != NULL && result->hostname == NULL) ||
|
|
|
|
(s->errstr != NULL && result->errstr == NULL) ||
|
|
|
|
(s->domain != NULL && result->domain == NULL) ||
|
|
|
|
(s->program != NULL && result->program == NULL) ||
|
|
|
|
(s->directory != NULL && result->directory == NULL) ||
|
2021-08-27 14:14:52 +03:00
|
|
|
(s->connection_description != NULL && result->connection_description == NULL))
|
2021-06-22 15:38:46 +03:00
|
|
|
{
|
|
|
|
scp_session_destroy(result);
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2007-09-17 19:26:23 +04:00
|
|
|
}
|