wfreerdp: fix portability issues

This commit is contained in:
Marc-André Moreau 2012-03-05 21:04:42 -05:00
parent 6ed928f362
commit 6c9ae5ddad
22 changed files with 135 additions and 54 deletions

View File

@ -19,6 +19,8 @@
* limitations under the License.
*/
#include <freerdp/utils/windows.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

View File

@ -22,12 +22,7 @@
#ifndef __WFREERDP_H
#define __WFREERDP_H
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#include <windows.h>
#include <freerdp/utils/windows.h>
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>

View File

@ -20,6 +20,9 @@
#ifndef FREERDP_CRYPTO_H
#define FREERDP_CRYPTO_H
/* OpenSSL includes windows.h */
#include <freerdp/utils/windows.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rc4.h>

View File

@ -22,10 +22,9 @@
#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/utils/windows.h>
#ifdef _WIN32
#include <windows.h>
#include <winsock.h>
#include <winerror.h>
#ifdef NATIVE_SSPI

View File

@ -0,0 +1,26 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* TCP Utils
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#ifndef FREERDP_TCP_UTILS_H
#define FREERDP_TCP_UTILS_H
#include <freerdp/api.h>
#include <freerdp/utils/windows.h>
#endif /* FREERDP_TCP_UTILS_H */

View File

@ -0,0 +1,37 @@
/**
* FreeRDP: A Remote Desktop Protocol Client
* Windows Header Utils
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#ifndef FREERDP_WINDOWS_UTILS_H
#define FREERDP_WINDOWS_UTILS_H
/* Windows header include order is important, use this instead of including windows.h directly */
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#endif /* FREERDP_WINDOWS_UTILS_H */

View File

@ -24,10 +24,7 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/extension.h>
#ifdef _WIN32
#include <windows.h>
#endif
#include <freerdp/utils/windows.h>
#define FREERDP_EXT_MAX_COUNT 16

View File

@ -21,11 +21,7 @@
#ifndef __TCP_H
#define __TCP_H
#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#endif
#include <freerdp/utils/windows.h>
#include <freerdp/types.h>
#include <freerdp/settings.h>

View File

