/*
 * resetpwtime.c: Reset a user's password change time on HP-UX.
 *
 * Author: Darren Tucker (dtucker at zip.com.au), 2003-11-18.
 * Hereby placed in the public domain.
 *
 * Compile with: cc -o resetpwtime resetpwtime.c -lsec
 *
 * Requires root privilege, making this setuid is *NOT* recommended.
 *
 * Why?  I do automated testing in both normal and Trusted Mode on a single
 * box, by converting with /usr/lbin/tsconvert.  Unfortunately, every time
 * this happens, it resets the password change time and requires it to be
 * changed at next login.  This messes up my tests, so I wrote this quick
 * hack to rest the password change time for a single account, which runs
 * from my test script.
 */

#include <stdio.h>
#include <sys/types.h>
#include <hpsecurity.h>
#include <prot.h>
#include <errno.h>

int
main(int argc, char **argv)
{
	struct pr_passwd *pr, newpr;
	char *name;

	if (argc != 2) {
		printf("Usage: %s username\n", argv[0]);
		exit(0);
	}
	name = argv[1];

	pr = getprpwnam(name);

	if (pr == NULL) {
		fprintf(stderr, "Could not get passwd entry\n");
		exit(1);
	}
		
	/* copy and modify */
	newpr = *pr;
	newpr.ufld.fd_schange = time(NULL);
	newpr.uflg.fg_schange = 1;

	if (putprpwnam(name, &newpr) == 0) {
		fprintf(stderr, "Failed to write passwd entry\n");
		exit(1);
	}
}
