]> wimlib.net Git - wimlib/blobdiff - src/win32_common.c
Add WIMLIB_INIT_FLAG_STRICT_{CAPTURE,APPLY}_PRIVILEGES
[wimlib] / src / win32_common.c
index c6605b4b53eae1fb59984d05b533503c2bded63e..5a2b79481f49c592858c2cd081fbc4ccf31c1597 100644 (file)
@@ -479,38 +479,26 @@ out:
        return ret;
 }
 
        return ret;
 }
 
-static void
+static bool
 win32_modify_capture_privileges(bool enable)
 {
 win32_modify_capture_privileges(bool enable)
 {
-       win32_modify_privilege(SE_BACKUP_NAME, enable);
-       win32_modify_privilege(SE_SECURITY_NAME, enable);
+       return win32_modify_privilege(SE_BACKUP_NAME, enable)
+           && win32_modify_privilege(SE_SECURITY_NAME, enable);
 }
 
 }
 
-static void
+static bool
 win32_modify_apply_privileges(bool enable)
 {
 win32_modify_apply_privileges(bool enable)
 {
-       win32_modify_privilege(SE_RESTORE_NAME, enable);
-       win32_modify_privilege(SE_SECURITY_NAME, enable);
-       win32_modify_privilege(SE_TAKE_OWNERSHIP_NAME, enable);
-}
-
-static void
-win32_modify_capture_and_apply_privileges(bool enable)
-{
-       win32_modify_capture_privileges(enable);
-       win32_modify_apply_privileges(enable);
-}
-
-static void
-win32_acquire_capture_and_apply_privileges(void)
-{
-       win32_modify_capture_and_apply_privileges(true);
+       return win32_modify_privilege(SE_RESTORE_NAME, enable)
+           && win32_modify_privilege(SE_SECURITY_NAME, enable)
+           && win32_modify_privilege(SE_TAKE_OWNERSHIP_NAME, enable);
 }
 
 static void
 win32_release_capture_and_apply_privileges(void)
 {
 }
 
 static void
 win32_release_capture_and_apply_privileges(void)
 {
-       win32_modify_capture_and_apply_privileges(false);
+       win32_modify_capture_privileges(false);
+       win32_modify_apply_privileges(false);
 }
 
 HANDLE
 }
 
 HANDLE
@@ -563,12 +551,17 @@ windows_version_is_at_least(unsigned major, unsigned minor)
 }
 
 /* One-time initialization for Windows capture/apply code.  */
 }
 
 /* One-time initialization for Windows capture/apply code.  */
-void
+int
 win32_global_init(int init_flags)
 {
        /* Try to acquire useful privileges.  */
        if (!(init_flags & WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES)) {
 win32_global_init(int init_flags)
 {
        /* Try to acquire useful privileges.  */
        if (!(init_flags & WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES)) {
-               win32_acquire_capture_and_apply_privileges();
+               if (!win32_modify_capture_privileges(true))
+                       if (init_flags & WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES)
+                               goto insufficient_privileges;
+               if (!win32_modify_apply_privileges(true))
+                       if (init_flags & WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES)
+                               goto insufficient_privileges;
                acquired_privileges = true;
        }
 
                acquired_privileges = true;
        }
 
@@ -589,6 +582,11 @@ win32_global_init(int init_flags)
                                win32func_FindFirstStreamW = NULL;
                }
        }
                                win32func_FindFirstStreamW = NULL;
                }
        }
+       return 0;
+
+insufficient_privileges:
+       win32_release_capture_and_apply_privileges();
+       return WIMLIB_ERR_INSUFFICIENT_PRIVILEGES;
 }
 
 void
 }
 
 void