1313010Sdes/*
2313010Sdes * Copyright (c) 2016 Darren Tucker.  All rights reserved.
3313010Sdes *
4313010Sdes * Permission to use, copy, modify, and distribute this software for any
5313010Sdes * purpose with or without fee is hereby granted, provided that the above
6313010Sdes * copyright notice and this permission notice appear in all copies.
7313010Sdes *
8313010Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9313010Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10313010Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11313010Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12313010Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13313010Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14313010Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15313010Sdes */
16313010Sdes
17313010Sdes#include "includes.h"
18313010Sdes
19313010Sdes#include <sys/types.h>
20313010Sdes#if defined(HAVE_SYS_PRCTL_H)
21313010Sdes#include <sys/prctl.h>	/* For prctl() and PR_SET_DUMPABLE */
22313010Sdes#endif
23313010Sdes#ifdef HAVE_PRIV_H
24313010Sdes#include <priv.h> /* For setpflags() and __PROC_PROTECT  */
25313010Sdes#endif
26313010Sdes#include <stdarg.h>
27313010Sdes
28313010Sdes#include "log.h"
29313010Sdes
30313010Sdesvoid
31313010Sdesplatform_disable_tracing(int strict)
32313010Sdes{
33313010Sdes#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
34313010Sdes	/* Disable ptrace on Linux without sgid bit */
35313010Sdes	if (prctl(PR_SET_DUMPABLE, 0) != 0 && strict)
36313010Sdes		fatal("unable to make the process undumpable");
37313010Sdes#endif
38313010Sdes#if defined(HAVE_SETPFLAGS) && defined(__PROC_PROTECT)
39313010Sdes	/* On Solaris, we should make this process untraceable */
40313010Sdes	if (setpflags(__PROC_PROTECT, 1) != 0 && strict)
41313010Sdes		fatal("unable to make the process untraceable");
42313010Sdes#endif
43313010Sdes}
44