ns_cache_door.c revision f3c070b2c81ee102c30722d6805ad034eb38803e
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 2006 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 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 _cache_trydoorcall(void *dptr, int *bufsize, int *actualsize); 2N/A * *dptr IN: points to arg buffer OUT: points to results buffer 2N/A * *bufsize IN: overall size of buffer OUT: overall size of buffer 2N/A * *actualsize 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 * 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 name service door cookie and 2N/A * that the file attached to the door is owned by root 2N/A * and readonly by user, group and other. 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 * mark this door descriptor as close on exec 2N/A * we should close doorfd because we just opened it 2N/A * someone else has clobbered fd 2N/A doorfd = -
1;
/* try and restart connection */ 2N/A * routine to check if server is already running