1 #include <fcntl.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #include <dlfcn.h>
6 
7 #ifdef _cplusplus
8 extern "C" {
9 #endif
10 
11 #ifdef SOLARIS
12 
13 #include <sys/systeminfo.h>
14 #include <strings.h>
15 
16 int   chown  (const char *path, uid_t owner, gid_t group) {return 0;}
17 int   lchown (const char *path, uid_t owner, gid_t group) {return 0;}
18 int   fchown (int fildes, uid_t owner, gid_t group)       {return 0;}
19 
20 uid_t getuid  (void) {return 0;}
21 int stat(const char *path,  struct stat *buf);
22 #ifdef __notdef__
23 uid_t geteuid (void) {return 0;}
24 gid_t getgid  (void) {return 0;}
25 gid_t getegid (void) {return 0;}
26 #endif
27 
28 int   setuid  (uid_t p)  {return 0;}
29 int   setgid  (gid_t p)  {return 0;}
30 
31 /* This is to fool cpio and pkgmk */
32 int fstat(int fildes, struct stat *buf)
33 {
34     int ret = 0;
35     static int (*p_fstat) (int fildes, struct stat *buf) = NULL;
36     if (p_fstat == NULL)
37         p_fstat = (int (*)(int fildes, struct stat *buf))
38             dlsym (RTLD_NEXT, "fstat");
39     ret = (*p_fstat)(fildes, buf);
40     if (buf != NULL)
41     {
42         buf->st_uid = 0; /* root */
43         buf->st_gid = 2; /* bin */
44     }
45 
46     return ret;
47 }
48 
49 /* this is to fool mkdir, don't allow to remove owner execute right from directories */
50 int chmod(const char *path, mode_t mode)
51 {
52     int ret = 0;
53     static int (*p_chmod) (const char *path, mode_t mode) = NULL;
54     if (p_chmod == NULL)
55         p_chmod = (int (*)(const char *path, mode_t mode))
56             dlsym (RTLD_NEXT, "chmod");
57 
58 	if ((mode & S_IXUSR) == 0)
59 	{
60 		struct stat statbuf;
61 		if (stat(path, &statbuf) == 0)
62 		{
63 			if ((statbuf.st_mode & S_IFDIR) != 0)
64 				mode = (mode | S_IXUSR);
65 		}
66 	}
67 
68     ret = (*p_chmod)(path, mode);
69     return ret;
70 }
71 
72 
73 
74 /* This is to fool tar */
75 int fstatat64(int fildes, const char *path, struct stat64  *buf, int flag)
76 {
77     int ret = 0;
78     static int (*p_fstatat) (int fildes, const char *path, struct stat64 *buf, int flag) = NULL;
79     if (p_fstatat == NULL)
80         p_fstatat = (int (*)(int fildes, const char *path, struct stat64 *buf, int flag))
81             dlsym (RTLD_NEXT, "fstatat64");
82     ret = (*p_fstatat)(fildes, path, buf, flag);
83     if (buf != NULL)
84     {
85         buf->st_uid = 0; /* root */
86         buf->st_gid = 2; /* bin */
87     }
88 
89     return ret;
90 }
91 #elif  defined LINUX
92 
93 uid_t getuid  (void) {return 0;}
94 uid_t geteuid (void) {return 0;}
95 
96 /* This is to fool tar */
97 #ifdef X86_64
98 int __lxstat(int n, const char *path, struct stat *buf)
99 {
100     int ret = 0;
101     static int (*p_lstat) (int n, const char *path, struct stat *buf) = NULL;
102     if (p_lstat == NULL)
103         p_lstat = (int (*)(int n, const char *path, struct stat *buf))
104             dlsym (RTLD_NEXT, "__lxstat");
105     ret = (*p_lstat)(n, path, buf);
106     if (buf != NULL)
107     {
108         buf->st_uid = 0; /* root */
109         buf->st_gid = 0; /* root */
110     }
111     return ret;
112 }
113 #else
114 int __lxstat64(int n, const char *path, struct stat64 *buf)
115 {
116     int ret = 0;
117     static int (*p_lstat) (int n, const char *path, struct stat64 *buf) = NULL;
118     if (p_lstat == NULL)
119         p_lstat = (int (*)(int n, const char *path, struct stat64 *buf))
120             dlsym (RTLD_NEXT, "__lxstat64");
121     ret = (*p_lstat)(n, path, buf);
122     if (buf != NULL)
123     {
124         buf->st_uid = 0;
125         buf->st_gid = 0;
126     }
127     return ret;
128 }
129 #endif
130 #endif
131 
132 #ifdef _cplusplus
133 }
134 #endif
135 
136