45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER START
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * The contents of this file are subject to the terms of the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Common Development and Distribution License (the "License").
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You may not use this file except in compliance with the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * See the License for the specific language governing permissions
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * and limitations under the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * When distributing Covered Code, include this CDDL HEADER in each
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * If applicable, add the following below this CDDL HEADER, with the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * fields enclosed by brackets "[]" replaced with your own identifying
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * information: Portions Copyright [yyyy] [name of copyright owner]
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER END
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Use is subject to license terms.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* !DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * This is cloned from _nsc_trydoorcall used by the nscd client.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Routine that actually performs the door call.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Note that we cache a file descriptor. We do
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * the following to prevent disasters:
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * 1) Never use 0, 1 or 2; if we get this from the open
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * we dup it upwards.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * 2) Set the close on exec flags so descriptor remains available
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * to child processes.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * 3) Verify that the door is still the same one we had before
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * by using door_info on the client side.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Note that we never close the file descriptor if it isn't one
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * we allocated; we check this with door info. The rather tricky
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * logic is designed to be fast in the normal case (fd is already
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * allocated and is ok) while handling the case where the application
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * closed it underneath us or where the nscd dies or re-execs itself
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * and we're a multi-threaded application. Note that we cannot protect
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * the application if it closes the fd and it is multi-threaded.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * int __call_labeld(label_door_op **dptr, int *ndata, int *adata);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * *dptr IN: points to arg buffer OUT: points to results buffer
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * *ndata IN: overall size of buffer OUT: overall size of buffer
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * *adata IN: size of call data OUT: size of return data
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Note that *dptr may change if provided space as defined by *bufsize is
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * inadequate. In this case the door call mmaps more space and places
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * the answer there and sets dptr to contain a pointer to the space, which
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * should be freed with munmap.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Returns 0 if the door call reached the server, -1 if contact was not made.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk__call_labeld(labeld_data_t **dptr, size_t *ndata, size_t *adata)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * the first time in we try and open and validate the door.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * the validations are that the door must have been
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * created with the label service door cookie and
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * that it has the same door ID. If any of these
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * validations fail we refuse to use the door.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * dup up the file descriptor if we have 0 - 2
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * to avoid problems with shells stdin/out/err
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk while (i--)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk while (i--)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * mark this door descriptor as close on exec
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * we should close doorfd because we just opened it
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\tuid = %d, gid = %d, mode = %o\n", st.st_uid,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\toutstanding requests = %d\n", st.st_nlink-1);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t procedure = %llx\n", real_door.di_proc);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t cookie = %llx\n", real_door.di_data);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t id = %llx\n", real_door.di_uniquifier);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
b30a53d02d9bc370d76b8125a98e34311c768b5eRichard Lowe (my_door.di_uniquifier != real_door.di_uniquifier)) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * don't close it - someone else has clobbered fd
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) sprintf(door_name, "%s%s", DOOR_PATH, DOOR_NAME);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\tuid = %d, gid = %d, mode = %o\n", st.st_uid,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\toutstanding requests = %d\n", st.st_nlink-1);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t procedure = %llx\n", my_door.di_proc);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t attributes = %x\n", my_door.di_attributes);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\t\t id = %llx\n", my_door.di_uniquifier);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /* adjust backoff */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk /*LINTED*/
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\tNo data returned, size = %lu, dptr = %p\n",
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("call buf = %x, buf size = %d, call size = %d\n",
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("retn buf = %x, buf size = %d, retn size = %d\n",
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk (void) printf("\treply status = %d\n", (*dptr)->param.aret.ret);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk#endif /* DEBUG */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk} /* __call_labeld */