1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
#include "mph.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <glib.h>
int wifexited (int status)
{
return WIFEXITED (status);
}
int wexitstatus (int status)
{
return WEXITSTATUS (status);
}
int wifsignaled (int status)
{
return WIFSIGNALED (status);
}
int wtermsig (int status)
{
return WTERMSIG (status);
}
int wifstopped (int status)
{
return WIFSTOPPED (status);
}
int wstopsig (int status)
{
return WSTOPSIG (status);
}
int helper_Mono_Posix_Stat(const char *filename, int dereference,
int *device,
int *inode,
int *mode,
int *nlinks,
int *uid,
int *gid,
int *rdev,
gint64 *size,
gint64 *blksize,
gint64 *blocks,
gint64 *atime,
gint64 *mtime,
gint64 *ctime
) {
int ret;
struct stat buf;
if (!dereference)
ret = stat(filename, &buf);
else
ret = lstat(filename, &buf);
if (ret) return ret;
*device = buf.st_dev;
*inode = buf.st_ino;
*mode = buf.st_mode;
*nlinks = buf.st_nlink;
*uid = buf.st_uid;
*gid = buf.st_gid;
*rdev = buf.st_rdev;
*size = buf.st_size;
*blksize = buf.st_blksize;
*blocks = buf.st_blocks;
*atime = buf.st_atime;
*mtime = buf.st_mtime;
*ctime = buf.st_ctime;
return 0;
}
const char *helper_Mono_Posix_GetUserName(int uid) {
struct passwd *p = getpwuid(uid);
if (p == NULL) return NULL;
return strdup (p->pw_name);
}
const char *helper_Mono_Posix_GetGroupName(int gid) {
struct group *p = getgrgid(gid);
if (p == NULL) return NULL;
return strdup (p->gr_name);
}
const char *helper_Mono_Posix_readdir(void *dir) {
struct dirent* e = readdir((DIR*) dir);
if (e == NULL) return NULL;
return strdup (e->d_name);
}
int helper_Mono_Posix_getpwnamuid (int mode, char *in_name, int in_uid,
char **account,
char **password,
int *uid,
int *gid,
char **name,
char **home,
char **shell
) {
struct passwd pw, *pwp;
char buf[4096];
int ret;
if (mode == 0)
ret = getpwnam_r (in_name, &pw, buf, 4096, &pwp);
else
ret = getpwuid_r (in_uid, &pw, buf, 4096, &pwp);
if (ret == 0 && pwp == NULL) {
// Don't know why this happens, but it does.
// ret == 0, errno == 0, but no record was found.
ret = ENOENT;
}
if (ret) {
*account = NULL; // prevent marshalling unset pointers
*password = NULL;
*uid = 0;
*gid = 0;
*name = NULL;
*home = NULL;
*shell = NULL;
return ret;
}
*account = pwp->pw_name;
*password = pwp->pw_passwd;
*uid = pwp->pw_uid;
*gid = pwp->pw_gid;
*name = pwp->pw_gecos;
*home = pwp->pw_dir;
*shell = pwp->pw_shell;
return 0;
}
|