Exemplo n.º 1
0
END_TEST

START_TEST(test_remove_subtree)
{
    int ret;
    char origpath[PATH_MAX+1];

    errno = 0;
    fail_unless(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
    fail_unless(errno == 0, "Cannot getcwd\n");

    DEBUG(SSSDBG_FUNC_DATA, "About to delete %s\n", dir_path);

    /* create a file */
    ret = chdir(dir_path);
    fail_if(ret == -1, "Cannot chdir1\n");

    ret = create_simple_file("bar", "bar");
    fail_if(ret == -1, "Cannot create file1\n");

    /* create a subdir and file inside it */
    ret = mkdir("subdir", 0700);
    fail_if(ret == -1, "Cannot create subdir\n");

    ret = chdir("subdir");
    fail_if(ret == -1, "Cannot chdir\n");

    ret = create_simple_file("foo", "foo");
    fail_if(ret == -1, "Cannot create file\n");

    /* create another subdir, empty this time */
    ret = mkdir("subdir2", 0700);
    fail_if(ret == -1, "Cannot create subdir\n");

    ret = chdir(origpath);
    fail_if(ret == -1, "Cannot chdir2\n");

    /* go back */
    ret = chdir(origpath);
    fail_if(ret == -1, "Cannot chdir\n");

    /* and finally wipe it out.. */
    ret = sss_remove_subtree(dir_path);
    fail_unless(ret == EOK, "remove_subtree failed\n");

    /* check if really gone */
    ret = access(dir_path, F_OK);
    fail_unless(ret == 0, "directory was deleted\n");

    ret = rmdir(dir_path);
    fail_unless(ret == 0, "unable to delete root directory\n");
}
Exemplo n.º 2
0
END_TEST

START_TEST(test_simple_copy)
{
    int ret;
    char origpath[PATH_MAX+1];
    char *tmp;
    int fd = -1;

    errno = 0;
    fail_unless(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
    fail_unless(errno == 0, "Cannot getcwd\n");

    /* create a file */
    ret = chdir(dir_path);
    fail_if(ret == -1, "Cannot chdir1\n");

    ret = create_simple_file("bar", "bar");
    fail_if(ret == -1, "Cannot create file1\n");

    /* create a subdir and file inside it */
    ret = mkdir("subdir", 0700);
    fail_if(ret == -1, "Cannot create subdir\n");

    ret = chdir("subdir");
    fail_if(ret == -1, "Cannot chdir\n");

    ret = create_simple_file("foo", "foo");
    fail_if(ret == -1, "Cannot create file\n");

    /* go back */
    ret = chdir(origpath);
    fail_if(ret == -1, "Cannot chdir\n");

    /* and finally copy.. */
    DEBUG(SSSDBG_FUNC_DATA,
          "Will copy from '%s' to '%s'\n", dir_path, dst_path);
    ret = copy_tree(dir_path, dst_path, 0700, uid, gid);
    fail_unless(ret == EOK, "copy_tree failed\n");

    /* check if really copied */
    ret = access(dst_path, F_OK);
    fail_unless(ret == 0, "destination directory not there\n");

    tmp = talloc_asprintf(test_ctx, "%s/bar", dst_path);
    ret = check_and_open_readonly(tmp, &fd, uid, gid, 0700, CHECK_REG);
    fail_unless(ret == EOK, "Cannot open %s\n");
    close(fd);
    talloc_free(tmp);
}
Exemplo n.º 3
0
END_TEST

START_TEST(test_copy_symlink)
{
    int ret;
    char origpath[PATH_MAX+1];
    char *tmp;
    struct stat statbuf;

    errno = 0;
    fail_unless(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
    fail_unless(errno == 0, "Cannot getcwd\n");

    /* create a subdir */
    ret = chdir(dir_path);
    fail_if(ret == -1, "Cannot chdir\n");

    ret = create_simple_file("footarget", "foo");
    fail_if(ret == -1, "Cannot create file\n");

    ret = symlink("footarget", "foolink");
    fail_if(ret == -1, "Cannot create symlink\n");

    /* go back */
    ret = chdir(origpath);
    fail_if(ret == -1, "Cannot chdir\n");

    /* and finally copy.. */
    DEBUG(SSSDBG_FUNC_DATA,
          "Will copy from '%s' to '%s'\n", dir_path, dst_path);
    ret = copy_tree(dir_path, dst_path, 0700, uid, gid);
    fail_unless(ret == EOK, "copy_tree failed\n");

    /* check if really copied */
    ret = access(dst_path, F_OK);
    fail_unless(ret == 0, "destination directory not there\n");

    tmp = talloc_asprintf(test_ctx, "%s/foolink", dst_path);
    ret = lstat(tmp, &statbuf);
    fail_unless(ret == 0, "cannot stat the symlink %s\n", tmp);
    fail_unless(S_ISLNK(statbuf.st_mode), "%s not a symlink?\n", tmp);
    talloc_free(tmp);
}
Exemplo n.º 4
0
END_TEST

START_TEST(test_copy_file)
{
    TALLOC_CTX *tmp_ctx = talloc_new(test_ctx);
    int ret;
    char origpath[PATH_MAX+1];
    char *foo_path;
    char *bar_path;
    int fd = -1;

    errno = 0;
    fail_unless(getcwd(origpath, PATH_MAX) == origpath, "Cannot getcwd\n");
    fail_unless(errno == 0, "Cannot getcwd\n");

    /* create a file */
    ret = chdir(dir_path);
    fail_if(ret == -1, "Cannot chdir1\n");

    ret = create_simple_file("foo", "foo");
    fail_if(ret == -1, "Cannot create foo\n");
    foo_path = talloc_asprintf(tmp_ctx, "%s/foo", dir_path);
    bar_path = talloc_asprintf(tmp_ctx, "%s/bar", dst_path);

    /* create a file */
    ret = chdir(origpath);
    fail_if(ret == -1, "Cannot chdir1\n");

    /* Copy this file to a new file */
    DEBUG(SSSDBG_FUNC_DATA,
          "Will copy from 'foo' to 'bar'\n");
    ret = sss_copy_file_secure(foo_path, bar_path, 0700, uid, gid, 0);
    fail_unless(ret == EOK, "copy_file_secure failed\n");

    /* check if really copied */
    ret = access(bar_path, F_OK);
    fail_unless(ret == 0, "destination file 'bar' not there\n");

    ret = check_and_open_readonly(bar_path, &fd, uid, gid, S_IFREG|S_IRWXU, 0);
    fail_unless(ret == EOK, "Cannot open %s\n", bar_path);
    close(fd);
    talloc_free(tmp_ctx);
}