Exemplo n.º 1
0
int	main (int argc, char *argv[])
{
	dki_t	*data = NULL;
	int	c;
	int	opt_index;
	int	action;
	const	char	*file;
	const	char	*defconfname = NULL;
	char	*p;
	char	str[254+1];
	zconf_t	*config;

	progname = *argv;
	if ( (p = strrchr (progname, '/')) )
		progname = ++p;
	view = getnameappendix (progname, "zkt-ls");

	defconfname = getdefconfname (view);
	config = loadconfig ("", (zconf_t *)NULL);	/* load built in config */
	if ( fileexist (defconfname) )			/* load default config file */
		config = loadconfig (defconfname, config);
	if ( config == NULL )
		fatal ("Out of memory\n");
	setglobalflags (config);

        opterr = 0;
	opt_index = 0;
	action = 0;
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
	while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 )
#else
	while ( (c = getopt (argc, argv, short_options)) != -1 )
#endif
	{
		switch ( c )
		{
#if defined(COLOR_MODE) && COLOR_MODE
		case 'C':	/* color mode on; optional with terminal name */
			if ( optarg )
				term = optarg;
			else
				term = getenv ("TERM");
			break;
#endif
		case 'M':
			managedkeyflag = 1;
			subdomain_before_parent = 0;
			zskflag = pathflag = 0;
			action = c;
			break;
		case 'T':
			trustedkeyflag = 1;
			subdomain_before_parent = 0;
			zskflag = pathflag = 0;
			/* fall through */
		case 'H':
		case 'K':
		case 'Z':
			action = c;
			break;
		case 'a':		/* age */
			ageflag = !ageflag;
			break;
		case 'f':		/* key lifetime */
			lifetimeflag = !lifetimeflag;
			break;
		case 'V':		/* view name */
			view = optarg;
			defconfname = getdefconfname (view);
			if ( fileexist (defconfname) )		/* load default config file */
				config = loadconfig (defconfname, config);
			if ( config == NULL )
				fatal ("Out of memory\n");
			setglobalflags (config);
			break;
		case 'c':
			config = loadconfig (optarg, config);
			setglobalflags (config);
			checkconfig (config);
			break;
		case 'O':		/* read option from commandline */
			config = loadconfig_fromstr (optarg, config);
			setglobalflags (config);
			checkconfig (config);
			break;
		case 'd':		/* ignore directory arg */
			dirflag = 1;
			break;
		case 'h':		/* print no headline */
			headerflag = 0;
			break;
		case 'k':		/* ksk only */
			zskflag = 0;
			break;
		case 'L':		/* ljust */
			ljustflag = !ljustflag;
			break;
		case 'l':		/* label list */
			labellist = prepstrlist (optarg, LISTDELIM);
			if ( labellist == NULL )
				fatal ("Out of memory\n");
			break;
		case 'p':		/* print path */
			pathflag = 1;
			break;
		case 'r':		/* switch recursive flag */
			recflag = !recflag;
			break;
		case 's':		/* switch subdomain sorting flag */
			subdomain_before_parent = !subdomain_before_parent;
			break;
		case 't':		/* time */
			timeflag = !timeflag;
			break;
		case 'e':		/* expire time */
			exptimeflag = !exptimeflag;
			break;
		case 'z':		/* zsk only */
			kskflag = 0;
			break;
		case ':':
			snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n",
										optopt);
			usage (str, config);
			break;
		case '?':
			if ( isprint (optopt) )
				snprintf (str, sizeof(str), "Unknown option \"-%c\".\n",
										optopt);
			else
				snprintf (str, sizeof (str), "Unknown option char \\x%x.\n",
										optopt);
			usage (str, config);
			break;
		default:
			abort();
		}
	}

	if ( kskflag == 0 && zskflag == 0 )
		kskflag = zskflag = 1;

	tc_init (stdout, term);

	c = optind;
	do {
		if ( c >= argc )		/* no args left */
			file = config->zonedir;	/* use default directory */
		else
			file = argv[c++];

		if ( is_directory (file) )
			parsedirectory (file, &data, subdomain_before_parent);
		else
			parsefile (file, &data, subdomain_before_parent);

	}  while ( c < argc );	/* for all arguments */

	switch ( action )
	{
	case 'H':
		usage ("", config);
	case 'K':
		zkt_list_dnskeys (data);
		break;
	case 'T':
		zkt_list_trustedkeys (data);
		break;
	case 'M':
		zkt_list_managedkeys (data);
		break;
	default:
		zkt_list_keys (data);
	}

	tc_end (stdout, term);

	return 0;
}
Exemplo n.º 2
0
int	main (int argc, char *argv[])
{
	int	c;
	int	opt_index;
	int	action;
	int	major;
	int	minor;
	const	char	*file;
	const	char	*defconfname = NULL;
	const	char	*confname = NULL;
	char	*p;
	char	str[254+1];
	zconf_t	*refconfig = NULL;
	zconf_t	*config;

	progname = *argv;
	if ( (p = strrchr (progname, '/')) )
		progname = ++p;
	view = getnameappendix (progname, "zkt-conf");

	defconfname = getdefconfname (view);
	dbg_val0 ("Load built in config \"%s\"\n");
	config = loadconfig ("", (zconf_t *)NULL);	/* load built in config */

	if ( fileexist (defconfname) )			/* load default config file */
	{
		dbg_val ("Load site wide config file \"%s\"\n", defconfname);
		config = loadconfig (defconfname, config);
	}
	if ( config == NULL )
		fatal ("Out of memory\n");
	confname = defconfname;

        opterr = 0;
	opt_index = 0;
	action = 0;
	setconfigversion (100);
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
	while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 )
