aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Util/ca/scasmbsched.cpp
blob: fefd4781ba82b835f39f1dc19ea5d1da3424ef57 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
// 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"


/********************************************************************
 Helper functions to maintain a list of file shares to create / remove

********************************************************************/
SCA_SMB* NewSmb()
{
    SCA_SMB* pss = (SCA_SMB*)MemAlloc(sizeof(SCA_SMB), TRUE);
    Assert(pss);
    return pss;
}


SCA_SMB_EX_USER_PERMS* NewExUserPermsSmb()
{
    SCA_SMB_EX_USER_PERMS* pExUserPerms = (SCA_SMB_EX_USER_PERMS*)MemAlloc(sizeof(SCA_SMB_EX_USER_PERMS), TRUE);
    Assert(pExUserPerms);
    return pExUserPerms;
}


SCA_SMB* AddSmbToList(SCA_SMB* pssList, SCA_SMB* pss)
{
    if (pssList)
    {
        SCA_SMB* pssT = pssList;
        while (pssT->pssNext)
        {
            pssT  = pssT->pssNext;
        }

        pssT->pssNext = pss;
    }
    else
    {
        pssList = pss;
    }

    return pssList;
}


SCA_SMB_EX_USER_PERMS* AddExUserPermsSmbToList(
    SCA_SMB_EX_USER_PERMS* pExUserPermsList, 
    SCA_SMB_EX_USER_PERMS* pExUserPerms
    )
{
    SCA_SMB_EX_USER_PERMS* pExUserPermsTemp = pExUserPermsList;
    if (pExUserPermsList)
    {
        while (pExUserPermsTemp->pExUserPermsNext)
        {
            pExUserPermsTemp = pExUserPermsTemp->pExUserPermsNext;
        }

        pExUserPermsTemp->pExUserPermsNext = pExUserPerms;
    }
    else
    {
        pExUserPermsList = pExUserPerms;
    }

    return pExUserPermsList;
}

void ScaSmbFreeList(SCA_SMB* pssList)
{
    SCA_SMB* pssDelete = pssList;
    while (pssList)
    {
        pssDelete = pssList;
        pssList = pssList->pssNext;

        MemFree(pssDelete);
    }
}

void ScaExUserPermsSmbFreeList(SCA_SMB_EX_USER_PERMS* pExUserPermsList)
{
    SCA_SMB_EX_USER_PERMS* pExUserPermsDelete = pExUserPermsList;
    while (pExUserPermsList)
    {
        pExUserPermsDelete = pExUserPermsList;
        pExUserPermsList = pExUserPermsList->pExUserPermsNext;

        MemFree(pExUserPermsDelete);
    }
}

// sql query constants
LPCWSTR vcsSmbQuery = L"SELECT `FileShare`, `ShareName`, `Component_`, `Description`, `Directory_` FROM `Wix4FileShare`";

enum eSmbQuery {
    ssqFileShare = 1,
    ssqShareName,
    ssqComponent,
    ssqDescription,
    ssqDirectory,
    };


