- error = netagent_send_client_message(wrapper, necp_client_uuid, message_type);
- if (error == 0 && message_type == NETAGENT_MESSAGE_TYPE_CLIENT_TRIGGER) {
- if (lck_rw_lock_shared_to_exclusive(&netagent_lock)) {
- // Grab the lock exclusively to add a pending client to the list
- struct netagent_client *new_pending_client = NULL;
- MALLOC(new_pending_client, struct netagent_client *, sizeof(*new_pending_client), M_NETAGENT, M_WAITOK);
- if (new_pending_client == NULL) {
- NETAGENTLOG0(LOG_ERR, "Failed to allocate client for trigger");
- } else {
- uuid_copy(new_pending_client->client_id, necp_client_uuid);
- struct proc *p = current_proc();
- if (p != NULL) {
- new_pending_client->client_pid = proc_pid(p);
- proc_getexecutableuuid(p, new_pending_client->client_proc_uuid, sizeof(new_pending_client->client_proc_uuid));
+ if (wrapper->control_unit == 0) {
+ should_unlock = FALSE;
+ lck_rw_done(&netagent_lock);
+ if (wrapper->event_handler == NULL) {
+ // No event handler registered for kernel agent
+ error = EINVAL;
+ } else {
+ error = wrapper->event_handler(message_type, necp_client_uuid, pid, wrapper->event_context, parameters, assigned_results, assigned_results_length);
+ if (error != 0) {
+ VERIFY(assigned_results == NULL || *assigned_results == NULL);
+ VERIFY(assigned_results_length == NULL || *assigned_results_length == 0);
+ }
+ }
+ } else {
+ // ABORT_NEXUS is kernel-private, so translate it for userspace nexus
+ if (message_type == NETAGENT_MESSAGE_TYPE_ABORT_NEXUS) {
+ message_type = NETAGENT_MESSAGE_TYPE_CLOSE_NEXUS;
+ }
+
+ error = netagent_send_client_message(wrapper, necp_client_uuid, message_type);
+ if (error == 0 && message_type == NETAGENT_MESSAGE_TYPE_CLIENT_TRIGGER) {
+ if (lck_rw_lock_shared_to_exclusive(&netagent_lock)) {
+ // Grab the lock exclusively to add a pending client to the list
+ struct netagent_client *new_pending_client = NULL;
+ MALLOC(new_pending_client, struct netagent_client *, sizeof(*new_pending_client), M_NETAGENT, M_WAITOK);
+ if (new_pending_client == NULL) {
+ NETAGENTLOG0(LOG_ERR, "Failed to allocate client for trigger");
+ } else {
+ uuid_copy(new_pending_client->client_id, necp_client_uuid);
+ if (parameters != NULL) {
+ new_pending_client->client_pid = parameters->epid;
+ uuid_copy(new_pending_client->client_proc_uuid, parameters->euuid);
+ } else {
+ struct proc *p = current_proc();
+ if (p != NULL) {
+ new_pending_client->client_pid = proc_pid(p);
+ proc_getexecutableuuid(p, new_pending_client->client_proc_uuid, sizeof(new_pending_client->client_proc_uuid));
+ }
+ }
+ LIST_INSERT_HEAD(&wrapper->pending_triggers_list, new_pending_client, client_chain);