(harden bool)
| 198 | } |
| 199 | |
| 200 | func cmdHardenRestore(harden bool) { |
| 201 | // check if hardentools has been started with elevated rights. |
| 202 | elevationStatus := isElevated() |
| 203 | if elevationStatus { |
| 204 | Info.Println("Started with elevated rights") |
| 205 | allHardenSubjects = hardenSubjectsForPrivilegedUsers |
| 206 | } else { |
| 207 | Info.Println("Started without elevated rights") |
| 208 | allHardenSubjects = hardenSubjectsForUnprivilegedUsers |
| 209 | } |
| 210 | |
| 211 | // TODO: verify if hardening has been done with elevate privileges and now restoring |
| 212 | // should be done without elevated privileges (needs additional registry key) |
| 213 | |
| 214 | // check hardening status |
| 215 | status := checkStatus() |
| 216 | if status == false && harden == false { |
| 217 | fmt.Println("Not hardened. Please harden before restoring.") |
| 218 | os.Exit(-1) |
| 219 | } else if status == true && harden == true { |
| 220 | fmt.Println("Already hardened. Please restore before hardening again.") |
| 221 | os.Exit(-1) |
| 222 | } |
| 223 | |
| 224 | // build up expert settings checkboxes and map |
| 225 | expertConfig = make(map[string]bool) |
| 226 | for _, hardenSubject := range allHardenSubjects { |
| 227 | var subjectIsHardened = hardenSubject.IsHardened() |
| 228 | //var enableField bool |
| 229 | |
| 230 | if status == false { |
| 231 | // harden only settings which are not hardened yet |
| 232 | expertConfig[hardenSubject.Name()] = !subjectIsHardened && hardenSubject.HardenByDefault() |
| 233 | } else { |
| 234 | // restore only hardened settings |
| 235 | expertConfig[hardenSubject.Name()] = subjectIsHardened |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | triggerAll(harden) |
| 240 | if !harden { |
| 241 | restoreSavedRegistryKeys() |
| 242 | } |
| 243 | markStatus(harden) |
| 244 | showStatus() |
| 245 | } |
| 246 | |
| 247 | // initLogging initializes loggers. |
| 248 | func initLogging(traceHandle io.Writer, infoHandle io.Writer, guiVersion bool) { |
no test coverage detected