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.

709 lines
13 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1989 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: validate.c
  7. //
  8. // Description: Contains routines to validate AFP_***_INFO structure
  9. // fields. These routines are called to validate information
  10. // passed by the user and information read from the registry.
  11. //
  12. // History:
  13. // July 11,1992. NarenG Created original version.
  14. //
  15. #include "afpsvcp.h"
  16. #include <lmcons.h> // UNLEN and GNLEN
  17. //**
  18. //
  19. // Call: IsAfpServerNameValid
  20. //
  21. // Returns: TRUE - valid
  22. // FALSE - invalid
  23. //
  24. // Description: Validated server name field.
  25. //
  26. BOOL
  27. IsAfpServerNameValid(
  28. IN LPVOID pAfpServerName
  29. )
  30. {
  31. BOOL fValid = TRUE;
  32. DWORD dwLength;
  33. try {
  34. dwLength = STRLEN( (LPWSTR)pAfpServerName );
  35. if ( ( dwLength > AFP_SERVERNAME_LEN ) || ( dwLength == 0 ) )
  36. fValid = FALSE;
  37. }
  38. except( EXCEPTION_EXECUTE_HANDLER ) {
  39. fValid = FALSE;
  40. }
  41. return( fValid );
  42. }
  43. //**
  44. //
  45. // Call: IsAfpServerOptionsValid
  46. //
  47. // Returns: TRUE - valid
  48. // FALSE - invalid
  49. //
  50. // Description: Validates Server options field.
  51. //
  52. BOOL
  53. IsAfpServerOptionsValid(
  54. IN LPVOID pServerOptions
  55. )
  56. {
  57. DWORD ServerOptions = *((LPDWORD)pServerOptions);
  58. BOOL fValid = TRUE;
  59. try {
  60. // Make sure only valid bits are set
  61. //
  62. if ( ServerOptions & ~( AFP_SRVROPT_GUESTLOGONALLOWED |
  63. AFP_SRVROPT_CLEARTEXTLOGONALLOWED |
  64. AFP_SRVROPT_4GB_VOLUMES |
  65. AFP_SRVROPT_MICROSOFT_UAM |
  66. AFP_SRVROPT_NATIVEAPPLEUAM |
  67. AFP_SRVROPT_ALLOWSAVEDPASSWORD ))
  68. fValid = FALSE;
  69. }
  70. except( EXCEPTION_EXECUTE_HANDLER ) {
  71. fValid = FALSE;
  72. }
  73. return( fValid );
  74. }
  75. //**
  76. //
  77. // Call: IsAfpMaxSessionsValid
  78. //
  79. // Returns: TRUE - valid
  80. // FALSE - invalid
  81. //
  82. // Description: Validates Max sessions field.
  83. //
  84. BOOL
  85. IsAfpMaxSessionsValid(
  86. IN LPVOID pMaxSessions
  87. )
  88. {
  89. BOOL fValid = TRUE;
  90. try {
  91. if ( *((LPDWORD)pMaxSessions) > AFP_MAX_ALLOWED_SRV_SESSIONS )
  92. fValid = FALSE;
  93. }
  94. except( EXCEPTION_EXECUTE_HANDLER ) {
  95. fValid = FALSE;
  96. }
  97. return( fValid );
  98. }
  99. //**
  100. //
  101. // Call: IsAfpMsgValid
  102. //
  103. // Returns: TRUE - valid
  104. // FALSE - invalid
  105. //
  106. // Description: Validates message field.
  107. //
  108. BOOL
  109. IsAfpMsgValid(
  110. IN LPVOID pMsg
  111. )
  112. {
  113. BOOL fValid = TRUE;
  114. try {
  115. if ( STRLEN( (LPWSTR)pMsg ) > AFP_MESSAGE_LEN )
  116. fValid = FALSE;
  117. }
  118. except( EXCEPTION_EXECUTE_HANDLER ) {
  119. fValid = FALSE;
  120. }
  121. return( fValid );
  122. }
  123. //**
  124. //
  125. // Call: IsAfpCodePageValid
  126. //
  127. // Returns: TRUE - valid
  128. // FALSE - invalid
  129. //
  130. // Description: Validates code page path.
  131. //
  132. BOOL
  133. IsAfpCodePageValid(
  134. IN LPVOID pCodePagePath
  135. )
  136. {
  137. BOOL fValid = TRUE;
  138. DWORD dwLength;
  139. try {
  140. dwLength = STRLEN( (LPWSTR)pCodePagePath );
  141. if ( ( dwLength == 0 ) || ( dwLength > MAX_PATH ) )
  142. fValid = FALSE;
  143. }
  144. except( EXCEPTION_EXECUTE_HANDLER ) {
  145. fValid = FALSE;
  146. }
  147. return( fValid );
  148. }
  149. //**
  150. //
  151. // Call: IsAfpExtensionValid
  152. //
  153. // Returns: TRUE - valid
  154. // FALSE - invalid
  155. //
  156. // Description: Validated the extension field in the AFP_EXTENSION structure.
  157. //
  158. BOOL
  159. IsAfpExtensionValid(
  160. IN PAFP_EXTENSION pAfpExtension
  161. )
  162. {
  163. BOOL fValid = TRUE;
  164. DWORD dwLength;
  165. try {
  166. // NULL extensions are not allowed
  167. //
  168. dwLength = STRLEN( pAfpExtension->afpe_extension );
  169. if ( ( dwLength == 0 ) || ( dwLength > AFP_EXTENSION_LEN ) )
  170. fValid = FALSE;
  171. STRUPR( pAfpExtension->afpe_extension );
  172. }
  173. except( EXCEPTION_EXECUTE_HANDLER ) {
  174. fValid = FALSE;
  175. }
  176. return( fValid );
  177. }
  178. //**
  179. //
  180. // Call: IsAfpMaxPagedMemValid
  181. //
  182. // Returns: TRUE - valid
  183. // FALSE - invalid
  184. //
  185. // Description: Validates Max. pages memory field.
  186. //
  187. BOOL
  188. IsAfpMaxPagedMemValid(
  189. IN LPVOID pMaxPagedMem
  190. )
  191. {
  192. BOOL fValid = TRUE;
  193. try {
  194. if ((*((LPDWORD)pMaxPagedMem) < AFP_MIN_ALLOWED_PAGED_MEM ) ||
  195. (*((LPDWORD)pMaxPagedMem) > AFP_MAX_ALLOWED_PAGED_MEM ))
  196. fValid = FALSE;
  197. }
  198. except( EXCEPTION_EXECUTE_HANDLER ) {
  199. fValid = FALSE;
  200. }
  201. return( fValid );
  202. }
  203. //**
  204. //
  205. // Call: IsAfpServerInfoValid
  206. //
  207. // Returns: TRUE - valid
  208. // FALSE - invalid
  209. //
  210. // Description: Validates the AFP_SERER_INFO structure.
  211. //
  212. BOOL
  213. IsAfpServerInfoValid(
  214. IN DWORD dwParmNum,
  215. IN PAFP_SERVER_INFO pAfpServerInfo
  216. )
  217. {
  218. // Can only set 5 fields
  219. //
  220. if ( dwParmNum & ~( AFP_SERVER_PARMNUM_MAX_SESSIONS |
  221. AFP_SERVER_PARMNUM_OPTIONS |
  222. AFP_SERVER_PARMNUM_NAME |
  223. AFP_SERVER_PARMNUM_LOGINMSG |
  224. AFP_SERVER_GUEST_ACCT_NOTIFY ))
  225. return( FALSE );
  226. // Null out the fields the are not allowed to be set so that RPC does
  227. // not think that they are valid pointers.
  228. //
  229. pAfpServerInfo->afpsrv_codepage = NULL;
  230. if ( dwParmNum & AFP_SERVER_PARMNUM_NAME ){
  231. if ( pAfpServerInfo->afpsrv_name != NULL ) {
  232. if ( !IsAfpServerNameValid( pAfpServerInfo->afpsrv_name ) )
  233. return( FALSE );
  234. }
  235. }
  236. else
  237. pAfpServerInfo->afpsrv_name = NULL;
  238. if ( dwParmNum & AFP_SERVER_PARMNUM_MAX_SESSIONS ) {
  239. if ( !IsAfpMaxSessionsValid( &(pAfpServerInfo->afpsrv_max_sessions) ))
  240. return( FALSE );
  241. }
  242. if ( dwParmNum & AFP_SERVER_PARMNUM_OPTIONS ){
  243. if ( !IsAfpServerOptionsValid( &(pAfpServerInfo->afpsrv_options) ))
  244. return( FALSE );
  245. }
  246. if ( dwParmNum & AFP_SERVER_PARMNUM_LOGINMSG ){
  247. if ( pAfpServerInfo->afpsrv_login_msg != NULL ) {
  248. if( !IsAfpMsgValid( pAfpServerInfo->afpsrv_login_msg ) )
  249. return( FALSE );
  250. }
  251. }
  252. else
  253. pAfpServerInfo->afpsrv_login_msg = NULL;
  254. return( TRUE );
  255. }
  256. //**
  257. //
  258. // Call: IsAfpTypeCreatorValid
  259. //
  260. // Returns: TRUE - valid
  261. // FALSE - invalid
  262. //
  263. // Description: Validates the AFP_TYPE_CREATOR structure.
  264. //
  265. BOOL
  266. IsAfpTypeCreatorValid(
  267. IN PAFP_TYPE_CREATOR pAfpTypeCreator
  268. )
  269. {
  270. BOOL fValid = TRUE;
  271. DWORD dwLength;
  272. try {
  273. dwLength = STRLEN( pAfpTypeCreator->afptc_type );
  274. if ( ( dwLength == 0 ) || ( dwLength > AFP_TYPE_LEN ) )
  275. fValid = FALSE;
  276. dwLength = STRLEN( pAfpTypeCreator->afptc_creator );
  277. if ( ( dwLength == 0 ) || ( dwLength > AFP_CREATOR_LEN ) )
  278. fValid = FALSE;
  279. dwLength = STRLEN(pAfpTypeCreator->afptc_comment);
  280. if ( dwLength > AFP_ETC_COMMENT_LEN )
  281. fValid = FALSE;
  282. }
  283. except( EXCEPTION_EXECUTE_HANDLER ) {
  284. fValid = FALSE;
  285. }
  286. return( fValid );
  287. }
  288. //**
  289. //
  290. // Call: IsAfpMaxNonPagedMemValid
  291. //
  292. // Returns: TRUE - valid
  293. // FALSE - invalid
  294. //
  295. // Description: Validates the max non-paged memory field.
  296. //
  297. BOOL
  298. IsAfpMaxNonPagedMemValid(
  299. IN LPVOID pMaxNonPagedMem
  300. )
  301. {
  302. BOOL fValid = TRUE;
  303. try {
  304. if ((*((LPDWORD)pMaxNonPagedMem) < AFP_MIN_ALLOWED_NONPAGED_MEM ) ||
  305. (*((LPDWORD)pMaxNonPagedMem) > AFP_MAX_ALLOWED_NONPAGED_MEM ))
  306. fValid = FALSE;
  307. }
  308. except( EXCEPTION_EXECUTE_HANDLER ) {
  309. fValid = FALSE;
  310. }
  311. return( fValid );
  312. }
  313. //**
  314. //
  315. // Call: IsAfpVolumeInfoValid
  316. //
  317. // Returns: TRUE - valid
  318. // FALSE - invalid
  319. //
  320. // Description: Wil validate a volume info structure and the associated
  321. // parm number. If the parm number is zero it is assume that
  322. // the user is trying to add a volume vs. trying to set
  323. // information for that volume. If the parm number is not
  324. // zero, then all string pointer values that are not being
  325. // set by the user, are set to NULL, otherwise RPC might mistake
  326. // these fields for valid string poiters.
  327. //
  328. //
  329. BOOL
  330. IsAfpVolumeInfoValid(
  331. IN DWORD dwParmNum,
  332. IN PAFP_VOLUME_INFO pAfpVolume
  333. )
  334. {
  335. BOOL fValid = TRUE;
  336. if ( !IsAfpVolumeNameValid( pAfpVolume->afpvol_name ) )
  337. return( FALSE );
  338. try {
  339. // User is wants to set info
  340. //
  341. if ( dwParmNum != AFP_VALIDATE_ALL_FIELDS ) {
  342. if ( ~AFP_VOL_PARMNUM_ALL & dwParmNum )
  343. fValid = FALSE;
  344. if ( dwParmNum & AFP_VOL_PARMNUM_PASSWORD ){
  345. // Validate password
  346. //
  347. if ( pAfpVolume->afpvol_password != NULL
  348. &&
  349. ( STRLEN(pAfpVolume->afpvol_password) > AFP_VOLPASS_LEN ))
  350. fValid = FALSE;
  351. }
  352. else
  353. pAfpVolume->afpvol_password = NULL;
  354. if ( dwParmNum & AFP_VOL_PARMNUM_PROPSMASK ) {
  355. if ( ~AFP_VOLUME_ALL & pAfpVolume->afpvol_props_mask )
  356. fValid = FALSE;
  357. }
  358. // Set path to NULL since user cannot change this
  359. //
  360. pAfpVolume->afpvol_path = NULL;
  361. }
  362. else {
  363. if ( pAfpVolume->afpvol_password != NULL
  364. &&
  365. ( STRLEN(pAfpVolume->afpvol_password) > AFP_VOLPASS_LEN ))
  366. fValid = FALSE;
  367. if ( ~AFP_VOLUME_ALL & pAfpVolume->afpvol_props_mask )
  368. fValid = FALSE;
  369. // Just make sure this is a valid string pointer
  370. //
  371. STRLEN( pAfpVolume->afpvol_path );
  372. }
  373. }
  374. except( EXCEPTION_EXECUTE_HANDLER ) {
  375. fValid = FALSE;
  376. }
  377. return( fValid );
  378. }
  379. //**
  380. //
  381. // Call: IsAfpVolumeNameValid
  382. //
  383. // Returns: TRUE - valid
  384. // FALSE - invalid
  385. //
  386. // Description: Will validate the volume name
  387. //
  388. BOOL
  389. IsAfpVolumeNameValid(
  390. IN LPWSTR lpwsVolumeName
  391. )
  392. {
  393. BOOL fValid = TRUE;
  394. DWORD dwLength;
  395. try {
  396. dwLength = STRLEN( lpwsVolumeName );
  397. if ( ( dwLength > AFP_VOLNAME_LEN ) || ( dwLength == 0 ) )
  398. fValid = FALSE;
  399. }
  400. except( EXCEPTION_EXECUTE_HANDLER ) {
  401. fValid = FALSE;
  402. }
  403. return( fValid );
  404. }
  405. //**
  406. //
  407. // Call: IsAfpDirInfoValid
  408. //
  409. // Returns: TRUE - valid
  410. // FALSE - invalid
  411. //
  412. // Description: Will validate various field in the AFP_VOLUME_INFO
  413. // structure depending on the parm number.
  414. //
  415. BOOL
  416. IsAfpDirInfoValid(
  417. IN DWORD dwParmNum,
  418. IN PAFP_DIRECTORY_INFO pAfpDirInfo
  419. )
  420. {
  421. BOOL fValid = TRUE;
  422. DWORD dwLength;
  423. if ( ~AFP_DIR_PARMNUM_ALL & dwParmNum )
  424. return( FALSE );
  425. try {
  426. // Make sure path is a valid string
  427. //
  428. dwLength = STRLEN( pAfpDirInfo->afpdir_path );
  429. if ( ( dwLength == 0 ) || ( dwLength > MAX_PATH ) )
  430. fValid = FALSE;
  431. if ( dwParmNum & AFP_DIR_PARMNUM_OWNER ) {
  432. dwLength = STRLEN( pAfpDirInfo->afpdir_owner );
  433. if ( ( dwLength == 0 ) || ( dwLength > UNLEN ) )
  434. fValid = FALSE;
  435. }
  436. else
  437. pAfpDirInfo->afpdir_owner = NULL;
  438. if ( dwParmNum & AFP_DIR_PARMNUM_GROUP ){
  439. dwLength = STRLEN( pAfpDirInfo->afpdir_group );
  440. if ( ( dwLength == 0 ) || ( dwLength > GNLEN ) )
  441. fValid = FALSE;
  442. }
  443. else
  444. pAfpDirInfo->afpdir_group = NULL;
  445. if ( dwParmNum & AFP_DIR_PARMNUM_PERMS ) {
  446. if ( ~( AFP_PERM_OWNER_MASK |
  447. AFP_PERM_GROUP_MASK |
  448. AFP_PERM_WORLD_MASK |
  449. AFP_PERM_INHIBIT_MOVE_DELETE |
  450. AFP_PERM_SET_SUBDIRS ) &
  451. pAfpDirInfo->afpdir_perms )
  452. fValid = FALSE;
  453. }
  454. }
  455. except( EXCEPTION_EXECUTE_HANDLER ) {
  456. fValid = FALSE;
  457. }
  458. return( fValid );
  459. }
  460. //**
  461. //
  462. // Call: IsAfpIconValid
  463. //
  464. // Returns: TRUE - valid
  465. // FALSE - invalid
  466. //
  467. // Description: Will validate a AFP_ICON_INFO data structure.
  468. //
  469. BOOL
  470. IsAfpIconValid(
  471. IN PAFP_ICON_INFO pAfpIconInfo
  472. )
  473. {
  474. BOOL fValid = TRUE;
  475. DWORD dwLength;
  476. try {
  477. dwLength = STRLEN( pAfpIconInfo->afpicon_type );
  478. if ( ( dwLength == 0 ) || ( dwLength > AFP_TYPE_LEN ) )
  479. fValid = FALSE;
  480. dwLength = STRLEN( pAfpIconInfo->afpicon_creator );
  481. if ( ( dwLength == 0 ) || ( dwLength > AFP_CREATOR_LEN ) )
  482. fValid = FALSE;
  483. switch( pAfpIconInfo->afpicon_icontype ) {
  484. case ICONTYPE_SRVR:
  485. case ICONTYPE_ICN:
  486. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICN )
  487. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  488. else
  489. fValid = FALSE;
  490. break;
  491. case ICONTYPE_ICS:
  492. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICS )
  493. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  494. else
  495. fValid = FALSE;
  496. break;
  497. case ICONTYPE_ICN4:
  498. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICN4 )
  499. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  500. else
  501. fValid = FALSE;
  502. break;
  503. case ICONTYPE_ICN8:
  504. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICN8 )
  505. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  506. else
  507. fValid = FALSE;
  508. break;
  509. case ICONTYPE_ICS4:
  510. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICS4 )
  511. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  512. else
  513. fValid = FALSE;
  514. break;
  515. case ICONTYPE_ICS8:
  516. if ( pAfpIconInfo->afpicon_length == ICONSIZE_ICS8 )
  517. pAfpIconInfo->afpicon_data[pAfpIconInfo->afpicon_length-1];
  518. else
  519. fValid = FALSE;
  520. break;
  521. default:
  522. fValid = FALSE;
  523. }
  524. }
  525. except( EXCEPTION_EXECUTE_HANDLER ) {
  526. fValid = FALSE;
  527. }
  528. return( fValid );
  529. }
  530. //**
  531. //
  532. // Call: IsAfpFinderInfoValid
  533. //
  534. // Returns: TRUE - valid
  535. // FALSE - invalid
  536. //
  537. // Description: Validates the Type, Creator, Path and ParmNum values
  538. //
  539. BOOL
  540. IsAfpFinderInfoValid(
  541. IN LPWSTR pType,
  542. IN LPWSTR pCreator,
  543. IN LPWSTR pData,
  544. IN LPWSTR pResource,
  545. IN LPWSTR pPath,
  546. IN DWORD dwParmNum
  547. )
  548. {
  549. BOOL fValid = TRUE;
  550. try {
  551. if ( dwParmNum & ~AFP_FD_PARMNUM_ALL )
  552. return( FALSE );
  553. if ( STRLEN( pPath ) == 0 )
  554. return( FALSE );
  555. if ( pData != NULL ) {
  556. if ( STRLEN( pData ) == 0 )
  557. return( FALSE );
  558. }
  559. if ( pResource != NULL ) {
  560. if ( STRLEN( pResource ) == 0 )
  561. return( FALSE );
  562. }
  563. if ( pType != NULL ) {
  564. if ( ( STRLEN( pType ) == 0 ) ||
  565. ( STRLEN( pType ) > AFP_TYPE_LEN ) )
  566. return( FALSE );
  567. }
  568. if ( pCreator != NULL ) {
  569. if ( ( STRLEN( pCreator ) == 0 ) ||
  570. ( STRLEN( pCreator ) > AFP_CREATOR_LEN ) )
  571. return( FALSE );
  572. }
  573. return( TRUE );
  574. }
  575. except( EXCEPTION_EXECUTE_HANDLER ) {
  576. fValid = FALSE;
  577. }
  578. return( fValid );
  579. }
  580.