Beispiel #1
0
void dounpack(FILE *f) {
  char fname[MAXPATH + 80];

  fscanf(f, "%s", fname);
  fgetc(f);
  if (fname[strlen(fname) - 1] == '\\') {
    dirproc(fname, f);
  } else {
    fileproc(fname, f);
  }
  return;
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	FILE *fp = stdin;
	int c;

	if (argc == 1) {
		usage(0);
	}

	thiszone = gmt2local(0);

	while ((c = getopt(argc, argv, "acdf:HlnvxDFPphVrk?")) != -1) {
		switch (c) {
		case 'c':
			f_mode = MODE_STDIN;
#ifdef HAVE_READLINE
			/* disable filename completion */
			rl_bind_key('\t', rl_insert);
#endif
			break;
		case 'f':
			f_mode = MODE_SCRIPT;
			if (strcmp(optarg, "-") == 0) {
				fp = stdin;
			} else if ((fp = fopen(optarg, "r")) == NULL) {
				err(1, "Can't open `%s'", optarg);
			}
			break;
		case 'D':
			f_mode = MODE_CMDDUMP;
			break;
		case 'F':
			f_mode = MODE_CMDFLUSH;
			break;
		case 'a':
			f_all = 1;
			break;
		case 'l':
			f_forever = 1;
			break;
		case 'n':
			f_notreally = 1;
			break;
#ifdef __NetBSD__
		case 'h':
#endif
		case 'H':
			f_hexdump = 1;
			break;
		case 'x':
			f_mode = MODE_PROMISC;
			f_tflag++;
			break;
		case 'P':
			f_policy = 1;
			break;
		case 'p':
			f_withports = 1;
			break;
		case 'v':
			f_verbose = 1;
			break;
		case 'r':
#ifdef HAVE_POLICY_FWD
			f_rfcmode = 1;
#else
			rkwarn();
#endif
			break;
		case 'k':
#ifdef HAVE_POLICY_FWD
			f_rfcmode = 0;
#else
			rkwarn();
#endif
			break;
		case 'V':
			usage(1);
			break;
#ifndef __NetBSD__
		case 'h':
#endif
		case '?':
		default:
			usage(0);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc > 0) {
		while (argc--) {
			if (fileproc(*argv++) < 0) {
				err(1, "%s", argv[-1]);
			}
		}
		exit(0);
	}

	so = pfkey_open();
	if (so < 0) {
		perror("pfkey_open");
		exit(1);
	}

	switch (f_mode) {
	case MODE_CMDDUMP:
		sendkeyshort(f_policy ? SADB_X_SPDDUMP : SADB_DUMP);
		break;
	case MODE_CMDFLUSH:
		sendkeyshort(f_policy ? SADB_X_SPDFLUSH: SADB_FLUSH);
		break;
	case MODE_SCRIPT:
		if (get_supported() < 0) {
			errx(1, "%s", ipsec_strerror());
		}
		if (parse(&fp))
			exit(1);
		break;
	case MODE_STDIN:
		if (get_supported() < 0) {
			errx(1, "%s", ipsec_strerror());
		}
		stdin_loop();
		break;
	case MODE_PROMISC:
		promisc();
		/* NOTREACHED */
	default:
		usage(0);
	}

	exit(0);
}