update dev300-m57
[ooovba.git] / setup_native / scripts / source / getuid.c
blob101b46efe36b4ba87222a788820c96e7dcb6976a
1 #include <fcntl.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #include <dlfcn.h>
7 #ifdef _cplusplus
8 extern "C" {
9 #endif
11 #ifdef SOLARIS
13 #include <sys/systeminfo.h>
14 #include <strings.h>
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;}
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
28 int setuid (uid_t p) {return 0;}
29 int setgid (gid_t p) {return 0;}
31 /* This is to fool cpio and pkgmk */
32 int fstat(int fildes, struct stat *buf)
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)
42 buf->st_uid = 0; /* root */
43 buf->st_gid = 2; /* bin */
46 return ret;
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)
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");
58 if ((mode & S_IXUSR) == 0)
60 struct stat statbuf;
61 if (stat(path, &statbuf) == 0)
63 if ((statbuf.st_mode & S_IFDIR) != 0)
64 mode = (mode | S_IXUSR);
68 ret = (*p_chmod)(path, mode);
69 return ret;
74 /* This is to fool tar */
75 int fstatat64(int fildes, const char *path, struct stat64 *buf, int flag)
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)
85 buf->st_uid = 0; /* root */
86 buf->st_gid = 2; /* bin */
89 return ret;
91 #elif defined LINUX
93 uid_t getuid (void) {return 0;}
94 uid_t geteuid (void) {return 0;}
96 /* This is to fool tar */
97 #ifdef X86_64
98 int __lxstat(int n, const char *path, struct stat *buf)
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)
108 buf->st_uid = 0; /* root */
109 buf->st_gid = 0; /* root */
111 return ret;
113 #else
114 int __lxstat64(int n, const char *path, struct stat64 *buf)
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)
124 buf->st_uid = 0;
125 buf->st_gid = 0;
127 return ret;
129 #endif
130 #endif
132 #ifdef _cplusplus
134 #endif