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