tools: Moved to new SCP interface
This commit is contained in:
+61
-100
@@ -33,13 +33,14 @@
|
||||
#include <ctype.h>
|
||||
|
||||
#include "parse.h"
|
||||
#include "trans.h"
|
||||
#include "os_calls.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "string_calls.h"
|
||||
#include "guid.h"
|
||||
|
||||
#include "libscp_connection.h"
|
||||
#include "tools_common.h"
|
||||
|
||||
#if !defined(PACKAGE_VERSION)
|
||||
#define PACKAGE_VERSION "???"
|
||||
@@ -71,18 +72,18 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Maps session type strings to internal code numbers
|
||||
* Maps session type strings session type codes
|
||||
*/
|
||||
static struct
|
||||
{
|
||||
const char *name;
|
||||
int code;
|
||||
enum scp_session_type type;
|
||||
} type_map[] =
|
||||
{
|
||||
{ "Xvnc", 0},
|
||||
{ "X11rdp", 10},
|
||||
{ "Xorg", 20},
|
||||
{ NULL, -1}
|
||||
{ "Xvnc", SCP_SESSION_TYPE_XVNC},
|
||||
{ "X11rdp", SCP_SESSION_TYPE_XRDP},
|
||||
{ "Xorg", SCP_SESSION_TYPE_XORG},
|
||||
{ NULL, (enum scp_session_type) - 1}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -93,37 +94,38 @@ struct session_params
|
||||
int width;
|
||||
int height;
|
||||
int bpp;
|
||||
int session_code;
|
||||
enum scp_session_type session_type;
|
||||
const char *server;
|
||||
|
||||
const char *domain; /* Currently unused by sesman */
|
||||
const char *directory;
|
||||
const char *shell;
|
||||
const char *client_ip;
|
||||
const char *connection_description;
|
||||
|
||||
const char *username;
|
||||
char password[MAX_PASSWORD_LEN + 1];
|
||||
};
|
||||
|
||||
/**************************************************************************//**
|
||||
* Maps a string to a session code
|
||||
* Maps a string to a session type value
|
||||
*
|
||||
* @param t session type
|
||||
* @return session code, or -1 if not found
|
||||
* @param string session type string
|
||||
* @param[out] value session type value
|
||||
* @return 0 for success or != 0 if not found
|
||||
*/
|
||||
static
|
||||
int get_session_type_code(const char *t)
|
||||
int string_to_session_type(const char *t, enum scp_session_type *value)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0 ; type_map[i].name != NULL; ++i)
|
||||
{
|
||||
if (g_strcasecmp(type_map[i].name, t) == 0)
|
||||
{
|
||||
return type_map[i].code;
|
||||
*value = type_map[i].type;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
@@ -182,7 +184,7 @@ usage(void)
|
||||
" -p <password> TESTING ONLY - DO NOT USE IN PRODUCTION\n"
|
||||
" -F <file-descriptor> Read password from this file descriptor\n"
|
||||
" -c <sesman_ini> Alternative sesman.ini file\n");
|
||||
g_printf("Supported types are %s or use int for internal code\n",
|
||||
g_printf("Supported types are %s\n",
|
||||
sesstype_list);
|
||||
g_printf("Password is prompted if -p or -F are not specified\n");
|
||||
}
|
||||
@@ -288,13 +290,12 @@ parse_program_args(int argc, char *argv[], struct session_params *sp,
|
||||
sp->width = DEFAULT_WIDTH;
|
||||
sp->height = DEFAULT_HEIGHT;
|
||||
sp->bpp = DEFAULT_BPP;
|
||||
sp->session_code = get_session_type_code(DEFAULT_TYPE);
|
||||
(void)string_to_session_type(DEFAULT_TYPE, &sp->session_type);
|
||||
sp->server = DEFAULT_SERVER;
|
||||
|
||||
sp->domain = "";
|
||||
sp->directory = "";
|
||||
sp->shell = "";
|
||||
sp->client_ip = "";
|
||||
sp->connection_description = "";
|
||||
|
||||
sp->username = NULL;
|
||||
sp->password[0] = '\0';
|
||||
@@ -320,19 +321,11 @@ parse_program_args(int argc, char *argv[], struct session_params *sp,
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (isdigit(optarg[0]))
|
||||
if (string_to_session_type(optarg, &sp->session_type) != 0)
|
||||
{
|
||||
sp->session_code = atoi(optarg);
|
||||
}
|
||||
else
|
||||
{
|
||||
sp->session_code = get_session_type_code(optarg);
|
||||
if (sp->session_code < 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Unrecognised session type '%s'",
|
||||
optarg);
|
||||
params_ok = 0;
|
||||
}
|
||||
LOG(LOG_LEVEL_ERROR, "Unrecognised session type '%s'",
|
||||
optarg);
|
||||
params_ok = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -416,89 +409,61 @@ parse_program_args(int argc, char *argv[], struct session_params *sp,
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* Sends an SCP V0 authorization request
|
||||
* Sends an SCP create session request
|
||||
*
|
||||
* @param sck file descriptor to send request on
|
||||
* @param t SCP connection
|
||||
* @param sp Data for request
|
||||
*
|
||||
* @todo This code duplicates functionality in the XRDP function
|
||||
* xrdp_mm_send_login(). When SCP is reworked, a common library
|
||||
* function should be used
|
||||
*/
|
||||
static enum SCP_CLIENT_STATES_E
|
||||
send_scpv0_auth_request(struct trans *t, const struct session_params *sp)
|
||||
static int
|
||||
send_create_session_request(struct trans *t, const struct session_params *sp)
|
||||
{
|
||||
LOG(LOG_LEVEL_DEBUG,
|
||||
"width:%d height:%d bpp:%d code:%d\n"
|
||||
"server:\"%s\" domain:\"%s\" directory:\"%s\"\n"
|
||||
"shell:\"%s\" client_ip:\"%s\"",
|
||||
sp->width, sp->height, sp->bpp, sp->session_code,
|
||||
sp->server, sp->domain, sp->directory,
|
||||
sp->shell, sp->client_ip);
|
||||
"server:\"%s\" directory:\"%s\"\n"
|
||||
"shell:\"%s\" connection_description:\"%s\"",
|
||||
sp->width, sp->height, sp->bpp, sp->session_type,
|
||||
sp->server, sp->directory,
|
||||
sp->shell, sp->connection_description);
|
||||
/* Only log the password in development builds */
|
||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "password:\"%s\"", sp->password);
|
||||
|
||||
return scp_v0c_create_session_request(
|
||||
t, sp->username, sp->password, sp->session_code, sp->width, sp->height,
|
||||
sp->bpp, sp->domain, sp->shell, sp->directory, sp->client_ip);
|
||||
return scp_send_create_session_request(
|
||||
t, sp->username, sp->password, sp->session_type,
|
||||
sp->width, sp->height, sp->bpp, sp->shell, sp->directory,
|
||||
sp->connection_description);
|
||||
}
|
||||
|
||||
/**************************************************************************//**
|
||||
* Receives an SCP V0 authorization reply
|
||||
* Receives an SCP create session response
|
||||
*
|
||||
* @param t SCP transport to receive reply on
|
||||
* @return 0 for success
|
||||
*/
|
||||
static int
|
||||
handle_scpv0_auth_reply(struct trans *t)
|
||||
handle_create_session_response(struct trans *t)
|
||||
{
|
||||
tbus wobj[1];
|
||||
int ocnt = 0;
|
||||
int auth_result;
|
||||
int display;
|
||||
struct guid guid;
|
||||
|
||||
int rv = 1;
|
||||
int rv = wait_for_sesman_reply(t, E_SCP_CREATE_SESSION_RESPONSE);
|
||||
if (rv == 0)
|
||||
{
|
||||
rv = scp_get_create_session_response(t, &auth_result,
|
||||
&display, &guid);
|
||||
|
||||
if (trans_get_wait_objs(t, wobj, &ocnt) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "Can't get wait object for sesman transport");
|
||||
}
|
||||
else
|
||||
{
|
||||
while (t->status == TRANS_STATUS_UP)
|
||||
if (rv == 0)
|
||||
{
|
||||
g_obj_wait(wobj, ocnt, NULL, 0, -1);
|
||||
if (trans_check_wait_objs(t) != 0)
|
||||
if (auth_result != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "sesman transport down");
|
||||
break;
|
||||
g_printf("Connection denied (authentication error)\n");
|
||||
}
|
||||
|
||||
if (scp_v0c_reply_available(t))
|
||||
else
|
||||
{
|
||||
struct scp_v0_reply_type msg;
|
||||
enum SCP_CLIENT_STATES_E e = scp_v0c_get_reply(t, &msg);
|
||||
if (e != SCP_CLIENT_STATE_OK)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
"Error reading response from sesman [%s]",
|
||||
scp_client_state_to_str(e));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg.auth_result == 0)
|
||||
{
|
||||
g_printf("Connection denied (authentication error)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
char guid_str[GUID_STR_SIZE];
|
||||
g_printf("ok data=%d display=:%d GUID=%s\n",
|
||||
msg.auth_result,
|
||||
msg.display,
|
||||
guid_to_str(&msg.guid, guid_str));
|
||||
}
|
||||
rv = 0;
|
||||
}
|
||||
break;
|
||||
char guid_str[GUID_STR_SIZE];
|
||||
g_printf("ok display=:%d GUID=%s\n",
|
||||
display,
|
||||
guid_to_str(&guid, guid_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,7 +479,6 @@ main(int argc, char **argv)
|
||||
struct config_sesman *cfg = NULL;
|
||||
|
||||
struct trans *t = NULL;
|
||||
enum SCP_CLIENT_STATES_E e;
|
||||
struct session_params sp;
|
||||
|
||||
struct log_config *logging;
|
||||
@@ -534,23 +498,20 @@ main(int argc, char **argv)
|
||||
LOG(LOG_LEVEL_ERROR, "error reading config file %s : %s",
|
||||
sesman_ini, g_get_strerror());
|
||||
}
|
||||
else if (!(t = scp_connect(sp.server, cfg->listen_port, NULL, NULL, NULL)))
|
||||
else if (!(t = scp_connect(sp.server, cfg->listen_port, NULL)))
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR, "connect error - %s", g_get_strerror());
|
||||
}
|
||||
else
|
||||
{
|
||||
e = send_scpv0_auth_request(t, &sp);
|
||||
if (e != SCP_CLIENT_STATE_OK)
|
||||
rv = send_create_session_request(t, &sp);
|
||||
if (rv != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
"Error sending create session to sesman [%s]",
|
||||
scp_client_state_to_str(e));
|
||||
rv = 1;
|
||||
LOG(LOG_LEVEL_ERROR, "Error sending create session to sesman");
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = handle_scpv0_auth_reply(t);
|
||||
rv = handle_create_session_response(t);
|
||||
}
|
||||
trans_delete(t);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user