Beispiel #1
0
PUBLIC	void	test_sp_lookup()

{
  errstat	err;
  capset	new_capset;


  (void)strcpy(testname, "test_sp_lookup()");
  if (verbose)  printf("\n----  %s  ----\n", testname);

  /* Look up an entry with a very long name in the default directory. */
  err = sp_lookup(SP_DEFAULT, long_name, &new_capset);
  if (test_good(err, "1a")) {
    check_capsets("1a", &aux_capset, &new_capset);
    cs_free(&new_capset);
  }

  /* Look up an entry in a regular directory with minimal rights. */
  err = sp_lookup(&rgt_capsets[READ], def_name, &new_capset);
  if (test_good(err, "1b")) {
    check_capsets("1b", &rgt_capsets[DEF], &new_capset);
    cs_free(&new_capset);
  }

}  /* test_sp_lookup() */
Beispiel #2
0
PUBLIC	void	test_b_size()
/* The name says it all. */

{
    b_fsize	size;
    errstat	err;
    capability	tmp_cap;


    (void)strcpy(testname, "test_b_size()");
    if (verbose)  printf("\n----  %s  ----\n", testname);

    /* Get size of empty file. */
    err = b_size(&empty_cap, &size);
    if (test_good(err, "1a"))
        TEST_ASSERT(size == ZERO, TEST_SERIOUS,
                    ("%s, 1a: size should be 0 but is %ld\n", testname, (long)size));

    /* Get size of file with one byte. */
    err = b_size(&one_cap, &size);
    if (test_good(err, "1b"))
        TEST_ASSERT(size == ONE, TEST_SERIOUS,
                    ("%s, 1b: size should be 1 but is %ld\n", testname, (long)size));

    /* Get size of normal committed file. */
    err = b_size(&commit_cap, &size);
    if (test_good(err, "1c"))
        TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
                    ("%s, 1c: size should be %ld but is %ld\n",
                     testname, (long)AVG_SIZE, (long)size));

    /* Get size with minimum required rights. */
    err = std_restrict(&commit_cap, BS_RGT_READ, &tmp_cap);
    if (test_good(err, "1d, std_restrict()")) {
        err = b_size(&tmp_cap, &size);
        if (test_good(err, "1d"))
            TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
                        ("%s, 1d: size should be %ld but is %ld\n",
                         testname, (long)AVG_SIZE, (long)size));
    }

}/* test_b_size() */
int main(int argc, char ** argv)
{
#ifndef DISABLE_BOOST_PROGRAM_OPTIONS
  test_default();
  test_good();
  test_empty();

  return 0;
#else
  return 77;
#endif  // DISABLE_BOOST_PROGRAM_OPTIONS
}
Beispiel #4
0
PUBLIC	void	test_sp_discard()
/* This should be the final test because it can mess up the test directory
 * structure severely.
 */

{
  errstat	err;
  bool		ok;
  capset	tmp_capset, disc_capset;


  (void)strcpy(testname, "test_sp_discard()");
  if (verbose)  printf("\n----  %s  ----\n", testname);

  /* Discard an empty directory with minimal rights. */

  /* Create a new directory. */
  err = sp_create(SP_DEFAULT, def_colnames, &tmp_capset);
  if (test_good(err, "1a, sp_create()")) {

    /* Append and look-up to get a restricted capset. */
    err = sp_append(SP_DEFAULT, aux_name, &tmp_capset, 1, rgt_masks[DEL]);
    if (ok = test_good(err, "1a, sp_append()")) {
      err = sp_lookup(SP_DEFAULT, aux_name, &disc_capset);
      if (ok = test_good(err, "1a, sp_lookup()")) {
	/* Try to discard the restricted empty capset. */
        err = sp_discard(&disc_capset);
	ok = test_good(err, "1a");
	/* Free the space for the capset. */
        cs_free(&disc_capset);
      }

      /* Delete the entry for the original capset. */
      err = sp_delete(SP_DEFAULT, aux_name);
      (void)test_good(err, "1a, sp_delete()");
    }

    if (!ok) {
      /* Destroy the directory using the unrestricted capset. */
      err = sp_discard(&tmp_capset);
      (void)test_good(err, "1a, sp_discard()");
    }
    cs_free(&tmp_capset);
  }

}  /* test_sp_discard() */
Beispiel #5
0
PUBLIC	void	test_sp_traverse()

