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.

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