source: trunk/base/src/darwintracelib1.0/mkdir.c @ 136621

Last change on this file since 136621 was 117962, checked in by cal@…, 6 years ago

darwintrace: don't export symbols

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2005 Apple Inc. All rights reserved.
3 * Copyright (c) 2005-2006 Paul Guyot <pguyot@kallisys.net>,
4 * All rights reserved.
5 * Copyright (c) 2006-2013 The MacPorts Project
6 *
7 * $Id: darwintrace.c 112642 2013-10-28 18:59:19Z cal@macports.org $
8 *
9 * @APPLE_BSD_LICENSE_HEADER_START@
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1.  Redistributions of source code must retain the above copyright
16 *     notice, this list of conditions and the following disclaimer.
17 * 2.  Redistributions in binary form must reproduce the above copyright
18 *     notice, this list of conditions and the following disclaimer in the
19 *     documentation and/or other materials provided with the distribution.
20 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
21 *     its contributors may be used to endorse or promote products derived
22 *     from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
25 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * @APPLE_BSD_LICENSE_HEADER_END@
36 */
37
38#include "darwintrace.h"
39
40#include <errno.h>
41#include <sys/stat.h>
42#include <sys/syscall.h>
43#include <unistd.h>
44
45#if __DARWIN_64_BIT_INO_T
46#define LSTATSYSNUM SYS_lstat64
47#else
48#define LSTATSYSNUM SYS_lstat
49#endif
50
51/**
52 * Wrapper around \c mkdir(2) that prevents creation of directories outside of
53 * the sandbox. Will silently do nothing and return success for directories
54 * outside the sandbox that already exist.
55 */
56static int _dt_mkdir(const char *path, mode_t mode) {
57#define mkdir(x,y) syscall(SYS_mkdir, (x), (y))
58#define lstat(x,y) syscall(LSTATSYSNUM, (x), (y))
59        __darwintrace_setup();
60
61        int result = 0;
62
63        if (!__darwintrace_is_in_sandbox(path, DT_REPORT | DT_FOLLOWSYMS)) {
64                struct stat st;
65                if (-1 == lstat(path, &st) && errno == ENOENT) {
66                        // directory doesn't exist yet */
67                        errno = EACCES;
68                        result = -1;
69                }
70                // otherwise, leave result at 0 and return to indicate success
71        } else {
72                result = mkdir(path, mode);
73        }
74
75        debug_printf("mkdir(%s) = %d\n", path, result);
76
77        return result;
78#undef lstat
79#undef mkdir
80}
81
82DARWINTRACE_INTERPOSE(_dt_mkdir, mkdir);
Note: See TracBrowser for help on using the repository browser.