Beispiel #1
0
DEBUG_LOCAL OSStatus	RemoveNSP( const char *inGUID )
{
	OSStatus		err;
	WSADATA			wsd;
	GUID			guid;
	
	require_action( inGUID && ( *inGUID != '\0' ), exit, err = kParamErr );
	
	err = StringToGUID( inGUID, &guid );
	require_noerr( err, exit );
	
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	
	err = WSCUnInstallNameSpace( &guid );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	WSACleanup();
	require_noerr( err, exit );
	
	if (!gToolQuietMode)
	{
		fprintf( stderr, "Removed NSP %s\n", inGUID );
	}
		
exit:
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to remove %s Name Space Provider\n", err, inGUID );
	}
	return( err );
}
int
main (int argc, char **argv)
{
  int ret;
  GUID id = GNUNET_NAMESPACE_PROVIDER_DNS;
  WSADATA wsd;

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

  ret = WSCUnInstallNameSpace (&id);
  if (ret == NO_ERROR)
  {
    WSACleanup ();
    return 0;
  }
  fprintf (stderr, "WSCUnInstallNameSpace() failed: %lu\n", GetLastError ());
  WSACleanup ();
  return 1;
}
Beispiel #3
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;
}
Beispiel #4
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 );
}
Beispiel #5
0
BOOL
RemoveNameSpaceProviderCallback(
    LPTSTR IniFile,
    LPTSTR SectionName,
    DWORD Context
    )

/*++

Routine Description:

    Callback routine for EnumProviderSections() that removes 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 providerIdString[MAX_INIFILE_LINE];
    DWORD length;
    INT result;
    INT error;
    GUID providerId;
    RPC_STATUS status;
    BOOL ignoreErrors;

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

    _tprintf(
        TEXT("Removing %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 provider name & ID.
    //

    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("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;

    }

    //
    // Remove it.
    //

    result = WSCUnInstallNameSpace(
                 &providerId
                 );

    if( result == SOCKET_ERROR ) {

        error = GetLastError();

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

        return ignoreErrors;

    }

    return TRUE;

}   // RemoveNameSpaceProviderCallback