示例#1
0
static void pendElement(void *ctxt, const xmlChar * uname)
{
  saxctxt *ctx = (saxctxt *) ctxt;
  const char *name = (const char *) uname;
  const htmlElemDesc *desc = htmlTagLookup(uname);

#if 0 /* for now, err on the side of leaving stuff alone */
  if ((ctx->cfg->doctype == fpi_html) || (ctx->cfg->doctype == fpi_xhtml)) {
    /* enforce html */
    if (!desc || desc->depr)
      return;

  } else if ((ctx->cfg->doctype == fpi_html)
		|| (ctx->cfg->doctype == fpi_xhtml)) {
    /* enforce html legacy */
    if (!desc)
      return;
  }
#endif

  if (ctx->offset > 0) {
    dump_content(ctx);
    ctx->offset = 0;        /* having dumped it, we can re-use the memory */
  }
  if (!desc || !desc->empty) {
    ap_fprintf(ctx->f->next, ctx->bb, "</%s>", name);
  }
}
示例#2
0
void
grg_parse_argv (gint argc, gchar * argv[], gchar ** filename,
		gboolean * rootCheck)
{
	poptContext optCon;
	gchar *wipe, *etit;
	gint passes, ennum;
	gboolean dump, help, strongRnd;

	struct poptOption optionsTable[] = {
		{"help", 'h', POPT_ARG_NONE, &help, 1, _("shows the help"),
		 NULL},
		{"input-file", 'f', POPT_ARG_STRING, filename, 0,
		 _("specify the input file to open"), _("FILE")},
#ifndef ROOT_FILTER
		{"allow-root", 's', POPT_ARG_NONE, rootCheck, 1,
		 _("allow usage as root -- DANGEROUS"), NULL},
#endif
		{"strong-random", 'R', POPT_ARG_NONE, &strongRnd, 0,
		 _("force use of /dev/random -- slower"), NULL},
		{"dump", 'd', POPT_ARG_NONE, &dump, 0,
		 _("dump the content of a file"), NULL},
		{"entry-num", 0, POPT_ARG_INT, &ennum, 0,
		 _("index of the entry to dump"), _("NUM")},
		{"entry-title", 0, POPT_ARG_STRING, &etit, 0,
		 _("title of the entry to dump"), _("TXT")},
		{"wipe-file", 'w', POPT_ARG_STRING, &wipe, 0,
		 _("securely wipe a file"), _("FILE")},
		{"wipe-passes", 0, POPT_ARG_INT, &passes, 0,
		 _("passes in file wiping"), _("NUM")},
		{NULL, 0, 0, NULL, 0}
	};

	*filename = NULL;
	wipe = NULL;
	etit = NULL;
	passes = 0;
	ennum = -1;
	*rootCheck = FALSE;
	strongRnd = FALSE;
	dump = FALSE;
	help = FALSE;

	optCon = poptGetContext (NULL, argc, (const char **) argv,
				 optionsTable, 0);

	while (poptGetNextOpt (optCon) >= 0) ;

	if (help)
	{
		poptPrintHelp (optCon, stdout, 0);
		poptFreeContext (optCon);
		exit_freeing_ctx (1);
	}

	poptFreeContext (optCon);

	if (strongRnd)
		grg_ctx_set_security_lvl (gctx, GRG_SEC_PARANOIA);

/*quite cerebrotic, I know. The idea is: to ensure that stdin isn't exploitable,
  the best way is to close and reopen it, so that any "abnormal" setting is
  wasted. Since it isn't possible to do this atomically, I check that the former
  file descriptor hasn't been opened in the while by someone that could pretend
  to "be" stdin.*/
	if (!(wipe || dump))
	{
		int canary;

		close (STDIN);
		canary = open ("/dev/null", O_RDONLY);
		if (canary != STDIN)
			exit_freeing_ctx (1);
		return;
	}

/*wipe and dump operations are processed without returning to main() */

/*FIXME this should be in grg_safe.c */
#ifdef HAVE_ISATTY
	if (!isatty (STDIN))
	{
		g_critical ("%s",
			    _
			    ("It isn't possible to redirect data to stdin, as it is a potential security flaw."));
		exit_freeing_ctx (1);
	}
#endif

	if (!grg_security_filter (*rootCheck))
		exit_freeing_ctx (1);

	if (wipe)
	{
		gint res;
		gchar c;

		if (!g_file_test (wipe, G_FILE_TEST_IS_REGULAR))
			report_err (_("The file does not exist"), 0, 1, NULL);

		printf ("%s (y/n)",
			_("Are you sure you want to wipe this file?\n"
			  "Its content will be securely erased, so no\n"
			  "recover is possible."));

		if (passes < 0 || passes > 32)
			passes = 8;

		c = getchar ();

		if (c != 'y' && c != 'Y')
			exit_freeing_ctx (0);

		res = grg_file_shred (wipe, passes);

		if (res < 0)
			report_err (_("File wiping failed"), 0, 1, NULL);

		exit_freeing_ctx (0);
	}

	if (dump)
	{
		if (!*filename)
			report_err (_
				    ("You must specify a file to dump (with the -f switch)"),
				    0, 1, NULL);
		dump_content (*filename, ennum, etit);
		exit_freeing_ctx (0);
	}
}
示例#3
0
int main(int argc, char **argv)
{
	char buf[MAX_REG_STR + 1];
	char path[PATH_MAX];
	char *dump[2];
	int i, fd, len;

	test_init(argc, argv);

	snprintf(NAME[0], PATH_MAX, "%s_magic", filename);
	snprintf(NAME[1], PATH_MAX, "%s_extension", filename);

	if (mkdir(dirname, 0777)) {
		fail("mkdir");
		exit(1);
	}

	if (mount("none", dirname, "binfmt_misc", 0, NULL)) {
		fail("mount failed");
		exit(1);
	}

	/* Register binfmt_entries */
	sprintf(path, "%s/" "register", dirname);
	fd = open(path, O_WRONLY);
	if (fd < 0) {
		fail("open");
		exit(1);
	}

	for (i = 0; i < 2; i++) {
		if (i % 2 == 0)
			create_magic_pattern(buf, NAME[i]);
		else
			create_extension_pattern(buf, NAME[i]);

		test_msg("string: %s\n", buf);
		len = strlen(buf);

		if (len != write(fd, buf, len)) {
			fail("write %s", NAME[i]);
			exit(1);
		}
	}

	close(fd);

	/* Disable one of the entries */
	ssprintf(path, "%s/%s", dirname, NAME[0]);
	fd = open(path, O_WRONLY);
	if (fd < 0 || write(fd, "0", 1) != 1) {
		fail("Can't disable %s\n", path);
		exit(1);
	}
	close(fd);

	/* Dump files content */
	for (i = 0; i < 2; i ++) {
		sprintf(path, "%s/%s", dirname, NAME[i]);
		if (dump_content(path, &dump[i]))
			exit(1);
	}

	test_daemon();
	test_waitsig();

	/* Check */
	for (i = 0; i < 2; i ++) {
		char *tmp;

		sprintf(path, "%s/%s", dirname, NAME[i]);
		if (dump_content(path, &tmp))
			exit(1);

		if (strcmp(tmp, dump[i])) {
			fail("Content differs:\n%s\nand\n%s\n", tmp, dump[i]);
			exit(1);
		}
		free(dump[i]);
		free(tmp);
	}

	pass();

	/* Clean up */
	for (i = 0; i < 2; i++) {
		sprintf(path, "%s/%s", dirname, NAME[i]);
		fd = open(path, O_WRONLY);
		if (fd < 0) {
			pr_perror("open %s", path);
			continue;
		}
		if (write(fd, "-1", 2) != 2)
			pr_perror("cleanup %s", path);
		close(fd);
	}

	umount(dirname);
	rmdir(dirname);

	return 0;
}