X-Git-Url: https://code.grnet.gr/git/snf-image-creator/blobdiff_plain/88f83027df65608a70e1a88f96b4a3055427dd52..121f3bc0cf7fc8591c01e21dc686e07c685ef23a:/image_creator/os_type/windows.py diff --git a/image_creator/os_type/windows.py b/image_creator/os_type/windows.py index f1e6921..9fb8218 100644 --- a/image_creator/os_type/windows.py +++ b/image_creator/os_type/windows.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2012 GRNET S.A. All rights reserved. # # Redistribution and use in source and binary forms, with or @@ -31,11 +33,46 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. +"""This module hosts OS-specific code common for the various Microsoft +Windows OSs.""" + from image_creator.os_type import OSBase +import hivex +import tempfile +import os + class Windows(OSBase): """OS class for Windows""" - pass + def __init__(self, rootdev, ghandler, output): + super(Windows, self).__init__(rootdev, ghandler, output) + + self.meta["USERS"] = " ".join(self._get_users()) + + def _get_users(self): + """Returns a list of users found in the images""" + samfd, sam = tempfile.mkstemp() + try: + systemroot = self.g.inspect_get_windows_systemroot(self.root) + path = "%s/system32/config/sam" % systemroot + path = self.g.case_sensitive_path(path) + self.g.download(path, sam) + + h = hivex.Hivex(sam) + + key = h.root() + + # Navigate to /SAM/Domains/Account/Users/Names + for child in ('SAM', 'Domains', 'Account', 'Users', 'Names'): + key = h.node_get_child(key, child) + + users = [h.node_name(x) for x in h.node_children(key)] + + finally: + os.unlink(sam) + + # Filter out the guest account + return filter(lambda x: x != "Guest", users) # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :