-
Notifications
You must be signed in to change notification settings - Fork 24
/
nfs-win.c
115 lines (99 loc) · 2.76 KB
/
nfs-win.c
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
#include <stdarg.h>
#include <stdio.h>
#include <pwd.h>
#include <unistd.h>
#define EXEC_ARGS \
"--foreground", \
"--rellinks", \
"--fsname=NFS" \
#if 0
#define execle pr_execl
static void pr_execl(const char *path, ...)
{
va_list ap;
const char *arg;
va_start(ap, path);
fprintf(stderr, "%s\n", path);
while (0 != (arg = va_arg(ap, const char *)))
fprintf(stderr, " %s\n", arg);
va_end(ap);
}
#endif
int main(int argc, char *argv[])
{
static const char *execname = "/bin/fuse-nfs.exe";
static const char *environ[] =
{
"PATH=/bin",
"CYGFUSE=WinFsp",
0
};
struct passwd *passwd;
char uidmap[32], gidmap[32], nfsuidmap[32], nfsgidmap[32], volpfx[256], remote[256];
char *locuser, *nfsuid, *nfsgid, *hostpath, *p;
if (3 != argc)
return 2;
snprintf(volpfx, sizeof volpfx, "--VolumePrefix=%s", argv[1]);
/* translate backslash to forward slash */
for (p = argv[1]; *p; p++)
if ('\\' == *p)
*p = '/';
/* skip class name (\\nfs\) */
p = argv[1];
while ('/' == *p)
p++;
while (*p && '/' != *p)
p++;
while ('/' == *p)
p++;
/* parse instance name (syntax: [[locuser=]uid@]host\path) */
hostpath = p;
locuser = nfsuid = nfsgid = 0;
while (*p && '@' != *p && '/' != *p)
p++;
if ('@' == *p)
{
*p = '\0';
nfsuid = hostpath;
hostpath = p + 1;
p = nfsuid;
while (*p && '=' != *p)
p++;
if ('=' == *p)
{
*p = '\0';
locuser = nfsuid;
nfsuid = p + 1;
}
}
if (0 != nfsuid)
{
p = nfsuid;
while (*p && '.' != *p)
p++;
if ('.' == *p)
{
*p = '\0';
nfsgid = p + 1;
}
}
snprintf(uidmap, sizeof uidmap, "--uid=11"); /* Authenticated Users */
snprintf(gidmap, sizeof gidmap, "--gid=65792"); /* Everyone */
if (0 != locuser)
{
/* get uid/gid from local user name */
passwd = getpwnam(locuser);
if (0 != passwd)
{
snprintf(uidmap, sizeof uidmap, "--uid=%d", passwd->pw_uid);
snprintf(gidmap, sizeof gidmap, "--gid=%d", passwd->pw_gid);
}
}
snprintf(nfsuidmap, sizeof nfsuidmap, "--fusenfs_uid=%s", nfsuid ? nfsuid : "65534");
snprintf(nfsgidmap, sizeof nfsgidmap, "--fusenfs_gid=%s", nfsgid ? nfsgid : "65534");
snprintf(remote, sizeof remote, "nfs://%s", hostpath);
execle(execname,
execname, EXEC_ARGS, uidmap, gidmap, nfsuidmap, nfsgidmap, volpfx, "-n", remote, "-m", argv[2], (void *)0,
environ);
return 1;
}