1228843Scperciva/*-
2228843Scperciva * Copyright (c) 2011 Xin Li <delphij@FreeBSD.org>
3228843Scperciva * All rights reserved.
4228843Scperciva *
5228843Scperciva * Redistribution and use in source and binary forms, with or without
6228843Scperciva * modification, are permitted provided that the following conditions
7228843Scperciva * are met:
8228843Scperciva * 1. Redistributions of source code must retain the above copyright
9228843Scperciva *    notice, this list of conditions and the following disclaimer.
10228843Scperciva * 2. Redistributions in binary form must reproduce the above copyright
11228843Scperciva *    notice, this list of conditions and the following disclaimer in the
12228843Scperciva *    documentation and/or other materials provided with the distribution.
13228843Scperciva *
14228843Scperciva * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15228843Scperciva * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16228843Scperciva * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17228843Scperciva * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18228843Scperciva * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19228843Scperciva * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20228843Scperciva * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21228843Scperciva * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22228843Scperciva * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23228843Scperciva * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24228843Scperciva * SUCH DAMAGE.
25228843Scperciva *
26228843Scperciva * $FreeBSD$
27228843Scperciva */
28228843Scperciva
29228843Scperciva#include <sys/cdefs.h>
30228843Scperciva__FBSDID("$FreeBSD$");
31228843Scperciva
32228843Scperciva#include <dlfcn.h>
33228843Scperciva#include <stddef.h>
34228843Scperciva#include <unistd.h>
35228843Scperciva
36228843Scperciva#include "libc_private.h"
37228843Scperciva
38228843Scperciva/*
39228843Scperciva * Whether we want to restrict dlopen()s.
40228843Scperciva */
41228843Scpercivastatic int __libc_restricted_mode = 0;
42228843Scperciva
43228843Scpercivavoid *
44228843Scpercivalibc_dlopen(const char *path, int mode)
45228843Scperciva{
46228843Scperciva
47228843Scperciva	if (__libc_restricted_mode) {
48228843Scperciva		_rtld_error("Service unavailable -- libc in restricted mode");
49228843Scperciva		return (NULL);
50228843Scperciva	} else
51228843Scperciva		return (dlopen(path, mode));
52228843Scperciva}
53228843Scperciva
54228843Scpercivavoid
55228843Scperciva__FreeBSD_libc_enter_restricted_mode(void)
56228843Scperciva{
57228843Scperciva
58228843Scperciva	__libc_restricted_mode = 1;
59228843Scperciva	return;
60228843Scperciva}
61228843Scperciva
62