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