#ifndef _SYS_UCRED_H_
#define _SYS_UCRED_H_
#include <sys/types.h>
#if defined(_KERNEL) || defined(_WANT_UCRED)
#include <sys/_lock.h>
#include <sys/_mutex.h>
#endif
#include <bsm/audit.h>
#if defined(_KERNEL) || defined(_WANT_UCRED)
#define CRED_FLAG_CAPMODE 0x00000001
#define CRED_FLAG_GROUPSET 0x00000002
#define CRED_SMALLGROUPS_NB 16
struct label;
struct loginclass;
struct prison;
struct uidinfo;
struct ucred {
struct mtx cr_mtx;
long cr_ref;
u_int cr_users;
u_int cr_flags;
struct auditinfo_addr cr_audit;
int cr_ngroups;
#define cr_startcopy cr_uid
uid_t cr_uid;
uid_t cr_ruid;
uid_t cr_svuid;
gid_t cr_gid;
gid_t cr_rgid;
gid_t cr_svgid;
struct uidinfo *cr_uidinfo;
struct uidinfo *cr_ruidinfo;
struct prison *cr_prison;
struct loginclass *cr_loginclass;
void *cr_pspare2[2];
#define cr_endcopy cr_label
struct label *cr_label;
gid_t *cr_groups;
int cr_agroups;
gid_t cr_smallgroups[CRED_SMALLGROUPS_NB];
};
#define NOCRED ((struct ucred *)0)
#define FSCRED ((struct ucred *)-1)
#endif
#define XU_NGROUPS 16
struct xucred {
u_int cr_version;
uid_t cr_uid;
short cr_ngroups;
union {
struct {
gid_t cr_gid;
gid_t cr_sgroups[XU_NGROUPS - 1];
};
gid_t cr_groups[XU_NGROUPS];
};
union {
void *_cr_unused1;
pid_t cr_pid;
};
};
#define XUCRED_VERSION 0
struct mac;
struct setcred {
uid_t sc_uid;
uid_t sc_ruid;
uid_t sc_svuid;
gid_t sc_gid;
gid_t sc_rgid;
gid_t sc_svgid;
u_int sc_pad;
u_int sc_supp_groups_nb;
gid_t *sc_supp_groups;
struct mac *sc_label;
};
#define SETCRED_INITIALIZER { -1, -1, -1, -1, -1, -1, 0, 0, NULL, NULL }
#define SETCREDF_UID (1u << 0)
#define SETCREDF_RUID (1u << 1)
#define SETCREDF_SVUID (1u << 2)
#define SETCREDF_GID (1u << 3)
#define SETCREDF_RGID (1u << 4)
#define SETCREDF_SVGID (1u << 5)
#define SETCREDF_SUPP_GROUPS (1u << 6)
#define SETCREDF_MAC_LABEL (1u << 7)
#ifdef _KERNEL
#define SETCREDF_MASK (SETCREDF_UID | SETCREDF_RUID | SETCREDF_SVUID | \
SETCREDF_GID | SETCREDF_RGID | SETCREDF_SVGID | SETCREDF_SUPP_GROUPS | \
SETCREDF_MAC_LABEL)
struct setcred32 {
uid_t sc_uid;
uid_t sc_ruid;
uid_t sc_svuid;
gid_t sc_gid;
gid_t sc_rgid;
gid_t sc_svgid;
u_int sc_pad;
u_int sc_supp_groups_nb;
uint32_t sc_supp_groups;
uint32_t sc_label;
};
struct thread;
int user_setcred(struct thread *td, const u_int flags,
struct setcred *const wcred);
struct proc;
struct credbatch {
struct ucred *cred;
u_int users;
long ref;
};
static inline void
credbatch_prep(struct credbatch *crb)
{
crb->cred = NULL;
crb->users = 0;
crb->ref = 0;
}
void credbatch_add(struct credbatch *crb, struct thread *td);
static inline void
credbatch_process(struct credbatch *crb __unused)
{
}
void credbatch_final(struct credbatch *crb);
void change_egid(struct ucred *newcred, gid_t egid);
void change_euid(struct ucred *newcred, struct uidinfo *euip);
void change_rgid(struct ucred *newcred, gid_t rgid);
void change_ruid(struct ucred *newcred, struct uidinfo *ruip);
void change_svgid(struct ucred *newcred, gid_t svgid);
void change_svuid(struct ucred *newcred, uid_t svuid);
void crcopy(struct ucred *dest, struct ucred *src);
struct ucred *crcopysafe(struct proc *p, struct ucred *cr);
struct ucred *crdup(struct ucred *cr);
void crextend(struct ucred *cr, int n);
void proc_set_cred(struct proc *p, struct ucred *newcred);
bool proc_set_cred_enforce_proc_lim(struct proc *p, struct ucred *newcred);
void proc_unset_cred(struct proc *p, bool decrement_proc_count);
void crfree(struct ucred *cr);
struct ucred *crcowsync(void);
struct ucred *crget(void);
struct ucred *crhold(struct ucred *cr);
struct ucred *crcowget(struct ucred *cr);
void crcowfree(struct thread *td);
void cru2x(struct ucred *cr, struct xucred *xcr);
void cru2xt(struct thread *td, struct xucred *xcr);
void crsetgroups(struct ucred *cr, int ngrp, const gid_t *groups);
void crsetgroups_and_egid(struct ucred *cr, int ngrp, const gid_t *groups,
const gid_t default_egid);
bool cr_xids_subset(struct ucred *active_cred, struct ucred *obj_cred);
static inline bool
group_is_primary(const gid_t gid, const struct ucred *const cred)
{
return (gid == cred->cr_groups[0] || gid == cred->cr_rgid ||
gid == cred->cr_svgid);
}
bool group_is_supplementary(const gid_t gid, const struct ucred *const cred);
bool groupmember(gid_t gid, const struct ucred *cred);
bool realgroupmember(gid_t gid, const struct ucred *cred);
#else
__BEGIN_DECLS
int setcred(u_int flags, const struct setcred *wcred, size_t size);
__END_DECLS
#endif
#endif