2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
27 #include <mach/mach.h>
32 #include "_lu_types.h"
35 #include "netdb_async.h"
37 #define MAX_LOOKUP_ATTEMPTS 10
38 #define _LU_MAXLUSTRLEN 256
39 #define QBUF_SIZE 4096
41 #define LU_MESSAGE_SEND_ID 4241776
42 #define LU_MESSAGE_REPLY_ID 4241876
44 static pthread_key_t _info_key
= NULL
;
45 static pthread_once_t _info_key_initialized
= PTHREAD_ONCE_INIT
;
52 void (**idata_destructor
)(void *);
55 typedef struct _lu_async_request_s
57 mach_port_t reply_port
;
62 ooline_data request_buffer
;
63 mach_msg_type_number_t request_buffer_len
;
64 struct _lu_async_request_s
*next
;
65 } _lu_async_request_t
;
69 mach_msg_header_t head
;
72 mach_msg_type_number_t query_data_len
;
73 unit query_data
[QBUF_SIZE
];
78 mach_msg_header_t head
;
79 mach_msg_body_t msgh_body
;
80 mach_msg_ool_descriptor_t reply_data
;
82 mach_msg_type_number_t reply_data_len
;
83 mach_msg_format_0_trailer_t trailer
;
86 static pthread_mutex_t _lu_worklist_lock
= PTHREAD_MUTEX_INITIALIZER
;
87 static _lu_async_request_t
*_lu_worklist
= NULL
;
89 /* Send an asynchronous query message to lookupd */
91 _lu_async_send(_lu_async_request_t
*r
)
94 register _lu_query_msg_t
*inp
= &in
;
95 mach_msg_return_t status
;
96 unsigned int msgh_size
;
98 if (r
== NULL
) return KERN_FAILURE
;
100 if (r
->retry
== 0) return MIG_SERVER_DIED
;
103 if (r
->request_buffer_len
> QBUF_SIZE
) return MIG_ARRAY_TOO_LARGE
;
105 msgh_size
= (sizeof(_lu_query_msg_t
) - 16384) + ((4 * r
->request_buffer_len
));
106 inp
->head
.msgh_bits
= MACH_MSGH_BITS(19, MACH_MSG_TYPE_MAKE_SEND_ONCE
);
107 inp
->head
.msgh_remote_port
= _lu_port
;
108 inp
->head
.msgh_local_port
= r
->reply_port
;
109 inp
->head
.msgh_id
= LU_MESSAGE_SEND_ID
;
110 inp
->NDR
= NDR_record
;
112 inp
->query_data_len
= r
->request_buffer_len
;
113 memcpy(inp
->query_data
, r
->request_buffer
, 4 * r
->request_buffer_len
);
115 status
= mach_msg(&inp
->head
, MACH_SEND_MSG
, msgh_size
, 0, MACH_PORT_NULL
, MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
116 if (status
== MACH_MSG_SUCCESS
) return KERN_SUCCESS
;
118 if (status
== MACH_SEND_INVALID_REPLY
)
120 mach_port_mod_refs(mach_task_self(), r
->reply_port
, MACH_PORT_RIGHT_RECEIVE
, -1);
121 r
->reply_port
= MACH_PORT_NULL
;
127 static _lu_async_request_t
*
128 _lu_worklist_remove(mach_port_t p
)
130 _lu_async_request_t
*r
, *n
;
132 if (p
== MACH_PORT_NULL
) return NULL
;
133 if (_lu_worklist
== NULL
) return NULL
;
135 pthread_mutex_lock(&_lu_worklist_lock
);
137 if (_lu_worklist
->reply_port
== p
)
140 _lu_worklist
= r
->next
;
141 pthread_mutex_unlock(&_lu_worklist_lock
);
145 for (r
= _lu_worklist
; r
!= NULL
; r
= r
->next
)
148 if (n
== NULL
) break;
150 if (n
->reply_port
== p
)
153 pthread_mutex_unlock(&_lu_worklist_lock
);
158 pthread_mutex_unlock(&_lu_worklist_lock
);
162 static _lu_async_request_t
*
163 _lu_worklist_find(mach_port_t p
)
165 _lu_async_request_t
*r
;
167 if (p
== MACH_PORT_NULL
) return NULL
;
168 if (_lu_worklist
== NULL
) return NULL
;
170 pthread_mutex_lock(&_lu_worklist_lock
);
172 for (r
= _lu_worklist
; r
!= NULL
; r
= r
->next
)
174 if (r
->reply_port
== p
)
176 pthread_mutex_unlock(&_lu_worklist_lock
);
181 pthread_mutex_unlock(&_lu_worklist_lock
);
186 _lu_free_request(_lu_async_request_t
*r
)
188 if (r
== NULL
) return;
190 if (r
->request_buffer
!= NULL
) free(r
->request_buffer
);
191 r
->request_buffer
= NULL
;
193 if (r
->reply_port
!= MACH_PORT_NULL
) mach_port_destroy(mach_task_self(), r
->reply_port
);
194 r
->reply_port
= MACH_PORT_NULL
;
199 /* Receive an asynchronous reply message from lookupd */
201 lu_async_receive(mach_port_t p
, char **buf
, uint32_t *len
)
204 kern_return_t status
;
206 _lu_async_request_t
*req
;
208 size
= sizeof(_lu_reply_msg_t
);
210 r
= (_lu_reply_msg_t
*)calloc(1, size
);
211 if (r
== NULL
) return KERN_RESOURCE_SHORTAGE
;
213 r
->head
.msgh_local_port
= p
;
214 r
->head
.msgh_size
= size
;
215 status
= mach_msg(&(r
->head
), MACH_RCV_MSG
, 0, size
, r
->head
.msgh_local_port
, 0, MACH_PORT_NULL
);
216 if (status
!= KERN_SUCCESS
)
222 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
229 *buf
= r
->reply_data
.address
;
230 *len
= r
->reply_data
.size
;
234 _lu_free_request(req
);
239 _lu_worklist_append(_lu_async_request_t
*r
)
241 _lu_async_request_t
*p
;
243 if (r
== NULL
) return;
245 pthread_mutex_lock(&_lu_worklist_lock
);
247 if (_lu_worklist
== NULL
)
250 pthread_mutex_unlock(&_lu_worklist_lock
);
254 for (p
= _lu_worklist
; p
->next
!= NULL
; p
= p
->next
);
257 pthread_mutex_unlock(&_lu_worklist_lock
);
261 lu_async_call_cancel(mach_port_t p
)
263 _lu_async_request_t
*req
;
265 req
= _lu_worklist_remove(p
);
266 if (req
!= NULL
) _lu_free_request(req
);
267 else if (p
!= MACH_PORT_NULL
) mach_port_destroy(mach_task_self(), p
);
270 static _lu_async_request_t
*
271 _lu_create_request(uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
273 _lu_async_request_t
*r
;
274 kern_return_t status
;
276 if (_lu_port
== NULL
) return NULL
;
278 r
= (_lu_async_request_t
*)calloc(1, sizeof(_lu_async_request_t
));
279 if (r
== NULL
) return NULL
;
281 status
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &(r
->reply_port
));
282 if (status
!= KERN_SUCCESS
)
288 r
->retry
= MAX_LOOKUP_ATTEMPTS
;
290 r
->context
= context
;
291 r
->callback
= callback
;
294 r
->request_buffer
= malloc(len
* BYTES_PER_XDR_UNIT
);
295 memcpy(r
->request_buffer
, buf
, len
* BYTES_PER_XDR_UNIT
);
296 r
->request_buffer_len
= len
;
304 lu_async_start(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
306 _lu_async_request_t
*r
;
307 kern_return_t status
;
310 if (p
== NULL
) return KERN_FAILURE
;
314 if (!_lu_running()) return KERN_FAILURE
;
316 /* Make a request struct to keep track */
317 r
= _lu_create_request(proc
, buf
, len
, callback
, context
);
318 if (r
== NULL
) return KERN_FAILURE
;
320 status
= MIG_SERVER_DIED
;
321 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
323 /* send to lookupd */
324 status
= _lu_async_send(r
);
327 if (status
!= KERN_SUCCESS
)
333 /* Add request to worklist */
334 _lu_worklist_append(r
);
341 lu_async_send(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
)
343 return lu_async_start(p
, proc
, buf
, len
, NULL
, NULL
);
347 lu_async_handle_reply(void *msg
, char **buf
, uint32_t *len
, void **callback
, void **context
)
350 _lu_async_request_t
*req
;
351 kern_return_t status
;
354 if (msg
== NULL
) return -1;
355 r
= (_lu_reply_msg_t
*)msg
;
357 /* If reply status was an error, resend */
358 if (r
->head
.msgh_id
!= LU_MESSAGE_REPLY_ID
)
360 if (r
->head
.msgh_id
== MACH_NOTIFY_SEND_ONCE
)
362 /* if MiG server (lookupd) died */
363 req
= _lu_worklist_find(r
->head
.msgh_local_port
);
364 if (req
== NULL
) return -1;
366 status
= MIG_SERVER_DIED
;
367 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
369 /* send to lookupd */
370 status
= _lu_async_send(req
);
373 if (status
!= KERN_SUCCESS
) return -1;
375 return MIG_REPLY_MISMATCH
;
378 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
379 if (req
== NULL
) return -1;
381 *buf
= r
->reply_data
.address
;
382 *len
= r
->reply_data
.size
;
383 *callback
= req
->callback
;
384 *context
= req
->context
;
386 _lu_free_request(req
);
391 _lookupd_xdr_dictionary(XDR
*inxdr
)
393 int i
, nkeys
, j
, nvals
;
397 if (!xdr_int(inxdr
, &nkeys
)) return NULL
;
399 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
402 l
->ni_proplist_len
= nkeys
;
403 l
->ni_proplist_val
= NULL
;
406 i
= nkeys
* sizeof(ni_property
);
407 l
->ni_proplist_val
= (ni_property
*)calloc(1, i
);
410 for (i
= 0; i
< nkeys
; i
++)
413 if (!xdr_string(inxdr
, &key
, -1))
419 l
->ni_proplist_val
[i
].nip_name
= key
;
421 if (!xdr_int(inxdr
, &nvals
))
427 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_len
= nvals
;
430 j
= nvals
* sizeof(ni_name
);
431 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
= (ni_name
*)calloc(1, j
);
434 for (j
= 0; j
< nvals
; j
++)
437 if (!xdr_string(inxdr
, &val
, -1))
443 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
[j
] = val
;
451 lookupd_query(ni_proplist
*l
, ni_proplist
***out
)
458 char databuf
[_LU_MAXLUSTRLEN
* BYTES_PER_XDR_UNIT
];
460 kern_return_t status
;
463 if (l
== NULL
) return 0;
464 if (out
== NULL
) return 0;
466 if (_lu_port
== NULL
) return 0;
468 status
= _lookup_link(_lu_port
, "query", &proc
);
469 if (status
!= KERN_SUCCESS
) return 0;
471 xdrmem_create(&outxdr
, databuf
, sizeof(databuf
), XDR_ENCODE
);
473 na
= l
->ni_proplist_len
;
475 /* Encode attribute count */
476 if (!xdr_int(&outxdr
, &na
))
478 xdr_destroy(&outxdr
);
482 for (i
= 0; i
< l
->ni_proplist_len
; i
++)
484 p
= &(l
->ni_proplist_val
[i
]);
486 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
488 xdr_destroy(&outxdr
);
493 if (!xdr_int(&outxdr
, &(p
->nip_val
.ni_namelist_len
)))
495 xdr_destroy(&outxdr
);
499 for (j
= 0; j
< p
->nip_val
.ni_namelist_len
; j
++)
502 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
504 xdr_destroy(&outxdr
);
507 p
->nip_val
.ni_namelist_val
[j
] = s
;
514 n
= xdr_getpos(&outxdr
) / BYTES_PER_XDR_UNIT
;
515 status
= _lookup_all(_lu_port
, proc
, (unit
*)databuf
, n
, &listbuf
, &datalen
);
516 if (status
!= KERN_SUCCESS
)
518 xdr_destroy(&outxdr
);
522 xdr_destroy(&outxdr
);
525 /* NOTDEF because OOL buffers are counted in bytes with untyped IPC */
526 datalen
*= BYTES_PER_XDR_UNIT
;
529 xdrmem_create(&inxdr
, listbuf
, datalen
, XDR_DECODE
);
531 if (!xdr_int(&inxdr
, &n
))
543 *out
= (ni_proplist
**)malloc(n
* sizeof(ni_proplist
*));
545 for (i
= 0; i
< n
; i
++)
547 (*out
)[i
] = _lookupd_xdr_dictionary(&inxdr
);
552 vm_deallocate(mach_task_self(), (vm_address_t
)listbuf
, datalen
);
558 lookupd_make_query(char *cat
, char *fmt
, ...)
566 if (fmt
== NULL
) return NULL
;
567 if (fmt
[0] != 'k') return NULL
;
569 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
577 l
->ni_proplist_val
= (ni_property
*)malloc(sizeof(ni_property
));
578 p
= &(l
->ni_proplist_val
[0]);
579 arg
= "_lookup_category";
580 p
->nip_name
= strdup(arg
);
581 p
->nip_val
.ni_namelist_len
= 1;
582 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
583 p
->nip_val
.ni_namelist_val
[0] = strdup(cat
);
585 l
->ni_proplist_len
++;
590 for (f
= fmt
; *f
!= NULL
; f
++)
592 arg
= va_arg(ap
, char *);
595 l
->ni_proplist_val
= (ni_property
*)realloc(l
->ni_proplist_val
, (l
->ni_proplist_len
+ 1) * sizeof(ni_property
));
597 p
= &(l
->ni_proplist_val
[l
->ni_proplist_len
]);
598 p
->nip_name
= strdup(arg
);
599 p
->nip_val
.ni_namelist_len
= 0;
600 p
->nip_val
.ni_namelist_val
= NULL
;
602 l
->ni_proplist_len
++;
607 p
= &(l
->ni_proplist_val
[x
]);
608 if (p
->nip_val
.ni_namelist_len
== 0)
610 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
614 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
));
616 p
->nip_val
.ni_namelist_val
[p
->nip_val
.ni_namelist_len
] = strdup(arg
);
617 p
->nip_val
.ni_namelist_len
++;
626 ni_property_merge(ni_property
*a
, ni_property
*b
)
630 if (a
== NULL
) return;
631 if (b
== NULL
) return;
633 for (j
= 0; j
< b
->nip_val
.ni_namelist_len
; j
++)
636 for (i
= 0; i
< (a
->nip_val
.ni_namelist_len
) && (addme
== 1); i
++)
638 if (!strcmp(a
->nip_val
.ni_namelist_val
[i
], b
->nip_val
.ni_namelist_val
[j
])) addme
= 0;
643 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
));
644 a
->nip_val
.ni_namelist_val
[a
->nip_val
.ni_namelist_len
] = strdup(b
->nip_val
.ni_namelist_val
[j
]);
645 a
->nip_val
.ni_namelist_len
++;
651 ni_proplist_merge(ni_proplist
*a
, ni_proplist
*b
)
656 if (a
== NULL
) return;
657 if (b
== NULL
) return;
659 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
662 for (wa
= 0; (wa
< a
->ni_proplist_len
) && (addme
== 1) ; wa
++)
664 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
)) addme
= 0;
668 a
->ni_proplist_val
= (ni_property
*)realloc(a
->ni_proplist_val
, (a
->ni_proplist_len
+ 1) * sizeof(ni_property
));
669 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_name
= strdup(b
->ni_proplist_val
[wb
].nip_name
);
670 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_len
= 0;
671 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_val
= NULL
;
672 a
->ni_proplist_len
++;
676 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
678 for (wa
= 0; wa
< a
->ni_proplist_len
; wa
++)
680 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
))
682 ni_property_merge(&(a
->ni_proplist_val
[wa
]), &(b
->ni_proplist_val
[wb
]));
689 _lu_data_free(void *x
)
691 struct _lu_data_s
*t
;
694 if (x
== NULL
) return;
696 t
= (struct _lu_data_s
*)x
;
698 for (i
= 0; i
< t
->icount
; i
++)
700 if ((t
->idata
[i
] != NULL
) && (t
->idata_destructor
[i
] != NULL
))
702 (*(t
->idata_destructor
[i
]))(t
->idata
[i
]);
706 t
->idata_destructor
[i
] = NULL
;
709 if (t
->ikey
!= NULL
) free(t
->ikey
);
712 if (t
->idata
!= NULL
) free(t
->idata
);
715 if (t
->idata_destructor
!= NULL
) free(t
->idata_destructor
);
716 t
->idata_destructor
= NULL
;
724 pthread_key_create(&_info_key
, _lu_data_free
);
728 static struct _lu_data_s
*
731 struct _lu_data_s
*libinfo_data
;
734 * Only one thread should create the _info_key
736 pthread_once(&_info_key_initialized
, _lu_data_init
);
738 /* Check if this thread already created libinfo_data */
739 libinfo_data
= pthread_getspecific(_info_key
);
740 if (libinfo_data
!= NULL
) return libinfo_data
;
742 libinfo_data
= (struct _lu_data_s
*)calloc(1, sizeof(struct _lu_data_s
));
744 pthread_setspecific(_info_key
, libinfo_data
);
749 _lu_data_create_key(unsigned int key
, void (*destructor
)(void *))
751 struct _lu_data_s
*libinfo_data
;
754 libinfo_data
= _lu_data_get();
756 for (i
= 0; i
< libinfo_data
->icount
; i
++)
758 if (libinfo_data
->ikey
[i
] == key
) return libinfo_data
->idata
[i
];
761 i
= libinfo_data
->icount
;
766 libinfo_data
->ikey
= (unsigned int *)malloc(sizeof(unsigned int));
767 libinfo_data
->idata
= (void **)malloc(sizeof(void *));
768 libinfo_data
->idata_destructor
= (void (**)(void *))malloc(sizeof(void (*)(void *)));
772 libinfo_data
->ikey
= (unsigned int *)realloc(libinfo_data
->ikey
, n
* sizeof(unsigned int));
773 libinfo_data
->idata
= (void **)realloc(libinfo_data
->idata
, n
* sizeof(void *));
774 libinfo_data
->idata_destructor
= (void (**)(void *))realloc(libinfo_data
->idata_destructor
, n
* sizeof(void (*)(void *)));
777 libinfo_data
->ikey
[i
] = key
;
778 libinfo_data
->idata
[i
] = NULL
;
779 libinfo_data
->idata_destructor
[i
] = destructor
;
780 libinfo_data
->icount
++;
786 _lu_data_index(unsigned int key
, struct _lu_data_s
*libinfo_data
)
790 if (libinfo_data
== NULL
) return (unsigned int)-1;
792 for (i
= 0; i
< libinfo_data
->icount
; i
++)
794 if (libinfo_data
->ikey
[i
] == key
) return i
;
797 return (unsigned int)-1;
801 _lu_data_set_key(unsigned int key
, void *data
)
803 struct _lu_data_s
*libinfo_data
;
806 libinfo_data
= _lu_data_get();
808 i
= _lu_data_index(key
, libinfo_data
);
809 if (i
== (unsigned int)-1) return;
811 libinfo_data
->idata
[i
] = data
;
815 _lu_data_get_key(unsigned int key
)
817 struct _lu_data_s
*libinfo_data
;
820 libinfo_data
= _lu_data_get();
822 i
= _lu_data_index(key
, libinfo_data
);
823 if (i
== (unsigned int)-1) return NULL
;
825 return libinfo_data
->idata
[i
];
829 _lu_data_free_vm_xdr(struct lu_thread_info
*tdata
)
831 if (tdata
== NULL
) return;
833 if (tdata
->lu_vm
!= NULL
)
835 vm_deallocate(mach_task_self(), (vm_address_t
)tdata
->lu_vm
, tdata
->lu_vm_length
);
838 tdata
->lu_vm_length
= 0;
839 tdata
->lu_vm_cursor
= 0;
841 if (tdata
->lu_xdr
!= NULL
)
843 xdr_destroy(tdata
->lu_xdr
);
845 tdata
->lu_xdr
= NULL
;
850 _lu_xdr_attribute(XDR
*xdr
, char **key
, char ***val
, unsigned int *count
)
852 unsigned int i
, j
, len
;
855 if (xdr
== NULL
) return -1;
856 if (key
== NULL
) return -1;
857 if (val
== NULL
) return -1;
858 if (count
== NULL
) return -1;
864 if (!xdr_string(xdr
, key
, -1)) return -1;
866 if (!xdr_int(xdr
, &len
))
873 if (len
== 0) return 0;
876 x
= (char **)calloc(len
+ 1, sizeof(char *));
879 for (i
= 0; i
< len
; i
++)
882 if (!xdr_string(xdr
, &s
, -1))
884 for (j
= 0; j
< i
; j
++) free(x
[j
]);
901 _lookup_link(mach_port_t server
, lookup_name name
, int *procno
)
903 kern_return_t status
;
904 security_token_t token
;
910 status
= MIG_SERVER_DIED
;
911 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
913 status
= _lookup_link_secure(server
, name
, procno
, &token
);
916 if (status
!= KERN_SUCCESS
)
919 syslog(LOG_DEBUG
, "pid %u _lookup_link %s status %u", getpid(), name
, status
);
924 if (token
.val
[0] != 0)
927 syslog(LOG_DEBUG
, "pid %u _lookup_link %s auth failure uid=%d", getpid(), name
, token
.val
[0]);
933 syslog(LOG_DEBUG
, "pid %u _lookup_link %s = %d", getpid(), name
, *procno
);
939 _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
)
941 kern_return_t status
;
942 security_token_t token
;
948 status
= MIG_SERVER_DIED
;
949 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
951 status
= _lookup_one_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
954 if (status
!= KERN_SUCCESS
)
957 syslog(LOG_DEBUG
, "pid %u _lookup_one %d status %u", getpid(), proc
, status
);
962 if (token
.val
[0] != 0)
965 syslog(LOG_DEBUG
, "pid %u _lookup_one %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
971 syslog(LOG_DEBUG
, "pid %u _lookup_one %d", getpid(), proc
);
977 _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
)
979 kern_return_t status
;
980 security_token_t token
;
986 status
= MIG_SERVER_DIED
;
987 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
989 status
= _lookup_all_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
992 if (status
!= KERN_SUCCESS
)
995 syslog(LOG_DEBUG
, "pid %u _lookup_all %d status %u", getpid(), proc
, status
);
1000 if (token
.val
[0] != 0)
1003 syslog(LOG_DEBUG
, "pid %u _lookup_all %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1005 return KERN_FAILURE
;
1009 syslog(LOG_DEBUG
, "pid %u _lookup_all %d", getpid(), proc
);
1015 _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
)
1017 kern_return_t status
;
1018 security_token_t token
;
1024 status
= MIG_SERVER_DIED
;
1025 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
1027 status
= _lookup_ooall_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
1030 if (status
!= KERN_SUCCESS
)
1033 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d status %u", getpid(), proc
, status
);
1038 if (token
.val
[0] != 0)
1041 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1043 return KERN_FAILURE
;
1047 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d", getpid(), proc
);