Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

478 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. sharegen.c
  5. Abstract:
  6. Implements a stub tool that is designed to run with NT-side
  7. upgrade code.
  8. Author:
  9. <full name> (<alias>) <date>
  10. Revision History:
  11. <alias> <date> <comments>
  12. --*/
  13. #include "pch.h"
  14. #define W95_ACCESS_READ 0x1
  15. #define W95_ACCESS_WRITE 0x2
  16. #define W95_ACCESS_CREATE 0x4
  17. #define W95_ACCESS_EXEC 0x8
  18. #define W95_ACCESS_DELETE 0x10
  19. #define W95_ACCESS_ATRIB 0x20
  20. #define W95_ACCESS_PERM 0x40
  21. #define W95_ACCESS_FINDFIRST 0x80
  22. #define W95_ACCESS_FULL 0xff
  23. #define W95_ACCESS_GROUP 0x8000
  24. #define W95_GENERIC_READ (W95_ACCESS_READ|W95_ACCESS_EXEC|W95_ACCESS_FINDFIRST)
  25. #define W95_GENERIC_WRITE (W95_ACCESS_FULL ^ W95_GENERIC_READ)
  26. #define W95_GENERIC_FULL (W95_ACCESS_FULL)
  27. #define W95_GENERIC_NONE 0
  28. #define SHI50F_RDONLY 0x0001
  29. #define SHI50F_FULL 0x0002
  30. #define SHI50F_DEPENDSON (SHI50F_RDONLY|SHI50F_FULL)
  31. #define SHI50F_ACCESSMASK (SHI50F_RDONLY|SHI50F_FULL)
  32. BOOL
  33. Init (
  34. VOID
  35. )
  36. {
  37. HINSTANCE hInstance;
  38. DWORD dwReason;
  39. PVOID lpReserved;
  40. //
  41. // Simulate DllMain
  42. //
  43. hInstance = GetModuleHandle (NULL);
  44. dwReason = DLL_PROCESS_ATTACH;
  45. lpReserved = NULL;
  46. //
  47. // Initialize DLL globals
  48. //
  49. if (!FirstInitRoutine (hInstance)) {
  50. return FALSE;
  51. }
  52. //
  53. // Initialize all libraries
  54. //
  55. if (!InitLibs (hInstance, dwReason, lpReserved)) {
  56. return FALSE;
  57. }
  58. //
  59. // Final initialization
  60. //
  61. if (!FinalInitRoutine ()) {
  62. return FALSE;
  63. }
  64. return TRUE;
  65. }
  66. VOID
  67. Terminate (
  68. VOID
  69. )
  70. {
  71. HINSTANCE hInstance;
  72. DWORD dwReason;
  73. PVOID lpReserved;
  74. //
  75. // Simulate DllMain
  76. //
  77. hInstance = GetModuleHandle (NULL);
  78. dwReason = DLL_PROCESS_DETACH;
  79. lpReserved = NULL;
  80. //
  81. // Call the cleanup routine that requires library APIs
  82. //
  83. FirstCleanupRoutine();
  84. //
  85. // Clean up all libraries
  86. //
  87. TerminateLibs (hInstance, dwReason, lpReserved);
  88. //
  89. // Do any remaining clean up
  90. //
  91. FinalCleanupRoutine();
  92. }
  93. VOID
  94. HelpAndExit (
  95. VOID
  96. )
  97. {
  98. wprintf (L"Command Line Syntax:\n\n"
  99. L"sharegen <sharename>\n\n"
  100. L"<sharename> - Specifies the share to create\n"
  101. );
  102. exit (-1);
  103. }
  104. VOID
  105. BuildMemDbTestData (
  106. VOID
  107. );
  108. BOOL
  109. SearchDomainsForUserAccounts (
  110. VOID
  111. );
  112. VOID
  113. DoCreateShares (
  114. VOID
  115. );
  116. INT
  117. __cdecl
  118. wmain (
  119. INT argc,
  120. WCHAR *argv[]
  121. )
  122. {
  123. INT i;
  124. PCWSTR ShareName = NULL;
  125. PCWSTR p;
  126. PCWSTR Path = L"C:\\TEMP";
  127. PCWSTR Remark = L"ShareGen test share";
  128. PCWSTR Password = L"";
  129. DWORD Members;
  130. GROWBUFFER NameList = GROWBUF_INIT;
  131. for (i = 1 ; i < argc ; i++) {
  132. if (argv[i][0] == '-' || argv[i][0] == '/') {
  133. switch (tolower (argv[i][1])) {
  134. case 'i':
  135. if (!argv[i][2] && (i + 1) < argc) {
  136. i++;
  137. p = argv[i];
  138. } else if (argv[i][2] == ':') {
  139. p = &argv[i][3];
  140. } else {
  141. HelpAndExit();
  142. }
  143. break;
  144. default:
  145. HelpAndExit();
  146. }
  147. } else {
  148. if (ShareName) {
  149. HelpAndExit();
  150. } else {
  151. ShareName = argv[i];
  152. }
  153. }
  154. }
  155. if (!ShareName) {
  156. HelpAndExit();
  157. }
  158. if (!Init()) {
  159. wprintf (L"Unable to initialize!\n");
  160. return 255;
  161. }
  162. //
  163. // Generate data as it would be generated during the report phase
  164. //
  165. BuildMemDbTestData();
  166. //
  167. // Call the routines that do migration based on memdb
  168. //
  169. SearchDomainsForUserAccounts();
  170. DoCreateShares();
  171. Terminate();
  172. return 0;
  173. }
  174. typedef struct {
  175. WCHAR UserName[64];
  176. DWORD Permissions;
  177. } USERATTRIBS, *PUSERATTRIBS;
  178. VOID
  179. pAddShare (
  180. PCWSTR ShareName,
  181. PCWSTR Remark,
  182. PCWSTR Path,
  183. DWORD AccessFlags,
  184. PCWSTR RoPassword, OPTIONAL
  185. PCWSTR RwPassword, OPTIONAL
  186. PUSERATTRIBS UserList OPTIONAL
  187. )
  188. {
  189. //
  190. // Add each field to memdb
  191. //
  192. MemDbSetValueEx (
  193. MEMDB_CATEGORY_NETSHARES,
  194. ShareName,
  195. MEMDB_FIELD_REMARK,
  196. Remark,
  197. 0,
  198. NULL
  199. );
  200. MemDbSetValueEx (
  201. MEMDB_CATEGORY_NETSHARES,
  202. ShareName,
  203. MEMDB_FIELD_PATH,
  204. Path,
  205. 0,
  206. NULL
  207. );
  208. if (UserList) {
  209. while (*UserList->UserName) {
  210. MemDbSetValueEx (
  211. MEMDB_CATEGORY_NETSHARES,
  212. ShareName,
  213. MEMDB_FIELD_ACCESS_LIST,
  214. UserList->UserName,
  215. UserList->Permissions,
  216. NULL
  217. );
  218. UserList++;
  219. }
  220. AccessFlags |= SHI50F_ACLS;
  221. }
  222. MemDbSetValueEx (
  223. MEMDB_CATEGORY_NETSHARES,
  224. ShareName,
  225. NULL,
  226. NULL,
  227. AccessFlags,
  228. NULL
  229. );
  230. if (RoPassword) {
  231. MemDbSetValueEx (
  232. MEMDB_CATEGORY_NETSHARES,
  233. ShareName,
  234. MEMDB_FIELD_RO_PASSWORD,
  235. RoPassword,
  236. 0,
  237. NULL
  238. );
  239. }
  240. if (RwPassword) {
  241. MemDbSetValueEx (
  242. MEMDB_CATEGORY_NETSHARES,
  243. ShareName,
  244. MEMDB_FIELD_RW_PASSWORD,
  245. RwPassword,
  246. 0,
  247. NULL
  248. );
  249. }
  250. }
  251. VOID
  252. pAddUserToList (
  253. IN OUT PGROWBUFFER List,
  254. IN PCWSTR UserName,
  255. IN DWORD Win9xAccessFlags
  256. )
  257. {
  258. PUSERATTRIBS User;
  259. User = (PUSERATTRIBS) GrowBuffer (List, sizeof (USERATTRIBS));
  260. if (!User) {
  261. wprintf (L"Can't alloc memory!\n");
  262. exit (-1);
  263. }
  264. StringCopyW (User->UserName, UserName);
  265. User->Permissions = Win9xAccessFlags;
  266. if (*UserName) {
  267. if (wcschr (UserName, L'\\')) {
  268. MemDbSetValueEx (
  269. MEMDB_CATEGORY_KNOWNDOMAIN,
  270. User->UserName,
  271. NULL,
  272. NULL,
  273. 0,
  274. NULL
  275. );
  276. } else {
  277. MemDbSetValueEx (
  278. MEMDB_CATEGORY_KNOWNDOMAIN,
  279. L"",
  280. !StringCompare (User->UserName, L"*") ? L"Everyone" : User->UserName,
  281. NULL,
  282. 0,
  283. NULL
  284. );
  285. }
  286. }
  287. }
  288. VOID
  289. pAddShareLevelShare (
  290. IN PCWSTR ShareName,
  291. IN PCWSTR Remark,
  292. IN PCWSTR Path,
  293. IN DWORD Win9xAccessFlags,
  294. IN PCWSTR RoPassword, OPTIONAL
  295. IN PCWSTR RwPassword
  296. )
  297. {
  298. //
  299. // Add the share to memdb
  300. //
  301. pAddShare (
  302. ShareName,
  303. Remark,
  304. Path,
  305. Win9xAccessFlags,
  306. RoPassword,
  307. RwPassword,
  308. NULL
  309. );
  310. }
  311. VOID
  312. pAddUserLevelShare (
  313. IN PCWSTR ShareName,
  314. IN PCWSTR Remark,
  315. IN PCWSTR Path,
  316. IN PCWSTR UserMultiSz
  317. )
  318. {
  319. GROWBUFFER List = GROWBUF_INIT;
  320. MULTISZ_ENUM e;
  321. PWSTR p;
  322. DWORD Win9xAccessFlags;
  323. PWSTR DupStr;
  324. PCWSTR q;
  325. DupStr = DuplicateText (UserMultiSz);
  326. p = wcschr (DupStr, L'|');
  327. while (p) {
  328. *p = 0;
  329. p = wcschr (p + 1, L'|');
  330. }
  331. //
  332. // Convert multi-sz of user names (with optional attributes)
  333. // into simple structure
  334. //
  335. q = DupStr;
  336. while (*q) {
  337. p = wcschr (q, L'=');
  338. if (p) {
  339. *p = 0;
  340. p++;
  341. Win9xAccessFlags = _wtoi (p);
  342. } else {
  343. p = (PWSTR) q;
  344. Win9xAccessFlags = 0;
  345. }
  346. pAddUserToList (&List, q, Win9xAccessFlags);
  347. q = GetEndOfStringW (p) + 1;
  348. }
  349. pAddUserToList (&List, L"", 0);
  350. //
  351. // Add the share to memdb
  352. //
  353. pAddShare (
  354. ShareName,
  355. Remark,
  356. Path,
  357. 0,
  358. NULL,
  359. NULL,
  360. (PUSERATTRIBS) List.Buf
  361. );
  362. FreeGrowBuffer (&List);
  363. FreeText (DupStr);
  364. }
  365. VOID
  366. BuildMemDbTestData (
  367. VOID
  368. )
  369. {
  370. WCHAR AccessStr[1024];
  371. #if 0
  372. pAddShareLevelShare (L"TestRO", L"sharegen test", L"c:\\temp", SHI50F_RDONLY, NULL, NULL);
  373. pAddShareLevelShare (L"TestRW", L"sharegen test", L"c:\\temp", SHI50F_FULL, NULL, NULL);
  374. pAddShareLevelShare (L"TestNone", L"sharegen test", L"c:\\temp", 0, NULL, NULL);
  375. wsprintfW (AccessStr, L"read=%u|write=%u|all=%u|mrnone=0|", W95_GENERIC_READ, W95_GENERIC_WRITE, W95_GENERIC_FULL);
  376. pAddUserLevelShare (L"User1", L"remark", L"c:\\temp", AccessStr);
  377. #endif
  378. wsprintfW (AccessStr, L"*=%u|", 0xb7);
  379. pAddUserLevelShare (L"User2", L"remark", L"c:\\temp", AccessStr);
  380. }