Example #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()
Example #2
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()
Example #3
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)
Example #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)