+ memset((void *)&udata, 0, sizeof(udata));
+
+ switch (uap->cmd) {
+ /* Some of the GET commands use the arguments too */
+ case A_SETPOLICY:
+ case A_SETKMASK:
+ case A_SETQCTRL:
+ case A_SETSTAT:
+ case A_SETUMASK:
+ case A_SETSMASK:
+ case A_SETCOND:
+ case A_SETCLASS:
+ case A_SETPMASK:
+ case A_SETFSIZE:
+ case A_SETKAUDIT:
+ case A_GETCLASS:
+ case A_GETPINFO:
+ case A_GETPINFO_ADDR:
+ ret = copyin(uap->data, (void *)&udata, uap->length);
+ if (ret)
+ return (ret);
+ AUDIT_ARG(auditon, &udata);
+ break;
+ }
+
+ /* XXX Need to implement these commands by accessing the global
+ * values associated with the commands.
+ */
+ switch (uap->cmd) {
+ case A_GETPOLICY:
+ if (!audit_fail_stop)
+ udata.au_policy |= AUDIT_CNT;
+ if (audit_panic_on_write_fail)
+ udata.au_policy |= AUDIT_AHLT;
+ break;
+ case A_SETPOLICY:
+ if (udata.au_policy & ~(AUDIT_CNT|AUDIT_AHLT))
+ return (EINVAL);
+ /*
+ * XXX - Need to wake up waiters if the policy relaxes?
+ */
+ audit_fail_stop = ((udata.au_policy & AUDIT_CNT) == 0);
+ audit_panic_on_write_fail = (udata.au_policy & AUDIT_AHLT);
+ break;
+ case A_GETKMASK:
+ udata.au_mask = audit_nae_mask;
+ break;
+ case A_SETKMASK:
+ audit_nae_mask = udata.au_mask;
+ break;
+ case A_GETQCTRL:
+ udata.au_qctrl = audit_qctrl;
+ break;
+ case A_SETQCTRL:
+ if ((udata.au_qctrl.aq_hiwater > AQ_MAXHIGH) ||
+ (udata.au_qctrl.aq_lowater >= udata.au_qctrl.aq_hiwater) ||
+ (udata.au_qctrl.aq_bufsz > AQ_MAXBUFSZ) ||
+ (udata.au_qctrl.aq_minfree < 0) ||
+ (udata.au_qctrl.aq_minfree > 100))
+ return (EINVAL);
+
+ audit_qctrl = udata.au_qctrl;
+ /* XXX The queue delay value isn't used with the kernel. */
+ audit_qctrl.aq_delay = -1;
+ break;
+ case A_GETCWD:
+ return (ENOSYS);
+ break;
+ case A_GETCAR:
+ return (ENOSYS);
+ break;
+ case A_GETSTAT:
+ return (ENOSYS);
+ break;
+ case A_SETSTAT:
+ return (ENOSYS);
+ break;
+ case A_SETUMASK:
+ return (ENOSYS);
+ break;
+ case A_SETSMASK:
+ return (ENOSYS);
+ break;
+ case A_GETCOND:
+ if (audit_enabled && !audit_suspended)
+ udata.au_cond = AUC_AUDITING;
+ else
+ udata.au_cond = AUC_NOAUDIT;
+ break;
+ case A_SETCOND:
+ if (udata.au_cond == AUC_NOAUDIT)
+ audit_suspended = 1;
+ if (udata.au_cond == AUC_AUDITING)
+ audit_suspended = 0;
+ if (udata.au_cond == AUC_DISABLED) {
+ audit_suspended = 1;
+ audit_shutdown();
+ }
+ break;
+ case A_GETCLASS:
+ udata.au_evclass.ec_class =
+ au_event_class(udata.au_evclass.ec_number);
+ break;
+ case A_SETCLASS:
+ au_evclassmap_insert(udata.au_evclass.ec_number,
+ udata.au_evclass.ec_class);
+ break;
+ case A_GETPINFO:
+ if (udata.au_aupinfo.ap_pid < 1)
+ return (EINVAL);
+ if ((tp = pfind(udata.au_aupinfo.ap_pid)) == NULL)
+ return (EINVAL);
+
+ udata.au_aupinfo.ap_auid = tp->p_au->ai_auid;
+ udata.au_aupinfo.ap_mask.am_success =
+ tp->p_au->ai_mask.am_success;
+ udata.au_aupinfo.ap_mask.am_failure =
+ tp->p_au->ai_mask.am_failure;
+ udata.au_aupinfo.ap_termid.machine =
+ tp->p_au->ai_termid.machine;
+ udata.au_aupinfo.ap_termid.port =
+ tp->p_au->ai_termid.port;
+ udata.au_aupinfo.ap_asid = tp->p_au->ai_asid;
+ break;
+ case A_SETPMASK:
+ if (udata.au_aupinfo.ap_pid < 1)
+ return (EINVAL);
+ if ((tp = pfind(udata.au_aupinfo.ap_pid)) == NULL)
+ return (EINVAL);
+
+ tp->p_au->ai_mask.am_success =
+ udata.au_aupinfo.ap_mask.am_success;
+ tp->p_au->ai_mask.am_failure =
+ udata.au_aupinfo.ap_mask.am_failure;
+ break;
+ case A_SETFSIZE:
+ if ((udata.au_fstat.af_filesz != 0) &&
+ (udata.au_fstat.af_filesz < MIN_AUDIT_FILE_SIZE))
+ return (EINVAL);
+ audit_fstat.af_filesz = udata.au_fstat.af_filesz;
+ break;
+ case A_GETFSIZE:
+ udata.au_fstat.af_filesz = audit_fstat.af_filesz;
+ udata.au_fstat.af_currsz = audit_fstat.af_currsz;
+ break;
+ case A_GETPINFO_ADDR:
+ return (ENOSYS);
+ break;
+ case A_GETKAUDIT:
+ return (ENOSYS);
+ break;
+ case A_SETKAUDIT:
+ return (ENOSYS);
+ break;
+ }
+ /* Copy data back to userspace for the GET comands */
+ switch (uap->cmd) {
+ case A_GETPOLICY:
+ case A_GETKMASK:
+ case A_GETQCTRL:
+ case A_GETCWD:
+ case A_GETCAR:
+ case A_GETSTAT:
+ case A_GETCOND:
+ case A_GETCLASS:
+ case A_GETPINFO:
+ case A_GETFSIZE:
+ case A_GETPINFO_ADDR:
+ case A_GETKAUDIT:
+ ret = copyout((void *)&udata, uap->data, uap->length);
+ if (ret)
+ return (ret);
+ break;
+ }
+
+ return (0);