+ return set_security_token_task_internal(p, p->task);
+}
+
+static void
+proc_calc_audit_token(proc_t p, kauth_cred_t my_cred, audit_token_t *audit_token)
+{
+ posix_cred_t my_pcred = posix_cred_get(my_cred);
+
+ /*
+ * The current layout of the Mach audit token explicitly
+ * adds these fields. But nobody should rely on such
+ * a literal representation. Instead, the BSM library
+ * provides a function to convert an audit token into
+ * a BSM subject. Use of that mechanism will isolate
+ * the user of the trailer from future representation
+ * changes.
+ */
+ audit_token->val[0] = my_cred->cr_audit.as_aia_p->ai_auid;
+ audit_token->val[1] = my_pcred->cr_uid;
+ audit_token->val[2] = my_pcred->cr_gid;
+ audit_token->val[3] = my_pcred->cr_ruid;
+ audit_token->val[4] = my_pcred->cr_rgid;
+ audit_token->val[5] = p->p_pid;
+ audit_token->val[6] = my_cred->cr_audit.as_aia_p->ai_asid;
+ audit_token->val[7] = p->p_idversion;
+}
+
+/*
+ * Set the secrity token of the task with current euid and eguid
+ * The function takes a proc and a task, where proc->task might point to a
+ * different task if called from exec.
+ */
+
+int
+set_security_token_task_internal(proc_t p, void *t)
+{
+ kauth_cred_t my_cred;