コード例 #1
0
ファイル: initiator.c プロジェクト: AkankshaGovil/Automation
int 
initiate_preregistration_mode (SA *sa)
{
     int pos;
     
     /*
      * these algs should, ideally, come from the PF_KEY, and they should
      * have some implied preference and logical construction. For now just
      * stick 'em here in plain serial, logical OR.
      */
    sa->hash_alg = HASH_SHA;
    sa->encr_alg = ET_DES_CBC;
    sa->auth_alg = PRESHRD;

    sa->group_desc = 1;		/* the default Oakley group */

    /* Nike : We use the Aggressive mode */
    construct_header(sa, NIKE_PREREGISTRATION, 0, ISA_SA);
    pos = sizeof(isakmp_hdr);
    construct_isakmp_sa(sa, ISA_KE, &pos);
    construct_ke(sa, ISA_SIGREQ, &pos);
    construct_sig_req(sa, 0, &pos);
#if 0
    switch (sa->auth_alg)
    {
	case PRESHRD:
		construct_id(sa, ISA_HASH, &pos);
		construct_hash(sa, 0, &pos);
		break;
        default:
		break;
    }
#endif
    return(0);
}
コード例 #2
0
ファイル: hash_tar.c プロジェクト: svn2github/staden-io_lib
int main(int argc, char **argv) {
    options_t opt;
    FILE *fp;
    HashFile *hf;

    /* process command line arguments of the form -arg */
    opt.directories  = 0;
    opt.verbose      = 0;
    opt.append_mode  = 0;
    opt.prepend_mode = 0;
    opt.basename     = 0;
    opt.header       = NULL;
    opt.footer       = NULL;
    opt.archive      = NULL;
    opt.map          = NULL;

    for (argc--, argv++; argc > 0; argc--, argv++) {
	if (**argv != '-' || strcmp(*argv, "--") == 0)
	    break;

	if (strcmp(*argv, "-a") == 0 && argc > 1) {
	    opt.archive = argv[1];
	    argv++;
	    argc--;
	}

	if (strcmp(*argv, "-A") == 0)
	    opt.append_mode = 1;

	if (strcmp(*argv, "-O") == 0)
	    opt.prepend_mode = 1;

	if (strcmp(*argv, "-d") == 0)
	    opt.directories = 1;

	if (strcmp(*argv, "-v") == 0)
	    opt.verbose = 1;

	if (strcmp(*argv, "-b") == 0)
	    opt.basename = 1;

	if (strcmp(*argv, "-m") == 0 && argc > 1) {
	    /* Name mapping */
	    opt.map = load_map(argv[1]);
	    if (!opt.map) {
		fprintf(stderr, "Failed to load map '%s'\n", argv[1]);
		return 1;
	    }

	    argv++;
	    argc--;
	}

	if (strcmp(*argv, "-h") == 0 && argc > 1) {
	    /* Common header */
	    hf->headers = (HashFileSection *)
		realloc(hf->headers, (hf->nheaders+1) *
			sizeof(HashFileSection));
	    opt.header = argv[1];
	    hf->nheaders++;
	    argv++;
	    argc--;
	}

	if (strcmp(*argv, "-f") == 0 && argc > 1) {
	    /* Common footer */
	    hf->footers = (HashFileSection *)
		realloc(hf->footers, (hf->nfooters+1) *
			sizeof(HashFileSection));
	    opt.footer = argv[1];
	    hf->nfooters++;
	    argv++;
	    argc--;
	}
    }

    if (argc < 1 && !opt.archive) {
	fprintf(stderr, "Usage: hash_tar [options] [tarfile] > tarfile.hash\n");
	fprintf(stderr, "    -a fname  Tar archive filename: use if reading from stdin\n");
	fprintf(stderr, "    -A        Force no archive name (eg will concat to archive itself)\n");
	fprintf(stderr, "    -O        Set arc. offset to size of hash (use when prepending)\n");
	fprintf(stderr, "    -v        Verbose mode\n");
	fprintf(stderr, "    -d        Index directory names (useless?)\n");
	fprintf(stderr, "    -h name   Set tar entry 'name' to be a file header\n");
	fprintf(stderr, "    -f name   Set tar entry 'name' to be a file footer\n");
	fprintf(stderr, "    -b        Use only the filename portion of a pathname\n");
	fprintf(stderr, "    -m fname  Reads lines of 'old new' and renames entries before indexing.");
	return 1;
    }



    /* Load the tar file index into memory */
    hf = HashFileCreate(0, HASH_DYNAMIC_SIZE);
    if (argc < 1) {
	if (!opt.archive) {
	    fprintf(stderr, "If reading from stdin you must use the "
		    "\"-a archivename\" option\n");
	    return 1;
	}
	
	accumulate(hf, stdin, opt.archive, &opt);
    } else {
	/* Single file mode */
	if (opt.append_mode) {
	    if (argc >= 2) {
		fprintf(stderr, "Can only use append_mode with a single "
			"tar file\n");
		return 1;
	    }
	}

	/* Iterate over all tar files */
	while (argc >= 1) {
	    FILE *fp = fopen(argv[0], "rb");
	    if (fp == NULL) {
		perror(argv[0]);
		return 1;
	    }
	    accumulate(hf, fp, argv[0], &opt);
	    fclose(fp);

	    argc--;
	    argv++;
	}
    }

   
    /*
     * Find the header/footer if specified. For now we only support one of
     * each.
     */
    link_footers(hf, &opt);


    /* Construct the hash */
    construct_hash(hf);


    /* Save hash */
    save_hash(hf, &opt);


    /* Tidy up */
    free(files);

    return 0;
}