コード例 #1
0
ファイル: krb5_utils-tests.c プロジェクト: nguay/SSSD
END_TEST

START_TEST(test_private_ccache_dir_in_user_dir)
{
    int ret;
    char *cwd;
    char *user_dir;
    char *dn1;
    char *dn2;
    char *dn3;
    char *filename;
    uid_t uid = getuid();
    gid_t gid = getgid();

    if (uid == 0) {
        uid = 12345;
        gid = 12345;
    }

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    user_dir = talloc_asprintf(tmp_ctx, "%s/%s/user", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(user_dir != NULL, "talloc_asprintf failed.");
    ret = mkdir(user_dir, 0700);
    fail_unless(ret == EOK, "mkdir failed.");
    ret = chown(user_dir, uid, gid);
    fail_unless(ret == EOK, "chown failed.");

    dn1 = talloc_asprintf(tmp_ctx, "%s/a", user_dir);
    fail_unless(dn1 != NULL, "talloc_asprintf failed.");
    dn2 = talloc_asprintf(tmp_ctx, "%s/b", dn1);
    fail_unless(dn2 != NULL, "talloc_asprintf failed.");
    dn3 = talloc_asprintf(tmp_ctx, "%s/c", dn2);
    fail_unless(dn3 != NULL, "talloc_asprintf failed.");
    filename = talloc_asprintf(tmp_ctx, "%s/ccfile", dn3);
    fail_unless(filename != NULL, "talloc_asprintf failed.");

    ret = chmod(user_dir, 0600);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
                               "while x-bit is missing.");

    ret = chmod(user_dir, 0700);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EOK, "cc_file_create failed.");

    check_dir(dn3, uid, gid, 0700);
    RMDIR(dn3);
    check_dir(dn2, uid, gid, 0700);
    RMDIR(dn2);
    check_dir(dn1, uid, gid, 0700);
    RMDIR(dn1);
    RMDIR(user_dir);
}
コード例 #2
0
ファイル: krb5_utils-tests.c プロジェクト: abbra/sssd
END_TEST

START_TEST(test_private_ccache_dir_in_wrong_user_dir)
{
    int ret;
    char *cwd;
    char *dirname;
    char *subdirname;
    char *filename;

    fail_unless(getuid() == 0, "This test must be run as root.");

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    dirname = talloc_asprintf(tmp_ctx, "%s/%s/priv_ccdir", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(dirname != NULL, "talloc_asprintf failed.");
    ret = mkdir(dirname, 0700);
    fail_unless(ret == EOK, "mkdir failed.\n");
    ret = chown(dirname, 12346, 12346);
    fail_unless(ret == EOK, "chown failed.\n");
    subdirname = talloc_asprintf(tmp_ctx, "%s/subdir", dirname);
    fail_unless(subdirname != NULL, "talloc_asprintf failed.");
    filename = talloc_asprintf(tmp_ctx, "%s/ccfile", subdirname);
    fail_unless(filename != NULL, "talloc_asprintf failed.");

    ret = sss_krb5_precreate_ccache(filename, 12345, 12345);
    fail_unless(ret == EINVAL, "Creating private ccache dir in wrong user "
                               "dir does not failed with EINVAL.");

    RMDIR(dirname);
}
コード例 #3
0
ファイル: plist.c プロジェクト: coyizumi/cs111
/* Selectively delete a hierarchy */
int
delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs)
{
    char *cp1, *cp2;

    cp1 = cp2 = strdup(dir);
    if (!fexists(dir) && !issymlink(dir)) {
	if (!ign_err)
	    warnx("%s '%s' doesn't exist",
		isdir(dir) ? "directory" : "file", dir);
	return !ign_err;
    }
    else if (nukedirs) {
	if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
	    return 1;
    }
    else if (isdir(dir) && !issymlink(dir)) {
	if (RMDIR(dir) && !ign_err)
	    return 1;
    }
    else {
	if (REMOVE(dir, ign_err))
	    return 1;
    }

    if (!nukedirs)
	return 0;
    while (cp2) {
	if ((cp2 = strrchr(cp1, '/')) != NULL)
	    *cp2 = '\0';
	if (!isemptydir(dir))
	    return 0;
	if (RMDIR(dir) && !ign_err) {
	    if (!fexists(dir))
		warnx("directory '%s' doesn't exist", dir);
	    else
		return 1;
	}
	/* back up the pathname one component */
	if (cp2) {
	    cp1 = strdup(dir);
	}
    }
    return 0;
}
コード例 #4
0
ファイル: krb5_utils-tests.c プロジェクト: nguay/SSSD
END_TEST

START_TEST(test_priv_ccache_dir)
{
    int ret;
    char *cwd;
    char *testpath;
    char *dirname;
    char *subdir;
    char *filename;
    uid_t uid = 12345;
    gid_t gid = 12345;

    fail_unless(getuid() == 0, "This test must be run as root.");

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    testpath = talloc_asprintf(tmp_ctx, "%s/%s", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(testpath != NULL, "talloc_asprintf failed.");
    dirname = talloc_asprintf(tmp_ctx, "%s/base", testpath);
    subdir = talloc_asprintf(tmp_ctx, "%s/priv_ccdir", dirname);
    fail_unless(subdir != NULL, "talloc_asprintf failed.");
    filename = talloc_asprintf(tmp_ctx, "%s/ccfile", subdir);
    fail_unless(filename != NULL, "talloc_asprintf failed.");

    ret = chmod(testpath, 0754);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
                               "while x-bit is missing.");

    ret = chmod(testpath, 0755);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EOK, "cc_file_create failed.");

    check_dir(subdir, uid, gid, 0700);
    RMDIR(subdir);
    check_dir(dirname, 0, 0, 0755);
    RMDIR(dirname);
}
コード例 #5
0
ファイル: trap.c プロジェクト: Protovision/io-lua
int	trap_RemoveDirectory(lua_State *s)
{
	const char *dir;

	trap_args(s, "RemoveDirectory", "s", &dir);
	dir = datapath(dir);
	if (RMDIR(dir) < 0) {
		FATAL("Failed to remove directory: %s", dir);
	}
	return 0;
}
コード例 #6
0
	/*******************************************************
		Function: cleanup_all_files

		

	 *******************************************************/
void
cleanup_all_files (void)
{
    int i;

    if (ld_ipa_opt[LD_IPA_KEEP_TEMPS].flag)
	return;
    
    for (i = tmp_list_size - 1; i > 0; i--)
	UNLINK (tmp_list[i]);

    if (tmp_list_size >= 1)
	RMDIR (tmp_list[0]);

} /* cleanup_all_files */
コード例 #7
0
ファイル: ipa_process.c プロジェクト: qiyao/xcc
	/*******************************************************
		Function: cleanup_all_files

		

	 *******************************************************/
void
cleanup_all_files (void)
{
    int i;

#ifdef  TARG_MIPS
    if (option[OPT_KEEP_TEMPS].flag)
	return;
#else
#endif
    
    for (i = tmp_list_size - 1; i > 0; i--)
	UNLINK (tmp_list[i]);

    if (tmp_list_size >= 1)
	RMDIR (tmp_list[0]);

} /* cleanup_all_files */
コード例 #8
0
ファイル: qdir_unix.cpp プロジェクト: Acidburn0zzz/doxygen
bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const
{
    return RMDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
}