1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <fcntl.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <dlfcn.h>
27
28 #ifdef _cplusplus
29 extern "C" {
30 #endif
31
32 #ifdef SOLARIS
33
34 #include <sys/systeminfo.h>
35 #include <strings.h>
36
chown(const char * path,uid_t owner,gid_t group)37 int chown (const char *path, uid_t owner, gid_t group) {return 0;}
lchown(const char * path,uid_t owner,gid_t group)38 int lchown (const char *path, uid_t owner, gid_t group) {return 0;}
fchown(int fildes,uid_t owner,gid_t group)39 int fchown (int fildes, uid_t owner, gid_t group) {return 0;}
40
getuid(void)41 uid_t getuid (void) {return 0;}
42 int stat(const char *path, struct stat *buf);
43 #ifdef __notdef__
geteuid(void)44 uid_t geteuid (void) {return 0;}
getgid(void)45 gid_t getgid (void) {return 0;}
getegid(void)46 gid_t getegid (void) {return 0;}
47 #endif
48
setuid(uid_t p)49 int setuid (uid_t p) {return 0;}
setgid(gid_t p)50 int setgid (gid_t p) {return 0;}
51
52 /* This is to fool cpio and pkgmk */
fstat(int fildes,struct stat * buf)53 int fstat(int fildes, struct stat *buf)
54 {
55 int ret = 0;
56 static int (*p_fstat) (int fildes, struct stat *buf) = NULL;
57 if (p_fstat == NULL)
58 p_fstat = (int (*)(int fildes, struct stat *buf))
59 dlsym (RTLD_NEXT, "fstat");
60 ret = (*p_fstat)(fildes, buf);
61 if (buf != NULL)
62 {
63 buf->st_uid = 0; /* root */
64 buf->st_gid = 2; /* bin */
65 }
66
67 return ret;
68 }
69
70 /* this is to fool mkdir, don't allow to remove owner execute right from directories */
chmod(const char * path,mode_t mode)71 int chmod(const char *path, mode_t mode)
72 {
73 int ret = 0;
74 static int (*p_chmod) (const char *path, mode_t mode) = NULL;
75 if (p_chmod == NULL)
76 p_chmod = (int (*)(const char *path, mode_t mode))
77 dlsym (RTLD_NEXT, "chmod");
78
79 if ((mode & S_IXUSR) == 0)
80 {
81 struct stat statbuf;
82 if (stat(path, &statbuf) == 0)
83 {
84 if ((statbuf.st_mode & S_IFDIR) != 0)
85 mode = (mode | S_IXUSR);
86 }
87 }
88
89 ret = (*p_chmod)(path, mode);
90 return ret;
91 }
92
93
94
95 /* This is to fool tar */
fstatat64(int fildes,const char * path,struct stat64 * buf,int flag)96 int fstatat64(int fildes, const char *path, struct stat64 *buf, int flag)
97 {
98 int ret = 0;
99 static int (*p_fstatat) (int fildes, const char *path, struct stat64 *buf, int flag) = NULL;
100 if (p_fstatat == NULL)
101 p_fstatat = (int (*)(int fildes, const char *path, struct stat64 *buf, int flag))
102 dlsym (RTLD_NEXT, "fstatat64");
103 ret = (*p_fstatat)(fildes, path, buf, flag);
104 if (buf != NULL)
105 {
106 buf->st_uid = 0; /* root */
107 buf->st_gid = 2; /* bin */
108 }
109
110 return ret;
111 }
112 #elif defined LINUX
113
114 uid_t getuid (void) {return 0;}
115 uid_t geteuid (void) {return 0;}
116 int setgid (gid_t p) {return 0;}
117
118 /* This is to fool epm, tar, dpkg, et.al. into thinking we are root */
119 #ifdef X86_64
120 int __lxstat(int n, const char *path, struct stat *buf)
121 {
122 int ret = 0;
123 static int (*p_lstat) (int n, const char *path, struct stat *buf) = NULL;
124 if (p_lstat == NULL)
125 p_lstat = (int (*)(int n, const char *path, struct stat *buf))
126 dlsym (RTLD_NEXT, "__lxstat");
127 ret = (*p_lstat)(n, path, buf);
128 if (buf != NULL)
129 {
130 buf->st_uid = 0; /* root */
131 buf->st_gid = 0; /* root */
132 }
133 return ret;
134 }
135 #else
136 int __lxstat64(int n, const char *path, struct stat64 *buf)
137 {
138 int ret = 0;
139 static int (*p_lstat) (int n, const char *path, struct stat64 *buf) = NULL;
140 if (p_lstat == NULL)
141 p_lstat = (int (*)(int n, const char *path, struct stat64 *buf))
142 dlsym (RTLD_NEXT, "__lxstat64");
143 ret = (*p_lstat)(n, path, buf);
144 if (buf != NULL)
145 {
146 buf->st_uid = 0;
147 buf->st_gid = 0;
148 }
149 return ret;
150 }
151 #endif
152 #endif
153
154 #ifdef _cplusplus
155 }
156 #endif
157
158