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