예제 #1
0
파일: conftest.py 프로젝트: yurchor/sssd
def create_ad_sudousers(session_multihost, request):
    """ create Ad sudo users and groups """
    ad = ADOperations(session_multihost.ad[0])
    for idx in range(1, 10):
        ad_user = '******' % idx
        ad_group = 'sudo_idmgroup%d' % idx
        ad.delete_ad_user_group(ad_group)
        ad.delete_ad_user_group(ad_user)
        ad.create_ad_unix_user_group(ad_user, ad_group)
    ad_user1 = 'sudo_user1'
    ad_group2 = 'sudo_group2'
    ad.create_ad_unix_user_group(ad_user1, ad_group2)
    ad_group1 = 'sudo_groupx'
    ad.create_ad_nonposix_group(ad_group1)
    ad.add_user_member_of_group(ad_group1, ad_user1)

    def remove_ad_sudousers():
        """ Remove AD sudo users and groups """
        for idx in range(1, 10):
            ad_user = '******' % idx
            ad_group = 'sudo_idmgroup%d' % idx
            ad.delete_ad_user_group(ad_group)
            ad.delete_ad_user_group(ad_user)
        for object in [ad_group1, ad_group2, ad_user1]:
            ad.delete_ad_user_group(object)
    request.addfinalizer(remove_ad_sudousers)
예제 #2
0
def fixture_prepare_users(session_multihost, request):
    """Prepare users and groups"""
    uid = random.randint(9999, 99999)
    ad_op = ADOperations(session_multihost.ad[0])

    # Setup non-posix user 1
    ad_user_1 = 'testuser1%d' % uid
    ad_group_1 = 'testgroup1%d' % uid
    ad_op.create_ad_nonposix_user(ad_user_1)
    ad_op.create_ad_nonposix_group(ad_group_1)
    ad_op.add_user_member_of_group(ad_group_1, ad_user_1)

    # Add gecos to user 1
    usr = f"powershell.exe -inputformat none -noprofile 'Set-ADUser " \
          f"-Identity \"{ad_user_1}\" -Add @{{" \
          f"gecos = \"{ad_user_1}\";}}'"
    session_multihost.ad[0].run_command(usr, raiseonerr=False)

    # Set user primary group
    upg = f"powershell.exe -inputformat none -noprofile " \
          f"'Set-ADUserPrimaryGroup {ad_user_1} \'{ad_group_1}\''"
    session_multihost.ad[0].run_command(upg, raiseonerr=False)

    # Setup posix user 2
    ad_user_2 = 'testuser2%d' % uid
    ad_group_2 = 'testgroup2%d' % uid
    ad_op.create_ad_unix_user_group(ad_user_2, ad_group_2)

    # Add gecos to user 2
    usr = f"powershell.exe -inputformat none -noprofile 'Set-ADUser " \
          f"-Identity \"{ad_user_2}\" -Add @{{" \
          f"gecos = \"{ad_user_2}\";}}'"
    session_multihost.ad[0].run_command(usr, raiseonerr=False)

    def remove_ad_user_groups():
        """ Remove windows AD users and groups"""
        ad_op.delete_ad_user_group(ad_user_1)
        ad_op.delete_ad_user_group(ad_group_1)
        ad_op.delete_ad_user_group(ad_user_2)
        ad_op.delete_ad_user_group(ad_group_2)

    request.addfinalizer(remove_ad_user_groups)
    return ad_user_1, ad_group_1, ad_user_2, ad_group_2
예제 #3
0
파일: conftest.py 프로젝트: yurchor/sssd
def samba_share_permissions(session_multihost, request):
    """ Set permissions on samba share """
    smbTools = sambaTools(session_multihost.master[0], session_multihost.ad[0])
    adops = ADOperations(session_multihost.ad[0])
    share_name = 'share1'
    share_path = '/mnt/samba/%s' % share_name
    smbTools.create_samba_share(share_path)
    realm = session_multihost.ad[0].realm
    for idx in range(1, 3):
        ad_user = '******' % idx
        ad_group = 'idmfoogroup%d' % idx
        all_group = 'idmfooallgroup'
        adops.delete_ad_user_group(ad_group)
        adops.delete_ad_user_group(ad_user)
    adops.delete_ad_user_group(all_group)
    adops.create_ad_unix_group(all_group)
    for idx in range(1, 3):
        ad_user = '******' % idx
        ad_group = 'idmfoogroup%d' % idx
        adops.create_ad_unix_user_group(ad_user, ad_group)
        adops.add_user_member_of_group(all_group, ad_user)
    session_multihost.master[0].service_sssd('restart')
    time.sleep(30)

    for idx in range(1, 3):
        ad_user = '******' % idx
        ad_group = 'idmfoogroup%d' % idx
        directory = '/mnt/samba/share1/idmfoogroup%d' % idx
        create_dir = 'mkdir -p %s' % directory
        session_multihost.master[0].run_command(create_dir)
        chmod = 'chmod 2770 %s' % directory
        session_multihost.master[0].run_command(chmod)
        chgrp = "chgrp '%s@%s' %s " % (ad_group, realm, directory)
        session_multihost.master[0].run_command(chgrp)

    all_group = 'idmfooallgroup'
    common_dir = 'mkdir -p /mnt/samba/share1/allgroup'
    session_multihost.master[0].run_command(common_dir)
    chgrp = "chgrp '%s@%s' /mnt/samba/share1/allgroup " % (all_group, realm)
    chmod = "chmod 2770 /mnt/samba/share1/allgroup"
    session_multihost.master[0].run_command(chgrp)
    session_multihost.master[0].run_command(chmod)

    # create mount point on client
    mount_point = 'mkdir -p %s' % share_path
    session_multihost.client[0].run_command(mount_point)

    def delete_share_directory():
        """ Delete share directory """
        print("we are deleting samba share directory")
        smbTools.delete_samba_share(share_path)
        remove_mount_point = "rm -rf %s" % share_path
        session_multihost.client[0].run_command(remove_mount_point)
        for idx in range(1, 3):
            ad_user = '******' % idx
            ad_group = 'idmfoogroup%d' % idx
            all_group = 'idmfooallgroup'
            adops.delete_ad_user_group(ad_group)
            adops.delete_ad_user_group(all_group)
            adops.delete_ad_user_group(ad_user)
    request.addfinalizer(delete_share_directory)