Skip to content

Commit 62d79cb

Browse files
committed
- Fix horribly broken implementation of SetupInstallServicesFromInfSectionExW, which should install a whole Services section and not a particular service.
- Simplify handling of Include and Needs directives svn path=/trunk/; revision=20283
1 parent cb0196f commit 62d79cb

File tree

2 files changed

+396
-456
lines changed

2 files changed

+396
-456
lines changed

reactos/lib/setupapi/devinst.c

Lines changed: 7 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,182 +3174,6 @@ static HKEY CreateClassKey(HINF hInf)
31743174
}
31753175

31763176

3177-
static BOOL
3178-
InstallServicesSection(
3179-
IN HINF hInf,
3180-
IN PCWSTR SectionName,
3181-
IN HDEVINFO DeviceInfoSet OPTIONAL,
3182-
IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
3183-
OUT PCWSTR* pAssociatedService OPTIONAL,
3184-
OUT PBOOL pRebootRequired OPTIONAL)
3185-
{
3186-
INFCONTEXT ContextService;
3187-
INFCONTEXT ContextInclude;
3188-
DWORD RequiredSize;
3189-
INT Flags;
3190-
BOOL ret = FALSE;
3191-
3192-
/* Parse 'Include' line */
3193-
if (SetupFindFirstLineW(hInf, SectionName, L"Include", &ContextInclude))
3194-
{
3195-
DWORD Index = 1;
3196-
while (TRUE)
3197-
{
3198-
static WCHAR szBuffer[MAX_PATH];
3199-
PWSTR pBuffer = NULL;
3200-
DWORD required;
3201-
3202-
ret = SetupGetStringFieldW(&ContextInclude, Index, szBuffer, MAX_PATH, &required);
3203-
if (!ret && GetLastError() == ERROR_INVALID_PARAMETER)
3204-
break;
3205-
else if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
3206-
{
3207-
pBuffer = MyMalloc(required);
3208-
ret = SetupGetStringFieldW(&ContextInclude, Index, pBuffer, required, &required);
3209-
}
3210-
if (ret)
3211-
ret = SetupOpenAppendInfFileW(pBuffer ? pBuffer : szBuffer, hInf, NULL);
3212-
3213-
MyFree(pBuffer);
3214-
if (!ret)
3215-
goto done;
3216-
Index++;
3217-
}
3218-
}
3219-
3220-
/* Parse 'Needs' line */
3221-
if (SetupFindFirstLineW(hInf, SectionName, L"Needs", &ContextInclude))
3222-
{
3223-
DWORD Index = 1;
3224-
while (TRUE)
3225-
{
3226-
static WCHAR szBuffer[MAX_PATH];
3227-
PWSTR pBuffer = NULL;
3228-
DWORD required;
3229-
3230-
ret = SetupGetStringFieldW(&ContextInclude, Index, szBuffer, MAX_PATH, &required);
3231-
if (!ret && GetLastError() == ERROR_INVALID_PARAMETER)
3232-
break;
3233-
else if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
3234-
{
3235-
pBuffer = MyMalloc(required);
3236-
ret = SetupGetStringFieldW(&ContextInclude, Index, pBuffer, required, &required);
3237-
}
3238-
if (ret)
3239-
{
3240-
ret = InstallServicesSection(hInf, pBuffer ? pBuffer : szBuffer,
3241-
DeviceInfoSet, DeviceInfoData, pAssociatedService, pRebootRequired);
3242-
}
3243-
3244-
MyFree(pBuffer);
3245-
if (!ret)
3246-
goto done;
3247-
Index++;
3248-
}
3249-
}
3250-
3251-
ret = SetupFindFirstLineW(hInf, SectionName, NULL, &ContextService);
3252-
while (ret)
3253-
{
3254-
LPWSTR ServiceName = NULL;
3255-
LPWSTR ServiceSection = NULL;
3256-
3257-
ret = SetupGetStringFieldW(
3258-
&ContextService,
3259-
1, /* Field index */
3260-
NULL, 0,
3261-
&RequiredSize);
3262-
if (!ret)
3263-
goto nextservice;
3264-
if (RequiredSize > 0)
3265-
{
3266-
/* We got the needed size for the buffer */
3267-
ServiceName = HeapAlloc(GetProcessHeap(), 0, RequiredSize * sizeof(WCHAR));
3268-
if (!ServiceName)
3269-
{
3270-
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3271-
goto nextservice;
3272-
}
3273-
ret = SetupGetStringFieldW(
3274-
&ContextService,
3275-
1, /* Field index */
3276-
ServiceName, RequiredSize,
3277-
&RequiredSize);
3278-
if (!ret)
3279-
goto nextservice;
3280-
}
3281-
ret = SetupGetIntField(
3282-
&ContextService,
3283-
2, /* Field index */
3284-
&Flags);
3285-
if (!ret)
3286-
{
3287-
/* The field may be empty. Ignore the error */
3288-
Flags = 0;
3289-
}
3290-
ret = SetupGetStringFieldW(
3291-
&ContextService,
3292-
3, /* Field index */
3293-
NULL, 0,
3294-
&RequiredSize);
3295-
if (!ret)
3296-
{
3297-
if (GetLastError() == ERROR_INVALID_PARAMETER)
3298-
{
3299-
/* This first is probably missing. It is not
3300-
* required, so ignore the error */
3301-
RequiredSize = 0;
3302-
ret = TRUE;
3303-
}
3304-
else
3305-
goto nextservice;
3306-
}
3307-
if (RequiredSize > 0)
3308-
{
3309-
/* We got the needed size for the buffer */
3310-
ServiceSection = HeapAlloc(GetProcessHeap(), 0, RequiredSize * sizeof(WCHAR));
3311-
if (!ServiceSection)
3312-
{
3313-
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
3314-
goto nextservice;
3315-
}
3316-
ret = SetupGetStringFieldW(
3317-
&ContextService,
3318-
3, /* Field index */
3319-
ServiceSection, RequiredSize,
3320-
&RequiredSize);
3321-
if (!ret)
3322-
goto nextservice;
3323-
3324-
SetLastError(ERROR_SUCCESS);
3325-
ret = SetupInstallServicesFromInfSectionExW(
3326-
hInf,
3327-
ServiceSection, Flags, DeviceInfoSet, DeviceInfoData, ServiceName, NULL);
3328-
}
3329-
if (ret && (Flags & SPSVCINST_ASSOCSERVICE))
3330-
{
3331-
if (pAssociatedService)
3332-
{
3333-
*pAssociatedService = ServiceName;
3334-
ServiceName = NULL;
3335-
}
3336-
if (pRebootRequired && GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED)
3337-
*pRebootRequired = TRUE;
3338-
}
3339-
nextservice:
3340-
HeapFree(GetProcessHeap(), 0, ServiceName);
3341-
HeapFree(GetProcessHeap(), 0, ServiceSection);
3342-
if (!ret)
3343-
goto done;
3344-
ret = SetupFindNextLine(&ContextService, &ContextService);
3345-
}
3346-
3347-
ret = TRUE;
3348-
3349-
done:
3350-
return ret;
3351-
}
3352-
33533177
/***********************************************************************
33543178
* SetupDiInstallClassExW (SETUPAPI.@)
33553179
*/
@@ -3451,7 +3275,7 @@ BOOL WINAPI SetupDiInstallClassExW(
34513275

34523276
/* Install .Services section */
34533277
lstrcatW(SectionName, DotServices);
3454-
ret = InstallServicesSection(hInf, SectionName, NULL, NULL, NULL, NULL);
3278+
ret = SetupInstallServicesFromInfSectionW(hInf, SectionName, 0);
34553279
if (!ret)
34563280
goto cleanup;
34573281

@@ -5585,8 +5409,6 @@ SetupDiBuildDriverInfoList(
55855409
SetLastError(ERROR_INVALID_HANDLE);
55865410
else if (DriverType != SPDIT_CLASSDRIVER && DriverType != SPDIT_COMPATDRIVER)
55875411
SetLastError(ERROR_INVALID_PARAMETER);
5588-
else if (DriverType == SPDIT_CLASSDRIVER && DeviceInfoData)
5589-
SetLastError(ERROR_INVALID_PARAMETER);
55905412
else if (DriverType == SPDIT_COMPATDRIVER && !DeviceInfoData)
55915413
SetLastError(ERROR_INVALID_PARAMETER);
55925414
else if (DeviceInfoData && DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA))
@@ -7404,7 +7226,6 @@ SetupDiInstallDevice(
74047226
BOOL Result = FALSE;
74057227
ULONG DoAction;
74067228
DWORD RequiredSize;
7407-
LPCWSTR AssociatedService = NULL;
74087229
LPWSTR pSectionName = NULL;
74097230
WCHAR ClassName[MAX_CLASS_NAME_LEN];
74107231
GUID ClassGuid;
@@ -7569,15 +7390,18 @@ SetupDiInstallDevice(
75697390

75707391
/* Install .Services section */
75717392
wcscpy(pSectionName, DotServices);
7572-
Result = InstallServicesSection(
7393+
Result = SetupInstallServicesFromInfSectionExW(
75737394
SelectedDriver->InfFileDetails->hInf,
75747395
SectionName,
7396+
0,
75757397
DeviceInfoSet,
75767398
DeviceInfoData,
7577-
&AssociatedService,
7578-
&RebootRequired);
7399+
NULL,
7400+
NULL);
75797401
if (!Result)
75807402
goto cleanup;
7403+
if (GetLastError() == ERROR_SUCCESS_REBOOT_REQUIRED)
7404+
RebootRequired = TRUE;
75817405

75827406
/* Copy .inf file to Inf\ directory (if needed) */
75837407
Result = InfIsFromOEMLocation(SelectedDriver->InfFileDetails->FullInfFileName, &NeedtoCopyFile);
@@ -7620,16 +7444,13 @@ SetupDiInstallDevice(
76207444
TRACE("ClassGUID : '%S'\n", lpFullGuidString);
76217445
TRACE("DeviceDesc : '%S'\n", SelectedDriver->Info.Description);
76227446
TRACE("Mfg : '%S'\n", SelectedDriver->Info.MfgName);
7623-
TRACE("Service : '%S'\n", AssociatedService);
76247447
rc = RegSetValueEx(hKey, REGSTR_VAL_CLASS, 0, REG_SZ, (const BYTE *)ClassName, (wcslen(ClassName) + 1) * sizeof(WCHAR));
76257448
if (rc == ERROR_SUCCESS)
76267449
rc = RegSetValueEx(hKey, REGSTR_VAL_CLASSGUID, 0, REG_SZ, (const BYTE *)lpFullGuidString, (wcslen(lpFullGuidString) + 1) * sizeof(WCHAR));
76277450
if (rc == ERROR_SUCCESS)
76287451
rc = RegSetValueEx(hKey, REGSTR_VAL_DEVDESC, 0, REG_SZ, (const BYTE *)SelectedDriver->Info.Description, (wcslen(SelectedDriver->Info.Description) + 1) * sizeof(WCHAR));
76297452
if (rc == ERROR_SUCCESS)
76307453
rc = RegSetValueEx(hKey, REGSTR_VAL_MFG, 0, REG_SZ, (const BYTE *)SelectedDriver->Info.MfgName, (wcslen(SelectedDriver->Info.MfgName) + 1) * sizeof(WCHAR));
7631-
if (rc == ERROR_SUCCESS && AssociatedService && *AssociatedService)
7632-
rc = RegSetValueEx(hKey, REGSTR_VAL_SERVICE, 0, REG_SZ, (const BYTE *)AssociatedService, (wcslen(AssociatedService) + 1) * sizeof(WCHAR));
76337454
if (rc != ERROR_SUCCESS)
76347455
{
76357456
SetLastError(rc);
@@ -7650,7 +7471,6 @@ SetupDiInstallDevice(
76507471
RegCloseKey(hKey);
76517472
if (lpGuidString)
76527473
RpcStringFreeW(&lpGuidString);
7653-
HeapFree(GetProcessHeap(), 0, (LPWSTR)AssociatedService);
76547474
HeapFree(GetProcessHeap(), 0, lpFullGuidString);
76557475

76567476
TRACE("Returning %d\n", ret);

0 commit comments

Comments
 (0)