#else
	while ( (c = getopt (argc, argv, short_options)) != -1 )
#endif
	{
		switch ( c )
		{
		case 'V':		/* view name */
			view = optarg;
			defconfname = getdefconfname (view);
			if ( fileexist (defconfname) )		/* load default config file */
				config = loadconfig (defconfname, config);
			if ( config == NULL )
				fatal ("Out of memory\n");
			confname = defconfname;
			break;
		case 'O':		/* read option from commandline */
			config = loadconfig_fromstr (optarg, config);
			break;
		case 'C':
			switch ( sscanf (optarg, "%d.%d", &major, &minor) )
			{
			case 2:	major = major * 100 + minor;
			case 1: break;
			default:
				usage ("illegal release number");
			}
			setconfigversion (major);
			break;
		case 'c':
			if ( *optarg == '\0' )
				usage ("empty config file name");
			config = loadconfig (optarg, config);
			if ( *optarg == '-' || strcmp (optarg, "stdin") == 0 )
				confname = "stdout";
			else
				confname = optarg;
			break;
		case 'd':		/* built-in default config */
			config = loadconfig ("", config);	/* load built-in config */
			confname = defconfname;
			break;
		case 's':		/* side wide config */
			/* this is the default **/
			break;	
		case 'a':		/* set all flag */
			allflag = 1;
			break;
		case 'l':		/* local config file */
			refconfig = dupconfig (config);	/* duplicate current config */
			confname = LOCALCONF_FILE;
			if ( fileexist (LOCALCONF_FILE) )	/* try to load local config file */
			{
				dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE);
				config = loadconfig (LOCALCONF_FILE, config);
			}
			else if ( !writeflag )
				usage ("error: no local config file found");
			break;
		case 't':		/* test config */
			testflag = 1;
			break;
		case 'v':		/* version */
			fprintf (stderr, "%s version %s compiled for BIND version %d\n",
							progname, ZKT_VERSION, BIND_VERSION);
			fprintf (stderr, "ZKT %s\n", ZKT_COPYRIGHT);
			return 0;
			break;
		case 'w':		/* write back conf file */
			writeflag = 1;
			break;
		case 'h':		/* print help */
			usage ("");
			break;
		case ':':
			snprintf (str, sizeof(str), "option \"-%c\" requires an argument.",
										optopt);
			usage (str);
			break;
		case '?':
			if ( isprint (optopt) )
				snprintf (str, sizeof(str), "Unknown option \"-%c\".",
										optopt);
			else
				snprintf (str, sizeof (str), "Unknown option char \\x%x.",
										optopt);
			usage (str);
			break;
		default:
			abort();
		}
	}

	c = optind;
	if ( c >= argc )	/* no arguments given on commandline */
	{
		if ( testflag )
		{
			if ( checkconfig (config) )
				fprintf (stderr, "All config file parameter seems to be ok\n");
		}
		else
		{
			if ( !writeflag )	/* print to stdout */
				confname = "stdout";

			if ( refconfig )	/* have we seen a local config file ? */
				if ( allflag )
					printconfig (confname, config);	
				else
					printconfigdiff (confname, refconfig, config);	
			else
				printconfig (confname, config);
		}
	}
	else	/* command line argument found: use it as name of zone file */
	{
		long	minttl;
		long	maxttl;
		int	keydbfound;
		char	*dnskeydb;

		file = argv[c++];

		dnskeydb = config->keyfile;

		minttl = 0x7FFFFFFF;
		maxttl = 0;
		keydbfound = parsezonefile (file, &minttl, &maxttl, dnskeydb);
		if ( keydbfound < 0 )
			error ("can't parse zone file %s\n", file);

		if ( dnskeydb && !keydbfound )
		{
			if ( writeflag )
			{
				addkeydb (file, dnskeydb);
				printf ("\"$INCLUDE %s\" directive added to \"%s\"\n", dnskeydb, file);
			}
			else
				printf ("\"$INCLUDE %s\" should be added to \"%s\" (run with option -w)\n",
							dnskeydb, file);
		}

		if ( minttl < (10 * MINSEC) )
			fprintf (stderr, "Min_TTL of %s (%ld seconds) is too low to use it in a signed zone (see RFC4641)\n", 
							timeint2str (minttl), minttl);
		else
			fprintf (stderr, "Min_TTL:\t%s\t# (%ld seconds)\n", timeint2str (minttl), minttl);
		fprintf (stdout, "Max_TTL:\t%s\t# (%ld seconds)\n", timeint2str (maxttl), maxttl);

		if ( writeflag )
		{
			refconfig = dupconfig (config);	/* duplicate current config */
			confname = LOCALCONF_FILE;
			if ( fileexist (LOCALCONF_FILE) )	/* try to load local config file */
			{
				dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE);
				config = loadconfig (LOCALCONF_FILE, config);
			}
			setconfigpar (config, "Max_TTL", &maxttl);
			printconfigdiff (confname, refconfig, config);
		}
	}


	return 0;
}
Exemplo n.º 3
0
int
main(int argc, char **argv, char **envp)
{
	const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
	    "/usr/local/bin:/usr/local/sbin";
	const char *confpath = NULL;
	char *shargv[] = { NULL, NULL };
	char *sh;
	const char *cmd;
	char cmdline[LINE_MAX];
	char myname[_PW_NAME_LEN + 1];
	struct passwd *pw;
	struct rule *rule;
	uid_t uid;
	uid_t target = 0;
	gid_t groups[NGROUPS_MAX + 1];
	int ngroups;
	int i, ch;
	int sflag = 0;
	int nflag = 0;
	char cwdpath[PATH_MAX];
	const char *cwd;

	closefrom(STDERR_FILENO + 1);

	uid = getuid();

	while ((ch = getopt(argc, argv, "C:nsu:")) != -1) {
		switch (ch) {
		case 'C':
			confpath = optarg;
			break;
		case 'u':
			if (parseuid(optarg, &target) != 0)
				errx(1, "unknown user");
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		default:
			usage();
			break;
		}
	}
	argv += optind;
	argc -= optind;

	if (confpath) {
		if (sflag)
			usage();
	} else if ((!sflag && !argc) || (sflag && argc))
		usage();

	pw = getpwuid(uid);
	if (!pw)
		err(1, "getpwuid failed");
	if (strlcpy(myname, pw->pw_name, sizeof(myname)) >= sizeof(myname))
		errx(1, "pw_name too long");
	ngroups = getgroups(NGROUPS_MAX, groups);
	if (ngroups == -1)
		err(1, "can't get groups");
	groups[ngroups++] = getgid();

	if (sflag) {
		sh = getenv("SHELL");
		if (sh == NULL || *sh == '\0')
			shargv[0] = pw->pw_shell;
		else
			shargv[0] = sh;
		argv = shargv;
		argc = 1;
	}

	if (confpath) {
		checkconfig(confpath, argc, argv, uid, groups, ngroups,
		    target);
		exit(1);	/* fail safe */
	}

	parseconfig("/etc/doas.conf", 1);

	/* cmdline is used only for logging, no need to abort on truncate */
	(void) strlcpy(cmdline, argv[0], sizeof(cmdline));
	for (i = 1; i < argc; i++) {
		if (strlcat(cmdline, " ", sizeof(cmdline)) >= sizeof(cmdline))
			break;
		if (strlcat(cmdline, argv[i], sizeof(cmdline)) >= sizeof(cmdline))
			break;
	}

	cmd = argv[0];
	if (!permit(uid, groups, ngroups, &rule, target, cmd,
	    (const char**)argv + 1)) {
		syslog(LOG_AUTHPRIV | LOG_NOTICE,
		    "failed command for %s: %s", myname, cmdline);
		errc(1, EPERM, NULL);
	}

	if (!(rule->options & NOPASS)) {
		if (nflag)
			errx(1, "Authorization required");
		if (!auth_userokay(myname, NULL, "auth-doas", NULL)) {
			syslog(LOG_AUTHPRIV | LOG_NOTICE,
			    "failed password for %s", myname);
			errc(1, EPERM, NULL);
		}
	}
	envp = copyenv((const char **)envp, rule);

	pw = getpwuid(target);
	if (!pw)
		errx(1, "no passwd entry for target");
	if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
	    LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
	    LOGIN_SETUSER) != 0)
		errx(1, "failed to set user context for target");

	if (getcwd(cwdpath, sizeof(cwdpath)) == NULL)
		cwd = "(failed)";
	else
		cwd = cwdpath;

	syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
	    myname, cmdline, pw->pw_name, cwd);

	if (rule->cmd) {
		if (setenv("PATH", safepath, 1) == -1)
			err(1, "failed to set PATH '%s'", safepath);
	}
	execvpe(cmd, argv, envp);
	if (errno == ENOENT)
		errx(1, "%s: command not found", cmd);
	err(1, "%s", cmd);
}
Exemplo n.º 4
0
Arquivo: doas.c Projeto: slicer69/doas
int
main(int argc, char **argv)
{
	const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
	    "/usr/local/bin:/usr/local/sbin";
	const char *confpath = NULL;
	char *shargv[] = { NULL, NULL };
	char *sh;
	const char *cmd;
	char cmdline[LINE_MAX];
	char myname[_PW_NAME_LEN + 1];
	struct passwd *pw;
	struct rule *rule;
	uid_t uid;
	uid_t target = 0;
	gid_t groups[NGROUPS_MAX + 1];
	int ngroups;
	int i, ch;
	int sflag = 0;
	int nflag = 0;
	char cwdpath[PATH_MAX];
	const char *cwd;
	char *login_style = NULL;
	char **envp;

        #ifndef linux
	setprogname("doas");
        #endif

        #ifndef linux
	closefrom(STDERR_FILENO + 1);
        #endif

	uid = getuid();

	while ((ch = getopt(argc, argv, "a:C:nsu:")) != -1) {
/*	while ((ch = getopt(argc, argv, "a:C:Lnsu:")) != -1) { */
		switch (ch) {
		case 'a':
			login_style = optarg;
			break;
		case 'C':
			confpath = optarg;
			break;
/*		case 'L':
			i = open("/dev/tty", O_RDWR);
			if (i != -1)
				ioctl(i, TIOCCLRVERAUTH);
			exit(i != -1);
*/
		case 'u':
			if (parseuid(optarg, &target) != 0)
				errx(1, "unknown user");
			break;
		case 'n':
			nflag = 1;
			break;
		case 's':
			sflag = 1;
			break;
		default:
			usage();
			break;
		}
	}
	argv += optind;
	argc -= optind;

	if (confpath) {
		if (sflag)
			usage();
	} else if ((!sflag && !argc) || (sflag && argc))
		usage();

	pw = getpwuid(uid);
	if (!pw)
		err(1, "getpwuid failed");
	if (strlcpy(myname, pw->pw_name, sizeof(myname)) >= sizeof(myname))
		errx(1, "pw_name too long");

	ngroups = getgroups(NGROUPS_MAX, groups);
	if (ngroups == -1)
		err(1, "can't get groups");
	groups[ngroups++] = getgid();

	if (sflag) {
		sh = getenv("SHELL");
		if (sh == NULL || *sh == '\0') {
			shargv[0] = strdup(pw->pw_shell);
			if (shargv[0] == NULL)
				err(1, NULL);
		} else
			shargv[0] = sh;
		argv = shargv;
		argc = 1;
	}

	if (confpath) {
		checkconfig(confpath, argc, argv, uid, groups, ngroups,
		    target);
		exit(1);	/* fail safe */
	}

	if (geteuid())
		errx(1, "not installed setuid");

	parseconfig(DOAS_CONF, 1);

	/* cmdline is used only for logging, no need to abort on truncate */
	(void)strlcpy(cmdline, argv[0], sizeof(cmdline));
	for (i = 1; i < argc; i++) {
		if (strlcat(cmdline, " ", sizeof(cmdline)) >= sizeof(cmdline))
			break;
		if (strlcat(cmdline, argv[i], sizeof(cmdline)) >= sizeof(cmdline))
			break;
	}

	cmd = argv[0];
	if (!permit(uid, groups, ngroups, &rule, target, cmd,
	    (const char **)argv + 1)) {
		syslog(LOG_AUTHPRIV | LOG_NOTICE,
		    "failed command for %s: %s", myname, cmdline);
		errc(1, EPERM, NULL);
	}

	if (!(rule->options & NOPASS)) {
		if (nflag)
			errx(1, "Authorization required");

#if defined(USE_BSD_AUTH) 
		authuser(myname, login_style, rule->options & PERSIST);
#elif defined(USE_PAM)
#define PAM_END(msg) do { 						\
	syslog(LOG_ERR, "%s: %s", msg, pam_strerror(pamh, pam_err)); 	\
	warnx("%s: %s", msg, pam_strerror(pamh, pam_err));		\
	pam_end(pamh, pam_err);						\
	exit(EXIT_FAILURE);						\
} while (/*CONSTCOND*/0)
		pam_handle_t *pamh = NULL;
		int pam_err;

/* #ifndef linux */
		int temp_stdin;

		/* openpam_ttyconv checks if stdin is a terminal and
		 * if it is then does not bother to open /dev/tty.
		 * The result is that PAM writes the password prompt
		 * directly to stdout.  In scenarios where stdin is a
		 * terminal, but stdout is redirected to a file
		 * e.g. by running doas ls &> ls.out interactively,
		 * the password prompt gets written to ls.out as well.
		 * By closing stdin first we forces PAM to read/write
		 * to/from the terminal directly.  We restore stdin
		 * after authenticating. */
		temp_stdin = dup(STDIN_FILENO);
		if (temp_stdin == -1)
			err(1, "dup");
		close(STDIN_FILENO);
/* #else */
		/* force password prompt to display on stderr, not stdout */
		int temp_stdout = dup(1);
		if (temp_stdout == -1)
			err(1, "dup");
		close(1);
		if (dup2(2, 1) == -1)
			err(1, "dup2");
/* #endif */

		pam_err = pam_start("doas", myname, &pamc, &pamh);
		if (pam_err != PAM_SUCCESS) {
			if (pamh != NULL)
				PAM_END("pam_start");
			syslog(LOG_ERR, "pam_start failed: %s",
			    pam_strerror(pamh, pam_err));
			errx(EXIT_FAILURE, "pam_start failed");
		}

		switch (pam_err = pam_authenticate(pamh, PAM_SILENT)) {
		case PAM_SUCCESS:
			switch (pam_err = pam_acct_mgmt(pamh, PAM_SILENT)) {
			case PAM_SUCCESS:
				break;

			case PAM_NEW_AUTHTOK_REQD:
				pam_err = pam_chauthtok(pamh,
				    PAM_SILENT|PAM_CHANGE_EXPIRED_AUTHTOK);
				if (pam_err != PAM_SUCCESS)
					PAM_END("pam_chauthtok");
				break;

			case PAM_AUTH_ERR:
			case PAM_USER_UNKNOWN:
			case PAM_MAXTRIES:
				syslog(LOG_AUTHPRIV | LOG_NOTICE,
				    "failed auth for %s", myname);
                                errx(EXIT_FAILURE, "second authentication failed");
				break;

			default:
				PAM_END("pam_acct_mgmt");
				break;
			}
			break;

		case PAM_AUTH_ERR:
		case PAM_USER_UNKNOWN:
		case PAM_MAXTRIES:
			syslog(LOG_AUTHPRIV | LOG_NOTICE,
			    "failed auth for %s", myname);
                        errx(EXIT_FAILURE, "authentication failed");
			break;

		default:
			PAM_END("pam_authenticate");
			break;
		}
		pam_end(pamh, pam_err);

#ifndef linux
		/* Re-establish stdin */
		if (dup2(temp_stdin, STDIN_FILENO) == -1)
			err(1, "dup2");
		close(temp_stdin);
#else 
		/* Re-establish stdout */
		close(1);
		if (dup2(temp_stdout, 1) == -1)
			err(1, "dup2");
#endif 
#else
#error	No auth module!
#endif
	}

        /*
	if (pledge("stdio rpath getpw exec id", NULL) == -1)
		err(1, "pledge");
        */
	pw = getpwuid(target);
	if (!pw)
		errx(1, "no passwd entry for target");

