ReactOS  0.4.14-dev-115-g4576127
net.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include "wine/debug.h"
#include "wine/library.h"
#include "windef.h"
#include "winbase.h"
#include "winhttp.h"
#include "wincrypt.h"
#include "schannel.h"
#include "winhttp_private.h"
#include "winsock2.h"
Include dependency graph for net.c:

Go to the source code of this file.

Classes

struct  resolve_args
 

Macros

#define NONAMELESSUNION
 
#define USE_WS_PREFIX
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (winhttp)
 
static int sock_get_error (int err)
 
static int sock_send (int fd, const void *msg, size_t len, int flags)
 
static int sock_recv (int fd, void *msg, size_t len, int flags)
 
static DWORD netconn_verify_cert (PCCERT_CONTEXT cert, WCHAR *server, DWORD security_flags)
 
void netconn_unload (void)
 
netconn_tnetconn_create (hostdata_t *host, const struct sockaddr_storage *sockaddr, int timeout)
 
BOOL netconn_close (netconn_t *conn)
 
BOOL netconn_secure_connect (netconn_t *conn, WCHAR *hostname, DWORD security_flags, CredHandle *cred_handle)
 
static BOOL send_ssl_chunk (netconn_t *conn, const void *msg, size_t size)
 
BOOL netconn_send (netconn_t *conn, const void *msg, size_t len, int *sent)
 
static BOOL read_ssl_chunk (netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof)
 
BOOL netconn_recv (netconn_t *conn, void *buf, size_t len, int flags, int *recvd)
 
ULONG netconn_query_data_available (netconn_t *conn)
 
DWORD netconn_set_timeout (netconn_t *netconn, BOOL send, int value)
 
BOOL netconn_is_alive (netconn_t *netconn)
 
static DWORD resolve_hostname (const WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr_storage *sa)
 
static DWORD CALLBACK resolve_proc (LPVOID arg)
 
BOOL netconn_resolve (WCHAR *hostname, INTERNET_PORT port, struct sockaddr_storage *sa, int timeout)
 
const voidnetconn_get_certificate (netconn_t *conn)
 
int netconn_get_cipher_strength (netconn_t *conn)
 

Variables

static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 }
 
static CRITICAL_SECTION_DEBUG critsect_debug
 

Macro Definition Documentation

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 42 of file net.c.

◆ USE_WS_PREFIX

#define USE_WS_PREFIX

Definition at line 56 of file net.c.

Function Documentation

◆ netconn_close()

BOOL netconn_close ( netconn_t conn)

Definition at line 405 of file net.c.

406 {
407  int res;
408 
409  if (conn->secure)
410  {
411  heap_free( conn->peek_msg_mem );
412  heap_free(conn->ssl_buf);
413  heap_free(conn->extra_buf);
415  }
416  res = closesocket( conn->socket );
417  release_host( conn->host );
418  heap_free(conn);
419  if (res == -1)
420  {
422  return FALSE;
423  }
424  return TRUE;
425 }
CtxtHandle ssl_ctx
#define TRUE
Definition: types.h:120
static int sock_get_error(int err)
Definition: net.c:77
char * ssl_buf
int errno
void release_host(hostdata_t *host)
Definition: request.c:1526
#define closesocket
Definition: main.c:39
char * extra_buf
hostdata_t * host
GLuint res
Definition: glext.h:9613
void set_last_error(DWORD error)
Definition: session.c:59
char * peek_msg_mem
SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
Definition: wrapper.c:450
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by close_connection(), connection_collector(), handle_redirect(), netconn_create(), and open_connection().

◆ netconn_create()

netconn_t* netconn_create ( hostdata_t host,
const struct sockaddr_storage sockaddr,
int  timeout 
)

Definition at line 300 of file net.c.

