HRESULT ScaSslCertificateWrite7( __in_z LPCWSTR wzWebBase, __in SCA_WEB_SSL_CERTIFICATE* pswscList ) { HRESULT hr = S_OK; WCHAR wzEncodedCertificateHash[CB_CERTIFICATE_HASH * 2 + 1] = { 0 }; for (SCA_WEB_SSL_CERTIFICATE* pswsc = pswscList; pswsc; pswsc = pswsc->pNext) { hr = ScaWriteConfigID(IIS_SSL_BINDING); ExitOnFailure(hr, "Failed write SSL binding ID"); hr = ScaWriteConfigID(IIS_CREATE); // Need to determine site action ExitOnFailure(hr, "Failed write binding action"); hr = ScaWriteConfigString(wzWebBase); //site name key ExitOnFailure(hr, "Failed to write SSL website"); hr = ScaWriteConfigString(pswsc->wzStoreName); //ssl store name ExitOnFailure(hr, "Failed to write SSL store name"); hr = StrHexEncode(pswsc->rgbSHA1Hash, countof(pswsc->rgbSHA1Hash), wzEncodedCertificateHash, countof(wzEncodedCertificateHash)); ExitOnFailure(hr, "Failed to encode SSL hash"); hr = ScaWriteConfigString(wzEncodedCertificateHash); //ssl hash ExitOnFailure(hr, "Failed to write SSL hash"); } LExit: return hr; }
static HRESULT WriteFilter(const SCA_FILTER* psf) { HRESULT hr = S_OK; hr = ScaWriteConfigID(IIS_FILTER); ExitOnFailure(hr, "Failed to write filter begin ID"); hr = ScaWriteConfigID(IIS_CREATE); ExitOnFailure(hr, "Failed to write filter create ID"); //filter Name key hr = ScaWriteConfigString(psf->wzKey); ExitOnFailure1(hr, "Failed to write key name for filter '%ls'", psf->wzKey); //web site name hr = ScaWriteConfigString(psf->wzFilterRoot); ExitOnFailure(hr, "Failed to write filter web root "); // filter path hr = ScaWriteConfigString(psf->wzPath); ExitOnFailure1(hr, "Failed to write Path for filter '%ls'", psf->wzKey); //filter load order hr = ScaWriteConfigInteger(psf->iLoadOrder); ExitOnFailure1(hr, "Failed to write load order for filter '%ls'", psf->wzKey); LExit: return hr; }
HRESULT ScaWriteWebError7( __in_z LPCWSTR wzWebName, __in_z LPCWSTR wzRoot, SCA_WEB_ERROR* psweList ) { HRESULT hr = S_OK; hr = ScaWriteConfigID(IIS_WEBERROR_BEGIN); ExitOnFailure(hr, "Fail to write webError begin ID"); hr = ScaWriteConfigString(wzWebName); ExitOnFailure(hr, "Fail to write webError Web Key"); hr = ScaWriteConfigString(wzRoot); ExitOnFailure(hr, "Fail to write webError Vdir key"); // Loop through the HTTP headers for (SCA_WEB_ERROR* pswe = psweList; pswe; pswe = pswe->psweNext) { hr = ScaWriteConfigID(IIS_WEBERROR); ExitOnFailure(hr, "Fail to write webError ID"); hr = ScaWriteConfigInteger(pswe->iErrorCode); ExitOnFailure(hr, "Fail to write webError code"); hr = ScaWriteConfigInteger(pswe->iSubCode); ExitOnFailure(hr, "Fail to write webError subcode"); //just write one if (*(pswe->wzFile)) { hr = ScaWriteConfigString(pswe->wzFile); ExitOnFailure(hr, "Fail to write webError file"); hr = ScaWriteConfigInteger(0); ExitOnFailure(hr, "Fail to write webError file code"); } else if (*(pswe->wzURL)) { hr = ScaWriteConfigString(pswe->wzURL); ExitOnFailure(hr, "Fail to write webError URL"); hr = ScaWriteConfigInteger(1); ExitOnFailure(hr, "Fail to write webError URL code"); } } hr = ScaWriteConfigID(IIS_WEBERROR_END); ExitOnFailure(hr, "Fail to write httpHeader end ID"); LExit: return hr; }
// prototypes HRESULT ScaWriteMimeMap7( __in_z LPCWSTR wzWebName, __in_z LPCWSTR wzRootOfWeb, SCA_MIMEMAP* psmmList ) { HRESULT hr = S_OK; SCA_MIMEMAP* psmm; //create the mimemap list for this vdir application //all go to same web/root location tag hr = ScaWriteConfigID(IIS_MIMEMAP_BEGIN); ExitOnFailure(hr, "Failed to write mimemap begin id"); hr = ScaWriteConfigString(wzWebName); //site name key ExitOnFailure(hr, "Failed to write mimemap web key"); hr = ScaWriteConfigString(wzRootOfWeb); //app path key ExitOnFailure(hr, "Failed to write mimemap app key"); psmm = psmmList; while (psmm) { //create the Extension for this vdir application hr = ScaWriteConfigID(IIS_MIMEMAP); ExitOnFailure(hr, "Failed to write mimemap id"); if (*psmm->wzExtension) { hr = ScaWriteConfigString(psmm->wzExtension); } else // blank means "*" (all) { hr = ScaWriteConfigString(L"*"); } ExitOnFailure(hr, "Failed to write mimemap extension"); hr = ScaWriteConfigString(psmm->wzMimeType); ExitOnFailure(hr, "Failed to write mimemap type"); psmm = psmm->psmmNext; } hr = ScaWriteConfigID(IIS_MIMEMAP_END); ExitOnFailure(hr, "Failed to write mimemap end id"); LExit: return hr; }
/* **************************************************************** * ScaWriteWebLog -Writes the IIS log values to the metabase. * * ****************************************************************/ HRESULT ScaWriteWebLog7( LPCWSTR wzWebBase, const SCA_WEB_LOG *pswl ) { HRESULT hr = S_OK; if (*pswl->wzFormat) { //write pswl->wzFormat hr = ScaWriteConfigID(IIS_WEBLOG); ExitOnFailure(hr, "Failed to write log format id"); hr = ScaWriteConfigString(wzWebBase); ExitOnFailure(hr, "Failed to write log web key"); hr = ScaWriteConfigString(pswl->wzFormat); ExitOnFailure(hr, "Failed to write log format string"); } LExit: return hr; }
HRESULT ScaVirtualDirsUninstall7( __in SCA_VDIR7* psvdList ) { HRESULT hr = S_OK; SCA_VDIR7* psvd = psvdList; LPWSTR wzPath = NULL; while (psvd) { if (WcaIsUninstalling(psvd->isInstalled, psvd->isAction)) { //init path hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); ExitOnFailure(hr, "Failed to create vdir path"); if (psvd->fHasApplication) { //delete Application hr = ScaWriteConfigID(IIS_APPLICATION); ExitOnFailure(hr, "Failed to write app ID "); hr = ScaWriteConfigID(IIS_DELETE); ExitOnFailure(hr, "Failed to write delete app ID "); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed to write App site Name"); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(wzPath); // App Path ExitOnFailure(hr, "Failed to write app path root "); hr = ScaWriteConfigString(L"NOP"); // App pool ExitOnFailure(hr, "Failed to write app path app pool "); } else { //delete VDir hr = ScaWriteConfigID(IIS_VDIR); ExitOnFailure(hr, "Failed to write vDir ID "); hr = ScaWriteConfigID(IIS_DELETE); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed to write App site Name"); hr = ScaWriteConfigString(wzPath); // Vdir Path ExitOnFailure(hr, "Failed to write app vdir "); hr = ScaWriteConfigString(L"NOP"); // Phy Path ExitOnFailure(hr, "Failed to write vdir path"); } ExitOnFailure(hr, "Failed to remove VirtualDir '%ls' from config", psvd->wzKey); } psvd = psvd->psvdNext; } LExit: ReleaseStr(wzPath); return hr; }
HRESULT ScaWriteHttpHeader7( __in_z LPCWSTR wzWebName, __in_z LPCWSTR wzRoot, SCA_HTTP_HEADER* pshhList ) { HRESULT hr = S_OK; DWORD cchData = 0; hr = ScaWriteConfigID(IIS_HTTP_HEADER_BEGIN); ExitOnFailure(hr, "Fail to write httpHeader begin ID"); hr = ScaWriteConfigString(wzWebName); ExitOnFailure(hr, "Fail to write httpHeader Web Key"); hr = ScaWriteConfigString(wzRoot); ExitOnFailure(hr, "Fail to write httpHeader Vdir key"); // Loop through the HTTP headers for (SCA_HTTP_HEADER* pshh = pshhList; pshh; pshh = pshh->pshhNext) { hr = ScaWriteConfigID(IIS_HTTP_HEADER); ExitOnFailure(hr, "Fail to write httpHeader ID"); hr = ScaWriteConfigString(pshh->wzName); ExitOnFailure(hr, "Fail to write httpHeader name"); hr = ScaWriteConfigString(pshh->wzValue); ExitOnFailure(hr, "Fail to write httpHeader value"); } hr = ScaWriteConfigID(IIS_HTTP_HEADER_END); ExitOnFailure(hr, "Fail to write httpHeader end ID"); LExit: return hr; }
HRESULT ScaWebAppExtensionsWrite7( __in_z LPCWSTR wzWebName, __in_z LPCWSTR wzRootOfWeb, __in SCA_WEB_APPLICATION_EXTENSION* pswappextList ) { HRESULT hr = S_OK; SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL; if (!pswappextList) { ExitFunction1(hr = S_OK); } //create the Extension for this vdir application //all go to same web/root location tag hr = ScaWriteConfigID(IIS_APPEXT_BEGIN); ExitOnFailure(hr, "Failed to write webappext begin id"); hr = ScaWriteConfigString(wzWebName); //site name key ExitOnFailure(hr, "Failed to write app web key"); hr = ScaWriteConfigString(wzRootOfWeb); //app path key ExitOnFailure(hr, "Failed to write app web key"); pswappext = pswappextList; while (pswappext) { //create the Extension for this vdir application hr = ScaWriteConfigID(IIS_APPEXT); ExitOnFailure(hr, "Failed to write webappext begin id"); if (*pswappext->wzExtension) { hr = ScaWriteConfigString(pswappext->wzExtension); } else // blank means "*" (all) { hr = ScaWriteConfigString(L"*"); } ExitOnFailure(hr, "Failed to write extension"); hr = ScaWriteConfigString(pswappext->wzExecutable); ExitOnFailure(hr, "Failed to write extension executable"); hr = ScaWriteConfigString(pswappext->wzVerbs); ExitOnFailure(hr, "Failed to write extension verbs"); pswappext = pswappext->pswappextNext; } hr = ScaWriteConfigID(IIS_APPEXT_END); ExitOnFailure(hr, "Failed to write webappext begin id"); LExit: return hr; }
HRESULT ScaVirtualDirsInstall7( __in SCA_VDIR7* psvdList, __in SCA_APPPOOL * psapList ) { HRESULT hr = S_OK; SCA_VDIR7* psvd = psvdList; LPWSTR wzPath = NULL; WCHAR wzAppPoolName[MAX_PATH]; while (psvd) { if (WcaIsInstalling(psvd->isInstalled, psvd->isAction)) { // First write all applications, this is necessary since vdirs must be nested under the applications. if (psvd->fHasApplication) { //create the application for this vdir application hr = ScaWriteConfigID(IIS_APPLICATION); ExitOnFailure(hr, "Failed to write app ID"); hr = ScaWriteConfigID(IIS_CREATE); ExitOnFailure(hr, "Failed to write app action"); #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed to write app web key"); hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); ExitOnFailure(hr, "Failed to create app path"); hr = ScaWriteConfigString(wzPath); // App Path ExitOnFailure(hr, "Failed to write app path root "); if (!*psvd->swapp.wzAppPool) { //This Application goes in default appPool hr = ScaWriteConfigString(L""); // App Pool } else { //get apppool from WebApplication #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaFindAppPool7(psvd->swapp.wzAppPool, wzAppPoolName, countof(wzAppPoolName), psapList); ExitOnFailure(hr, "Failed to read app pool from application"); hr = ScaWriteConfigString(wzAppPoolName); // App Pool ExitOnFailure(hr, "Failed to write appPool for vdir"); } } } psvd = psvd->psvdNext; } // Reset our linked list and write all the VDirs psvd = psvdList; while (psvd) { if (WcaIsInstalling(psvd->isInstalled, psvd->isAction)) { //create the Vdir hr = ScaWriteConfigID(IIS_VDIR); ExitOnFailure(hr, "Failed write VirDir ID") hr = ScaWriteConfigID(IIS_CREATE); ExitOnFailure(hr, "Failed write VirDir action") #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzWebName); //site name key ExitOnFailure(hr, "Failed write VirDir web name"); hr = StrAllocFormatted(&wzPath, L"/%s", psvd->wzVDirRoot); ExitOnFailure(hr, "Failed to create vdir path"); hr = ScaWriteConfigString(wzPath); //vdir path ExitOnFailure(hr, "Failed write VirDir path") #pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW") hr = ScaWriteConfigString(psvd->wzDirectory); //physical dir ExitOnFailure(hr, "Failed write VirDir dir"); if (psvd->fHasProperties) { ScaWriteWebDirProperties7(psvd->wzWebName, psvd->wzVDirRoot, &psvd->swp); ExitOnFailure(hr, "Failed to write directory properties for VirtualDir"); } if (psvd->fHasApplication) { hr = ScaWriteWebApplication7(psvd->wzWebName, psvd->wzVDirRoot, &psvd->swapp, psapList); ExitOnFailure(hr, "Failed to write application for VirtualDir"); } if (psvd->psmm) { hr = ScaWriteMimeMap7(psvd->wzWebName, psvd->wzVDirRoot, psvd->psmm); ExitOnFailure(hr, "Failed to write mimemap for VirtualDir"); } if (psvd->pshh) { hr = ScaWriteHttpHeader7(psvd->wzWebName, psvd->wzVDirRoot, psvd->pshh); ExitOnFailure(hr, "Failed to write custom HTTP headers for VirtualDir"); } if (psvd->pswe) { hr = ScaWriteWebError7(psvd->wzWebName, psvd->wzVDirRoot, psvd->pswe); ExitOnFailure(hr, "Failed to write custom web errors for VirtualDir"); } } psvd = psvd->psvdNext; } LExit: ReleaseStr(wzPath); return hr; }
HRESULT ScaFiltersUninstall7( __in SCA_FILTER* psfList ) { HRESULT hr = S_OK; SCA_FILTER* psf = psfList; if (!psf) { ExitFunction1(hr = S_OK); } //Uninstall global filters hr = ScaWriteConfigID(IIS_FILTER_GLOBAL_BEGIN); ExitOnFailure(hr, "Failed to write filter begin ID"); while (psf) { if (WcaIsUninstalling(psf->isInstalled, psf->isAction)) { if (0 == wcscmp(psf->wzFilterRoot, L"/")) { hr = ScaWriteConfigID(IIS_FILTER); ExitOnFailure(hr, "Failed to write filter begin ID"); hr = ScaWriteConfigID(IIS_DELETE); ExitOnFailure(hr, "Failed to write filter create ID"); //filter Name key hr = ScaWriteConfigString(psf->wzKey); ExitOnFailure1(hr, "Failed to write key name for filter '%ls'", psf->wzKey); //web site name hr = ScaWriteConfigString(psf->wzFilterRoot); ExitOnFailure(hr, "Failed to write filter web root "); } } psf = psf->psfNext; } hr = ScaWriteConfigID(IIS_FILTER_END); ExitOnFailure(hr, "Failed to write filter ID"); psf = psfList; //Uninstall website filters hr = ScaWriteConfigID(IIS_FILTER_BEGIN); ExitOnFailure(hr, "Failed to write filter begin ID"); while (psf) { if (WcaIsUninstalling(psf->isInstalled, psf->isAction)) { if (0 != wcscmp(psf->wzFilterRoot, L"/")) { hr = ScaWriteConfigID(IIS_FILTER); ExitOnFailure(hr, "Failed to write filter begin ID"); hr = ScaWriteConfigID(IIS_DELETE); ExitOnFailure(hr, "Failed to write filter create ID"); //filter Name key hr = ScaWriteConfigString(psf->wzKey); ExitOnFailure1(hr, "Failed to write key name for filter '%ls'", psf->wzKey); //web site name hr = ScaWriteConfigString(psf->wzFilterRoot); ExitOnFailure(hr, "Failed to write filter web root "); } } psf = psf->psfNext; } hr = ScaWriteConfigID(IIS_FILTER_END); ExitOnFailure(hr, "Failed to write filter ID"); LExit: return hr; }