struct deviceProfile {
	char		deviceName[8];
	int		deviceSeid[3];
		unsigned int	securityCategory;
		unsigned int	integrityCategory;
		unsigned long	securityCompart;
		unsigned int	owner;
		unsigned int	group;
		unsigned int	da;
		unsigned long	tiiPriv;
	int		validRequired;	/* boolean */
	int		assignRequired;	/* boolean */
	};

main(argc, argv)
int	argc;
char	*argv[];
{
register int		ifd, ofd, i;
char			packed[8 + 4 + 1+1+4+2+2+2+4 + 1 + 1];
struct deviceProfile	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++;
	*to++ = *from++; *to++ = '\0'; *to++ = '\0'; *to++ = '\0';	/* nsp */
	if (*from == '\0377') {
		unpacked.deviceSeid[1] = -1;
		from++;
		to += 4;
		}
	else {
		*to++ = *from++; *to++ = '\0'; *to++ = '\0'; *to++ = '\0';	/* uniqId0 */
		}
	*to++ = *from++; *to++ = *from++; *to++ = '\0'; *to++ = '\0';	/* uniqId1 */
	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 */
	if (*from = 'y')	
		unpacked.validRequired = 1;
	else if (*from = 'n')
		unpacked.validRequired = 0;
	else {
		printf("Bad value in KSOS-11 validRequired field.\n");
		unpacked.validRequired = 0;
		}
	from++;
	if (*from = 'y')	
		unpacked.assignRequired = 1;
	else if (*from = 'n')
		unpacked.assignRequired = 0;
	else {
		printf("Bad value in KSOS-11 assignRequired field.\n");
		unpacked.assignRequired = 0;
		}
	printf("device name     : %s\n", unpacked.deviceName);
	printf("device SEID     : %d %d %d\n", unpacked.deviceSeid[0], unpacked.deviceSeid[1], unpacked.deviceSeid[2]);
	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("d'ary access    : 0%o\n", unpacked.da);
	printf("privileges      : 0x%lx\n", unpacked.tiiPriv);
	printf("valid required  : %d\n", unpacked.validRequired);
	printf("assign required : %d\n\n", unpacked.assignRequired);
	(void)write(ofd, (char *)&unpacked, sizeof unpacked);
	}
(void)close(ifd);
(void)close(ofd);
}