301 {
302  netconn_t *conn;
303  unsigned int addr_len;
304  BOOL ret = FALSE;
305  int res;
306  ULONG state;
307 
308  conn = heap_alloc_zero(sizeof(*conn));
309  if (!conn) return NULL;
310  conn->host = host;
311  conn->sockaddr = *sockaddr;
312  if ((conn->socket = socket( sockaddr->ss_family, SOCK_STREAM, 0 )) == -1)
313  {
314  WARN("unable to create socket (%s)\n", strerror(errno));
316  heap_free(conn);
317  return NULL;
318  }
319 
320  switch (conn->sockaddr.ss_family)
321  {
322  case AF_INET:
323  addr_len = sizeof(struct sockaddr_in);
324  break;
325  case AF_INET6:
326  addr_len = sizeof(struct sockaddr_in6);
327  break;
328  default:
329  assert(0);
330  }
331 
332  if (timeout > 0)
333  {
334  state = 1;
335  ioctlsocket( conn->socket, FIONBIO, &state );
336  }
337 
338  for (;;)
339  {
340  res = 0;
341  if (connect( conn->socket, (const struct sockaddr *)&conn->sockaddr, addr_len ) < 0)
342  {
343  res = sock_get_error( errno );
344  if (res == WSAEWOULDBLOCK || res == WSAEINPROGRESS)
345  {
346 #ifdef __REACTOS__
347  /* ReactOS: use select instead of poll */
348  fd_set outfd;
349  struct timeval tv;
350 
351  FD_ZERO(&outfd);
352  FD_SET(conn->socket, &outfd);
353 
354  tv.tv_sec = 0;
355  tv.tv_usec = timeout * 1000;
356  for (;;)
357  {
358  res = 0;
359 
360  if (select( 0, NULL, &outfd, NULL, &tv ) > 0)
361 #else
362  struct pollfd pfd;
363 
364  pfd.fd = conn->socket;
365  pfd.events = POLLOUT;
366  for (;;)
367  {
368  res = 0;
369  if (poll( &pfd, 1, timeout ) > 0)
370 #endif
371  {
372  ret = TRUE;
373  break;
374  }
375  else
376  {
377  res = sock_get_error( errno );
378  if (res != WSAEINTR) break;
379  }
380  }
381  }
382  if (res != WSAEINTR) break;
383  }
384  else
385  {
386  ret = TRUE;
387  break;
388  }
389  }
390  if (timeout > 0)
391  {
392  state = 0;
393  ioctlsocket( conn->socket, FIONBIO, &state );
394  }
395  if (!ret)
396  {
397  WARN("unable to connect to host (%d)\n", res);
398  set_last_error( res );
399  netconn_close( conn );
400  return NULL;
401  }
402  return conn;
403 }
Definition: winsock.h:66
#define TRUE
Definition: types.h:120
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define WARN(fmt,...)
Definition: debug.h:111
char * host
Definition: whois.c:55
static int sock_get_error(int err)
Definition: net.c:77
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define assert(x)
Definition: debug.h:53
Definition: dhcpd.h:245
int errno
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
const char * strerror(int err)
Definition: compat_str.c:23
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: sockctrl.c:23
#define WSAEINPROGRESS
Definition: winerror.h:1949
struct sockaddr_storage sockaddr
unsigned int BOOL
Definition: ntddk_ex.h:94
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
smooth NULL
Definition: ftsmooth.c:416
#define AF_INET6
Definition: winsock.h:369
#define ioctlsocket
Definition: main.c:40
int poll(struct pollfd *ufds, int nfds, int timeout)
Definition: adnstest.c:68
Definition: linux.h:1867
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
int ret
static int state
Definition: maze.c:121
#define FIONBIO
Definition: winsock.h:149
hostdata_t * host
GLuint res
Definition: glext.h:9613
unsigned int ULONG
Definition: retypes.h:1
#define AF_INET
Definition: tcpip.h:117
void set_last_error(DWORD error)
Definition: session.c:59
#define SOCK_STREAM
Definition: tcpip.h:118
#define POLLOUT
Definition: linux.h:1855
BOOL netconn_close(netconn_t *conn)
Definition: net.c:405
#define WSAEINTR
Definition: winerror.h:1942
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by open_connection().

◆ netconn_get_certificate()

const void* netconn_get_certificate ( netconn_t conn)

Definition at line 928 of file net.c.

929 {
930  const CERT_CONTEXT *ret;
932 
933  if (!conn->secure) return NULL;
935  return res == SEC_E_OK ? ret : NULL;
936 }
CtxtHandle ssl_ctx
#define SECPKG_ATTR_REMOTE_CERT_CONTEXT
Definition: schannel.h:69
smooth NULL
Definition: ftsmooth.c:416
LONG SECURITY_STATUS
Definition: sspi.h:34
int ret
#define SEC_E_OK
Definition: winerror.h:2356
SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
Definition: wrapper.c:535
GLuint res
Definition: glext.h:9613

Referenced by request_query_option().

◆ netconn_get_cipher_strength()

int netconn_get_cipher_strength ( netconn_t conn)

Definition at line 938 of file net.c.

939 {
942 
943  if (!conn->secure) return 0;
944  res = QueryContextAttributesW(&conn->ssl_ctx, SECPKG_ATTR_CONNECTION_INFO, (void*)&conn_info);
945  if(res != SEC_E_OK)
946  WARN("QueryContextAttributesW failed: %08x\n", res);
947  return res == SEC_E_OK ? conn_info.dwCipherStrength : 0;
948 }
CtxtHandle ssl_ctx
#define WARN(fmt,...)
Definition: debug.h:111
LONG SECURITY_STATUS
Definition: sspi.h:34
#define SECPKG_ATTR_CONNECTION_INFO
Definition: schannel.h:76
#define SEC_E_OK
Definition: winerror.h:2356
SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
Definition: wrapper.c:535
GLuint res
Definition: glext.h:9613

Referenced by request_query_option().

◆ netconn_is_alive()

BOOL netconn_is_alive ( netconn_t netconn)

Definition at line 784 of file net.c.

785 {
786 #ifdef MSG_DONTWAIT
787  ssize_t len;
788  BYTE b;
789 
790  len = recv( netconn->socket, &b, 1, MSG_PEEK | MSG_DONTWAIT );
791  return len == 1 || (len == -1 && errno == EWOULDBLOCK);
792 #elif defined(__MINGW32__) || defined(_MSC_VER)
793  ULONG mode;
794  int len;
795  char b;
796 
797  mode = 1;
798  if(!ioctlsocket(netconn->socket, FIONBIO, &mode))
799  return FALSE;
800 
801  len = recv(netconn->socket, &b, 1, MSG_PEEK);
802 
803  mode = 0;
804  if(!ioctlsocket(netconn->socket, FIONBIO, &mode))
805  return FALSE;
806 
807  return len == 1 || (len == -1 && WSAGetLastError() == WSAEWOULDBLOCK);
808 #else
809  FIXME("not supported on this platform\n");
810  return TRUE;
811 #endif
812 }
#define TRUE
Definition: types.h:120
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
int errno
#define EWOULDBLOCK
Definition: errno.h:42
#define FIXME(fmt,...)
Definition: debug.h:110
#define ioctlsocket
Definition: main.c:40
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
int ssize_t
Definition: rosdhcp.h:48
GLenum mode
Definition: glext.h:6217
#define FIONBIO
Definition: winsock.h:149
unsigned int ULONG
Definition: retypes.h:1
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define MSG_PEEK
Definition: winsock.h:222

Referenced by open_connection().

◆ netconn_query_data_available()

ULONG netconn_query_data_available ( netconn_t conn)

Definition at line 763 of file net.c.

764 {
765  return conn->secure ? conn->peek_len : 0;
766 }
size_t peek_len

Referenced by query_data_available().

◆ netconn_recv()

BOOL netconn_recv ( netconn_t conn,
void buf,
size_t  len,
int  flags,
int recvd 
)

Definition at line 706 of file net.c.

707 {
708  *recvd = 0;
709  if (!len) return TRUE;
710 
711  if (conn->secure)
712  {
713  SIZE_T size, cread;
714  BOOL res, eof;
715 
716  if (conn->peek_msg)
717  {
718  *recvd = min( len, conn->peek_len );
719  memcpy( buf, conn->peek_msg, *recvd );
720  conn->peek_len -= *recvd;
721  conn->peek_msg += *recvd;
722 
723  if (conn->peek_len == 0)
724  {
725  heap_free( conn->peek_msg_mem );
726  conn->peek_msg_mem = NULL;
727  conn->peek_msg = NULL;
728  }
729  /* check if we have enough data from the peek buffer */
730  if (!(flags & MSG_WAITALL) || *recvd == len) return TRUE;
731  }
732  size = *recvd;
733 
734  do {
735  res = read_ssl_chunk(conn, (BYTE*)buf+size, len-size, &cread, &eof);
736  if(!res) {
737  WARN("read_ssl_chunk failed\n");
738  if(!size)
739  return FALSE;
740  break;
741  }
742 
743  if(eof) {
744  TRACE("EOF\n");
745  break;
746  }
747 
748  size += cread;
749  }while(!size || ((flags & MSG_WAITALL) && size < len));
750 
751  TRACE("received %ld bytes\n", size);
752  *recvd = size;
753  return TRUE;
754  }
755  if ((*recvd = sock_recv( conn->socket, buf, len, flags )) == -1)
756  {
758  return FALSE;
759  }
760  return TRUE;
761 }
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define WARN(fmt,...)
Definition: debug.h:111
static int sock_get_error(int err)
Definition: net.c:77
size_t peek_len
int errno
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
char * peek_msg
static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof)
Definition: net.c:615
GLbitfield flags
Definition: glext.h:7161
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define min(a, b)
Definition: monoChain.cc:55
GLuint res
Definition: glext.h:9613
void set_last_error(DWORD error)
Definition: session.c:59
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:163
char * peek_msg_mem
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by read_more_data().

◆ netconn_resolve()

