- if (fmode & O_CREAT) {
- if ((fmode & O_EXCL) && incache) {
- AUDIT_ARG(posix_ipc_perm, pinfo->pshm_uid,
- pinfo->pshm_gid, pinfo->pshm_mode);
-
- /* shm obj exists and opened O_EXCL */
-#if notyet
- if (pinfo->pshm_flags & PSHM_INDELETE) {
- }
-#endif
- error = EEXIST;
- PSHM_SUBSYS_UNLOCK();
- goto bad1;
- }
- if (!incache) {
- PSHM_SUBSYS_UNLOCK();
- /* create a new one */
- MALLOC(pinfo, struct pshminfo *, sizeof(struct pshminfo), M_SHM, M_WAITOK|M_ZERO);
- if (pinfo == NULL) {
- error = ENOSPC;
- goto bad1;
- }
- PSHM_SUBSYS_LOCK();
- pinfo_alloc = 1;
- pinfo->pshm_flags = PSHM_DEFINED | PSHM_INCREATE;
- pinfo->pshm_usecount = 1; /* existence reference */
- pinfo->pshm_mode = cmode;
- pinfo->pshm_uid = kauth_cred_getuid(kauth_cred_get());
- pinfo->pshm_gid = kauth_cred_get()->cr_gid;
- bcopy(pnbuf, &pinfo->pshm_name[0], PSHMNAMLEN);
- pinfo->pshm_name[PSHMNAMLEN]=0;
- } else {
- /* already exists */
- if( pinfo->pshm_flags & PSHM_INDELETE) {
- PSHM_SUBSYS_UNLOCK();
- error = ENOENT;
- goto bad1;
- }
- AUDIT_ARG(posix_ipc_perm, pinfo->pshm_uid,
- pinfo->pshm_gid, pinfo->pshm_mode);
- if ( (error = pshm_access(pinfo, fmode, kauth_cred_get(), p)) ) {
- PSHM_SUBSYS_UNLOCK();
- goto bad1;
- }
- }
+ if (error == ENOENT) {
+ error = EINVAL;
+ goto bad;
+ }
+
+ if (!error) {
+ incache = 0;
+ if (fmode & O_CREAT) {
+ /* create a new one (commit the allocation) */
+ pinfo = new_pinfo;
+ pinfo->pshm_flags = PSHM_DEFINED | PSHM_INCREATE;
+ pinfo->pshm_usecount = 1; /* existence reference */
+ pinfo->pshm_mode = cmode;
+ pinfo->pshm_uid = kauth_getuid();
+ pinfo->pshm_gid = kauth_getgid();
+ bcopy(pnbuf, &pinfo->pshm_name[0], pathlen);
+ pinfo->pshm_name[pathlen]=0;
+#if CONFIG_MACF
+ error = mac_posixshm_check_create(kauth_cred_get(), nameptr);
+ if (error) {
+ goto bad;
+ }
+ mac_posixshm_label_associate(kauth_cred_get(), pinfo, nameptr);
+#endif
+ }