Revision 010f6b30 image_creator/os_type/windows.py

b/image_creator/os_type/windows.py
123 123
        try:
124 124
            disabled_uac = self._update_uac_remote_setting(1)
125 125
            token = self._enable_os_monitor()
126

  
127
            # disable the firewalls
128
            firewall_states = self._update_firewalls(0, 0, 0)
129

  
130
            # Delete the pagefile. It will be recreated when the system boots
131
            systemroot = self.g.inspect_get_windows_systemroot(self.root)
132
            pagefile = "%s/pagefile.sys" % systemroot
133
            self.g.rm_rf(self.g.case_sensitive_path(pagefile))
134

  
126 135
        finally:
127 136
            self.umount()
128 137

  
......
179 188
                task()
180 189
                setattr(task.im_func, 'executed', True)
181 190

  
182
            self.out.output("Shutting down windows VM ...", False)
191
            self.out.output("Sending shut down command ...", False)
183 192
            if not ms_sysprep_enabled:
184 193
                self._shutdown()
185 194
            self.out.success("done")
186 195

  
196
            self.out.output("Waiting for windows to shut down ...", False)
187 197
            vm.wait()
198
            self.out.success("done")
188 199
        finally:
189 200
            if monitor is not None:
190 201
                os.unlink(monitor)
......
197 208
            self.g.launch()
198 209
            self.out.success('done')
199 210

  
200
        if disabled_uac:
201
            self._update_uac_remote_setting(0)
211
            self.mount(readonly=False)
212
            try:
213
                if disabled_uac:
214
                    self._update_uac_remote_setting(0)
215

  
216
                self._update_firewalls(*firewall_states)
217
            finally:
218
                self.umount()
202 219

  
203 220
    def _create_vm(self, monitor):
204 221
        """Create a VM with the image attached as the disk
......
343 360

  
344 361
        return token
345 362

  
363
    def _update_firewalls(self, domain, public, standard):
364
        """Enables or disables the firewall for the Domain, the Public and the
365
        Standard profile. Returns a triplete with the old values.
366

  
367
        1 will enable a firewall and 0 will disable it
368
        """
369

  
370
        if domain not in (0, 1):
371
            raise ValueError("Valid values for domain parameter are 0 and 1")
372

  
373
        if public not in (0, 1):
374
            raise ValueError("Valid values for public parameter are 0 and 1")
375

  
376
        if standard not in (0, 1):
377
            raise ValueError("Valid values for standard parameter are 0 and 1")
378

  
379
        path = self._registry_file_path("SYSTEM")
380
        systemfd, system = tempfile.mkstemp()
381
        try:
382
            os.close(systemfd)
383
            self.g.download(path, system)
384

  
385
            h = hivex.Hivex(system, write=True)
386

  
387
            select = h.node_get_child(h.root(), 'Select')
388
            current_value = h.node_get_value(select, 'Current')
389

  
390
            # expecting a little endian dword
391
            assert h.value_type(current_value)[1] == 4
392
            current = "%03d" % h.value_dword(current_value)
393

  
394
            firewall_policy = h.root()
395
            for child in ('ControlSet%s' % current, 'services', 'SharedAccess',
396
                          'Parameters', 'FirewallPolicy'):
397
                firewall_policy = h.node_get_child(firewall_policy, child)
398

  
399
            old_values = []
400
            new_values = [domain, public, standard]
401
            for profile in ('Domain', 'Public', 'Standard'):
402
                node = h.node_get_child(firewall_policy, '%sProfile' % profile)
403

  
404
                old_value = h.node_get_value(node, 'EnableFirewall')
405

  
406
                # expecting a little endian dword
407
                assert h.value_type(old_value)[1] == 4
408
                old_values.append(h.value_dword(old_value))
409

  
410
                new_value = '\x00' if new_values.pop(0) == 0 else '\x01'
411
                h.node_set_value(node, {'key': 'EnableFirewall', 't': 4L,
412
                                        'value': '%s\x00\x00\x00' % new_value})
413

  
414
            h.commit(None)
415
            self.g.upload(system, path)
416

  
417
        finally:
418
            os.unlink(system)
419

  
420
        return old_values
421

  
346 422
    def _update_uac_remote_setting(self, value):
347 423
        """Updates the registry key value:
348 424
        [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies

Also available in: Unified diff