struct uaadb {
	char		userName[8];
	char		userPassword[11];
	char		filler1;
	char		loginOk;
	char		filler2[3];
		unsigned int	max_securityCategory;
		unsigned int	max_integrityCategory;
		unsigned long	max_securityCompart;
		unsigned int	securityCategory;
		unsigned int	integrityCategory;
		unsigned long	securityCompart;
		unsigned int	owner;
		unsigned int	group;
		unsigned int	da;
		unsigned long	tiiPriv;
	char		loginDir[64];
	char		loginShell[64];
	char		loginEmul[64];
	char		filler[20];
	};

main(argc, argv)
int	argc;
char	*argv[];
{
register int		ifd, ofd, i;
char			packed[8 + 11 + /* filler */ 1 + 1 + /* filler */ 1 + 1+1+4 + 1+1+4+2+2+2+4 + 64 + 64 + 64 + 20];
struct uaadb		unpacked;
register char		*from, *to;

if (argc != 3) {
	printf("Usage: %s input_file output_file\n", argv[0]);
	printf("       Use krd to get the input file and kwr to install the output file.\n");
	exit(1);
	}
if ((ifd = open(argv[1], 0)) < 0) {
	perror(argv[1]);
	exit(2);
	}
if ((ofd = creat(argv[2], 0666)) < 0) {
	perror(argv[2]);
	(void)close(ifd);
	exit(3);
	}
while (read(ifd, packed, sizeof packed) == sizeof packed) {
	from = (char *)&packed[0];
	to = (char *)&unpacked;
	for (i = 0; i < 8; i++)
		*to++ = *from++;	/* userName */
	for (i = 0; i < 11; i++)
		*to++ = *from++;	/* userPassword */
	*to++ = *from++;		/* filler1 */
	*to++ = *from++; *to++ = *from++; *to++ = '\0'; *to++ = '\0';	/* loginOk */
	unpacked.max_securityCategory = *from++ & 0377; to += 4;
	unpacked.max_integrityCategory = *from++ & 0377; to += 4;
	for (i = 0; i < 4; i++)
		*to++ = *from++;	/* max_securityCompart */
	unpacked.securityCategory = *from++ & 0377; to += 4;
	unpacked.integrityCategory = *from++ & 0377; to += 4;
	for (i = 0; i < 4; i++)
		*to++ = *from++;	/* securityCompart */
	*to++ = *from++; *to++ = *from++; *to++ = '\0'; *to++ = '\0';	/* owner */
	*to++ = *from++; *to++ = *from++; *to++ = '\0'; *to++ = '\0';	/* group */
	*to++ = *from++; *to++ = *from++; *to++ = '\0'; *to++ = '\0';	/* da */
	for (i = 0; i < 4; i++)
		*to++ = *from++;	/* tiiPriv */
	for (i = 0; i < 64; i++)
		*to++ = *from++;	/* loginDir */
	for (i = 0; i < 64; i++)
		*to++ = *from++;	/* loginShell */
	for (i = 0; i < 64; i++)
		*to++ = *from++;	/* loginEmul */
	for (i = 0; i < 20; i++)
		*to++ = *from++;	/* filler */
	printf("user name           : %s\n", unpacked.userName);
	if (strncmp(unpacked.userName, "bill", 8) == 0) {
		strcpy(unpacked.userName, "jeff");
		printf("           CHANGED TO %s\n", unpacked.userName);
		}
	else if (strncmp(unpacked.userName, "jh", 8) == 0) {
		strcpy(unpacked.userName, "jw");
		printf("           CHANGED TO %s\n", unpacked.userName);
		}
	printf("user password       : %s\n", unpacked.userPassword);
	if (strncmp(unpacked.userPassword, "Seldom!", 11) == 0) {
		strncpy(unpacked.userPassword, "ksos", 11);
		printf("           CHANGED TO %s\n", unpacked.userPassword);
		}
	printf("login ok            : %c\n", unpacked.loginOk);
	printf("max security cat    : %d\n", unpacked.securityCategory);
	printf("max ingegrity cat   : %d\n", unpacked.integrityCategory);
	printf("max security compart: 0x%lx\n", unpacked.securityCompart);
	printf("security cat        : %d\n", unpacked.securityCategory);
	printf("ingegrity cat       : %d\n", unpacked.integrityCategory);
	printf("security compart    : 0x%lx\n", unpacked.securityCompart);
	printf("owner               : %u\n", unpacked.owner);
	printf("group               : %u\n", unpacked.group);
	printf("discretionary access: 0%o\n", unpacked.da);
	printf("privileges          : 0x%lx\n", unpacked.tiiPriv);
	printf("login directory     : %s\n", unpacked.loginDir);
	printf("login shell         : %s\n", unpacked.loginShell);
	printf("login emulator      : %s\n\n", unpacked.loginEmul);
	(void)write(ofd, (char *)&unpacked, sizeof unpacked);
	}
(void)close(ifd);
(void)close(ofd);
}
