Statistics
| Branch: | Tag: | Revision:

root / image_creator / os_type / windows.py @ c71f38be

History | View | Annotate | Download (2.8 kB)

1 121f3bc0 Nikos Skalkotos
# -*- coding: utf-8 -*-
2 121f3bc0 Nikos Skalkotos
#
3 ae48a082 Nikos Skalkotos
# Copyright 2012 GRNET S.A. All rights reserved.
4 ae48a082 Nikos Skalkotos
#
5 ae48a082 Nikos Skalkotos
# Redistribution and use in source and binary forms, with or
6 ae48a082 Nikos Skalkotos
# without modification, are permitted provided that the following
7 ae48a082 Nikos Skalkotos
# conditions are met:
8 ae48a082 Nikos Skalkotos
#
9 ae48a082 Nikos Skalkotos
#   1. Redistributions of source code must retain the above
10 ae48a082 Nikos Skalkotos
#      copyright notice, this list of conditions and the following
11 ae48a082 Nikos Skalkotos
#      disclaimer.
12 ae48a082 Nikos Skalkotos
#
13 ae48a082 Nikos Skalkotos
#   2. Redistributions in binary form must reproduce the above
14 ae48a082 Nikos Skalkotos
#      copyright notice, this list of conditions and the following
15 ae48a082 Nikos Skalkotos
#      disclaimer in the documentation and/or other materials
16 ae48a082 Nikos Skalkotos
#      provided with the distribution.
17 ae48a082 Nikos Skalkotos
#
18 ae48a082 Nikos Skalkotos
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 ae48a082 Nikos Skalkotos
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ae48a082 Nikos Skalkotos
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 ae48a082 Nikos Skalkotos
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 ae48a082 Nikos Skalkotos
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 ae48a082 Nikos Skalkotos
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 ae48a082 Nikos Skalkotos
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 ae48a082 Nikos Skalkotos
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 ae48a082 Nikos Skalkotos
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 ae48a082 Nikos Skalkotos
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 ae48a082 Nikos Skalkotos
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 ae48a082 Nikos Skalkotos
# POSSIBILITY OF SUCH DAMAGE.
30 ae48a082 Nikos Skalkotos
#
31 ae48a082 Nikos Skalkotos
# The views and conclusions contained in the software and
32 ae48a082 Nikos Skalkotos
# documentation are those of the authors and should not be
33 ae48a082 Nikos Skalkotos
# interpreted as representing official policies, either expressed
34 ae48a082 Nikos Skalkotos
# or implied, of GRNET S.A.
35 ae48a082 Nikos Skalkotos
36 121f3bc0 Nikos Skalkotos
"""This module hosts OS-specific code common for the various Microsoft
37 121f3bc0 Nikos Skalkotos
Windows OSs."""
38 121f3bc0 Nikos Skalkotos
39 61d14323 Nikos Skalkotos
from image_creator.os_type import OSBase
40 aa2062ba Nikos Skalkotos
41 76b200cf Nikos Skalkotos
import hivex
42 76b200cf Nikos Skalkotos
import tempfile
43 76b200cf Nikos Skalkotos
import os
44 76b200cf Nikos Skalkotos
45 8c574358 Nikos Skalkotos
46 aa2062ba Nikos Skalkotos
class Windows(OSBase):
47 88f83027 Nikos Skalkotos
    """OS class for Windows"""
48 76b200cf Nikos Skalkotos
49 b8c0848c Nikos Skalkotos
    def _do_collect_metadata(self):
50 b8c0848c Nikos Skalkotos
        """Collect metadata about the OS"""
51 b8c0848c Nikos Skalkotos
        super(Windows, self)._do_collect_metadata()
52 76b200cf Nikos Skalkotos
        self.meta["USERS"] = " ".join(self._get_users())
53 76b200cf Nikos Skalkotos
54 76b200cf Nikos Skalkotos
    def _get_users(self):
55 121f3bc0 Nikos Skalkotos
        """Returns a list of users found in the images"""
56 76b200cf Nikos Skalkotos
        samfd, sam = tempfile.mkstemp()
57 76b200cf Nikos Skalkotos
        try:
58 76b200cf Nikos Skalkotos
            systemroot = self.g.inspect_get_windows_systemroot(self.root)
59 76b200cf Nikos Skalkotos
            path = "%s/system32/config/sam" % systemroot
60 76b200cf Nikos Skalkotos
            path = self.g.case_sensitive_path(path)
61 76b200cf Nikos Skalkotos
            self.g.download(path, sam)
62 76b200cf Nikos Skalkotos
63 76b200cf Nikos Skalkotos
            h = hivex.Hivex(sam)
64 76b200cf Nikos Skalkotos
65 76b200cf Nikos Skalkotos
            key = h.root()
66 76b200cf Nikos Skalkotos
67 76b200cf Nikos Skalkotos
            # Navigate to /SAM/Domains/Account/Users/Names
68 76b200cf Nikos Skalkotos
            for child in ('SAM', 'Domains', 'Account', 'Users', 'Names'):
69 76b200cf Nikos Skalkotos
                key = h.node_get_child(key, child)
70 76b200cf Nikos Skalkotos
71 76b200cf Nikos Skalkotos
            users = [h.node_name(x) for x in h.node_children(key)]
72 76b200cf Nikos Skalkotos
73 76b200cf Nikos Skalkotos
        finally:
74 76b200cf Nikos Skalkotos
            os.unlink(sam)
75 76b200cf Nikos Skalkotos
76 76b200cf Nikos Skalkotos
        # Filter out the guest account
77 76b200cf Nikos Skalkotos
        return filter(lambda x: x != "Guest", users)
78 aa2062ba Nikos Skalkotos
79 aa2062ba Nikos Skalkotos
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :