/* Check user, group, other permissions for access to ipc resources. return 0 if allowed  */
int ipcperms(struct kern_ipc_perm *ipcp, short flag)
/* Check user, group, other permissions for access to ipc resources. return 0 if allowed  */
int ipcperms(struct kern_ipc_perm *ipcp, short flag)
{
	uid_t euid = current_euid();
	int requested_mode, granted_mode;
	audit_ipc_obj(ipcp);
	requested_mode = (flag >> 6) | (flag >> 3) | flag;
	granted_mode = ipcp->mode;
	if (euid == ipcp->cuid ||
	    euid == ipcp->uid)
		granted_mode >>= 6;
	else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
		granted_mode >>= 3;
	if ((requested_mode & ~granted_mode & 0007) && 
	    !capable(CAP_IPC_OWNER))
		return -1;
	return security_ipc_permission(ipcp, flag);
}