Skip to content
Snippets Groups Projects
Commit f5bc174b authored by Corentin Chary's avatar Corentin Chary Committed by Corentin Chary
Browse files

pkcs11: win32 port

parent 93dc073f
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,22 @@ cmake_minimum_required (VERSION 2.6)
project (pkcs11 C)
set(PKCS11_PROXY_SRCS gck-rpc-module.c gck-rpc-message.c gck-rpc-util.c egg-buffer.c)
set(PKCS11_DAEMON_SRCS egg-buffer.c gck-rpc-daemon-standalone.c gck-rpc-dispatch.c gck-rpc-message.c gck-rpc-util.c)
add_definitions(-Wall)
add_library(pkcs11-proxy.so SHARED gck-rpc-module.c gck-rpc-message.c egg-buffer.c)
add_executable (pkcs11-daemon egg-buffer.c gck-rpc-daemon-standalone.c gck-rpc-dispatch.c gck-rpc-message.c gck-rpc-util.c)
add_library(pkcs11-proxy SHARED ${PKCS11_PROXY_SRCS})
add_executable (pkcs11-daemon ${PKCS11_DAEMON_SRCS})
if (WIN32)
include_directories("ext/include")
add_library(dl STATIC IMPORTED)
set_property(TARGET dl PROPERTY
IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/ext/lib/libdl.a)
target_link_libraries (pkcs11-daemon ws2_32)
target_link_libraries (pkcs11-proxy ws2_32)
endif ()
target_link_libraries (pkcs11-proxy pthread)
target_link_libraries (pkcs11-daemon dl pthread)
......@@ -6,11 +6,12 @@
# include <stdint.h>
# include <stdlib.h>
# include <limits.h>
# include <winsock2.h>
typedef uint32_t __uid32_t;
typedef uint32_t __gid32_t;
typedef uint32_t uid_t;
typedef size_t socklen_t;
typedef int socklen_t;
struct sockaddr_un {
uint16_t sun_family;
......@@ -23,6 +24,18 @@ enum {
SHUT_RDWR /* No more receptions or transmissions. */
};
#ifdef __MINGW32__
static inline int inet_aton(const char * cp, struct in_addr *pin)
{
int rc = inet_addr(cp);
if (rc == -1 && strcmp(cp, "255.255.255.255"))
return 0;
pin->s_addr = rc;
return 1;
}
#endif
#endif
#endif /* CONFIG_H */
/*
* dlfcn-win32
* Copyright (c) 2007 Ramiro Polla
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DLFCN_H
#define DLFCN_H
/* POSIX says these are implementation-defined.
* To simplify use with Windows API, we treat them the same way.
*/
#define RTLD_LAZY 0
#define RTLD_NOW 0
#define RTLD_GLOBAL (1 << 1)
#define RTLD_LOCAL (1 << 2)
/* These two were added in The Open Group Base Specifications Issue 6.
* Note: All other RTLD_* flags in any dlfcn.h are not standard compliant.
*/
#define RTLD_DEFAULT 0
#define RTLD_NEXT 0
void *dlopen ( const char *file, int mode );
int dlclose( void *handle );
void *dlsym ( void *handle, const char *name );
char *dlerror( void );
#endif /* DLFCN_H */
File added
......@@ -2006,7 +2006,7 @@ static int read_all(int sock, unsigned char *data, size_t len)
while (len > 0) {
r = recv(sock, data, len, 0);
r = recv(sock, (void *)data, len, 0);
if (r == 0) {
/* Connection was closed on client */
......@@ -2035,7 +2035,7 @@ static int write_all(int sock, unsigned char *data, size_t len)
while (len > 0) {
r = send(sock, data, len, 0);
r = send(sock, (void *)data, len, 0);
if (r == -1) {
if (errno == EPIPE) {
......@@ -2204,18 +2204,6 @@ void gck_rpc_layer_accept(void)
pkcs11_dispatchers = ds;
}
#ifdef __MINGW32__
int inet_aton(const char * cp, struct in_addr *pin)
{
int rc = inet_addr(cp);
if (rc == -1 && strcmp(cp, "255.255.255.255"))
return 0;
pin->s_addr = rc;
return 1;
}
#endif
int gck_rpc_layer_initialize(const char *prefix, CK_FUNCTION_LIST_PTR module)
{
struct sockaddr_un addr;
......@@ -2281,7 +2269,7 @@ int gck_rpc_layer_initialize(const char *prefix, CK_FUNCTION_LIST_PTR module)
}
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
&one, sizeof(one)) == -1) {
(char *)&one, sizeof(one)) == -1) {
gck_rpc_warn
("couldn't create set pkcs11 socket options : %s",
strerror(errno));
......
......@@ -30,11 +30,15 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/un.h>
#ifdef __MINGW32__
# include <winsock2.h>
#else
# include <sys/socket.h>
# include <sys/un.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <stdlib.h>
#include <limits.h>
......@@ -280,12 +284,14 @@ static CK_RV call_connect(CallState * cs)
}
}
/* close on exec */
#ifndef __MINGW32__
/* close on exec */
if (fcntl(sock, F_SETFD, 1) == -1) {
close(sock);
warning(("couldn't secure socket: %s", strerror(errno)));
return CKR_DEVICE_ERROR;
}
#endif
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
close(sock);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment