#ifndef _SYS_UCRED_H
#define _SYS_UCRED_H
#include <sys/types.h>
#include <sys/procfs.h>
#include <sys/cred.h>
#include <sys/priv.h>
#include <sys/tsol/label.h>
#include <sys/tsol/label_macro.h>
#ifdef _KERNEL
#include <c2/audit.h>
#else
#include <bsm/audit.h>
#endif
#ifndef _KERNEL
#include <unistd.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_KERNEL) || _STRUCTURED_PROC != 0
struct ucred_s {
uint32_t uc_size;
uint32_t uc_credoff;
uint32_t uc_privoff;
pid_t uc_pid;
uint32_t uc_audoff;
zoneid_t uc_zoneid;
projid_t uc_projid;
uint32_t uc_labeloff;
};
#define UCCRED(uc) (prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \
((char *)(uc)) + (uc)->uc_credoff)
#define UCPRIV(uc) (prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \
((char *)(uc)) + (uc)->uc_privoff)
#define UCAUD(uc) (auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \
((char *)(uc)) + (uc)->uc_audoff)
#define UCLABEL(uc) (bslabel_t *)(((uc)->uc_labeloff == 0) ? NULL : \
((char *)(uc)) + (uc)->uc_labeloff)
#endif
#define UCREDSYS_UCREDGET 0
#define UCREDSYS_GETPEERUCRED 1
#ifdef _KERNEL
extern uint32_t ucredminsize(const cred_t *);
#define UCRED_PRIV_OFF (sizeof (struct ucred_s))
#define UCRED_AUD_OFF (UCRED_PRIV_OFF + priv_prgetprivsize(NULL))
#define UCRED_LABEL_OFF (UCRED_AUD_OFF + get_audit_ucrsize())
#define UCRED_CRED_OFF (UCRED_LABEL_OFF + \
(is_system_labeled() ? sizeof (bslabel_t) : 0))
#define UCRED_SIZE (UCRED_CRED_OFF + sizeof (prcred_t) + \
(ngroups_max - 1) * sizeof (gid_t))
struct proc;
extern struct ucred_s *pgetucred(struct proc *);
extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *,
const cred_t *);
extern int get_audit_ucrsize(void);
#else
#if _STRUCTURED_PROC != 0
#define UCRED_SIZE(ip) (sizeof (struct ucred_s) + sizeof (prcred_t) + \
((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \
sizeof (prpriv_t) + \
sizeof (priv_chunk_t) * \
((ip)->priv_setsize * (ip)->priv_nsets - 1) + \
(ip)->priv_infosize + \
sizeof (auditinfo64_addr_t) + \
sizeof (bslabel_t))
#endif
extern struct ucred_s *_ucred_alloc(void);
#endif
#ifdef __cplusplus
}
#endif
#endif