Exemplo n.º 1
0
//---------------------------------------------------------------------------
//  FUNCTION: CheckAvailableNameSpaceProviders(BOOL& fNsSap, BOOL& fNsNtds)
//
//  PURPOSE:  Check the avaliable name space providers, set fNsSap to TRUE if
//            SAP is available, and fNsNtds to TRUE if NT Directory Service 
//            is avaialble.
//
//  RETURNS:
//    TRUE if succeed otherwise FALSE
//
//  NOTE: In this sample, we are only interested to know if NS_NTDS or NS_SAP
//        name space provoder is available.
//---------------------------------------------------------------------------
BOOL CheckAvailableNameSpaceProviders(BOOL& fNsSap, BOOL& fNsNtds)
{
    LPWSANAMESPACE_INFO pInfo = NULL;
    DWORD dwBufLen = 0;
    PBYTE pBuf = NULL;
    int nCount = 0;
    int nRet = 0;

    dwBufLen = 0;

    fNsSap = fNsNtds = FALSE;

    nRet = WSAEnumNameSpaceProviders(&dwBufLen, NULL);
    if (nRet == SOCKET_ERROR)
    {
        if (WSAGetLastError() != WSAEFAULT)
        {
            printf("Error %d\n", WSAGetLastError());
            return FALSE;
        }
    }

    // dwBufLen contains the needed buffer size
    pBuf = (PBYTE) HeapAlloc(GetProcessHeap(), 0, dwBufLen);
    if (pBuf == NULL)
    {
        printf("\nCould not allocate buffer\n");
        return FALSE;
    }

    nRet = WSAEnumNameSpaceProviders(&dwBufLen, (LPWSANAMESPACE_INFO)pBuf);
    if (nRet == SOCKET_ERROR)
    {
        printf("Error: %d\n", WSAGetLastError());
        HeapFree(GetProcessHeap(), 0, pBuf);
        return FALSE;
    }

    //Loop thru the returned info
    pInfo = (LPWSANAMESPACE_INFO)pBuf;
    for (nCount = 0; nCount < nRet; nCount++)
    {
        switch (pInfo->dwNameSpace)
        {
        case NS_SAP:
            fNsSap = TRUE;
            break;
        case NS_NTDS:
            fNsNtds = TRUE;
            break;
        default:
            break;
        }
        pInfo++;
    }
    HeapFree(GetProcessHeap(), 0, pBuf);
    return TRUE;
}
Exemplo n.º 2
0
CString CTcpSocket::GetProviders()
{
	static CString strProviders;

	WSANAMESPACE_INFO info[20];
	DWORD dwBufferLength = (sizeof(WSANAMESPACE_INFO) * 20);
	int i, iNumber;

	iNumber = WSAEnumNameSpaceProviders(&dwBufferLength, &info[0]);

	strProviders = _T("");
	for (i = 0; i < iNumber; i ++)
	{
		strProviders += info[i].lpszIdentifier;
		strProviders += _T("\n");
	}

	return strProviders;
}
Exemplo n.º 3
0
DEBUG_LOCAL OSStatus	ReorderNameSpaces( void )
{
	OSStatus				err;
	WSADATA					wsd;
	bool					started;
	int						n;
	int						i;
	DWORD					size;
	WSANAMESPACE_INFO *		array;
	WCHAR					name[ 256 ];
	WCHAR					path[ MAX_PATH ];
	
	array 	= NULL;
	started	= false;
		
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	started = true;
	
	// Build an array of all the NSPs. Call it first with NULL to get the size, allocate a buffer, then get them into it.
	
	size = 0;
	n = WSAEnumNameSpaceProviders( &size, NULL );
	err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr );
	require_action( err == WSAEFAULT, exit, err = kUnknownErr );
	
	array = (WSANAMESPACE_INFO *) malloc( size );
	require_action( array, exit, err = kNoMemoryErr );
	
	n = WSAEnumNameSpaceProviders( &size, array );
	err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr );
	require_noerr( err, exit );
	
	// Find the "Tcpip" NSP.
	
	for( i = 0; i < n; ++i )
	{
		if( strcmp( array[ i ].lpszIdentifier, "Tcpip" ) == 0 )
		{
			break;
		}
	}
	require_action( i < n, exit, err = kNotFoundErr );
	
	// Uninstall it then re-install it to move it to the end.
	
	size = (DWORD) strlen( array[ i ].lpszIdentifier );
	require_action( size < sizeof_array( name ), exit, err = kSizeErr );
	CharToWCharString( array[ i ].lpszIdentifier, name );
	
	size = (DWORD) strlen( "%SystemRoot%\\System32\\mswsock.dll" );
	require_action( size < sizeof_array( path ), exit, err = kSizeErr );
	CharToWCharString( "%SystemRoot%\\System32\\mswsock.dll", path );
	
	err = WSCUnInstallNameSpace( &array[ i ].NSProviderId );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	
	err = WSCInstallNameSpace( name, path, NS_DNS, array[ i ].dwVersion, &array[ i ].NSProviderId );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
		
	// Success!
	
	fprintf( stderr, "Reordered \"Tcpip\" NSP to to the bottom of the NSP chain\n" );	
	err = kNoErr;
	
