2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * This is cloned from _nsc_trydoorcall used by the nscd client. 2N/A * Routine that actually performs the door call. 2N/A * Note that we cache a file descriptor. We do 2N/A * the following to prevent disasters: 2N/A * 1) Never use 0, 1 or 2; if we get this from the open 2N/A * we dup it upwards. 2N/A * 2) Set the close on exec flags so descriptor remains available 2N/A * to child processes. 2N/A * 3) Verify that the door is still the same one we had before 2N/A * by using door_info on the client side. 2N/A * Note that we never close the file descriptor if it isn't one 2N/A * we allocated; we check this with door info. The rather tricky 2N/A * logic is designed to be fast in the normal case (fd is already 2N/A * allocated and is ok) while handling the case where the application 2N/A * closed it underneath us or where the nscd dies or re-execs itself 2N/A * and we're a multi-threaded application. Note that we cannot protect 2N/A * the application if it closes the fd and it is multi-threaded. 2N/A * int __call_labeld(label_door_op **dptr, int *ndata, int *adata); 2N/A * *dptr IN: points to arg buffer OUT: points to results buffer 2N/A * *ndata IN: overall size of buffer OUT: overall size of buffer 2N/A * *adata IN: size of call data OUT: size of return data 2N/A * Note that *dptr may change if provided space as defined by *bufsize is 2N/A * inadequate. In this case the door call mmaps more space and places 2N/A * the answer there and sets dptr to contain a pointer to the space, which 2N/A * should be freed with munmap. 2N/A * Returns 0 if the door call reached the server, -1 if contact was not made. 2N/A int busy = 0;
/* number of busy loops */ 2N/A * the first time in we try and open and validate the door. 2N/A * the validations are that the door must have been 2N/A * created with the label service door cookie and 2N/A * that it has the same door ID. If any of these 2N/A * validations fail we refuse to use the door. 2N/A * dup up the file descriptor if we have 0 - 2 2N/A while (
doorfd <
3) {
/* we have a reserved fd */ 2N/A * we should close doorfd because we just opened it 2N/A * don't close it - someone else has clobbered fd 2N/A doorfd = -
1;
/* try and restart connection */ 2N/A /* adjust backoff */ 2N/A (
void)
printf(
"\tNo data returned, size = %lu, dptr = %p\n",
2N/A (
void)
printf(
"call buf = %x, buf size = %d, call size = %d\n",
2N/A (
void)
printf(
"retn buf = %x, buf size = %d, retn size = %d\n",
2N/A}
/* __call_labeld */