BOOL netconn_resolve ( WCHAR hostname,
INTERNET_PORT  port,
struct sockaddr_storage sa,
int  timeout 
)

Definition at line 896 of file net.c.

897 {
898  DWORD ret;
899 
900  if (timeout)
901  {
902  DWORD status;
903  HANDLE thread;
904  struct resolve_args ra;
905 
906  ra.hostname = hostname;
907  ra.port = port;
908  ra.sa = sa;
909 
910  thread = CreateThread( NULL, 0, resolve_proc, &ra, 0, NULL );
911  if (!thread) return FALSE;
912 
915  else ret = ERROR_WINHTTP_TIMEOUT;
916  CloseHandle( thread );
917  }
918  else ret = resolve_hostname( hostname, port, sa );
919 
920  if (ret)
921  {
922  set_last_error( ret );
923  return FALSE;
924  }
925  return TRUE;
926 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static DWORD resolve_hostname(const WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr_storage *sa)
Definition: net.c:814
#define ERROR_WINHTTP_TIMEOUT
Definition: winhttp.h:189
Definition: dhcpd.h:245
char * hostname
Definition: ftp.c:88
BOOL WINAPI GetExitCodeThread(IN HANDLE hThread, OUT LPDWORD lpExitCode)
Definition: thread.c:540
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
smooth NULL
Definition: ftsmooth.c:416
#define WAIT_OBJECT_0
Definition: winbase.h:387
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE thread
Definition: service.c:33
int ret
const WCHAR * hostname
Definition: net.c:885
void set_last_error(DWORD error)
Definition: session.c:59
USHORT port
Definition: uri.c:227
static SERVICE_STATUS status
Definition: service.c:31
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
static DWORD CALLBACK resolve_proc(LPVOID arg)
Definition: net.c:890
Definition: ps.c:97

Referenced by open_connection().

◆ netconn_secure_connect()

BOOL netconn_secure_connect ( netconn_t conn,
WCHAR hostname,
DWORD  security_flags,
CredHandle cred_handle 
)

Definition at line 427 of file net.c.

428 {
429  SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}};
430  SecBufferDesc out_desc = {SECBUFFER_VERSION, 1, &out_buf}, in_desc = {SECBUFFER_VERSION, 2, in_bufs};
431  BYTE *read_buf;
432  SIZE_T read_buf_size = 2048;
433  ULONG attrs = 0;
434  CtxtHandle ctx;
435  SSIZE_T size;
436  const CERT_CONTEXT *cert;
439 
442 
443  read_buf = heap_alloc(read_buf_size);
444  if(!read_buf)
445  return FALSE;
446 
447  status = InitializeSecurityContextW(cred_handle, NULL, hostname, isc_req_flags, 0, 0, NULL, 0,
448  &ctx, &out_desc, &attrs, NULL);
449 
450  assert(status != SEC_E_OK);
451 
453  if(out_buf.cbBuffer) {
455 
456  TRACE("sending %u bytes\n", out_buf.cbBuffer);
457 
458  size = sock_send(conn->socket, out_buf.pvBuffer, out_buf.cbBuffer, 0);
459  if(size != out_buf.cbBuffer) {
460  ERR("send failed\n");
462  break;
463  }
464 
465  FreeContextBuffer(out_buf.pvBuffer);
466  out_buf.pvBuffer = NULL;
467  out_buf.cbBuffer = 0;
468  }
469 
471  assert(in_bufs[1].cbBuffer < read_buf_size);
472 
473  memmove(read_buf, (BYTE*)in_bufs[0].pvBuffer+in_bufs[0].cbBuffer-in_bufs[1].cbBuffer, in_bufs[1].cbBuffer);
474  in_bufs[0].cbBuffer = in_bufs[1].cbBuffer;
475 
476  in_bufs[1].BufferType = SECBUFFER_EMPTY;
477  in_bufs[1].cbBuffer = 0;
478  in_bufs[1].pvBuffer = NULL;
479  }
480 
481  assert(in_bufs[0].BufferType == SECBUFFER_TOKEN);
482  assert(in_bufs[1].BufferType == SECBUFFER_EMPTY);
483 
484  if(in_bufs[0].cbBuffer + 1024 > read_buf_size) {
485  BYTE *new_read_buf;
486 
487  new_read_buf = heap_realloc(read_buf, read_buf_size + 1024);
488  if(!new_read_buf) {
490  break;
491  }
492 
493  in_bufs[0].pvBuffer = read_buf = new_read_buf;
494  read_buf_size += 1024;
495  }
496 
497  size = sock_recv(conn->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0);
498  if(size < 1) {
500  break;
501  }
502 
503  TRACE("recv %lu bytes\n", size);
504 
505  in_bufs[0].cbBuffer += size;
506  in_bufs[0].pvBuffer = read_buf;
507  status = InitializeSecurityContextW(cred_handle, &ctx, hostname, isc_req_flags, 0, 0, &in_desc,
508  0, NULL, &out_desc, &attrs, NULL);
509  TRACE("InitializeSecurityContext ret %08x\n", status);
510 
511  if(status == SEC_E_OK) {
512  if(in_bufs[1].BufferType == SECBUFFER_EXTRA)
513  FIXME("SECBUFFER_EXTRA not supported\n");
514 
516  if(status != SEC_E_OK) {
517  WARN("Could not get sizes\n");
518  break;
519  }
520 
522  if(status == SEC_E_OK) {
523  res = netconn_verify_cert(cert, hostname, security_flags);
525  if(res != ERROR_SUCCESS) {
526  WARN("cert verify failed: %u\n", res);
527  break;
528  }
529  }else {
530  WARN("Could not get cert\n");
531  break;
532  }
533 
535  if(!conn->ssl_buf) {
536  res = GetLastError();
537  break;
538  }
539  }
540  }
541 
543 
544  if(status != SEC_E_OK || res != ERROR_SUCCESS) {
545  WARN("Failed to initialize security context failed: %08x\n", status);
546  heap_free(conn->ssl_buf);
547  conn->ssl_buf = NULL;
548  DeleteSecurityContext(&ctx);
550  return FALSE;
551  }
552 
553 
554  TRACE("established SSL connection\n");
555  conn->secure = TRUE;
556  conn->ssl_ctx = ctx;
557  return TRUE;
558 }
#define ISC_REQ_SEQUENCE_DETECT
Definition: sspi.h:351
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
CtxtHandle ssl_ctx
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
SECURITY_STATUS WINAPI FreeContextBuffer(PVOID pv)
Definition: sspi.c:699
#define ERROR_WINHTTP_SECURE_CHANNEL_ERROR
Definition: winhttp.h:219
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:371
#define WARN(fmt,...)
Definition: debug.h:111
#define SECPKG_ATTR_REMOTE_CERT_CONTEXT
Definition: schannel.h:69
static SecHandle cred_handle
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LONG_PTR SSIZE_T
Definition: basetsd.h:183
char * ssl_buf
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define SECBUFFER_EXTRA
Definition: sspi.h:150
unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size)
Definition: deflate.c:1167
char * hostname
Definition: ftp.c:88
#define ISC_REQ_MANUAL_CRED_VALIDATION
Definition: sspi.h:367
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define SECBUFFER_EMPTY
Definition: sspi.h:145
#define SEC_I_CONTINUE_NEEDED
Definition: winerror.h:2927
static BYTE cert[]
Definition: msg.c:1437
LONG SECURITY_STATUS
Definition: sspi.h:34
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
SECURITY_STATUS WINAPI InitializeSecurityContextW(PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry)
Definition: wrapper.c:301
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ISC_REQ_USE_SESSION_KEY
Definition: sspi.h:353
#define SECPKG_ATTR_STREAM_SIZES
Definition: sspi.h:511
#define ISC_REQ_ALLOCATE_MEMORY
Definition: sspi.h:356
#define SECBUFFER_TOKEN
Definition: sspi.h:147
unsigned char BYTE
Definition: mem.h:68
#define SEC_E_OK
Definition: winerror.h:2356
SECURITY_STATUS WINAPI QueryContextAttributesW(PCtxtHandle phContext, ULONG ulAttribute, void *pBuffer)
Definition: wrapper.c:535
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
static int sock_send(int fd, const void *msg, size_t len, int flags)
Definition: net.c:152
#define SECBUFFER_VERSION
Definition: sspi.h:173
ULONG cbBuffer
Definition: sspi.h:139
static DWORD netconn_verify_cert(PCCERT_CONTEXT cert, WCHAR *server, DWORD security_flags)
Definition: net.c:174
GLuint res
Definition: glext.h:9613
unsigned int ULONG
Definition: retypes.h:1
#define ISC_REQ_CONFIDENTIALITY
Definition: sspi.h:352
#define ISC_REQ_REPLAY_DETECT
Definition: sspi.h:350
void set_last_error(DWORD error)
Definition: session.c:59
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:163
static SERVICE_STATUS status
Definition: service.c:31
SecPkgContext_StreamSizes ssl_sizes
#define SEC_E_INCOMPLETE_MESSAGE
Definition: winerror.h:2934
SECURITY_STATUS WINAPI DeleteSecurityContext(PCtxtHandle phContext)
Definition: wrapper.c:450
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
Definition: ps.c:97

