Exemplo n.º 1
0
Arquivo: treenode.c Projeto: jes/jfind
/* allocate a name for the given node (by traversing up to the root and
 * prepending the name for the parent node) and return it
 * you must free the returned pointer
 */
char *treenode_name(TreeNode *t) {
    if(!t->parent)
        return strdup("/");

    char *path = strallocat("/", t->name, (t->dir ? "/" : ""), NULL);

    t = t->parent;

    /* repeatedly prepend the parent's name */
    while(t->parent) {
        char *newpath = strallocat("/", t->name, path, NULL);
        free(path);
        path = newpath;
        t = t->parent;
    }

    return path;
}
Exemplo n.º 2
0
/*
 * strkey0
 */
char *
strkey0(const char *s)
{
	return (strallocat(s, "0"));
}
Exemplo n.º 3
0
/*
 * strmac
 */
char *
strmac(const char *s)
{
	return (strallocat(s, ".mac"));
}
Exemplo n.º 4
0
/*
 * main
 */
int
main(int argc, char **argv)
{
	int	 ch;
	int	 argcnt;
	int	 mac;

	/* integrity check mode, stdin */
	actionf = CHECK | ST_IN;

	/* default values */
	logfile = default_logfile;
	keyfile = default_keyfile;
	key0file = NULL;
	mac = 0;
	macfile = NULL;
	method = SHA1;

	argcnt = 1;	/* skip program name */

	while ((ch = getxopt(argc, argv, "f!logfile: g!generatekey"
	    " i!initkeyfile: k!keyfile: l!mac m!method: q!quiet h!help",
	    &argcnt)) != -1) {

		switch (ch) {
			case 'f':
				/* log file (intrusion detection mode) */
				if (logfile != default_logfile)
					free(logfile);

				if ((logfile = strrealpath(argv[argcnt]))
				    == NULL) {
					release();
					perror(argv[argcnt]);
					exit(-1);
				}

				actionf &= ~ST_IN;
				break;

			case 'g':
				/* generate new keyfile and initial key */
				actionf &= ~CHECK;
				break;

			case 'i':
				/* key 0 file */
				if (key0file)
					free(key0file);
				if ((key0file = strdup(argv[argcnt]))
				    == NULL) {
					release();
					perror(argv[argcnt]);
					exit(-1);
				}
				break;

			case 'k':
				/* keyfile */
				if (keyfile != default_keyfile)
					free(keyfile);

				if ((keyfile = strdup(argv[argcnt])) == NULL) {
					release();
					perror(argv[argcnt]);
					exit(-1);
				}
				break;

			case 'l':
				mac = 1;
				break;

			case 'm':
				/* hash method */
				if ( (method = gethash(argv[argcnt])) < 0) {
					release();
					usage();
				}
				break;

			case 'q':
				/* quiet mode */
				actionf |= QUIET;
				break;
			case 'h':
			default:
				release();
				usage();
		}

		argcnt++;

	}

	/* check logfile specified without -f switch */
	argc -= argc;
	argv += argc;
	if (argc && (actionf & ST_IN))
		if ( (logfile = strrealpath(argv[argc-1])) == NULL) {
			release();
			perror(argv[argc-1]);
			exit(-1);
		}

	/* if keyfile was not specified converted logfile is used instead */
	if (keyfile == default_keyfile && logfile != default_logfile) {
		char *tmp;

		if ( (tmp = strallocat("/var/ssyslog/", logfile)) == NULL) {
			release();
			perror("buffer for keyfile");
			exit(-1);
		}
		strdot(tmp+13);
		if ( (keyfile = strallocat(tmp, ".key")) == NULL) {
			free(tmp);
			release();
			perror("buffer for keyfile");
			exit(-1);
		}
		free(tmp);
	}

	/* if key0file was not specified create one */
	if (key0file == NULL)
		if ( (key0file = strkey0(keyfile)) == NULL) {
		release();
		perror("creating key0 file");
		exit(-1);
		}

	/* create macfile */
	if (mac)
		if ( (macfile = strmac(keyfile)) == NULL) {
			release();
			perror("creating mac file");
			exit(-1);
		}

	/* execute action */
	if (actionf & CHECK)
		check();
	else
		generate();

	release();
	return (0);
}