示例#1
0
int main() {
#ifdef _WINDOWS
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
    test_parse();
    test_access();
    printf("%d/%d (%3.2f%%) passed\n", test_pass, test_count, test_pass * 100.0 / test_count);
    return main_ret;
}
示例#2
0
文件: test-rrr.cpp 项目: choobin/rrr
 void test() {
     test_access();
     test_rank0();
     test_rank1();
     test_select0();
     test_select1();
     test_rank0_select0();
     test_rank1_select1();
 }
示例#3
0
static int filetest_core(struct stat buf, char test){
  switch(test){
    case 'b':
      return S_ISBLK(buf.st_mode);
    case 'c':
      return S_ISCHR(buf.st_mode);
    case 'd':
      return S_ISDIR(buf.st_mode);
    case 'e':
      //if this gets called stat succeded so the file must exist
      return 1;
    case 'f':
      return S_ISREG(buf.st_mode);
    case 'g':
      return (buf.st_mode & S_ISGID);
    case 'G':
      return (buf.st_gid == getegid());
    case 'h':
    case 'L':
      return S_ISLNK(buf.st_mode);
    case 'k':
      return (buf.st_mode & S_ISVTX);
    case 'O':
      return (buf.st_uid == geteuid());
    case 'p':
      return S_ISFIFO(buf.st_mode);
    case 'r':
      return test_access(buf, R_OK);
    case 's':
      return (buf.st_size > 0);
    case 'S':
      return S_ISSOCK(buf.st_mode);
    case 'u':
      return (buf.st_mode & S_ISUID);
    case 'w':
      return test_access(buf, W_OK);
    case 'x':
      return test_access(buf, X_OK);
    default:
      return 0;
  }
}
示例#4
0
文件: exec.c 项目: PimpMy42Sh/depot
void			start_prgm(char **env, char **argv)
{
	if (test_access(argv[0]))
		exit(1);
	if (!ft_strncmp("./", argv[0], 2))
		execve(argv[0] + 2, argv, env);
	else if ((argv[0] = hash_cmd(argv[0], env)))
		execve(argv[0], argv, env);
	command_not_find(argv[0]);
	exit(1);
}
示例#5
0
文件: test.cpp 项目: semenovf/pfs
int main ()
{
    BEGIN_TESTS(0);

    test_constructors();
    test_assignments();
    test_access();
    test_iterators();
    test_capacity();
    test_operations();
    test_search();

    return END_TESTS;
}
示例#6
0
void execute_line(char *cmdbuf)
{
  int argc;
  char *argv[MAXARGS];

  argc = parse(cmdbuf, argv);
  if (argc == 0)
    return;
  if (!strcmp(argv[0], "noop"))
    test_noop();
  else if (!strcmp(argv[0], "connect") || !strcmp(argv[0], "c"))
    test_connect(argc, argv);
  else if (!strcmp(argv[0], "disconnect") || !strcmp(argv[0], "d"))
    test_disconnect();
  else if (!strcmp(argv[0], "host"))
    test_host();
  else if (!strcmp(argv[0], "motd") || !strcmp(argv[0], "m"))
    test_motd();
  else if (!strcmp(argv[0], "query") || !strcmp(argv[0], "qy"))
    test_query(argc, argv);
  else if (!strcmp(argv[0], "auth") || !strcmp(argv[0], "a"))
    test_krb5_auth();
  else if (!strcmp(argv[0], "proxy") || !strcmp(argv[0], "p"))
    test_proxy(argc, argv);
  else if (!strcmp(argv[0], "access"))
    test_access(argc, argv);
  else if (!strcmp(argv[0], "dcm"))
    test_dcm();
  else if (!strcmp(argv[0], "script") || !strcmp(argv[0], "s"))
    test_script(argc, argv);
  else if (!strcmp(argv[0], "list_requests") ||
	  !strcmp(argv[0], "lr") || !strcmp(argv[0], "?"))
    test_list_requests();
  else if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "Q"))
    quit = 1;
  else if (!strcmp(argv[0], "version") || !strcmp(argv[0], "v"))
    test_version(argc, argv);
  else if (!strcmp(argv[0], "krb4_auth") || !strcmp(argv[0], "4"))
    test_auth();
  else
    {
      fprintf(stderr, "moira: Unknown request \"%s\".  "
	      "Type \"?\" for a request list.\n", argv[0]);
    }
}
示例#7
0
int
main(int argc, char* argv[])
{
    file_info(STDIN_FILENO);
    file_info(STDOUT_FILENO);

    test_access();
    test_faccessat();
    test_mode();
    test_chown();
    test_write_test();
    test_unlink();
    test_link();
    test_mkdir();
    test_readdir();
    test_openat();
    test_ln();

    return EXIT_SUCCESS;
}
示例#8
0
文件: test33.c 项目: AjeyBohare/minix
void test33a()
{				/* Test normal operation. */
  int stat_loc;			/* For the wait(&stat_loc) call. */

  subtest = 1;
  System("rm -rf ../DIR_33/*");

  /* To test normal access first make some files for real uid. */
  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);
	setuid(getuid());	/* (Re)set the effective ids to the
				 * real ids. */
	setgid(getgid());
	System("> rwx; chmod 700 rwx");
	System("> rw_; chmod 600 rw_");
	System("> r_x; chmod 500 r_x");
	System("> r__; chmod 400 r__");
	System("> _wx; chmod 300 _wx");
	System("> _w_; chmod 200 _w_");
	System("> __x; chmod 100 __x");
	System("> ___; chmod 000 ___");
	exit(0);

      default:
	wait(&stat_loc);
	if (stat_loc != 0) e(1);/* Alarm? */
  }
  test_access();

  /* Let's test access() on directorys. */
  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);
	setuid(getuid());	/* (Re)set the effective ids to the
				 * real ids. */
	setgid(getgid());
	System("rm -rf [_r][_w][_x]");
	System("mkdir rwx; chmod 700 rwx");
	System("mkdir rw_; chmod 600 rw_");
	System("mkdir r_x; chmod 500 r_x");
	System("mkdir r__; chmod 400 r__");
	System("mkdir _wx; chmod 300 _wx");
	System("mkdir _w_; chmod 200 _w_");
	System("mkdir __x; chmod 100 __x");
	System("mkdir ___; chmod 000 ___");
	exit(0);

      default:
	wait(&stat_loc);
	if (stat_loc != 0) e(2);/* Alarm? */
  }
  test_access();

  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);
	setuid(getuid());	/* (Re)set the effective ids to the
				 * real ids. */
	setgid(getgid());
	System("rmdir [_r][_w][_x]");
	Mkfifo("rwx");
	System("chmod 700 rwx");
	Mkfifo("rw_");
	System("chmod 600 rw_");
	Mkfifo("r_x");
	System("chmod 500 r_x");
	Mkfifo("r__");
	System("chmod 400 r__");
	Mkfifo("_wx");
	System("chmod 300 _wx");
	Mkfifo("_w_");
	System("chmod 200 _w_");
	Mkfifo("__x");
	System("chmod 100 __x");
	Mkfifo("___");
	System("chmod 000 ___");
	exit(0);

      default:
	wait(&stat_loc);
	if (stat_loc != 0) e(3);/* Alarm? */
  }
  test_access();

  /* Remove all the fifos. */
  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);
	setuid(getuid());
	setgid(getgid());
	System("rm -rf [_r][_w][_x]");
	exit(0);

      default:
	wait(&stat_loc);
	if (stat_loc != 0) e(4);/* Alarm? */
  }
}
int main(int argc, char *argv[])
{
    hash_table_t *ht_ip_stats;
    struct prealloc_pool *ip_stats_pool;
    exportlist_t pexport;
    int root, read, write, mdonly_read, mdonly_write,
        root_user, uid, operation, export_check_result,
        predicted_result, nonroot, accesstype,
        return_status=0;
    char *ip = "192.0.2.10";
    //  char *match_str = "192.0.2.10";
    char *match_str = "*";
    char *hostname = "hostname";

    SetDefaultLogging("TEST");
    SetNamePgm("test_mnt_proto");

    init_vars(&ht_ip_stats, &ip_stats_pool);

    printf("TESTING THE NEW ACCESS LIST FORMAT\n------------------------------------\n");
    printf("TEST: root read write mdonly_read mdonly_write : uid operation\n");
    /* loop through all combinations of new access list uses. */
    for(root=0; root < 2; root++)
        for(read=0; read < 2; read++)
            for(write=0; write < 2; write++)
                for(mdonly_read=0; mdonly_read < 2; mdonly_read++)
                    for(mdonly_write=0; mdonly_write < 2; mdonly_write++)
                    {
                        memset(&pexport, 0, sizeof(pexport));

                        /* These strings come from local defines in ../support/exports.c */
                        if (root)
                            parseAccessParam("Root_Access", match_str, &pexport, EXPORT_OPTION_ROOT);
                        if (read)
                            parseAccessParam("R_Access", match_str, &pexport, EXPORT_OPTION_READ_ACCESS);
                        if (write)
                            parseAccessParam("RW_Access", match_str, &pexport,
                                             EXPORT_OPTION_READ_ACCESS | EXPORT_OPTION_WRITE_ACCESS);
                        if (mdonly_read)
                            parseAccessParam("MDONLY_RO_Access", match_str, &pexport, EXPORT_OPTION_MD_READ_ACCESS);
                        if (mdonly_write)
                            parseAccessParam("MDONLY_Access", match_str, &pexport,
                                             EXPORT_OPTION_MD_WRITE_ACCESS | EXPORT_OPTION_MD_READ_ACCESS);

                        /* This is critical */
                        pexport.new_access_list_version = 1;

                        /* With this export entry test both root and user access. */
                        for(root_user=0; root_user < 2; root_user++)
                            for(operation=0; operation < 5; operation++)
                            {
                                if (root_user == 0)
                                    uid = USER_UID;
                                else
                                    uid = ROOT_UID;

                                printf("TEST: %d %d %d %d %d : %d ",
                                       root, read, write, mdonly_read, mdonly_write,uid);
                                if (operation == TEST_MOUNT)
                                    printf("TEST_MOUNT\n");
                                else if (operation == TEST_READ)
                                    printf("READ\n");
                                else if (operation == TEST_WRITE)
                                    printf("WRITE\n");
                                else if (operation == MDONLY_READ)
                                    printf("MDONLY_READ\n");
                                else if (operation == MDONLY_WRITE)
                                    printf("MDONLY_WRITE\n");

                                export_check_result = test_access(ip, hostname, ht_ip_stats, ip_stats_pool,
                                                                  &pexport, uid, operation);

                                /* predict how the result will turn out */
                                predicted_result = predict(ip, hostname, root, read, write,
                                                           mdonly_read, mdonly_write, uid, operation);

                                /* report on what was expected vs what we received */
                                if (expected(predicted_result, export_check_result) == 1)
                                    return_status = 1;
                            }
                    }

    /* loop through all combinations of old access list uses. */
    printf("\n\nTESTING THE OLDER ACCESS LIST FORMAT\n------------------------------------\n");
    printf("TEST: root nonroot accesstype : uid operation\n");
    /* loop through all combinations of new access list uses. */
    for(root=0; root < 2; root++)
        for(nonroot=0; nonroot < 2; nonroot++)
            for(accesstype=1; accesstype < 4; accesstype++)
            {
                memset(&pexport, 0, sizeof(pexport));

                /* These strings come from local defines in ../support/exports.c */
                if (root)
                    parseAccessParam("Root_Access", match_str, &pexport, EXPORT_OPTION_ROOT);
                if (nonroot)
                    parseAccessParam("Access", match_str, &pexport, EXPORT_OPTION_READ_ACCESS|EXPORT_OPTION_WRITE_ACCESS);

                if (accesstype == TEST_READ)
                    pexport.access_type = ACCESSTYPE_RO;
                else if (accesstype == TEST_WRITE)
                    pexport.access_type = ACCESSTYPE_RW;
                else if (accesstype == MDONLY_READ)
                    pexport.access_type = ACCESSTYPE_MDONLY_RO;
                else if (accesstype == MDONLY_WRITE)
                    pexport.access_type = ACCESSTYPE_MDONLY;
                else
                    printf("FAIL: INVALID access_type \n");

                /* This is critical */
                pexport.new_access_list_version = 0;

                /* With this export entry test both root and user access. */
                for(root_user=0; root_user < 2; root_user++)
                    for(operation=0; operation < 5; operation++)
                    {
                        if (root_user == 0)
                            uid = USER_UID;
                        else
                            uid = ROOT_UID;

                        printf("TEST: %d %d ", root, nonroot);
                        if (accesstype == TEST_READ)
                            printf("ACCESSTYPE_RO ");
                        else if (accesstype == TEST_WRITE)
                            printf("ACCESSTYPE_RW ");
                        else if (accesstype == MDONLY_READ)
                            printf("ACCESSTYPE_MDONLY_RO ");
                        else if (accesstype == MDONLY_WRITE)
                            printf("ACCESSTYPE_MDONLY ");
                        else
                            printf("INVALID ");
                        printf(": %d ",uid);
                        if (operation == TEST_MOUNT)
                            printf("TEST_MOUNT\n");
                        else if (operation == TEST_READ)
                            printf("READ\n");
                        else if (operation == TEST_WRITE)
                            printf("WRITE\n");
                        else if (operation == MDONLY_READ)
                            printf("MDONLY_READ\n");
                        else if (operation == MDONLY_WRITE)
                            printf("MDONLY_WRITE\n");

                        export_check_result = test_access(ip, hostname, ht_ip_stats, ip_stats_pool,
                                                          &pexport, uid, operation);

                        /* predict how the result will turn out */
                        if ((operation == TEST_WRITE || operation == MDONLY_WRITE) && accesstype == TEST_READ)
                            predicted_result = EXPORT_WRITE_ATTEMPT_WHEN_RO;
                        else
                            predicted_result = old_predict(ip, hostname, root, nonroot,
                                                           accesstype, uid, operation);

                        /* report on what was expected vs what we received */
                        if (expected(predicted_result, export_check_result) == 1)
                            return_status = 1;
                    }
            }

    printf("----------------------------------------------------\n");
    if (!return_status)
        printf("ALL ACCESS LIST TYPE TESTS COMPLETED SUCCESSFULLY!!\n");
    else
        printf("ACCESS LIST TYPE TESTS FAILED!!\n");
    printf("----------------------------------------------------\n");

    return return_status;
}
示例#10
0
文件: test.c 项目: dezelin/kBuild
static int
filstat(char *nm, enum token mode)
{
	struct stat s;

	if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))
		return 0;

	switch (mode) {
	case FILRD:
		return test_access(&s, S_IROTH);
	case FILWR:
		return test_access(&s, S_IWOTH);
	case FILEX:
		return test_access(&s, S_IXOTH);
	case FILEXIST:
		return 1; /* the successful lstat()/stat() is good enough */
	case FILREG:
		return S_ISREG(s.st_mode);
	case FILDIR:
		return S_ISDIR(s.st_mode);
	case FILCDEV:
#ifdef S_ISCHR
		return S_ISCHR(s.st_mode);
#else
		return 0;
#endif
	case FILBDEV:
#ifdef S_ISBLK
		return S_ISBLK(s.st_mode);
#else
		return 0;
#endif
	case FILFIFO:
#ifdef S_ISFIFO
		return S_ISFIFO(s.st_mode);
#else
		return 0;
#endif
	case FILSOCK:
#ifdef S_ISSOCK
		return S_ISSOCK(s.st_mode);
#else
		return 0;
#endif
	case FILSYM:
#ifdef S_ISLNK
		return S_ISLNK(s.st_mode);
#else
		return 0;
#endif
	case FILSUID:
		return (s.st_mode & S_ISUID) != 0;
	case FILSGID:
		return (s.st_mode & S_ISGID) != 0;
	case FILSTCK:
#ifdef S_ISVTX
		return (s.st_mode & S_ISVTX) != 0;
#else
		return 0;
#endif
	case FILGZ:
		return s.st_size > (off_t)0;
	case FILUID:
		return s.st_uid == geteuid();
	case FILGID:
		return s.st_gid == getegid();
	default:
		return 1;
	}
}