[PATCH setup 6/7] Pass a "Install for all users" flag into setDefaultSecurity()

Jon Turney jon.turney@dronecode.org.uk
Sat Feb 15 17:05:00 GMT 2020


Pass an "Install for all users" flag into setDefaultSecurity(), rather
than evaluating it there, for better decoupling from settings & UI.
---
 main.cc  | 2 +-
 win32.cc | 5 ++---
 win32.h  | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/main.cc b/main.cc
index 749b00c..5de1f36 100644
--- a/main.cc
+++ b/main.cc
@@ -355,7 +355,7 @@ WinMain (HINSTANCE h,
     else
       {
 	/* Set default DACL and Group. */
-	nt_sec.setDefaultSecurity ();
+	nt_sec.setDefaultSecurity ((root_scope == IDC_ROOT_SYSTEM));
 
 	UserSettings Settings (local_dir);
 	main_display ();
diff --git a/win32.cc b/win32.cc
index 0981355..6a551ba 100644
--- a/win32.cc
+++ b/win32.cc
@@ -18,7 +18,6 @@
 #include <malloc.h>
 #include "LogFile.h"
 #include "resource.h"
-#include "state.h"
 #include "ini.h"
 #include <sys/stat.h>
 
@@ -308,7 +307,7 @@ NTSecurity::setAdminGroup ()
 }
 
 void
-NTSecurity::setDefaultSecurity ()
+NTSecurity::setDefaultSecurity (bool isAdmin)
 {
   /* Get the processes access token. */
   if (!OpenProcessToken (GetCurrentProcess (),
@@ -359,7 +358,7 @@ NTSecurity::setDefaultSecurity ()
   /* Try to set the primary group to the Administrators group, but only if
      "Install for all users" has been chosen.  If it doesn't work, we're
      no admin and that's all there's to say about it. */
-  if (root_scope == IDC_ROOT_SYSTEM)
+  if (isAdmin)
     setAdminGroup ();
 }
 
diff --git a/win32.h b/win32.h
index c866790..1b9db49 100644
--- a/win32.h
+++ b/win32.h
@@ -130,7 +130,7 @@ public:
   void resetPrimaryGroup();
   void setAdminGroup ();
   void initialiseWellKnownSIDs ();
-  void setDefaultSecurity();
+  void setDefaultSecurity(bool isAdmin);
   bool isRunAsAdmin ();
 private:
   void NoteFailedAPI (const std::string &);
-- 
2.21.0



More information about the Cygwin-apps mailing list