示例#1
0
def test_apply_to_path_restricted_access():
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith("cygwin"):
        return  # chmod 000 isn't effective.
    tmpdir = tempfile.mkdtemp(prefix="bup-tmetadata-")
    try:
        parent = tmpdir + "/foo"
        path = parent + "/bar"
        os.mkdir(parent)
        os.mkdir(path)
        clear_errors()
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(parent, 000)
        m.apply_to_path(path)
        print >>sys.stderr, helpers.saved_errors
        expected_errors = ["utime: "]
        if m.linux_attr and _linux_attr_supported(tmpdir):
            expected_errors.append("Linux chattr: ")
        if metadata.xattr and m.linux_xattr:
            expected_errors.append("xattr.set: ")
        WVPASS(len(helpers.saved_errors) == len(expected_errors))
        for i in xrange(len(expected_errors)):
            WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i]))
        clear_errors()
    finally:
        subprocess.call(["chmod", "-R", "u+rwX", tmpdir])
        subprocess.call(["rm", "-rf", tmpdir])
示例#2
0
文件: tmetadata.py 项目: barroque/bup
def test_restore_restricted_user_group():
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        WVPASSEQ(m.apply_to_path(path), None)
        orig_uid = m.uid
        m.uid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('lchown: '))
        clear_errors()
        m.uid = orig_uid
        m.gid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('lchown: ') or os.stat(path).st_gid == m.gid)
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#3
0
def test_apply_to_path_restricted_access():
    initial_failures = wvfailure_count()
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith('cygwin'):
        return # chmod 000 isn't effective.
    tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-')
    parent = tmpdir + '/foo'
    path = parent + '/bar'
    os.mkdir(parent)
    os.mkdir(path)
    clear_errors()
    m = metadata.from_path(path, archive_path=path, save_symlinks=True)
    WVPASSEQ(m.path, path)
    os.chmod(parent, 000)
    m.apply_to_path(path)
    print >> sys.stderr, helpers.saved_errors
    expected_errors = ['utime: ']
    if m.linux_attr and _linux_attr_supported(tmpdir):
        expected_errors.append('Linux chattr: ')
    if metadata.xattr and m.linux_xattr:
        expected_errors.append('xattr.set: ')
    WVPASS(len(helpers.saved_errors) == len(expected_errors))
    for i in xrange(len(expected_errors)):
        WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i]))
    clear_errors()
    if wvfailure_count() == initial_failures:
        subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
        subprocess.call(['rm', '-rf', tmpdir])
示例#4
0
def test_apply_to_path_restricted_access(tmpdir):
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith('cygwin'):
        return # chmod 000 isn't effective.
    try:
        parent = tmpdir + b'/foo'
        path = parent + b'/bar'
        os.mkdir(parent)
        os.mkdir(path)
        clear_errors()
        if metadata.xattr:
            try:
                metadata.xattr.set(path, b'user.buptest', b'bup')
            except:
                print("failed to set test xattr")
                # ignore any failures here - maybe FS cannot do it
                pass
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(parent, 0o000)
        m.apply_to_path(path)
        print(b'saved_errors:', helpers.saved_errors, file=sys.stderr)
        expected_errors = ['utime: ']
        if m.linux_attr and _linux_attr_supported(tmpdir):
            expected_errors.append('Linux chattr: ')
        if metadata.xattr and m.linux_xattr:
            expected_errors.append("xattr.set ")
        WVPASS(len(helpers.saved_errors) == len(expected_errors))
        for i in range(len(expected_errors)):
            assert str(helpers.saved_errors[i]).startswith(expected_errors[i])
    finally:
        clear_errors()