/********************************************************************
 ScaSmbRead - read all of the information from the msi tables and 
              return a list of file share jobs to be done.

********************************************************************/
HRESULT ScaSmbRead(SCA_SMB** ppssList)
{
    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;
    PMSIHANDLE hView, hRec;

    LPWSTR pwzData = NULL;

    SCA_SMB* pss = NULL;
    BOOL bUserPermissionsTableExists = FALSE;

    if (S_OK != WcaTableExists(L"Wix4FileShare"))
    {
        WcaLog(LOGMSG_VERBOSE, "Skipping ScaSmbCreateShare() - Wix4FileShare table not present");
        ExitFunction1(hr = S_FALSE);
    }

    if (S_OK == WcaTableExists(L"Wix4FileSharePermissions"))
    {
        bUserPermissionsTableExists = TRUE;
    }
    else
    {
        WcaLog(LOGMSG_VERBOSE, "No Additional Permissions - Wix4FileSharePermissions table not present");
    }

    WcaLog(LOGMSG_VERBOSE, "Reading File Share Tables");

    // loop through all the fileshares
    hr = WcaOpenExecuteView(vcsSmbQuery, &hView);
    ExitOnFailure(hr, "Failed to open view on Wix4FileShare table");
    while (S_OK == (hr = WcaFetchRecord(hView, &hRec)))
    {
        pss = NewSmb();
        if (!pss)
        {
            hr = E_OUTOFMEMORY;
            break;
        }
        Assert(pss);
        ::ZeroMemory(pss, sizeof(*pss));

        hr = WcaGetRecordString(hRec, ssqFileShare, &pwzData);
        ExitOnFailure(hr, "Failed to get Wix4FileShare.FileShare");
        hr = ::StringCchCopyW(pss->wzId, countof(pss->wzId), pwzData);
        ExitOnFailure(hr, "Failed to copy ID string to smb object");

        hr = WcaGetRecordFormattedString(hRec, ssqShareName, &pwzData);
        ExitOnFailure(hr, "Failed to get Wix4FileShare.ShareName");
        hr = ::StringCchCopyW(pss->wzShareName, countof(pss->wzShareName), pwzData);
        ExitOnFailure(hr, "Failed to copy share name string to smb object");

        hr = WcaGetRecordString(hRec, ssqComponent, &pwzData);
        ExitOnFailure(hr, "Failed to get Component for Wix4FileShare: '%ls'", pss->wzShareName);
        hr = ::StringCchCopyW(pss->wzComponent, countof(pss->wzComponent), pwzData);
        ExitOnFailure(hr, "Failed to copy component string to smb object");

        hr = WcaGetRecordFormattedString(hRec, ssqDescription, &pwzData);
        ExitOnFailure(hr, "Failed to get Share Description for Wix4FileShare: '%ls'", pss->wzShareName);
        hr = ::StringCchCopyW(pss->wzDescription, countof(pss->wzDescription), pwzData);
        ExitOnFailure(hr, "Failed to copy description string to smb object");

        // get component install state
        er = ::MsiGetComponentStateW(WcaGetInstallHandle(), pss->wzComponent, &pss->isInstalled, &pss->isAction);
        hr = HRESULT_FROM_WIN32(er);
        ExitOnFailure(hr, "Failed to get Component state for Wix4FileShare");

        // get the share's directory
        hr = WcaGetRecordString(hRec, ssqDirectory, &pwzData);
        ExitOnFailure(hr, "Failed to get directory for Wix4FileShare: '%ls'", pss->wzShareName);

        WCHAR wzPath[MAX_PATH];
        DWORD dwLen;
        dwLen = countof(wzPath);
        // review: relevant for file shares?
        if (INSTALLSTATE_SOURCE == pss->isAction)
        {
            er = ::MsiGetSourcePathW(WcaGetInstallHandle(), pwzData, wzPath, &dwLen);
        }
        else
        {
            er = ::MsiGetTargetPathW(WcaGetInstallHandle(), pwzData, wzPath, &dwLen);
        }
        hr = HRESULT_FROM_WIN32(er);
        ExitOnFailure(hr, "Failed to get Source/TargetPath for Directory");

        // If the path is to the root of a drive, then it needs a trailing backslash.
        // Otherwise, it can't have a trailing backslash.
        if (3 < dwLen)
        {
            if (wzPath[dwLen - 1] == L'\\')
            {
                wzPath[dwLen - 1] = 0;
            }
        }
        else if (2 == dwLen && wzPath[1] == L':')
        {
            wzPath[2] = L'\\';
            wzPath[3] = 0;
        }

        hr = ::StringCchCopyW(pss->wzDirectory, countof(pss->wzDirectory), wzPath);
        ExitOnFailure(hr, "Failed to copy directory string to smb object");

        // Check to see if additional user & permissions are specified for this share
        if (bUserPermissionsTableExists)
        {
            hr = ScaSmbExPermsRead(pss);
            ExitOnFailure(hr, "Failed to get Additional File Share Permissions");
        }

        *ppssList = AddSmbToList(*ppssList, pss);
        pss = NULL; // set the smb NULL so it doesn't accidentally get freed below
    }

    if (E_NOMOREITEMS == hr)
    {
        hr = S_OK;
    }
    ExitOnFailure(hr, "Failure occured while processing Wix4FileShare table");

LExit:
    // if anything was left over after an error clean it all up
    if (pss)
    {
        ScaSmbFreeList(pss);
    }

    ReleaseStr(pwzData);

    return hr;
}