Referenced by open_connection().

◆ netconn_send()

BOOL netconn_send ( netconn_t conn,
const void msg,
size_t  len,
int sent 
)

Definition at line 586 of file net.c.

587 {
588  if (conn->secure)
589  {
590  const BYTE *ptr = msg;
591  size_t chunk_size;
592 
593  *sent = 0;
594 
595  while(len) {
596  chunk_size = min(len, conn->ssl_sizes.cbMaximumMessage);
597  if(!send_ssl_chunk(conn, ptr, chunk_size))
598  return FALSE;
599 
600  *sent += chunk_size;
601  ptr += chunk_size;
602  len -= chunk_size;
603  }
604 
605  return TRUE;
606  }
607  if ((*sent = sock_send( conn->socket, msg, len, 0 )) == -1)
608  {
610  return FALSE;
611  }
612  return TRUE;
613 }
#define TRUE
Definition: types.h:120
static int sock_get_error(int err)
Definition: net.c:77
static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size)
Definition: net.c:560
int errno
static PVOID ptr
Definition: dispmode.c:27
Definition: msg.h:34
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
static int sock_send(int fd, const void *msg, size_t len, int flags)
Definition: net.c:152
#define min(a, b)
Definition: monoChain.cc:55
#define msg(x)
Definition: auth_time.c:54
void set_last_error(DWORD error)
Definition: session.c:59
SecPkgContext_StreamSizes ssl_sizes

Referenced by secure_proxy_connect(), send_request(), and write_data().

◆ netconn_set_timeout()

DWORD netconn_set_timeout ( netconn_t netconn,
BOOL  send,
int  value 
)

Definition at line 768 of file net.c.

769 {
770  struct timeval tv;
771 
772  /* value is in milliseconds, convert to struct timeval */
773  tv.tv_sec = value / 1000;
774  tv.tv_usec = (value % 1000) * 1000;
775 
776  if (setsockopt( netconn->socket, SOL_SOCKET, send ? SO_SNDTIMEO : SO_RCVTIMEO, (void*)&tv, sizeof(tv) ) == -1)
777  {
778  WARN("setsockopt failed (%s)\n", strerror( errno ));
779  return sock_get_error( errno );
780  }
781  return ERROR_SUCCESS;
782 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WARN(fmt,...)
Definition: debug.h:111
unsigned long tv_sec
Definition: linux.h:1738
static int sock_get_error(int err)
Definition: net.c:77
int errno
#define SOL_SOCKET
Definition: winsock.h:398
const char * strerror(int err)
Definition: compat_str.c:23
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
#define SO_RCVTIMEO
Definition: winsock.h:193
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
#define SO_SNDTIMEO
Definition: winsock.h:192

Referenced by open_connection(), and WinHttpSetTimeouts().

◆ netconn_unload()

void netconn_unload ( void  )

Definition at line 289 of file net.c.

290 {
291 #ifndef HAVE_GETADDRINFO
293 #endif
294 #ifdef __REACTOS__
295  if(winsock_initialized)
296  WSACleanup();
297 #endif
298 }
static CRITICAL_SECTION cs_gethostbyname
Definition: net.c:64
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by DllMain().

◆ netconn_verify_cert()

static DWORD netconn_verify_cert ( PCCERT_CONTEXT  cert,
WCHAR server,
DWORD  security_flags 
)
static

Definition at line 174 of file net.c.

175 {
176  HCERTSTORE store = cert->hCertStore;
177  BOOL ret;
178  CERT_CHAIN_PARA chainPara = { sizeof(chainPara), { 0 } };
180  char oid_server_auth[] = szOID_PKIX_KP_SERVER_AUTH;
181  char *server_auth[] = { oid_server_auth };
183 
184  TRACE("verifying %s\n", debugstr_w( server ));
185  chainPara.RequestedUsage.Usage.cUsageIdentifier = 1;
186  chainPara.RequestedUsage.Usage.rgpszUsageIdentifier = server_auth;
187  if ((ret = CertGetCertificateChain( NULL, cert, NULL, store, &chainPara,
189  NULL, &chain )))
190  {
191  if (chain->TrustStatus.dwErrorStatus)
192  {
193  static const DWORD supportedErrors =
197 
198  if (chain->TrustStatus.dwErrorStatus & CERT_TRUST_IS_NOT_TIME_VALID)
199  {
200  if (!(security_flags & SECURITY_FLAG_IGNORE_CERT_DATE_INVALID))
202  }
203  else if (chain->TrustStatus.dwErrorStatus &
205  {
206  if (!(security_flags & SECURITY_FLAG_IGNORE_UNKNOWN_CA))
208  }
209  else if ((chain->TrustStatus.dwErrorStatus &
211  (chain->TrustStatus.dwErrorStatus &
214  else if (chain->TrustStatus.dwErrorStatus & CERT_TRUST_IS_REVOKED)
216  else if (chain->TrustStatus.dwErrorStatus &
218  {
219  if (!(security_flags & SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE))
221  }
222  else if (chain->TrustStatus.dwErrorStatus & ~supportedErrors)
224  }
225  if (!err)
226  {
227  CERT_CHAIN_POLICY_PARA policyPara;
228  SSL_EXTRA_CERT_CHAIN_POLICY_PARA sslExtraPolicyPara;
229  CERT_CHAIN_POLICY_STATUS policyStatus;
230  CERT_CHAIN_CONTEXT chainCopy;
231 
232  /* Clear chain->TrustStatus.dwErrorStatus so
233  * CertVerifyCertificateChainPolicy will verify additional checks
234  * rather than stopping with an existing, ignored error.
235  */
236  memcpy(&chainCopy, chain, sizeof(chainCopy));
237  chainCopy.TrustStatus.dwErrorStatus = 0;
238  sslExtraPolicyPara.u.cbSize = sizeof(sslExtraPolicyPara);
239  sslExtraPolicyPara.dwAuthType = AUTHTYPE_SERVER;
240  sslExtraPolicyPara.pwszServerName = server;
241  sslExtraPolicyPara.fdwChecks = security_flags;
242  policyPara.cbSize = sizeof(policyPara);
243  policyPara.dwFlags = 0;
244  policyPara.pvExtraPolicyPara = &sslExtraPolicyPara;
246  &chainCopy, &policyPara,
247  &policyStatus );
248  /* Any error in the policy status indicates that the
249  * policy couldn't be verified.
250  */
251  if (ret && policyStatus.dwError)
252  {
253  if (policyStatus.dwError == CERT_E_CN_NO_MATCH)
255  else
257  }
258  }
260  }
261  else
263  TRACE("returning %08x\n", err);
264  return err;
265 }
BOOL WINAPI CertGetCertificateChain(HCERTCHAINENGINE hChainEngine, PCCERT_CONTEXT pCertContext, LPFILETIME pTime, HCERTSTORE hAdditionalStore, PCERT_CHAIN_PARA pChainPara, DWORD dwFlags, LPVOID pvReserved, PCCERT_CHAIN_CONTEXT *ppChainContext)
Definition: chain.c:2879
CERT_ENHKEY_USAGE Usage
Definition: wincrypt.h:1048
#define SECURITY_FLAG_IGNORE_UNKNOWN_CA
Definition: winhttp.h:281
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define CERT_TRUST_IS_NOT_TIME_VALID
Definition: wincrypt.h:870
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT
Definition: wincrypt.h:1058
#define ERROR_WINHTTP_SECURE_CHANNEL_ERROR
Definition: winhttp.h:219
CERT_USAGE_MATCH RequestedUsage
Definition: wincrypt.h:1070
#define szOID_PKIX_KP_SERVER_AUTH
Definition: wincrypt.h:3294
VOID WINAPI CertFreeCertificateChain(PCCERT_CHAIN_CONTEXT pChainContext)
Definition: chain.c:2960
#define CERT_E_CN_NO_MATCH
Definition: winerror.h:3131
BOOL WINAPI CertVerifyCertificateChainPolicy(LPCSTR szPolicyOID, PCCERT_CHAIN_CONTEXT pChainContext, PCERT_CHAIN_POLICY_PARA pPolicyPara, PCERT_CHAIN_POLICY_STATUS pPolicyStatus)
Definition: chain.c:3716
#define ERROR_WINHTTP_SECURE_INVALID_CERT
Definition: winhttp.h:222
#define CERT_TRUST_IS_REVOKED
Definition: wincrypt.h:872
#define CERT_CHAIN_POLICY_SSL
Definition: wincrypt.h:965
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_WINHTTP_SECURE_CERT_CN_INVALID
Definition: winhttp.h:205
#define CERT_TRUST_REVOCATION_STATUS_UNKNOWN
Definition: wincrypt.h:876
struct sock * chain
Definition: tcpcore.h:1164
static BYTE cert[]
Definition: msg.c:1437
CERT_TRUST_STATUS TrustStatus
Definition: wincrypt.h:939
#define ERROR_WINHTTP_SECURE_CERT_REVOKED
Definition: winhttp.h:223
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE
Definition: winhttp.h:284
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define err(...)
#define SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
Definition: winhttp.h:282
#define CERT_TRUST_IS_NOT_VALID_FOR_USAGE
Definition: wincrypt.h:874
DWORD cUsageIdentifier
Definition: wincrypt.h:719
#define ERROR_WINHTTP_SECURE_CERT_WRONG_USAGE
Definition: winhttp.h:227
#define CERT_TRUST_IS_UNTRUSTED_ROOT
Definition: wincrypt.h:875
LPSTR * rgpszUsageIdentifier
Definition: wincrypt.h:720
#define ERROR_WINHTTP_SECURE_INVALID_CA
Definition: winhttp.h:207
#define ERROR_WINHTTP_SECURE_CERT_REV_FAILED
Definition: winhttp.h:208
#define CERT_TRUST_IS_OFFLINE_REVOCATION
Definition: wincrypt.h:886
#define AUTHTYPE_SERVER
Definition: wincrypt.h:1035
#define ERROR_WINHTTP_SECURE_CERT_DATE_INVALID
Definition: winhttp.h:204

Referenced by netconn_secure_connect().

◆ read_ssl_chunk()

static BOOL read_ssl_chunk ( netconn_t conn,
void buf,
SIZE_T  buf_size,
SIZE_T ret_size,
BOOL eof 
)
static

Definition at line 615 of file net.c.

616 {
617  const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer;
618  SecBuffer bufs[4];
619  SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
620  SSIZE_T size, buf_len;
621  unsigned int i;
623 
624  assert(conn->extra_len < ssl_buf_size);
625 
626  if(conn->extra_len) {
627  memcpy(conn->ssl_buf, conn->extra_buf, conn->extra_len);
628  buf_len = conn->extra_len;
629  conn->extra_len = 0;
630  heap_free(conn->extra_buf);
631  conn->extra_buf = NULL;
632  }else {
633  buf_len = sock_recv(conn->socket, conn->ssl_buf+conn->extra_len, ssl_buf_size-conn->extra_len, 0);
634  if(buf_len < 0)
635  return FALSE;
636 
637  if(!buf_len) {
638  *eof = TRUE;
639  return TRUE;
640  }
641  }
642 
643  *ret_size = 0;
644  *eof = FALSE;
645 
646  do {
647  memset(bufs, 0, sizeof(bufs));
648  bufs[0].BufferType = SECBUFFER_DATA;
649  bufs[0].cbBuffer = buf_len;
650  bufs[0].pvBuffer = conn->ssl_buf;
651 
652  res = DecryptMessage(&conn->ssl_ctx, &buf_desc, 0, NULL);
653  switch(res) {
654  case SEC_E_OK:
655  break;
657  TRACE("context expired\n");
658  *eof = TRUE;
659  return TRUE;
661  assert(buf_len < ssl_buf_size);
662 
663  size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, 0);
664  if(size < 1)
665  return FALSE;
666 
667  buf_len += size;
668  continue;
669  default:
670  WARN("failed: %08x\n", res);
671  return FALSE;
672  }
673  } while(res != SEC_E_OK);
674 
675  for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) {
676  if(bufs[i].BufferType == SECBUFFER_DATA) {
677  size = min(buf_size, bufs[i].cbBuffer);
678  memcpy(buf, bufs[i].pvBuffer, size);
679  if(size < bufs[i].cbBuffer) {
680  assert(!conn->peek_len);
681  conn->peek_msg_mem = conn->peek_msg = heap_alloc(bufs[i].cbBuffer - size);
682  if(!conn->peek_msg)
683  return FALSE;
684  conn->peek_len = bufs[i].cbBuffer-size;
685  memcpy(conn->peek_msg, (char*)bufs[i].pvBuffer+size, conn->peek_len);
686  }
687 
688  *ret_size = size;
689  }
690  }
691 
692  for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) {
693  if(bufs[i].BufferType == SECBUFFER_EXTRA) {
694  conn->extra_buf = heap_alloc(bufs[i].cbBuffer);
695  if(!conn->extra_buf)
696  return FALSE;
697 
698  conn->extra_len = bufs[i].cbBuffer;
699  memcpy(conn->extra_buf, bufs[i].pvBuffer, conn->extra_len);
700  }
701  }
702 
703  return TRUE;
704 }
size_t extra_len
CtxtHandle ssl_ctx
#define TRUE
Definition: types.h:120
const GLenum * bufs
Definition: glext.h:6026
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define SEC_I_CONTEXT_EXPIRED
Definition: winerror.h:2933
#define WARN(fmt,...)
Definition: debug.h:111
#define SECBUFFER_DATA
Definition: sspi.h:146
#define assert(x)
Definition: debug.h:53
LONG_PTR SSIZE_T
Definition: basetsd.h:183
char * ssl_buf
size_t peek_len
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define SECBUFFER_EXTRA
Definition: sspi.h:150
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
char * extra_buf
smooth NULL
Definition: ftsmooth.c:416
LONG SECURITY_STATUS
Definition: sspi.h:34
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
char * peek_msg
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SEC_E_OK
Definition: winerror.h:2356
_Check_return_ _CRTIMP int __cdecl __cdecl eof(_In_ int _FileHandle)
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define SECBUFFER_VERSION
Definition: sspi.h:173
#define min(a, b)
Definition: monoChain.cc:55
SECURITY_STATUS WINAPI DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP)
Definition: wrapper.c:1036
GLuint res
Definition: glext.h:9613
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:163
#define memset(x, y, z)
Definition: compat.h:39
SecPkgContext_StreamSizes ssl_sizes
#define SEC_E_INCOMPLETE_MESSAGE
Definition: winerror.h:2934
char * peek_msg_mem
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by netconn_recv(), and tcp_recv().

◆ resolve_hostname()

static DWORD resolve_hostname ( const WCHAR hostnameW,
INTERNET_PORT  port,
struct sockaddr_storage sa 
)
static

Definition at line 814 of file net.c.

815 {
816  char *hostname;
817 #ifdef HAVE_GETADDRINFO
818  struct addrinfo *res, hints;
819  int ret;
820 #else
821  struct hostent *he;
822  struct sockaddr_in *sin = (struct sockaddr_in *)sa;
823 #endif
824 
825  if (!(hostname = strdupWA( hostnameW ))) return ERROR_OUTOFMEMORY;
826 
827 #ifdef HAVE_GETADDRINFO
828  memset( &hints, 0, sizeof(struct addrinfo) );
829  /* Prefer IPv4 to IPv6 addresses, since some web servers do not listen on
830  * their IPv6 addresses even though they have IPv6 addresses in the DNS.
831  */
832  hints.ai_family = AF_INET;
833 
834  ret = getaddrinfo( hostname, NULL, &hints, &res );
835  if (ret != 0)
836  {
837  TRACE("failed to get IPv4 address of %s (%s), retrying with IPv6\n", debugstr_w(hostnameW), gai_strerror(ret));
838  hints.ai_family = AF_INET6;
839  ret = getaddrinfo( hostname, NULL, &hints, &res );
840  if (ret != 0)
841  {
842  TRACE("failed to get address of %s (%s)\n", debugstr_w(hostnameW), gai_strerror(ret));
843  heap_free( hostname );
845  }
846  }
847  heap_free( hostname );
848  memcpy( sa, res->ai_addr, res->ai_addrlen );
849  /* Copy port */
850  switch (res->ai_family)
851  {
852  case AF_INET:
853  ((struct sockaddr_in *)sa)->sin_port = htons( port );
854  break;
855  case AF_INET6:
856  ((struct sockaddr_in6 *)sa)->sin6_port = htons( port );
857  break;
858  }
859 
860  freeaddrinfo( res );
861  return ERROR_SUCCESS;
862 #else
864 
865  he = gethostbyname( hostname );
866  heap_free( hostname );
867  if (!he)
868  {
869  TRACE("failed to get address of %s (%d)\n", debugstr_w(hostnameW), h_errno);
872  }
873  memset( sa, 0, sizeof(struct sockaddr_in) );
874  memcpy( &sin->sin_addr, he->h_addr, he->h_length );
875  sin->sin_family = he->h_addrtype;
876  sin->sin_port = htons( port );
877 
879  return ERROR_SUCCESS;
880 #endif
881 }
static CRITICAL_SECTION cs_gethostbyname
Definition: net.c:64
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
#define freeaddrinfo
Definition: wspiapi.h:46
#define ERROR_SUCCESS
Definition: deptool.c:10
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
char * hostname
Definition: ftp.c:88
#define debugstr_w
Definition: kernel32.h:32
short h_length
Definition: winsock.h:137
smooth NULL
Definition: ftsmooth.c:416
#define AF_INET6
Definition: winsock.h:369
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
Definition: getxbyxx.c:221
#define TRACE(s)
Definition: solgame.cpp:4
#define gai_strerror
Definition: ws2tcpip.h:521
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
short h_addrtype
Definition: winsock.h:136
static char * strdupWA(const WCHAR *src)
Definition: main.c:111
GLuint res
Definition: glext.h:9613
#define AF_INET
Definition: tcpip.h:117
#define h_errno
Definition: winsock.h:225
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define htons(x)
Definition: module.h:213
USHORT port
Definition: uri.c:227
#define memset(x, y, z)
Definition: compat.h:39
#define ERROR_WINHTTP_NAME_NOT_RESOLVED
Definition: winhttp.h:193
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
#define getaddrinfo
Definition: wspiapi.h:44

Referenced by netconn_resolve(), and resolve_proc().

◆ resolve_proc()

static DWORD CALLBACK resolve_proc ( LPVOID  arg)
static

Definition at line 890 of file net.c.

891 {
892  struct resolve_args *ra = arg;
893  return resolve_hostname( ra->hostname, ra->port, ra->sa );
894 }
static DWORD resolve_hostname(const WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr_storage *sa)
Definition: net.c:814
INTERNET_PORT port
Definition: net.c:886
struct sockaddr_storage * sa
Definition: net.c:887
void * arg
Definition: msvc.h:12
const WCHAR * hostname
Definition: net.c:885

Referenced by netconn_resolve().

◆ send_ssl_chunk()

static BOOL send_ssl_chunk ( netconn_t conn,
const void msg,
size_t  size 
)
static

Definition at line 560 of file net.c.

561 {
562  SecBuffer bufs[4] = {
564  {size, SECBUFFER_DATA, conn->ssl_buf+conn->ssl_sizes.cbHeader},
566  {0, SECBUFFER_EMPTY, NULL}
567  };
568  SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs};
570 
571  memcpy(bufs[1].pvBuffer, msg, size);
572  res = EncryptMessage(&conn->ssl_ctx, 0, &buf_desc, 0);
573  if(res != SEC_E_OK) {
574  WARN("EncryptMessage failed\n");
575  return FALSE;
576  }
577 
578  if(sock_send(conn->socket, conn->ssl_buf, bufs[0].cbBuffer+bufs[1].cbBuffer+bufs[2].cbBuffer, 0) < 1) {
579  WARN("send failed\n");
580  return FALSE;
581  }
582 
583  return TRUE;
584 }
CtxtHandle ssl_ctx
#define TRUE
Definition: types.h:120
#define SECBUFFER_STREAM_HEADER
Definition: sspi.h:152
const GLenum * bufs
Definition: glext.h:6026
#define WARN(fmt,...)
Definition: debug.h:111
#define SECBUFFER_DATA
Definition: sspi.h:146
char * ssl_buf
smooth NULL
Definition: ftsmooth.c:416
#define SECBUFFER_EMPTY
Definition: sspi.h:145
LONG SECURITY_STATUS
Definition: sspi.h:34
GLsizeiptr size
Definition: glext.h:5919
#define SECBUFFER_STREAM_TRAILER
Definition: sspi.h:151
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SEC_E_OK
Definition: winerror.h:2356
static int sock_send(int fd, const void *msg, size_t len, int flags)
Definition: net.c:152
#define SECBUFFER_VERSION
Definition: sspi.h:173
#define msg(x)
Definition: auth_time.c:54
GLuint res
Definition: glext.h:9613
SecPkgContext_StreamSizes ssl_sizes
SECURITY_STATUS WINAPI EncryptMessage(PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo)
Definition: wrapper.c:1006

