File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / voucher.c
Revision 1.1.2.2: download - view: text, annotated - select for diffs - revision graph
Wed Jul 4 15:59:10 2012 UTC (11 years, 11 months ago) by misho
Branches: tools1_1
added voucher config and script for sign rsa key

#include "global.h"


io_enableDEBUG;

cfg_root_t cfg;
FILE *output;
char szConfig[MAXPATHLEN] = VOUCHER_CFG;
extern char compiled[], compiledby[], compilehost[];


static void
Usage()
{
	printf(	" -= VOUCHER =- management tool\n"
		"=== %s === %s@%s ===\n\n"
		"Syntax: voucher [options] -r <RollID> [count]\n"
		"\tvoucher [options] -t <voucher> [voucher [voucher ...]]\n\n"
		"\t-v\t\tVerbose (more -v more verbosity)\n"
		"\t-r\t\tRequest new voucher(s) mode\n"
		"\t-t\t\tTest voucher(s) mode\n"
		"\t-c <config>\tConfig file\n"
		"\t-o <output>\tOutput file [default=-]\n"
		"\n", compiled, compiledby, compilehost);
}

static void
AtExit()
{
	if (output != stdout)
		fclose(output);
}

static inline int
RedirOutput(const char *name)
{
	AtExit();

	if (strcmp(name, "-")) {
		output = fopen(name, "w+");
		if (!output) {
			printf("Error:: can't redirect output #%d - %s\n", 
					errno, strerror(errno));
			return -1;
		}
	} else
		output = stdout;
	return 0;
}


int
main(int argc, char **argv)
{
	char ch, mode = 0;
	int rid, cnt = 1;

	output = stdout;
	atexit(AtExit);

	while ((ch = getopt(argc, argv, "hvrtc:o:")) != -1)
		switch (ch) {
			case 'r':
				mode = 1;
				break;
			case 't':
				mode = 2;
				break;
			case 'c':
				strlcpy(szConfig, optarg, sizeof szConfig);
				break;
			case 'o':
				RedirOutput(optarg);
				break;
			case 'v':
				io_incDebug;
				break;
			case 'h':
			default:
				Usage();
				return 1;
		}
	argc -= optind;
	argv += optind;
	if (!argc || !mode) {
		printf("Error:: not enough parameter or unspecified mode ...\n\n");
		Usage();
		return 1;
	}
	if (cfgLoadConfig(szConfig, &cfg)) {
		printf("Error:: load config #%d - %s\n", cfg_GetErrno(), cfg_GetError());
		return 2;
	}

	cfgUnloadConfig(&cfg);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>