示例#1
0
def hostActionMigrateGroupFile(_context):
    # Save the default group file, there is no default gshadow file installed.
    newPath = migrate.preserveFile(os.path.join(HOST_ROOT, "etc/group"))
    assert newPath != None

    migrate.migratePath("/etc/group")
    migrate.migratePath("/etc/gshadow")

    oldFile = GroupFile.fromFile(os.path.join(HOST_ROOT, "etc/group"))
    newFile = GroupFile.fromFile(newPath)

    gFile = open(os.path.join(HOST_ROOT, "etc/group"), 'a')

    # If there's a shadow file, we need to add any new groups to it.
    gshadowFile = None
    gshadowFileName = os.path.join(HOST_ROOT, "etc/gshadow")
    if os.path.exists(gshadowFileName):
        gshadowFile = open(gshadowFileName, 'a')

    try:
        for groupData in newFile:
            if not oldFile.hasName(groupData.name):
                gFile.write("%s\n" % ":".join(groupData))
                if gshadowFile:
                    shadowData = [
                        groupData.name, groupData.passwd, "", groupData.users
                    ]
                    gshadowFile.write("%s\n" % ":".join(shadowData))
    finally:
        gFile.close()
        if gshadowFile:
            gshadowFile.close()
def test_migrate():
    try:
        fauxroot.resetLogs()

        srcDir = os.path.join(TEST_DIR, "upgrade")
        root = os.path.join(TEST_DIR, "good-config.1")
        esx3 = consts.HOST_ROOT + consts.ESX3_INSTALLATION
    
        copyIntoRoot(os.path.join(srcDir, "xinetd.conf.1"),
                     root,
                     os.path.join(esx3, "etc/xinetd.conf"))
        copyIntoRoot(os.path.join(srcDir, "time"),
                     root,
                     os.path.join(esx3, "etc/xinetd.d/time"))
        copyIntoRoot(os.path.join(srcDir, "time"),
                     root,
                     os.path.join(consts.HOST_ROOT, "etc/xinetd.d/time-stream"))
        copyIntoRoot(os.path.join(srcDir, "vmware-authd"),
                     root,
                     os.path.join(esx3, "etc/xinetd.d/vmware-authd"))
        copyIntoRoot(os.path.join(srcDir, "vmware-authd"),
                     root,
                     os.path.join(consts.HOST_ROOT,
                                  "etc/xinetd.d/vmware-authd"))
        
        fauxroot.FAUXROOT = [root]

        migrate.migratePath("/etc/xinetd.conf")

        assert fauxroot.SYSTEM_LOG == [
            ['/sbin/chkconfig', 'time-stream', 'off'],
            ['/sbin/chkconfig', 'vmware-authd', 'on'],
            ]
    finally:
        fauxroot.FAUXROOT = None
示例#3
0
文件: users.py 项目: vmware/weasel
def hostActionMigrateGroupFile(_context):
    # Save the default group file, there is no default gshadow file installed.
    newPath = migrate.preserveFile(os.path.join(HOST_ROOT, "etc/group"))
    assert newPath != None
    
    migrate.migratePath("/etc/group")
    migrate.migratePath("/etc/gshadow")
    
    oldFile = GroupFile.fromFile(os.path.join(HOST_ROOT, "etc/group"))
    newFile = GroupFile.fromFile(newPath)

    gFile = open(os.path.join(HOST_ROOT, "etc/group"), 'a')

    # If there's a shadow file, we need to add any new groups to it.
    gshadowFile = None
    gshadowFileName = os.path.join(HOST_ROOT, "etc/gshadow")
    if os.path.exists(gshadowFileName):
        gshadowFile = open(gshadowFileName, 'a')
        
    try:
        for groupData in newFile:
            if not oldFile.hasName(groupData.name):
                gFile.write("%s\n" % ":".join(groupData))
                if gshadowFile:
                    shadowData = [
                        groupData.name, groupData.passwd, "", groupData.users]
                    gshadowFile.write("%s\n" % ":".join(shadowData))
    finally:
        gFile.close()
        if gshadowFile:
            gshadowFile.close()
示例#4
0
def hostActionMigratePasswdFile(_context):
    newPath = migrate.preserveFile(os.path.join(HOST_ROOT, "etc/passwd"))
    assert newPath != None

    migrate.migratePath("/etc/passwd")
    migrate.migratePath("/etc/shadow")

    oldFile = PasswdFile.fromFile(os.path.join(HOST_ROOT, "etc/passwd"))
    newFile = PasswdFile.fromFile(newPath)

    _mergeNewUsers(oldFile, newFile)

    _normalizeUsers(oldFile)
示例#5
0
文件: users.py 项目: vmware/weasel
def hostActionMigratePasswdFile(_context):
    newPath = migrate.preserveFile(os.path.join(HOST_ROOT, "etc/passwd"))
    assert newPath != None
    
    migrate.migratePath("/etc/passwd")
    migrate.migratePath("/etc/shadow")
    
    oldFile = PasswdFile.fromFile(os.path.join(HOST_ROOT, "etc/passwd"))
    newFile = PasswdFile.fromFile(newPath)

    _mergeNewUsers(oldFile, newFile)

    _normalizeUsers(oldFile)