示例#5
0
def test_restore_restricted_user_group():
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        WVPASSEQ(m.apply_to_path(path), None)
        orig_uid = m.uid
        m.uid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('lchown: '))
        clear_errors()
        m.uid = orig_uid
        m.gid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('lchown: ') or os.stat(path).st_gid == m.gid)
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#6
0
def test_apply_to_path_restricted_access():
    initial_failures = wvfailure_count()
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith('cygwin'):
        return  # chmod 000 isn't effective.
    tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-')
    parent = tmpdir + '/foo'
    path = parent + '/bar'
    os.mkdir(parent)
    os.mkdir(path)
    clear_errors()
    m = metadata.from_path(path, archive_path=path, save_symlinks=True)
    WVPASSEQ(m.path, path)
    os.chmod(parent, 000)
    m.apply_to_path(path)
    print >> sys.stderr, helpers.saved_errors
    expected_errors = ['utime: ']
    if m.linux_attr and _linux_attr_supported(tmpdir):
        expected_errors.append('Linux chattr: ')
    if metadata.xattr and m.linux_xattr:
        expected_errors.append("xattr.set '")
    WVPASS(len(helpers.saved_errors) == len(expected_errors))
    for i in xrange(len(expected_errors)):
        WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i]))
    clear_errors()
    if wvfailure_count() == initial_failures:
        subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
        subprocess.call(['rm', '-rf', tmpdir])
示例#7
0
def test_apply_to_path_restricted_access():
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith('cygwin'):
        return # chmod 000 isn't effective.
    with no_lingering_errors(), test_tempdir('bup-tmetadata-') as tmpdir:
        parent = tmpdir + '/foo'
        path = parent + '/bar'
        os.mkdir(parent)
        os.mkdir(path)
        clear_errors()
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(parent, 000)
        m.apply_to_path(path)
        print >> sys.stderr, 'saved_errors:', helpers.saved_errors
        expected_errors = ['utime: ']
        if m.linux_attr and _linux_attr_supported(tmpdir):
            expected_errors.append('Linux chattr: ')
        if metadata.xattr and m.linux_xattr:
            expected_errors.append("xattr.set '")
        WVPASS(len(helpers.saved_errors) == len(expected_errors))
        for i in xrange(len(expected_errors)):
            WVPASS(str(helpers.saved_errors[i]).startswith(expected_errors[i]))
        clear_errors()
示例#8
0
def test_from_path_error(tmpdir):
    if is_superuser() or detect_fakeroot():
        return
    path = tmpdir + b'/foo'
    os.mkdir(path)
    m = metadata.from_path(path, archive_path=path, save_symlinks=True)
    WVPASSEQ(m.path, path)
    os.chmod(path, 0o000)
    metadata.from_path(path, archive_path=path, save_symlinks=True)
    if metadata.get_linux_file_attr:
        print('saved_errors:', helpers.saved_errors, file=sys.stderr)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('read Linux attr'))
        clear_errors()
示例#9
0
def test_from_path_error():
    if is_superuser() or detect_fakeroot():
        return
    with no_lingering_errors(), test_tempdir('bup-tmetadata-') as tmpdir:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(path, 000)
        metadata.from_path(path, archive_path=path, save_symlinks=True)
        if metadata.get_linux_file_attr:
            print >> sys.stderr, 'saved_errors:', helpers.saved_errors
            WVPASS(len(helpers.saved_errors) == 1)
            errmsg = _first_err()
            WVPASS(errmsg.startswith('read Linux attr'))
            clear_errors()
示例#10
0
文件: tmetadata.py 项目: meeee/bup
def test_from_path_error():
    if os.geteuid() == 0 or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        subprocess.call(['mkdir', path])
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        subprocess.call(['chmod', '000', path])
        metadata.from_path(path, archive_path=path, save_symlinks=True)
        errmsg = helpers.saved_errors[0] if helpers.saved_errors else ''
        WVPASS(errmsg.startswith('read Linux attr'))
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#11
0
def no_lingering_errors():
    def fail_if_errors():
        if helpers.saved_errors:
            bt = extract_stack()
            src_file, src_line, src_func, src_txt = bt[-4]
            msg = 'saved_errors ' + repr(helpers.saved_errors)
            print('! %-70s %s' %
                  ('%s:%-4d %s' %
                   (basename(src_file), src_line, msg), 'FAILED'))
            sys.stdout.flush()

    fail_if_errors()
    helpers.clear_errors()
    yield
    fail_if_errors()
    helpers.clear_errors()
示例#12
0
文件: buptest.py 项目: bup/bup
def no_lingering_errors():
    def fail_if_errors():
        if helpers.saved_errors:
            bt = extract_stack()
            src_file, src_line, src_func, src_txt = bt[-4]
            msg = 'saved_errors ' + repr(helpers.saved_errors)
            print('! %-70s %s' % ('%s:%-4d %s' % (basename(src_file),
                                                  src_line,
                                                  msg),
                                  'FAILED'))
            sys.stdout.flush()
    fail_if_errors()
    helpers.clear_errors()
    yield
    fail_if_errors()
    helpers.clear_errors()
