10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1618Srie * Common Development and Distribution License (the "License"). 6*1618Srie * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1618Srie 220Sstevel@tonic-gate /* 23*1618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <unistd.h> 300Sstevel@tonic-gate #include <strings.h> 310Sstevel@tonic-gate #include <limits.h> 320Sstevel@tonic-gate #include <dlfcn.h> 330Sstevel@tonic-gate #include "_conv.h" 340Sstevel@tonic-gate #include "lddstub_msg.h" 350Sstevel@tonic-gate 360Sstevel@tonic-gate static int 370Sstevel@tonic-gate originlddstub(char *buffer, const char *orgfile) 380Sstevel@tonic-gate { 390Sstevel@tonic-gate int len; 400Sstevel@tonic-gate 410Sstevel@tonic-gate if (dlinfo(RTLD_SELF, RTLD_DI_ORIGIN, (void *)buffer) == -1) 420Sstevel@tonic-gate return (-1); 430Sstevel@tonic-gate if (strlcat(buffer, orgfile, PATH_MAX) >= PATH_MAX) 440Sstevel@tonic-gate return (-1); 450Sstevel@tonic-gate if ((len = resolvepath(buffer, buffer, (PATH_MAX - 1))) == -1) 460Sstevel@tonic-gate return (-1); 470Sstevel@tonic-gate buffer[len] = '\0'; 48*1618Srie if (access(buffer, X_OK) == -1) 490Sstevel@tonic-gate return (-1); 500Sstevel@tonic-gate 51*1618Srie return (1); 520Sstevel@tonic-gate } 530Sstevel@tonic-gate 54*1618Srie static char orgstub[PATH_MAX], orgstub64[PATH_MAX]; 55*1618Srie static int orgflag, orgflag64; 56*1618Srie 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Determine what lddstub to run. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate const char * 610Sstevel@tonic-gate conv_lddstub(int class) 620Sstevel@tonic-gate { 630Sstevel@tonic-gate const char *stub; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Establish defaults. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate if (class == ELFCLASS32) 690Sstevel@tonic-gate stub = MSG_ORIG(MSG_PTH_LDDSTUB); 700Sstevel@tonic-gate else 710Sstevel@tonic-gate stub = MSG_ORIG(MSG_PTH_LDDSTUB_64); 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Provided we're not secure, determine lddstub's location from our 750Sstevel@tonic-gate * own origin. 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate if (geteuid()) { 780Sstevel@tonic-gate if ((class == ELFCLASS32) && (orgflag != -1)) { 790Sstevel@tonic-gate if (orgflag == 0) { 800Sstevel@tonic-gate if ((orgflag = originlddstub(orgstub, 810Sstevel@tonic-gate MSG_ORIG(MSG_ORG_LDDSTUB))) == -1) 820Sstevel@tonic-gate return (stub); 830Sstevel@tonic-gate } 840Sstevel@tonic-gate stub = (const char *)orgstub; 850Sstevel@tonic-gate } 860Sstevel@tonic-gate if ((class == ELFCLASS64) && (orgflag64 != -1)) { 870Sstevel@tonic-gate if (orgflag64 == 0) { 880Sstevel@tonic-gate if ((orgflag64 = originlddstub(orgstub64, 890Sstevel@tonic-gate MSG_ORIG(MSG_ORG_LDDSTUB_64))) == -1) 900Sstevel@tonic-gate return (stub); 910Sstevel@tonic-gate } 920Sstevel@tonic-gate stub = (const char *)orgstub64; 930Sstevel@tonic-gate } 940Sstevel@tonic-gate } 950Sstevel@tonic-gate return (stub); 960Sstevel@tonic-gate } 97