libc_dlopen.c revision 228843
1212795Sdim/*-
2212795Sdim * Copyright (c) 2011 Xin Li <delphij@FreeBSD.org>
3212795Sdim * All rights reserved.
4212795Sdim *
5212795Sdim * Redistribution and use in source and binary forms, with or without
6212795Sdim * modification, are permitted provided that the following conditions
7212795Sdim * are met:
8212795Sdim * 1. Redistributions of source code must retain the above copyright
9212795Sdim *    notice, this list of conditions and the following disclaimer.
10212795Sdim * 2. Redistributions in binary form must reproduce the above copyright
11212795Sdim *    notice, this list of conditions and the following disclaimer in the
12212795Sdim *    documentation and/or other materials provided with the distribution.
13212795Sdim *
14212795Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15212795Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16212795Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17212795Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18212795Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19212795Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20212795Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21212795Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22212795Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23212795Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24212795Sdim * SUCH DAMAGE.
25212795Sdim *
26212795Sdim * $FreeBSD: stable/9/lib/libc/gen/libc_dlopen.c 228843 2011-12-23 15:00:37Z cperciva $
27219077Sdim */
28219077Sdim
29219077Sdim#include <sys/cdefs.h>
30212795Sdim__FBSDID("$FreeBSD: stable/9/lib/libc/gen/libc_dlopen.c 228843 2011-12-23 15:00:37Z cperciva $");
31212795Sdim
32212795Sdim#include <dlfcn.h>
33212795Sdim#include <stddef.h>
34212795Sdim#include <unistd.h>
35212795Sdim
36212795Sdim#include "libc_private.h"
37212795Sdim
38212795Sdim/*
39212795Sdim * Whether we want to restrict dlopen()s.
40226633Sdim */
41263508Sdimstatic int __libc_restricted_mode = 0;
42212795Sdim
43212795Sdimvoid *
44212795Sdimlibc_dlopen(const char *path, int mode)
45212795Sdim{
46212795Sdim
47212795Sdim	if (__libc_restricted_mode) {
48212795Sdim		_rtld_error("Service unavailable -- libc in restricted mode");
49212795Sdim		return (NULL);
50212795Sdim	} else
51212795Sdim		return (dlopen(path, mode));
52212795Sdim}
53212795Sdim
54224145Sdimvoid
55224145Sdim__FreeBSD_libc_enter_restricted_mode(void)
56212795Sdim{
57224145Sdim
58224145Sdim	__libc_restricted_mode = 1;
59224145Sdim	return;
60224145Sdim}
61224145Sdim
62224145Sdim