xref: /xnu-12377.41.6/osfmk/UserNotification/KUNCUserNotifications.c (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the License.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions 
29*bbb1b6f9SApple OSS Distributions #include <mach/port.h>
30*bbb1b6f9SApple OSS Distributions #include <mach/message.h>
31*bbb1b6f9SApple OSS Distributions #include <mach/kern_return.h>
32*bbb1b6f9SApple OSS Distributions #include <mach/host_priv.h>
33*bbb1b6f9SApple OSS Distributions 
34*bbb1b6f9SApple OSS Distributions #include <kern/kern_types.h>
35*bbb1b6f9SApple OSS Distributions #include <kern/kalloc.h>
36*bbb1b6f9SApple OSS Distributions #include <kern/host.h>
37*bbb1b6f9SApple OSS Distributions #include <kern/ipc_kobject.h>
38*bbb1b6f9SApple OSS Distributions 
39*bbb1b6f9SApple OSS Distributions #include <ipc/ipc_port.h>
40*bbb1b6f9SApple OSS Distributions 
41*bbb1b6f9SApple OSS Distributions #include <UserNotification/UNDTypes.h>
42*bbb1b6f9SApple OSS Distributions #include <UserNotification/UNDRequest.h>
43*bbb1b6f9SApple OSS Distributions #include <UserNotification/UNDReplyServer.h>
44*bbb1b6f9SApple OSS Distributions #include <UserNotification/KUNCUserNotifications.h>
45*bbb1b6f9SApple OSS Distributions 
46*bbb1b6f9SApple OSS Distributions #ifdef KERNEL_CF
47*bbb1b6f9SApple OSS Distributions // external
48*bbb1b6f9SApple OSS Distributions #include <IOKit/IOCFSerialize.h>
49*bbb1b6f9SApple OSS Distributions #include <IOKit/IOCFUnserialize.h>
50*bbb1b6f9SApple OSS Distributions #endif
51*bbb1b6f9SApple OSS Distributions 
52*bbb1b6f9SApple OSS Distributions #if CONFIG_USER_NOTIFICATION
53*bbb1b6f9SApple OSS Distributions /*
54*bbb1b6f9SApple OSS Distributions  * DEFINES AND STRUCTURES
55*bbb1b6f9SApple OSS Distributions  */
56*bbb1b6f9SApple OSS Distributions 
57*bbb1b6f9SApple OSS Distributions struct UNDReply {
58*bbb1b6f9SApple OSS Distributions 	decl_lck_mtx_data(, lock);                               /* UNDReply lock */
59*bbb1b6f9SApple OSS Distributions 	int                             userLandNotificationKey;
60*bbb1b6f9SApple OSS Distributions 	KUNCUserNotificationCallBack    callback;
61*bbb1b6f9SApple OSS Distributions 	boolean_t                       inprogress;
62*bbb1b6f9SApple OSS Distributions 	ipc_port_t                      self_port;      /* Our port */
63*bbb1b6f9SApple OSS Distributions };
64*bbb1b6f9SApple OSS Distributions 
65*bbb1b6f9SApple OSS Distributions static void
66*bbb1b6f9SApple OSS Distributions UNDReply_no_senders(ipc_port_t port, mach_port_mscount_t mscount);
67*bbb1b6f9SApple OSS Distributions 
68*bbb1b6f9SApple OSS Distributions IPC_KOBJECT_DEFINE(IKOT_UND_REPLY,
69*bbb1b6f9SApple OSS Distributions     .iko_op_movable_send = true,
70*bbb1b6f9SApple OSS Distributions     .iko_op_stable     = true,
71*bbb1b6f9SApple OSS Distributions     .iko_op_no_senders = UNDReply_no_senders);
72*bbb1b6f9SApple OSS Distributions 
73*bbb1b6f9SApple OSS Distributions #define UNDReply_lock(reply)            lck_mtx_lock(&reply->lock)
74*bbb1b6f9SApple OSS Distributions #define UNDReply_unlock(reply)          lck_mtx_unlock(&reply->lock)
75*bbb1b6f9SApple OSS Distributions 
76*bbb1b6f9SApple OSS Distributions LCK_GRP_DECLARE(UNDLckGrp, "UND");
77*bbb1b6f9SApple OSS Distributions 
78*bbb1b6f9SApple OSS Distributions static UNDServerRef
UNDServer_reference(void)79*bbb1b6f9SApple OSS Distributions UNDServer_reference(void)
80*bbb1b6f9SApple OSS Distributions {
81*bbb1b6f9SApple OSS Distributions 	UNDServerRef UNDServer;
82*bbb1b6f9SApple OSS Distributions 	kern_return_t kr;
83*bbb1b6f9SApple OSS Distributions 
84*bbb1b6f9SApple OSS Distributions 	kr = host_get_user_notification_port(host_priv_self(), &UNDServer);
85*bbb1b6f9SApple OSS Distributions 	assert(kr == KERN_SUCCESS);
86*bbb1b6f9SApple OSS Distributions 	return UNDServer;
87*bbb1b6f9SApple OSS Distributions }
88*bbb1b6f9SApple OSS Distributions 
89*bbb1b6f9SApple OSS Distributions static void
UNDServer_deallocate(UNDServerRef UNDServer)90*bbb1b6f9SApple OSS Distributions UNDServer_deallocate(
91*bbb1b6f9SApple OSS Distributions 	UNDServerRef    UNDServer)
92*bbb1b6f9SApple OSS Distributions {
93*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(UNDServer)) {
94*bbb1b6f9SApple OSS Distributions 		ipc_port_release_send(UNDServer);
95*bbb1b6f9SApple OSS Distributions 	}
96*bbb1b6f9SApple OSS Distributions }
97*bbb1b6f9SApple OSS Distributions 
98*bbb1b6f9SApple OSS Distributions /*
99*bbb1b6f9SApple OSS Distributions  * UND Mig Callbacks
100*bbb1b6f9SApple OSS Distributions  */
101*bbb1b6f9SApple OSS Distributions 
102*bbb1b6f9SApple OSS Distributions kern_return_t
UNDAlertCompletedWithResult_rpc(UNDReplyRef reply,int result,xmlData_t keyRef,mach_msg_type_number_t keyLen)103*bbb1b6f9SApple OSS Distributions UNDAlertCompletedWithResult_rpc(
104*bbb1b6f9SApple OSS Distributions 	UNDReplyRef             reply,
105*bbb1b6f9SApple OSS Distributions 	int                     result,
106*bbb1b6f9SApple OSS Distributions 	xmlData_t               keyRef,         /* raw XML bytes */
107*bbb1b6f9SApple OSS Distributions #ifdef KERNEL_CF
108*bbb1b6f9SApple OSS Distributions 	mach_msg_type_number_t  keyLen)
109*bbb1b6f9SApple OSS Distributions #else
110*bbb1b6f9SApple OSS Distributions 	__unused mach_msg_type_number_t keyLen)
111*bbb1b6f9SApple OSS Distributions #endif
112*bbb1b6f9SApple OSS Distributions {
113*bbb1b6f9SApple OSS Distributions #ifdef KERNEL_CF
114*bbb1b6f9SApple OSS Distributions 	CFStringRef             xmlError = NULL;
115*bbb1b6f9SApple OSS Distributions 	CFDictionaryRef         dict = NULL;
116*bbb1b6f9SApple OSS Distributions #else
117*bbb1b6f9SApple OSS Distributions 	const void *dict = (const void *)keyRef;
118*bbb1b6f9SApple OSS Distributions #endif
119*bbb1b6f9SApple OSS Distributions 
120*bbb1b6f9SApple OSS Distributions 	if (reply == UND_REPLY_NULL || !reply->inprogress) {
121*bbb1b6f9SApple OSS Distributions 		return KERN_INVALID_ARGUMENT;
122*bbb1b6f9SApple OSS Distributions 	}
123*bbb1b6f9SApple OSS Distributions 
124*bbb1b6f9SApple OSS Distributions 	/*
125*bbb1b6f9SApple OSS Distributions 	 * JMM - No C vesion of the Unserialize code in-kernel
126*bbb1b6f9SApple OSS Distributions 	 * and no C type for a CFDictionary either.  For now,
127*bbb1b6f9SApple OSS Distributions 	 * just pass the raw keyRef through.
128*bbb1b6f9SApple OSS Distributions 	 */
129*bbb1b6f9SApple OSS Distributions #ifdef KERNEL_CF
130*bbb1b6f9SApple OSS Distributions 	if (keyRef && keyLen) {
131*bbb1b6f9SApple OSS Distributions 		dict = IOCFUnserialize(keyRef, NULL, NULL, &xmlError);
132*bbb1b6f9SApple OSS Distributions 	}
133*bbb1b6f9SApple OSS Distributions 
134*bbb1b6f9SApple OSS Distributions 	if (xmlError) {
135*bbb1b6f9SApple OSS Distributions 		CFShow(xmlError);
136*bbb1b6f9SApple OSS Distributions 		CFRelease(xmlError);
137*bbb1b6f9SApple OSS Distributions 	}
138*bbb1b6f9SApple OSS Distributions #endif /* KERNEL_CF */
139*bbb1b6f9SApple OSS Distributions 
140*bbb1b6f9SApple OSS Distributions 	if (reply->callback) {
141*bbb1b6f9SApple OSS Distributions 		(reply->callback)((int)(KUNCUserNotificationID)reply, result, dict);
142*bbb1b6f9SApple OSS Distributions 	}
143*bbb1b6f9SApple OSS Distributions 
144*bbb1b6f9SApple OSS Distributions 	UNDReply_lock(reply);
145*bbb1b6f9SApple OSS Distributions 	reply->inprogress = FALSE;
146*bbb1b6f9SApple OSS Distributions 	reply->userLandNotificationKey = -1;
147*bbb1b6f9SApple OSS Distributions 	UNDReply_unlock(reply);
148*bbb1b6f9SApple OSS Distributions 
149*bbb1b6f9SApple OSS Distributions 	return KERN_SUCCESS;
150*bbb1b6f9SApple OSS Distributions }
151*bbb1b6f9SApple OSS Distributions 
152*bbb1b6f9SApple OSS Distributions /*
153*bbb1b6f9SApple OSS Distributions  *	Routine: UNDNotificationCreated_rpc
154*bbb1b6f9SApple OSS Distributions  *
155*bbb1b6f9SApple OSS Distributions  *		Intermediate routine.  Allows the kernel mechanism
156*bbb1b6f9SApple OSS Distributions  *		to be informed that the notification request IS
157*bbb1b6f9SApple OSS Distributions  *		being processed by the user-level daemon, and how
158*bbb1b6f9SApple OSS Distributions  *		to identify that request.
159*bbb1b6f9SApple OSS Distributions  */
160*bbb1b6f9SApple OSS Distributions kern_return_t
UNDNotificationCreated_rpc(UNDReplyRef reply,int userLandNotificationKey)161*bbb1b6f9SApple OSS Distributions UNDNotificationCreated_rpc(
162*bbb1b6f9SApple OSS Distributions 	UNDReplyRef     reply,
163*bbb1b6f9SApple OSS Distributions 	int             userLandNotificationKey)
164*bbb1b6f9SApple OSS Distributions {
165*bbb1b6f9SApple OSS Distributions 	if (reply == UND_REPLY_NULL) {
166*bbb1b6f9SApple OSS Distributions 		return KERN_INVALID_ARGUMENT;
167*bbb1b6f9SApple OSS Distributions 	}
168*bbb1b6f9SApple OSS Distributions 
169*bbb1b6f9SApple OSS Distributions 	UNDReply_lock(reply);
170*bbb1b6f9SApple OSS Distributions 	if (reply->inprogress || reply->userLandNotificationKey != -1) {
171*bbb1b6f9SApple OSS Distributions 		UNDReply_unlock(reply);
172*bbb1b6f9SApple OSS Distributions 		return KERN_INVALID_ARGUMENT;
173*bbb1b6f9SApple OSS Distributions 	}
174*bbb1b6f9SApple OSS Distributions 	reply->userLandNotificationKey = userLandNotificationKey;
175*bbb1b6f9SApple OSS Distributions 	UNDReply_unlock(reply);
176*bbb1b6f9SApple OSS Distributions 	return KERN_SUCCESS;
177*bbb1b6f9SApple OSS Distributions }
178*bbb1b6f9SApple OSS Distributions 
179*bbb1b6f9SApple OSS Distributions /*
180*bbb1b6f9SApple OSS Distributions  * KUNC Functions
181*bbb1b6f9SApple OSS Distributions  */
182*bbb1b6f9SApple OSS Distributions 
183*bbb1b6f9SApple OSS Distributions 
184*bbb1b6f9SApple OSS Distributions KUNCUserNotificationID
KUNCGetNotificationID(void)185*bbb1b6f9SApple OSS Distributions KUNCGetNotificationID(void)
186*bbb1b6f9SApple OSS Distributions {
187*bbb1b6f9SApple OSS Distributions 	UNDReplyRef reply;
188*bbb1b6f9SApple OSS Distributions 
189*bbb1b6f9SApple OSS Distributions 	reply = kalloc_type(struct UNDReply, Z_WAITOK | Z_ZERO | Z_NOFAIL);
190*bbb1b6f9SApple OSS Distributions 	reply->self_port = ipc_kobject_alloc_port((ipc_kobject_t)reply,
191*bbb1b6f9SApple OSS Distributions 	    IKOT_UND_REPLY, IPC_KOBJECT_ALLOC_NONE);
192*bbb1b6f9SApple OSS Distributions 	lck_mtx_init(&reply->lock, &UNDLckGrp, LCK_ATTR_NULL);
193*bbb1b6f9SApple OSS Distributions 	reply->userLandNotificationKey = -1;
194*bbb1b6f9SApple OSS Distributions 	reply->inprogress = FALSE;
195*bbb1b6f9SApple OSS Distributions 
196*bbb1b6f9SApple OSS Distributions 	return (KUNCUserNotificationID) reply;
197*bbb1b6f9SApple OSS Distributions }
198*bbb1b6f9SApple OSS Distributions 
199*bbb1b6f9SApple OSS Distributions static void
UNDReply_no_senders(ipc_port_t port,mach_port_mscount_t mscount)200*bbb1b6f9SApple OSS Distributions UNDReply_no_senders(ipc_port_t port, mach_port_mscount_t mscount)
201*bbb1b6f9SApple OSS Distributions {
202*bbb1b6f9SApple OSS Distributions 	UNDReplyRef reply;
203*bbb1b6f9SApple OSS Distributions 
204*bbb1b6f9SApple OSS Distributions 	reply = ipc_kobject_dealloc_port(port, mscount, IKOT_UND_REPLY);
205*bbb1b6f9SApple OSS Distributions 	lck_mtx_destroy(&reply->lock, &UNDLckGrp);
206*bbb1b6f9SApple OSS Distributions 	kfree_type(struct UNDReply, reply);
207*bbb1b6f9SApple OSS Distributions }
208*bbb1b6f9SApple OSS Distributions 
209*bbb1b6f9SApple OSS Distributions kern_return_t
KUNCExecute(char executionPath[1024],int uid,int gid)210*bbb1b6f9SApple OSS Distributions KUNCExecute(char executionPath[1024], int uid, int gid)
211*bbb1b6f9SApple OSS Distributions {
212*bbb1b6f9SApple OSS Distributions 	UNDServerRef UNDServer;
213*bbb1b6f9SApple OSS Distributions 
214*bbb1b6f9SApple OSS Distributions 	UNDServer = UNDServer_reference();
215*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(UNDServer)) {
216*bbb1b6f9SApple OSS Distributions 		kern_return_t kr;
217*bbb1b6f9SApple OSS Distributions 		kr = UNDExecute_rpc(UNDServer, executionPath, uid, gid);
218*bbb1b6f9SApple OSS Distributions 		UNDServer_deallocate(UNDServer);
219*bbb1b6f9SApple OSS Distributions 		return kr;
220*bbb1b6f9SApple OSS Distributions 	}
221*bbb1b6f9SApple OSS Distributions 	return MACH_SEND_INVALID_DEST;
222*bbb1b6f9SApple OSS Distributions }
223*bbb1b6f9SApple OSS Distributions 
224*bbb1b6f9SApple OSS Distributions kern_return_t
KUNCUserNotificationDisplayNotice(int noticeTimeout,unsigned flags,char * iconPath,char * soundPath,char * localizationPath,char * alertHeader,char * alertMessage,char * defaultButtonTitle)225*bbb1b6f9SApple OSS Distributions KUNCUserNotificationDisplayNotice(
226*bbb1b6f9SApple OSS Distributions 	int             noticeTimeout,
227*bbb1b6f9SApple OSS Distributions 	unsigned        flags,
228*bbb1b6f9SApple OSS Distributions 	char            *iconPath,
229*bbb1b6f9SApple OSS Distributions 	char            *soundPath,
230*bbb1b6f9SApple OSS Distributions 	char            *localizationPath,
231*bbb1b6f9SApple OSS Distributions 	char            *alertHeader,
232*bbb1b6f9SApple OSS Distributions 	char            *alertMessage,
233*bbb1b6f9SApple OSS Distributions 	char            *defaultButtonTitle)
234*bbb1b6f9SApple OSS Distributions {
235*bbb1b6f9SApple OSS Distributions 	UNDServerRef UNDServer;
236*bbb1b6f9SApple OSS Distributions 
237*bbb1b6f9SApple OSS Distributions 	UNDServer = UNDServer_reference();
238*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(UNDServer)) {
239*bbb1b6f9SApple OSS Distributions 		kern_return_t kr;
240*bbb1b6f9SApple OSS Distributions 		kr = UNDDisplayNoticeSimple_rpc(UNDServer,
241*bbb1b6f9SApple OSS Distributions 		    noticeTimeout,
242*bbb1b6f9SApple OSS Distributions 		    flags,
243*bbb1b6f9SApple OSS Distributions 		    iconPath,
244*bbb1b6f9SApple OSS Distributions 		    soundPath,
245*bbb1b6f9SApple OSS Distributions 		    localizationPath,
246*bbb1b6f9SApple OSS Distributions 		    alertHeader,
247*bbb1b6f9SApple OSS Distributions 		    alertMessage,
248*bbb1b6f9SApple OSS Distributions 		    defaultButtonTitle);
249*bbb1b6f9SApple OSS Distributions 		UNDServer_deallocate(UNDServer);
250*bbb1b6f9SApple OSS Distributions 		return kr;
251*bbb1b6f9SApple OSS Distributions 	}
252*bbb1b6f9SApple OSS Distributions 	return MACH_SEND_INVALID_DEST;
253*bbb1b6f9SApple OSS Distributions }
254*bbb1b6f9SApple OSS Distributions 
255*bbb1b6f9SApple OSS Distributions kern_return_t
KUNCUserNotificationDisplayAlert(int alertTimeout,unsigned flags,char * iconPath,char * soundPath,char * localizationPath,char * alertHeader,char * alertMessage,char * defaultButtonTitle,char * alternateButtonTitle,char * otherButtonTitle,unsigned * responseFlags)256*bbb1b6f9SApple OSS Distributions KUNCUserNotificationDisplayAlert(
257*bbb1b6f9SApple OSS Distributions 	int             alertTimeout,
258*bbb1b6f9SApple OSS Distributions 	unsigned        flags,
259*bbb1b6f9SApple OSS Distributions 	char            *iconPath,
260*bbb1b6f9SApple OSS Distributions 	char            *soundPath,
261*bbb1b6f9SApple OSS Distributions 	char            *localizationPath,
262*bbb1b6f9SApple OSS Distributions 	char            *alertHeader,
263*bbb1b6f9SApple OSS Distributions 	char            *alertMessage,
264*bbb1b6f9SApple OSS Distributions 	char            *defaultButtonTitle,
265*bbb1b6f9SApple OSS Distributions 	char            *alternateButtonTitle,
266*bbb1b6f9SApple OSS Distributions 	char            *otherButtonTitle,
267*bbb1b6f9SApple OSS Distributions 	unsigned        *responseFlags)
268*bbb1b6f9SApple OSS Distributions {
269*bbb1b6f9SApple OSS Distributions 	UNDServerRef    UNDServer;
270*bbb1b6f9SApple OSS Distributions 
271*bbb1b6f9SApple OSS Distributions 	UNDServer = UNDServer_reference();
272*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(UNDServer)) {
273*bbb1b6f9SApple OSS Distributions 		kern_return_t   kr;
274*bbb1b6f9SApple OSS Distributions 		kr = UNDDisplayAlertSimple_rpc(UNDServer,
275*bbb1b6f9SApple OSS Distributions 		    alertTimeout,
276*bbb1b6f9SApple OSS Distributions 		    flags,
277*bbb1b6f9SApple OSS Distributions 		    iconPath,
278*bbb1b6f9SApple OSS Distributions 		    soundPath,
279*bbb1b6f9SApple OSS Distributions 		    localizationPath,
280*bbb1b6f9SApple OSS Distributions 		    alertHeader,
281*bbb1b6f9SApple OSS Distributions 		    alertMessage,
282*bbb1b6f9SApple OSS Distributions 		    defaultButtonTitle,
283*bbb1b6f9SApple OSS Distributions 		    alternateButtonTitle,
284*bbb1b6f9SApple OSS Distributions 		    otherButtonTitle,
285*bbb1b6f9SApple OSS Distributions 		    responseFlags);
286*bbb1b6f9SApple OSS Distributions 		UNDServer_deallocate(UNDServer);
287*bbb1b6f9SApple OSS Distributions 		return kr;
288*bbb1b6f9SApple OSS Distributions 	}
289*bbb1b6f9SApple OSS Distributions 	return MACH_SEND_INVALID_DEST;
290*bbb1b6f9SApple OSS Distributions }
291*bbb1b6f9SApple OSS Distributions 
292*bbb1b6f9SApple OSS Distributions kern_return_t
KUNCUserNotificationDisplayFromBundle(KUNCUserNotificationID id,char * bundlePath,char * fileName,char * fileExtension,char * messageKey,char * tokenString,KUNCUserNotificationCallBack callback,__unused int contextKey)293*bbb1b6f9SApple OSS Distributions KUNCUserNotificationDisplayFromBundle(
294*bbb1b6f9SApple OSS Distributions 	KUNCUserNotificationID       id,
295*bbb1b6f9SApple OSS Distributions 	char                         *bundlePath,
296*bbb1b6f9SApple OSS Distributions 	char                         *fileName,
297*bbb1b6f9SApple OSS Distributions 	char                         *fileExtension,
298*bbb1b6f9SApple OSS Distributions 	char                         *messageKey,
299*bbb1b6f9SApple OSS Distributions 	char                         *tokenString,
300*bbb1b6f9SApple OSS Distributions 	KUNCUserNotificationCallBack callback,
301*bbb1b6f9SApple OSS Distributions 	__unused int                    contextKey)
302*bbb1b6f9SApple OSS Distributions {
303*bbb1b6f9SApple OSS Distributions 	UNDReplyRef reply = (UNDReplyRef)id;
304*bbb1b6f9SApple OSS Distributions 	UNDServerRef UNDServer;
305*bbb1b6f9SApple OSS Distributions 	ipc_port_t reply_port;
306*bbb1b6f9SApple OSS Distributions 
307*bbb1b6f9SApple OSS Distributions 	if (reply == UND_REPLY_NULL) {
308*bbb1b6f9SApple OSS Distributions 		return KERN_INVALID_ARGUMENT;
309*bbb1b6f9SApple OSS Distributions 	}
310*bbb1b6f9SApple OSS Distributions 	UNDReply_lock(reply);
311*bbb1b6f9SApple OSS Distributions 	if (reply->inprogress == TRUE || reply->userLandNotificationKey != -1) {
312*bbb1b6f9SApple OSS Distributions 		UNDReply_unlock(reply);
313*bbb1b6f9SApple OSS Distributions 		return KERN_INVALID_ARGUMENT;
314*bbb1b6f9SApple OSS Distributions 	}
315*bbb1b6f9SApple OSS Distributions 	reply->inprogress = TRUE;
316*bbb1b6f9SApple OSS Distributions 	reply->callback = callback;
317*bbb1b6f9SApple OSS Distributions 	reply_port = ipc_kobject_make_send(reply->self_port, reply, IKOT_UND_REPLY);
318*bbb1b6f9SApple OSS Distributions 	UNDReply_unlock(reply);
319*bbb1b6f9SApple OSS Distributions 
320*bbb1b6f9SApple OSS Distributions 	UNDServer = UNDServer_reference();
321*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(UNDServer)) {
322*bbb1b6f9SApple OSS Distributions 		kern_return_t kr;
323*bbb1b6f9SApple OSS Distributions 
324*bbb1b6f9SApple OSS Distributions 		kr = UNDDisplayCustomFromBundle_rpc(UNDServer,
325*bbb1b6f9SApple OSS Distributions 		    reply_port,
326*bbb1b6f9SApple OSS Distributions 		    bundlePath,
327*bbb1b6f9SApple OSS Distributions 		    fileName,
328*bbb1b6f9SApple OSS Distributions 		    fileExtension,
329*bbb1b6f9SApple OSS Distributions 		    messageKey,
330*bbb1b6f9SApple OSS Distributions 		    tokenString);
331*bbb1b6f9SApple OSS Distributions 		UNDServer_deallocate(UNDServer);
332*bbb1b6f9SApple OSS Distributions 		return kr;
333*bbb1b6f9SApple OSS Distributions 	}
334*bbb1b6f9SApple OSS Distributions 	return MACH_SEND_INVALID_DEST;
335*bbb1b6f9SApple OSS Distributions }
336*bbb1b6f9SApple OSS Distributions 
337*bbb1b6f9SApple OSS Distributions /*
338*bbb1b6f9SApple OSS Distributions  *	Routine: convert_port_to_UNDReply
339*bbb1b6f9SApple OSS Distributions  *
340*bbb1b6f9SApple OSS Distributions  *		MIG helper routine to convert from a mach port to a
341*bbb1b6f9SApple OSS Distributions  *		UNDReply object.
342*bbb1b6f9SApple OSS Distributions  *
343*bbb1b6f9SApple OSS Distributions  *	Assumptions:
344*bbb1b6f9SApple OSS Distributions  *		Nothing locked.
345*bbb1b6f9SApple OSS Distributions  */
346*bbb1b6f9SApple OSS Distributions UNDReplyRef
convert_port_to_UNDReply(ipc_port_t port)347*bbb1b6f9SApple OSS Distributions convert_port_to_UNDReply(
348*bbb1b6f9SApple OSS Distributions 	ipc_port_t port)
349*bbb1b6f9SApple OSS Distributions {
350*bbb1b6f9SApple OSS Distributions 	UNDReplyRef reply = NULL;
351*bbb1b6f9SApple OSS Distributions 	if (IP_VALID(port)) {
352*bbb1b6f9SApple OSS Distributions 		reply = ipc_kobject_get_stable(port, IKOT_UND_REPLY);
353*bbb1b6f9SApple OSS Distributions 	}
354*bbb1b6f9SApple OSS Distributions 
355*bbb1b6f9SApple OSS Distributions 	return reply;
356*bbb1b6f9SApple OSS Distributions }
357*bbb1b6f9SApple OSS Distributions #endif
358*bbb1b6f9SApple OSS Distributions 
359*bbb1b6f9SApple OSS Distributions /*
360*bbb1b6f9SApple OSS Distributions  *      User interface for setting the host UserNotification Daemon port.
361*bbb1b6f9SApple OSS Distributions  */
362*bbb1b6f9SApple OSS Distributions 
363*bbb1b6f9SApple OSS Distributions kern_return_t
host_set_UNDServer(host_priv_t host_priv,UNDServerRef server)364*bbb1b6f9SApple OSS Distributions host_set_UNDServer(
365*bbb1b6f9SApple OSS Distributions 	host_priv_t     host_priv,
366*bbb1b6f9SApple OSS Distributions 	UNDServerRef    server)
367*bbb1b6f9SApple OSS Distributions {
368*bbb1b6f9SApple OSS Distributions #if CONFIG_USER_NOTIFICATION
369*bbb1b6f9SApple OSS Distributions 	return host_set_user_notification_port(host_priv, server);
370*bbb1b6f9SApple OSS Distributions #else
371*bbb1b6f9SApple OSS Distributions #pragma unused(host_priv, server)
372*bbb1b6f9SApple OSS Distributions 	return KERN_NOT_SUPPORTED;
373*bbb1b6f9SApple OSS Distributions #endif
374*bbb1b6f9SApple OSS Distributions }
375*bbb1b6f9SApple OSS Distributions 
376*bbb1b6f9SApple OSS Distributions /*
377*bbb1b6f9SApple OSS Distributions  *      User interface for retrieving the UserNotification Daemon port.
378*bbb1b6f9SApple OSS Distributions  */
379*bbb1b6f9SApple OSS Distributions 
380*bbb1b6f9SApple OSS Distributions kern_return_t
host_get_UNDServer(host_priv_t host_priv,UNDServerRef * serverp)381*bbb1b6f9SApple OSS Distributions host_get_UNDServer(
382*bbb1b6f9SApple OSS Distributions 	host_priv_t     host_priv,
383*bbb1b6f9SApple OSS Distributions 	UNDServerRef    *serverp)
384*bbb1b6f9SApple OSS Distributions {
385*bbb1b6f9SApple OSS Distributions #if CONFIG_USER_NOTIFICATION
386*bbb1b6f9SApple OSS Distributions 	return host_get_user_notification_port(host_priv, serverp);
387*bbb1b6f9SApple OSS Distributions #else
388*bbb1b6f9SApple OSS Distributions #pragma unused(host_priv, serverp)
389*bbb1b6f9SApple OSS Distributions 	return KERN_NOT_SUPPORTED;
390*bbb1b6f9SApple OSS Distributions #endif
391*bbb1b6f9SApple OSS Distributions }
392