libc_dlopen.c revision 256281
178915Smsmith/*- 278915Smsmith * Copyright (c) 2011 Xin Li <delphij@FreeBSD.org> 378915Smsmith * All rights reserved. 478915Smsmith * 578915Smsmith * Redistribution and use in source and binary forms, with or without 678915Smsmith * modification, are permitted provided that the following conditions 778915Smsmith * are met: 878915Smsmith * 1. Redistributions of source code must retain the above copyright 978915Smsmith * notice, this list of conditions and the following disclaimer. 1078915Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1178915Smsmith * notice, this list of conditions and the following disclaimer in the 1278915Smsmith * documentation and/or other materials provided with the distribution. 1378915Smsmith * 1478915Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1578915Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1678915Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1778915Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1878915Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1978915Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2078915Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2178915Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2278915Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2378915Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2478915Smsmith * SUCH DAMAGE. 2578915Smsmith * 2678915Smsmith * $FreeBSD: stable/10/lib/libc/gen/libc_dlopen.c 228843 2011-12-23 15:00:37Z cperciva $ 2778915Smsmith */ 2878915Smsmith 2978915Smsmith#include <sys/cdefs.h> 3078915Smsmith__FBSDID("$FreeBSD: stable/10/lib/libc/gen/libc_dlopen.c 228843 2011-12-23 15:00:37Z cperciva $"); 3178915Smsmith 3278915Smsmith#include <dlfcn.h> 3378915Smsmith#include <stddef.h> 3478915Smsmith#include <unistd.h> 3578915Smsmith 3678915Smsmith#include "libc_private.h" 3778915Smsmith 3878915Smsmith/* 3978915Smsmith * Whether we want to restrict dlopen()s. 4078915Smsmith */ 4178915Smsmithstatic int __libc_restricted_mode = 0; 4278915Smsmith 4378915Smsmithvoid * 4478915Smsmithlibc_dlopen(const char *path, int mode) 4578915Smsmith{ 4678915Smsmith 4778915Smsmith if (__libc_restricted_mode) { 4878915Smsmith _rtld_error("Service unavailable -- libc in restricted mode"); 4978915Smsmith return (NULL); 5078915Smsmith } else 5178915Smsmith return (dlopen(path, mode)); 5278915Smsmith} 5378915Smsmith 5478915Smsmithvoid 5578915Smsmith__FreeBSD_libc_enter_restricted_mode(void) 5678915Smsmith{ 5778915Smsmith 5878915Smsmith __libc_restricted_mode = 1; 5978915Smsmith return; 6078915Smsmith} 6178915Smsmith 6278915Smsmith