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