more smartcard locking fixes

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@1327 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2006-11-03 23:51:35 +00:00
parent 8419d91138
commit c3f49ea246
7 changed files with 40 additions and 38 deletions

View File

@ -83,6 +83,10 @@ channel_send(STREAM s, VCHANNEL * channel)
uint32 thislength, remaining;
uint8 *data;
#ifdef WITH_SCARD
scard_lock(SCARD_LOCK_CHANNEL);
#endif
/* first fragment sent in-place */
s_pop_layer(s, channel_hdr);
length = s->end - s->p - 8;
@ -125,6 +129,10 @@ channel_send(STREAM s, VCHANNEL * channel)
data += thislength;
}
#ifdef WITH_SCARD
scard_unlock(SCARD_LOCK_CHANNEL);
#endif
}
void

View File

@ -425,3 +425,10 @@ enum RDP_INPUT_DEVICE
#define SEAMLESSRDP_HELLO_RECONNECT 0x0001
#define SEAMLESSRDP_HELLO_HIDDEN 0x0002
/* Smartcard constants */
#define SCARD_LOCK_TCP 0
#define SCARD_LOCK_SEC 1
#define SCARD_LOCK_CHANNEL 2
#define SCARD_LOCK_RDPDR 3
#define SCARD_LOCK_LAST 4

View File

@ -307,10 +307,8 @@ unsigned int seamless_send_focus(unsigned long id, unsigned long flags);
/* scard.c */
void scardSetInfo(uint32 device, uint32 id, uint32 bytes_out);
int scard_enum_devices(uint32 * id, char *optarg);
void scard_tcp_lock(void);
void scard_tcp_unlock(void);
void scard_sec_lock(void);
void scard_sec_unlock(void);
void scard_lock(int lock);
void scard_unlock(int lock);
STREAM scard_tcp_init(void);
void scard_tcp_connect(void);
void scard_tcp_reset_state(void);

10
rdpdr.c
View File

@ -66,11 +66,7 @@ extern DEVICE_FNS scard_fns;
extern FILEINFO g_fileinfo[];
extern BOOL g_notify_stamp;
#ifdef WITH_SCARD
VCHANNEL *rdpdr_channel;
#else
static VCHANNEL *rdpdr_channel;
#endif
/* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */
NTHANDLE g_min_timeout_fd;
@ -323,6 +319,9 @@ rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, ui
uint8 magic[4] = "rDCI";
STREAM s;
#ifdef WITH_SCARD
scard_lock(SCARD_LOCK_RDPDR);
#endif
s = channel_init(rdpdr_channel, 20 + length);
out_uint8a(s, magic, 4);
out_uint32_le(s, device);
@ -337,6 +336,9 @@ rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, ui
/* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */
#endif
channel_send(s, rdpdr_channel);
#ifdef WITH_SCARD
scard_unlock(SCARD_LOCK_RDPDR);
#endif
}
static void

35
scard.c
View File

@ -44,8 +44,7 @@
static struct stream out[STREAM_COUNT];
static int cur_stream_id = 0;
static pthread_mutex_t *tcp_sendcontrol_mutex = NULL;
static pthread_mutex_t *sec_channels_mutex = NULL;
static pthread_mutex_t **scard_mutex = NULL;
static uint32 curDevice = 0, curId = 0, curBytesOut = 0;
static PSCNameMapRec nameMapList = NULL;
@ -2620,39 +2619,27 @@ DEVICE_FNS scard_fns = {
#endif /* MAKE_PROTO */
void
scard_tcp_lock(void)
scard_lock(int lock)
{
if (!tcp_sendcontrol_mutex)
if (!scard_mutex)
{
tcp_sendcontrol_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
pthread_mutex_init(tcp_sendcontrol_mutex, NULL);
scard_mutex =
(pthread_mutex_t **) xmalloc(sizeof(pthread_mutex_t *) * SCARD_LOCK_LAST);
}
pthread_mutex_lock(tcp_sendcontrol_mutex);
}
void
scard_tcp_unlock(void)
{
pthread_mutex_unlock(tcp_sendcontrol_mutex);
}
void
scard_sec_lock(void)
{
if (!sec_channels_mutex)
if (!scard_mutex[lock])
{
sec_channels_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
pthread_mutex_init(sec_channels_mutex, NULL);
scard_mutex[lock] = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t));
pthread_mutex_init(scard_mutex[lock], NULL);
}
pthread_mutex_lock(sec_channels_mutex);
pthread_mutex_lock(scard_mutex[lock]);
}
void
scard_sec_unlock(void)
scard_unlock(int lock)
{
pthread_mutex_unlock(sec_channels_mutex);
pthread_mutex_unlock(scard_mutex[lock]);
}
STREAM

View File

@ -363,7 +363,7 @@ sec_send_to_channel(STREAM s, uint32 flags, uint16 channel)
int datalen;
#ifdef WITH_SCARD
scard_sec_lock();
scard_lock(SCARD_LOCK_SEC);
#endif
s_pop_layer(s, sec_hdr);
@ -387,7 +387,7 @@ sec_send_to_channel(STREAM s, uint32 flags, uint16 channel)
mcs_send_to_channel(s, channel);
#ifdef WITH_SCARD
scard_sec_unlock();
scard_unlock(SCARD_LOCK_SEC);
#endif
}

8
tcp.c
View File

@ -46,7 +46,7 @@ tcp_init(uint32 maxlen)
STREAM result = NULL;
#ifdef WITH_SCARD
scard_tcp_lock();
scard_lock(SCARD_LOCK_TCP);
result = scard_tcp_init();
#else
result = &out;
@ -61,7 +61,7 @@ tcp_init(uint32 maxlen)
result->p = result->data;
result->end = result->data + result->size;
#ifdef WITH_SCARD
scard_tcp_unlock();
scard_unlock(SCARD_LOCK_TCP);
#endif
return result;
}
@ -74,7 +74,7 @@ tcp_send(STREAM s)
int sent, total = 0;
#ifdef WITH_SCARD
scard_tcp_lock();
scard_lock(SCARD_LOCK_TCP);
#endif
while (total < length)
{
@ -88,7 +88,7 @@ tcp_send(STREAM s)
total += sent;
}
#ifdef WITH_SCARD
scard_tcp_unlock();
scard_unlock(SCARD_LOCK_TCP);
#endif
}