os/security/crypto/weakcryptospi/test/kms/driver/test/kmslddtest/dup.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Tests handle to KMS LDD channel can only be be duplicated as
sl@0
    16
* thread-relative and into the owning thread.
sl@0
    17
*
sl@0
    18
*/
sl@0
    19
sl@0
    20
sl@0
    21
/**
sl@0
    22
 @file
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "kmslddtest.h"
sl@0
    26
sl@0
    27
sl@0
    28
static TInt DupIntoSecondProcess(TAny* aPtr)
sl@0
    29
/**
sl@0
    30
	Test duplicating the KMS channel handle into a second thread.
sl@0
    31
	
sl@0
    32
	@param	aPtr			Standard entrypoint argument.  This actually
sl@0
    33
							points to the calling thread's ID.
sl@0
    34
	@return					KErrNone.  This value has no meaning, and is
sl@0
    35
							only used to satisfy the TThreadFunction signature.
sl@0
    36
 */
sl@0
    37
	{
sl@0
    38
	TInt r;
sl@0
    39
	
sl@0
    40
	// test thread id
sl@0
    41
	TThreadId testThreadId = *reinterpret_cast<const TThreadId*>(aPtr);
sl@0
    42
	RThread testThread;
sl@0
    43
	r = testThread.Open(testThreadId);
sl@0
    44
	test(r == KErrNone);
sl@0
    45
	
sl@0
    46
	RKmsChannel dupCh;
sl@0
    47
	TInt h = KmsChannel.Handle();
sl@0
    48
	
sl@0
    49
	// duplicate into process-relative handle "in" second thread
sl@0
    50
	dupCh.SetHandle(h);
sl@0
    51
	r = dupCh.Duplicate(testThread, EOwnerProcess);
sl@0
    52
	test(r == KErrAccessDenied);
sl@0
    53
	
sl@0
    54
	// duplicate into thread-relative handle "in" second thread
sl@0
    55
	dupCh.SetHandle(h);
sl@0
    56
	r = dupCh.Duplicate(testThread, EOwnerThread);
sl@0
    57
	test(r == KErrAccessDenied);
sl@0
    58
sl@0
    59
	testThread.Close();	
sl@0
    60
	return KErrNone;
sl@0
    61
	}
sl@0
    62
sl@0
    63
void TestDup()
sl@0
    64
/**
sl@0
    65
	Test a KMS channel handle can only be duplicated by the thread
sl@0
    66
	which opened it.
sl@0
    67
 */
sl@0
    68
	{
sl@0
    69
	TInt r;
sl@0
    70
	
sl@0
    71
	RKmsChannel dupCh;
sl@0
    72
	TInt h = KmsChannel.Handle();
sl@0
    73
	RThread currentThread;
sl@0
    74
	
sl@0
    75
	// duplicate into process-relative handle "in" test thread
sl@0
    76
	dupCh.SetHandle(h);
sl@0
    77
	r = dupCh.Duplicate(currentThread, EOwnerProcess);
sl@0
    78
	test(r == KErrAccessDenied);
sl@0
    79
	
sl@0
    80
	// duplicate into thread-relative handle in test thread
sl@0
    81
	dupCh.SetHandle(h);
sl@0
    82
	r = dupCh.Duplicate(currentThread, EOwnerThread);
sl@0
    83
	test(r == KErrNone);
sl@0
    84
	dupCh.Close();
sl@0
    85
	
sl@0
    86
	TThreadId id = currentThread.Id();
sl@0
    87
	RThread secondThread = LaunchThreadAndWaitForRendezvous(DupIntoSecondProcess, &id);
sl@0
    88
	secondThread.Close();
sl@0
    89
	}
sl@0
    90