/********************************************************************
 RetrieveSMBShareUserPermList - retrieve SMB Share's user permission list

********************************************************************/
HRESULT RetrieveFileShareUserPerm(SCA_SMB* pss, SCA_SMB_EX_USER_PERMS** ppExUserPermsList, DWORD *pUserPermsCount)
{
    HRESULT hr = S_OK;
    SHARE_INFO_502* psi = NULL;
    NET_API_STATUS s;
    BOOL bValid, bDaclDefaulted;
    PACL acl = NULL;
    PEXPLICIT_ACCESSW pEA = NULL;
    ULONG nCount = 0;
    DWORD er = ERROR_SUCCESS;
    PSID pSID = NULL;
    DWORD nUserNameSize = MAX_DARWIN_COLUMN;
    DWORD nDomainNameSize = MAX_DARWIN_COLUMN;
    SID_NAME_USE peUse;
    DWORD dwCounter = 0;
    SCA_SMB_EX_USER_PERMS* pExUserPermsList = NULL;
    DWORD dwUserPermsCount = 0;

    *pUserPermsCount = 0;
    s = ::NetShareGetInfo(NULL, pss->wzShareName, 502, (LPBYTE*)&psi);
    WcaLog(LOGMSG_VERBOSE, "retrieving permissions on existing file share.");
    if (NERR_NetNameNotFound == s)
    {
        WcaLog(LOGMSG_VERBOSE, "File share has already been removed.");
        ExitFunction1(hr = S_OK);
    }
    else if (NERR_Success != s || psi == NULL)
    {
        hr = E_FAIL;
        ExitOnFailure(hr, "Failed to get share information with return code: %d", s);
    }
    if (!::GetSecurityDescriptorDacl(psi->shi502_security_descriptor, &bValid, &acl, &bDaclDefaulted) || !bValid)
    {
        ExitOnLastError(hr, "Failed to get acl from security descriptor");
    }

    er = ::GetExplicitEntriesFromAclW(acl, &nCount, &pEA);
    hr = HRESULT_FROM_WIN32(er);
    ExitOnFailure(hr, "Failed to get  access entries from acl for file share %ls", pss->wzShareName);
    for (dwCounter = 0; dwCounter < nCount; ++dwCounter)
    {
        if (TRUSTEE_IS_SID == pEA[dwCounter].Trustee.TrusteeForm)
        {
            SCA_SMB_EX_USER_PERMS* pExUserPerms = NewExUserPermsSmb();
            ::ZeroMemory(pExUserPerms, sizeof(*pExUserPerms));
            pExUserPermsList = AddExUserPermsSmbToList(pExUserPermsList, pExUserPerms);
            pSID = (PSID)(pEA[dwCounter].Trustee.ptstrName);
            if (!::LookupAccountSidW(NULL, pSID, pExUserPerms->scau.wzName, &nUserNameSize, pExUserPerms->scau.wzDomain, &nDomainNameSize, &peUse))
            {
                hr = E_FAIL;
                ExitOnFailure(hr, "Failed to get account name from SID");
            }
            pExUserPerms->nPermissions = pEA[dwCounter].grfAccessPermissions;
            pExUserPerms->accessMode = pEA[dwCounter].grfAccessMode;
            ++dwUserPermsCount;
            nUserNameSize = MAX_DARWIN_COLUMN;
            nDomainNameSize = MAX_DARWIN_COLUMN;
        }
    }
    *ppExUserPermsList = pExUserPermsList;
    *pUserPermsCount = dwUserPermsCount;

LExit:
    if (psi)
    {
        ::NetApiBufferFree(psi);
    }

    if (pEA)
    {
        ::LocalFree(pEA);
    }

    return hr;
}


