示例#1
0
int main (int argc, char **argv)
{
	const struct spwd *sp;
	uid_t ruid;
	gid_t rgid;
	const struct passwd *pw;

	/*
	 * Get the program name so that error messages can use it.
	 */
	Prog = Basename (argv[0]);

	sanitize_env ();
	(void) setlocale (LC_ALL, "");
	(void) bindtextdomain (PACKAGE, LOCALEDIR);
	(void) textdomain (PACKAGE);

	process_root_flag ("-R", argc, argv);

#ifdef WITH_AUDIT
	audit_help_open ();
#endif
	OPENLOG ("chage");

	ruid = getuid ();
	rgid = getgid ();
	amroot = (ruid == 0);
#ifdef WITH_SELINUX
	if (amroot && (is_selinux_enabled () > 0)) {
		amroot = (selinux_check_passwd_access (PASSWD__ROOTOK) == 0);
	}
#endif

	process_flags (argc, argv);

	check_perms ();

	if (!spw_file_present ()) {
		fprintf (stderr,
		         _("%s: the shadow password file is not present\n"),
		         Prog);
		SYSLOG ((LOG_WARN, "can't find the shadow password file"));
		closelog ();
		exit (E_SHADOW_NOTFOUND);
	}

	open_files (lflg);
	/* Drop privileges */
	if (lflg && (   (setregid (rgid, rgid) != 0)
	             || (setreuid (ruid, ruid) != 0))) {
		fprintf (stderr, _("%s: failed to drop privileges (%s)\n"),
		         Prog, strerror (errno));
		fail_exit (E_NOPERM);
	}

	pw = pw_locate (argv[optind]);
	if (NULL == pw) {
		fprintf (stderr, _("%s: user '%s' does not exist in %s\n"),
		         Prog, argv[optind], pw_dbname ());
		closelog ();
		fail_exit (E_NOPERM);
	}

	STRFCPY (user_name, pw->pw_name);
#ifdef WITH_TCB
	if (shadowtcb_set_user (pw->pw_name) == SHADOWTCB_FAILURE) {
		fail_exit (E_NOPERM);
	}
#endif
	user_uid = pw->pw_uid;

	sp = spw_locate (argv[optind]);
	get_defaults (sp);

	/*
	 * Print out the expiration fields if the user has requested the
	 * list option.
	 */
	if (lflg) {
		if (!amroot && (ruid != user_uid)) {
			fprintf (stderr, _("%s: Permission denied.\n"), Prog);
			fail_exit (E_NOPERM);
		}
#ifdef WITH_AUDIT
		audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
		              "display aging info",
		              user_name, (unsigned int) user_uid, 1);
#endif
		list_fields ();
		fail_exit (E_SUCCESS);
	}

	/*
	 * If none of the fields were changed from the command line, let the
	 * user interactively change them.
	 */
	if (!mflg && !Mflg && !dflg && !Wflg && !Iflg && !Eflg) {
		printf (_("Changing the aging information for %s\n"),
		        user_name);
		if (new_fields () == 0) {
			fprintf (stderr, _("%s: error changing fields\n"),
			         Prog);
			fail_exit (E_NOPERM);
		}
#ifdef WITH_AUDIT
		else {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change all aging information",
			              user_name, (unsigned int) user_uid, 1);
		}
#endif
	} else {
#ifdef WITH_AUDIT
		if (Mflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change max age",
			              user_name, (unsigned int) user_uid, 1);
		}
		if (mflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change min age",
			              user_name, (unsigned int) user_uid, 1);
		}
		if (dflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change last change date",
			              user_name, (unsigned int) user_uid, 1);
		}
		if (Wflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change passwd warning",
			              user_name, (unsigned int) user_uid, 1);
		}
		if (Iflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change inactive days",
			              user_name, (unsigned int) user_uid, 1);
		}
		if (Eflg) {
			audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
			              "change passwd expiration",
			              user_name, (unsigned int) user_uid, 1);
		}
#endif
	}

	update_age (sp, pw);

	close_files ();

	SYSLOG ((LOG_INFO, "changed password expiry for %s", user_name));

	closelog ();
	exit (E_SUCCESS);
}
示例#2
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  main is called with number of runs to simulate TODO: other params
 *
 * =====================================================================================
 */
int main(int argc, char* argv[])
{
    int32_t seed = (int32_t)time(0);
	StochasticLib1 s(seed);
	CRandomMersenne r((int)seed);
	process_flags(argc, argv);
	list<person> infected, removed;	
    list<person> susceptible;
    list<prevalence_data> pr_data;	
    list<birth_data> br_data;
    list<death_data> death_data;
    list<float> birth_rate_data;
    ofstream prev_out("outputs/prevalence.txt", ios::out), out("outputs/population.txt", ios::out);
    //set up data
    import_prevalence_data(pr_data);
    import_birth_rates(birth_rate_data);
    import_death_data(death_data);
	initialize_population(susceptible, infected, pr_data, s, r);

    float b_rate;
    list<float>::iterator birthrate_itr = birth_rate_data.begin();
    //print prleminary (day 0) stats
    //
    cout << "time 0: ";
    print_prevalence(susceptible, infected, prev_out);

    int year = 0;
    // run simulation
    

    int total = 0, prev_total = susceptible.size() + infected.size();

    for(int i = 0; i < NUM_ITERATIONS; ++i) // 3 month intervals
    {
        update_births(susceptible, infected, b_rate, s);
        shuffle_population(susceptible);
        compute_infected(susceptible, infected, s, r);
        update_cd4_count(infected, r);
        update_age(susceptible, infected); // quarterly update
        output_population_statistics(susceptible, infected, removed, out);
        
        //update_cd4_count(
        if(i % 20 == 0) // every 5 years
        {
            if(birthrate_itr != birth_rate_data.end())
            {
                b_rate = *birthrate_itr;
                ++birthrate_itr;
            }
        }

        if(i  % 4 == 0) // every year
        {
            compute_deaths(susceptible, infected, removed, death_data, s); // life tables assume annual
            map<string, int> S, I, R;
            ++year;
            cout << "Year: " << year << "  \t";
            total = susceptible.size() + infected.size();
            float d_p = 100.0 * (total - prev_total) / prev_total;
            prev_total = total;
            cout << "change (TOTAL population): " << d_p <<  "% (" << total << ")" << "\t";
            // TODO: this outputs/couts
            print_prevalence(susceptible, infected, prev_out);
            //cout << "susceptibles: " << susceptible.size() << " infected: " 
             //   << infected.size() << " removed: " << removed.size() << endl << endl;
            print_population_changes(susceptible, infected, removed, S, I, R);
        }
	}


    out.close();
    prev_out.close();
    return 0;
}