Exemplo n.º 1
0
OSStatus	InstallNSP( const char *inName, const char *inGUID, const char *inPath )
{
	OSStatus		err;
	size_t			size;
	WSADATA			wsd;
	WCHAR			name[ 256 ];
	GUID			guid;
	WCHAR			path[ MAX_PATH ];
	
	require_action( inName && ( *inName != '\0' ), exit, err = kParamErr );
	require_action( inGUID && ( *inGUID != '\0' ), exit, err = kParamErr );
	require_action( inPath && ( *inPath != '\0' ), exit, err = kParamErr );
	
	size = strlen( inName );
	require_action( size < sizeof_array( name ), exit, err = kSizeErr );
	CharToWCharString( inName, name );
	
	err = StringToGUID( inGUID, &guid );
	require_noerr( err, exit );
	
	size = strlen( inPath );
	require_action( size < sizeof_array( path ), exit, err = kSizeErr );
	CharToWCharString( inPath, path );
	
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	
	err = WSCInstallNameSpace( name, path, NS_DNS, 1, &guid );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	WSACleanup();
	require_noerr( err, exit );
	
	if (!gToolQuietMode)
	{
		fprintf( stderr, "Installed NSP \"%s\" (%s) at %s\n", inName, inGUID, inPath );
	}
	
exit:
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to install \"%s\" (%s) Name Space Provider at %s\n", err, inName, inGUID, inPath );
	}
	return( err );
}
Exemplo n.º 2
0
//
// Function: main
//
// Description:
//    This function parses the command line and executes the
//    appropriate command - either install or remove our name
//    space provider.
//
int main(int argc, char **argv)
{
    WSADATA        wsd;
    char          *ptr; 
    int            ret;

    // Check for the appropriate number of arguments.
    //
    if (argc != 2)
    {
        usage(argv[0]);
        return -1;
    }
    if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
    {
        printf("WSAStartup() failed: %d\n", GetLastError());
        return -1;
    }
    // Convert any arguments to lower case
    //
    ptr = argv[1];
    while (*ptr)
        *ptr++ = tolower(*ptr);
    //
    // Install the name space provider
    //
    if (!strncmp(argv[1], "install", 6))
    {
        // Pnstall the provider
        //
        ret = WSCInstallNameSpace(L"Custom Name Space Provider",
                L"%SystemRoot%\\System32\\mynsp.dll", NS_MYNSP, 1, &MY_NAMESPACE_GUID);
        if (ret == SOCKET_ERROR)
        {
            printf("Failed to install name space provider: %d\n",
                WSAGetLastError());
        }
        else
        {
            printf("Successfully installed name space provider\n");
        }
    }
    // Remove the name space provider
    //
    else if (!strncmp(argv[1], "remove", 6))
    {
        ret = WSCUnInstallNameSpace(&MY_NAMESPACE_GUID);
        if (ret == SOCKET_ERROR)
        {
            printf("Failed to remove provider: %d\n", WSAGetLastError());
        }
        else
        {
            printf("Successfully removed name space provider\n");
        }
    }
    else
    {
        usage(argv[0]);
    }

    WSACleanup();
    return 0;
}
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
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;
}
Exemplo n.º 5
0
BOOL
InstallNameSpaceProviderCallback(
    LPTSTR IniFile,
    LPTSTR SectionName,
    DWORD Context
    )

/*++

Routine Description:

    Callback routine for EnumProviderSections() that installs the
    namespace service provider described by the given .INI file section.

Arguments:

    IniFile - The name of the .INI file describing the namespace provider.

    SectionName - The name of the .INI file section for this provider.

    Context - Actually contains behaviour control options (OPTION_FLAG_*).

Return Value:

    BOOL - TRUE if successful, FALSE otherwise.

--*/

{

    TCHAR providerName[MAX_INIFILE_LINE];
    TCHAR providerPath[MAX_INIFILE_LINE];
    TCHAR providerIdString[MAX_INIFILE_LINE];
    UINT i;
    DWORD length;
    INT result;
    INT error;
    GUID providerId;
    DWORD nameSpaceId;
    RPC_STATUS status;
    BOOL ignoreErrors;

    //
    // Let the user know what we're up to.
    //

    _tprintf(
        TEXT("Installing %s\n"),
        SectionName
        );

    //
    // Determine if we should ignore errors. If so, then this routine
    // will always return TRUE.
    //

    ignoreErrors = ( ( Context & OPTION_FLAG_IGNORE_ERRORS ) != 0 );

    //
    // Read the fixed information.
    //

    length = GetPrivateProfileString(
                 SectionName,
                 TEXT("ProviderName"),
                 TEXT(""),
                 providerName,
                 sizeof(providerName) / sizeof(providerName[0]),
                 IniFile
                 );

    if( length == 0 ) {

        _tprintf(
            TEXT("ERROR: missing ProviderName key\n")
            );

        return ignoreErrors;

    }

    length = GetPrivateProfileString(
                 SectionName,
                 TEXT("ProviderPath"),
                 TEXT(""),
                 providerPath,
                 sizeof(providerPath) / sizeof(providerPath[0]),
                 IniFile
                 );

    if( length == 0 ) {

        _tprintf(
            TEXT("ERROR: missing ProviderPath key\n")
            );

        return ignoreErrors;

    }

    length = GetPrivateProfileString(
                 SectionName,
                 TEXT("ProviderId"),
                 TEXT(""),
                 providerIdString,
                 sizeof(providerIdString) / sizeof(providerIdString[0]),
                 IniFile
                 );

    if( length == 0 ) {

        _tprintf(
            TEXT("ERROR: missing ProviderId key\n")
            );

        return ignoreErrors;

    }

    //
    // Build the GUID.
    //

    status = UuidFromString(
                 providerIdString,
                 &providerId
                 );

    if( status != RPC_S_OK ) {

        _tprintf(
            TEXT("ERROR: invalid ProviderId %s\n"),
            providerIdString
            );

        return ignoreErrors;

    }

    nameSpaceId = GetPrivateProfileInt(
                      SectionName,
                      TEXT("NameSpaceId"),
                      0,
                      IniFile
                      );

    if( nameSpaceId == 0 ) {

        _tprintf(
            TEXT("ERROR: missing NameSpaceId key\n")
            );

        return ignoreErrors;

    }

    //
    // Install it.
    //

    result = WSCInstallNameSpace(
                 providerName,
                 providerPath,
                 nameSpaceId,
                 2,
                 &providerId
                 );

    if( result == SOCKET_ERROR ) {

        error = GetLastError();

        _tprintf(
            TEXT("Cannot install %s, error %d\n"),
            providerName,
            error
            );

        return ignoreErrors;

    }

    return TRUE;

}   // InstallNameSpaceProviderCallback