GetSidForThreadId method

This method is deprecated.

Retrieves the Security Identifier under which a given thread is running.

Syntax

HRESULT

GetSidForThreadId(

    [in]           int ThreadId

    [out, retval]  BSTR* SidString

)

Parameters

ThreadId [in]

The Thread ID of a currently active thread.

SidString [out, retval]

A pointer to a string into which to return the string format of the Security Identifier (SID) under which the thread is executing.

Return value

If the method succeeds, S_OK is returned.

Note that this method can fail due to security reasons, when called for certain Windows protected processes.  This is by (Microsoft’s) design and cannot be bypassed.

If the method fails for any reason, an appropriate error code is returned.

Remarks

Important: This method is deprecated and is pending removal from FESF. Do not use it. Convert existing code that uses it as soon as possible. Use the equivalent function provided by the FesfUtil2 Library.

A Client Solution may call this method to retrieve the Security Identifier (SID) under which a given thread is executing.

This method relies on support from the FESF Kernel Mode Components.  Note that methods in the FESF Utility library are only designed for use when FESF is installed and the FESF Kernel Mode Components are running.  If GetSidForThreadId is called when the FESF Kernel Mode Components are not running, an error value is returned.

Examples

The following example is taken from the Sample Policy DLL (SampPolicy) that is part of the UM_Sample project.

//

// Get the SID (Security ID) based on the calling thread. This uniquely

// identifies the user that created the thread, so it can be used in 

// user-based policy decisions. The FesfUtil dll provides a helper for this.

//

CComBSTR sid;

HRESULT hr = g_pFesfUtil->GetSidForThreadId(ThreadId, &sid);

if (FAILED(hr))

{

    ATLTRACE(L">>>Failed to obtain SID for thread %d : %x\n"ThreadIdhr);

    return FE_POLICY_RAW;

}

 

//

// Get a path to the executable that is creating the file. FesfUtil provides

// a helper for this as well.

//

CComBSTR exePath;

hr = g_pFesfUtil->GetExecutablePathForThreadId(ThreadId, &exePath);

 

if (FAILED(hr))

{

    ATLTRACE(L">>>Failed to obtain executable file for thread %d : %x\n"ThreadIdhr);

    return FE_POLICY_RAW;

}

 

//

// We've gathered all the sample policy manager needs to make a decision,

// so ask it what we should do with the file. We could make that decision

// here if it were more convenient to do so.

//

VARIANT_BOOL encdec = VARIANT_FALSE;

hr = g_pPolicyManager->GetPolicyNewFile(

     &PolicyPathInfo->VolumeGuidCComBSTR(PolicyPathInfo->RelativePath),

     exePathsidThreadId, &encdec);

 

See Also

The provided UM_Sample solution contains several examples that illustrate the use of this method.

 

Requirements

Software version

FESF V1 (or later)

DLL

FESFUtility.DLL

Supported FESF State

FESF Online State.

Type Library

\UM_FESF\UMLIB\FESFUTILITY.TLB

IID

IFesfUtil  (please use the defintion from the Type Library)

CLSID

FesfUtil (please use the definition from the Type Library)