/********************************************************************
 SchedCreateSmb - schedule one instance of a file share creation

********************************************************************/
HRESULT SchedCreateSmb(SCA_SMB* pss)
{
    HRESULT hr = S_OK;

    WCHAR wzDomainUser[255]; // "domain\user"
    SCA_SMB_EX_USER_PERMS* pExUserPermsList = NULL;
    int nCounter = 0;
    WCHAR* pwzRollbackCustomActionData = NULL;
    WCHAR* pwzCustomActionData = NULL;

    hr = WcaWriteStringToCaData(pss->wzShareName, &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "failed to add ShareName to CustomActionData");

    hr = WcaWriteStringToCaData(pss->wzShareName, &pwzCustomActionData);
    ExitOnFailure(hr, "failed to add ShareName to CustomActionData");

    hr = WcaWriteStringToCaData(pss->wzDescription, &pwzCustomActionData);
    ExitOnFailure(hr, "Failed to add server name to CustomActionData");

    hr = WcaWriteStringToCaData(pss->wzDirectory, &pwzCustomActionData);
    ExitOnFailure(hr, "Failed to add full path instance to CustomActionData");

    hr = WcaWriteStringToCaData(pss->fUseIntegratedAuth ? L"1" : L"0", &pwzCustomActionData);
    ExitOnFailure(hr, "Failed to add server name to CustomActionData");

    hr = WcaWriteIntegerToCaData(pss->nUserPermissionCount, &pwzCustomActionData);
    ExitOnFailure(hr, "Failed to add additional user permission count to CustomActionData");

    if (pss->nUserPermissionCount > 0)
    {
        nCounter = 0;
        for (pExUserPermsList = pss->pExUserPerms; pExUserPermsList; pExUserPermsList = pExUserPermsList->pExUserPermsNext)
        {
            Assert(nCounter < pss->nUserPermissionCount);

            hr = UserBuildDomainUserName(wzDomainUser, countof(wzDomainUser), pExUserPermsList->scau.wzName, pExUserPermsList->scau.wzDomain);
            ExitOnFailure(hr, "Failed to build user and domain name for CustomActionData");
            hr = WcaWriteStringToCaData(wzDomainUser, &pwzCustomActionData);
            ExitOnFailure(hr, "Failed to add server Domain\\UserName to CustomActionData");

            hr = WcaWriteIntegerToCaData((int)pExUserPermsList->accessMode, &pwzCustomActionData);
            ExitOnFailure(hr, "Failed to add access mode to CustomActionData");
            
            hr = WcaWriteIntegerToCaData(pExUserPermsList->nPermissions, &pwzCustomActionData);
            ExitOnFailure(hr, "Failed to add permissions to CustomActionData");
            ++nCounter;
        }
        Assert(nCounter == pss->nUserPermissionCount);
    }

    // Schedule the rollback first
    hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"CreateSmbRollback"), pwzRollbackCustomActionData, COST_SMB_DROPSMB);
    ExitOnFailure(hr, "Failed to schedule DropSmb action");

    hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"CreateSmb"), pwzCustomActionData, COST_SMB_CREATESMB);
    ExitOnFailure(hr, "Failed to schedule CreateSmb action");

LExit:
    ReleaseStr(pwzRollbackCustomActionData);
    ReleaseStr(pwzCustomActionData);

    if (pExUserPermsList)
    {
        ScaExUserPermsSmbFreeList(pExUserPermsList);
    }

    return hr;
}


