FreeBSD/sys/security/audit/bsm_token.c
/*
 * token ID                1 byte
 * owner user ID           4 bytes
 * owner group ID          4 bytes
 * creator user ID         4 bytes
 * creator group ID        4 bytes
 * access mode             4 bytes
 * slot sequence #         4 bytes
 * key                     4 bytes
 */
token ID                1 byte
owner user ID           4 bytes
owner group ID          4 bytes
creator user ID         4 bytes
creator group ID        4 bytes
access mode             4 bytes
slot sequence #         4 bytes
key                     4 bytes
token ID 1 byte owner user ID 4 bytes owner group ID 4 bytes creator user ID 4 bytes creator group ID 4 bytes access mode 4 bytes slot sequence # 4 bytes key 4 bytes
token_t *
au_to_ipc_perm(struct ipc_perm *perm)
{
	token_t *t;
	u_char *dptr = NULL;
	u_int16_t pad0 = 0;
	GET_TOKEN_AREA(t, dptr, sizeof(u_char) + 12 * sizeof(u_int16_t) +
	    sizeof(u_int32_t));
	ADD_U_CHAR(dptr, AUT_IPC_PERM);
	if (sizeof(perm->uid) != sizeof(u_int32_t)) {
		ADD_U_INT16(dptr, pad0);
		ADD_U_INT16(dptr, perm->uid);
		ADD_U_INT16(dptr, pad0);
		ADD_U_INT16(dptr, perm->gid);
		ADD_U_INT16(dptr, pad0);
		ADD_U_INT16(dptr, perm->cuid);
		ADD_U_INT16(dptr, pad0);
		ADD_U_INT16(dptr, perm->cgid);
	} else {
		ADD_U_INT32(dptr, perm->uid);
		ADD_U_INT32(dptr, perm->gid);
		ADD_U_INT32(dptr, perm->cuid);
		ADD_U_INT32(dptr, perm->cgid);
	}
	ADD_U_INT16(dptr, pad0);
	ADD_U_INT16(dptr, perm->mode);
	ADD_U_INT16(dptr, pad0);
	ADD_U_INT16(dptr, perm->seq);
	ADD_U_INT32(dptr, perm->key);
	return (t);
}
token_t * au_to_ipc_perm ( struct ipc_perm * perm ) { token_t * t ; u_char * dptr = NULL ; u_int16_t pad0 = 0 ; GET_TOKEN_AREA ( t , dptr , sizeof ( u_char ) + 12 * sizeof ( u_int16_t ) + sizeof ( u_int32_t ) ) ; ADD_U_CHAR ( dptr , AUT_IPC_PERM ) ; if ( sizeof ( perm -> uid ) != sizeof ( u_int32_t ) ) { ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> uid ) ; ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> gid ) ; ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> cuid ) ; ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> cgid ) ; } else { ADD_U_INT32 ( dptr , perm -> uid ) ; ADD_U_INT32 ( dptr , perm -> gid ) ; ADD_U_INT32 ( dptr , perm -> cuid ) ; ADD_U_INT32 ( dptr , perm -> cgid ) ; } ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> mode ) ; ADD_U_INT16 ( dptr , pad0 ) ; ADD_U_INT16 ( dptr , perm -> seq ) ; ADD_U_INT32 ( dptr , perm -> key ) ; return ( t ) ; }
token ID                1 byte
 owner user ID           4 bytes
 owner group ID          4 bytes
 creator user ID         4 bytes
 creator group ID        4 bytes
 access mode             4 bytes
 slot sequence #         4 bytes
 key                     4 bytes
token ID 1 byte owner user ID 4 bytes owner group ID 4 bytes creator user ID 4 bytes creator group ID 4 bytes access mode 4 bytes slot sequence # 4 bytes key 4 bytes
/*
	 * Systems vary significantly in what types they use in struct
	 * ipc_perm; at least a few still use 16-bit uid's and gid's, so
	 * allow for that, as BSM define 32-bit values here.
	 * Some systems define the sizes for ipc_perm members as 2 bytes;
	 * BSM defines 4 so pad with 0.
	 *
	 * XXXRW: Possibly shoulid be conditionally compiled, and more cases
	 * need to be handled.
	 */