Reactos

[NET] Implement adding and deleting of network shares.

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