/********************************************************************
 ScaSmbInstall - for every file share, schedule the create custom action

********************************************************************/
HRESULT ScaSmbInstall(SCA_SMB* pssList)
{
    HRESULT hr = S_FALSE; // assume nothing will be done
    SCA_SMB* pss = NULL;

    for (pss = pssList; pss; pss = pss->pssNext)
    {
        // if installing this component
        if (WcaIsInstalling(pss->isInstalled, pss->isAction) )
        {
            hr = SchedCreateSmb(pss);
            ExitOnFailure(hr, "Failed to schedule the creation of the fileshare: %ls", pss->wzShareName);
        }
    }

LExit:
    return hr;
}


/********************************************************************
 SchedDropSmb - schedule one instance of a file share removal

********************************************************************/
HRESULT SchedDropSmb(SCA_SMB* pss)
{
    HRESULT hr = S_OK;

    WCHAR* pwzCustomActionData = NULL;
    WCHAR* pwzRollbackCustomActionData = NULL;
    SCA_SMB_EX_USER_PERMS *pExUserPermsList = NULL;
    SCA_SMB_EX_USER_PERMS *pExUserPerm = NULL;
    WCHAR wzDomainUser[255]; // "domain\user"
    DWORD dwUserPermsCount = 0;
    
    // roll back DropSmb
    hr = WcaWriteStringToCaData(pss->wzShareName, &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "failed to add ShareName to CustomActionData");

    hr = WcaWriteStringToCaData(pss->wzDescription, &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "Failed to add server name to CustomActionData");

    hr = WcaWriteStringToCaData(pss->wzDirectory, &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "Failed to add full path instance to CustomActionData");

    hr = WcaWriteStringToCaData(L"1", &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "Failed to add useintegrated flag  to CustomActionData");

    hr = RetrieveFileShareUserPerm(pss, &pExUserPermsList, &dwUserPermsCount);
    ExitOnFailure(hr, "Failed to retrieve SMBShare's user permissions");

    hr = WcaWriteIntegerToCaData((int)dwUserPermsCount, &pwzRollbackCustomActionData);
    ExitOnFailure(hr, "Failed to add additional user permission count to CustomActionData");

    for (pExUserPerm = pExUserPermsList; pExUserPerm; pExUserPerm = pExUserPerm->pExUserPermsNext)
    {
        hr = UserBuildDomainUserName(wzDomainUser, countof(wzDomainUser), pExUserPerm->scau.wzName, pExUserPerm->scau.wzDomain);
        ExitOnFailure(hr, "Failed to build user and domain name for CustomActionData");
        hr = WcaWriteStringToCaData(wzDomainUser, &pwzRollbackCustomActionData);
        ExitOnFailure(hr, "Failed to add server Domain\\UserName to CustomActionData");

        hr = WcaWriteIntegerToCaData((int)pExUserPerm->accessMode, &pwzRollbackCustomActionData);
        ExitOnFailure(hr, "Failed to add access mode to CustomActionData");
        
        hr = WcaWriteIntegerToCaData(pExUserPerm->nPermissions, &pwzRollbackCustomActionData);
        ExitOnFailure(hr, "Failed to add permissions to CustomActionData");
    }

    hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"DropSmbRollback"), pwzRollbackCustomActionData, COST_SMB_CREATESMB);
    ExitOnFailure(hr, "Failed to schedule DropSmbRollback action");

    // DropSMB
    hr = WcaWriteStringToCaData(pss->wzShareName, &pwzCustomActionData);
    ExitOnFailure(hr, "failed to add ShareName to CustomActionData");

    hr = WcaDoDeferredAction(CUSTOM_ACTION_DECORATION(L"DropSmb"), pwzCustomActionData, COST_SMB_DROPSMB);
    ExitOnFailure(hr, "Failed to schedule DropSmb action");

LExit:
    ReleaseStr(pwzCustomActionData);

    if (pExUserPermsList)
    {
        ScaExUserPermsSmbFreeList(pExUserPermsList);
    }
    
    return hr;

}


