MCPcopy
hub / github.com/hardentools/hardentools / cmdHardenRestore

Function cmdHardenRestore

utils.go:200–245  ·  view source on GitHub ↗
(harden bool)

Source from the content-addressed store, hash-verified

198}
199
200func 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.
248func initLogging(traceHandle io.Writer, infoHandle io.Writer, guiVersion bool) {

Callers 4

cmdHardenFunction · 0.85
cmdRestoreFunction · 0.85
cmdHardenFunction · 0.85
cmdRestoreFunction · 0.85

Calls 9

isElevatedFunction · 0.85
checkStatusFunction · 0.85
triggerAllFunction · 0.85
restoreSavedRegistryKeysFunction · 0.85
markStatusFunction · 0.85
showStatusFunction · 0.70
IsHardenedMethod · 0.65
NameMethod · 0.65
HardenByDefaultMethod · 0.65

Tested by

no test coverage detected