Referenced by netconn_send(), and tcp_send().

◆ sock_get_error()

static int sock_get_error ( int  err)
static

Definition at line 77 of file net.c.

78 {
79 #if !defined(__MINGW32__) && !defined (_MSC_VER)
80  switch (err)
81  {
82  case EINTR: return WSAEINTR;
83  case EBADF: return WSAEBADF;
84  case EPERM:
85  case EACCES: return WSAEACCES;
86  case EFAULT: return WSAEFAULT;
87  case EINVAL: return WSAEINVAL;
88  case EMFILE: return WSAEMFILE;
89  case EWOULDBLOCK: return WSAEWOULDBLOCK;
90  case EINPROGRESS: return WSAEINPROGRESS;
91  case EALREADY: return WSAEALREADY;
92  case ENOTSOCK: return WSAENOTSOCK;
93  case EDESTADDRREQ: return WSAEDESTADDRREQ;
94  case EMSGSIZE: return WSAEMSGSIZE;
95  case EPROTOTYPE: return WSAEPROTOTYPE;
96  case ENOPROTOOPT: return WSAENOPROTOOPT;
99  case EOPNOTSUPP: return WSAEOPNOTSUPP;
100  case EPFNOSUPPORT: return WSAEPFNOSUPPORT;
101  case EAFNOSUPPORT: return WSAEAFNOSUPPORT;
102  case EADDRINUSE: return WSAEADDRINUSE;
103  case EADDRNOTAVAIL: return WSAEADDRNOTAVAIL;
104  case ENETDOWN: return WSAENETDOWN;
105  case ENETUNREACH: return WSAENETUNREACH;
106  case ENETRESET: return WSAENETRESET;
107  case ECONNABORTED: return WSAECONNABORTED;
108  case EPIPE:
109  case ECONNRESET: return WSAECONNRESET;
110  case ENOBUFS: return WSAENOBUFS;
111  case EISCONN: return WSAEISCONN;
112  case ENOTCONN: return WSAENOTCONN;
113  case ESHUTDOWN: return WSAESHUTDOWN;
114  case ETOOMANYREFS: return WSAETOOMANYREFS;
115  case ETIMEDOUT: return WSAETIMEDOUT;
116  case ECONNREFUSED: return WSAECONNREFUSED;
117  case ELOOP: return WSAELOOP;
118  case ENAMETOOLONG: return WSAENAMETOOLONG;
119  case EHOSTDOWN: return WSAEHOSTDOWN;
120  case EHOSTUNREACH: return WSAEHOSTUNREACH;
121  case ENOTEMPTY: return WSAENOTEMPTY;
122 #ifdef EPROCLIM
123  case EPROCLIM: return WSAEPROCLIM;
124 #endif
125 #ifdef EUSERS
126  case EUSERS: return WSAEUSERS;
127 #endif
128 #ifdef EDQUOT
129  case EDQUOT: return WSAEDQUOT;
130 #endif
131 #ifdef ESTALE
132  case ESTALE: return WSAESTALE;
133 #endif
134 #ifdef EREMOTE
135  case EREMOTE: return WSAEREMOTE;
136 #endif
137  default: errno = err; perror( "sock_set_error" ); return WSAEFAULT;
138  }
139 #endif
140  return err;
141 }
#define EPIPE
Definition: acclib.h:91
#define WSAENOTSOCK
Definition: winerror.h:1951
#define WSAESTALE
Definition: winerror.h:1983
#define WSAETOOMANYREFS
Definition: winerror.h:1972
#define WSAEDQUOT
Definition: winerror.h:1982
#define EHOSTDOWN
Definition: errno.h:123
#define EREMOTE
Definition: errno.h:71
#define WSAEFAULT
Definition: winerror.h:1945
#define ECONNABORTED
Definition: errno.h:114
Definition: arc.h:38
#define WSAEINVAL
Definition: winerror.h:1946
Definition: arc.h:39
#define WSAEAFNOSUPPORT
Definition: winerror.h:1960
#define EINTR
Definition: acclib.h:80
#define EOPNOTSUPP
Definition: errno.h:104
#define ENOBUFS
Definition: errno.h:116
#define WSAEPFNOSUPPORT
Definition: winerror.h:1959
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define ELOOP
Definition: errno.h:41
#define ENOTSOCK
Definition: errno.h:94
#define WSAEUSERS
Definition: winerror.h:1981
#define EINPROGRESS
Definition: errno.h:126
int errno
#define WSAEACCES
Definition: winerror.h:1944
Definition: arc.h:36
#define WSAENOPROTOOPT
Definition: winerror.h:1955
#define WSAEINPROGRESS
Definition: winerror.h:1949
#define ECONNREFUSED
Definition: errno.h:122
#define ETOOMANYREFS
Definition: errno.h:120
#define WSAEOPNOTSUPP
Definition: winerror.h:1958
#define WSAENOTEMPTY
Definition: winerror.h:1979
#define WSAEPROTONOSUPPORT
Definition: winerror.h:1956
#define ENETUNREACH
Definition: errno.h:112
#define WSAEISCONN
Definition: winerror.h:1969
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define ECONNRESET
Definition: errno.h:115
#define ENOTEMPTY
Definition: errno.h:47
#define EWOULDBLOCK
Definition: errno.h:42
#define ENOPROTOOPT
Definition: errno.h:100
#define WSAETIMEDOUT
Definition: winerror.h:1973
#define ESOCKTNOSUPPORT
Definition: errno.h:102
#define EPROTONOSUPPORT
Definition: errno.h:101
#define WSAEALREADY
Definition: winerror.h:1950
#define ESTALE
Definition: errno.h:127
#define EDESTADDRREQ
Definition: errno.h:95
#define ENOTCONN
Definition: errno.h:118
#define WSAEHOSTDOWN
Definition: winerror.h:1977
#define WSAEHOSTUNREACH
Definition: winerror.h:1978
#define WSAENETDOWN
Definition: winerror.h:1963
#define WSAESOCKTNOSUPPORT
Definition: winerror.h:1957
#define EPROTOTYPE
Definition: errno.h:99
#define WSAEMSGSIZE
Definition: winerror.h:1953
#define EADDRNOTAVAIL
Definition: errno.h:110
#define EPFNOSUPPORT
Definition: errno.h:106
Definition: arc.h:34
#define WSAEREMOTE
Definition: winerror.h:1984
#define WSAENETUNREACH
Definition: winerror.h:1964
#define WSAENOTCONN
Definition: winerror.h:1970
#define err(...)
#define WSAELOOP
Definition: winerror.h:1975
#define EADDRINUSE
Definition: errno.h:109
#define WSAEADDRNOTAVAIL
Definition: winerror.h:1962
#define WSAECONNABORTED
Definition: winerror.h:1966
#define ESHUTDOWN
Definition: errno.h:119
#define WSAESHUTDOWN
Definition: winerror.h:1971
#define WSAEPROTOTYPE
Definition: winerror.h:1954
#define WSAEDESTADDRREQ
Definition: winerror.h:1952
#define EALREADY
Definition: errno.h:125
Definition: arc.h:42
#define WSAEBADF
Definition: winerror.h:1943
#define WSAECONNRESET
Definition: winerror.h:1967
#define EDQUOT
Definition: errno.h:133
#define WSAEMFILE
Definition: winerror.h:1947
#define ENETDOWN
Definition: errno.h:111
#define ENETRESET
Definition: errno.h:113
#define EISCONN
Definition: errno.h:117
#define EHOSTUNREACH
Definition: errno.h:124
#define EUSERS
Definition: errno.h:93
#define EAFNOSUPPORT
Definition: errno.h:107
#define WSAECONNREFUSED
Definition: winerror.h:1974
#define EMSGSIZE
Definition: errno.h:97
#define ETIMEDOUT
Definition: errno.h:121
#define WSAEADDRINUSE
Definition: winerror.h:1961
#define EPERM
Definition: acclib.h:78
#define WSAENOBUFS
Definition: winerror.h:1968
#define WSAEINTR
Definition: winerror.h:1942
#define WSAENETRESET
Definition: winerror.h:1965
#define WSAENAMETOOLONG
Definition: winerror.h:1976
#define WSAEPROCLIM
Definition: winerror.h:1980

