2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 #include <mach/mach.h>
33 #include "_lu_types.h"
36 #include "netdb_async.h"
38 #define MAX_LOOKUP_ATTEMPTS 10
39 #define _LU_MAXLUSTRLEN 256
40 #define QBUF_SIZE 4096
42 #define LU_MESSAGE_SEND_ID 4241776
43 #define LU_MESSAGE_REPLY_ID 4241876
45 static pthread_key_t _info_key
= NULL
;
46 static pthread_once_t _info_key_initialized
= PTHREAD_ONCE_INIT
;
53 void (**idata_destructor
)(void *);
56 typedef struct _lu_async_request_s
58 mach_port_t reply_port
;
63 ooline_data request_buffer
;
64 mach_msg_type_number_t request_buffer_len
;
65 struct _lu_async_request_s
*next
;
66 } _lu_async_request_t
;
70 mach_msg_header_t head
;
73 mach_msg_type_number_t query_data_len
;
74 unit query_data
[QBUF_SIZE
];
79 mach_msg_header_t head
;
80 mach_msg_body_t msgh_body
;
81 mach_msg_ool_descriptor_t reply_data
;
83 mach_msg_type_number_t reply_data_len
;
84 mach_msg_format_0_trailer_t trailer
;
87 static pthread_mutex_t _lu_worklist_lock
= PTHREAD_MUTEX_INITIALIZER
;
88 static _lu_async_request_t
*_lu_worklist
= NULL
;
90 /* Send an asynchronous query message to lookupd */
92 _lu_async_send(_lu_async_request_t
*r
)
95 register _lu_query_msg_t
*inp
= &in
;
96 mach_msg_return_t status
;
97 unsigned int msgh_size
;
99 if (r
== NULL
) return KERN_FAILURE
;
101 if (r
->retry
== 0) return MIG_SERVER_DIED
;
104 if (r
->request_buffer_len
> QBUF_SIZE
) return MIG_ARRAY_TOO_LARGE
;
106 msgh_size
= (sizeof(_lu_query_msg_t
) - 16384) + ((4 * r
->request_buffer_len
));
107 inp
->head
.msgh_bits
= MACH_MSGH_BITS(19, MACH_MSG_TYPE_MAKE_SEND_ONCE
);
108 inp
->head
.msgh_remote_port
= _lu_port
;
109 inp
->head
.msgh_local_port
= r
->reply_port
;
110 inp
->head
.msgh_id
= LU_MESSAGE_SEND_ID
;
111 inp
->NDR
= NDR_record
;
113 inp
->query_data_len
= r
->request_buffer_len
;
114 memcpy(inp
->query_data
, r
->request_buffer
, 4 * r
->request_buffer_len
);
116 status
= mach_msg(&inp
->head
, MACH_SEND_MSG
, msgh_size
, 0, MACH_PORT_NULL
, MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
117 if (status
== MACH_MSG_SUCCESS
) return KERN_SUCCESS
;
119 if (status
== MACH_SEND_INVALID_REPLY
)
121 mach_port_mod_refs(mach_task_self(), r
->reply_port
, MACH_PORT_RIGHT_RECEIVE
, -1);
122 r
->reply_port
= MACH_PORT_NULL
;
128 static _lu_async_request_t
*
129 _lu_worklist_remove(mach_port_t p
)
131 _lu_async_request_t
*r
, *n
;
133 if (p
== MACH_PORT_NULL
) return NULL
;
134 if (_lu_worklist
== NULL
) return NULL
;
136 pthread_mutex_lock(&_lu_worklist_lock
);
138 if (_lu_worklist
->reply_port
== p
)
141 _lu_worklist
= r
->next
;
142 pthread_mutex_unlock(&_lu_worklist_lock
);
146 for (r
= _lu_worklist
; r
!= NULL
; r
= r
->next
)
149 if (n
== NULL
) break;
151 if (n
->reply_port
== p
)
154 pthread_mutex_unlock(&_lu_worklist_lock
);
159 pthread_mutex_unlock(&_lu_worklist_lock
);
163 static _lu_async_request_t
*
164 _lu_worklist_find(mach_port_t p
)
166 _lu_async_request_t
*r
;
168 if (p
== MACH_PORT_NULL
) return NULL
;
169 if (_lu_worklist
== NULL
) return NULL
;
171 pthread_mutex_lock(&_lu_worklist_lock
);
173 for (r
= _lu_worklist
; r
!= NULL
; r
= r
->next
)
175 if (r
->reply_port
== p
)
177 pthread_mutex_unlock(&_lu_worklist_lock
);
182 pthread_mutex_unlock(&_lu_worklist_lock
);
187 _lu_free_request(_lu_async_request_t
*r
)
189 if (r
== NULL
) return;
191 if (r
->request_buffer
!= NULL
) free(r
->request_buffer
);
192 r
->request_buffer
= NULL
;
194 if (r
->reply_port
!= MACH_PORT_NULL
) mach_port_destroy(mach_task_self(), r
->reply_port
);
195 r
->reply_port
= MACH_PORT_NULL
;
200 /* Receive an asynchronous reply message from lookupd */
202 lu_async_receive(mach_port_t p
, char **buf
, uint32_t *len
)
205 kern_return_t status
;
207 _lu_async_request_t
*req
;
209 size
= sizeof(_lu_reply_msg_t
);
211 r
= (_lu_reply_msg_t
*)calloc(1, size
);
212 if (r
== NULL
) return KERN_RESOURCE_SHORTAGE
;
214 r
->head
.msgh_local_port
= p
;
215 r
->head
.msgh_size
= size
;
216 status
= mach_msg(&(r
->head
), MACH_RCV_MSG
, 0, size
, r
->head
.msgh_local_port
, 0, MACH_PORT_NULL
);
217 if (status
!= KERN_SUCCESS
)
223 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
230 *buf
= r
->reply_data
.address
;
231 *len
= r
->reply_data
.size
;
235 _lu_free_request(req
);
240 _lu_worklist_append(_lu_async_request_t
*r
)
242 _lu_async_request_t
*p
;
244 if (r
== NULL
) return;
246 pthread_mutex_lock(&_lu_worklist_lock
);
248 if (_lu_worklist
== NULL
)
251 pthread_mutex_unlock(&_lu_worklist_lock
);
255 for (p
= _lu_worklist
; p
->next
!= NULL
; p
= p
->next
);
258 pthread_mutex_unlock(&_lu_worklist_lock
);
262 lu_async_call_cancel(mach_port_t p
)
264 _lu_async_request_t
*req
;
266 req
= _lu_worklist_remove(p
);
267 if (req
!= NULL
) _lu_free_request(req
);
268 else if (p
!= MACH_PORT_NULL
) mach_port_destroy(mach_task_self(), p
);
271 static _lu_async_request_t
*
272 _lu_create_request(uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
274 _lu_async_request_t
*r
;
275 kern_return_t status
;
277 if (_lu_port
== NULL
) return NULL
;
279 r
= (_lu_async_request_t
*)calloc(1, sizeof(_lu_async_request_t
));
280 if (r
== NULL
) return NULL
;
282 status
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &(r
->reply_port
));
283 if (status
!= KERN_SUCCESS
)
289 r
->retry
= MAX_LOOKUP_ATTEMPTS
;
291 r
->context
= context
;
292 r
->callback
= callback
;
295 r
->request_buffer
= malloc(len
* BYTES_PER_XDR_UNIT
);
296 memcpy(r
->request_buffer
, buf
, len
* BYTES_PER_XDR_UNIT
);
297 r
->request_buffer_len
= len
;
305 lu_async_start(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
307 _lu_async_request_t
*r
;
308 kern_return_t status
;
311 if (p
== NULL
) return KERN_FAILURE
;
315 if (!_lu_running()) return KERN_FAILURE
;
317 /* Make a request struct to keep track */
318 r
= _lu_create_request(proc
, buf
, len
, callback
, context
);
319 if (r
== NULL
) return KERN_FAILURE
;
321 status
= MIG_SERVER_DIED
;
322 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
324 /* send to lookupd */
325 status
= _lu_async_send(r
);
328 if (status
!= KERN_SUCCESS
)
334 /* Add request to worklist */
335 _lu_worklist_append(r
);
342 lu_async_send(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
)
344 return lu_async_start(p
, proc
, buf
, len
, NULL
, NULL
);
348 lu_async_handle_reply(void *msg
, char **buf
, uint32_t *len
, void **callback
, void **context
)
351 _lu_async_request_t
*req
;
352 kern_return_t status
;
355 if (msg
== NULL
) return -1;
356 r
= (_lu_reply_msg_t
*)msg
;
358 /* If reply status was an error, resend */
359 if (r
->head
.msgh_id
!= LU_MESSAGE_REPLY_ID
)
361 if (r
->head
.msgh_id
== MACH_NOTIFY_SEND_ONCE
)
363 /* if MiG server (lookupd) died */
364 req
= _lu_worklist_find(r
->head
.msgh_local_port
);
365 if (req
== NULL
) return -1;
367 status
= MIG_SERVER_DIED
;
368 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
370 /* send to lookupd */
371 status
= _lu_async_send(req
);
374 if (status
!= KERN_SUCCESS
) return -1;
376 return MIG_REPLY_MISMATCH
;
379 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
380 if (req
== NULL
) return -1;
382 *buf
= r
->reply_data
.address
;
383 *len
= r
->reply_data
.size
;
384 *callback
= req
->callback
;
385 *context
= req
->context
;
387 _lu_free_request(req
);
392 _lookupd_xdr_dictionary(XDR
*inxdr
)
394 int i
, nkeys
, j
, nvals
;
398 if (!xdr_int(inxdr
, &nkeys
)) return NULL
;
400 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
403 l
->ni_proplist_len
= nkeys
;
404 l
->ni_proplist_val
= NULL
;
407 i
= nkeys
* sizeof(ni_property
);
408 l
->ni_proplist_val
= (ni_property
*)calloc(1, i
);
411 for (i
= 0; i
< nkeys
; i
++)
414 if (!xdr_string(inxdr
, &key
, -1))
420 l
->ni_proplist_val
[i
].nip_name
= key
;
422 if (!xdr_int(inxdr
, &nvals
))
428 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_len
= nvals
;
431 j
= nvals
* sizeof(ni_name
);
432 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
= (ni_name
*)calloc(1, j
);
435 for (j
= 0; j
< nvals
; j
++)
438 if (!xdr_string(inxdr
, &val
, -1))
444 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
[j
] = val
;
452 lookupd_query(ni_proplist
*l
, ni_proplist
***out
)
459 char databuf
[_LU_MAXLUSTRLEN
* BYTES_PER_XDR_UNIT
];
461 kern_return_t status
;
464 if (l
== NULL
) return 0;
465 if (out
== NULL
) return 0;
467 if (_lu_port
== NULL
) return 0;
469 status
= _lookup_link(_lu_port
, "query", &proc
);
470 if (status
!= KERN_SUCCESS
) return 0;
472 xdrmem_create(&outxdr
, databuf
, sizeof(databuf
), XDR_ENCODE
);
474 na
= l
->ni_proplist_len
;
476 /* Encode attribute count */
477 if (!xdr_int(&outxdr
, &na
))
479 xdr_destroy(&outxdr
);
483 for (i
= 0; i
< l
->ni_proplist_len
; i
++)
485 p
= &(l
->ni_proplist_val
[i
]);
487 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
489 xdr_destroy(&outxdr
);
494 if (!xdr_int(&outxdr
, &(p
->nip_val
.ni_namelist_len
)))
496 xdr_destroy(&outxdr
);
500 for (j
= 0; j
< p
->nip_val
.ni_namelist_len
; j
++)
503 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
505 xdr_destroy(&outxdr
);
508 p
->nip_val
.ni_namelist_val
[j
] = s
;
515 n
= xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
;
516 status
= _lookup_all(_lu_port
, proc
, (unit
*)databuf
, n
, &listbuf
, &datalen
);
517 if (status
!= KERN_SUCCESS
)
519 xdr_destroy(&outxdr
);
523 xdr_destroy(&outxdr
);
526 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
527 datalen
*= BYTES_PER_XDR_UNIT
;
530 xdrmem_create(&inxdr
, listbuf
, datalen
, XDR_DECODE
);
532 if (!xdr_int(&inxdr
, &n
))
544 *out
= (ni_proplist
**)malloc(n
* sizeof(ni_proplist
*));
546 for (i
= 0; i
< n
; i
++)
548 (*out
)[i
] = _lookupd_xdr_dictionary(&inxdr
);
553 vm_deallocate(mach_task_self(), (vm_address_t
)listbuf
, datalen
);
559 lookupd_make_query(char *cat
, char *fmt
, ...)
567 if (fmt
== NULL
) return NULL
;
568 if (fmt
[0] != 'k') return NULL
;
570 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
578 l
->ni_proplist_val
= (ni_property
*)malloc(sizeof(ni_property
));
579 p
= &(l
->ni_proplist_val
[0]);
580 arg
= "_lookup_category";
581 p
->nip_name
= strdup(arg
);
582 p
->nip_val
.ni_namelist_len
= 1;
583 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
584 p
->nip_val
.ni_namelist_val
[0] = strdup(cat
);
586 l
->ni_proplist_len
++;
591 for (f
= fmt
; *f
!= NULL
; f
++)
593 arg
= va_arg(ap
, char *);
596 l
->ni_proplist_val
= (ni_property
*)realloc(l
->ni_proplist_val
, (l
->ni_proplist_len
+ 1) * sizeof(ni_property
));
598 p
= &(l
->ni_proplist_val
[l
->ni_proplist_len
]);
599 p
->nip_name
= strdup(arg
);
600 p
->nip_val
.ni_namelist_len
= 0;
601 p
->nip_val
.ni_namelist_val
= NULL
;
603 l
->ni_proplist_len
++;
608 p
= &(l
->ni_proplist_val
[x
]);
609 if (p
->nip_val
.ni_namelist_len
== 0)
611 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
615 p
->nip_val
.ni_namelist_val
= (ni_name
*)realloc(p
->nip_val
.ni_namelist_val
, (p
->nip_val
.ni_namelist_len
+ 1) * sizeof(ni_name
));
617 p
->nip_val
.ni_namelist_val
[p
->nip_val
.ni_namelist_len
] = strdup(arg
);
618 p
->nip_val
.ni_namelist_len
++;
627 ni_property_merge(ni_property
*a
, ni_property
*b
)
631 if (a
== NULL
) return;
632 if (b
== NULL
) return;
634 for (j
= 0; j
< b
->nip_val
.ni_namelist_len
; j
++)
637 for (i
= 0; i
< (a
->nip_val
.ni_namelist_len
) && (addme
== 1); i
++)
639 if (!strcmp(a
->nip_val
.ni_namelist_val
[i
], b
->nip_val
.ni_namelist_val
[j
])) addme
= 0;
644 a
->nip_val
.ni_namelist_val
= (ni_name
*)realloc(a
->nip_val
.ni_namelist_val
, (a
->nip_val
.ni_namelist_len
+ 1) * sizeof(ni_name
));
645 a
->nip_val
.ni_namelist_val
[a
->nip_val
.ni_namelist_len
] = strdup(b
->nip_val
.ni_namelist_val
[j
]);
646 a
->nip_val
.ni_namelist_len
++;
652 ni_proplist_merge(ni_proplist
*a
, ni_proplist
*b
)
657 if (a
== NULL
) return;
658 if (b
== NULL
) return;
660 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
663 for (wa
= 0; (wa
< a
->ni_proplist_len
) && (addme
== 1) ; wa
++)
665 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
)) addme
= 0;
669 a
->ni_proplist_val
= (ni_property
*)realloc(a
->ni_proplist_val
, (a
->ni_proplist_len
+ 1) * sizeof(ni_property
));
670 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_name
= strdup(b
->ni_proplist_val
[wb
].nip_name
);
671 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_len
= 0;
672 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_val
= NULL
;
673 a
->ni_proplist_len
++;
677 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
679 for (wa
= 0; wa
< a
->ni_proplist_len
; wa
++)
681 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
))
683 ni_property_merge(&(a
->ni_proplist_val
[wa
]), &(b
->ni_proplist_val
[wb
]));
690 _lu_data_free(void *x
)
692 struct _lu_data_s
*t
;
695 if (x
== NULL
) return;
697 t
= (struct _lu_data_s
*)x
;
699 for (i
= 0; i
< t
->icount
; i
++)
701 if ((t
->idata
[i
] != NULL
) && (t
->idata_destructor
[i
] != NULL
))
703 (*(t
->idata_destructor
[i
]))(t
->idata
[i
]);
707 t
->idata_destructor
[i
] = NULL
;
710 if (t
->ikey
!= NULL
) free(t
->ikey
);
713 if (t
->idata
!= NULL
) free(t
->idata
);
716 if (t
->idata_destructor
!= NULL
) free(t
->idata_destructor
);
717 t
->idata_destructor
= NULL
;
725 pthread_key_create(&_info_key
, _lu_data_free
);
729 static struct _lu_data_s
*
732 struct _lu_data_s
*libinfo_data
;
735 * Only one thread should create the _info_key
737 pthread_once(&_info_key_initialized
, _lu_data_init
);
739 /* Check if this thread already created libinfo_data */
740 libinfo_data
= pthread_getspecific(_info_key
);
741 if (libinfo_data
!= NULL
) return libinfo_data
;
743 libinfo_data
= (struct _lu_data_s
*)calloc(1, sizeof(struct _lu_data_s
));
745 pthread_setspecific(_info_key
, libinfo_data
);
750 _lu_data_create_key(unsigned int key
, void (*destructor
)(void *))
752 struct _lu_data_s
*libinfo_data
;
755 libinfo_data
= _lu_data_get();
757 for (i
= 0; i
< libinfo_data
->icount
; i
++)
759 if (libinfo_data
->ikey
[i
] == key
) return libinfo_data
->idata
[i
];
762 i
= libinfo_data
->icount
;
767 libinfo_data
->ikey
= (unsigned int *)malloc(sizeof(unsigned int));
768 libinfo_data
->idata
= (void **)malloc(sizeof(void *));
769 libinfo_data
->idata_destructor
= (void (**)(void *))malloc(sizeof(void (*)(void *)));
773 libinfo_data
->ikey
= (unsigned int *)realloc(libinfo_data
->ikey
, n
* sizeof(unsigned int));
774 libinfo_data
->idata
= (void **)realloc(libinfo_data
->idata
, n
* sizeof(void *));
775 libinfo_data
->idata_destructor
= (void (**)(void *))realloc(libinfo_data
->idata_destructor
, n
* sizeof(void (*)(void *)));
778 libinfo_data
->ikey
[i
] = key
;
779 libinfo_data
->idata
[i
] = NULL
;
780 libinfo_data
->idata_destructor
[i
] = destructor
;
781 libinfo_data
->icount
++;
787 _lu_data_index(unsigned int key
, struct _lu_data_s
*libinfo_data
)
791 if (libinfo_data
== NULL
) return (unsigned int)-1;
793 for (i
= 0; i
< libinfo_data
->icount
; i
++)
795 if (libinfo_data
->ikey
[i
] == key
) return i
;
798 return (unsigned int)-1;
802 _lu_data_set_key(unsigned int key
, void *data
)
804 struct _lu_data_s
*libinfo_data
;
807 libinfo_data
= _lu_data_get();
809 i
= _lu_data_index(key
, libinfo_data
);
810 if (i
== (unsigned int)-1) return;
812 libinfo_data
->idata
[i
] = data
;
816 _lu_data_get_key(unsigned int key
)
818 struct _lu_data_s
*libinfo_data
;
821 libinfo_data
= _lu_data_get();
823 i
= _lu_data_index(key
, libinfo_data
);
824 if (i
== (unsigned int)-1) return NULL
;
826 return libinfo_data
->idata
[i
];
830 _lu_data_free_vm_xdr(struct lu_thread_info
*tdata
)
832 if (tdata
== NULL
) return;
834 if (tdata
->lu_vm
!= NULL
)
836 vm_deallocate(mach_task_self(), (vm_address_t
)tdata
->lu_vm
, tdata
->lu_vm_length
);
839 tdata
->lu_vm_length
= 0;
840 tdata
->lu_vm_cursor
= 0;
842 if (tdata
->lu_xdr
!= NULL
)
844 xdr_destroy(tdata
->lu_xdr
);
846 tdata
->lu_xdr
= NULL
;
851 _lu_xdr_attribute(XDR
*xdr
, char **key
, char ***val
, unsigned int *count
)
853 unsigned int i
, j
, len
;
856 if (xdr
== NULL
) return -1;
857 if (key
== NULL
) return -1;
858 if (val
== NULL
) return -1;
859 if (count
== NULL
) return -1;
865 if (!xdr_string(xdr
, key
, -1)) return -1;
867 if (!xdr_int(xdr
, &len
))
874 if (len
== 0) return 0;
877 x
= (char **)calloc(len
+ 1, sizeof(char *));
880 for (i
= 0; i
< len
; i
++)
883 if (!xdr_string(xdr
, &s
, -1))
885 for (j
= 0; j
< i
; j
++) free(x
[j
]);
902 _lookup_link(mach_port_t server
, lookup_name name
, int *procno
)
904 kern_return_t status
;
905 security_token_t token
;
911 status
= MIG_SERVER_DIED
;
912 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
914 status
= _lookup_link_secure(server
, name
, procno
, &token
);
917 if (status
!= KERN_SUCCESS
)
920 syslog(LOG_DEBUG
, "pid %u _lookup_link %s status %u", getpid(), name
, status
);
925 if (token
.val
[0] != 0)
928 syslog(LOG_DEBUG
, "pid %u _lookup_link %s auth failure uid=%d", getpid(), name
, token
.val
[0]);
934 syslog(LOG_DEBUG
, "pid %u _lookup_link %s = %d", getpid(), name
, *procno
);
940 _lookup_one(mach_port_t server
, int proc
, inline_data indata
, mach_msg_type_number_t indataCnt
, inline_data outdata
, mach_msg_type_number_t
*outdataCnt
)
942 kern_return_t status
;
943 security_token_t token
;
949 status
= MIG_SERVER_DIED
;
950 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
952 status
= _lookup_one_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
955 if (status
!= KERN_SUCCESS
)
958 syslog(LOG_DEBUG
, "pid %u _lookup_one %d status %u", getpid(), proc
, status
);
963 if (token
.val
[0] != 0)
966 syslog(LOG_DEBUG
, "pid %u _lookup_one %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
972 syslog(LOG_DEBUG
, "pid %u _lookup_one %d", getpid(), proc
);
978 _lookup_all(mach_port_t server
, int proc
, inline_data indata
, mach_msg_type_number_t indataCnt
, ooline_data
*outdata
, mach_msg_type_number_t
*outdataCnt
)
980 kern_return_t status
;
981 security_token_t token
;
987 status
= MIG_SERVER_DIED
;
988 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
990 status
= _lookup_all_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
993 if (status
!= KERN_SUCCESS
)
996 syslog(LOG_DEBUG
, "pid %u _lookup_all %d status %u", getpid(), proc
, status
);
1001 if (token
.val
[0] != 0)
1004 syslog(LOG_DEBUG
, "pid %u _lookup_all %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1006 return KERN_FAILURE
;
1010 syslog(LOG_DEBUG
, "pid %u _lookup_all %d", getpid(), proc
);
1016 _lookup_ooall(mach_port_t server
, int proc
, ooline_data indata
, mach_msg_type_number_t indataCnt
, ooline_data
*outdata
, mach_msg_type_number_t
*outdataCnt
)
1018 kern_return_t status
;
1019 security_token_t token
;
1025 status
= MIG_SERVER_DIED
;
1026 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
1028 status
= _lookup_ooall_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
1031 if (status
!= KERN_SUCCESS
)
1034 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d status %u", getpid(), proc
, status
);
1039 if (token
.val
[0] != 0)
1042 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1044 return KERN_FAILURE
;
1048 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d", getpid(), proc
);