#if defined(HAVE_LOGIN_CAP_H)
	if (setusercontext(NULL, pw, target, LOGIN_SETGROUP |
	    LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
	    LOGIN_SETUSER) != 0)
		errx(1, "failed to set user context for target");
#endif
        /*
	if (pledge("stdio rpath exec", NULL) == -1)
		err(1, "pledge");
        */

	if (getcwd(cwdpath, sizeof(cwdpath)) == NULL)
		cwd = "(failed)";
	else
		cwd = cwdpath;

	/*
        if (pledge("stdio exec", NULL) == -1)
		err(1, "pledge");
        */
#ifndef HAVE_LOGIN_CAP_H
        /* If we effectively are root, set the UID to actually be root to avoid
           permission errors. */
        if (target != 0)
           setuid(target);
        if ( geteuid() == ROOT_UID )
           setuid(ROOT_UID);
#endif

	syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
	    myname, cmdline, pw->pw_name, cwd);

	envp = prepenv(rule);

	if (rule->cmd) {
		if (setenv("PATH", safepath, 1) == -1)
			err(1, "failed to set PATH '%s'", safepath);
	}
	execvpe(cmd, argv, envp);
	if (errno == ENOENT)
		errx(1, "%s: command not found", cmd);
	err(1, "%s", cmd);
}
void Check::Out_put_config()
{
	mpsconfig CON; //解析条件格納クラス
	stringstream day;
	double Mh=CON.get_magnet_H();//磁石の高さ
	double Mc=CON.get_magnet_Z();//自作中心座標
	double MMd=(abs((Mh/2)+Mc)+0.006)*1000;	//0.006?なぜ決め打ちなのか15/5/24
	day<<checkf<<Set_y_m_d()<<".dat";
	system("mkdir Check");
	ofstream checkconfig(day.str());
	if(checkconfig.fail()){
		system("mkdir Check");
		ofstream checkconfig(day.str());//同じ階層でないと書き込めない?ここでファイルを作ると空のファイルができる。
		if(!checkconfig){
			cout<<"can't open file(checkconfig) "<<endl;	
			getchar();
		}
	}
	checkconfig<<"///////解析条件////////"<<endl;
	checkconfig<<"時間刻み="<<CON.get_dt()<<endl;
	checkconfig<<"step="<<CON.get_step()<<endl;
	checkconfig<<"interval="<<CON.get_interval()<<endl;
	checkconfig<<"distancebp="<<CON.get_distancebp()<<endl;	
	if(CON.get_FEM_flag()==0) checkconfig<<"FEM=OFF"<<endl;
	else checkconfig<<"FEM=ON"<<endl;
	if(CON.get_nonlinear_elastic_flag()==0) checkconfig<<"elastic nonlinearity=OFF"<<endl;
	else checkconfig<<"elastic nonlinearity=ON"<<endl;
	cout<<endl;
	checkconfig<<"///////モデル条件////////"<<endl;
	checkconfig<<"model_number="<<CON.get_model_number()<<endl;
	if(CON.get_FEM_flag()==ON)
	{
		checkconfig<<"電磁場の解法="<<CON.get_EM_method()<<endl;
		if(CON.get_EM_method()==1)
		{
			checkconfig<<"MREと磁石の距離[mm]="<<MMd<<endl;
			checkconfig<<"MREの比透磁率="<<CON.get_RP()<<endl;
			checkconfig<<"ICCG法FEMの解析度="<<CON.get_FEMCGep()<<"\n";
			checkconfig<<"球の半径="<<CON.get_R1()<<"\n";
		}
	}
	if(CON.get_flag_ELAST()==ON)
	{
		checkconfig<<"MREのヤング率="<<CON.get_E_m()<<endl;
		checkconfig<<"MREのポアソン比="<<CON.get_v_m()<<endl;
		checkconfig<<"viscosity="<<CON.get_nensei()<<endl;
	}
	if(CON.get_flag_HYPER()==ON)
	{
		checkconfig<<"c10="<<CON.get_c10()<<endl;
		checkconfig<<"c01="<<CON.get_c01()<<endl;
		checkconfig<<"hyper_density="<<CON.get_hyper_density()<<endl;
	
		if(CON.get_flag_vis()==ON)
		{
			checkconfig<<"viscosity="<<CON.get_h_viscousity()<<endl;
		}
	}

/*		if(CON.get_avoid_step()!=0)
			checkconfig<<"避けているstep="<<CON.get_avoid_step()<<","<<CON.get_avoid_step2()<<","<<CON.get_avoid_step3()<<","<<CON.get_avoid_step4()<<","<<CON.get_avoid_step5()<<","<<CON.get_avoid_step6()<<","<<CON.get_avoid_step7()<<"\n";*/

	checkconfig.close();
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
   int ret, opt, conn, plugins_loaded = 0, banner_displayed = 0;
   unsigned long now, lastconn = time(NULL);
   FILE *urandom;

   runlevel = RL_OFFLINE;   

   while ((opt = getopt(argc, argv, "c:dj:u:vh")) != -1) {
      switch(opt) {
         case 'c':
            settings.config = optarg;
            break;
         case 'd':
            settings.daemonize = 1;
            break;
         case 'j':
            settings.chroot = optarg;
            break;
         case 'u':
            settings.chuser = optarg;
            break;
         case 'v':
            print_version();
            break;
         case 'h':
         default:
            print_usage(argv[0]);
            break;
      }
   }

   srand(time(NULL));
   
   urandom = fopen("/dev/urandom", "r");
   srrand(time(NULL) ^ getpid(), urandom);

   if (config_parse(settings.config)) {
      fprintf(stderr, "Unable to load configuration file '%s'.\n",
	settings.config);
      return -1;
   }

   if (checkconfig())
      return -1;

   if (settings.daemonize) {
      ret = fork();
      switch(ret) {
         case -1:
            fprintf(stderr, "Unable to fork to background\n");
            return -1;
        default:
            return 0;
      }
   }

   if (secure_it(settings.chroot, settings.chuser)) {
      fprintf(stderr, "Failed to chroot/setuid\n");
      return -1;
   }

#ifdef TLS
  if (gnutls_global_init() == GNUTLS_E_SUCCESS)
    atexit(gnutls_global_deinit);
  else
    fprintf(stderr, "Unable to initialize TLS library\n");
#endif

  if (dns_init() == -1)
      warn("Unable to initialize dns resolver\n");
  
   for(runlevel = RL_RUNNING; runlevel;) {
      if (irc_init() == -1) {
         warn("Unable to init irc data structure");
         return -1;
      }

      if(!plugins_loaded) {
         plugins_load();
         plugins_loaded = 1;
      }

      if(!banner_displayed) {
         banner_displayed = banner("Welcome to " PACKAGE_STRING
#ifdef SVN_REV
            "." SVN_REV
#endif
         );
      }

      while ((runlevel == RL_RUNNING) && (irc_conn() == -1)) {
         warn("Unable to establish irc connection\n");
         sleep(RECONNECT_DELAY);
      }

      lastconn = time(NULL);
      while(runlevel == RL_RUNNING)
         io_loop(100);
      
      irc_free();

      if((runlevel != RL_RUNNING) && plugins_loaded) { 
         plugins_unload();
         plugins_loaded = 0;
      }
      
      if(runlevel == RL_RELOAD) {
         printc("Reloading config file '%s'...\n", settings.config);
         if(config_parse(settings.config)) {
            warn("Error reloading config file.\n");
            runlevel = RL_OFFLINE;
         } else if(checkconfig()) {
            runlevel = RL_OFFLINE;
         }
         runlevel = RL_RUNNING;
      }

      conn = 0;
      now = time(NULL);
      if(runlevel != RL_OFFLINE) {
        runlevel = RL_RUNNING;
        if (now < lastconn + RECONNECT_DELAY)
          sleep(lastconn + RECONNECT_DELAY - now);
      }
   }

   if(urandom)
      fclose(urandom);
   return 0;
}
int	main (int argc, char *argv[])
{
	dki_t	*data = NULL;
	dki_t	*dkp;
	int	c;
	int	opt_index;
	int	action;
	const	char	*file;
	const	char	*defconfname = NULL;
	char	*p;
	char	str[254+1];
	const char	*keyname = NULL;
	int		searchtag;
	zconf_t	*config;

	progname = *argv;
	if ( (p = strrchr (progname, '/')) )
		progname = ++p;
	view = getnameappendix (progname, "dnssec-zkt");

	defconfname = getdefconfname (view);
	config = loadconfig ("", (zconf_t *)NULL);	/* load built in config */
	if ( fileexist (defconfname) )			/* load default config file */
		config = loadconfig (defconfname, config);
	if ( config == NULL )
		fatal ("Out of memory\n");
	setglobalflags (config);

        opterr = 0;
	opt_index = 0;
	action = 0;
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
	while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 )
