コード例 #1
0
static int __init honeevent_init(void)
{
	int err;

	if (hostid && *hostid) {
		if (!hostid_type)
			devinfo.host_id = hostid;
		else if (hostid_type == 1) {
			if (parse_guid(&devinfo.host_guid, hostid)) {
				printm(KERN_ERR, "invalid host GUID: %s\n", hostid);
				return -1;
			}
			printm(KERN_DEBUG, "using host GUID {" GUID_FMT "}\n",
					GUID_TUPLE(&devinfo.host_guid));
			devinfo.host_guid_is_set = true;
		} else {
			printm(KERN_ERR, "invalid hostid_type: %d\n", hostid_type);
			return -1;
		}
	}
	if (comment && *comment)
		devinfo.comment = comment;
	if ((err = hone_notify_init()))
		return -1;
	if ((err = register_chrdev(major, devname, &device_ops)) < 0) {
		printm(KERN_ERR, "character device registration returned error %d\n", err);
		hone_notify_release();
		return -1;
	}
	if (!major)
		major = err;

	class_hone = class_create(THIS_MODULE, devname);
	if (IS_ERR(class_hone)) {
		printm(KERN_ERR, "class_create failed\n");
		return PTR_ERR(class_hone);
	}

	device_create(class_hone, NULL, MKDEV(major, 0), NULL, "%s", devname);
	device_create(class_hone, NULL, MKDEV(major, 1), NULL, "%st", devname);

	printk(KERN_INFO "%s: v%s module successfully loaded with major number %d\n",
			mod_name, version, major);
	return 0;
}
コード例 #2
0
int main(int argc, char **argv)
{
	const char *guid_str;
    const char *attr_str;
    const char *varname;
	const char *keyfilename;
    const char *certfilename;
	varsign_context *ctx;
	bool include_attrs;
	int c = 0;
    	unsigned char no_signing = 0;
	unsigned char no_repack = 0;

	ctx = talloc_zero(NULL, varsign_context);

	keyfilename = NULL;
	certfilename = NULL;
	guid_str = NULL;
	attr_str= NULL;
	include_attrs = false;

	for (;;) {
		int idx;

		c = getopt_long(argc, argv, "o:g:a:k:c:n:ivVh", options, &idx);

		if (c == -1) {
			break;
        }

		switch (c) {
	case 'o':
			ctx->outfilename = optarg;
			break;

        case 'g':
			guid_str = optarg;
			break;

        case 'a':
			attr_str = optarg;
			break;

        case 'k':
			keyfilename = optarg;
			break;

        case 'c':
			certfilename = optarg;
			break;

        case 'i':
			include_attrs = true;
			break;

        case 'v':
			ctx->verbose = 1;
			break;

        case 'V':
			version();
			return EXIT_SUCCESS;

        case 'n':
            no_signing = 1;
            break;

        case 'N':
            no_signing = 1;
            break;

        case 'r':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'R':
            no_repack = 1;
            do_direct = 1;
            break;

        case 'h':
			usage();
			return EXIT_SUCCESS;
		}
	}

	if (argc != (optind + 2)) {
		usage();

		return EXIT_FAILURE;
	}

	if ((!keyfilename) && (!no_signing)) {
		fprintf(stderr, "No signing key specified\n");

		return EXIT_FAILURE;
	}

	if ((!certfilename) && (!no_signing)) {
		fprintf(stderr, "No signing certificate specified\n");

		return EXIT_FAILURE;
	}

	/* initialise openssl */
	OpenSSL_add_all_digests();
	OpenSSL_add_all_ciphers();
	ERR_load_crypto_strings();

	/* set up the variable signing context */
	varname = argv[optind];
	set_varname(ctx, varname);
	ctx->infilename = argv[optind+1];

	if (!ctx->outfilename) {
		set_default_outfilename(ctx);
    }

	if (attr_str) {
		ctx->var_attrs = parse_attrs(attr_str);

		if (ctx->var_attrs == attr_invalid) {
			return EXIT_FAILURE;
        }
	} else {
		ctx->var_attrs = default_attrs;
	}

	if (guid_str) {
		if (parse_guid(guid_str, &ctx->var_guid)) {
			fprintf(stderr, "Invalid GUID '%s'\n", guid_str);

			return EXIT_FAILURE;
		}
	} else {
		set_default_guid(ctx, varname);
	}

	if (fileio_read_file(ctx, ctx->infilename, &ctx->data, &ctx->data_len)) {
		return EXIT_FAILURE;
    }

    if (!no_signing)
    {
        ctx->key = fileio_read_pkey(keyfilename);
        if (!ctx->key) {
            return EXIT_FAILURE;
        }
        
        ctx->cert = fileio_read_cert(certfilename);
        if (!ctx->cert) {
            return EXIT_FAILURE;
        }
    }

	/* do the signing */
	if (add_auth_descriptor(ctx, no_signing)) {
		return EXIT_FAILURE;
    }

	/* write the resulting image */
	if (write_signed(ctx, include_attrs, no_repack)) {
		return EXIT_FAILURE;
    }

	return EXIT_SUCCESS;
}