exit:
	if( array )
	{
		free( array );
	}
	if( started )
	{
		WSACleanup();
	}
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to reorder Name Space Providers\n", err );
	}
	return( err );
}
Exemplo n.º 4
0
DEBUG_LOCAL OSStatus	ListNameSpaces( void )
{
	OSStatus				err;
	WSADATA					wsd;
	bool					started;
	int						n;
	int						i;
	DWORD					size;
	WSANAMESPACE_INFO *		array;
	char					s[ 256 ];
	
	array 	= NULL;
	started	= false;
	
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	started = true;
	
	// Build an array of all the NSPs. Call it first with NULL to get the size, allocate a buffer, then get them into it.
	
	size = 0;
	n = WSAEnumNameSpaceProviders( &size, NULL );
	err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr );
	require_action( err == WSAEFAULT, exit, err = kUnknownErr );
	
	array = (WSANAMESPACE_INFO *) malloc( size );
	require_action( array, exit, err = kNoMemoryErr );
	
	n = WSAEnumNameSpaceProviders( &size, array );
	err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr );
	require_noerr( err, exit );
	
	fprintf( stdout, "\n" );
	for( i = 0; i < n; ++i )
	{
		fprintf( stdout, "Name Space %d\n", i + 1 );
		fprintf( stdout, "    NSProviderId:   %s\n", GUIDtoString( &array[ i ].NSProviderId, sizeof( s ), s ) );
		fprintf( stdout, "    dwNameSpace:    %d\n", array[ i ].dwNameSpace );
		fprintf( stdout, "    fActive:        %s\n", array[ i ].fActive ? "YES" : "NO" );
		fprintf( stdout, "    dwVersion:      %d\n", array[ i ].dwVersion );
		fprintf( stdout, "    lpszIdentifier: \"%s\"\n", array[ i ].lpszIdentifier );
		fprintf( stdout, "\n" );
	}
	err = kNoErr;
	
exit:
	if( array )
	{
		free( array );
	}
	if( started )
	{
		WSACleanup();
	}
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to list Name Space Providers\n", err );
	}
	return( err );
}
Exemplo n.º 5
0
int
main (int argc, char **argv)
{
  int ret;
  int r = 1;
  WSADATA wsd;
  GUID id = GNUNET_NAMESPACE_PROVIDER_DNS;
  wchar_t *cmdl;
  int wargc;
  wchar_t **wargv;
  /* Allocate a 4K buffer to retrieve all the namespace providers */
  DWORD dwInitialBufferLen = 4096;
  DWORD dwBufferLen;
  WSANAMESPACE_INFO *pi;
  int p_count;
  int i;

  if (WSAStartup (MAKEWORD (2,2), &wsd) != 0)
  {
    fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ());
    return 5;
  }

  dwBufferLen = dwInitialBufferLen;
  pi = malloc (dwBufferLen);
  if (NULL == pi)
  {
    fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
    WSACleanup ();
    return 6;
  }
  p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi);
  if (SOCKET_ERROR == p_count)
  {
    DWORD err = GetLastError ();
    if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen)
    {
      free (pi);

      pi = malloc (dwBufferLen);
      if (pi == NULL)
      {
        fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
        WSACleanup ();
        return 6;
      }

      p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi);
      if (SOCKET_ERROR == p_count)
      {
        fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ());
        free (pi);
        WSACleanup ();
        return 7;
      }
    }
    else
    {
      fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ());
      free (pi);
      WSACleanup ();
      return 8;
    }
  }
  for (i= 0; i < p_count; i++)
  {
    if (IsEqualGUID (&pi[i].NSProviderId, &id))
    {
      fprintf (stderr, "GNUnet DNS provider is already installed\n");
      free (pi);
      WSACleanup ();
      return 0;
    }
  }
  free (pi);

  cmdl = GetCommandLineW ();
  if (cmdl == NULL)
  {
    WSACleanup ();
    return 2;
  }
  wargv = CommandLineToArgvW (cmdl, &wargc);
  if (wargv == NULL)
  {
    WSACleanup ();
    return 3;
  }
  r = 4;

  if (wargc == 2)
  {
    ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id);
    if (ret == NO_ERROR)
    {
      fprintf (stderr, "Installed GNUnet DNS provider\n");
      r = 0;
    }
    else
    {
      r = 1;
      fprintf (stderr,
          "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n",
          wargv[1], NS_DNS, &id, GetLastError ());
    }
  }
  else
    fprintf (stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]);
  WSACleanup ();
  return r;
}