示例#13
0
def test_from_path_error():
    if os.geteuid() == 0 or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(path, 000)
        metadata.from_path(path, archive_path=path, save_symlinks=True)
        if metadata.get_linux_file_attr:
            errmsg = _first_err()
            WVPASS(errmsg.startswith('read Linux attr'))
            clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#14
0
文件: tmetadata.py 项目: dmr/bup
def test_from_path_error():
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(path, 000)
        metadata.from_path(path, archive_path=path, save_symlinks=True)
        if metadata.get_linux_file_attr:
            errmsg = _first_err()
            WVPASS(errmsg.startswith('read Linux attr'))
            clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#15
0
文件: tmetadata.py 项目: dmr/bup
def test_apply_to_path_restricted_access():
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        clear_errors()
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(tmpdir, 000)
        m.apply_to_path(path)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('utime: '))
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#16
0
def test_apply_to_path_restricted_access():
    if os.geteuid() == 0 or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        clear_errors()
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(tmpdir, 000)
        m.apply_to_path(path)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('utime: '))
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#17
0
def test_from_path_error():
    initial_failures = wvfailure_count()
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-')
    path = tmpdir + '/foo'
    os.mkdir(path)
    m = metadata.from_path(path, archive_path=path, save_symlinks=True)
    WVPASSEQ(m.path, path)
    os.chmod(path, 000)
    metadata.from_path(path, archive_path=path, save_symlinks=True)
    if metadata.get_linux_file_attr:
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('read Linux attr'))
        clear_errors()
    if wvfailure_count() == initial_failures:
        subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
        subprocess.call(['rm', '-rf', tmpdir])
示例#18
0
def test_from_path_error():
    initial_failures = wvfailure_count()
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(dir=bup_tmp, prefix='bup-tmetadata-')
    path = tmpdir + '/foo'
    os.mkdir(path)
    m = metadata.from_path(path, archive_path=path, save_symlinks=True)
    WVPASSEQ(m.path, path)
    os.chmod(path, 000)
    metadata.from_path(path, archive_path=path, save_symlinks=True)
    if metadata.get_linux_file_attr:
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('read Linux attr'))
        clear_errors()
    if wvfailure_count() == initial_failures:
        subprocess.call(['chmod', '-R', 'u+rwX', tmpdir])
        subprocess.call(['rm', '-rf', tmpdir])
示例#19
0
def test_from_path_error():
    if is_superuser() or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix="bup-tmetadata-")
    try:
        path = tmpdir + "/foo"
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(path, 000)
        metadata.from_path(path, archive_path=path, save_symlinks=True)
        if metadata.get_linux_file_attr:
            WVPASS(len(helpers.saved_errors) == 1)
            errmsg = _first_err()
            WVPASS(errmsg.startswith("read Linux attr"))
            clear_errors()
    finally:
        subprocess.call(["chmod", "-R", "u+rwX", tmpdir])
        subprocess.call(["rm", "-rf", tmpdir])
示例#20
0
def test_apply_to_path_restricted_access():
    if is_superuser() or detect_fakeroot():
        return
    if sys.platform.startswith('cygwin'):
        return  # chmod 000 isn't effective.
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        clear_errors()
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        os.chmod(tmpdir, 000)
        m.apply_to_path(path)
        WVPASS(len(helpers.saved_errors) == 1)
        errmsg = _first_err()
        WVPASS(errmsg.startswith('utime: '))
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])
示例#21
0
文件: tmetadata.py 项目: meeee/bup
def test_restore_restricted_user_group():
    if os.geteuid() == 0 or detect_fakeroot():
        return
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        subprocess.call(['mkdir', path])
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        WVPASSEQ(m.apply_to_path(path), None)
        orig_uid = m.uid
        m.uid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else ''
        WVPASS(errmsg.startswith('lchown: '))
        clear_errors()
        m.uid = orig_uid
        m.gid = 0;
        m.apply_to_path(path, restore_numeric_ids=True)
        errmsg = str(helpers.saved_errors[0]) if helpers.saved_errors else ''
        WVPASS(errmsg.startswith('lchown: '))
        clear_errors()
    finally:
        subprocess.call(['rm', '-rf', tmpdir])