@ -80,11 +80,12 @@ char* der_read_general_string(STREAM* s, int *length)
int der_write_principal_name(STREAM* s, uint8 ntype, char** name)
{
uint8 len;
len = 0;
char** p;
len = 0;
p = name;
while(*p != NULL)
while (*p != NULL)
{
len += strlen(*p) + 2;
p++;
@ -97,7 +98,7 @@ int der_write_principal_name(STREAM* s, uint8 ntype, char** name)
der_write_contextual_tag(s, 1, len + 2, true);
der_write_sequence_tag(s, len);
while(*p != NULL)
while (*p != NULL)
{
der_write_general_string(s, *p);
p++;

View File

@ -22,9 +22,9 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef _WIN32
#include <unistd.h>
#include <netdb.h>
#include <net/if.h>
#include <unistd.h>
@ -45,6 +45,7 @@
#include <freerdp/sspi/sspi.h>
#include <freerdp/utils/blob.h>
#include <freerdp/utils/print.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/unicode.h>
@ -598,7 +599,7 @@ void krb_asreq_send(KRB_CONTEXT* krb_ctx, uint8 errcode)
{
freerdp_blob_alloc(&msg, 21);
memcpy(msg.data, "\x30\x13\xa0\x11\x18\x0f", 6); // PA-ENC-TS-ENC without optional pausec
memcpy(msg.data + 6, krb_asreq->req_body.from, 15);
memcpy(((uint8*) msg.data) + 6, krb_asreq->req_body.from, 15);
enckey = string2key(&(krb_ctx->passwd), krb_ctx->enctype);
encmsg = crypto_kdcmsg_encrypt(&msg, enckey, 1); //RFC4757 section 3 for msgtype (T=1)
enc_data.enctype = enckey->enctype;

View File

@ -20,22 +20,24 @@
#ifndef FREERDP_SSPI_KERBEROS_PRIVATE_H
#define FREERDP_SSPI_KERBEROS_PRIVATE_H
#include <sys/types.h>
#include <netinet/in.h>
#ifndef _WIN32
#include <netdb.h>
#include <arpa/nameser.h>
#include <resolv.h>
#ifdef _WIN32
#include <winsock2.h>
#include <Windows.h>
#include <ws2tcpip.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#endif
#include <freerdp/sspi/sspi.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
#include <sys/types.h>
#include <freerdp/types.h>
#include <freerdp/settings.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/blob.h>
#include <freerdp/sspi/sspi.h>
#define MSKRB_OID "1.2.840.48018.1.2.2"
#define STDKRB_OID "1.2.840.113554.1.2.2"

View File

@ -68,7 +68,7 @@ rdpBlob* crypto_kdcmsg_encrypt_rc4(rdpBlob* msg, uint8* key, uint32 msgtype)
HMAC(EVP_md5(), (void*) K1, 16, (uint8*)&(edata->Checksum), 16, (void*)K3, NULL);
memcpy(encmsg->data, &(edata->Checksum), 16);
rc4 = crypto_rc4_init(K3, 16);
crypto_rc4(rc4, len - 16, (uint8*)edata->Confounder, (uint8*)(encmsg->data + 16));
crypto_rc4(rc4, len - 16, (uint8*) edata->Confounder, (uint8*)(((uint8*) encmsg->data) + 16));
crypto_rc4_free(rc4);
xfree(K1);
xfree(K3);
@ -100,10 +100,10 @@ rdpBlob* crypto_kdcmsg_decrypt_rc4(rdpBlob* msg, uint8* key, uint32 msgtype)
K3 = xzalloc(16);
len = msg->length;
edata = xzalloc(len);
HMAC(EVP_md5(), (void*) key, 16, (uint8*)&msgtype, 4, (void*) K1, NULL);
HMAC(EVP_md5(), (void*) K1, 16, msg->data , 16, (void*)K3, NULL);
HMAC(EVP_md5(), (void*) key, 16, (uint8*) &msgtype, 4, (void*) K1, NULL);
HMAC(EVP_md5(), (void*) K1, 16, (uint8*) msg->data , 16, (void*) K3, NULL);
rc4 = crypto_rc4_init(K3, 16);
crypto_rc4(rc4, len - 16, (uint8*)(msg->data + 16), (uint8*)edata->Confounder);
crypto_rc4(rc4, len - 16, (uint8*)(((uint8*) msg->data) + 16), (uint8*) edata->Confounder);
crypto_rc4_free(rc4);
HMAC(EVP_md5(), (void*) K1, 16, (uint8*)edata->Confounder, len - 16, (void*)&(edata->Checksum), NULL);
if(memcmp(msg->data, &edata->Checksum, 16))

View File

@ -674,7 +674,7 @@ ENCKDCREPPart* krb_decode_enc_reppart(rdpBlob* msg, uint8 apptag)
reppart = xnew(ENCKDCREPPart);
s = stream_new(0);
stream_attach(s, msg->data + 24, msg->length);
stream_attach(s, ((uint8*) msg->data) + 24, msg->length);
verlen = msg->length - 24;
/* application tag */

View File

@ -69,12 +69,18 @@ int krb_encode_cname(STREAM* s, uint8 tag, char* cname)
{
uint8* bm;
uint32 len;
char* names[2];
names[0] = cname;
names[1] = NULL;
len = strlen(cname) + 15;
stream_rewind(s, len);
stream_get_mark(s, bm);
der_write_contextual_tag(s, tag, len - 2, true);
der_write_principal_name(s, NAME_TYPE_PRINCIPAL, (char*[]){ cname, NULL });
der_write_principal_name(s, NAME_TYPE_PRINCIPAL, names);
stream_set_mark(s, bm);
return len;
}
@ -82,17 +88,30 @@ int krb_encode_sname(STREAM* s, uint8 tag, char* sname)
{
uint8* bm;
char* str;
char* names[3];
uint32 len, tmp;
len = strlen(sname) - 1 + 17;
stream_rewind(s, len);
stream_get_mark(s, bm);
der_write_contextual_tag(s, tag, len - 2, true);
tmp = index(sname, '/') - sname;
str = (char*)xzalloc(tmp + 1);
tmp = strchr(sname, '/') - sname;
str = (char*) xzalloc(tmp + 1);
strncpy(str, sname, tmp);
der_write_principal_name(s, NAME_TYPE_SERVICE, (char*[]){ str, (sname + tmp + 1), NULL });
names[0] = str;
names[1] = sname + tmp + 1;
names[2] = NULL;
der_write_principal_name(s, NAME_TYPE_SERVICE, names);
xfree(str);
stream_set_mark(s, bm);
return len;
}
@ -204,12 +223,14 @@ int krb_encode_checksum(STREAM* s, rdpBlob* cksum, int cktype)
int krb_encode_padata(STREAM* s, PAData** pa_data)
{
uint32 totlen, curlen;
totlen = 0;
uint32 totlen;
uint32 curlen;
PAData** lpa_data;
totlen = 0;
lpa_data = pa_data;
while(*lpa_data != NULL)
while (*lpa_data != NULL)
{
/* padata value */
curlen = krb_encode_octet_string(s, ((*lpa_data)->value).data, ((*lpa_data)->value).length);
@ -221,6 +242,7 @@ int krb_encode_padata(STREAM* s, PAData** pa_data)
totlen += curlen;
lpa_data++;
}
totlen += krb_encode_sequence_tag(s, totlen);
return totlen;

View File

@ -17,11 +17,12 @@
* limitations under the License.
*/
#include <time.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <time.h>
#include <freerdp/crypto/tls.h>
#include <freerdp/utils/stream.h>

View File

@ -35,13 +35,13 @@
#endif
#include <freerdp/utils/file.h>
#include <freerdp/utils/windows.h>
#ifndef _WIN32
#define PATH_SEPARATOR_STR "/"
#define PATH_SEPARATOR_CHR '/'
#define HOME_ENV_VARIABLE "HOME"
#else
#include <windows.h>
#define PATH_SEPARATOR_STR "\\"
#define PATH_SEPARATOR_CHR '\\'
#define HOME_ENV_VARIABLE "HOME"

View File

@ -17,6 +17,8 @@
* limitations under the License.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -24,12 +26,10 @@
#include <freerdp/utils/print.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/load_plugin.h>
#include "config.h"
#include <freerdp/utils/windows.h>
#ifdef _WIN32
#include <windows.h>
#define DLOPEN(f) LoadLibraryA(f)
#define DLSYM(f, n) GetProcAddress(f, n)
#define DLCLOSE(f) FreeLibrary(f)

View File

@ -19,9 +19,9 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/mutex.h>
#include <freerdp/utils/windows.h>
#ifdef _WIN32
#include <windows.h>
#define freerdp_mutex_t HANDLE
#else
#include <pthread.h>

View File

@ -19,6 +19,7 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/semaphore.h>
#include <freerdp/utils/windows.h>
#if defined __APPLE__
@ -31,7 +32,6 @@
#elif defined _WIN32
#include <windows.h>
#define freerdp_sem_t HANDLE
#else

View File

@ -18,14 +18,13 @@
*/
#include <freerdp/utils/sleep.h>
#include <freerdp/utils/windows.h>
#include <time.h>
#ifndef _WIN32
#define _XOPEN_SOURCE 500
#include <unistd.h>
#else
#include <windows.h>
#endif
void freerdp_sleep(uint32 seconds)

View File

@ -22,8 +22,9 @@
#include <string.h>
#include <time.h>
#include <freerdp/utils/windows.h>
#ifdef _WIN32
#include <windows.h>
#ifdef _MSC_VER
#include <process.h>
#endif

View File

@ -23,11 +23,10 @@
#include <string.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/wait_obj.h>
#include <freerdp/utils/windows.h>
#ifndef _WIN32
#include <sys/time.h>
#else
#include <winsock2.h>
#endif
#ifdef HAVE_UNISTD_H