#else
	while ( (c = getopt (argc, argv, short_options)) != -1 )
#endif
	{
		switch ( c )
		{
		case '9':		/* ksk rollover help */
			ksk_roll ("help", c - '0', NULL, NULL);
			exit (1);
		case '1':		/* ksk rollover: create new key */
		case '2':		/* ksk rollover: publish DS */
		case '3':		/* ksk rollover: delete old key */
		case '0':		/* ksk rollover: show current status */
			action = c;
			if ( !optarg )
				usage ("ksk rollover requires an domain argument", config);
			kskdomain = domain_canonicdup (optarg);
			break;
		case 'h':
		case 'K':
		case 'Z':
			action = c;
			break;
		case 'C':
			pathflag = !pathflag;
			/* fall through */
		case 'P':
		case 'S':
		case 'A':
		case 'D':
		case 'R':
		case 's':
		case 19:
		case 20:
			if ( (keyname = parsetag (optarg, &searchtag)) != NULL )
				keyname = domain_canonicdup (keyname);
			action = c;
			break;
		case 'F':		/* set key lifetime */
			lifetime = atoi (optarg);
			action = c;
			break;
		case 'V':		/* view name */
			view = optarg;
			defconfname = getdefconfname (view);
			if ( fileexist (defconfname) )		/* load default config file */
				config = loadconfig (defconfname, config);
			if ( config == NULL )
				fatal ("Out of memory\n");
			setglobalflags (config);
			break;
		case 'c':
			config = loadconfig (optarg, config);
			setglobalflags (config);
			checkconfig (config);
			break;
		case 'O':		/* read option from commandline */
			config = loadconfig_fromstr (optarg, config);
			setglobalflags (config);
			checkconfig (config);
			break;
		case 'd':		/* ignore directory arg */
			dirflag = 1;
			break;
		case 'k':		/* ksk only */
			zskflag = 0;
			break;
		case 'r':		/* switch recursive flag */
			recflag = !recflag;
			break;
		case 'z':		/* zsk only */
			kskflag = 0;
			break;
		case ':':
			snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n",
										optopt);
			usage (str, config);
			break;
		case '?':
			if ( isprint (optopt) )
				snprintf (str, sizeof(str), "Unknown option \"-%c\".\n",
										optopt);
			else
				snprintf (str, sizeof (str), "Unknown option char \\x%x.\n",
										optopt);
			usage (str, config);
			break;
		default:
			abort();
		}
	}

	if ( kskflag == 0 && zskflag == 0 )
		kskflag = zskflag = 1;

	c = optind;
	do {
		if ( c >= argc )		/* no args left */
			file = config->zonedir;	/* use default directory */
		else
			file = argv[c++];

		if ( is_directory (file) )
			parsedirectory (file, &data);
		else
			parsefile (file, &data);

	}  while ( c < argc );	/* for all arguments */

	switch ( action )
	{
	case 'h':
		usage ("", config);
	case 'C':
		createkey (keyname, data, config);
		break;
	case 'P':
	case 'S':
	case 'A':
	case 'D':
		if ( (dkp = (dki_t*)zkt_search (data, searchtag, keyname)) == NULL )
			fatal ("Key with tag %u not found\n", searchtag);
		else if ( dkp == (void *) 01 )
			fatal ("Key with tag %u found multiple times\n", searchtag);
		if ( (c = dki_setstatus_preservetime (dkp, action)) != 0 )
			fatal ("Couldn't change status of key %u: %d\n", searchtag, c);
		break;
	case 19:	/* remove (rename) key file */
		if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL )
			fatal ("Key with tag %u not found\n", searchtag);
		else if ( dkp == (void *) 01 )
			fatal ("Key with tag %u found multiple times\n", searchtag);
		dki_remove (dkp);
		break;
	case 20:	/* destroy the key (remove the files!) */
		if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL )
			fatal ("Key with tag %u not found\n", searchtag);
		else if ( dkp == (void *) 01 )
			fatal ("Key with tag %u found multiple times\n", searchtag);
		dki_destroy (dkp);
		break;
	case 'R':
		if ( (dkp = (dki_t *)zkt_search (data, searchtag, keyname)) == NULL )
			fatal ("Key with tag %u not found\n", searchtag);
		else if ( dkp == (void *) 01 )
			fatal ("Key with tag %u found multiple times\n", searchtag);
		if ( (c = dki_setstatus (dkp, action)) != 0 )
			fatal ("Couldn't change status of key %u: %d\n", searchtag, c);
		break;
	case '1':	/* ksk rollover new key */
	case '2':	/* ksk rollover publish DS */
	case '3':	/* ksk rollover delete old key */
	case '0':	/* ksk rollover status */
		ksk_roll (kskdomain, action - '0', data, config);
		break;
	case 'F':
		zkt_setkeylifetime (data);
		/* fall through */
	default:
		zkt_list_keys (data);
	}

	return 0;
}