MCPcopy
hub / github.com/hardentools/hardentools / hardenKeySZ

Function hardenKeySZ

registry_utils.go:320–342  ·  view source on GitHub ↗

Harden SZ (String) value including saving the original state.

(rootKey registry.Key, path string, valueName string, hardenedValue string)

Source from the content-addressed store, hash-verified

318
319// Harden SZ (String) value including saving the original state.
320func hardenKeySZ(rootKey registry.Key, path string, valueName string, hardenedValue string) error {
321 rootKeyName, _ := getRootKeyName(rootKey)
322 key, _, err := registry.CreateKey(rootKey, path, registry.WRITE)
323 if err != nil {
324 return fmt.Errorf("Couldn't create / open registry key for write access: %s\\%s",
325 rootKeyName, path)
326 }
327 defer key.Close()
328
329 // Save current state.
330 err = saveOriginalRegistrySZ(rootKey, path, valueName)
331 if err != nil {
332 return err
333 }
334 // Harden.
335 err = key.SetStringValue(valueName, hardenedValue)
336 if err != nil {
337 return fmt.Errorf("Couldn't set registry value: %s \\ %s \\ %s",
338 rootKeyName, path, valueName)
339 }
340
341 return nil
342}
343
344// Helper method for saving original registry key DWORD.
345func saveOriginalRegistryDWORD(rootKey registry.Key, keyName string, valueName string) error {

Callers 1

HardenMethod · 0.85

Calls 2

getRootKeyNameFunction · 0.85
saveOriginalRegistrySZFunction · 0.85

Tested by

no test coverage detected