{
  errstat	err;
  char		tmp_path[1024], *path;
  capset	new_capset;


  (void)strcpy(testname, "test_sp_traverse()");
  if (verbose)  printf("\n----  %s  ----\n", testname);

  /* Traverse absolute path using the default capset. */
  sprintf(tmp_path, "%s/%s/../%s/%s", testpath, def_name, def_name, def_name);
  path = tmp_path;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1a")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1a (directory names don't compare)\n", testname));
    check_capsets("1a", &dir_capset, &new_capset);
    cs_free(&new_capset);
  }

  /* Traverse absolute path using a regular capset. */
  path = tmp_path;
  err = sp_traverse(&rgt_capsets[NORGT], (const char **) &path, &new_capset);
  if (test_good(err, "1b")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1b (directory names don't compare)\n", testname));
    check_capsets("1b", &dir_capset, &new_capset);
    cs_free(&new_capset);
  }

  /* Traverse path relative to a regular directory. */
  sprintf(tmp_path, "%s/../%s/./%s", def_name, def_name, def_name);
  path = tmp_path;
  err = sp_traverse(&rgt_capsets[READ], (const char **) &path, &new_capset);
  if (test_good(err, "1c")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1c (directory names don't compare)\n", testname));
    check_capsets("1c", &rgt_capsets[DEF], &new_capset);
    cs_free(&new_capset);
  }

  /* Traverse empty path relative to the default directory. */
  tmp_path[0] = (char)0;
  path = tmp_path;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1d")) {
    TEST_ASSERT(strcmp(path, "") == 0, TEST_SERIOUS,
		("%s, 1d (directory names don't compare)\n", testname));
    cs_free(&new_capset);
  }

  /* Traverse absolute path to the root directory. */
  tmp_path[0] = '/'; tmp_path[1] = '\0';
  path = tmp_path;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1e")) {
    TEST_ASSERT(strcmp(path, "") == 0, TEST_SERIOUS,
		("%s, 1e (directory names don't compare)\n", testname));
    cs_free(&new_capset);
  }

  /* Traverse path with single directory name. */
  path = def_name;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1f")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1f (directory names don't compare)\n", testname));
    cs_free(&new_capset);
  }

  /* Traverse path with single directory name with minimal rights. */
  path = def_name;
  err = sp_traverse(&rgt_capsets[NORGT], (const char **) &path, &new_capset);
  if (test_good(err, "1g")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1g (directory names don't compare)\n", testname));
    check_capsets("1g", &rgt_capsets[NORGT], &new_capset);
    cs_free(&new_capset);
  }

  /* Traverse path relative to the default directory. */
  sprintf(tmp_path, "%s/../%s/%s", def_name, def_name, def_name);
  path = tmp_path;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1h")) {
    TEST_ASSERT(strcmp(path, def_name) == 0, TEST_SERIOUS,
		("%s, 1h (directory names don't compare)\n", testname));
    check_capsets("1h", &def_capset, &new_capset);
    cs_free(&new_capset);
  }

  /* Traverse path ending with a '/'. */
  sprintf(tmp_path, "%s/%s/", testpath, def_name);
  path = tmp_path;
  err = sp_traverse(SP_DEFAULT, (const char **) &path, &new_capset);
  if (test_good(err, "1i")) {
    TEST_ASSERT(strcmp(path, "") == 0, TEST_SERIOUS,
		("%s, 1i (directory names don't compare)\n", testname));
    check_capsets("1i", &dir_capset, &new_capset);
    cs_free(&new_capset);
  }

}  /* test_sp_traverse() */
Beispiel #6
0
PUBLIC	void	test_combi()

{
  errstat	err;
  bool		ok, ok1;
  capability	new_cap, tmp_cap;
  b_fsize	size;


  (void)strcpy(testname, "test_many()");
  if (verbose)  printf("\n----  %s  ----\n", testname);

  /* Create an uncommitted file with the same contents as the original. */
  err = b_create(&commit_cap, write_buf, AVG_SIZE, 0, &new_cap);
  if (test_good(err, "1a, b_create()")) {
    TEST_ASSERT(ok = !obj_cmp(&new_cap, &commit_cap), TEST_SERIOUS,
			("%s, 1a: new object expected\n", testname));

    /* Modify it. */
    err = b_modify(&new_cap, AVG_OFFS, write_buf, AUX_SIZE, 0, &tmp_cap);
    if (test_good(err, "1a, b_modify()")) {

      /* The capability shouldn't change. */
      TEST_ASSERT(ok1 = cap_cmp(&tmp_cap, &new_cap), TEST_SERIOUS,
			("%s, 1a: previous capability expected\n", testname));

      /* Clean up possible debris. */
      if (!ok1) {
	if (ok) {
	  err = std_destroy(&new_cap);
	  (void)test_good(err, "std_destroy()");
	}

	new_cap = tmp_cap;
	err = std_destroy(&tmp_cap);
	(void)test_good(err, "std_destroy()");
	TEST_ASSERT(ok = !obj_cmp(&new_cap, &commit_cap), TEST_SERIOUS,
			("%s, 1a: new object expected\n", testname));
      }

      /* Delete some. */
      err = b_delete(&new_cap, AVG_OFFS, AUX_SIZE, 0, &tmp_cap);
      if (test_good(err, "1a, b_delete()")) {
	TEST_ASSERT(ok1 = cap_cmp(&tmp_cap, &new_cap), TEST_SERIOUS,
			("%s, 1a: previous capability expected\n", testname));

	if (!ok1) {
	  if (ok) {
	    err = std_destroy(&new_cap);
	    (void)test_good(err, "std_destroy()");
	  }

	  new_cap = tmp_cap;
	  err = std_destroy(&tmp_cap);
	  (void)test_good(err, "std_destroy()");
	  TEST_ASSERT(ok = !obj_cmp(&new_cap, &commit_cap), TEST_SERIOUS,
			("%s, 1a: new object expected\n", testname));
	}

	/* Insert some (restore original contents) and commit. */
	err = b_insert(&new_cap, AVG_OFFS, write_buf + (int)AVG_OFFS,
					AUX_SIZE, SAFE_COMMIT, &tmp_cap);
	if (test_good(err, "1a, b_insert()")) {

          /* The capability should be the same as the original one. */
	  TEST_ASSERT(ok1 = cap_cmp(&tmp_cap, &commit_cap), TEST_SERIOUS,
			("%s, 1a: original capability expected\n", testname));
	  TEST_ASSERT(!obj_cmp(&tmp_cap, &new_cap), TEST_SERIOUS,
			("%s, 1a: new object expected\n", testname));

	  err = b_size(&tmp_cap, &size);
	  if (test_good(err, "1a, b_size()"))
		TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
			("%s, 1a: size should be %ld but is %ld\n",
				testname, (long)AVG_SIZE, (long)size));

	  memset(read_buf, 0, (size_t)BIG_SIZE);
	  err = b_read(&tmp_cap, ZERO, read_buf, BIG_SIZE, &size);
	  if (test_good(err, "1a, b_read()")) {
	    TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
			("%s, 1a: bytes read should be %ld but is %ld\n",
				testname, (long)AVG_SIZE, (long)size));
	    TEST_ASSERT(memcmp(read_buf, write_buf, (size_t)size)==0,TEST_SERIOUS,
		("%s, 1a: data read do not match original data\n", testname));
	  }

	  if (!ok1) {
	    err = std_destroy(&tmp_cap);
	    (void)test_good(err, "1a, std_destroy()");
	  }

	  ok = FALSE;	/* Nothing left to destroy. */
	}
      }
    }

    if (ok) {
      err = std_destroy(&new_cap);
      (void)test_good(err, "1a, std_destroy()");
    }
  }

}  /* test_many() */
Beispiel #7
0
PUBLIC	void	test_b_read()

