au_id_t ucred_getauid(const ucred_t *uc) { /* LINTED: alignment */ const auditinfo64_addr_t *ainfo = UCAUD(uc); if (ainfo == NULL) return (AU_NOAUDITID); return (ainfo->ai_auid); }
au_asid_t ucred_getasid(const ucred_t *uc) { /* LINTED: alignment */ const auditinfo64_addr_t *ainfo = UCAUD(uc); if (ainfo == NULL) return ((au_asid_t)-1); return (ainfo->ai_asid); }
const au_mask_t * ucred_getamask(const ucred_t *uc) { /* LINTED: alignment */ const auditinfo64_addr_t *ainfo = UCAUD(uc); if (ainfo == NULL) { errno = EINVAL; return (NULL); } return (&ainfo->ai_mask); }
/* * Convert a credential into a "ucred". Allow the caller to specify * and aligned buffer, e.g., in an mblk, so we don't have to allocate * memory and copy it twice. * * This function may call cred2ucaud(), which calls CRED(). Since this * can be called from an interrupt thread, receiver's cred (rcr) is needed * to determine whether audit info should be included. */ struct ucred_s * cred2ucred(const cred_t *cr, pid_t pid, void *buf, const cred_t *rcr) { struct ucred_s *uc; uint32_t realsz = ucredminsize(cr); ts_label_t *tslp = is_system_labeled() ? crgetlabel(cr) : NULL; /* The structure isn't always completely filled in, so zero it */ if (buf == NULL) { uc = kmem_zalloc(realsz, KM_SLEEP); } else { bzero(buf, realsz); uc = buf; } uc->uc_size = realsz; uc->uc_pid = pid; uc->uc_projid = cr->cr_projid; uc->uc_zoneid = crgetzoneid(cr); if (REMOTE_PEER_CRED(cr)) { /* * Other than label, the rest of cred info about a * remote peer isn't available. Copy the label directly * after the header where we generally copy the prcred. * That's why we use sizeof (struct ucred_s). The other * offset fields are initialized to 0. */ uc->uc_labeloff = tslp == NULL ? 0 : sizeof (struct ucred_s); } else { uc->uc_credoff = UCRED_CRED_OFF; uc->uc_privoff = UCRED_PRIV_OFF; uc->uc_audoff = UCRED_AUD_OFF; uc->uc_labeloff = tslp == NULL ? 0 : UCRED_LABEL_OFF; cred2prcred(cr, UCCRED(uc)); cred2prpriv(cr, UCPRIV(uc)); if (audoff == 0 || cred2ucaud(cr, UCAUD(uc), rcr) != 0) uc->uc_audoff = 0; } if (tslp != NULL) bcopy(&tslp->tsl_label, UCLABEL(uc), sizeof (bslabel_t)); return (uc); }