00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_SECURITY_HPP_TOKEN_INFORMATION
00048 #define WINSTL_INCL_WINSTL_SECURITY_HPP_TOKEN_INFORMATION
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_SECURITY_HPP_TOKEN_INFORMATION_MAJOR 4
00052 # define WINSTL_VER_WINSTL_SECURITY_HPP_TOKEN_INFORMATION_MINOR 1
00053 # define WINSTL_VER_WINSTL_SECURITY_HPP_TOKEN_INFORMATION_REVISION 1
00054 # define WINSTL_VER_WINSTL_SECURITY_HPP_TOKEN_INFORMATION_EDIT 53
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
00065 # include <winstl/memory/processheap_allocator.hpp>
00066 #endif
00067 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS
00068 # include <stlsoft/error/exceptions.hpp>
00069 #endif
00070 #ifndef WINSTL_INCL_WINSTL_ERROR_HPP_LAST_ERROR_SCOPE
00071 # include <winstl/error/last_error_scope.hpp>
00072 #endif
00073
00074
00075
00076
00077
00078 #ifndef _WINSTL_NO_NAMESPACE
00079 # if defined(_STLSOFT_NO_NAMESPACE) || \
00080 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00081
00082 namespace winstl
00083 {
00084 # else
00085
00086
00087 namespace stlsoft
00088 {
00089
00090 namespace winstl_project
00091 {
00092
00093 # endif
00094 #endif
00095
00096
00097
00098 enum
00099 {
00100 TokenRestrictedSids = 1 + TokenStatistics
00101 , TokenSessionId
00102 , TokenGroupsAndPrivileges
00103 , TokenSessionReference
00104 , TokenSandBoxInert
00105 , TokenAuditPolicy
00106 , TokenOrigin
00107 };
00108
00109
00110
00111
00112
00118 template <TOKEN_INFORMATION_CLASS C>
00119 struct token_information_traits;
00120
00121
00122 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00123 STLSOFT_TEMPLATE_SPECIALISATION
00124 struct token_information_traits<TokenUser>
00125 {
00126 typedef TOKEN_USER data_type;
00127 };
00128
00129 STLSOFT_TEMPLATE_SPECIALISATION
00130 struct token_information_traits<TokenGroups>
00131 {
00132 typedef TOKEN_GROUPS data_type;
00133 };
00134
00135 STLSOFT_TEMPLATE_SPECIALISATION
00136 struct token_information_traits<TokenPrivileges>
00137 {
00138 typedef TOKEN_PRIVILEGES data_type;
00139 };
00140
00141 STLSOFT_TEMPLATE_SPECIALISATION
00142 struct token_information_traits<TokenOwner>
00143 {
00144 typedef TOKEN_OWNER data_type;
00145 };
00146
00147 STLSOFT_TEMPLATE_SPECIALISATION
00148 struct token_information_traits<TokenPrimaryGroup>
00149 {
00150 typedef TOKEN_PRIMARY_GROUP data_type;
00151 };
00152
00153 STLSOFT_TEMPLATE_SPECIALISATION
00154 struct token_information_traits<TokenDefaultDacl>
00155 {
00156 typedef TOKEN_DEFAULT_DACL data_type;
00157 };
00158
00159 STLSOFT_TEMPLATE_SPECIALISATION
00160 struct token_information_traits<TokenSource>
00161 {
00162 typedef TOKEN_SOURCE data_type;
00163 };
00164
00165 STLSOFT_TEMPLATE_SPECIALISATION
00166 struct token_information_traits<TokenType>
00167 {
00168 typedef TOKEN_TYPE data_type;
00169 };
00170
00171 STLSOFT_TEMPLATE_SPECIALISATION
00172 struct token_information_traits<TokenImpersonationLevel>
00173 {
00174 typedef SECURITY_IMPERSONATION_LEVEL data_type;
00175 };
00176
00177 STLSOFT_TEMPLATE_SPECIALISATION
00178 struct token_information_traits<TokenStatistics>
00179 {
00180 typedef TOKEN_STATISTICS data_type;
00181 };
00182
00183 STLSOFT_TEMPLATE_SPECIALISATION
00184 struct token_information_traits<static_cast<TOKEN_INFORMATION_CLASS>(TokenRestrictedSids)>
00185 {
00186 typedef TOKEN_GROUPS data_type;
00187 };
00188
00189 STLSOFT_TEMPLATE_SPECIALISATION
00190 struct token_information_traits<static_cast<TOKEN_INFORMATION_CLASS>(TokenSessionId)>
00191 {
00192 typedef DWORD data_type;
00193 };
00194
00195 #if defined(WINSTL_TOKEN_INFORMATION_TOKEN_GROUPS_AND_PRIVILEGES_SUPPORT) || \
00196 ( !defined(WINSTL_TOKEN_INFORMATION_NO_GUESS) && \
00197 defined(SE_MANAGE_VOLUME_NAME))
00198 STLSOFT_TEMPLATE_SPECIALISATION
00199 struct token_information_traits<static_cast<TOKEN_INFORMATION_CLASS>(TokenGroupsAndPrivileges)>
00200 {
00201 typedef TOKEN_GROUPS_AND_PRIVILEGES data_type;
00202 };
00203 #endif
00204
00205 STLSOFT_TEMPLATE_SPECIALISATION
00206 struct token_information_traits<static_cast<TOKEN_INFORMATION_CLASS>(TokenSandBoxInert)>
00207 {
00208 typedef DWORD data_type;
00209 };
00210
00211 #if defined(WINSTL_TOKEN_INFORMATION_TOKEN_ORIGIN_SUPPORT)
00212
00213
00214 STLSOFT_TEMPLATE_SPECIALISATION
00215 struct token_information_traits<static_cast<TOKEN_INFORMATION_CLASS>(TokenOrigin)>
00216 {
00217 typedef TOKEN_ORIGIN data_type;
00218 };
00219 #endif
00220
00221
00222
00223 #endif
00224
00225
00230 template< TOKEN_INFORMATION_CLASS C
00231 #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00232 # ifdef __SYNSOFT_DBS_COMPILER_SUPPORTS_PRAGMA_MESSAGE
00233 # pragma message(_sscomp_fileline_message("Note that we have to have data_type as a parameter, otherwise VC5&6 have a cow"))
00234 # endif
00235 , ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
00236 , ss_typename_param_k D = ss_typename_type_def_k token_information_traits<C>::data_type
00237 , ss_typename_param_k A = processheap_allocator<ss_byte_t>
00238 #else
00239 , ss_typename_param_k X
00240 , ss_typename_param_k D
00241 , ss_typename_param_k A
00242 #endif
00243 >
00244 class token_information
00245 {
00248 public:
00249 typedef token_information<C, X, D, A> class_type;
00250 typedef token_information_traits<C> traits_type;
00251 typedef X exception_thrower_type;
00252 typedef D data_type;
00253 typedef A allocator_type;
00254
00256
00259 public:
00262 ss_explicit_k token_information(HANDLE hToken)
00263 : m_data(0)
00264 {
00265 DWORD cbRequired;
00266 DWORD dwError;
00267
00268 ::GetTokenInformation(hToken, C, NULL, 0, &cbRequired);
00269 dwError = ::GetLastError();
00270 if(ERROR_INSUFFICIENT_BUFFER != dwError)
00271 {
00272
00273 exception_thrower_type()(dwError);
00274 }
00275 else
00276 {
00277 data_type *data = reinterpret_cast<data_type*>(allocator_type().allocate(cbRequired));
00278
00279 if(NULL == data)
00280 {
00281
00282 exception_thrower_type()(ERROR_NOT_ENOUGH_MEMORY);
00283
00284
00285 ::SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00286 }
00287 else
00288 {
00289 if(!::GetTokenInformation(hToken, C, data, cbRequired, &cbRequired))
00290 {
00291
00292 last_error_scope scope;
00293
00294 allocator_type().deallocate(reinterpret_cast<ss_byte_t*>(data));
00295
00296
00297 exception_thrower_type()(DWORD((scope)));
00298 }
00299 else
00300 {
00301
00302 m_data = data;
00303
00304 ::SetLastError(ERROR_SUCCESS);
00305 }
00306 }
00307 }
00308 }
00309 ~token_information() stlsoft_throw_0()
00310 {
00311 allocator_type().deallocate(reinterpret_cast<ss_byte_t*>(m_data));
00312 }
00314
00317 public:
00318 operator data_type *()
00319 {
00320 return m_data;
00321 }
00322 operator data_type const* () const
00323 {
00324 return m_data;
00325 }
00326
00327 data_type *operator ->()
00328 {
00329 return m_data;
00330 }
00331 data_type const* operator ->() const
00332 {
00333 return m_data;
00334 }
00335
00336
00337
00338
00339
00340
00341 ws_bool_t operator !() const
00342 {
00343 return 0 == m_data;
00344 }
00346
00349 private:
00351
00354 private:
00355 data_type *m_data;
00357
00360 private:
00361 token_information(token_information const&);
00362 token_information& operator =(token_information const&);
00364 };
00365
00366
00367
00368 #ifndef _WINSTL_NO_NAMESPACE
00369 # if defined(_STLSOFT_NO_NAMESPACE) || \
00370 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00371 }
00372 # else
00373 }
00374 }
00375 # endif
00376 #endif
00377
00378
00379
00380 #endif
00381
00382