tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[NET] Implement adding and deleting of network shares.
Eric Kohl
6 years ago
22df51ed
347a7478
+91
-6
1 changed file
expand all
collapse all
unified
split
base
applications
network
net
cmdShare.c
+91
-6
base/applications/network/net/cmdShare.c
···
95
95
INT argc,
96
96
WCHAR **argv)
97
97
{
98
98
-
PWSTR pShareName = NULL;
98
98
+
SHARE_INFO_2 ShareInfo;
99
99
+
PWSTR pszShareName = NULL;
100
100
+
PWSTR pszSharePath = NULL;
101
101
+
PWSTR ptr;
102
102
+
BOOL bDelete = FALSE;
103
103
+
INT len;
99
104
INT i, result = 0;
100
105
NET_API_STATUS Status;
101
106
102
107
i = 2;
103
103
-
if (argv[i][0] != L'/')
108
108
+
if (argc > 2 && argv[i][0] != L'/')
104
109
{
105
105
-
pShareName = argv[i];
110
110
+
ptr = wcschr(argv[i], L'=');
111
111
+
if (ptr != NULL)
112
112
+
{
113
113
+
if (ptr[1] != UNICODE_NULL)
114
114
+
{
115
115
+
len = wcslen(&ptr[i]);
116
116
+
pszSharePath = HeapAlloc(GetProcessHeap(),
117
117
+
HEAP_ZERO_MEMORY,
118
118
+
(len + 1) * sizeof(WCHAR));
119
119
+
if (pszSharePath == NULL)
120
120
+
{
121
121
+
// FIXME: Proper error code!
122
122
+
return 1;
123
123
+
}
124
124
+
125
125
+
wcscpy(pszSharePath, &ptr[1]);
126
126
+
}
127
127
+
128
128
+
len = ((INT_PTR)ptr - (INT_PTR)argv[i]) / sizeof(WCHAR);
129
129
+
pszShareName = HeapAlloc(GetProcessHeap(),
130
130
+
HEAP_ZERO_MEMORY,
131
131
+
(len + 1) * sizeof(WCHAR));
132
132
+
if (pszShareName == NULL)
133
133
+
{
134
134
+
// FIXME: Proper error code!
135
135
+
return 1;
136
136
+
}
137
137
+
138
138
+
wcsncpy(pszShareName, argv[i], len);
139
139
+
}
140
140
+
else
141
141
+
{
142
142
+
len = wcslen(argv[i]);
143
143
+
pszShareName = HeapAlloc(GetProcessHeap(),
144
144
+
HEAP_ZERO_MEMORY,
145
145
+
(len + 1) * sizeof(WCHAR));
146
146
+
if (pszShareName == NULL)
147
147
+
{
148
148
+
// FIXME: Proper error code!
149
149
+
return 1;
150
150
+
}
151
151
+
152
152
+
wcscpy(pszShareName, argv[i]);
153
153
+
}
154
154
+
106
155
i++;
107
156
}
108
157
···
117
166
PrintNetMessage(MSG_SHARE_HELP);
118
167
return 0;
119
168
}
169
169
+
else if (_wcsicmp(argv[i], L"/delete") == 0)
170
170
+
{
171
171
+
bDelete = TRUE;
172
172
+
}
120
173
}
121
174
122
122
-
if (pShareName == NULL)
175
175
+
printf("pszShareName: '%S'\n", pszShareName);
176
176
+
printf("pszSharePath: '%S'\n", pszSharePath);
177
177
+
178
178
+
if (pszShareName == NULL && pszSharePath == NULL)
123
179
{
124
180
Status = EnumerateShares();
125
181
ConPrintf(StdOut, L"Status: %lu\n", Status);
126
182
}
127
127
-
else
183
183
+
else if (pszShareName != NULL && pszSharePath == NULL)
128
184
{
129
129
-
Status = DisplayShare(pShareName);
185
185
+
if (bDelete == TRUE)
186
186
+
{
187
187
+
Status = NetShareDel(NULL,
188
188
+
pszShareName,
189
189
+
0);
190
190
+
}
191
191
+
else
192
192
+
{
193
193
+
Status = DisplayShare(pszShareName);
194
194
+
}
195
195
+
130
196
ConPrintf(StdOut, L"Status: %lu\n", Status);
131
197
}
198
198
+
else if (pszShareName != NULL && pszSharePath != NULL)
199
199
+
{
200
200
+
ZeroMemory(&ShareInfo, sizeof(SHARE_INFO_2));
201
201
+
ShareInfo.shi2_netname = pszShareName;
202
202
+
ShareInfo.shi2_path = pszSharePath;
203
203
+
204
204
+
Status = NetShareAdd(NULL,
205
205
+
2,
206
206
+
(LPBYTE)&ShareInfo,
207
207
+
NULL);
208
208
+
209
209
+
ConPrintf(StdOut, L"Status: %lu\n", Status);
210
210
+
}
211
211
+
212
212
+
if (pszSharePath != NULL)
213
213
+
HeapFree(GetProcessHeap(), 0, pszSharePath);
214
214
+
215
215
+
if (pszShareName != NULL)
216
216
+
HeapFree(GetProcessHeap(), 0, pszShareName);
132
217
133
218
return result;
134
219
}