From 95ff73141553f22287547401aa4eacc53dfa59e8 Mon Sep 17 00:00:00 2001 From: Ariel Abreu Date: Sun, 28 Nov 2021 23:45:34 -0500 Subject: [PATCH] Implement xpc_dictionary_get_audit_token; remove _od_rpc_call It's in libinfo now, where it belongs --- include/xpc/private.h | 2 -- internal-include/xpc/objects/dictionary.h | 4 ++++ src/connection.m | 3 +++ src/dictionary.m | 27 ++++++++++++++++++++++- src/pipe.m | 7 ------ 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/include/xpc/private.h b/include/xpc/private.h index d11047b..c5049a7 100644 --- a/include/xpc/private.h +++ b/include/xpc/private.h @@ -53,8 +53,6 @@ XPC_TYPE(_xpc_type_file_transfer); int _xpc_runtime_is_app_sandboxed(); -xpc_object_t _od_rpc_call(const char *procname, xpc_object_t payload, xpc_pipe_t (*get_pipe)(bool)); - xpc_object_t xpc_create_with_format(const char * format, ...); xpc_object_t xpc_create_reply_with_format(xpc_object_t original, const char * format, ...); diff --git a/internal-include/xpc/objects/dictionary.h b/internal-include/xpc/objects/dictionary.h index df38b39..2596eee 100644 --- a/internal-include/xpc/objects/dictionary.h +++ b/internal-include/xpc/objects/dictionary.h @@ -44,6 +44,7 @@ struct xpc_dictionary_s { XPC_CLASS(connection)* associatedConnection; mach_port_t incoming_port; mach_port_t outgoing_port; + audit_token_t associated_audit_token; }; @interface XPC_CLASS_INTERFACE(dictionary) @@ -90,6 +91,9 @@ struct xpc_dictionary_s { // useful extensions: - (XPC_CLASS(string)*)stringForKey: (const char*)key; +- (void)setAssociatedAuditToken: (audit_token_t*)auditToken; +- (void)copyAssociatedAuditTokenTo: (audit_token_t*)auditToken; + @end #endif // _XPC_OBJECTS_DICTIONARY_H_ diff --git a/src/connection.m b/src/connection.m index e5cc480..366f985 100644 --- a/src/connection.m +++ b/src/connection.m @@ -225,6 +225,9 @@ static void dispatch_mach_handler(void* context, dispatch_mach_reason_t reason, [message retain]; // because the deserializer consumes a reference on the message dict = [XPC_CLASS(deserializer) process: message]; dict.associatedConnection = self; + if (token) { + [dict setAssociatedAuditToken: token]; + } this->event_handler(dict); } diff --git a/src/dictionary.m b/src/dictionary.m index f8bfb9b..67238ff 100644 --- a/src/dictionary.m +++ b/src/dictionary.m @@ -134,6 +134,7 @@ XPC_CLASS_HEADER(dictionary); if (self = [super init]) { XPC_THIS_DECL(dictionary); LIST_INIT(&this->head); + memset(&this->associated_audit_token, 0xff, sizeof(audit_token_t)); } return self; } @@ -299,6 +300,28 @@ XPC_CLASS_HEADER(dictionary); return result; } +- (void)setAssociatedAuditToken: (audit_token_t*)auditToken +{ + XPC_THIS_DECL(dictionary); + + if (!auditToken) { + return; + } + + memcpy(&this->associated_audit_token, auditToken, sizeof(audit_token_t)); +} + +- (void)copyAssociatedAuditTokenTo: (audit_token_t*)auditToken +{ + XPC_THIS_DECL(dictionary); + + if (!auditToken) { + return; + } + + memcpy(auditToken, &this->associated_audit_token, sizeof(audit_token_t)); +} + @end @implementation XPC_CLASS(dictionary) (XPCSerialization) @@ -504,7 +527,9 @@ xpc_connection_t xpc_dictionary_get_remote_connection(xpc_object_t xdict) { XPC_EXPORT void xpc_dictionary_get_audit_token(xpc_object_t xdict, audit_token_t* token) { - + TO_OBJC_CHECKED(dictionary, xdict, dict) { + [dict copyAssociatedAuditTokenTo: token]; + } }; // diff --git a/src/pipe.m b/src/pipe.m index 29c8a68..0b06fbd 100644 --- a/src/pipe.m +++ b/src/pipe.m @@ -814,13 +814,6 @@ xpc_pipe_t xpc_pipe_create_from_port(mach_port_t port, uint64_t flags) { return [[XPC_CLASS(pipe) alloc] initWithPort: port flags: flags]; }; -// actually belongs in libsystem_info -XPC_EXPORT -xpc_object_t _od_rpc_call(const char* procname, xpc_object_t payload, xpc_pipe_t (*get_pipe)(bool)) { - xpc_stub(); - return NULL; -}; - XPC_EXPORT int xpc_pipe_routine_reply(xpc_object_t xdict) { TO_OBJC_CHECKED(dictionary, xdict, dict) {