STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

comstl_security_initialisers.h

Go to the documentation of this file.
00001 /* 
00002  * File:        comstl_security_initialisers.h (originally MOSecFns.h, ::SynesisCom)
00003  *
00004  * Purpose:     Contains classes for initialising COM/OLE.
00005  *
00006  * Created:     1st February 1998
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 1998-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef COMSTL_INCL_H_COMSTL_SECURITY_INITIALISERS
00046 #define COMSTL_INCL_H_COMSTL_SECURITY_INITIALISERS
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define COMSTL_VER_H_COMSTL_SECURITY_INITIALISERS_MAJOR        3
00050 # define COMSTL_VER_H_COMSTL_SECURITY_INITIALISERS_MINOR        0
00051 # define COMSTL_VER_H_COMSTL_SECURITY_INITIALISERS_REVISION     1
00052 # define COMSTL_VER_H_COMSTL_SECURITY_INITIALISERS_EDIT         21
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef COMSTL_INCL_H_COMSTL
00060 # include "comstl.h"                // Include the COMSTL root header
00061 #endif /* !COMSTL_INCL_H_COMSTL */
00062 
00063 #if (   !defined(_WIN32_WINNT) || \
00064         (_WIN32_WINNT < 0x0400)) && \
00065     !defined(_WIN32_DCOM)
00066 # error This file can only be used in the context of DCOM compilations.
00067 #endif /* _WIN32_WINNT < 0x0400 && !_WIN32_DCOM */
00068 
00069 #if _MSC_VER >= 1200
00070 # include <iaccess.h>
00071 #endif /* _MSC_VER >= 1200 */
00072 
00073 /* 
00074  * Namespace
00075  *
00076  * The COMSTL components are contained within the comstl namespace. This is
00077  * actually an alias for stlsoft::comstl_project,
00078  *
00079  * The definition matrix is as follows:
00080  *
00081  * _STLSOFT_NO_NAMESPACE    _COMSTL_NO_NAMESPACE    comstl definition
00082  * ---------------------    --------------------    -----------------
00083  *  not defined              not defined             = stlsoft::comstl_project
00084  *  not defined              defined                 not defined
00085  *  defined                  not defined             comstl
00086  *  defined                  defined                 not defined
00087  *
00088  */
00089 
00090 #ifndef _COMSTL_NO_NAMESPACE
00091 # if defined(_STLSOFT_NO_NAMESPACE) || \
00092      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00093 /* There is no stlsoft namespace, so must define ::comstl */
00094 namespace comstl
00095 {
00096 # else
00097 /* Define stlsoft::comstl_project */
00098 
00099 namespace stlsoft
00100 {
00101 
00102 namespace comstl_project
00103 {
00104 
00105 # endif /* _STLSOFT_NO_NAMESPACE */
00106 #endif /* !_COMSTL_NO_NAMESPACE */
00107 
00108 /* 
00109 
00114 
00115 /* 
00116  * Constants & definitions.
00117  */
00118 
00119 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00120 const DWORD _EOAC_SEC_DESC          =   0x0;
00121 const DWORD _EOAC_ACCESS_CONTROL    =   0x4;
00122 const DWORD _EOAC_APPID             =   0x8;
00123 const DWORD _EOAC_SECURITY_MASK     =   (   _EOAC_SEC_DESC |
00124                                             _EOAC_APPID |
00125                                             _EOAC_ACCESS_CONTROL);
00126 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00127 
00128 /* 
00129  * Functions
00130  */
00131 
00132 // function CoInitSecurity
00133 //
00134 // The three overloaded CoInitSecurity functions
00135 // provide a type-safe interface to the CoInitializeSecurity
00136 // API, discriminating between IAccessControl, AppID, and
00137 // SECURITY_DESCRIPTOR security information parameters.
00138 
00141 #ifdef __IAccessControl_INTERFACE_DEFINED__
00142 inline HRESULT CoInitSecurity(  LPUNKNOWN                   punkAccessControl,
00143                                 DWORD                       cAuthSvc,
00144                                 SOLE_AUTHENTICATION_SERVICE *asAuthSvc,
00145                                 DWORD                       dwAuthnLevel,
00146                                 DWORD                       dwImpLevel,
00147                                 RPC_AUTH_IDENTITY_HANDLE    pAuthInfo,
00148                                 DWORD                       dwCapabilities)
00149 {
00150     HRESULT         hr;
00151     IAccessControl  *pac;
00152 
00153     /* Ensure correct flag. */
00154     dwCapabilities &= ~_EOAC_SECURITY_MASK;
00155     dwCapabilities |= _EOAC_ACCESS_CONTROL;
00156 
00157     hr = punkAccessControl->QueryInterface(IID_IAccessControl, (void**)&pac);
00158 
00159     if(SUCCEEDED(hr))
00160     {
00161         hr = ::CoInitializeSecurity(pac, cAuthSvc, asAuthSvc, NULL, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities, NULL);
00162 
00163         pac->Release();
00164     }
00165 
00166     return hr;
00167 }
00168 #endif // __IAccessControl_INTERFACE_DEFINED__
00169 
00172 inline HRESULT CoInitSecurity(  const GUID                  &appid,
00173                                 DWORD                       cAuthSvc,
00174                                 SOLE_AUTHENTICATION_SERVICE *asAuthSvc,
00175                                 DWORD                       dwAuthnLevel,
00176                                 DWORD                       dwImpLevel,
00177                                 RPC_AUTH_IDENTITY_HANDLE    pAuthInfo,
00178                                 DWORD                       dwCapabilities)
00179 {
00180     /* Ensure correct flag. */
00181     dwCapabilities &= ~_EOAC_SECURITY_MASK;
00182     dwCapabilities |= _EOAC_APPID;
00183 
00184     return ::CoInitializeSecurity((LPVOID)&appid, cAuthSvc, asAuthSvc, NULL, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities, NULL);
00185 }
00186 
00189 inline HRESULT CoInitSecurity(  SECURITY_DESCRIPTOR         *psd,
00190                                 DWORD                       cAuthSvc,
00191                                 SOLE_AUTHENTICATION_SERVICE *asAuthSvc,
00192                                 DWORD                       dwAuthnLevel,
00193                                 DWORD                       dwImpLevel,
00194                                 RPC_AUTH_IDENTITY_HANDLE    pAuthInfo,
00195                                 DWORD                       dwCapabilities)
00196 {
00197     /* Ensure correct flag. */
00198     dwCapabilities &= ~_EOAC_SECURITY_MASK;
00199     dwCapabilities |= _EOAC_SEC_DESC;
00200 
00201     return ::CoInitializeSecurity(psd, cAuthSvc, asAuthSvc, NULL, dwAuthnLevel, dwImpLevel, pAuthInfo, dwCapabilities, NULL);
00202 }
00203 
00205 // Unit-testing
00206 
00207 #ifdef STLSOFT_UNITTEST
00208 
00209 namespace unittest
00210 {
00211     ss_bool_t test_comstl_security_initialisers(unittest_reporter *r)
00212     {
00213         using stlsoft::unittest::unittest_initialiser;
00214 
00215         ss_bool_t               bSuccess    =   true;
00216 
00217         unittest_initialiser    init(r, "COMSTL", "security_initialisers", __FILE__);
00218 
00219 #if 0
00220         if(<<TODO>>)
00221         {
00222             r->report("<<TODO>> failed ", __LINE__);
00223             bSuccess = false;
00224         }
00225 #endif /* 0 */
00226 
00227         return bSuccess;
00228     }
00229 
00230     unittest_registrar    unittest_comstl_security_initialisers(test_comstl_security_initialisers);
00231 
00232 } // namespace unittest
00233 
00234 #endif /* STLSOFT_UNITTEST */
00235 
00236 /* 
00237 
00239 
00240 /* 
00241 
00242 #ifndef _COMSTL_NO_NAMESPACE
00243 # if defined(_STLSOFT_NO_NAMESPACE) || \
00244      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00245 } // namespace comstl
00246 # else
00247 } // namespace stlsoft::comstl_project
00248 } // namespace stlsoft
00249 # endif /* _STLSOFT_NO_NAMESPACE */
00250 #endif /* !_COMSTL_NO_NAMESPACE */
00251 
00252 /* 
00253 
00254 #endif /* !COMSTL_INCL_H_COMSTL_SECURITY_INITIALISERS */
00255 
00256 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004