ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

main.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2008 Juan Lang
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "config.h"
00020 #include <stdarg.h>
00021 #include "windef.h"
00022 #include "winbase.h"
00023 #include "wincrypt.h"
00024 #include "mssip.h"
00025 #define COBJMACROS
00026 #include "objbase.h"
00027 #include "initguid.h"
00028 #include "wine/debug.h"
00029 
00030 WINE_DEFAULT_DEBUG_CHANNEL(msisip);
00031 
00032 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
00033 {
00034     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
00035 
00036     switch (fdwReason)
00037     {
00038         case DLL_WINE_PREATTACH:
00039             return FALSE;    /* prefer native version */
00040         case DLL_PROCESS_ATTACH:
00041             DisableThreadLibraryCalls(hinstDLL);
00042             break;
00043         case DLL_PROCESS_DETACH:
00044             break;
00045         default:
00046             break;
00047     }
00048 
00049     return TRUE;
00050 }
00051 
00052 static GUID mySubject = { 0x000c10f1, 0x0000, 0x0000,
00053  { 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
00054 
00055 /***********************************************************************
00056  *              DllRegisterServer (MSISIP.@)
00057  */
00058 HRESULT WINAPI DllRegisterServer(void)
00059 {
00060     static WCHAR msisip[] = { 'M','S','I','S','I','P','.','D','L','L',0 };
00061     static WCHAR getSignedDataMsg[] = { 'M','s','i','S','I','P','G','e','t',
00062      'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
00063     static WCHAR putSignedDataMsg[] = { 'M','s','i','S','I','P','P','u','t',
00064      'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
00065     static WCHAR createIndirectData[] = { 'M','s','i','S','I','P',
00066      'C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a',
00067      0 };
00068     static WCHAR verifyIndirectData[] = { 'M','s','i','S','I','P',
00069      'V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a',
00070      0 };
00071     static WCHAR removeSignedDataMsg[] = { 'M','s','i','S','I','P','R','e','m',
00072      'o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0 };
00073     static WCHAR isMyTypeOfFile[] = { 'M','s','i','S','I','P',
00074      'I','s','M','y','T','y','p','e','O','f','F','i','l','e',0 };
00075 
00076     SIP_ADD_NEWPROVIDER prov;
00077 
00078     memset(&prov, 0, sizeof(prov));
00079     prov.cbStruct = sizeof(prov);
00080     prov.pwszDLLFileName = msisip;
00081     prov.pgSubject = &mySubject;
00082     prov.pwszGetFuncName = getSignedDataMsg;
00083     prov.pwszPutFuncName = putSignedDataMsg;
00084     prov.pwszCreateFuncName = createIndirectData;
00085     prov.pwszVerifyFuncName = verifyIndirectData;
00086     prov.pwszRemoveFuncName = removeSignedDataMsg;
00087     prov.pwszIsFunctionNameFmt2 = isMyTypeOfFile;
00088     return CryptSIPAddProvider(&prov) ? S_OK : S_FALSE;
00089 }
00090 
00091 /***********************************************************************
00092  *              DllUnregisterServer (MSISIP.@)
00093  */
00094 HRESULT WINAPI DllUnregisterServer(void)
00095 {
00096     CryptSIPRemoveProvider(&mySubject);
00097     return S_OK;
00098 }
00099 
00100 /***********************************************************************
00101  *              MsiSIPGetSignedDataMsg  (MSISIP.@)
00102  */
00103 BOOL WINAPI MsiSIPGetSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo,
00104  DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg,
00105  BYTE *pbSignedDataMsg)
00106 {
00107     static const WCHAR digitalSig[] = { 5,'D','i','g','i','t','a','l',
00108      'S','i','g','n','a','t','u','r','e',0 };
00109     BOOL ret = FALSE;
00110     IStorage *stg = NULL;
00111     HRESULT r;
00112     IStream *stm = NULL;
00113     BYTE hdr[2], len[sizeof(DWORD)];
00114     DWORD count, lenBytes, dataBytes;
00115 
00116     TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
00117           pcbSignedDataMsg, pbSignedDataMsg);
00118 
00119     r = StgOpenStorage(pSubjectInfo->pwsFileName, NULL,
00120      STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
00121     if (FAILED(r))
00122     {
00123         TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo->pwsFileName));
00124         goto end;
00125     }
00126 
00127     r = IStorage_OpenStream(stg, digitalSig, 0,
00128      STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &stm);
00129     if (FAILED(r))
00130     {
00131         TRACE("couldn't find digital signature stream\n");
00132         goto freestorage;
00133     }
00134 
00135     r = IStream_Read(stm, hdr, sizeof(hdr), &count);
00136     if (FAILED(r) || count != sizeof(hdr))
00137         goto freestream;
00138     if (hdr[0] != 0x30)
00139     {
00140         WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr[0], hdr[1]);
00141         goto freestream;
00142     }
00143 
00144     /* Read the asn.1 length from the stream.  Only supports definite-length
00145      * values, which DER-encoded signatures should be.
00146      */
00147     if (hdr[1] == 0x80)
00148     {
00149         WARN("indefinite-length encoding not supported!\n");
00150         goto freestream;
00151     }
00152     else if (hdr[1] & 0x80)
00153     {
00154         DWORD temp;
00155         LPBYTE ptr;
00156 
00157         lenBytes = hdr[1] & 0x7f;
00158         if (lenBytes > sizeof(DWORD))
00159         {
00160             WARN("asn.1 length too long (%d)\n", lenBytes);
00161             goto freestream;
00162         }
00163         r = IStream_Read(stm, len, lenBytes, &count);
00164         if (FAILED(r) || count != lenBytes)
00165             goto freestream;
00166         dataBytes = 0;
00167         temp = lenBytes;
00168         ptr = len;
00169         while (temp--)
00170         {
00171             dataBytes <<= 8;
00172             dataBytes |= *ptr++;
00173         }
00174     }
00175     else
00176     {
00177         lenBytes = 0;
00178         dataBytes = hdr[1];
00179     }
00180 
00181     if (!pbSignedDataMsg)
00182     {
00183         *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
00184         ret = TRUE;
00185     }
00186     else if (*pcbSignedDataMsg < 2 + lenBytes + dataBytes)
00187     {
00188         SetLastError(ERROR_INSUFFICIENT_BUFFER);
00189         *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
00190     }
00191     else
00192     {
00193         LPBYTE ptr = pbSignedDataMsg;
00194 
00195         memcpy(ptr, hdr, sizeof(hdr));
00196         ptr += sizeof(hdr);
00197         if (lenBytes)
00198         {
00199             memcpy(ptr, len, lenBytes);
00200             ptr += lenBytes;
00201         }
00202         r = IStream_Read(stm, ptr, dataBytes, &count);
00203         if (SUCCEEDED(r) && count == dataBytes)
00204         {
00205             *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
00206             *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
00207             ret = TRUE;
00208         }
00209     }
00210 
00211 freestream:
00212     IStream_Release(stm);
00213 freestorage:
00214     IStorage_Release(stg);
00215 end:
00216 
00217     TRACE("returning %d\n", ret);
00218     return ret;
00219 }
00220 
00221 DEFINE_GUID(CLSID_MsiTransform, 0x000c1082,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
00222 DEFINE_GUID(CLSID_MsiDatabase,  0x000c1084,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
00223 DEFINE_GUID(CLSID_MsiPatch,     0x000c1086,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
00224 
00225 /***********************************************************************
00226  *              MsiSIPIsMyTypeOfFile (MSISIP.@)
00227  */
00228 BOOL WINAPI MsiSIPIsMyTypeOfFile(WCHAR *name, GUID *subject)
00229 {
00230     BOOL ret = FALSE;
00231     IStorage *stg = NULL;
00232     HRESULT r;
00233 
00234     TRACE("(%s, %p)\n", debugstr_w(name), subject);
00235 
00236     r = StgOpenStorage(name, NULL, STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE,
00237      NULL, 0, &stg);
00238     if (SUCCEEDED(r))
00239     {
00240         STATSTG stat;
00241 
00242         r = IStorage_Stat(stg, &stat, STATFLAG_NONAME);
00243         if (SUCCEEDED(r))
00244         {
00245             if (IsEqualGUID(&stat.clsid, &CLSID_MsiDatabase) ||
00246              IsEqualGUID(&stat.clsid, &CLSID_MsiPatch) ||
00247              IsEqualGUID(&stat.clsid, &CLSID_MsiTransform))
00248             {
00249                 ret = TRUE;
00250                 *subject = mySubject;
00251             }
00252         }
00253         IStorage_Release(stg);
00254     }
00255     return ret;
00256 }

Generated on Sun May 27 2012 04:16:43 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.