Reactos

[SETUPAPI] Refactor `SetupInstallServicesFromInfSectionExW` (#7770)

Fix `SetupInstallServicesFromInfSectionEx`.

- Call SetupDiSetDeviceRegistryPropertyW only if DeviceInfoSet is valid
- DeviceInfoSet can be INVALID_HANDLE_VALUE, treat this as NULL
- Improve function declaration

authored by

Ratin Gao and committed by
GitHub
49a55a09 7a9c744b

+106 -39
+106 -39
dll/win32/setupapi/install.c
··· 1612 1612 /*********************************************************************** 1613 1613 * SetupInstallServicesFromInfSectionW (SETUPAPI.@) 1614 1614 */ 1615 - BOOL WINAPI SetupInstallServicesFromInfSectionW( HINF Inf, PCWSTR SectionName, DWORD Flags) 1615 + BOOL 1616 + WINAPI 1617 + SetupInstallServicesFromInfSectionW( 1618 + _In_ HINF InfHandle, 1619 + _In_ PCWSTR SectionName, 1620 + _In_ DWORD Flags) 1616 1621 { 1617 - return SetupInstallServicesFromInfSectionExW( Inf, SectionName, Flags, 1618 - NULL, NULL, NULL, NULL ); 1622 + return SetupInstallServicesFromInfSectionExW(InfHandle, 1623 + SectionName, 1624 + Flags, 1625 + INVALID_HANDLE_VALUE, 1626 + NULL, 1627 + NULL, 1628 + NULL); 1619 1629 } 1620 1630 1621 1631 /*********************************************************************** 1622 1632 * SetupInstallServicesFromInfSectionA (SETUPAPI.@) 1623 1633 */ 1624 - BOOL WINAPI SetupInstallServicesFromInfSectionA( HINF Inf, PCSTR SectionName, DWORD Flags) 1634 + BOOL 1635 + WINAPI 1636 + SetupInstallServicesFromInfSectionA( 1637 + _In_ HINF InfHandle, 1638 + _In_ PCSTR SectionName, 1639 + _In_ DWORD Flags) 1625 1640 { 1626 - return SetupInstallServicesFromInfSectionExA( Inf, SectionName, Flags, 1627 - NULL, NULL, NULL, NULL ); 1641 + return SetupInstallServicesFromInfSectionExA(InfHandle, 1642 + SectionName, 1643 + Flags, 1644 + INVALID_HANDLE_VALUE, 1645 + NULL, 1646 + NULL, 1647 + NULL); 1628 1648 } 1629 1649 1630 1650 /*********************************************************************** 1631 1651 * SetupInstallServicesFromInfSectionExA (SETUPAPI.@) 1632 1652 */ 1633 - BOOL WINAPI SetupInstallServicesFromInfSectionExA( HINF hinf, PCSTR sectionname, DWORD flags, HDEVINFO devinfo, PSP_DEVINFO_DATA devinfo_data, PVOID reserved1, PVOID reserved2 ) 1653 + BOOL 1654 + WINAPI 1655 + SetupInstallServicesFromInfSectionExA( 1656 + _In_ HINF InfHandle, 1657 + _In_ PCSTR SectionName, 1658 + _In_ DWORD Flags, 1659 + _In_opt_ HDEVINFO DeviceInfoSet, 1660 + _In_opt_ PSP_DEVINFO_DATA DeviceInfoData, 1661 + _Reserved_ PVOID Reserved1, 1662 + _Reserved_ PVOID Reserved2) 1634 1663 { 1635 - UNICODE_STRING sectionnameW; 1636 - BOOL ret = FALSE; 1664 + UNICODE_STRING SectionNameW; 1665 + BOOL ret; 1637 1666 1638 - if (RtlCreateUnicodeStringFromAsciiz( &sectionnameW, sectionname )) 1667 + if (!RtlCreateUnicodeStringFromAsciiz(&SectionNameW, SectionName)) 1639 1668 { 1640 - ret = SetupInstallServicesFromInfSectionExW( hinf, sectionnameW.Buffer, flags, devinfo, devinfo_data, reserved1, reserved2 ); 1641 - RtlFreeUnicodeString( &sectionnameW ); 1669 + SetLastError(ERROR_NOT_ENOUGH_MEMORY); 1670 + return FALSE; 1642 1671 } 1643 - else 1644 - SetLastError( ERROR_NOT_ENOUGH_MEMORY ); 1645 1672 1673 + ret = SetupInstallServicesFromInfSectionExW(InfHandle, 1674 + SectionNameW.Buffer, 1675 + Flags, 1676 + DeviceInfoSet, 1677 + DeviceInfoData, 1678 + Reserved1, 1679 + Reserved2); 1680 + RtlFreeUnicodeString(&SectionNameW); 1646 1681 return ret; 1647 1682 } 1648 1683 ··· 2078 2113 /*********************************************************************** 2079 2114 * SetupInstallServicesFromInfSectionExW (SETUPAPI.@) 2080 2115 */ 2081 - BOOL WINAPI SetupInstallServicesFromInfSectionExW( HINF hinf, PCWSTR sectionname, DWORD flags, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PVOID reserved1, PVOID reserved2 ) 2116 + BOOL 2117 + WINAPI 2118 + SetupInstallServicesFromInfSectionExW( 2119 + _In_ HINF InfHandle, 2120 + _In_ PCWSTR SectionName, 2121 + _In_ DWORD Flags, 2122 + _In_opt_ HDEVINFO DeviceInfoSet, 2123 + _In_opt_ PSP_DEVINFO_DATA DeviceInfoData, 2124 + _Reserved_ PVOID Reserved1, 2125 + _Reserved_ PVOID Reserved2) 2082 2126 { 2083 - struct DeviceInfoSet *list = NULL; 2127 + struct DeviceInfoSet *list; 2084 2128 BOOL ret = FALSE; 2085 2129 2086 - TRACE("%p, %s, 0x%lx, %p, %p, %p, %p\n", hinf, debugstr_w(sectionname), 2087 - flags, DeviceInfoSet, DeviceInfoData, reserved1, reserved2); 2130 + /* FIXME: SPSVCINST_ASSOCSERVICE is not fully supported */ 2131 + static const DWORD SupportedFlags = 2132 + SPSVCINST_TAGTOFRONT | SPSVCINST_DELETEEVENTLOGENTRY | SPSVCINST_NOCLOBBER_DISPLAYNAME | 2133 + SPSVCINST_NOCLOBBER_STARTTYPE | SPSVCINST_NOCLOBBER_ERRORCONTROL | 2134 + SPSVCINST_NOCLOBBER_LOADORDERGROUP | SPSVCINST_NOCLOBBER_DEPENDENCIES | 2135 + SPSVCINST_STOPSERVICE; 2136 + 2137 + TRACE("%p, %s, 0x%lx, %p, %p, %p, %p\n", 2138 + InfHandle, 2139 + debugstr_w(SectionName), 2140 + Flags, 2141 + DeviceInfoSet, 2142 + DeviceInfoData, 2143 + Reserved1, 2144 + Reserved2); 2088 2145 2089 - if (!sectionname) 2090 - SetLastError(ERROR_INVALID_PARAMETER); 2091 - else if (flags & ~(SPSVCINST_TAGTOFRONT | SPSVCINST_DELETEEVENTLOGENTRY | SPSVCINST_NOCLOBBER_DISPLAYNAME | SPSVCINST_NOCLOBBER_STARTTYPE | SPSVCINST_NOCLOBBER_ERRORCONTROL | SPSVCINST_NOCLOBBER_LOADORDERGROUP | SPSVCINST_NOCLOBBER_DEPENDENCIES | SPSVCINST_STOPSERVICE)) 2146 + if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) 2092 2147 { 2093 - TRACE("Unknown flags: 0x%08lx\n", flags & ~(SPSVCINST_TAGTOFRONT | SPSVCINST_DELETEEVENTLOGENTRY | SPSVCINST_NOCLOBBER_DISPLAYNAME | SPSVCINST_NOCLOBBER_STARTTYPE | SPSVCINST_NOCLOBBER_ERRORCONTROL | SPSVCINST_NOCLOBBER_LOADORDERGROUP | SPSVCINST_NOCLOBBER_DEPENDENCIES | SPSVCINST_STOPSERVICE)); 2148 + list = NULL; 2149 + } else 2150 + { 2151 + list = (struct DeviceInfoSet*)DeviceInfoSet; 2152 + } 2153 + 2154 + if (Flags & ~(SupportedFlags)) 2155 + { 2156 + TRACE("Unknown flags: 0x%08lx\n", Flags & ~(SupportedFlags)); 2094 2157 SetLastError(ERROR_INVALID_FLAGS); 2095 2158 } 2096 - else if (DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE) 2159 + else if (!SectionName || Reserved1 || Reserved2) 2160 + { 2161 + SetLastError(ERROR_INVALID_PARAMETER); 2162 + } 2163 + else if (list && list->magic != SETUP_DEVICE_INFO_SET_MAGIC) 2164 + { 2097 2165 SetLastError(ERROR_INVALID_HANDLE); 2098 - else if (DeviceInfoSet && (list = (struct DeviceInfoSet *)DeviceInfoSet)->magic != SETUP_DEVICE_INFO_SET_MAGIC) 2099 - SetLastError(ERROR_INVALID_HANDLE); 2166 + } 2100 2167 else if (DeviceInfoData && DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)) 2168 + { 2101 2169 SetLastError(ERROR_INVALID_USER_BUFFER); 2102 - else if (reserved1 != NULL || reserved2 != NULL) 2103 - SetLastError(ERROR_INVALID_PARAMETER); 2170 + } 2104 2171 else 2105 2172 { 2106 2173 struct needs_callback_info needs_info; ··· 2111 2178 BOOL bNeedReboot = FALSE; 2112 2179 2113 2180 /* Parse 'Include' and 'Needs' directives */ 2114 - iterate_section_fields( hinf, sectionname, Include, include_callback, NULL); 2181 + iterate_section_fields(InfHandle, SectionName, Include, include_callback, NULL); 2115 2182 needs_info.type = 1; 2116 - needs_info.flags = flags; 2183 + needs_info.flags = Flags; 2117 2184 needs_info.devinfo = DeviceInfoSet; 2118 2185 needs_info.devinfo_data = DeviceInfoData; 2119 - needs_info.reserved1 = reserved1; 2120 - needs_info.reserved2 = reserved2; 2121 - iterate_section_fields( hinf, sectionname, Needs, needs_callback, &needs_info); 2186 + needs_info.reserved1 = Reserved1; 2187 + needs_info.reserved2 = Reserved2; 2188 + iterate_section_fields(InfHandle, SectionName, Needs, needs_callback, &needs_info); 2122 2189 2123 - if (flags & SPSVCINST_STOPSERVICE) 2190 + if (Flags & SPSVCINST_STOPSERVICE) 2124 2191 { 2125 2192 FIXME("Stopping the device not implemented\n"); 2126 2193 /* This may lead to require a reboot */ ··· 2136 2203 goto done; 2137 2204 } 2138 2205 #endif 2139 - flags &= ~SPSVCINST_STOPSERVICE; 2206 + Flags &= ~SPSVCINST_STOPSERVICE; 2140 2207 } 2141 2208 2142 - if (!(ret = SetupFindFirstLineW( hinf, sectionname, NULL, &ContextService ))) 2209 + if (!(ret = SetupFindFirstLineW(InfHandle, SectionName, NULL, &ContextService))) 2143 2210 { 2144 - SetLastError( ERROR_SECTION_NOT_FOUND ); 2211 + SetLastError(ERROR_SECTION_NOT_FOUND); 2145 2212 goto done; 2146 2213 } 2147 2214 2148 - ret = SetupFindFirstLineW(hinf, sectionname, AddService, &ContextService); 2215 + ret = SetupFindFirstLineW(InfHandle, SectionName, AddService, &ContextService); 2149 2216 while (ret) 2150 2217 { 2151 2218 if (!GetStringField(&ContextService, 1, &ServiceName)) ··· 2164 2231 if (!GetStringField(&ContextService, 3, &ServiceSection)) 2165 2232 goto done; 2166 2233 2167 - ret = InstallOneService(list, hinf, ServiceSection, ServiceName, (ServiceFlags & ~SPSVCINST_ASSOCSERVICE) | flags); 2234 + ret = InstallOneService(list, InfHandle, ServiceSection, ServiceName, (ServiceFlags & ~SPSVCINST_ASSOCSERVICE) | Flags); 2168 2235 if (!ret) 2169 2236 goto done; 2170 2237 2171 - if (ServiceFlags & SPSVCINST_ASSOCSERVICE) 2238 + if (list && (ServiceFlags & SPSVCINST_ASSOCSERVICE)) 2172 2239 { 2173 2240 ret = SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, SPDRP_SERVICE, (LPBYTE)ServiceName, (strlenW(ServiceName) + 1) * sizeof(WCHAR)); 2174 2241 if (!ret)