Harden SZ (String) value including saving the original state.
(rootKey registry.Key, path string, valueName string, hardenedValue string)
| 318 | |
| 319 | // Harden SZ (String) value including saving the original state. |
| 320 | func 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. |
| 345 | func saveOriginalRegistryDWORD(rootKey registry.Key, keyName string, valueName string) error { |
no test coverage detected