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
= 0;
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
;
207 boolean_t msgh_simple
;
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 msgh_simple
= !(r
->head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
);
225 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
232 if (msgh_simple
&& ((mig_reply_error_t
*) r
)->RetCode
!= KERN_SUCCESS
)
234 _lu_free_request(req
);
235 status
= ((mig_reply_error_t
*) r
)->RetCode
;
240 *buf
= r
->reply_data
.address
;
241 *len
= r
->reply_data
.size
;
245 _lu_free_request(req
);
250 _lu_worklist_append(_lu_async_request_t
*r
)
252 _lu_async_request_t
*p
;
254 if (r
== NULL
) return;
256 pthread_mutex_lock(&_lu_worklist_lock
);
258 if (_lu_worklist
== NULL
)
261 pthread_mutex_unlock(&_lu_worklist_lock
);
265 for (p
= _lu_worklist
; p
->next
!= NULL
; p
= p
->next
);
268 pthread_mutex_unlock(&_lu_worklist_lock
);
272 lu_async_call_cancel(mach_port_t p
)
274 _lu_async_request_t
*req
;
276 req
= _lu_worklist_remove(p
);
277 if (req
!= NULL
) _lu_free_request(req
);
278 else if (p
!= MACH_PORT_NULL
) mach_port_destroy(mach_task_self(), p
);
281 static _lu_async_request_t
*
282 _lu_create_request(uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
284 _lu_async_request_t
*r
;
285 kern_return_t status
;
287 if (_lu_port
== MACH_PORT_NULL
) return NULL
;
289 r
= (_lu_async_request_t
*)calloc(1, sizeof(_lu_async_request_t
));
290 if (r
== NULL
) return NULL
;
292 status
= mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE
, &(r
->reply_port
));
293 if (status
!= KERN_SUCCESS
)
299 r
->retry
= MAX_LOOKUP_ATTEMPTS
;
301 r
->context
= context
;
302 r
->callback
= callback
;
305 r
->request_buffer
= malloc(len
* BYTES_PER_XDR_UNIT
);
306 memcpy(r
->request_buffer
, buf
, len
* BYTES_PER_XDR_UNIT
);
307 r
->request_buffer_len
= len
;
315 lu_async_start(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
, void *callback
, void *context
)
317 _lu_async_request_t
*r
;
318 kern_return_t status
;
321 if (p
== NULL
) return KERN_FAILURE
;
325 if (!_lu_running()) return KERN_FAILURE
;
327 /* Make a request struct to keep track */
328 r
= _lu_create_request(proc
, buf
, len
, callback
, context
);
329 if (r
== NULL
) return KERN_FAILURE
;
331 status
= MIG_SERVER_DIED
;
332 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
334 /* send to lookupd */
335 status
= _lu_async_send(r
);
338 if (status
!= KERN_SUCCESS
)
344 /* Add request to worklist */
345 _lu_worklist_append(r
);
352 lu_async_send(mach_port_t
*p
, uint32_t proc
, const char *buf
, uint32_t len
)
354 return lu_async_start(p
, proc
, buf
, len
, NULL
, NULL
);
358 lu_async_handle_reply(void *msg
, char **buf
, uint32_t *len
, void **callback
, void **context
)
361 _lu_async_request_t
*req
;
362 kern_return_t status
;
364 boolean_t msgh_simple
;
366 if (msg
== NULL
) return -1;
367 r
= (_lu_reply_msg_t
*)msg
;
369 /* If reply status was an error, resend */
370 if (r
->head
.msgh_id
!= LU_MESSAGE_REPLY_ID
)
372 if (r
->head
.msgh_id
== MACH_NOTIFY_SEND_ONCE
)
374 /* if MiG server (lookupd) died */
375 req
= _lu_worklist_find(r
->head
.msgh_local_port
);
376 if (req
== NULL
) return -1;
378 status
= MIG_SERVER_DIED
;
379 for (retry
= 0; (status
== MIG_SERVER_DIED
) && (retry
< MAX_LOOKUP_ATTEMPTS
); retry
++)
381 /* send to lookupd */
382 status
= _lu_async_send(req
);
385 if (status
!= KERN_SUCCESS
) return -1;
387 return MIG_REPLY_MISMATCH
;
390 msgh_simple
= !(r
->head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
);
392 req
= _lu_worklist_remove(r
->head
.msgh_local_port
);
393 if (req
== NULL
) return -1;
395 *callback
= req
->callback
;
396 *context
= req
->context
;
397 _lu_free_request(req
);
399 if (msgh_simple
&& ((mig_reply_error_t
*) r
)->RetCode
!= KERN_SUCCESS
)
401 return ((mig_reply_error_t
*) r
)->RetCode
;
404 *buf
= r
->reply_data
.address
;
405 *len
= r
->reply_data
.size
;
411 _lookupd_xdr_dictionary(XDR
*inxdr
)
413 int i
, nkeys
, j
, nvals
;
417 if (!xdr_int(inxdr
, &nkeys
)) return NULL
;
419 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
422 l
->ni_proplist_len
= nkeys
;
423 l
->ni_proplist_val
= NULL
;
426 l
->ni_proplist_val
= (ni_property
*)calloc(nkeys
, sizeof(ni_property
));
429 for (i
= 0; i
< nkeys
; i
++)
432 if (!xdr_string(inxdr
, &key
, -1))
438 l
->ni_proplist_val
[i
].nip_name
= key
;
440 if (!xdr_int(inxdr
, &nvals
))
446 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_len
= nvals
;
449 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
= (ni_name
*)calloc(nvals
, sizeof(ni_name
));
452 for (j
= 0; j
< nvals
; j
++)
455 if (!xdr_string(inxdr
, &val
, -1))
461 l
->ni_proplist_val
[i
].nip_val
.ni_namelist_val
[j
] = val
;
469 lookupd_query(ni_proplist
*l
, ni_proplist
***out
)
476 char databuf
[_LU_MAXLUSTRLEN
* BYTES_PER_XDR_UNIT
];
478 kern_return_t status
;
481 if (l
== NULL
) return 0;
482 if (out
== NULL
) return 0;
484 if (_lu_port
== MACH_PORT_NULL
) return 0;
486 status
= _lookup_link(_lu_port
, "query", &proc
);
487 if (status
!= KERN_SUCCESS
) return 0;
489 xdrmem_create(&outxdr
, databuf
, sizeof(databuf
), XDR_ENCODE
);
491 na
= l
->ni_proplist_len
;
493 /* Encode attribute count */
494 if (!xdr_int(&outxdr
, &na
))
496 xdr_destroy(&outxdr
);
500 for (i
= 0; i
< l
->ni_proplist_len
; i
++)
502 p
= &(l
->ni_proplist_val
[i
]);
504 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
506 xdr_destroy(&outxdr
);
510 if (!xdr_int(&outxdr
, &(p
->nip_val
.ni_namelist_len
)))
512 xdr_destroy(&outxdr
);
516 for (j
= 0; j
< p
->nip_val
.ni_namelist_len
; j
++)
518 s
= p
->nip_val
.ni_namelist_val
[j
];
519 if (!xdr_string(&outxdr
, &s
, _LU_MAXLUSTRLEN
))
521 xdr_destroy(&outxdr
);
530 n
= xdr_getpos(&outxdr
);
531 status
= _lookup_all(_lu_port
, proc
, (void *)databuf
, n
, &listbuf
, &datalen
);
532 if (status
!= KERN_SUCCESS
)
534 xdr_destroy(&outxdr
);
538 xdr_destroy(&outxdr
);
539 datalen
*= BYTES_PER_XDR_UNIT
;
540 xdrmem_create(&inxdr
, listbuf
, datalen
, XDR_DECODE
);
542 if (!xdr_int(&inxdr
, &n
))
554 *out
= (ni_proplist
**)malloc(n
* sizeof(ni_proplist
*));
556 for (i
= 0; i
< n
; i
++)
558 (*out
)[i
] = _lookupd_xdr_dictionary(&inxdr
);
563 vm_deallocate(mach_task_self(), (vm_address_t
)listbuf
, datalen
);
569 lookupd_make_query(char *cat
, char *fmt
, ...)
577 if (fmt
== NULL
) return NULL
;
578 if (fmt
[0] != 'k') return NULL
;
580 l
= (ni_proplist
*)malloc(sizeof(ni_proplist
));
588 l
->ni_proplist_val
= (ni_property
*)malloc(sizeof(ni_property
));
589 p
= &(l
->ni_proplist_val
[0]);
590 arg
= "_lookup_category";
591 p
->nip_name
= strdup(arg
);
592 p
->nip_val
.ni_namelist_len
= 1;
593 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
594 p
->nip_val
.ni_namelist_val
[0] = strdup(cat
);
596 l
->ni_proplist_len
++;
601 for (f
= fmt
; (*f
) != '\0'; f
++)
603 arg
= va_arg(ap
, char *);
606 l
->ni_proplist_val
= (ni_property
*)realloc(l
->ni_proplist_val
, (l
->ni_proplist_len
+ 1) * sizeof(ni_property
));
608 p
= &(l
->ni_proplist_val
[l
->ni_proplist_len
]);
609 p
->nip_name
= strdup(arg
);
610 p
->nip_val
.ni_namelist_len
= 0;
611 p
->nip_val
.ni_namelist_val
= NULL
;
613 l
->ni_proplist_len
++;
618 p
= &(l
->ni_proplist_val
[x
]);
619 if (p
->nip_val
.ni_namelist_len
== 0)
621 p
->nip_val
.ni_namelist_val
= (ni_name
*)malloc(sizeof(ni_name
));
625 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
));
627 p
->nip_val
.ni_namelist_val
[p
->nip_val
.ni_namelist_len
] = strdup(arg
);
628 p
->nip_val
.ni_namelist_len
++;
637 ni_property_merge(ni_property
*a
, ni_property
*b
)
641 if (a
== NULL
) return;
642 if (b
== NULL
) return;
644 for (j
= 0; j
< b
->nip_val
.ni_namelist_len
; j
++)
647 for (i
= 0; i
< (a
->nip_val
.ni_namelist_len
) && (addme
== 1); i
++)
649 if (!strcmp(a
->nip_val
.ni_namelist_val
[i
], b
->nip_val
.ni_namelist_val
[j
])) addme
= 0;
654 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
));
655 a
->nip_val
.ni_namelist_val
[a
->nip_val
.ni_namelist_len
] = strdup(b
->nip_val
.ni_namelist_val
[j
]);
656 a
->nip_val
.ni_namelist_len
++;
662 ni_proplist_merge(ni_proplist
*a
, ni_proplist
*b
)
667 if (a
== NULL
) return;
668 if (b
== NULL
) return;
670 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
673 for (wa
= 0; (wa
< a
->ni_proplist_len
) && (addme
== 1) ; wa
++)
675 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
)) addme
= 0;
679 a
->ni_proplist_val
= (ni_property
*)realloc(a
->ni_proplist_val
, (a
->ni_proplist_len
+ 1) * sizeof(ni_property
));
680 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_name
= strdup(b
->ni_proplist_val
[wb
].nip_name
);
681 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_len
= 0;
682 a
->ni_proplist_val
[a
->ni_proplist_len
].nip_val
.ni_namelist_val
= NULL
;
683 a
->ni_proplist_len
++;
687 for (wb
= 0; wb
< b
->ni_proplist_len
; wb
++)
689 for (wa
= 0; wa
< a
->ni_proplist_len
; wa
++)
691 if (!strcmp(a
->ni_proplist_val
[wa
].nip_name
, b
->ni_proplist_val
[wb
].nip_name
))
693 ni_property_merge(&(a
->ni_proplist_val
[wa
]), &(b
->ni_proplist_val
[wb
]));
700 _lu_data_free(void *x
)
702 struct _lu_data_s
*t
;
705 if (x
== NULL
) return;
707 t
= (struct _lu_data_s
*)x
;
709 for (i
= 0; i
< t
->icount
; i
++)
711 if ((t
->idata
[i
] != NULL
) && (t
->idata_destructor
[i
] != NULL
))
713 (*(t
->idata_destructor
[i
]))(t
->idata
[i
]);
717 t
->idata_destructor
[i
] = NULL
;
720 if (t
->ikey
!= NULL
) free(t
->ikey
);
723 if (t
->idata
!= NULL
) free(t
->idata
);
726 if (t
->idata_destructor
!= NULL
) free(t
->idata_destructor
);
727 t
->idata_destructor
= NULL
;
735 pthread_key_create(&_info_key
, _lu_data_free
);
739 static struct _lu_data_s
*
742 struct _lu_data_s
*libinfo_data
;
745 * Only one thread should create the _info_key
747 pthread_once(&_info_key_initialized
, _lu_data_init
);
749 /* Check if this thread already created libinfo_data */
750 libinfo_data
= pthread_getspecific(_info_key
);
751 if (libinfo_data
!= NULL
) return libinfo_data
;
753 libinfo_data
= (struct _lu_data_s
*)calloc(1, sizeof(struct _lu_data_s
));
755 pthread_setspecific(_info_key
, libinfo_data
);
760 _lu_data_create_key(unsigned int key
, void (*destructor
)(void *))
762 struct _lu_data_s
*libinfo_data
;
765 libinfo_data
= _lu_data_get();
767 for (i
= 0; i
< libinfo_data
->icount
; i
++)
769 if (libinfo_data
->ikey
[i
] == key
) return libinfo_data
->idata
[i
];
772 i
= libinfo_data
->icount
;
777 libinfo_data
->ikey
= (unsigned int *)malloc(sizeof(unsigned int));
778 libinfo_data
->idata
= (void **)malloc(sizeof(void *));
779 libinfo_data
->idata_destructor
= (void (**)(void *))malloc(sizeof(void (*)(void *)));
783 libinfo_data
->ikey
= (unsigned int *)realloc(libinfo_data
->ikey
, n
* sizeof(unsigned int));
784 libinfo_data
->idata
= (void **)realloc(libinfo_data
->idata
, n
* sizeof(void *));
785 libinfo_data
->idata_destructor
= (void (**)(void *))realloc(libinfo_data
->idata_destructor
, n
* sizeof(void (*)(void *)));
788 libinfo_data
->ikey
[i
] = key
;
789 libinfo_data
->idata
[i
] = NULL
;
790 libinfo_data
->idata_destructor
[i
] = destructor
;
791 libinfo_data
->icount
++;
797 _lu_data_index(unsigned int key
, struct _lu_data_s
*libinfo_data
)
801 if (libinfo_data
== NULL
) return (unsigned int)-1;
803 for (i
= 0; i
< libinfo_data
->icount
; i
++)
805 if (libinfo_data
->ikey
[i
] == key
) return i
;
808 return (unsigned int)-1;
812 _lu_data_set_key(unsigned int key
, void *data
)
814 struct _lu_data_s
*libinfo_data
;
817 libinfo_data
= _lu_data_get();
819 i
= _lu_data_index(key
, libinfo_data
);
820 if (i
== (unsigned int)-1) return;
822 libinfo_data
->idata
[i
] = data
;
826 _lu_data_get_key(unsigned int key
)
828 struct _lu_data_s
*libinfo_data
;
831 libinfo_data
= _lu_data_get();
833 i
= _lu_data_index(key
, libinfo_data
);
834 if (i
== (unsigned int)-1) return NULL
;
836 return libinfo_data
->idata
[i
];
840 _lu_data_free_vm_xdr(struct lu_thread_info
*tdata
)
842 if (tdata
== NULL
) return;
844 if (tdata
->lu_vm
!= NULL
)
846 vm_deallocate(mach_task_self(), (vm_address_t
)tdata
->lu_vm
, tdata
->lu_vm_length
);
849 tdata
->lu_vm_length
= 0;
850 tdata
->lu_vm_cursor
= 0;
852 if (tdata
->lu_xdr
!= NULL
)
854 xdr_destroy(tdata
->lu_xdr
);
856 tdata
->lu_xdr
= NULL
;
861 _lu_xdr_attribute(XDR
*xdr
, char **key
, char ***val
, unsigned int *count
)
863 unsigned int i
, j
, len
;
866 if (xdr
== NULL
) return -1;
867 if (key
== NULL
) return -1;
868 if (val
== NULL
) return -1;
869 if (count
== NULL
) return -1;
875 if (!xdr_string(xdr
, key
, -1)) return -1;
877 if (!xdr_int(xdr
, &len
))
884 if (len
== 0) return 0;
887 x
= (char **)calloc(len
+ 1, sizeof(char *));
890 for (i
= 0; i
< len
; i
++)
893 if (!xdr_string(xdr
, &s
, -1))
895 for (j
= 0; j
< i
; j
++) free(x
[j
]);
912 _lookup_link(mach_port_t server
, lookup_name name
, int *procno
)
914 kern_return_t status
;
915 security_token_t token
;
921 status
= MIG_SERVER_DIED
;
922 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
924 status
= _lookup_link_secure(server
, name
, procno
, &token
);
927 if (status
!= KERN_SUCCESS
)
930 syslog(LOG_DEBUG
, "pid %u _lookup_link %s status %u", getpid(), name
, status
);
935 if (token
.val
[0] != 0)
938 syslog(LOG_DEBUG
, "pid %u _lookup_link %s auth failure uid=%d", getpid(), name
, token
.val
[0]);
944 syslog(LOG_DEBUG
, "pid %u _lookup_link %s = %d", getpid(), name
, *procno
);
950 _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
)
952 kern_return_t status
;
953 security_token_t token
;
959 status
= MIG_SERVER_DIED
;
960 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
962 status
= _lookup_one_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
965 if (status
!= KERN_SUCCESS
)
968 syslog(LOG_DEBUG
, "pid %u _lookup_one %d status %u", getpid(), proc
, status
);
973 if (token
.val
[0] != 0)
976 syslog(LOG_DEBUG
, "pid %u _lookup_one %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
982 syslog(LOG_DEBUG
, "pid %u _lookup_one %d", getpid(), proc
);
988 _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
)
990 kern_return_t status
;
991 security_token_t token
;
997 status
= MIG_SERVER_DIED
;
998 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
1000 status
= _lookup_all_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
1003 if (status
!= KERN_SUCCESS
)
1006 syslog(LOG_DEBUG
, "pid %u _lookup_all %d status %u", getpid(), proc
, status
);
1011 if (token
.val
[0] != 0)
1014 syslog(LOG_DEBUG
, "pid %u _lookup_all %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1016 return KERN_FAILURE
;
1020 syslog(LOG_DEBUG
, "pid %u _lookup_all %d", getpid(), proc
);
1026 _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
)
1028 kern_return_t status
;
1029 security_token_t token
;
1035 status
= MIG_SERVER_DIED
;
1036 for (n
= 0; (status
== MIG_SERVER_DIED
) && (n
< MAX_LOOKUP_ATTEMPTS
); n
++)
1038 status
= _lookup_ooall_secure(server
, proc
, indata
, indataCnt
, outdata
, outdataCnt
, &token
);
1041 if (status
!= KERN_SUCCESS
)
1044 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d status %u", getpid(), proc
, status
);
1049 if (token
.val
[0] != 0)
1052 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d auth failure uid=%d", getpid(), proc
, token
.val
[0]);
1054 return KERN_FAILURE
;
1058 syslog(LOG_DEBUG
, "pid %u _lookup_ooall %d", getpid(), proc
);