/********************************************************************
 ScaSmbUninstall - for every file share, schedule the drop custom action

********************************************************************/
HRESULT ScaSmbUninstall(SCA_SMB* pssList)
{
    HRESULT hr = S_FALSE; // assume nothing will be done
    SCA_SMB* pss = NULL;

    for (pss = pssList; pss; pss = pss->pssNext)
    {
        // if uninstalling this component
        if (WcaIsUninstalling(pss->isInstalled, pss->isAction) )
        {
            hr = SchedDropSmb(pss);
            ExitOnFailure(hr, "Failed to remove file share %ls", pss->wzShareName);
        }
    }

LExit:
    return hr;
}

LPCWSTR vcsSmbExUserPermsQuery = L"SELECT `FileShare_`,`User_`,`Permissions` "
    L"FROM `Wix4FileSharePermissions` WHERE `FileShare_`=?";

enum  eSmbUserPermsQuery {
    ssupqFileShare = 1,
    ssupqUser,
    ssupqPermissions

};


/********************************************************************
 ScaSmbExPermsRead - for Every entry in File Permissions table add a 
                     User Name & Permissions structure to the List

********************************************************************/
HRESULT ScaSmbExPermsRead(SCA_SMB* pss)
{
    HRESULT hr = S_OK;
    PMSIHANDLE hView, hRec;

    LPWSTR pwzData = NULL;
    SCA_SMB_EX_USER_PERMS* pExUserPermsList = pss->pExUserPerms;
    SCA_SMB_EX_USER_PERMS* pExUserPerms = NULL;
    int nCounter = 0;

    hRec = ::MsiCreateRecord(1);
    hr = WcaSetRecordString(hRec, 1, pss->wzId);
    ExitOnFailure(hr, "Failed to look up FileShare");

    hr = WcaOpenView(vcsSmbExUserPermsQuery, &hView);
    ExitOnFailure(hr, "Failed to open view on Wix4FileSharePermissions table");
    hr = WcaExecuteView(hView, hRec);
    ExitOnFailure(hr, "Failed to execute view on Wix4FileSharePermissions table");

    // loop through all User/Permissions paris returned
    while (S_OK == (hr = WcaFetchRecord(hView, &hRec)))
    {
        pExUserPerms = NewExUserPermsSmb();
        if (!pExUserPerms)
        {
            hr = E_OUTOFMEMORY;
            break;
        }
        Assert(pExUserPerms);
        ::ZeroMemory(pExUserPerms, sizeof(*pExUserPerms));

        hr = WcaGetRecordString(hRec, ssupqUser, &pwzData);
        ExitOnFailure(hr, "Failed to get Wix4FileSharePermissions.User");
        hr = ScaGetUser(pwzData, &pExUserPerms->scau);
        ExitOnFailure(hr, "Failed to get user information for fileshare: '%ls'", pss->wzShareName);

        hr = WcaGetRecordInteger(hRec, ssupqPermissions, &pExUserPerms->nPermissions);
        ExitOnFailure(hr, "Failed to get Wix4FileSharePermissions.Permissions");
        pExUserPerms->accessMode = SET_ACCESS;  // we only support SET_ACCESS here

        pExUserPermsList = AddExUserPermsSmbToList(pExUserPermsList, pExUserPerms);
        ++nCounter;
        pExUserPerms = NULL; // set the smb NULL so it doesn't accidentally get freed below
    }

    if (E_NOMOREITEMS == hr)
    {
        hr = S_OK;
        pss->pExUserPerms = pExUserPermsList;
        pss->nUserPermissionCount = nCounter;
    }
    ExitOnFailure(hr, "Failure occured while processing FileShare table");

LExit:
    // if anything was left over after an error clean it all up
    if (pExUserPerms)
    {
        ScaExUserPermsSmbFreeList(pExUserPerms);
    }

    ReleaseStr(pwzData);

    return hr;
}