Leaked source code of windows server 2003
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.

1043 lines
29 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1989 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: cmd.c
  7. //
  8. // Description:
  9. //
  10. // History:
  11. // Oct 1,1993. NarenG Created original version.
  12. //
  13. #include <client.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include "cmd.h"
  17. CHAR * pszTRUE = "TRUE";
  18. CHAR * pszFALSE = "FALSE";
  19. CHAR * pszUnlimited = "UNLIMITED";
  20. VOID
  21. PrintMessageAndExit(
  22. DWORD ids,
  23. CHAR * pchInsertString
  24. )
  25. {
  26. CHAR Error[10];
  27. CHAR MsgBuf[1000];
  28. DWORD cbMessage;
  29. LPSTR pszMessage = NULL;
  30. switch( ids )
  31. {
  32. case IDS_GENERAL_SYNTAX:
  33. case IDS_VOLUME_SYNTAX:
  34. case IDS_DIRECTORY_SYNTAX:
  35. case IDS_SERVER_SYNTAX:
  36. case IDS_FORKIZE_SYNTAX:
  37. case IDS_VOLUME_TOO_BIG:
  38. case IDS_SUCCESS:
  39. cbMessage = FormatMessageA(
  40. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  41. FORMAT_MESSAGE_FROM_HMODULE,
  42. NULL,
  43. (DWORD)ids,
  44. LANG_NEUTRAL,
  45. (LPSTR)&pszMessage,
  46. 128,
  47. NULL );
  48. break;
  49. case IDS_AMBIGIOUS_SWITCH_ERROR:
  50. case IDS_UNKNOWN_SWITCH_ERROR:
  51. case IDS_DUPLICATE_SWITCH_ERROR:
  52. cbMessage = FormatMessageA(
  53. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  54. FORMAT_MESSAGE_FROM_HMODULE |
  55. FORMAT_MESSAGE_IGNORE_INSERTS,
  56. NULL,
  57. (DWORD)ids,
  58. LANG_NEUTRAL,
  59. (LPSTR)&pszMessage,
  60. 128,
  61. NULL );
  62. if ( cbMessage > 0 )
  63. {
  64. sprintf( MsgBuf, pszMessage, pchInsertString );
  65. CharToOem( MsgBuf, MsgBuf );
  66. LocalFree( pszMessage );
  67. fprintf( stdout, MsgBuf );
  68. fprintf( stdout, "\n" );
  69. pszMessage = NULL;
  70. }
  71. exit( 0 );
  72. break;
  73. case IDS_API_ERROR:
  74. _itoa( (int)((ULONG_PTR)pchInsertString), Error, 10 );
  75. cbMessage = FormatMessageA(
  76. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  77. FORMAT_MESSAGE_FROM_HMODULE |
  78. FORMAT_MESSAGE_IGNORE_INSERTS,
  79. NULL,
  80. (DWORD)ids,
  81. LANG_NEUTRAL,
  82. (LPSTR)&pszMessage,
  83. 128,
  84. NULL );
  85. if ( cbMessage > 0 )
  86. {
  87. sprintf( MsgBuf, pszMessage, Error );
  88. CharToOem( MsgBuf, MsgBuf );
  89. fprintf( stdout, MsgBuf );
  90. fprintf( stdout, "\n" );
  91. LocalFree( pszMessage );
  92. pszMessage = NULL;
  93. }
  94. if ( ((LONG)((LONG_PTR)pchInsertString)) > 0 )
  95. {
  96. cbMessage = FormatMessageA(
  97. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  98. FORMAT_MESSAGE_FROM_SYSTEM,
  99. NULL,
  100. (LONG)((LONG_PTR)pchInsertString),
  101. LANG_NEUTRAL,
  102. (LPSTR)&pszMessage,
  103. 128,
  104. NULL );
  105. }
  106. if ( ((LONG)((LONG_PTR)pchInsertString)) < 0 )
  107. {
  108. cbMessage = FormatMessageA(
  109. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  110. FORMAT_MESSAGE_FROM_HMODULE,
  111. NULL,
  112. AFPERR_TO_STRINGID( (LONG)((LONG_PTR)pchInsertString) ),
  113. LANG_NEUTRAL,
  114. (LPSTR)&pszMessage,
  115. 128,
  116. NULL );
  117. }
  118. break;
  119. default:
  120. exit( 0 );
  121. }
  122. if (( cbMessage > 0 ) && (pszMessage != NULL ))
  123. {
  124. CharToOem( pszMessage, pszMessage );
  125. fprintf( stdout, pszMessage );
  126. fprintf( stdout, "\n" );
  127. LocalFree( pszMessage );
  128. }
  129. exit(0);
  130. }
  131. VOID
  132. DoVolumeAdd(
  133. CHAR * pchServer,
  134. CHAR * pchName,
  135. CHAR * pchPath,
  136. CHAR * pchPassword,
  137. CHAR * pchReadOnly,
  138. CHAR * pchGuestsAllowed,
  139. CHAR * pchMaxUses
  140. )
  141. {
  142. PAFP_DIRECTORY_INFO pAfpDirInfo;
  143. AFP_VOLUME_INFO AfpVolInfo;
  144. DWORD dwRetCode;
  145. AFP_SERVER_HANDLE hServer;
  146. WCHAR wchName[AFP_VOLNAME_LEN+1];
  147. WCHAR wchPassword[AFP_VOLPASS_LEN+1];
  148. WCHAR wchServer[CNLEN+3];
  149. LPWSTR lpwsPath;
  150. LPSTR lpDrivePath;
  151. DWORD dwParmNum = AFP_DIR_PARMNUM_PERMS;
  152. ZeroMemory( &AfpVolInfo, sizeof( AfpVolInfo ) );
  153. //
  154. // Check to see if the mandatory values are not supplied
  155. //
  156. if ( ( pchName == NULL ) || ( pchPath == NULL ) || ( *pchName == (CHAR)NULL)
  157. || ( *pchPath == (CHAR)NULL ) )
  158. PrintMessageAndExit( IDS_VOLUME_SYNTAX, NULL );
  159. mbstowcs(wchName, pchName, sizeof(wchName)/sizeof(wchName[0]));
  160. AfpVolInfo.afpvol_name = wchName;
  161. lpwsPath = LocalAlloc(LPTR, (strlen(pchPath) + 1) * sizeof(WCHAR));
  162. if (lpwsPath == NULL)
  163. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  164. lpDrivePath = LocalAlloc(LPTR, (CNLEN + 6 + 1));
  165. if (lpDrivePath == NULL)
  166. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  167. mbstowcs(lpwsPath, pchPath, strlen(pchPath)+1);
  168. AfpVolInfo.afpvol_path = lpwsPath;
  169. if ( pchServer )
  170. {
  171. if (*pchServer)
  172. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  173. else
  174. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  175. }
  176. if ( (pchPassword) && ( strlen( pchPassword ) > 0 ) )
  177. {
  178. mbstowcs(wchPassword, pchPassword, sizeof(wchPassword)/sizeof(WCHAR));
  179. AfpVolInfo.afpvol_password = wchPassword;
  180. }
  181. else
  182. AfpVolInfo.afpvol_password = NULL;
  183. if ( pchMaxUses )
  184. {
  185. if ( *pchMaxUses )
  186. {
  187. if (_strnicmp(pchMaxUses, pszUnlimited, strlen(pchMaxUses)) == 0)
  188. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  189. else if ( strspn(pchMaxUses, "1234567890") != strlen(pchMaxUses) )
  190. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  191. else if ( strlen( pchMaxUses ) > strlen( "4294967295" ) )
  192. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  193. else if ( ( strlen( pchMaxUses ) == strlen( "4294967295" ) ) &&
  194. ( _stricmp( pchMaxUses, "4294967295" ) > 0 ) )
  195. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  196. else
  197. AfpVolInfo.afpvol_max_uses = atoi(pchMaxUses);
  198. if ( AfpVolInfo.afpvol_max_uses == 0 )
  199. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  200. }
  201. else
  202. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  203. }
  204. else
  205. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  206. AfpVolInfo.afpvol_props_mask = 0;
  207. if (pchReadOnly != NULL)
  208. {
  209. if ( *pchReadOnly )
  210. {
  211. if (_strnicmp(pchReadOnly, pszTRUE, strlen(pchReadOnly) ) == 0)
  212. AfpVolInfo.afpvol_props_mask |= AFP_VOLUME_READONLY;
  213. else if (_strnicmp(pchReadOnly, pszFALSE, strlen(pchReadOnly))!=0)
  214. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  215. }
  216. else
  217. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  218. }
  219. if (pchGuestsAllowed != NULL)
  220. {
  221. if ( *pchGuestsAllowed )
  222. {
  223. if (_strnicmp(pchGuestsAllowed,pszTRUE,strlen(pchGuestsAllowed))==0)
  224. AfpVolInfo.afpvol_props_mask |= AFP_VOLUME_GUESTACCESS;
  225. else if(_strnicmp(pchGuestsAllowed,
  226. pszFALSE,strlen(pchGuestsAllowed))!=0)
  227. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  228. }
  229. else
  230. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  231. }
  232. else
  233. AfpVolInfo.afpvol_props_mask |= AFP_VOLUME_GUESTACCESS;
  234. //
  235. // Connect with the server
  236. //
  237. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  238. if (dwRetCode != NO_ERROR)
  239. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  240. //
  241. // First get and set directory information.
  242. //
  243. dwRetCode = AfpAdminDirectoryGetInfo(hServer,
  244. lpwsPath,
  245. (LPBYTE*)&pAfpDirInfo);
  246. if (dwRetCode == NO_ERROR)
  247. {
  248. pAfpDirInfo->afpdir_path = lpwsPath;
  249. if ( pAfpDirInfo->afpdir_owner != (LPWSTR)NULL )
  250. {
  251. dwParmNum |= AFP_DIR_PARMNUM_OWNER;
  252. }
  253. if ( pAfpDirInfo->afpdir_group != (LPWSTR)NULL )
  254. {
  255. dwParmNum |= AFP_DIR_PARMNUM_GROUP;
  256. }
  257. dwRetCode = AfpAdminVolumeAdd(hServer, (LPBYTE)&AfpVolInfo);
  258. // Directory permissions need not be changed here
  259. #if 0
  260. if (dwRetCode == NO_ERROR)
  261. {
  262. dwRetCode = AfpAdminDirectorySetInfo(hServer,
  263. (LPBYTE)pAfpDirInfo,
  264. dwParmNum);
  265. }
  266. #endif
  267. if (dwRetCode != NO_ERROR)
  268. {
  269. printf ("AfpAdminVolumeAdd failed with error %ld\n",
  270. dwRetCode);
  271. }
  272. AfpAdminBufferFree(pAfpDirInfo);
  273. }
  274. // we will get this if it's a CDROM. UI ignores this error: why not macfile?
  275. else if (dwRetCode == AFPERR_SecurityNotSupported)
  276. {
  277. dwRetCode = AfpAdminVolumeAdd(hServer, (LPBYTE)&AfpVolInfo);
  278. }
  279. if (dwRetCode != NO_ERROR)
  280. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  281. AfpAdminDisconnect(hServer);
  282. LocalFree(lpwsPath);
  283. if (pchServer)
  284. {
  285. DWORD dwLen;
  286. // using the server name, form a path like \\foobar\d$\
  287. // (the +2 for the leading \\)
  288. for (dwLen=0; dwLen < CNLEN+2; dwLen++ )
  289. {
  290. lpDrivePath[dwLen] = pchServer[dwLen];
  291. if (pchServer[dwLen] == 0)
  292. {
  293. break;
  294. }
  295. }
  296. lpDrivePath[CNLEN] = 0; // just to be sure
  297. strcat(lpDrivePath,"\\");
  298. dwLen = strlen(lpDrivePath);
  299. lpDrivePath[dwLen] = pchPath[0];
  300. lpDrivePath[dwLen+1] = 0;
  301. strcat(lpDrivePath,"$\\");
  302. }
  303. else
  304. {
  305. strncpy(lpDrivePath, pchPath, 3);
  306. lpDrivePath[2] = '\\';
  307. lpDrivePath[3] = 0;
  308. }
  309. if (IsDriveGreaterThan2Gig(lpDrivePath))
  310. {
  311. LocalFree(lpDrivePath);
  312. PrintMessageAndExit(IDS_VOLUME_TOO_BIG, NULL);
  313. }
  314. LocalFree(lpDrivePath);
  315. if (dwRetCode != NO_ERROR)
  316. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  317. else
  318. PrintMessageAndExit(IDS_SUCCESS, NULL);
  319. }
  320. VOID
  321. DoVolumeDelete(
  322. CHAR * pchServer,
  323. CHAR * pchName
  324. )
  325. {
  326. WCHAR wchName[AFP_VOLNAME_LEN+1];
  327. DWORD dwRetCode;
  328. AFP_SERVER_HANDLE hServer;
  329. WCHAR wchServer[CNLEN+3];
  330. PAFP_VOLUME_INFO pAfpVolumeInfo;
  331. PAFP_CONNECTION_INFO pAfpConnections;
  332. PAFP_CONNECTION_INFO pAfpConnInfoIter;
  333. DWORD cEntriesRead;
  334. DWORD cTotalAvail;
  335. DWORD dwIndex;
  336. ZeroMemory (wchName, (AFP_VOLNAME_LEN+1)*sizeof(WCHAR));
  337. if ( ( pchName == NULL ) || ( *pchName == (CHAR)NULL ) )
  338. PrintMessageAndExit( IDS_VOLUME_SYNTAX, NULL );
  339. mbstowcs(wchName, pchName, sizeof(wchName)/sizeof(WCHAR));
  340. if (pchServer)
  341. {
  342. if (*pchServer)
  343. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  344. else
  345. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  346. }
  347. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  348. if (dwRetCode != NO_ERROR)
  349. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  350. dwRetCode = AfpAdminVolumeGetInfo( hServer,
  351. (LPWSTR)wchName,
  352. (LPBYTE*)&pAfpVolumeInfo );
  353. if (dwRetCode != NO_ERROR)
  354. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  355. //
  356. // Check if there are any users connected to the volume
  357. // by enumerating the connections to this volume.
  358. //
  359. dwRetCode = AfpAdminConnectionEnum( hServer,
  360. (LPBYTE*)&pAfpConnections,
  361. AFP_FILTER_ON_VOLUME_ID,
  362. pAfpVolumeInfo->afpvol_id,
  363. (DWORD)-1, // Get all conenctions
  364. &cEntriesRead,
  365. &cTotalAvail,
  366. NULL );
  367. AfpAdminBufferFree( pAfpVolumeInfo );
  368. if (dwRetCode != NO_ERROR)
  369. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  370. for ( dwIndex = 0, pAfpConnInfoIter = pAfpConnections;
  371. dwIndex < cEntriesRead;
  372. dwIndex++, pAfpConnInfoIter++ )
  373. {
  374. dwRetCode = AfpAdminConnectionClose( hServer,
  375. pAfpConnInfoIter->afpconn_id );
  376. if ( dwRetCode != NO_ERROR )
  377. PrintMessageAndExit( IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode) );
  378. }
  379. AfpAdminBufferFree( pAfpConnections );
  380. dwRetCode = AfpAdminVolumeDelete( hServer, wchName );
  381. if (dwRetCode != NO_ERROR)
  382. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  383. AfpAdminDisconnect( hServer );
  384. PrintMessageAndExit(IDS_SUCCESS, NULL);
  385. }
  386. VOID
  387. DoVolumeSet(
  388. CHAR * pchServer,
  389. CHAR * pchName,
  390. CHAR * pchPassword,
  391. CHAR * pchReadOnly,
  392. CHAR * pchGuestsAllowed,
  393. CHAR * pchMaxUses
  394. )
  395. {
  396. DWORD dwParmNum = 0;
  397. AFP_VOLUME_INFO AfpVolInfo;
  398. DWORD dwRetCode;
  399. AFP_SERVER_HANDLE hServer;
  400. WCHAR wchName[AFP_VOLNAME_LEN+1];
  401. WCHAR wchPassword[AFP_VOLPASS_LEN+1];
  402. WCHAR wchServer[CNLEN+3];
  403. ZeroMemory (&AfpVolInfo, sizeof(AFP_VOLUME_INFO));
  404. //
  405. // Check to see if the mandatory values are not supplied
  406. //
  407. if ( ( pchName == NULL ) || ( *pchName == (CHAR)NULL ) )
  408. PrintMessageAndExit( IDS_VOLUME_SYNTAX, NULL );
  409. mbstowcs(wchName, pchName, sizeof(wchName)/sizeof(WCHAR));
  410. AfpVolInfo.afpvol_name = wchName;
  411. if (pchServer)
  412. {
  413. if (*pchServer)
  414. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  415. else
  416. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  417. }
  418. if (pchPassword)
  419. {
  420. dwParmNum |= AFP_VOL_PARMNUM_PASSWORD;
  421. if (*pchPassword)
  422. {
  423. mbstowcs(wchPassword, pchPassword, sizeof(wchPassword)/sizeof(WCHAR));
  424. AfpVolInfo.afpvol_password = wchPassword;
  425. }
  426. else
  427. AfpVolInfo.afpvol_password = NULL;
  428. }
  429. if (pchMaxUses)
  430. {
  431. if (*pchMaxUses)
  432. {
  433. dwParmNum |= AFP_VOL_PARMNUM_MAXUSES;
  434. if (_strnicmp(pchMaxUses, pszUnlimited, strlen(pchMaxUses))== 0)
  435. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  436. else if ( strspn(pchMaxUses, "1234567890") != strlen(pchMaxUses) )
  437. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  438. else if ( strlen( pchMaxUses ) > strlen( "4294967295" ) )
  439. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  440. else if ( ( strlen( pchMaxUses ) == strlen( "4294967295" ) ) &&
  441. ( _stricmp( pchMaxUses, "4294967295" ) > 0 ) )
  442. AfpVolInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  443. else
  444. AfpVolInfo.afpvol_max_uses = atoi(pchMaxUses);
  445. if ( AfpVolInfo.afpvol_max_uses == 0 )
  446. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  447. }
  448. else
  449. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  450. }
  451. else
  452. AfpVolInfo.afpvol_max_uses = 0;
  453. AfpVolInfo.afpvol_props_mask = 0;
  454. if (pchReadOnly)
  455. {
  456. if (*pchReadOnly)
  457. {
  458. dwParmNum |= AFP_VOL_PARMNUM_PROPSMASK;
  459. if (_strnicmp(pchReadOnly, pszTRUE, strlen(pchReadOnly) ) == 0)
  460. AfpVolInfo.afpvol_props_mask |= AFP_VOLUME_READONLY;
  461. else if (_strnicmp(pchReadOnly, pszFALSE, strlen(pchReadOnly))!=0)
  462. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  463. }
  464. else
  465. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  466. }
  467. if (pchGuestsAllowed)
  468. {
  469. if (*pchGuestsAllowed)
  470. {
  471. dwParmNum |= AFP_VOL_PARMNUM_PROPSMASK;
  472. if (_strnicmp(pchGuestsAllowed, pszTRUE,
  473. strlen(pchGuestsAllowed))==0)
  474. AfpVolInfo.afpvol_props_mask |= AFP_VOLUME_GUESTACCESS;
  475. else if (_strnicmp(pchGuestsAllowed,
  476. pszFALSE,strlen(pchGuestsAllowed)) != 0)
  477. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  478. }
  479. else
  480. PrintMessageAndExit(IDS_VOLUME_SYNTAX, NULL);
  481. }
  482. if (dwParmNum == 0)
  483. PrintMessageAndExit( IDS_VOLUME_SYNTAX, NULL );
  484. //
  485. // Connect with the server
  486. //
  487. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  488. if (dwRetCode != NO_ERROR)
  489. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  490. dwRetCode = AfpAdminVolumeSetInfo( hServer,
  491. (LPBYTE)&AfpVolInfo,
  492. dwParmNum);
  493. if (dwRetCode != NO_ERROR)
  494. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  495. AfpAdminDisconnect(hServer);
  496. PrintMessageAndExit(IDS_SUCCESS, NULL);
  497. }
  498. VOID
  499. DoServerSetInfo(
  500. CHAR * pchServer,
  501. CHAR * pchMaxSessions,
  502. CHAR * pchLoginMessage,
  503. CHAR * pchGuestsAllowed,
  504. CHAR * pchUAMRequired,
  505. CHAR * pchAllowSavedPasswords,
  506. CHAR * pchMacServerName
  507. )
  508. {
  509. DWORD dwRetCode;
  510. AFP_SERVER_HANDLE hServer;
  511. WCHAR wchServer[CNLEN+3];
  512. DWORD dwParmNum = 0;
  513. AFP_SERVER_INFO AfpServerInfo;
  514. WCHAR wchLoginMsg[AFP_MESSAGE_LEN+1];
  515. WCHAR wchMacServerName[AFP_SERVERNAME_LEN+1];
  516. ZeroMemory (&AfpServerInfo, sizeof(AFP_SERVER_INFO));
  517. if (pchMaxSessions)
  518. {
  519. if (*pchMaxSessions)
  520. {
  521. dwParmNum |= AFP_SERVER_PARMNUM_MAX_SESSIONS;
  522. if (_strnicmp(pchMaxSessions,
  523. pszUnlimited,
  524. strlen(pchMaxSessions)) == 0)
  525. AfpServerInfo.afpsrv_max_sessions = AFP_MAXSESSIONS;
  526. else if (strspn(pchMaxSessions, "1234567890")
  527. != strlen(pchMaxSessions))
  528. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  529. else
  530. AfpServerInfo.afpsrv_max_sessions = atoi(pchMaxSessions);
  531. }
  532. else
  533. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  534. }
  535. if (pchLoginMessage)
  536. {
  537. if (*pchLoginMessage)
  538. {
  539. dwParmNum |= AFP_SERVER_PARMNUM_LOGINMSG;
  540. if (strlen(pchLoginMessage) > AFP_MESSAGE_LEN)
  541. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  542. else
  543. {
  544. mbstowcs(wchLoginMsg, pchLoginMessage, sizeof(wchLoginMsg)/sizeof(WCHAR));
  545. AfpServerInfo.afpsrv_login_msg = wchLoginMsg;
  546. }
  547. }
  548. else
  549. {
  550. dwParmNum |= AFP_SERVER_PARMNUM_LOGINMSG;
  551. AfpServerInfo.afpsrv_login_msg = NULL;
  552. }
  553. }
  554. AfpServerInfo.afpsrv_options = 0;
  555. #if 0
  556. if (pchGuestsAllowed)
  557. {
  558. if (*pchGuestsAllowed)
  559. {
  560. dwParmNum |= AFP_SERVER_PARMNUM_OPTIONS;
  561. if (_strnicmp(pchGuestsAllowed,
  562. pszTRUE,
  563. strlen(pchGuestsAllowed)) == 0)
  564. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_GUESTLOGONALLOWED;
  565. else if (_strnicmp(pchGuestsAllowed,
  566. pszFALSE,
  567. strlen(pchGuestsAllowed)) != 0)
  568. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  569. }
  570. else
  571. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  572. }
  573. else
  574. AfpServerInfo.afpsrv_options |= AFP_SRVROPT_GUESTLOGONALLOWED;
  575. #endif
  576. if (pchUAMRequired)
  577. {
  578. if (*pchUAMRequired)
  579. {
  580. dwParmNum |= AFP_SERVER_PARMNUM_OPTIONS;
  581. if (_strnicmp(pchUAMRequired,
  582. pszFALSE,
  583. strlen(pchGuestsAllowed)) == 0)
  584. AfpServerInfo.afpsrv_options|=AFP_SRVROPT_CLEARTEXTLOGONALLOWED;
  585. else if (_strnicmp(pchUAMRequired,
  586. pszTRUE,
  587. strlen(pchUAMRequired)) != 0)
  588. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  589. }
  590. else
  591. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  592. }
  593. if (pchAllowSavedPasswords)
  594. {
  595. if (*pchAllowSavedPasswords)
  596. {
  597. dwParmNum |= AFP_SERVER_PARMNUM_OPTIONS;
  598. if (_strnicmp(pchAllowSavedPasswords,
  599. pszTRUE,
  600. strlen(pchAllowSavedPasswords)) == 0)
  601. AfpServerInfo.afpsrv_options|=AFP_SRVROPT_ALLOWSAVEDPASSWORD;
  602. else if (_strnicmp(pchAllowSavedPasswords,
  603. pszFALSE,
  604. strlen(pchAllowSavedPasswords)) != 0)
  605. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  606. }
  607. else
  608. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  609. }
  610. if (pchMacServerName)
  611. {
  612. if (*pchMacServerName)
  613. {
  614. dwParmNum |= AFP_SERVER_PARMNUM_NAME;
  615. if (strlen(pchMacServerName) > AFP_SERVERNAME_LEN)
  616. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  617. else
  618. {
  619. mbstowcs(wchMacServerName,
  620. pchMacServerName,
  621. sizeof(wchMacServerName)/sizeof(WCHAR));
  622. AfpServerInfo.afpsrv_name = wchMacServerName;
  623. }
  624. }
  625. else
  626. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  627. }
  628. if (dwParmNum == 0)
  629. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  630. if (pchServer)
  631. {
  632. if (*pchServer)
  633. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  634. else
  635. PrintMessageAndExit(IDS_SERVER_SYNTAX, NULL);
  636. }
  637. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  638. if (dwRetCode != NO_ERROR)
  639. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  640. dwRetCode = AfpAdminServerSetInfo( hServer,
  641. (LPBYTE)&AfpServerInfo,
  642. dwParmNum);
  643. if (dwRetCode != NO_ERROR)
  644. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  645. AfpAdminDisconnect(hServer);
  646. PrintMessageAndExit(IDS_SUCCESS, NULL);
  647. }
  648. VOID
  649. DoDirectorySetInfo(
  650. CHAR * pchServer,
  651. CHAR * pchPath,
  652. CHAR * pchOwnerName,
  653. CHAR * pchGroupName,
  654. CHAR * pchPermissions
  655. )
  656. {
  657. DWORD dwRetCode;
  658. AFP_SERVER_HANDLE hServer;
  659. WCHAR wchServer[CNLEN+3];
  660. LPWSTR lpwsPath;
  661. WCHAR wchOwner[UNLEN+1];
  662. WCHAR wchGroup[GNLEN+1];
  663. DWORD dwPerms;
  664. AFP_DIRECTORY_INFO AfpDirInfo;
  665. DWORD dwParmNum = 0;
  666. if ( ( pchPath == NULL ) || ( *pchPath == (CHAR)NULL ) )
  667. PrintMessageAndExit( IDS_DIRECTORY_SYNTAX, NULL );
  668. lpwsPath = LocalAlloc(LPTR, (strlen(pchPath) + 1) * sizeof(WCHAR));
  669. if (lpwsPath == NULL)
  670. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  671. mbstowcs(lpwsPath, pchPath, strlen(pchPath)+1);
  672. AfpDirInfo.afpdir_path = lpwsPath;
  673. if (pchServer)
  674. {
  675. if (*pchServer)
  676. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  677. else
  678. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  679. }
  680. if (pchOwnerName)
  681. {
  682. if (*pchOwnerName)
  683. {
  684. if (strlen(pchOwnerName) > UNLEN)
  685. PrintMessageAndExit(IDS_GENERAL_SYNTAX, NULL);
  686. mbstowcs(wchOwner, pchOwnerName, sizeof(wchOwner)/sizeof(WCHAR));
  687. AfpDirInfo.afpdir_owner = wchOwner;
  688. dwParmNum |= AFP_DIR_PARMNUM_OWNER;
  689. }
  690. else
  691. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  692. }
  693. if (pchGroupName)
  694. {
  695. if (*pchGroupName)
  696. {
  697. mbstowcs(wchGroup, pchGroupName, sizeof(wchGroup)/sizeof(WCHAR));
  698. AfpDirInfo.afpdir_group = wchGroup;
  699. dwParmNum |= AFP_DIR_PARMNUM_GROUP;
  700. }
  701. else
  702. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  703. }
  704. if (pchPermissions)
  705. {
  706. if (*pchPermissions)
  707. {
  708. if (strspn(pchPermissions, "10") != strlen(pchPermissions))
  709. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  710. if (strlen(pchPermissions) != 11)
  711. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  712. dwPerms = 0;
  713. if (pchPermissions[0] == '1')
  714. dwPerms |= AFP_PERM_OWNER_SFI;
  715. if (pchPermissions[1] == '1')
  716. dwPerms |= AFP_PERM_OWNER_SFO;
  717. if (pchPermissions[2] == '1')
  718. dwPerms |= AFP_PERM_OWNER_MC;
  719. if (pchPermissions[3] == '1')
  720. dwPerms |= AFP_PERM_GROUP_SFI;
  721. if (pchPermissions[4] == '1')
  722. dwPerms |= AFP_PERM_GROUP_SFO;
  723. if (pchPermissions[5] == '1')
  724. dwPerms |= AFP_PERM_GROUP_MC;
  725. if (pchPermissions[6] == '1')
  726. dwPerms |= AFP_PERM_WORLD_SFI;
  727. if (pchPermissions[7] == '1')
  728. dwPerms |= AFP_PERM_WORLD_SFO;
  729. if (pchPermissions[8] == '1')
  730. dwPerms |= AFP_PERM_WORLD_MC;
  731. if (pchPermissions[9] == '1')
  732. dwPerms |= AFP_PERM_INHIBIT_MOVE_DELETE;
  733. if (pchPermissions[10] == '1')
  734. dwPerms |= AFP_PERM_SET_SUBDIRS;
  735. AfpDirInfo.afpdir_perms = dwPerms;
  736. dwParmNum |= AFP_DIR_PARMNUM_PERMS;
  737. }
  738. else
  739. PrintMessageAndExit(IDS_DIRECTORY_SYNTAX, NULL);
  740. }
  741. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  742. if (dwRetCode != NO_ERROR)
  743. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  744. dwRetCode = AfpAdminDirectorySetInfo(hServer,
  745. (LPBYTE)&AfpDirInfo,
  746. dwParmNum);
  747. if (dwRetCode != NO_ERROR)
  748. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  749. AfpAdminDisconnect(hServer);
  750. LocalFree(lpwsPath);
  751. PrintMessageAndExit(IDS_SUCCESS, NULL);
  752. }
  753. VOID
  754. DoForkize(
  755. CHAR * pchServer,
  756. CHAR * pchType,
  757. CHAR * pchCreator,
  758. CHAR * pchDataFork,
  759. CHAR * pchResourceFork,
  760. CHAR * pchTargetFile
  761. )
  762. {
  763. DWORD dwRetCode;
  764. AFP_SERVER_HANDLE hServer;
  765. WCHAR wchServer[CNLEN+3];
  766. LPWSTR lpwsTarget;
  767. LPWSTR lpwsResource;
  768. LPWSTR lpwsData;
  769. WCHAR wchType[AFP_TYPE_LEN+1];
  770. WCHAR wchCreator[AFP_CREATOR_LEN+1];
  771. DWORD dwParmNum = 0;
  772. if ( ( pchTargetFile == NULL ) || ( *pchTargetFile == (CHAR)NULL ) )
  773. PrintMessageAndExit( IDS_FORKIZE_SYNTAX, NULL );
  774. lpwsTarget = LocalAlloc(LPTR, (strlen(pchTargetFile) + 1) * sizeof(WCHAR));
  775. if (lpwsTarget == NULL)
  776. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  777. mbstowcs(lpwsTarget,pchTargetFile,strlen(pchTargetFile)+1);
  778. if (pchServer)
  779. {
  780. if (*pchServer)
  781. mbstowcs(wchServer, pchServer, sizeof(wchServer)/sizeof(WCHAR));
  782. else
  783. PrintMessageAndExit(IDS_FORKIZE_SYNTAX, NULL);
  784. }
  785. if (pchType != NULL)
  786. {
  787. if ( ( *pchType == (CHAR)NULL ) || ( strlen( pchType ) > AFP_TYPE_LEN ))
  788. PrintMessageAndExit(IDS_API_ERROR,(LPSTR)AFPERR_InvalidTypeCreator);
  789. else
  790. mbstowcs(wchType, pchType, sizeof(wchType)/sizeof(WCHAR));
  791. dwParmNum |= AFP_FD_PARMNUM_TYPE;
  792. }
  793. if (pchCreator != NULL)
  794. {
  795. if ((*pchCreator == (CHAR)NULL) || (strlen(pchCreator)>AFP_CREATOR_LEN))
  796. PrintMessageAndExit(IDS_API_ERROR,(LPSTR)AFPERR_InvalidTypeCreator);
  797. else
  798. mbstowcs(wchCreator, pchCreator, sizeof(wchCreator)/sizeof(WCHAR));
  799. dwParmNum |= AFP_FD_PARMNUM_CREATOR;
  800. }
  801. if (pchResourceFork != NULL)
  802. {
  803. if ( *pchResourceFork == (CHAR)NULL )
  804. PrintMessageAndExit( IDS_FORKIZE_SYNTAX, NULL );
  805. lpwsResource=LocalAlloc(LPTR,(strlen(pchResourceFork)+1)*sizeof(WCHAR));
  806. if (lpwsResource == NULL)
  807. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  808. mbstowcs(lpwsResource,pchResourceFork,
  809. strlen(pchResourceFork)+1);
  810. }
  811. else
  812. lpwsResource = NULL;
  813. if (pchDataFork != NULL)
  814. {
  815. if ( *pchDataFork == (CHAR)NULL )
  816. PrintMessageAndExit( IDS_FORKIZE_SYNTAX, NULL );
  817. lpwsData = LocalAlloc(LPTR,(strlen(pchDataFork)+1)*sizeof(WCHAR));
  818. if (lpwsData == NULL)
  819. PrintMessageAndExit(IDS_API_ERROR, (CHAR*)ERROR_NOT_ENOUGH_MEMORY);
  820. mbstowcs(lpwsData,pchDataFork,
  821. strlen(pchDataFork)+1);
  822. }
  823. else
  824. lpwsData = NULL;
  825. if ((pchType == NULL) && (pchCreator == NULL) &&
  826. (pchResourceFork == NULL) && (pchDataFork == NULL))
  827. PrintMessageAndExit(IDS_FORKIZE_SYNTAX, NULL);
  828. dwRetCode = AfpAdminConnect(pchServer ? wchServer : NULL, &hServer);
  829. if (dwRetCode != NO_ERROR)
  830. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  831. dwRetCode = AfpAdminFinderSetInfo( hServer,
  832. wchType,
  833. wchCreator,
  834. lpwsData,
  835. lpwsResource,
  836. lpwsTarget,
  837. dwParmNum);
  838. if (dwRetCode != NO_ERROR)
  839. PrintMessageAndExit(IDS_API_ERROR, (CHAR *)((ULONG_PTR)dwRetCode));
  840. AfpAdminDisconnect(hServer);
  841. PrintMessageAndExit(IDS_SUCCESS, NULL);
  842. }