+#if CONFIG_MACF
+/*
+ * This function is called by the MAC Framework to add audit data
+ * from a policy to the current audit record.
+ */
+int
+audit_mac_data(int type, int len, u_char *data) {
+ struct kaudit_record *cur;
+ struct mac_audit_record *record;
+ int ret = 0;
+
+ if (audit_enabled == 0) {
+ ret = ENOTSUP;
+ goto out_fail;
+ }
+
+ cur = currecord();
+ if (cur == NULL) {
+ ret = ENOTSUP;
+ goto out_fail;
+ }
+
+ /*
+ * XXX: Note that we silently drop the audit data if this
+ * allocation fails - this is consistent with the rest of the
+ * audit implementation.
+ */
+ record = (struct mac_audit_record *)kalloc(sizeof(*record));
+ if (record == NULL)
+ goto out_fail;
+
+ record->type = type;
+ record->length = len;
+ record->data = data;
+ LIST_INSERT_HEAD(cur->k_ar.ar_mac_records, record, records);
+
+ return (0);
+
+out_fail:
+ kfree(data, len);
+ return (ret);
+}
+
+void
+audit_arg_mac_string(const char *string)
+{
+ struct kaudit_record *ar;
+
+ ar = currecord();
+ if (ar == NULL)
+ return;
+
+ if (ar->k_ar.ar_arg_mac_string == NULL) {
+ ar->k_ar.ar_arg_mac_string =
+ (char *)kalloc(MAC_MAX_LABEL_BUF_LEN + MAC_ARG_PREFIX_LEN);
+ /* This should be a rare event. If kalloc() returns NULL, the
+ * system is low on kernel virtual memory. To be consistent with the
+ * rest of audit, just return (may need to panic if required to for audit6).
+ */
+ if (ar->k_ar.ar_arg_mac_string == NULL)
+ return;
+ }
+ strncpy(ar->k_ar.ar_arg_mac_string, MAC_ARG_PREFIX, MAC_ARG_PREFIX_LEN);
+ strncpy(ar->k_ar.ar_arg_mac_string + MAC_ARG_PREFIX_LEN, string, MAC_MAX_LABEL_BUF_LEN);
+ ar->k_ar.ar_valid_arg |= ARG_MAC_STRING;
+
+}
+#endif /* MAC */
+
+/*
+ * kau_will_audit can be used by a security policy to determine
+ * if an audit record will be stored, reducing wasted memory allocation
+ * and string handling.
+ */
+
+int
+kau_will_audit(void)
+{
+
+ return (audit_enabled && currecord() != NULL);
+}
+