{
    errstat	err;
    capability	tmp_cap;
    b_fsize	size;


    (void)strcpy(testname, "test_b_read()");
    if (verbose)  printf("\n----  %s  ----\n", testname);

    /* Read some bytes from the beginning of an empty file. */
    err = b_read(&empty_cap, ZERO, read_buf, AVG_SIZE, &size);
    if (test_good(err, "1a"))
        TEST_ASSERT(size == ZERO, TEST_SERIOUS,
                    ("%s, 1a: bytes read should be 0 but is %ld\n", testname, (long)size));

    /* Read some bytes from the beginning of a full file. */
    memset(read_buf, 0, (size_t)AUX_SIZE);
    err = b_read(&commit_cap, ZERO, read_buf, AUX_SIZE, &size);
    if (test_good(err, "1b")) {

        /* Check the size and contents of the file. */
        TEST_ASSERT(size == AUX_SIZE, TEST_SERIOUS,
                    ("%s, 1b: bytes read should be %ld but is %ld\n",
                     testname, (long)AUX_SIZE, (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf, (size_t)size) == 0, TEST_SERIOUS,
                    ("%s, 1b: data read do not match original data\n", testname));
    }

    /* Read all bytes from the middle of a full file. */
    memset(read_buf, 0, (size_t)AUX_SIZE);
    err = b_read(&commit_cap, AVG_OFFS, read_buf, AUX_SIZE, &size);
    if (test_good(err, "1c")) {
        TEST_ASSERT(size == AUX_SIZE, TEST_SERIOUS,
                    ("%s, 1c: bytes read should be %ld but is %ld\n",
                     testname, (long)AUX_SIZE, (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf + (int)AVG_OFFS, (size_t)size) == 0,
                    TEST_SERIOUS,("%s, 1c: data read do not match original data\n", testname));
    }

    /* Read 0 bytes from the middle of a full file. */
    err = b_read(&commit_cap, AVG_OFFS, read_buf, ZERO, &size);
    if (test_good(err, "1d"))
        TEST_ASSERT(size == ZERO, TEST_SERIOUS,
                    ("%s, 1d: bytes read should be 0 but is %ld\n", testname, (long)size));

    /* Read some bytes from the end of a full file. */
    err = b_read(&commit_cap, AVG_SIZE, read_buf, AUX_SIZE, &size);
    if (test_good(err, "1e"))
        TEST_ASSERT(size == ZERO, TEST_SERIOUS,
                    ("%s, 1e: bytes read should be 0 but is %ld\n", testname, (long)size));

    /* Read beyond the end from the middle of a full file. */
    memset(read_buf, 0, (size_t)AVG_SIZE);
    err = b_read(&commit_cap, AVG_OFFS, read_buf, AVG_SIZE, &size);
    if (test_good(err, "1f")) {
        TEST_ASSERT(size == AVG_SIZE-AVG_OFFS, TEST_SERIOUS,
                    ("%s, 1f: bytes read should be %ld but is %ld\n",
                     testname, (long)(AVG_SIZE-AVG_OFFS), (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf + (int)AVG_OFFS, (size_t)size) == 0,
                    TEST_SERIOUS,("%s, 1f: data read do not match original data\n", testname));
    }

    /* Read an entire full file plus one extra byte. */
    memset(read_buf, 0, (size_t)(AVG_SIZE+ONE));
    err = b_read(&commit_cap, ZERO, read_buf, AVG_SIZE+ONE, &size);
    if (test_good(err, "1g")) {
        TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
                    ("%s, 1g: bytes read should be %ld but is %ld\n",
                     testname, (long)AVG_SIZE, (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf, (size_t)size) == 0, TEST_SERIOUS,
                    ("%s, 1g: data read do not match original data\n", testname));
    }

    /* Read one byte in the middle of a file. */
    memset(read_buf, 0, (size_t)AVG_SIZE);
    read_buf[0] = ~write_buf[(int)AVG_OFFS];
    err = b_read(&commit_cap, AVG_OFFS, read_buf, ONE, &size);
    if (test_good(err, "1h")) {
        TEST_ASSERT(size == ONE, TEST_SERIOUS,
                    ("%s, 1h: bytes read should be 1 but is %ld\n", testname, (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf + (int)AVG_OFFS, (size_t)size) == 0,
                    TEST_SERIOUS,("%s, 1h: data read do not match original data\n", testname));
    }

    /* Read some bytes from a file with one byte. */
    memset(read_buf, 0, (size_t)AVG_SIZE);
    read_buf[0] = ~write_buf[0];
    err = b_read(&one_cap, ZERO, read_buf, AUX_SIZE, &size);
    if (test_good(err, "1i")) {
        TEST_ASSERT(size == ONE, TEST_SERIOUS,
                    ("%s, 1i: bytes read should be 1 but is %ld\n", testname, (long)size));
        TEST_ASSERT(memcmp(read_buf, write_buf, (size_t)size) == 0, TEST_SERIOUS,
                    ("%s, 1i: data read do not match original data\n", testname));
    }

    /* Read 0 bytes from an empty file. */
    err = b_read(&empty_cap, ZERO, read_buf, ZERO , &size);
    if (test_good(err, "1j"))
        TEST_ASSERT(size == ZERO, TEST_SERIOUS,
                    ("%s, 1j: bytes read should be 0 but is %ld\n", testname, (long)size));

    /* Read an entire full file with the minimum required rights. */
    err = std_restrict(&commit_cap, BS_RGT_READ, &tmp_cap);
    if (test_good(err, "1k, std_restrict()")) {
        memset(read_buf, 0, (size_t)AVG_SIZE);
        err = b_read(&tmp_cap, ZERO, read_buf, AVG_SIZE, &size);
        if (test_good(err, "1k")) {
            TEST_ASSERT(size == AVG_SIZE, TEST_SERIOUS,
                        ("%s, 1k: bytes read should be %ld but is %ld\n",
                         testname, (long)AVG_SIZE, (long)size));
            TEST_ASSERT(memcmp(read_buf, write_buf, (size_t)size) == 0, TEST_SERIOUS,
                        ("%s, 1k: data read do not match original data\n", testname));
        }
    }

}  /* test_b_read() */