aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Iis/ca/scawebprop7.cpp
blob: b8d99b0a345e6b8e9ff4a44df26a2f6bdc3b292f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

#include "precomp.h"

HRESULT ScaWriteWebDirProperties7(
    __in_z LPCWSTR wzWebName,
    __in_z LPCWSTR wzRootOfWeb,
    __in const SCA_WEB_PROPERTIES* pswp
    )
{
    HRESULT hr = S_OK;
    WCHAR wz[METADATA_MAX_NAME_LEN + 1];

    //all go to same web/root location tag
    hr = ScaWriteConfigID(IIS_DIRPROP_BEGIN);
    ExitOnFailure(hr, "Failed to write DirProp begin id");
    hr = ScaWriteConfigString(wzWebName);                //site name key
    ExitOnFailure(hr, "Failed to write DirProp web key");
    hr = ScaWriteConfigString(wzRootOfWeb);               //app path key
    ExitOnFailure(hr, "Failed to write DirProp app key");

    // write the access permissions to the metabase
    if (MSI_NULL_INTEGER != pswp->iAccess)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_ACCESS);
        ExitOnFailure(hr, "Failed to write DirProp access id");
        hr = ScaWriteConfigInteger(pswp->iAccess);
        ExitOnFailure(hr, "Failed to write access permissions for Web");
    }

    if (MSI_NULL_INTEGER != pswp->iAuthorization)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_AUTH);
        ExitOnFailure(hr, "Failed to write DirProp auth id");
        hr = ScaWriteConfigInteger(pswp->iAuthorization);
        ExitOnFailure(hr, "Failed to write authorization for Web");
    }

    if (pswp->fHasUser)
    {
        Assert(pswp->scau.wzName);
        // write the user name
        if (*pswp->scau.wzDomain)
        {
            hr = ::StringCchPrintfW(wz, countof(wz), L"%s\\%s", pswp->scau.wzDomain, pswp->scau.wzName);
            ExitOnFailure(hr, "Failed to format domain\\username string");
        }
        else
        {
#pragma prefast(suppress:26037, "Source string is null terminated - it is populated as target of ::StringCchCopyW")
            hr = ::StringCchCopyW(wz, countof(wz), pswp->scau.wzName);
            ExitOnFailure(hr, "Failed to copy user name");
        }
        hr = ScaWriteConfigID(IIS_DIRPROP_USER);
        ExitOnFailure(hr, "Failed to write DirProp user id");
        hr = ScaWriteConfigString(wz);
        ExitOnFailure(hr, "Failed to write anonymous user name for Web");

        // write the password
        hr = ScaWriteConfigID(IIS_DIRPROP_PWD);
        ExitOnFailure(hr, "Failed to write DirProp pwd id");
        hr = ScaWriteConfigString(pswp->scau.wzPassword);
        ExitOnFailure(hr, "Failed to write anonymous user password for Web");

        if (pswp->fIIsControlledPassword)
        {
            //Not Supported by IIS7 : pswp->fIIsControlledPassword
            WcaLog(LOGMSG_VERBOSE, "Not supported by IIS7: WebDirProperties.IIsControlledPassword, ignoring");
        }
    }

    if (MSI_NULL_INTEGER != pswp->fLogVisits)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_LOGVISITS);
        ExitOnFailure(hr, "Failed to write DirProp logVisits id");
        hr = ScaWriteConfigInteger(pswp->fLogVisits ? FALSE : TRUE); // we capture "should log" but IIS7 wants "should not log"
        ExitOnFailure(hr, "Failed to write DirProp logVisits");
    }

    if (MSI_NULL_INTEGER != pswp->fIndex)
    {
        //Not Supported by IIS7 : pswp->fIndex
        WcaLog(LOGMSG_VERBOSE, "Not supported by IIS7: WebDirProperties.Index, ignoring");
    }

    if (pswp->fHasDefaultDoc)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_DEFDOCS);
        ExitOnFailure(hr, "Failed to write DirProp defdocs id");
        hr = ScaWriteConfigString(pswp->wzDefaultDoc);
        ExitOnFailure(hr, "Failed to write default documents for Web");
    }

    if (MSI_NULL_INTEGER != pswp->fAspDetailedError)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_ASPERROR);
        ExitOnFailure(hr, "Failed to write ASP script error id");
        hr = ScaWriteConfigInteger(pswp->fAspDetailedError);
        ExitOnFailure(hr, "Failed to write ASP script error for Web");
    }

    if (pswp->fHasHttpExp)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_HTTPEXPIRES);
        ExitOnFailure(hr, "Failed to write DirProp HttpExpires id");
        hr = ScaWriteConfigString(pswp->wzHttpExp);
        ExitOnFailure(hr, "Failed to write DirProp HttpExpires value");
    }

    if (MSI_NULL_INTEGER != pswp->iCacheControlMaxAge)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_MAXAGE);
        ExitOnFailure(hr, "Failed to write DirProp MaxAge id");
        hr = ScaWriteConfigInteger(pswp->iCacheControlMaxAge);
        ExitOnFailure(hr, "Failed to write DirProp MaxAge value");
    }

    if (pswp->fHasCacheControlCustom)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_CACHECUST);
        ExitOnFailure(hr, "Failed to write DirProp Cache Control Custom id");
        hr = ScaWriteConfigString(pswp->wzCacheControlCustom);
        ExitOnFailure(hr, "Failed to write Cache Control Custom for Web");
    }

    if (pswp->fNoCustomError)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_NOCUSTERROR);
        ExitOnFailure(hr, "Failed to write DirProp clear Cust Errors id");
    }

    if (MSI_NULL_INTEGER != pswp->iAccessSSLFlags)
    {
        hr = ScaWriteConfigID(IIS_DIRPROP_SSLFLAGS);
        ExitOnFailure(hr, "Failed to write DirProp sslFlags id");
        hr = ScaWriteConfigInteger(pswp->iAccessSSLFlags);
        ExitOnFailure(hr, "Failed to write AccessSSLFlags for Web");
    }

    if (*pswp->wzAuthenticationProviders)
    {
        hr = ::StringCchCopyW(wz, countof(wz), pswp->wzAuthenticationProviders);
        ExitOnFailure(hr, "Failed to copy authentication providers string");
        hr = ScaWriteConfigID(IIS_DIRPROP_AUTHPROVID);
        ExitOnFailure(hr, "Failed to write DirProp AuthProvid id");
        hr = ScaWriteConfigString(wz);
        ExitOnFailure(hr, "Failed to write AuthenticationProviders for Web");
    }
    //End of Dir Properties
    hr = ScaWriteConfigID(IIS_DIRPROP_END);
    ExitOnFailure(hr, "Failed to write DirProp end id");

LExit:
    return hr;
}