summaryrefslogtreecommitdiff
path: root/src/vm/securitydeclarativecache.h
blob: 5ca71c6fd38f96dfd7de3693330c0e032f075ac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// 

// 


#ifndef __SecurityDecarativeCache_h__
#define __SecurityDecarativeCache_h__

struct PsetCacheKey
{
public:
    PBYTE m_pbPset;
    DWORD m_cbPset;
    BOOL m_bCopyArray;

    void Init (PBYTE pbPset, DWORD cbPset, BOOL CopyArray, LoaderHeap *pHeap) 
    {
        CONTRACTL
        {
            THROWS;
            GC_NOTRIGGER;
            MODE_ANY;
        }
        CONTRACTL_END;

        m_cbPset = cbPset;
        
        if (CopyArray) {
            m_pbPset = (PBYTE) ((void*)pHeap->AllocMem((S_SIZE_T)(cbPset * sizeof(BYTE)))) ;
            memcpy (m_pbPset, pbPset, cbPset);
        } else {
            m_pbPset = pbPset;
        }
    }
    
    BOOL IsEquiv(PsetCacheKey *pOther);
    DWORD Hash();
};

//
// Records a serialized permission set we've seen and decoded. 
//

enum CanUnrestrictedOverride
{
    CUO_DontKnow = 0,
    CUO_Yes = 1,
    CUO_No = 2,
};

class PsetCacheEntry
{
private:
    PsetCacheKey* m_pKey;
    OBJECTHANDLE m_handle;
    BYTE m_eCanUnrestrictedOverride;
    bool m_fEmptyPermissionSet;

    bool ContainsBuiltinCASPermsOnlyInternal(DWORD dwAction);

public:

    void Init(PsetCacheKey* pKey, AppDomain* pDomain);

    OBJECTREF CreateManagedPsetObject(DWORD dwAction, bool createEmptySet = false);
    
    OBJECTREF GetManagedPsetObject()
    {
        WRAPPER_NO_CONTRACT;
        return ObjectFromHandle(m_handle); 
    }

    bool ContainsBuiltinCASPermsOnly (DWORD dwAction);
    PsetCacheEntry() {m_pKey = NULL;}
    ~PsetCacheEntry()
    {
    	 if (m_pKey) { 
        	delete m_pKey;
    	}
    }
};



class SecurityDeclarativeCache {

private:
    EEPsetHashTable* m_pCachedPsetsHash;
    SimpleRWLock* m_prCachedPsetsLock;
    LoaderHeap* m_pHeap;

    PsetCacheEntry* GetCachedPsetWithoutLocks(IN PBYTE pbAttrBlob,
                                              IN DWORD cbAttrBlob
        );

public:
    void Init(LoaderHeap *pHeap);

    SecurityDeclarativeCache() :
       m_pCachedPsetsHash(NULL),
       m_prCachedPsetsLock(NULL),
       m_pHeap(NULL)
    {
        LIMITED_METHOD_CONTRACT;
    }
    
    ~SecurityDeclarativeCache();

    PsetCacheEntry* CreateAndCachePset(IN PBYTE pbAttrBlob,
                                       IN DWORD cbAttrBlob
        );

    PsetCacheEntry* GetCachedPset(IN PBYTE pbAttrBlob,
                                  IN DWORD cbAttrBlob
        );

    
};

#endif