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