Referenced by netconn_close(), netconn_create(), netconn_recv(), netconn_send(), and netconn_set_timeout().

◆ sock_recv()

static int sock_recv ( int  fd,
void msg,
size_t  len,
int  flags 
)
static

Definition at line 163 of file net.c.

164 {
165  int ret;
166  do
167  {
168  if ((ret = recv(fd, msg, len, flags)) == -1) WARN("recv error %s\n", strerror(errno));
169  }
170  while(ret == -1 && errno == EINTR);
171  return ret;
172 }
#define WARN(fmt,...)
Definition: debug.h:111
#define EINTR
Definition: acclib.h:80
static int fd
Definition: io.c:51
int errno
const char * strerror(int err)
Definition: compat_str.c:23
GLbitfield flags
Definition: glext.h:7161
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define msg(x)
Definition: auth_time.c:54
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23

Referenced by FTP_GetNextLine(), FTP_ReceiveRequestData(), FTP_RetrieveFileData(), FTPFILE_QueryDataAvailable(), FTPFILE_ReadFile(), netconn_recv(), netconn_secure_connect(), and read_ssl_chunk().

◆ sock_send()

static int sock_send ( int  fd,
const void msg,
size_t  len,
int  flags 
)
static

Definition at line 152 of file net.c.

153 {
154  int ret;
155  do
156  {
157  if ((ret = send(fd, msg, len, flags)) == -1) WARN("send error %s\n", strerror(errno));
158  }
159  while(ret == -1 && errno == EINTR);
160  return ret;
161 }
#define WARN(fmt,...)
Definition: debug.h:111
#define EINTR
Definition: acclib.h:80
static int fd
Definition: io.c:51
int errno
const char * strerror(int err)
Definition: compat_str.c:23
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
GLbitfield flags
Definition: glext.h:7161
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define msg(x)
Definition: auth_time.c:54

Referenced by FTP_SendCommandA(), FTP_SendData(), FtpCommandW(), FTPFILE_WriteFile(), netconn_secure_connect(), netconn_send(), and send_ssl_chunk().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( winhttp  )

Variable Documentation

◆ critsect_debug

CRITICAL_SECTION_DEBUG critsect_debug
static
Initial value:
=
{
0, 0, { (DWORD_PTR)(__FILE__ ": cs_gethostbyname") }
}
static CRITICAL_SECTION cs_gethostbyname
Definition: net.c:64
#define DWORD_PTR
Definition: treelist.c:76
static CRITICAL_SECTION_DEBUG critsect_debug
Definition: net.c:65
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855

Definition at line 65 of file net.c.

◆ cs_gethostbyname

static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 }
static

Definition at line 64 of file net.c.

Referenced by netconn_unload(), and resolve_hostname().