共用方式為


將 SID 新增至用戶端內容

應用程式可以藉由呼叫AuthzAddSidsToCoNtext函式,將安全性識別碼 () 新增至現有的用戶端內容。 AuthzAddSidsToCoNtext函式可讓應用程式同時指定 SID 清單,以及將 SID 限制為指定用戶端內容的清單。

當系統檢查權杖對安全性實體物件的存取權時,系統會使用限制 SID 的清單。 當受限制的進程或執行緒嘗試存取安全性實體物件時,系統會執行兩個存取檢查:一個使用權杖已啟用的 SID,另一個則使用限制 SID 的清單。 只有在兩個存取檢查都允許要求的存取權限時,才會授與存取權。

當搭配邏輯運算子使用時,屬性變數的格式必須是運算式;否則,系統會將其評估為未知。

範例

下列範例會在 初始化用戶端內容中,將 SID 和限制 SID 新增至範例所建立的用戶端內容。

BOOL AddSidsToContext(AUTHZ_CLIENT_CONTEXT_HANDLE *phClientContext)
{
    AUTHZ_CLIENT_CONTEXT_HANDLE        NewContext = NULL;
    PSID                            pEveryoneSid = NULL;
    PSID                            pLocalSid = NULL;
    SID_AND_ATTRIBUTES                Sids;
    SID_AND_ATTRIBUTES                RestrictedSids;
    DWORD                            SidCount = 0;
    DWORD                            RestrictedSidCount = 0;

    //Create a PSID from the "Everyone" well-known SID.
    if(!ConvertStringSidToSid(L"S-1-1-0", &pEveryoneSid))
    {
        printf_s("ConvertStringSidToSid failed with %d\n", GetLastError());
        return FALSE;
    }

    //Create a PSID from the "Local" well-known SID.
    if(!ConvertStringSidToSid(L"S-1-2-0", &pLocalSid))
    {
        printf_s("ConvertStringSidToSid failed with %d\n", GetLastError);
        return FALSE;
    }

    //Set the members of the SID_AND_ATTRIBUTES structure to be added.
    Sids.Sid = pEveryoneSid;
    Sids.Attributes = SE_GROUP_ENABLED;

    //Set the members of the SID_AND_ATTRIBUTES structure for the restricting SID.
    RestrictedSids.Sid = pLocalSid;
    RestrictedSids.Attributes = SE_GROUP_ENABLED;

    

    //Create a new context with the new "Everyone" SID and "Local" restricting SID.
    if(!AuthzAddSidsToContext(
        *phClientContext,
        &Sids,
        1,
        &RestrictedSids,
        1,
        &NewContext))
    {
        printf_s("AuthzAddSidsToContext failed with %d\n", GetLastError());
        if(pEveryoneSid)
        {
            FreeSid(pEveryoneSid);
        }
        if(pLocalSid)
        {
            FreeSid(pLocalSid);
        }
        return FALSE;
    }

    if(pEveryoneSid)
        {
            FreeSid(pEveryoneSid);
        }
        if(pLocalSid)
        {
            FreeSid(pLocalSid);
        }
        
        AuthzFreeContext(*phClientContext);
        *phClientContext = NewContext;

    return TRUE;

}

快取存取檢查

使用 Authz API 檢查存取

初始化用戶端內容

查詢用戶端內容