Skip to content

Commit

Permalink
adding scp v1 first code, fixed passwd auth for disabled password
Browse files Browse the repository at this point in the history
  • Loading branch information
ilsimo committed Nov 24, 2006
1 parent b681420 commit 078b4d3
Show file tree
Hide file tree
Showing 13 changed files with 982 additions and 46 deletions.
7 changes: 5 additions & 2 deletions sesman/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LIBSCPOBJ = libscp_vX.o libscp_v0.o libscp_v1s.o

SESMANOBJ = sesman.o config.o tcp.o sig.o session.o env.o \
os_calls.o d3des.o list.o file.o log.o access.o \
scp.o scp_v0.o thread.o lock.o \
scp.o scp_v0.o scp_v1.o thread.o lock.o \
$(LIBSCPOBJ)

SESRUNOBJ = sesrun.o config.o tcp.o lock.o \
Expand All @@ -16,7 +16,7 @@ MANDIR = /usr/local/man
DOCDIR = /usr/doc/xrdp

DEFINES = -DSESMAN_CFG_FILE=\"$(CFGDIR)/sesman.ini\" \
-DSESMAN_PID_FILE=\"$(PIDDIR)/sesman.pid\"
-DSESMAN_PID_FILE=\"$(PIDDIR)/sesman.pid\" -DDEBUG

CFLAGS = -Wall -O2 -I../common -I/usr/include/nptl $(DEFINES)
LDFLAGS = -L /usr/gnu/lib -I/usr/include/nptl -L/usr/lib/nptl -lpthread $(DEFINES)
Expand Down Expand Up @@ -44,15 +44,18 @@ kerberos-base: $(SESMANOBJ) verify_user_kerberos.o

tools: $(SESRUNOBJ)
$(CC) $(LDFLAGS) -o sesrun $(SESRUNOBJ) -ldl
make -C tools

clean:
rm -f $(SESMANOBJ) verify_user.o verify_user_pam.o verify_user_pam_userpass.o sesman sesrun.o sesrun
make -C tools clean

install:
install sesman $(DESTDIR)/sesman
install sesrun $(DESTDIR)/sesrun
install startwm.sh $(DESTDIR)/startwm.sh
install sesman.ini $(CFGDIR)/sesman.ini
make -C tools install

installdeb:
install sesman $(DESTDIRDEB)/usr/lib/xrdp/sesman
Expand Down
2 changes: 1 addition & 1 deletion sesman/libscp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
#include "libscp_vX.h"
#include "libscp_v0.h"
#include "libscp_v1s.h"
//#include "libscp_v1c.h"
#include "libscp_v1c.h"

#endif
249 changes: 249 additions & 0 deletions sesman/libscp_v1c.c
Original file line number Diff line number Diff line change
@@ -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;
}
23 changes: 7 additions & 16 deletions sesman/libscp_v1c.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,15 @@

#include "libscp_types.h"

enum SCP_CLIENt_STATES_E
{
SCP_CLIENT_STATE_NO,
SCP_CLIENT_STATE_WRONGPWD,
SCP_CLIENT_STATE_PWDCHG_REQ,
SCP_CLIENT_STATE_PWDCHG_CANCEL,
SCP_CLIENT_STATE_
};

/* client API */
/* 001 */ SCP_CLIENT_STATES_E scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
/* 004 */ SCP_CLIENT_STATES_E scp_v1c_resend_credentials(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
/* 001 */ enum SCP_CLIENT_STATES_E scp_v1c_connect(struct SCP_CONNECTION* c, struct SCP_SESSION* s);
/* 004 */ enum SCP_CLIENT_STATES_E scp_v1c_resend_credentials(struct SCP_CONNECTION* c, struct SCP_SESSION* s);

/* 021 */ SCP_CLIENT_STATES_E scp_v1c_pwd_change(struct SCP_CONNECTION* c, char* newpass);
/* 022 */ SCP_CLIENT_STATES_E scp_v1c_pwd_change_cancel(struct SCP_CONNECTION* c);
/* 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);

/* ... */ SCP_CLIENT_STATES_E scp_v1c_get_session_list(struct SCP_CONNECTION* c, int* scount, struct SCP_DISCONNECTED_SESSION** s);
/* 041 */ SCP_CLIENT_STATES_E scp_v1c_select_session(struct SCP_CONNECTION* c, SCP_SID sid);
/* 042 */ SCP_CLIENT_STATES_E scp_v1c_select_session_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);

#endif
Loading

0 comments on commit 078b4d3

Please sign in to comment.