-#if CONFIG_LCTX
-/*
- * __mac_get_lcid:
- * Get login context ID. A login context associates a BSD process
- * with an instance of a user. For more information see getlcid(2) man page.
- *
- * Parameters: p Process requesting the get
- * uap User argument descriptor (see below)
- * ret (ignored)
- *
- * Indirect: uap->lcid login context ID to search
- * uap->mac_p.m_buflen MAC info buffer size
- * uap->mac_p.m_string MAC info user address
- *
- * Returns: 0 Success
- * !0 Not success
- */
-int
-__mac_get_lcid(proc_t p, struct __mac_get_lcid_args *uap, int *ret __unused)
-{
- char *elements, *buffer;
- struct user_mac mac;
- struct lctx *l;
- int error;
- size_t ulen;
-
- AUDIT_ARG(value32, uap->lcid);
- if (IS_64BIT_PROCESS(p)) {
- struct user64_mac mac64;
- error = copyin(uap->mac_p, &mac64, sizeof(mac64));
- mac.m_buflen = mac64.m_buflen;
- mac.m_string = mac64.m_string;
- } else {
- struct user32_mac mac32;
- error = copyin(uap->mac_p, &mac32, sizeof(mac32));
- mac.m_buflen = mac32.m_buflen;
- mac.m_string = mac32.m_string;
- }
-
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- l = lcfind(uap->lcid);
- if (l == NULL)
- return (ESRCH);
-
- MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
- if (error) {
- LCTX_UNLOCK(l);
- FREE(elements, M_MACTEMP);
- return (error);
- }
- AUDIT_ARG(mac_string, elements);
- MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = mac_lctx_label_externalize(l->lc_label, elements,
- buffer, mac.m_buflen);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
- LCTX_UNLOCK(l);
- FREE(buffer, M_MACTEMP);
- FREE(elements, M_MACTEMP);
- return (error);
-}
-
-/*
- * __mac_get_lctx:
- * Get login context label. A login context associates a BSD process
- * associated with an instance of a user.
- *
- * Parameters: p Process requesting the get
- * uap User argument descriptor (see below)
- * ret (ignored)
- *
- * Indirect: uap->lcid login context ID to search
- * uap->mac_p MAC info
- *
- * Returns: 0 Success
- * !0 Not success
- *
- */
-int
-__mac_get_lctx(proc_t p, struct __mac_get_lctx_args *uap, int *ret __unused)
-{
- char *elements, *buffer;
- struct user_mac mac;
- int error;
- size_t ulen;
-
- if (IS_64BIT_PROCESS(p)) {
- struct user64_mac mac64;
- error = copyin(uap->mac_p, &mac64, sizeof(mac64));
- mac.m_buflen = mac64.m_buflen;
- mac.m_string = mac64.m_string;
- } else {
- struct user32_mac mac32;
- error = copyin(uap->mac_p, &mac32, sizeof(mac32));
- mac.m_buflen = mac32.m_buflen;
- mac.m_string = mac32.m_string;
- }
-
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- MALLOC(elements, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, elements, mac.m_buflen, &ulen);
- if (error) {
- FREE(elements, M_MACTEMP);
- return (error);
- }
- AUDIT_ARG(mac_string, elements);
- MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
-
- proc_lock(p);
- if (p->p_lctx == NULL) {
- proc_unlock(p);
- error = ENOENT;
- goto out;
- }
-
- error = mac_lctx_label_externalize(p->p_lctx->lc_label,
- elements, buffer, mac.m_buflen);
- proc_unlock(p);
- if (error == 0)
- error = copyout(buffer, mac.m_string, strlen(buffer)+1);
-
-out:
- FREE(buffer, M_MACTEMP);
- FREE(elements, M_MACTEMP);
- return (error);
-}
-
-int
-__mac_set_lctx(proc_t p, struct __mac_set_lctx_args *uap, int *ret __unused)
-{
- struct user_mac mac;
- struct label *intlabel;
- char *buffer;
- int error;
- size_t ulen;
-
- if (IS_64BIT_PROCESS(p)) {
- struct user64_mac mac64;
- error = copyin(uap->mac_p, &mac64, sizeof(mac64));
- mac.m_buflen = mac64.m_buflen;
- mac.m_string = mac64.m_string;
- } else {
- struct user32_mac mac32;
- error = copyin(uap->mac_p, &mac32, sizeof(mac32));
- mac.m_buflen = mac32.m_buflen;
- mac.m_string = mac32.m_string;
- }
- if (error)
- return (error);
-
- error = mac_check_structmac_consistent(&mac);
- if (error)
- return (error);
-
- MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK);
- error = copyinstr(mac.m_string, buffer, mac.m_buflen, &ulen);
- if (error) {
- FREE(buffer, M_MACTEMP);
- return (error);
- }
- AUDIT_ARG(mac_string, buffer);
-
- intlabel = mac_lctx_label_alloc();
- error = mac_lctx_label_internalize(intlabel, buffer);
- FREE(buffer, M_MACTEMP);
- if (error)
- goto out;
-
- proc_lock(p);
- if (p->p_lctx == NULL) {
- proc_unlock(p);
- error = ENOENT;
- goto out;
- }
-
- error = mac_lctx_check_label_update(p->p_lctx, intlabel);
- if (error) {
- proc_unlock(p);
- goto out;
- }
- mac_lctx_label_update(p->p_lctx, intlabel);
- proc_unlock(p);
-out:
- mac_lctx_label_free(intlabel);
- return (error);
-}
-
-#else /* LCTX */
-
-int
-__mac_get_lcid(proc_t p __unused, struct __mac_get_lcid_args *uap __unused, int *ret __unused)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_get_lctx(proc_t p __unused, struct __mac_get_lctx_args *uap __unused, int *ret __unused)
-{
-
- return (ENOSYS);
-}
-
-int
-__mac_set_lctx(proc_t p __unused, struct __mac_set_lctx_args *uap __unused, int *ret __unused)
-{
-
- return (ENOSYS);
-}
-#endif /* !LCTX */
-