adding scp v1 first code, fixed passwd auth for disabled password
parent
b681420acc
commit
078b4d3f41
@ -0,0 +1,249 @@
|
||||
/*
|
||||
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-2006
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file libscp_v1c.c
|
||||
* @brief libscp version 1 client api code
|
||||
* @author Simone Fedele
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libscp_v1c.h"
|
||||
|
||||
static enum SCP_CLIENT_STATES_E _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)
|
||||
{
|
||||
unsigned char sz;
|
||||
uint32_t size;
|
||||
//uint32_t version;
|
||||
//uint16_t cmd;
|
||||
//uint16_t dim;
|
||||
|
||||
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
|
||||
{
|
||||
#warning ipv6 address needed
|
||||
}
|
||||
|
||||
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!=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)
|
||||
{
|
||||
unsigned char sz;
|
||||
uint32_t size;
|
||||
//uint32_t version;
|
||||
//uint16_t cmd;
|
||||
//uint16_t dim;
|
||||
|
||||
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!=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);
|
||||
/* 022 */ enum SCP_CLIENT_STATES_E scp_v1c_pwd_change_cancel(struct SCP_CONNECTION* c);
|
||||
|
||||
/* ... */ enum SCP_CLIENT_STATES_E scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, struct SCP_DISCONNECTED_SESSION** s);
|
||||
/* 041 */ enum SCP_CLIENT_STATES_E scp_v1c_select_session(struct SCP_CONNECTION* c, SCP_SID sid);
|
||||
/* 042 */ enum SCP_CLIENT_STATES_E scp_v1c_select_session_cancel(struct SCP_CONNECTION* c);
|
||||
|
||||
/* 03x */ enum SCP_CLIENT_STATES_E scp_v1c_retrieve_session(struct SCP_CONNECTION* c, struct SCP_SESSION* s, struct SCP_DISCONNECTED_SESSION* ds);
|
||||
|
||||
static enum SCP_CLIENT_STATES_E _scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
||||
{
|
||||
uint32_t version;
|
||||
uint32_t size;
|
||||
uint16_t cmd;
|
||||
uint16_t dim;
|
||||
|
||||
init_stream(c->in_s, c->in_s->size);
|
||||
if (0!=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!=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==2) /* connection denied */
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (cmd==3) /* resend usr/pwd */
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (cmd==20) /* password change */
|
||||
{
|
||||
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;
|
||||
}
|
||||
else if (cmd==30) /* display */
|
||||
{
|
||||
in_uint16_be(c->in_s, s->display);
|
||||
|
||||
return SCP_CLIENT_STATE_OK;
|
||||
}
|
||||
else if (cmd==32) /* 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;
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
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-2006
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file scp_v1.c
|
||||
* @brief scp version 1 implementation
|
||||
* @author Jay Sorg, Simone Fedele
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sesman.h"
|
||||
|
||||
//#include "libscp_types.h"
|
||||
#include "libscp.h"
|
||||
|
||||
extern struct config_sesman g_cfg;
|
||||
|
||||
/******************************************************************************/
|
||||
void DEFAULT_CC
|
||||
scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
|
||||
{
|
||||
long data;
|
||||
int display;
|
||||
int retries;
|
||||
int current_try;
|
||||
enum SCP_SERVER_STATES_E e;
|
||||
struct SCP_DISCONNECTED_SESSION* slist;
|
||||
struct session_item* sitem;
|
||||
int scount;
|
||||
SCP_SID sid;
|
||||
|
||||
retries=g_cfg.sec.login_retry;
|
||||
current_try=retries;
|
||||
|
||||
data=auth_userpass(s->username, s->password);
|
||||
LOG_DBG("user: %s\npass: %s", s->username, s->password);
|
||||
|
||||
while ((!data) && ((retries==0) || (current_try>0)))
|
||||
{
|
||||
LOG_DBG("data %d - retry %d - currenttry %d - expr %d", data, retries, current_try, ((!data) && ((retries==0) || (current_try>0))));
|
||||
|
||||
e=scp_v1s_request_password(c,s,"Wrong username and/or password");
|
||||
|
||||
switch (e)
|
||||
{
|
||||
case SCP_SERVER_STATE_OK:
|
||||
/* all ok, we got new username and password */
|
||||
data=auth_userpass(s->username, s->password);
|
||||
/* one try less */
|
||||
if (current_try>0)
|
||||
{
|
||||
current_try--;
|
||||
}
|
||||
break;
|
||||
case SCP_SERVER_STATE_VERSION_ERR:
|
||||
LOG_DBG("version error",0)
|
||||
case SCP_SERVER_STATE_SIZE_ERR:
|
||||
/* an unknown scp version was requested, so we shut down the */
|
||||
/* connection (and log the fact) */
|
||||
log_message(LOG_LEVEL_WARNING,"protocol violation. connection closed.");
|
||||
return;
|
||||
case SCP_SERVER_STATE_NETWORK_ERR:
|
||||
log_message(LOG_LEVEL_WARNING,"libscp network error.");
|
||||
return;
|
||||
case SCP_SERVER_STATE_SEQUENCE_ERR:
|
||||
log_message(LOG_LEVEL_WARNING,"libscp sequence error.");
|
||||
return;
|
||||
case SCP_SERVER_STATE_INTERNAL_ERR:
|
||||
/* internal error occurred (eg. malloc() error, ecc.) */
|
||||
log_message(LOG_LEVEL_ERROR, "libscp internal error occurred.");
|
||||
return;
|
||||
default:
|
||||
/* dummy: scp_v1s_request_password won't generate any other */
|
||||
/* error other than the ones before */
|
||||
log_message(LOG_LEVEL_ALWAYS, "unknown return from scp_v1s_request_password()");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data)
|
||||
{
|
||||
scp_v1s_deny_connection(c,"Login failed");
|
||||
log_message(LOG_LEVEL_INFO,"Login failed for user %s. Connection terminated", s->username);
|
||||
free_session(s);
|
||||
return;
|
||||
}
|
||||
|
||||
/* testing if login is allowed*/
|
||||
if (0==access_login_allowed(s->username))
|
||||
{
|
||||
scp_v1s_deny_connection(c,"Access to Terminal Server not allowed.");
|
||||
log_message(LOG_LEVEL_INFO,"User %s not allowed on TS. Connection terminated", s->username);
|
||||
free_session(s);
|
||||
return;
|
||||
}
|
||||
|
||||
//check if we need password change
|
||||
|
||||
/* list disconnected sessions */
|
||||
slist=session_get_byuser(s->username, &scount);
|
||||
|
||||
if (scount==0)
|
||||
{
|
||||
#warning FIXME we should check for MaxSessions
|
||||
/* no disconnected sessions - start a new one */
|
||||
log_message(LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
|
||||
if (SCP_SESSION_TYPE_XVNC == s->type)
|
||||
{
|
||||
log_message(LOG_LEVEL_INFO, "starting Xvnc session...");
|
||||
display = session_start(s->width, s->height, s->bpp, s->username, s->password,
|
||||
data, SESMAN_SESSION_TYPE_XVNC);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_message(LOG_LEVEL_INFO, "starting Xrdp session...");
|
||||
display = session_start(s->width, s->height, s->bpp, s->username, s->password,
|
||||
data, SESMAN_SESSION_TYPE_XRDP);
|
||||
}
|
||||
|
||||
e=scp_v1s_connect_new_session(c, display);
|
||||
switch (e)
|
||||
{
|
||||
case SCP_SERVER_STATE_OK:
|
||||
/* all ok, we got new username and password */
|
||||
break;
|
||||
case SCP_SERVER_STATE_NETWORK_ERR:
|
||||
log_message(LOG_LEVEL_WARNING,"libscp network error.");
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (scount==1)
|
||||
{
|
||||
/* there's only one session - returning that */
|
||||
sitem=session_get_bypid(slist->SID);
|
||||
#warning FIXME session_get_by*() should return a malloc()ated struct
|
||||
#warning FIXME or at least lock the chain
|
||||
if (0==sitem)
|
||||
{
|
||||
e=scp_v1s_connection_error(c, "Internal error");
|
||||
log_message(LOG_LEVEL_INFO, "Cannot find session item on the chain");
|
||||
}
|
||||
else
|
||||
{
|
||||
display=sitem->display;
|
||||
e=scp_v1s_reconnect_session(c, slist, display);
|
||||
log_message(LOG_LEVEL_INFO, "User %s reconnected to session %d on port %d", \
|
||||
s->username, sitem->pid, display);
|
||||
}
|
||||
g_free(slist);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 2 or more disconnected sessions - listing */
|
||||
|
||||
//max session x packet = 100 => pkt size = 1300 (13x100)
|
||||
e=scp_v1s_list_sessions(c, scount, slist, &sid);
|
||||
|
||||
//CHECK RETURN
|
||||
|
||||
g_free(slist);
|
||||
}
|
||||
|
||||
/* resource management */
|
||||
if ((e==SCP_SERVER_STATE_OK) && (s->rsr))
|
||||
{
|
||||
/* here goes scp resource sharing code */
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
free_session(s);
|
||||
auth_end(data);
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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-2006
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @file scp_v1.h
|
||||
* @brief scp version 1 declarations
|
||||
* @author Simone Fedele
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SCP_V1_H
|
||||
#define SCP_V1_H
|
||||
|
||||
/**
|
||||
*
|
||||
* @brief processes the stream using scp version 1
|
||||
* @param in_sck connection socket
|
||||
* @param in_s input stream
|
||||
* @param out_s output stream
|
||||
*
|
||||
*/
|
||||
void DEFAULT_CC
|
||||
scp_v1_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
|
||||
|
||||
#endif
|
@ -0,0 +1,40 @@
|
||||
# sesman makefile
|
||||
SESTESTOBJ = sestest.o tcp.o \
|
||||
os_calls.o d3des.o list.o file.o \
|
||||
libscp_v1c.o
|
||||
|
||||
DEFINES = -DLIBSCP_CLIENT
|
||||
|
||||
CFLAGS = -Wall -O2 -I../../common -I../ -I/usr/include/nptl $(DEFINES)
|
||||
LDFLAGS = -L /usr/gnu/lib -I/usr/include/nptl -L/usr/lib/nptl -lpthread -ldl $(DEFINES)
|
||||
C_OS_FLAGS = $(CFLAGS) -c
|
||||
CC = gcc
|
||||
|
||||
all: sestest
|
||||
|
||||
sestest: $(SESTESTOBJ)
|
||||
$(CC) $(LDFLAGS) -o sestest $(SESTESTOBJ)
|
||||
|
||||
os_calls.o: ../../common/os_calls.c
|
||||
$(CC) $(C_OS_FLAGS) ../../common/os_calls.c
|
||||
|
||||
d3des.o: ../../common/d3des.c
|
||||
$(CC) $(C_OS_FLAGS) ../../common/d3des.c
|
||||
|
||||
list.o: ../../common/list.c
|
||||
$(CC) $(C_OS_FLAGS) ../../common/list.c
|
||||
|
||||
file.o: ../../common/file.c
|
||||
$(CC) $(C_OS_FLAGS) ../../common/file.c
|
||||
|
||||
tcp.o: ../tcp.c
|
||||
$(CC) $(C_OS_FLAGS) ../tcp.c
|
||||
|
||||
libscp_v1c.o: ../libscp_v1c.c
|
||||
$(CC) $(C_OS_FLAGS) ../libscp_v1c.c
|
||||
|
||||
clean:
|
||||
rm $(SESTESTOBJ) sestest
|
||||
|
||||
install:
|
||||
#install:wq
|
@ -0,0 +1,155 @@
|
||||
|
||||
|
||||
#include "arch.h"
|
||||
#include "tcp.h"
|
||||
#include "libscp.h"
|
||||
#include "parse.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int inputSession(struct SCP_SESSION* s);
|
||||
unsigned int menuSelect(unsigned int choices);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
struct SCP_SESSION s;
|
||||
struct SCP_CONNECTION c;
|
||||
enum SCP_CLIENT_STATES_E e;
|
||||
int end;
|
||||
|
||||
make_stream(c.in_s);
|
||||
init_stream(c.in_s, 8192);
|
||||
make_stream(c.out_s);
|
||||
init_stream(c.out_s, 8192);
|
||||
c.in_sck = g_tcp_socket();
|
||||
|
||||
if (0!=g_tcp_connect(c.in_sck, "localhost", "3350"))
|
||||
{
|
||||
g_printf("error connecting");
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_printf("001 - send connect request\n");
|
||||
|
||||
/*struct SCP_SESSION
|
||||
{
|
||||
uint16_t display;
|
||||
char* errstr;
|
||||
};*/
|
||||
|
||||
s.type=SCP_SESSION_TYPE_XVNC;
|
||||
s.version=1;
|
||||
s.height=600;
|
||||
s.width=800;
|
||||
s.bpp=8;
|
||||
s.rsr=0;
|
||||
g_strncpy(s.locale,"it_IT 0123456789",18);
|
||||
|
||||
s.username=g_malloc(256, 1);
|
||||
g_strncpy(s.username,"prog",255);
|
||||
|
||||
s.password=g_malloc(256,1);
|
||||
g_strncpy(s.password, "prog", 255);
|
||||
g_printf("%s - %s\n", s.username, s.password);
|
||||
|
||||
|
||||
s.hostname=g_malloc(256,1);
|
||||
g_strncpy(s.hostname, "odin", 255);
|
||||
|
||||
s.addr_type=SCP_ADDRESS_TYPE_IPV4;
|
||||
s.ipv4addr=0;
|
||||
s.errstr=0;
|
||||
|
||||
end=0;
|
||||
e=scp_v1c_connect(&c,&s);
|
||||
|
||||
while (!end)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case SCP_CLIENT_STATE_OK:
|
||||
g_printf("OK : display is %d\n", (int)s.display);
|
||||
end=1;
|
||||
break;
|
||||
case SCP_CLIENT_STATE_SESSION_LIST:
|
||||
g_printf("OK : session list needed\n");
|
||||
break;
|
||||
case SCP_CLIENT_STATE_RESEND_CREDENTIALS:
|
||||
g_printf("ERR: resend credentials - %s\n", s.errstr);
|
||||
g_printf(" username:");
|
||||
scanf("%255s", s.username);
|
||||
g_printf(" password:");
|
||||
scanf("%255s", s.password);
|
||||
e=scp_v1c_resend_credentials(&c,&s);
|
||||
break;
|
||||
case SCP_CLIENT_STATE_CONNECTION_DENIED:
|
||||
g_printf("ERR: connection denied: %s\n", s.errstr);
|
||||
end=1;
|
||||
break;
|
||||
case SCP_CLIENT_STATE_PWD_CHANGE_REQ:
|
||||
g_printf("OK : password change required\n");
|
||||
break;
|
||||
default:
|
||||
g_printf("protocol error: %d\n", e);
|
||||
end=1;
|
||||
}
|
||||
}
|
||||
|
||||
g_tcp_close(c.in_sck);
|
||||
free_stream(c.in_s);
|
||||
free_stream(c.out_s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inputSession(struct SCP_SESSION* s)
|
||||
{
|
||||
unsigned int integer;
|
||||
|
||||
g_printf("username: ");
|
||||
scanf("%255s", s->username);
|
||||
g_printf("password:");
|
||||
scanf("%255s", s->password);
|
||||
g_printf("hostname:");
|
||||
scanf("%255s", s->hostname);
|
||||
|
||||
g_printf("session type:\n");
|
||||
g_printf("0: Xvnc\n", SCP_SESSION_TYPE_XVNC);
|
||||
g_printf("1: x11rdp\n", SCP_SESSION_TYPE_XRDP);
|
||||
integer=menuSelect(1);
|
||||
if (integer==1)
|
||||
{
|
||||
s->type=SCP_SESSION_TYPE_XRDP;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->type=SCP_SESSION_TYPE_XVNC;
|
||||
}
|
||||
|
||||
s->version=1;
|
||||
s->height=600;
|
||||
s->width=800;
|
||||
s->bpp=8;
|
||||
|
||||
/* fixed for now */
|
||||
s->rsr=0;
|
||||
g_strncpy(s->locale,"it_IT 0123456789",18);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int menuSelect(unsigned int choices)
|
||||
{
|
||||
unsigned int sel;
|
||||
int ret;
|
||||
|
||||
ret=scanf("%u", &sel);
|
||||
|
||||
while ((ret==0) || (sel > choices))
|
||||
{
|
||||
g_printf("invalid choice.");
|
||||
scanf("%u", &sel);
|
||||
}
|
||||
|
||||
return sel;
|
||||
}
|
Loading…
Reference in New Issue