|
Lines 51-72
DWORD GetObjectSecurityDescriptor(HANDLE
|
Link Here
|
---|
|
51 |
|
51 |
|
52 |
} // namespace |
52 |
} // namespace |
53 |
|
53 |
|
54 |
DWORD CreateRestrictedToken(HANDLE effective_token, |
54 |
DWORD CreateRestrictedToken(HANDLE effective_token, |
55 |
TokenLevel security_level, |
55 |
TokenLevel security_level, |
56 |
IntegrityLevel integrity_level, |
56 |
IntegrityLevel integrity_level, |
57 |
TokenType token_type, |
57 |
TokenType token_type, |
58 |
bool lockdown_default_dacl, |
58 |
bool lockdown_default_dacl, |
|
|
59 |
PSID unique_restricted_sid, |
59 |
bool use_restricting_sids, |
60 |
bool use_restricting_sids, |
60 |
base::win::ScopedHandle* token) { |
61 |
base::win::ScopedHandle* token) { |
61 |
RestrictedToken restricted_token; |
62 |
RestrictedToken restricted_token; |
62 |
restricted_token.Init(effective_token); |
63 |
restricted_token.Init(effective_token); |
63 |
if (lockdown_default_dacl) |
64 |
if (lockdown_default_dacl) |
64 |
restricted_token.SetLockdownDefaultDacl(); |
65 |
restricted_token.SetLockdownDefaultDacl(); |
|
|
66 |
if (unique_restricted_sid) { |
67 |
restricted_token.AddDefaultDaclSid(Sid(unique_restricted_sid), GRANT_ACCESS, |
68 |
GENERIC_ALL); |
69 |
restricted_token.AddDefaultDaclSid(Sid(WinCreatorOwnerRightsSid), |
70 |
GRANT_ACCESS, READ_CONTROL); |
71 |
} |
65 |
|
72 |
|
66 |
std::vector<base::string16> privilege_exceptions; |
73 |
std::vector<base::string16> privilege_exceptions; |
67 |
std::vector<Sid> sid_exceptions; |
74 |
std::vector<Sid> sid_exceptions; |
68 |
|
75 |
|
69 |
bool deny_sids = true; |
76 |
bool deny_sids = true; |
70 |
bool remove_privileges = true; |
77 |
bool remove_privileges = true; |
71 |
|
78 |
|
72 |
switch (security_level) { |
79 |
switch (security_level) { |
Lines 103-152
DWORD CreateRestrictedToken(HANDLE effec
|
Link Here
|
---|
|
103 |
sid_exceptions.push_back(WinAuthenticatedUserSid); |
110 |
sid_exceptions.push_back(WinAuthenticatedUserSid); |
104 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
111 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
105 |
if (use_restricting_sids) { |
112 |
if (use_restricting_sids) { |
106 |
restricted_token.AddRestrictingSid(WinBuiltinUsersSid); |
113 |
restricted_token.AddRestrictingSid(WinBuiltinUsersSid); |
107 |
restricted_token.AddRestrictingSid(WinWorldSid); |
114 |
restricted_token.AddRestrictingSid(WinWorldSid); |
108 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
115 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
109 |
restricted_token.AddRestrictingSidCurrentUser(); |
116 |
restricted_token.AddRestrictingSidCurrentUser(); |
110 |
restricted_token.AddRestrictingSidLogonSession(); |
117 |
restricted_token.AddRestrictingSidLogonSession(); |
|
|
118 |
if (unique_restricted_sid) |
119 |
restricted_token.AddRestrictingSid(Sid(unique_restricted_sid)); |
111 |
} |
120 |
} |
112 |
break; |
121 |
break; |
113 |
} |
122 |
} |
114 |
case USER_LIMITED: { |
123 |
case USER_LIMITED: { |
115 |
sid_exceptions.push_back(WinBuiltinUsersSid); |
124 |
sid_exceptions.push_back(WinBuiltinUsersSid); |
116 |
sid_exceptions.push_back(WinWorldSid); |
125 |
sid_exceptions.push_back(WinWorldSid); |
117 |
sid_exceptions.push_back(WinInteractiveSid); |
126 |
sid_exceptions.push_back(WinInteractiveSid); |
118 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
127 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
119 |
if (use_restricting_sids) { |
128 |
if (use_restricting_sids) { |
120 |
restricted_token.AddRestrictingSid(WinBuiltinUsersSid); |
129 |
restricted_token.AddRestrictingSid(WinBuiltinUsersSid); |
121 |
restricted_token.AddRestrictingSid(WinWorldSid); |
130 |
restricted_token.AddRestrictingSid(WinWorldSid); |
122 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
131 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
|
|
132 |
if (unique_restricted_sid) |
133 |
restricted_token.AddRestrictingSid(Sid(unique_restricted_sid)); |
123 |
|
134 |
|
124 |
// This token has to be able to create objects in BNO. |
135 |
// This token has to be able to create objects in BNO. |
125 |
// Unfortunately, on Vista+, it needs the current logon sid |
136 |
// Unfortunately, on Vista+, it needs the current logon sid |
126 |
// in the token to achieve this. You should also set the process to be |
137 |
// in the token to achieve this. You should also set the process to be |
127 |
// low integrity level so it can't access object created by other |
138 |
// low integrity level so it can't access object created by other |
128 |
// processes. |
139 |
// processes. |
129 |
restricted_token.AddRestrictingSidLogonSession(); |
140 |
restricted_token.AddRestrictingSidLogonSession(); |
|
|
141 |
} else { |
142 |
restricted_token.AddUserSidForDenyOnly(); |
130 |
} |
143 |
} |
131 |
break; |
144 |
break; |
132 |
} |
145 |
} |
133 |
case USER_RESTRICTED: { |
146 |
case USER_RESTRICTED: { |
134 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
147 |
privilege_exceptions.push_back(SE_CHANGE_NOTIFY_NAME); |
135 |
restricted_token.AddUserSidForDenyOnly(); |
148 |
restricted_token.AddUserSidForDenyOnly(); |
136 |
if (use_restricting_sids) { |
149 |
if (use_restricting_sids) { |
137 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
150 |
restricted_token.AddRestrictingSid(WinRestrictedCodeSid); |
|
|
151 |
if (unique_restricted_sid) |
152 |
restricted_token.AddRestrictingSid(Sid(unique_restricted_sid)); |
138 |
} |
153 |
} |
139 |
break; |
154 |
break; |
140 |
} |
155 |
} |
141 |
case USER_LOCKDOWN: { |
156 |
case USER_LOCKDOWN: { |
142 |
restricted_token.AddUserSidForDenyOnly(); |
157 |
restricted_token.AddUserSidForDenyOnly(); |
143 |
if (use_restricting_sids) { |
158 |
if (use_restricting_sids) { |
144 |
restricted_token.AddRestrictingSid(WinNullSid); |
159 |
restricted_token.AddRestrictingSid(WinNullSid); |
|
|
160 |
if (unique_restricted_sid) |
161 |
restricted_token.AddRestrictingSid(Sid(unique_restricted_sid)); |
145 |
} |
162 |
} |
146 |
break; |
163 |
break; |
147 |
} |
164 |
} |
148 |
default: { return ERROR_BAD_ARGUMENTS; } |
165 |
default: { return ERROR_BAD_ARGUMENTS; } |
149 |
} |
166 |
} |
150 |
|
167 |
|
151 |
DWORD err_code = ERROR_SUCCESS; |
168 |
DWORD err_code = ERROR_SUCCESS; |
152 |
if (deny_sids) { |
169 |
if (deny_sids) { |