// Created by Robert Sesek on 6/19/24.
//
+import Darwin
import Foundation
import OSLog
+@_silgen_name("proc_pidpath")
+func proc_pidpath(
+ _ pid: pid_t,
+ _ string: UnsafeMutablePointer<UInt8>?,
+ _ size: UInt32
+) -> Int
+
extension OS_xpc_object {
func description() -> String {
let d = xpc_copy_description(self)
return
}
+ let peerPid = xpc_connection_get_pid(authConn)
+ let peerUid = xpc_connection_get_euid(authConn)
+ var peerPath = ""
+ let path = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(MAXPATHLEN))
+ if proc_pidpath(peerPid, path, UInt32(MAXPATHLEN)) > 0 {
+ peerPath = String(cString: path)
+ }
+ path.deallocate()
+
log.log("Received authentication request, forwarding to control: \(obj.description, privacy: .public)")
let req = xpc_dictionary_create_empty()
xpc_dictionary_set_value(req, "request", obj)
+ xpc_dictionary_set_int64(req, "pid", Int64(peerPid))
+ xpc_dictionary_set_int64(req, "uid", Int64(peerUid))
+ xpc_dictionary_set_string(req, "path", peerPath.cString(using: .utf8) ?? [])
xpc_connection_send_message_with_reply(connection!, req, nil) { response in
self.log.log("Received control channel response: \(response.description, privacy: .public)")
xpc_dictionary_set_string(reply, "reply", "authenticate")
}
print("\n*** Authentication Request ***")
+ print(" PAM:")
print(" User = \(getXPCString(req, "user"))")
print(" Service = \(getXPCString(req, "service"))")
print(" Applicant = \(getXPCString(req, "applicant"))")
+ print(" Application:")
+ print(" PID = \(xpc_dictionary_get_int64(msg, "pid"))")
+ print(" UID = \(xpc_dictionary_get_int64(msg, "uid"))")
+ print(" Path = \(getXPCString(msg, "path"))")
var authorize = false
while true {
xpc_connection_send_message(conn, ping)
dispatchMain()
-