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.

3790 lines
97 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. SrvStub.C
  5. Abstract:
  6. These are the server service API RPC client stubs.
  7. Author:
  8. Dan Lafferty (danl) 06-Feb-1991
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 06-Feb-1991 Danl
  13. Created
  14. 07-Jun-1991 JohnRo
  15. Added downlevel support for NetServer APIs.
  16. Added NET_API_FUNCTION where necessary.
  17. 15-Jul-1991 RFirth
  18. Integrated RxNetShare routines into NetShare stubs
  19. 24-Jul-1991 JohnRo
  20. Implement downlevel NetConnectionEnum. Try using <netrpc.h> macros.
  21. 25-Jul-1991 JohnRo
  22. Quiet DLL stub debug output. Use NetRpc.h macros for NetServer APIs.
  23. 06-Sep-1991 JohnRo
  24. Downlevel NetFile APIs.
  25. 25-Sep-1991 JohnRo
  26. Use NetRpc.h macros for all other APIs, to quiet normal debug output.
  27. 07-Oct-1991 JohnRo
  28. RAID 3210: "NET FILE 0" causes assertion. (Was bug in NetFileGetInfo
  29. DLL stub.)
  30. 16-Oct-1991 JohnRo
  31. Implement remote NetSession APIs. Changed LPSTR to LPTSTR.
  32. 07-Nov-1991 JohnRo
  33. RAID 4186: assert in RxNetShareAdd and other DLL stub problems.
  34. 12-Nov-1991 JohnRo
  35. APIs in this file need SERVICE_SERVER started to run locally.
  36. 04-Dec-1991 JohnRo
  37. Change RxNetServerSetInfo() to new-style interface.
  38. Fixed bug in calling RxNetShareSetInfo().
  39. 09-May-1992 rfirth
  40. Resurrect NetStatisticsGet as NetServerStatisticsGet
  41. 5-Aug-1992 JohnsonA
  42. Added new share info level 502 to enable passing of security
  43. descriptors.
  44. 08-Sep-1992 JohnRo
  45. Fix NET_API_FUNCTION references.
  46. --*/
  47. //
  48. // INCLUDES
  49. //
  50. #include <nt.h> // DbgPrint prototype
  51. #include <ntrtl.h> // DbgPrint
  52. #include <rpc.h> // DataTypes and runtime APIs
  53. #include <srvsvc.h> // generated by the MIDL complier
  54. #include <rpcutil.h> // GENERIC_ENUM_STRUCT
  55. #include <lmcons.h> // NET_API_STATUS
  56. #include <debuglib.h> // (needed by netrpc.h)
  57. #include <lmsvc.h> // (needed by netrpc.h)
  58. #include <netdebug.h> // (needed by netrpc.h)
  59. #include <lmerr.h> // NetError codes
  60. #include <netlib.h> // NetpIsServiceStarted().
  61. #include <netlibnt.h> // NetpNtStatusToApiStatus
  62. #include <netrpc.h> // NET_REMOTE_ macros.
  63. #include <lmremutl.h> // SUPPORTS_RPC
  64. #include <lmshare.h> // Required by rxsess.h.
  65. #include <rap.h> // Needed by <rxserver.h>.
  66. #include <rxconn.h> // RxNetConnection routines.
  67. #include <rxfile.h> // RxNetFile routines.
  68. #include <rxremutl.h> // RxNetRemoteTOD
  69. #include <rxserver.h> // RxNetServer routines.
  70. #include <rxsess.h> // RxNetSession routines.
  71. #include <rxshare.h> // RxNetShare routines
  72. #include <icanon.h> // NetpIsRemote
  73. #include <netstats.h> // NetServerStatisticsGet private prototype
  74. #include <rxstats.h> // RxNetStatisticsGet (down-level)
  75. #include <netcan.h> // prototypes for Netps canonicalization functions
  76. #include <rxcanon.h> // prototypes for down-level canonicalization functions
  77. #include <tstr.h>
  78. #include "cscp.h"
  79. #define SET_ERROR_PARAMETER(a) \
  80. if ( ARGUMENT_PRESENT( parm_err ) ) { *parm_err = a; }
  81. NET_API_STATUS NET_API_FUNCTION
  82. NetCharDevControl (
  83. IN LPCWSTR servername,
  84. IN LPCWSTR devname,
  85. IN DWORD opcode
  86. )
  87. /*++
  88. Routine Description:
  89. This is the DLL entrypoint for NetCharDevControl.
  90. Arguments:
  91. servername --A pointer to an ASCIIZ string containing the name of
  92. the remote server on which the function is to execute. A NULL
  93. pointer or string specifies the local machine.
  94. devname --A pointer to the ASCIIZ string containing the name of
  95. the device to control
  96. opcode --Control opcode: currently defined are:
  97. CHARDEV_CLOSE for the device closed.
  98. Return Value:
  99. --*/
  100. {
  101. NET_API_STATUS apiStatus;
  102. NET_REMOTE_TRY_RPC
  103. apiStatus = NetrCharDevControl (
  104. (LPWSTR)servername,
  105. (LPWSTR)devname,
  106. opcode);
  107. NET_REMOTE_RPC_FAILED(
  108. "NetCharDevControl",
  109. servername,
  110. apiStatus,
  111. NET_REMOTE_FLAG_NORMAL,
  112. SERVICE_SERVER)
  113. apiStatus = ERROR_NOT_SUPPORTED;
  114. NET_REMOTE_END
  115. return(apiStatus);
  116. } // NetCharDevControl
  117. NET_API_STATUS NET_API_FUNCTION
  118. NetCharDevEnum (
  119. IN LPCWSTR servername,
  120. IN DWORD level,
  121. OUT LPBYTE *bufptr,
  122. IN DWORD prefmaxlen,
  123. OUT LPDWORD entriesread,
  124. OUT LPDWORD totalentries,
  125. IN OUT LPDWORD resume_handle
  126. )
  127. /*++
  128. Routine Description:
  129. This is the DLL entrypoint for NetCharDevEnum.
  130. Arguments:
  131. servername --A pointer to an ASCIIZ string containing the name of
  132. the remote server on which the function is to execute. A NULL
  133. pointer or string specifies the local machine.
  134. level --Level of information required. 0 and 1 are valid.
  135. bufptr --On return a pointer to the return information structure
  136. is returned in the address pointed to by bufptr.
  137. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  138. bytes). 0xffffffff specifies no limit.
  139. entriesread --On return the actual enumerated element count is
  140. located in the DWORD pointed to by entriesread.
  141. totalentries --On return the total entries available to be
  142. enumerated is located in the DWORD pointed to by
  143. totalentries.
  144. resumehandle --On return, a resume handle is stored in the DWORD
  145. pointed to by resumehandle, and is used to continue an
  146. existing character device search. The handle should be zero
  147. on the first call and left unchanged for subsequent calls. If
  148. resumehandle is NULL, then no resume handle is stored..
  149. Return Value:
  150. --*/
  151. {
  152. NET_API_STATUS apiStatus;
  153. GENERIC_INFO_CONTAINER genericInfoContainer;
  154. GENERIC_ENUM_STRUCT infoStruct;
  155. genericInfoContainer.Buffer = NULL;
  156. genericInfoContainer.EntriesRead = 0;
  157. infoStruct.Container = &genericInfoContainer;
  158. infoStruct.Level = level;
  159. NET_REMOTE_TRY_RPC
  160. apiStatus = NetrCharDevEnum (
  161. (LPWSTR)servername,
  162. (LPCHARDEV_ENUM_STRUCT)&infoStruct,
  163. prefmaxlen,
  164. totalentries,
  165. resume_handle);
  166. if (genericInfoContainer.Buffer != NULL) {
  167. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  168. *entriesread = genericInfoContainer.EntriesRead;
  169. } else {
  170. *bufptr = NULL;
  171. *entriesread = 0;
  172. }
  173. NET_REMOTE_RPC_FAILED(
  174. "NetCharDevEnum",
  175. servername,
  176. apiStatus,
  177. NET_REMOTE_FLAG_NORMAL,
  178. SERVICE_SERVER)
  179. apiStatus = ERROR_NOT_SUPPORTED;
  180. NET_REMOTE_END
  181. if ( apiStatus == ERROR_SUCCESS ) {
  182. if (bufptr == NULL) {
  183. return RPC_X_BAD_STUB_DATA;
  184. }
  185. }
  186. return(apiStatus);
  187. } // NetCharDevEnum
  188. NET_API_STATUS NET_API_FUNCTION
  189. NetCharDevGetInfo (
  190. IN LPCWSTR servername,
  191. IN LPCWSTR devname,
  192. IN DWORD level,
  193. OUT LPBYTE *bufptr
  194. )
  195. /*++
  196. Routine Description:
  197. This is the DLL entrypoint for NetCharDevGetInfo.
  198. Arguments:
  199. servername --A pointer to an ASCIIZ string containing the name of
  200. the remote server on which the function is to execute. A NULL
  201. pointer or string specifies the local machine.
  202. devname --A pointer to the ASCIIZ string containing the name of
  203. the device to return information on.
  204. level --Level of information required. 0 and 1 are valid.
  205. bufptr --On return a pointer to the return information structure
  206. is returned in the address pointed to by bufptr.
  207. Return Value:
  208. --*/
  209. {
  210. NET_API_STATUS apiStatus;
  211. *bufptr = NULL; // Must be NULL so RPC knows to till it in.
  212. NET_REMOTE_TRY_RPC
  213. apiStatus = NetrCharDevGetInfo (
  214. (LPWSTR)servername,
  215. (LPWSTR)devname,
  216. level,
  217. (LPCHARDEV_INFO) bufptr);
  218. NET_REMOTE_RPC_FAILED(
  219. "NetCharDevGetInfo",
  220. servername,
  221. apiStatus,
  222. NET_REMOTE_FLAG_NORMAL,
  223. SERVICE_SERVER)
  224. apiStatus = ERROR_NOT_SUPPORTED;
  225. NET_REMOTE_END
  226. if ( apiStatus == ERROR_SUCCESS ) {
  227. if (bufptr == NULL) {
  228. return RPC_X_BAD_STUB_DATA;
  229. }
  230. }
  231. return(apiStatus);
  232. } // NetCharDevGetInfo
  233. NET_API_STATUS NET_API_FUNCTION
  234. NetCharDevQEnum (
  235. IN LPCWSTR servername,
  236. IN LPCWSTR username,
  237. IN DWORD level,
  238. OUT LPBYTE *bufptr,
  239. IN DWORD prefmaxlen,
  240. OUT LPDWORD entriesread,
  241. OUT LPDWORD totalentries,
  242. IN OUT LPDWORD resume_handle
  243. )
  244. /*++
  245. Routine Description:
  246. This is the DLL entrypoint for NetCharDevQEnum.
  247. Arguments:
  248. servername --A pointer to an ASCIIZ string containing the name of
  249. the remote server on which the function is to execute. A NULL
  250. pointer or string specifies the local machine.
  251. username --A pointer to an ASCIIZ string containing an a username
  252. for the active queues of interest. This parameter is
  253. optional, if NULL then all device queues are enumerated.
  254. level --Level of information required. 0 and 1 are valid.
  255. bufptr --On return a pointer to the return information structure
  256. is returned in the address pointed to by bufptr.
  257. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  258. bytes). 0xffffffff specifies no limit.
  259. entriesread --On return the actual enumerated element count is
  260. located in the DWORD pointed to by entriesread.
  261. totalentries --On return the total entries available to be
  262. enumerated is located in the DWORD pointed to by
  263. totalentries.
  264. resumehandle --On return, a resume handle is stored in the DWORD
  265. pointed to by resumehandle, and is used to continue an
  266. existing character device queue search. The handle should be
  267. Return Value:
  268. --*/
  269. {
  270. NET_API_STATUS apiStatus;
  271. GENERIC_INFO_CONTAINER genericInfoContainer;
  272. GENERIC_ENUM_STRUCT infoStruct;
  273. genericInfoContainer.Buffer = NULL;
  274. genericInfoContainer.EntriesRead = 0;
  275. infoStruct.Container = &genericInfoContainer;
  276. infoStruct.Level = level;
  277. NET_REMOTE_TRY_RPC
  278. apiStatus = NetrCharDevQEnum (
  279. (LPWSTR)servername,
  280. (LPWSTR)username,
  281. (LPCHARDEVQ_ENUM_STRUCT) &infoStruct,
  282. prefmaxlen,
  283. totalentries,
  284. resume_handle);
  285. if (genericInfoContainer.Buffer != NULL) {
  286. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  287. *entriesread = genericInfoContainer.EntriesRead;
  288. } else {
  289. *bufptr = NULL;
  290. *entriesread = 0;
  291. }
  292. NET_REMOTE_RPC_FAILED(
  293. "NetCharDevQEnum",
  294. servername,
  295. apiStatus,
  296. NET_REMOTE_FLAG_NORMAL,
  297. SERVICE_SERVER)
  298. apiStatus = ERROR_NOT_SUPPORTED;
  299. NET_REMOTE_END
  300. if ( apiStatus == ERROR_SUCCESS ) {
  301. if (bufptr == NULL) {
  302. return RPC_X_BAD_STUB_DATA;
  303. }
  304. }
  305. return(apiStatus);
  306. } // NetCharDevQEnum
  307. NET_API_STATUS NET_API_FUNCTION
  308. NetCharDevQGetInfo (
  309. IN LPCWSTR servername,
  310. IN LPCWSTR queuename,
  311. IN LPCWSTR username,
  312. IN DWORD level,
  313. OUT LPBYTE *bufptr
  314. )
  315. /*++
  316. Routine Description:
  317. This is the DLL entrypoint for NetCharDevQGetInfo.
  318. Arguments:
  319. servername --A pointer to an ASCIIZ string containing the name of
  320. the remote server on which the function is to execute. A NULL
  321. pointer or string specifies the local machine.
  322. queuename --A pointer to an ASCIIZ string containing the name of
  323. the queue to return information on.
  324. username --A pointer to an ASCIIZ string containing the username
  325. of the a user whose job of of interest for the cq1_numahead
  326. count.
  327. level --Level of information required. 0 and 1 are valid.
  328. bufptr --On return a pointer to the return information structure
  329. is returned in the address pointed to by bufptr.
  330. Return Value:
  331. --*/
  332. {
  333. NET_API_STATUS apiStatus;
  334. *bufptr = NULL; // Must be NULL so RPC knows to till it in.
  335. NET_REMOTE_TRY_RPC
  336. apiStatus = NetrCharDevQGetInfo (
  337. (LPWSTR)servername,
  338. (LPWSTR)queuename,
  339. (LPWSTR)username,
  340. level,
  341. (LPCHARDEVQ_INFO) bufptr);
  342. NET_REMOTE_RPC_FAILED(
  343. "NetCharDevQGetInfo",
  344. servername,
  345. apiStatus,
  346. NET_REMOTE_FLAG_NORMAL,
  347. SERVICE_SERVER)
  348. apiStatus = ERROR_NOT_SUPPORTED;
  349. NET_REMOTE_END
  350. if ( apiStatus == ERROR_SUCCESS ) {
  351. if (bufptr == NULL) {
  352. return RPC_X_BAD_STUB_DATA;
  353. }
  354. }
  355. return(apiStatus);
  356. } // NetCharDevQGetInfo
  357. NET_API_STATUS NET_API_FUNCTION
  358. NetCharDevQPurge (
  359. IN LPCWSTR servername,
  360. IN LPCWSTR queuename
  361. )
  362. /*++
  363. Routine Description:
  364. This is the DLL entrypoint for NetCharDevQPurge.
  365. Arguments:
  366. servername --A pointer to an ASCIIZ string containing the name of
  367. the remote server on which the function is to execute. A NULL
  368. pointer or string specifies the local machine.
  369. queuename --A pointer to an ASCIIZ string containing the name of
  370. the queue to be purged.
  371. Return Value:
  372. --*/
  373. {
  374. NET_API_STATUS apiStatus;
  375. NET_REMOTE_TRY_RPC
  376. apiStatus = NetrCharDevQPurge (
  377. (LPWSTR)servername,
  378. (LPWSTR)queuename);
  379. NET_REMOTE_RPC_FAILED(
  380. "NetCharDevQPurge",
  381. servername,
  382. apiStatus,
  383. NET_REMOTE_FLAG_NORMAL,
  384. SERVICE_SERVER)
  385. apiStatus = ERROR_NOT_SUPPORTED;
  386. NET_REMOTE_END
  387. return(apiStatus);
  388. } // NetCharDevQPurge
  389. NET_API_STATUS NET_API_FUNCTION
  390. NetCharDevQPurgeSelf (
  391. IN LPCWSTR servername,
  392. IN LPCWSTR queuename,
  393. IN LPCWSTR computername
  394. )
  395. /*++
  396. Routine Description:
  397. This is the DLL entrypoint for NetCharDevQPurgeSelf.
  398. Arguments:
  399. servername --A pointer to an ASCIIZ string containing the name of
  400. the remote server on which the function is to execute. A NULL
  401. pointer or string specifies the local machine.
  402. queuename --A pointer to an ASCIIZ string containing the name of
  403. the queue to be purged of pending entries from the specified
  404. computer.
  405. Return Value:
  406. --*/
  407. {
  408. NET_API_STATUS apiStatus;
  409. NET_REMOTE_TRY_RPC
  410. apiStatus = NetrCharDevQPurgeSelf (
  411. (LPWSTR)servername,
  412. (LPWSTR)queuename,
  413. (LPWSTR)computername);
  414. NET_REMOTE_RPC_FAILED(
  415. "NetCharDevQPurgeSelf",
  416. servername,
  417. apiStatus,
  418. NET_REMOTE_FLAG_NORMAL,
  419. SERVICE_SERVER)
  420. apiStatus = ERROR_NOT_SUPPORTED;
  421. NET_REMOTE_END
  422. return(apiStatus);
  423. } // NetCharDevQPurgeSelf
  424. NET_API_STATUS NET_API_FUNCTION
  425. NetCharDevQSetInfo (
  426. IN LPCWSTR servername,
  427. IN LPCWSTR queuename,
  428. IN DWORD level,
  429. IN LPBYTE buf,
  430. OUT LPDWORD parm_err
  431. )
  432. /*++
  433. Routine Description:
  434. This is the DLL entrypoint for NetCharDevQSetInfo.
  435. Arguments:
  436. servername --A pointer to an ASCIIZ string containing the name of
  437. the remote server on which the function is to execute. A NULL
  438. pointer or string specifies the local machine.
  439. queuename --A pointer to an ASCIIZ string containing the name of
  440. the queue to set information on.
  441. level --Level of information to set.
  442. buf --A pointer to a buffer containing the chardev information.
  443. If parmnum is non zero then the buffer contains only the
  444. appropriate data for the specific element. If parmnum is
  445. zero, then the buffer contains the whole chardev information
  446. structure.
  447. parm_err --Optional pointer to a DWORD to return the index of the
  448. first parameter in error when ERROR_INVALID_PARAMETER is
  449. returned. If NULL the parameter is not returned on error.
  450. Return Value:
  451. --*/
  452. {
  453. NET_API_STATUS apiStatus;
  454. NET_REMOTE_TRY_RPC
  455. apiStatus = NetrCharDevQSetInfo (
  456. (LPWSTR)servername,
  457. (LPWSTR)queuename,
  458. level,
  459. (LPCHARDEVQ_INFO) &buf,
  460. parm_err);
  461. NET_REMOTE_RPC_FAILED(
  462. "NetCharDevQSetInfo",
  463. servername,
  464. apiStatus,
  465. NET_REMOTE_FLAG_NORMAL,
  466. SERVICE_SERVER)
  467. apiStatus = ERROR_NOT_SUPPORTED;
  468. NET_REMOTE_END
  469. return(apiStatus);
  470. } // NetCharDevQSetInfo
  471. NET_API_STATUS NET_API_FUNCTION
  472. NetConnectionEnum (
  473. IN LPTSTR servername,
  474. IN LPTSTR qualifier,
  475. IN DWORD level,
  476. OUT LPBYTE *bufptr,
  477. IN DWORD prefmaxlen,
  478. OUT LPDWORD entriesread,
  479. OUT LPDWORD totalentries,
  480. IN OUT LPDWORD resume_handle
  481. )
  482. /*++
  483. Routine Description:
  484. This is the DLL entrypoint for NetConnectionEnum.
  485. Arguments:
  486. servername --A pointer to an ASCIIZ string containing the name of
  487. the remote server on which the function is to execute. A NULL
  488. pointer or string specifies the local machine.
  489. qualifier --A pointer to an ASCIIZ string containing a sharename
  490. or computername for the connections of interest. If it is a
  491. sharename, then all the connections made to that sharename
  492. are listed. If it is a computername (i.e. it starts with two
  493. backslash characters), then NetConnectionEnum lists all
  494. connections made from that computer to the server specified.
  495. level --Level of information required. 0 and 1 are valid.
  496. bufptr --On return a pointer to the return information structure
  497. is returned in the address pointed to by bufptr.
  498. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  499. bytes). 0xffffffff specifies no limit.
  500. entriesread --On return the actual enumerated element count is
  501. located in the DWORD pointed to by entriesread.
  502. Return Value:
  503. --*/
  504. {
  505. NET_API_STATUS apiStatus;
  506. GENERIC_INFO_CONTAINER genericInfoContainer;
  507. GENERIC_ENUM_STRUCT infoStruct;
  508. genericInfoContainer.Buffer = NULL;
  509. genericInfoContainer.EntriesRead = 0;
  510. infoStruct.Container = &genericInfoContainer;
  511. infoStruct.Level = level;
  512. NET_REMOTE_TRY_RPC
  513. apiStatus = NetrConnectionEnum (
  514. servername,
  515. qualifier,
  516. (LPCONNECT_ENUM_STRUCT)&infoStruct,
  517. prefmaxlen,
  518. totalentries,
  519. resume_handle);
  520. if (genericInfoContainer.Buffer != NULL) {
  521. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  522. *entriesread = genericInfoContainer.EntriesRead;
  523. } else {
  524. *bufptr = NULL;
  525. *entriesread = 0;
  526. }
  527. NET_REMOTE_RPC_FAILED(
  528. "NetConnectionEnum",
  529. servername,
  530. apiStatus,
  531. NET_REMOTE_FLAG_NORMAL,
  532. SERVICE_SERVER)
  533. //
  534. // Try call to downlevel.
  535. //
  536. apiStatus = RxNetConnectionEnum(
  537. servername,
  538. qualifier,
  539. level,
  540. bufptr,
  541. prefmaxlen,
  542. entriesread,
  543. totalentries,
  544. resume_handle
  545. );
  546. NET_REMOTE_END
  547. if ( apiStatus == ERROR_SUCCESS ) {
  548. if (bufptr == NULL) {
  549. return RPC_X_BAD_STUB_DATA;
  550. }
  551. }
  552. return(apiStatus);
  553. } // NetConnectionEnum
  554. NET_API_STATUS NET_API_FUNCTION
  555. NetFileClose (
  556. IN LPTSTR servername,
  557. IN DWORD fileid
  558. )
  559. /*++
  560. Routine Description:
  561. This is the DLL entrypoint for NetFileClose.
  562. Arguments:
  563. servername --A pointer to an ASCIIZ string containing the name of
  564. the remote server on which the function is to execute. A NULL
  565. pointer or string specifies the local machine.
  566. fileid --The fileid of the opened resource instance to be closed.
  567. Return Value:
  568. --*/
  569. {
  570. NET_API_STATUS apiStatus;
  571. NET_REMOTE_TRY_RPC
  572. apiStatus = NetrFileClose (
  573. servername,
  574. fileid);
  575. NET_REMOTE_RPC_FAILED(
  576. "NetFileClose",
  577. servername,
  578. apiStatus,
  579. NET_REMOTE_FLAG_NORMAL,
  580. SERVICE_SERVER)
  581. apiStatus = RxNetFileClose (
  582. servername,
  583. fileid);
  584. NET_REMOTE_END
  585. return(apiStatus);
  586. }
  587. NET_API_STATUS NET_API_FUNCTION
  588. NetFileEnum (
  589. IN LPTSTR servername,
  590. IN LPTSTR basepath,
  591. IN LPTSTR username,
  592. IN DWORD level,
  593. OUT LPBYTE *bufptr,
  594. IN DWORD prefmaxlen,
  595. OUT LPDWORD entriesread,
  596. OUT LPDWORD totalentries,
  597. IN OUT PDWORD_PTR resume_handle
  598. )
  599. /*++
  600. Routine Description:
  601. This is the DLL entrypoint for NetFileEnum.
  602. Arguments:
  603. servername --A pointer to an ASCIIZ string containing the name of
  604. the remote server on which the function is to execute. A NULL
  605. pointer or string specifies the local machine.
  606. basepath --A pointer to an ASCIIZ string containing a qualifier
  607. for the returned information. If NULL then all open resources
  608. are enumerated, else only resources which have basepath as a
  609. prefix are enumerated.
  610. username --A pointer to an ASCIIZ string that specifies the name
  611. of the user. If not NULL, username serves as a qualifier to
  612. the ennumeration. The files returned are limited to those
  613. that have usernames matching the qualifier. If username is
  614. NULL, no username qualifier is used.
  615. level --Level of information required. 2 and 3 are valid.
  616. bufptr --On return a pointer to the return information structure
  617. is returned in the address pointed to by bufptr.
  618. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  619. bytes). 0xffffffff specifies no limit.
  620. entriesread --On return the actual enumerated element count is
  621. located in the DWORD pointed to by entriesread.
  622. totalentries --On return the total entries available to be
  623. enumerated is located in the DWORD pointed to by
  624. totalentries.
  625. resumehandle --On return, a resume handle is stored in the DWORD
  626. pointed to by resumehandle, and is used to continue an
  627. existing file search. The handle should be zero on the first
  628. call and left unchanged for subsequent calls. If resumehandle
  629. is NULL, then no resume handle is stored..
  630. Return Value:
  631. --*/
  632. {
  633. NET_API_STATUS apiStatus;
  634. GENERIC_INFO_CONTAINER genericInfoContainer;
  635. GENERIC_ENUM_STRUCT infoStruct;
  636. genericInfoContainer.Buffer = NULL;
  637. genericInfoContainer.EntriesRead = 0;
  638. infoStruct.Container = &genericInfoContainer;
  639. infoStruct.Level = level;
  640. NET_REMOTE_TRY_RPC
  641. //
  642. // NetrFileEnum's resume_handle parm is a true index that will remain
  643. // 32 bits wide for on-the-wire compatibility. Thus, the cast to
  644. // (PDWORD) here works.
  645. //
  646. apiStatus = NetrFileEnum (
  647. servername,
  648. basepath,
  649. username,
  650. (LPFILE_ENUM_STRUCT) &infoStruct,
  651. prefmaxlen,
  652. totalentries,
  653. (PDWORD)resume_handle);
  654. if (genericInfoContainer.Buffer != NULL) {
  655. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  656. *entriesread = genericInfoContainer.EntriesRead;
  657. } else {
  658. *bufptr = NULL;
  659. *entriesread = 0;
  660. }
  661. NET_REMOTE_RPC_FAILED(
  662. "NetFileEnum",
  663. servername,
  664. apiStatus,
  665. NET_REMOTE_FLAG_NORMAL,
  666. SERVICE_SERVER)
  667. apiStatus = RxNetFileEnum(
  668. servername,
  669. basepath,
  670. username,
  671. level,
  672. bufptr,
  673. prefmaxlen,
  674. entriesread,
  675. totalentries,
  676. resume_handle);
  677. NET_REMOTE_END
  678. if ( apiStatus == ERROR_SUCCESS ) {
  679. if (bufptr == NULL) {
  680. return RPC_X_BAD_STUB_DATA;
  681. }
  682. }
  683. return(apiStatus);
  684. } // NetFileEnum
  685. NET_API_STATUS NET_API_FUNCTION
  686. NetFileGetInfo (
  687. IN LPTSTR servername,
  688. IN DWORD fileid,
  689. IN DWORD level,
  690. OUT LPBYTE *bufptr
  691. )
  692. /*++
  693. Routine Description:
  694. This is the DLL entrypoint for NetFileGetInfo.
  695. Arguments:
  696. servername --A pointer to an ASCIIZ string containing the name of
  697. the remote server on which the function is to execute. A NULL
  698. pointer or string specifies the local machine.
  699. fileid --The fileid of the open resource to return information
  700. on. The fileid value must be that returned in a previous
  701. enumeration call.
  702. level --Level of information required. 2 and 3 are valid.
  703. bufptr --On return a pointer to the return information structure
  704. is returned in the address pointed to by bufptr.
  705. Return Value:
  706. --*/
  707. {
  708. NET_API_STATUS apiStatus;
  709. *bufptr = NULL; // Must be NULL so RPC knows to fill it in.
  710. NET_REMOTE_TRY_RPC
  711. apiStatus = NetrFileGetInfo (
  712. servername,
  713. fileid,
  714. level,
  715. (LPFILE_INFO) bufptr);
  716. NET_REMOTE_RPC_FAILED(
  717. "NetFileGetInfo",
  718. servername,
  719. apiStatus,
  720. NET_REMOTE_FLAG_NORMAL,
  721. SERVICE_SERVER)
  722. apiStatus = RxNetFileGetInfo (
  723. servername,
  724. fileid,
  725. level,
  726. bufptr);
  727. NET_REMOTE_END
  728. if ( apiStatus == ERROR_SUCCESS ) {
  729. if (bufptr == NULL) {
  730. return RPC_X_BAD_STUB_DATA;
  731. }
  732. }
  733. return(apiStatus);
  734. } // NetFileGetInfo
  735. NET_API_STATUS NET_API_FUNCTION
  736. NetSessionDel (
  737. IN LPTSTR servername,
  738. IN LPTSTR clientname,
  739. IN LPTSTR username
  740. )
  741. /*++
  742. Routine Description:
  743. This is the DLL entrypoint for NetSessionDel.
  744. Arguments:
  745. servername --A pointer to an ASCIIZ string containing the name of
  746. the remote server on which the function is to execute. A NULL
  747. pointer or string specifies the local machine.
  748. clientname --A pointer to an ASCIIZ string containing the
  749. computername of the client to disconnect.
  750. username --A pointer to an ASCIIZ string containing the name of
  751. the user whose session is to be terminated. A NULL indicates
  752. that all users' sessions from the computername specified are
  753. to be terminated.
  754. Return Value:
  755. --*/
  756. {
  757. NET_API_STATUS apiStatus;
  758. NET_REMOTE_TRY_RPC
  759. apiStatus = NetrSessionDel (
  760. servername,
  761. clientname,
  762. username);
  763. NET_REMOTE_RPC_FAILED("NetSessionDel", servername, apiStatus,
  764. NET_REMOTE_FLAG_NORMAL,
  765. SERVICE_SERVER )
  766. //
  767. // Call downlevel version of the API.
  768. //
  769. apiStatus = RxNetSessionDel (
  770. servername,
  771. clientname,
  772. username);
  773. NET_REMOTE_END
  774. return(apiStatus);
  775. } // NetSessionDel
  776. NET_API_STATUS NET_API_FUNCTION
  777. NetSessionEnum (
  778. IN LPTSTR servername,
  779. IN LPTSTR clientname,
  780. IN LPTSTR username,
  781. IN DWORD level,
  782. OUT LPBYTE *bufptr,
  783. IN DWORD prefmaxlen,
  784. OUT LPDWORD entriesread,
  785. OUT LPDWORD totalentries,
  786. IN OUT LPDWORD resume_handle
  787. )
  788. /*++
  789. Routine Description:
  790. This is the DLL entrypoint for NetSessionEnum.
  791. Arguments:
  792. servername --A pointer to an ASCIIZ string containing the name of
  793. the remote server on which the function is to execute. A NULL
  794. pointer or string specifies the local machine.
  795. clientname --A pointer to an ASCIIZ string containing the name of
  796. the computer session for which information is to be returned.
  797. A NULL pointer or string specifies that all computer sessions
  798. on the server are to be ennumerated.
  799. username --A pointer to an ASCIIZ string containing the name of
  800. the the user for which to ennumerate the sessions. A NULL
  801. pointer or string specifies that sessions for all users are
  802. to be ennumerated.
  803. level --Level of information required. 0, 1, 2 and 10 are valid.
  804. bufptr --On return a pointer to the return information structure
  805. is returned in the address pointed to by bufptr.
  806. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  807. bytes). 0xffffffff specifies no limit.
  808. entriesread --On return the actual enumerated element count is
  809. located in the DWORD pointed to by entriesread.
  810. totalentries --On return the total entries available to be
  811. enumerated is located in the DWORD pointed to by
  812. totalentries.
  813. resumehandle --On return, a resume handle is stored in the DWORD
  814. pointed to by resumehandle, and is used to continue an
  815. existing session search. The handle should be zero on the
  816. first call and left unchanged for subsequent calls. If
  817. resumehandle is NULL, then no resume handle is stored.
  818. Return Value:
  819. --*/
  820. {
  821. NET_API_STATUS apiStatus;
  822. GENERIC_INFO_CONTAINER genericInfoContainer;
  823. GENERIC_ENUM_STRUCT infoStruct;
  824. genericInfoContainer.Buffer = NULL;
  825. genericInfoContainer.EntriesRead = 0;
  826. infoStruct.Container = &genericInfoContainer;
  827. infoStruct.Level = level;
  828. NET_REMOTE_TRY_RPC
  829. apiStatus = NetrSessionEnum (
  830. servername,
  831. clientname,
  832. username,
  833. (PSESSION_ENUM_STRUCT) &infoStruct,
  834. prefmaxlen,
  835. totalentries,
  836. resume_handle);
  837. if (genericInfoContainer.Buffer != NULL) {
  838. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  839. *entriesread = genericInfoContainer.EntriesRead;
  840. } else {
  841. *bufptr = NULL;
  842. *entriesread = 0;
  843. }
  844. NET_REMOTE_RPC_FAILED("NetSessionEnum", servername, apiStatus,
  845. NET_REMOTE_FLAG_NORMAL,
  846. SERVICE_SERVER )
  847. //
  848. // Call downlevel version of the API.
  849. //
  850. apiStatus = RxNetSessionEnum (
  851. servername,
  852. clientname,
  853. username,
  854. level,
  855. bufptr,
  856. prefmaxlen,
  857. entriesread,
  858. totalentries,
  859. resume_handle);
  860. NET_REMOTE_END
  861. if ( apiStatus == ERROR_SUCCESS ) {
  862. if (bufptr == NULL) {
  863. return RPC_X_BAD_STUB_DATA;
  864. }
  865. }
  866. return(apiStatus);
  867. } // NetSessionEnum
  868. NET_API_STATUS NET_API_FUNCTION
  869. NetSessionGetInfo (
  870. IN LPTSTR servername,
  871. IN LPTSTR clientname,
  872. IN LPTSTR username,
  873. IN DWORD level,
  874. OUT LPBYTE *bufptr
  875. )
  876. /*++
  877. Routine Description:
  878. This is the DLL entrypoint for NetSessionEnum.
  879. Arguments:
  880. servername --A pointer to an ASCIIZ string containing the name of
  881. the remote server on which the function is to execute. A NULL
  882. pointer or string specifies the local machine.
  883. clientname --A pointer to an ASCIIZ string containing the name of
  884. the computer session for which information is to be returned.
  885. This field cannot be NULL.
  886. username --A pointer to an ASCIIZ string containing the name of
  887. the the user for which to ennumerate the sessions. This field
  888. cannot be NULL.
  889. level --Level of information required. 0, 1, 2 and 10 are valid.
  890. bufptr --On return a pointer to the return information structure
  891. is returned in the address pointed to by bufptr.
  892. Return Value:
  893. --*/
  894. {
  895. NET_API_STATUS apiStatus;
  896. GENERIC_INFO_CONTAINER genericInfoContainer;
  897. GENERIC_ENUM_STRUCT infoStruct;
  898. DWORD totalentries;
  899. if ( clientname == NULL || username == NULL ) {
  900. return ERROR_INVALID_PARAMETER;
  901. }
  902. genericInfoContainer.Buffer = NULL;
  903. genericInfoContainer.EntriesRead = 0;
  904. infoStruct.Container = &genericInfoContainer;
  905. infoStruct.Level = level;
  906. NET_REMOTE_TRY_RPC
  907. apiStatus = NetrSessionEnum (
  908. servername,
  909. clientname,
  910. username,
  911. (PSESSION_ENUM_STRUCT) &infoStruct,
  912. (DWORD)-1,
  913. &totalentries,
  914. NULL);
  915. if (genericInfoContainer.Buffer != NULL) {
  916. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  917. } else {
  918. *bufptr = NULL;
  919. if ( apiStatus == NO_ERROR ) {
  920. return NERR_ClientNameNotFound;
  921. }
  922. }
  923. NET_REMOTE_RPC_FAILED("NetSessionGetInfo", servername, apiStatus,
  924. NET_REMOTE_FLAG_NORMAL,
  925. SERVICE_SERVER )
  926. //
  927. // Call downlevel version of the API.
  928. //
  929. apiStatus = RxNetSessionGetInfo (
  930. servername,
  931. clientname,
  932. username,
  933. level,
  934. bufptr);
  935. NET_REMOTE_END
  936. if ( apiStatus == ERROR_SUCCESS ) {
  937. if (bufptr == NULL) {
  938. return RPC_X_BAD_STUB_DATA;
  939. }
  940. }
  941. return(apiStatus);
  942. } // NetSessionGetInfo
  943. NET_API_STATUS NET_API_FUNCTION
  944. NetShareAdd (
  945. IN LPTSTR servername,
  946. IN DWORD level,
  947. IN LPBYTE buf,
  948. OUT LPDWORD parm_err
  949. )
  950. /*++
  951. Routine Description:
  952. This is the DLL entrypoint for NetShareAdd. Only levels 2 and 502
  953. are allowed.
  954. Arguments:
  955. servername --A pointer to an ASCIIZ string containing the name of
  956. the remote server on which the function is to execute. A NULL
  957. pointer or string specifies the local machine.
  958. level --Level of information provided. Must be 2.
  959. buf --A pointer to a buffer containing the share information
  960. structure.
  961. parm_err --Optional pointer to a DWORD to return the index of the
  962. first parameter in error when ERROR_INVALID_PARAMETER is
  963. returned. If NULL the parameter is not returned on error.
  964. Return Value:
  965. --*/
  966. {
  967. NET_API_STATUS apiStatus;
  968. NTSTATUS status;
  969. ULONG SDLength = 0;
  970. ULONG oldSDLength;
  971. PSECURITY_DESCRIPTOR securityDescriptor = NULL;
  972. PSECURITY_DESCRIPTOR oldSecurityDescriptor = NULL;
  973. //
  974. // do the parameter validation here - this way we only need do it once and
  975. // in a centralized place
  976. //
  977. if (level != 2 && level != 502) {
  978. return ERROR_INVALID_LEVEL;
  979. }
  980. NET_REMOTE_TRY_RPC
  981. if ( level == 502 ) {
  982. PSHARE_INFO_502 shi502 = (LPSHARE_INFO_502) buf;
  983. //
  984. // Save this. We need to restore this later.
  985. //
  986. oldSecurityDescriptor = shi502->shi502_security_descriptor;
  987. oldSDLength = shi502->shi502_reserved;
  988. if ( oldSecurityDescriptor != NULL ) {
  989. if ( !RtlValidSecurityDescriptor( oldSecurityDescriptor) ) {
  990. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  991. return ERROR_INVALID_PARAMETER;
  992. }
  993. //
  994. // Make a self relative security descriptor for use in the
  995. // RPC call..
  996. //
  997. status = RtlMakeSelfRelativeSD(
  998. oldSecurityDescriptor,
  999. NULL,
  1000. &SDLength
  1001. );
  1002. if (status != STATUS_BUFFER_TOO_SMALL) {
  1003. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  1004. return(ERROR_INVALID_PARAMETER);
  1005. } else {
  1006. securityDescriptor = MIDL_user_allocate( SDLength );
  1007. if ( securityDescriptor == NULL) {
  1008. return ERROR_NOT_ENOUGH_MEMORY;
  1009. } else {
  1010. //
  1011. // make an appropriate self-relative security descriptor
  1012. //
  1013. status = RtlMakeSelfRelativeSD(
  1014. oldSecurityDescriptor,
  1015. (PSECURITY_DESCRIPTOR) securityDescriptor,
  1016. &SDLength
  1017. );
  1018. if ( !NT_SUCCESS(status) ) {
  1019. MIDL_user_free( securityDescriptor );
  1020. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  1021. return(ERROR_INVALID_PARAMETER);
  1022. }
  1023. shi502->shi502_security_descriptor = securityDescriptor;
  1024. shi502->shi502_reserved = SDLength;
  1025. }
  1026. }
  1027. } else {
  1028. shi502->shi502_reserved = 0;
  1029. }
  1030. }
  1031. apiStatus = NetrShareAdd (
  1032. servername,
  1033. level,
  1034. (LPSHARE_INFO) &buf,
  1035. parm_err);
  1036. if ( securityDescriptor != NULL ) {
  1037. //
  1038. // restore old values
  1039. //
  1040. PSHARE_INFO_502 shi502 = (LPSHARE_INFO_502) buf;
  1041. shi502->shi502_security_descriptor = oldSecurityDescriptor;
  1042. shi502->shi502_reserved = oldSDLength;
  1043. MIDL_user_free( securityDescriptor );
  1044. }
  1045. NET_REMOTE_RPC_FAILED(
  1046. "NetShareAdd",
  1047. servername,
  1048. apiStatus,
  1049. NET_REMOTE_FLAG_NORMAL,
  1050. SERVICE_SERVER)
  1051. //
  1052. // Call downlevel server.
  1053. //
  1054. if ( level != 502 ) {
  1055. apiStatus = RxNetShareAdd(
  1056. servername,
  1057. 2,
  1058. buf,
  1059. parm_err
  1060. );
  1061. } else {
  1062. apiStatus = ERROR_NOT_SUPPORTED;
  1063. }
  1064. NET_REMOTE_END
  1065. return(apiStatus);
  1066. } // NetShareAdd
  1067. NET_API_STATUS NET_API_FUNCTION
  1068. NetShareCheck (
  1069. IN LPTSTR servername,
  1070. IN LPTSTR device,
  1071. OUT LPDWORD type
  1072. )
  1073. /*++
  1074. Routine Description:
  1075. This is the DLL entrypoint for NetShareCheck
  1076. Arguments:
  1077. servername --A pointer to an ASCIIZ string containing the name of
  1078. the remote server on which the function is to execute. A NULL
  1079. pointer or string specifies the local machine.
  1080. device --A pointer to an ASCIIZ string containing the name of the
  1081. device to check for shared access.
  1082. type --On return the address pointed to by the type parameter
  1083. contains the type of share the device is offered with. This
  1084. field is only set if success was returned.
  1085. Return Value:
  1086. --*/
  1087. {
  1088. NET_API_STATUS apiStatus;
  1089. if (!(device && *device) || !type) {
  1090. return ERROR_INVALID_PARAMETER;
  1091. }
  1092. NET_REMOTE_TRY_RPC
  1093. apiStatus = NetrShareCheck (
  1094. servername,
  1095. device,
  1096. type);
  1097. NET_REMOTE_RPC_FAILED(
  1098. "NetShareCheck",
  1099. servername,
  1100. apiStatus,
  1101. NET_REMOTE_FLAG_NORMAL,
  1102. SERVICE_SERVER)
  1103. //
  1104. // Call downlevel server.
  1105. //
  1106. apiStatus = RxNetShareCheck(servername, device, type);
  1107. NET_REMOTE_END
  1108. return(apiStatus);
  1109. } // NetShareCheck
  1110. NET_API_STATUS NET_API_FUNCTION
  1111. NetShareDel (
  1112. IN LPTSTR servername,
  1113. IN LPTSTR netname,
  1114. IN DWORD reserved
  1115. )
  1116. /*++
  1117. Routine Description:
  1118. This is the DLL entrypoint for NetShareDel.
  1119. Arguments:
  1120. servername --A pointer to an ASCIIZ string containing the name of
  1121. the remote server on which the function is to execute. A NULL
  1122. pointer or string specifies the local machine.
  1123. netname --A pointer to an ASCIIZ string containing the netname of
  1124. the share to delete.
  1125. reserved --Reserved, must be zero.
  1126. Return Value:
  1127. --*/
  1128. {
  1129. NET_API_STATUS apiStatus;
  1130. BOOL committingIpcDelete = FALSE;
  1131. SHARE_DEL_HANDLE handle;
  1132. BOOL tryDownLevel = FALSE;
  1133. if ( !netname || (*netname == 0) || reserved ) {
  1134. return ERROR_INVALID_PARAMETER;
  1135. }
  1136. RpcTryExcept {
  1137. if ( STRICMP( netname, TEXT("IPC$") ) != 0 ) {
  1138. apiStatus = NetrShareDel(
  1139. servername,
  1140. netname,
  1141. reserved
  1142. );
  1143. } else {
  1144. apiStatus = NetrShareDelStart(
  1145. servername,
  1146. netname,
  1147. reserved,
  1148. &handle
  1149. );
  1150. if ( apiStatus == NERR_Success ) {
  1151. committingIpcDelete = TRUE;
  1152. apiStatus = NetrShareDelCommit( &handle );
  1153. }
  1154. }
  1155. } RpcExcept ( 1 ) {
  1156. RPC_STATUS rpcStatus;
  1157. rpcStatus = RpcExceptionCode( );
  1158. if ( committingIpcDelete && (rpcStatus == RPC_S_CALL_FAILED) ) {
  1159. apiStatus = NERR_Success;
  1160. } else {
  1161. apiStatus = NetpHandleRpcFailure(
  1162. "NetShareDel",
  1163. rpcStatus,
  1164. servername,
  1165. SERVICE_SERVER,
  1166. NET_REMOTE_FLAG_NORMAL,
  1167. &tryDownLevel
  1168. );
  1169. }
  1170. }
  1171. RpcEndExcept
  1172. if (apiStatus == NERR_TryDownLevel) {
  1173. tryDownLevel = TRUE;
  1174. }
  1175. if ( tryDownLevel ) {
  1176. //
  1177. // Call downlevel server.
  1178. //
  1179. // note: push value 0 instead of real reserved
  1180. //
  1181. apiStatus = RxNetShareDel(servername, netname, 0);
  1182. }
  1183. return apiStatus;
  1184. } // NetShareDel
  1185. NET_API_STATUS NET_API_FUNCTION
  1186. NetShareDelSticky (
  1187. IN LPTSTR servername,
  1188. IN LPTSTR netname,
  1189. IN DWORD reserved
  1190. )
  1191. /*++
  1192. Routine Description:
  1193. This is the DLL entrypoint for NetShareDelSticky.
  1194. Arguments:
  1195. servername --A pointer to an ASCIIZ string containing the name of
  1196. the remote server on which the function is to execute. A NULL
  1197. pointer or string specifies the local machine.
  1198. netname --A pointer to an ASCIIZ string containing the netname of
  1199. the share to delete.
  1200. reserved --Reserved, must be zero.
  1201. Return Value:
  1202. --*/
  1203. {
  1204. NET_API_STATUS apiStatus;
  1205. if (!(netname && *netname) || reserved) {
  1206. return ERROR_INVALID_PARAMETER;
  1207. }
  1208. NET_REMOTE_TRY_RPC
  1209. apiStatus = NetrShareDelSticky (
  1210. servername,
  1211. netname,
  1212. reserved);
  1213. NET_REMOTE_RPC_FAILED(
  1214. "NetShareDelSticky",
  1215. servername,
  1216. apiStatus,
  1217. NET_REMOTE_FLAG_NORMAL,
  1218. SERVICE_SERVER)
  1219. //
  1220. // No downlevel call.
  1221. //
  1222. apiStatus = ERROR_NOT_SUPPORTED;
  1223. NET_REMOTE_END
  1224. return(apiStatus);
  1225. } // NetShareDelSticky
  1226. NET_API_STATUS NET_API_FUNCTION
  1227. NetShareEnum (
  1228. IN LPTSTR servername,
  1229. IN DWORD level,
  1230. OUT LPBYTE *bufptr,
  1231. IN DWORD prefmaxlen,
  1232. OUT LPDWORD entriesread,
  1233. OUT LPDWORD totalentries,
  1234. IN OUT LPDWORD resume_handle
  1235. )
  1236. /*++
  1237. Routine Description:
  1238. This is the DLL entrypoint for NetShareEnum
  1239. Arguments:
  1240. servername --A pointer to an ASCIIZ string containing the name of
  1241. the remote server on which the function is to execute. A NULL
  1242. pointer or string specifies the local machine.
  1243. level --Level of information required. 0, 1 and 2 are valid.
  1244. bufptr --On return a pointer to the return information structure
  1245. is returned in the address pointed to by bufptr.
  1246. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  1247. bytes). 0xffffffff specifies no limit.
  1248. entriesread --On return the actual enumerated element count is
  1249. located in the DWORD pointed to by entriesread.
  1250. totalentries --On return the total entries available to be
  1251. enumerated is located in the DWORD pointed to by
  1252. totalentries.
  1253. resumehandle --On return, a resume handle is stored in the DWORD
  1254. pointed to by resumehandle, and is used to continue an
  1255. existing share search. The handle should be zero on the first
  1256. call and left unchanged for subsequent calls. If resumehandle
  1257. is NULL, then no resume handle is stored..
  1258. Return Value:
  1259. --*/
  1260. {
  1261. NET_API_STATUS apiStatus;
  1262. GENERIC_INFO_CONTAINER genericInfoContainer;
  1263. GENERIC_ENUM_STRUCT infoStruct;
  1264. //
  1265. // check the caller's parameters
  1266. //
  1267. *totalentries = *entriesread = 0;
  1268. *bufptr = NULL;
  1269. if ( (level > 2) && (level != 501) && (level != 502) ) {
  1270. return ERROR_INVALID_LEVEL;
  1271. }
  1272. genericInfoContainer.Buffer = NULL;
  1273. genericInfoContainer.EntriesRead = 0;
  1274. infoStruct.Container = &genericInfoContainer;
  1275. infoStruct.Level = level;
  1276. NET_REMOTE_TRY_RPC
  1277. apiStatus = NetrShareEnum (
  1278. servername,
  1279. (LPSHARE_ENUM_STRUCT) &infoStruct,
  1280. prefmaxlen,
  1281. totalentries,
  1282. resume_handle);
  1283. if (genericInfoContainer.Buffer != NULL) {
  1284. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  1285. *entriesread = genericInfoContainer.EntriesRead;
  1286. } else {
  1287. *bufptr = NULL;
  1288. *entriesread = 0;
  1289. }
  1290. NET_REMOTE_RPC_FAILED(
  1291. "NetShareEnum",
  1292. servername,
  1293. apiStatus,
  1294. NET_REMOTE_FLAG_NORMAL,
  1295. SERVICE_SERVER)
  1296. //
  1297. // Call downlevel server.
  1298. //
  1299. if ( level != 502 && level != 501 ) {
  1300. apiStatus = RxNetShareEnum(servername, level, bufptr,
  1301. prefmaxlen, entriesread, totalentries, resume_handle);
  1302. } else {
  1303. apiStatus = ERROR_NOT_SUPPORTED;
  1304. }
  1305. NET_REMOTE_END
  1306. //
  1307. // If we haven't gotten anything, and the server is offline,
  1308. // return the offline share state
  1309. //
  1310. if( ( *bufptr == NULL || *entriesread == 0 ) &&
  1311. ARGUMENT_PRESENT( servername ) &&
  1312. CSCIsServerOffline( servername ) ) {
  1313. NET_API_STATUS cscStatus;
  1314. cscStatus = CSCNetShareEnum(
  1315. servername,
  1316. level,
  1317. bufptr,
  1318. entriesread,
  1319. totalentries
  1320. );
  1321. if( cscStatus == NERR_Success ) {
  1322. apiStatus = cscStatus;
  1323. }
  1324. }
  1325. if ( apiStatus == ERROR_SUCCESS ) {
  1326. if (bufptr == NULL) {
  1327. return RPC_X_BAD_STUB_DATA;
  1328. }
  1329. }
  1330. return(apiStatus);
  1331. } // NetShareEnum
  1332. NET_API_STATUS NET_API_FUNCTION
  1333. NetShareEnumSticky (
  1334. IN LPTSTR servername,
  1335. IN DWORD level,
  1336. OUT LPBYTE *bufptr,
  1337. IN DWORD prefmaxlen,
  1338. OUT LPDWORD entriesread,
  1339. OUT LPDWORD totalentries,
  1340. IN OUT LPDWORD resume_handle
  1341. )
  1342. /*++
  1343. Routine Description:
  1344. This is the DLL entrypoint for NetShareEnumSticky
  1345. Arguments:
  1346. servername --A pointer to an ASCIIZ string containing the name of
  1347. the remote server on which the function is to execute. A NULL
  1348. pointer or string specifies the local machine.
  1349. level --Level of information required. 0, 1 and 2 are valid.
  1350. bufptr --On return a pointer to the return information structure
  1351. is returned in the address pointed to by bufptr.
  1352. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  1353. bytes). 0xffffffff specifies no limit.
  1354. entriesread --On return the actual enumerated element count is
  1355. located in the DWORD pointed to by entriesread.
  1356. totalentries --On return the total entries available to be
  1357. enumerated is located in the DWORD pointed to by
  1358. totalentries.
  1359. resumehandle --On return, a resume handle is stored in the DWORD
  1360. pointed to by resumehandle, and is used to continue an
  1361. existing share search. The handle should be zero on the first
  1362. call and left unchanged for subsequent calls. If resumehandle
  1363. is NULL, then no resume handle is stored..
  1364. Return Value:
  1365. --*/
  1366. {
  1367. NET_API_STATUS apiStatus;
  1368. GENERIC_INFO_CONTAINER genericInfoContainer;
  1369. GENERIC_ENUM_STRUCT infoStruct;
  1370. //
  1371. // check the caller's parameters
  1372. //
  1373. *totalentries = *entriesread = 0;
  1374. *bufptr = NULL;
  1375. if ( (level > 2) && (level != 501) && (level != 502) ) {
  1376. return ERROR_INVALID_LEVEL;
  1377. }
  1378. genericInfoContainer.Buffer = NULL;
  1379. genericInfoContainer.EntriesRead = 0;
  1380. infoStruct.Container = &genericInfoContainer;
  1381. infoStruct.Level = level;
  1382. NET_REMOTE_TRY_RPC
  1383. apiStatus = NetrShareEnumSticky (
  1384. servername,
  1385. (LPSHARE_ENUM_STRUCT) &infoStruct,
  1386. prefmaxlen,
  1387. totalentries,
  1388. resume_handle);
  1389. if (genericInfoContainer.Buffer != NULL) {
  1390. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  1391. *entriesread = genericInfoContainer.EntriesRead;
  1392. } else {
  1393. *bufptr = NULL;
  1394. *entriesread = 0;
  1395. }
  1396. NET_REMOTE_RPC_FAILED(
  1397. "NetShareEnum",
  1398. servername,
  1399. apiStatus,
  1400. NET_REMOTE_FLAG_NORMAL,
  1401. SERVICE_SERVER)
  1402. //
  1403. // No downlevel support
  1404. //
  1405. apiStatus = ERROR_NOT_SUPPORTED;
  1406. NET_REMOTE_END
  1407. if ( apiStatus == ERROR_SUCCESS ) {
  1408. if (bufptr == NULL) {
  1409. return RPC_X_BAD_STUB_DATA;
  1410. }
  1411. }
  1412. return(apiStatus);
  1413. } // NetShareEnumSticky
  1414. NET_API_STATUS NET_API_FUNCTION
  1415. NetShareGetInfo (
  1416. IN LPTSTR servername,
  1417. IN LPTSTR netname,
  1418. IN DWORD level,
  1419. OUT LPBYTE *bufptr
  1420. )
  1421. /*++
  1422. Routine Description:
  1423. NetShareGetInfo
  1424. Arguments:
  1425. servername --A pointer to an ASCIIZ string containing the name of
  1426. the remote server on which the function is to execute. A NULL
  1427. pointer or string specifies the local machine.
  1428. netname --A pointer to an ASCIIZ string containing the netname of
  1429. the share to return information on.
  1430. level --Level of information required. 0, 1 and 2 are valid.
  1431. bufptr --On return a pointer to the return information structure
  1432. is returned in the address pointed to by bufptr.
  1433. Return Value:
  1434. --*/
  1435. {
  1436. NET_API_STATUS apiStatus;
  1437. if (bufptr == NULL) {
  1438. return ERROR_INVALID_PARAMETER;
  1439. }
  1440. *bufptr = NULL; // Must be NULL so RPC knows to fill it in.
  1441. if ( (level > 2) &&
  1442. (level != 501) &&
  1443. (level != 502) &&
  1444. (level != 1005) ) {
  1445. return ERROR_INVALID_LEVEL;
  1446. }
  1447. if (!(netname && *netname)) {
  1448. return ERROR_INVALID_PARAMETER;
  1449. }
  1450. NET_REMOTE_TRY_RPC
  1451. apiStatus = NetrShareGetInfo (
  1452. servername,
  1453. netname,
  1454. level,
  1455. (LPSHARE_INFO) bufptr);
  1456. NET_REMOTE_RPC_FAILED(
  1457. "NetShareGetInfo",
  1458. servername,
  1459. apiStatus,
  1460. NET_REMOTE_FLAG_NORMAL,
  1461. SERVICE_SERVER)
  1462. //
  1463. // Call downlevel server.
  1464. //
  1465. if( level == 0 || level == 1 || level == 2 ) {
  1466. apiStatus = RxNetShareGetInfo(servername, netname, level, bufptr);
  1467. } else {
  1468. apiStatus = ERROR_NOT_SUPPORTED;
  1469. }
  1470. NET_REMOTE_END
  1471. if( *bufptr == NULL &&
  1472. ARGUMENT_PRESENT( servername ) &&
  1473. ARGUMENT_PRESENT( netname ) &&
  1474. CSCIsServerOffline( servername) ) {
  1475. NET_API_STATUS cscStatus;
  1476. cscStatus = CSCNetShareGetInfo ( servername, netname, level, bufptr );
  1477. if( cscStatus == NERR_Success ) {
  1478. apiStatus = cscStatus;
  1479. }
  1480. }
  1481. if ( apiStatus == ERROR_SUCCESS ) {
  1482. if (bufptr == NULL) {
  1483. return RPC_X_BAD_STUB_DATA;
  1484. }
  1485. }
  1486. return(apiStatus);
  1487. } // NetShareGetInfo
  1488. NET_API_STATUS NET_API_FUNCTION
  1489. NetShareSetInfo (
  1490. IN LPTSTR servername,
  1491. IN LPTSTR netname,
  1492. IN DWORD level,
  1493. IN LPBYTE buf,
  1494. OUT LPDWORD parm_err
  1495. )
  1496. /*++
  1497. Routine Description:
  1498. This is the DLL entrypoint for NetShareSetInfo
  1499. Arguments:
  1500. servername --A pointer to an ASCIIZ string containing the name of
  1501. the remote server on which the function is to execute. A NULL
  1502. pointer or string specifies the local machine.
  1503. netname --A pointer to an ASCIIZ string containing the netname of
  1504. the share to set information on.
  1505. level --Level of information to set.
  1506. buf --A pointer to a buffer containing the share information. If
  1507. parmnum is non zero then the buffer contains only the
  1508. appropriate data for the specific element.
  1509. parm_err --Optional pointer to a DWORD to return the index of the
  1510. first parameter in error when ERROR_INVALID_PARAMETER is
  1511. returned. If NULL the parameter is not returned on error.
  1512. Return Value:
  1513. --*/
  1514. {
  1515. NET_API_STATUS apiStatus;
  1516. NTSTATUS status;
  1517. ULONG sdLength = 0;
  1518. ULONG oldSdLength;
  1519. PSECURITY_DESCRIPTOR securityDescriptor = NULL;
  1520. PSECURITY_DESCRIPTOR oldSecurityDescriptor = NULL;
  1521. LPSHARE_INFO_1501 shi1501 = NULL;
  1522. NET_REMOTE_TRY_RPC
  1523. //
  1524. // If the info level can change the security descriptor, get
  1525. // the necessary information.
  1526. //
  1527. // *** Note that this code expects the layout of the reserved
  1528. // and security_descriptor fields in the 502 struct to
  1529. // match the 1501 struct.
  1530. //
  1531. if ( level == 502 ) {
  1532. if (buf == NULL) {
  1533. SET_ERROR_PARAMETER(PARM_ERROR_UNKNOWN);
  1534. return ERROR_INVALID_PARAMETER;
  1535. }
  1536. shi1501 =
  1537. (LPSHARE_INFO_1501)&((LPSHARE_INFO_502)buf)->shi502_reserved;
  1538. } else if ( level == SHARE_FILE_SD_INFOLEVEL ) {
  1539. shi1501 = (LPSHARE_INFO_1501)buf;
  1540. }
  1541. if ( shi1501 != NULL ) {
  1542. oldSdLength = shi1501->shi1501_reserved;
  1543. oldSecurityDescriptor = shi1501->shi1501_security_descriptor;
  1544. if ( oldSecurityDescriptor != NULL ) {
  1545. //
  1546. // Make a self relative security descriptor for use in the
  1547. // RPC call.
  1548. //
  1549. if ( !RtlValidSecurityDescriptor( oldSecurityDescriptor) ) {
  1550. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  1551. return ERROR_INVALID_PARAMETER;
  1552. }
  1553. status = RtlMakeSelfRelativeSD(
  1554. oldSecurityDescriptor,
  1555. NULL,
  1556. &sdLength
  1557. );
  1558. if ( status != STATUS_BUFFER_TOO_SMALL ) {
  1559. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  1560. return ERROR_INVALID_PARAMETER;
  1561. } else {
  1562. securityDescriptor = MIDL_user_allocate( sdLength );
  1563. if ( securityDescriptor == NULL) {
  1564. return ERROR_NOT_ENOUGH_MEMORY;
  1565. } else {
  1566. //
  1567. // Make an appropriate self-relative security
  1568. // descriptor.
  1569. //
  1570. status = RtlMakeSelfRelativeSD(
  1571. oldSecurityDescriptor,
  1572. securityDescriptor,
  1573. &sdLength
  1574. );
  1575. if ( !NT_SUCCESS(status) ) {
  1576. MIDL_user_free( securityDescriptor );
  1577. SET_ERROR_PARAMETER( SHARE_FILE_SD_PARMNUM );
  1578. return ERROR_INVALID_PARAMETER;
  1579. }
  1580. shi1501->shi1501_reserved = sdLength;
  1581. shi1501->shi1501_security_descriptor =
  1582. securityDescriptor;
  1583. }
  1584. }
  1585. } else {
  1586. shi1501->shi1501_reserved = 0;
  1587. }
  1588. }
  1589. apiStatus = NetrShareSetInfo(
  1590. servername,
  1591. netname,
  1592. level,
  1593. (LPSHARE_INFO) &buf,
  1594. parm_err);
  1595. if ( shi1501 != NULL ) {
  1596. //
  1597. // restore old values
  1598. //
  1599. shi1501->shi1501_reserved = oldSdLength;
  1600. shi1501->shi1501_security_descriptor = oldSecurityDescriptor;
  1601. MIDL_user_free( securityDescriptor );
  1602. }
  1603. NET_REMOTE_RPC_FAILED(
  1604. "NetShareSetInfo",
  1605. servername,
  1606. apiStatus,
  1607. NET_REMOTE_FLAG_NORMAL,
  1608. SERVICE_SERVER)
  1609. //
  1610. // Call downlevel server.
  1611. //
  1612. if ( level != 502 &&
  1613. level != 501 &&
  1614. level != SHARE_FILE_SD_INFOLEVEL &&
  1615. level != 1005 ) {
  1616. apiStatus = RxNetShareSetInfo(
  1617. servername,
  1618. netname,
  1619. level,
  1620. buf,
  1621. parm_err);
  1622. } else {
  1623. apiStatus = ERROR_NOT_SUPPORTED;
  1624. }
  1625. NET_REMOTE_END
  1626. return(apiStatus);
  1627. } // NetShareSetInfo
  1628. NET_API_STATUS NET_API_FUNCTION
  1629. NetServerDiskEnum (
  1630. IN LPTSTR servername,
  1631. IN DWORD level,
  1632. OUT LPBYTE *bufptr,
  1633. IN DWORD prefmaxlen,
  1634. OUT LPDWORD entriesread,
  1635. OUT LPDWORD totalentries,
  1636. IN OUT LPDWORD resume_handle
  1637. )
  1638. /*++
  1639. Routine Description:
  1640. This is the DLL entrypoint for NetServerDiskEnum.
  1641. Arguments:
  1642. servername --A pointer to an ASCIIZ string containing the name of
  1643. the remote server on which the function is to execute. A NULL
  1644. pointer or string specifies the local machine.
  1645. level --Level of information required. 0 is the only valid level.
  1646. bufptr --On return a pointer to the return information structure
  1647. is returned in the address pointed to by bufptr.
  1648. prefmaxlen --Prefered maximum length of returned data (in 8-bit
  1649. bytes). 0xffffffff specifies no limit.
  1650. entriesread --On return the actual enumerated element count is
  1651. located in the DWORD pointed to by entriesread.
  1652. totalentries --On return the total entries available to be
  1653. enumerated is located in the DWORD pointed to by totalentries
  1654. resumehandle --On return, a resume handle is stored in the DWORD
  1655. pointed to by resumehandle, and is used to continue an
  1656. existing server disk search. The handle should be zero on the
  1657. first call and left unchanged for subsequent calls. If
  1658. resumehandle is NULL, then no resume handle is stored..
  1659. Return Value:
  1660. --*/
  1661. {
  1662. NET_API_STATUS apiStatus;
  1663. DISK_ENUM_CONTAINER diskEnumContainer;
  1664. diskEnumContainer.Buffer = NULL;
  1665. NET_REMOTE_TRY_RPC
  1666. apiStatus = NetrServerDiskEnum (
  1667. servername,
  1668. level,
  1669. &diskEnumContainer,
  1670. prefmaxlen,
  1671. totalentries,
  1672. resume_handle);
  1673. if (diskEnumContainer.Buffer != NULL) {
  1674. *bufptr = (LPBYTE)diskEnumContainer.Buffer;
  1675. } else {
  1676. *bufptr = NULL;
  1677. }
  1678. if (diskEnumContainer.EntriesRead > 0) {
  1679. //
  1680. // We must subtract out the extra count that we added so
  1681. // that RPC would buffer the extra NUL at the end of the list.
  1682. //
  1683. *entriesread = diskEnumContainer.EntriesRead - 1;
  1684. } else {
  1685. *entriesread = 0;
  1686. }
  1687. NET_REMOTE_RPC_FAILED(
  1688. "NetServerDiskEnum",
  1689. servername,
  1690. apiStatus,
  1691. NET_REMOTE_FLAG_NORMAL,
  1692. SERVICE_SERVER)
  1693. //
  1694. // Call downlevel version of the API.
  1695. //
  1696. apiStatus = RxNetServerDiskEnum(
  1697. servername,
  1698. level,
  1699. bufptr,
  1700. prefmaxlen,
  1701. entriesread,
  1702. totalentries,
  1703. resume_handle);
  1704. NET_REMOTE_END
  1705. if ( apiStatus == ERROR_SUCCESS ) {
  1706. if (bufptr == NULL) {
  1707. return RPC_X_BAD_STUB_DATA;
  1708. }
  1709. }
  1710. return(apiStatus);
  1711. } // NetServerDiskEnum
  1712. NET_API_STATUS NET_API_FUNCTION
  1713. NetServerGetInfo (
  1714. IN LPTSTR servername,
  1715. IN DWORD level,
  1716. OUT LPBYTE *bufptr
  1717. )
  1718. /*++
  1719. Routine Description:
  1720. This is the DLL entrypoint for NetServerGetInfo
  1721. Arguments:
  1722. servername --A pointer to an ASCIIZ string containing the name of
  1723. the remote server on which the function is to execute. A NULL
  1724. pointer or string specifies the local machine.
  1725. level --Level of information required. 100, 101 and 102 are valid
  1726. for all platforms. 302, 402, 403, 502 are valid for the
  1727. appropriate platform.
  1728. bufptr --On return a pointer to the return information structure
  1729. is returned in the address pointed to by bufptr.
  1730. Return Value:
  1731. --*/
  1732. {
  1733. NET_API_STATUS apiStatus;
  1734. *bufptr = NULL; // Must be NULL so RPC knows to fill it in.
  1735. NET_REMOTE_TRY_RPC
  1736. apiStatus = NetrServerGetInfo (
  1737. servername,
  1738. level,
  1739. (LPSERVER_INFO) bufptr);
  1740. NET_REMOTE_RPC_FAILED(
  1741. "NetServerGetInfo",
  1742. servername,
  1743. apiStatus,
  1744. NET_REMOTE_FLAG_NORMAL,
  1745. SERVICE_SERVER)
  1746. //
  1747. // Call downlevel version of the API.
  1748. //
  1749. apiStatus = RxNetServerGetInfo (
  1750. servername,
  1751. level,
  1752. bufptr);
  1753. NET_REMOTE_END
  1754. if ( apiStatus == ERROR_SUCCESS ) {
  1755. if (bufptr == NULL) {
  1756. return RPC_X_BAD_STUB_DATA;
  1757. }
  1758. }
  1759. return(apiStatus);
  1760. } // NetServerGetInfo
  1761. NET_API_STATUS NET_API_FUNCTION
  1762. NetServerSetInfo (
  1763. IN LPTSTR servername,
  1764. IN DWORD level,
  1765. IN LPBYTE buf,
  1766. OUT LPDWORD parm_err
  1767. )
  1768. /*++
  1769. Routine Description:
  1770. This is the DLL entrypoint for NetServerSetInfo.
  1771. Arguments:
  1772. servername --A pointer to an ASCIIZ string containing the name of
  1773. the remote server on which the function is to execute. A NULL
  1774. pointer or string specifies the local machine.
  1775. level --Level of information to set.
  1776. buf --A pointer to a buffer containing the server information. If
  1777. parmnum is non zero then the buffer contains only the
  1778. appropriate data for the specific element.
  1779. parm_err --Optional pointer to a DWORD to return the index of the
  1780. first parameter in error when ERROR_INVALID_PARAMETER is
  1781. returned. If NULL the parameter is not returned on error.
  1782. Return Value:
  1783. --*/
  1784. {
  1785. NET_API_STATUS apiStatus;
  1786. NET_REMOTE_TRY_RPC
  1787. apiStatus = NetrServerSetInfo (
  1788. servername,
  1789. level,
  1790. (LPSERVER_INFO ) &buf,
  1791. parm_err);
  1792. NET_REMOTE_RPC_FAILED(
  1793. "NetServerSetInfo",
  1794. servername,
  1795. apiStatus,
  1796. NET_REMOTE_FLAG_NORMAL,
  1797. SERVICE_SERVER)
  1798. //
  1799. // Call downlevel server.
  1800. //
  1801. apiStatus = RxNetServerSetInfo(
  1802. servername,
  1803. level,
  1804. buf,
  1805. parm_err);
  1806. NET_REMOTE_END
  1807. return(apiStatus);
  1808. } // NetServerSetInfo
  1809. NET_API_STATUS NET_API_FUNCTION
  1810. NetServerStatisticsGet (
  1811. IN LPTSTR servername,
  1812. IN DWORD level,
  1813. IN DWORD options,
  1814. OUT LPBYTE *bufptr
  1815. )
  1816. /*++
  1817. Routine Description:
  1818. This is the DLL entrypoint for NetStatisticsGet.
  1819. Arguments:
  1820. servername --Points to an ASCIIZ string that contains the name of the
  1821. server on which to execute NetStatisticsGet. A NULL pointer or
  1822. NULL string specifies the local computer.
  1823. level --Specifies the level of detail requested; must be 0.
  1824. options --Specifies the options flags.
  1825. Bit(s) Meaning
  1826. 0 Clear statistics.
  1827. 1-31 Reserved; must be 0.
  1828. bufptr --On return a pointer to the returned information is
  1829. returned in the address pointed to by bufptr.
  1830. Return Value:
  1831. --*/
  1832. {
  1833. NET_API_STATUS apiStatus;
  1834. *bufptr = NULL; // Must be NULL so RPC knows to fill it in.
  1835. NET_REMOTE_TRY_RPC
  1836. apiStatus = NetrServerStatisticsGet (
  1837. servername,
  1838. SERVICE_SERVER,
  1839. level,
  1840. options,
  1841. (LPSTAT_SERVER_0 *) bufptr);
  1842. NET_REMOTE_RPC_FAILED(
  1843. "NetServerStatisticsGet",
  1844. servername,
  1845. apiStatus,
  1846. NET_REMOTE_FLAG_NORMAL,
  1847. SERVICE_SERVER)
  1848. //
  1849. // RPC call didn't work - try down-level routine
  1850. //
  1851. apiStatus = RxNetStatisticsGet(
  1852. servername,
  1853. SERVICE_SERVER,
  1854. level,
  1855. options,
  1856. bufptr
  1857. );
  1858. NET_REMOTE_END
  1859. if ( apiStatus == ERROR_SUCCESS ) {
  1860. if (bufptr == NULL) {
  1861. return RPC_X_BAD_STUB_DATA;
  1862. }
  1863. }
  1864. return(apiStatus);
  1865. } // NetServerStatisticsGet
  1866. NET_API_STATUS NET_API_FUNCTION
  1867. NetServerTransportAdd (
  1868. IN LPTSTR servername,
  1869. IN DWORD level,
  1870. IN LPBYTE bufptr
  1871. )
  1872. /*++
  1873. Routine Description:
  1874. This is the DLL entrypoint for NetServerTransportAdd
  1875. Arguments:
  1876. Return Value:
  1877. --*/
  1878. {
  1879. NET_API_STATUS apiStatus;
  1880. NET_REMOTE_TRY_RPC
  1881. apiStatus = NetrServerTransportAdd (
  1882. servername,
  1883. level,
  1884. (LPSERVER_TRANSPORT_INFO_0) bufptr);
  1885. NET_REMOTE_RPC_FAILED(
  1886. "NetServerTransportAdd",
  1887. servername,
  1888. apiStatus,
  1889. NET_REMOTE_FLAG_NORMAL,
  1890. SERVICE_SERVER)
  1891. //
  1892. // No downlevel call.
  1893. //
  1894. apiStatus = ERROR_NOT_SUPPORTED;
  1895. NET_REMOTE_END
  1896. return(apiStatus);
  1897. } // NetServerTransportAdd
  1898. NET_API_STATUS NET_API_FUNCTION
  1899. NetServerTransportDelEx (
  1900. IN LPTSTR servername,
  1901. IN DWORD level,
  1902. IN LPBYTE bufptr
  1903. )
  1904. /*++
  1905. Routine Description:
  1906. This is the DLL entrypoint for NetServerTransportAdd
  1907. Arguments:
  1908. Return Value:
  1909. --*/
  1910. {
  1911. NET_API_STATUS apiStatus;
  1912. NET_REMOTE_TRY_RPC
  1913. apiStatus = NetrServerTransportDelEx (
  1914. servername,
  1915. level,
  1916. (LPTRANSPORT_INFO) bufptr);
  1917. NET_REMOTE_RPC_FAILED(
  1918. "NetServerTransportDel",
  1919. servername,
  1920. apiStatus,
  1921. NET_REMOTE_FLAG_NORMAL,
  1922. SERVICE_SERVER)
  1923. //
  1924. // No downlevel call.
  1925. //
  1926. apiStatus = ERROR_NOT_SUPPORTED;
  1927. NET_REMOTE_END
  1928. // Around the Win2K/NT4 time frame a bug was introduced for TransportDel with
  1929. // level other than 0. In these cases, the buffer was cast instead of marshalled
  1930. // correctly over RPC. This means that Level 1 never worked anyway. To fix this,
  1931. // we added a new RPC interface that supports all the other levels. However, downlevel
  1932. // servers will not support this interface. In these cases, we call back with the TRUE
  1933. // level 0 interface to satisfy backwards compatibility
  1934. if( apiStatus == RPC_S_PROCNUM_OUT_OF_RANGE )
  1935. {
  1936. apiStatus = NetServerTransportDel( servername, 0, bufptr );
  1937. }
  1938. return(apiStatus);
  1939. } // NetServerTransportDel
  1940. NET_API_STATUS NET_API_FUNCTION
  1941. NetServerTransportDel (
  1942. IN LPTSTR servername,
  1943. IN DWORD level,
  1944. IN LPBYTE bufptr
  1945. )
  1946. /*++
  1947. Routine Description:
  1948. This is the DLL entrypoint for NetServerTransportAdd
  1949. Arguments:
  1950. Return Value:
  1951. --*/
  1952. {
  1953. NET_API_STATUS apiStatus;
  1954. if( level == 0 )
  1955. {
  1956. NET_REMOTE_TRY_RPC
  1957. apiStatus = NetrServerTransportDel (
  1958. servername,
  1959. level,
  1960. (LPSERVER_TRANSPORT_INFO_0) bufptr);
  1961. NET_REMOTE_RPC_FAILED(
  1962. "NetServerTransportDel",
  1963. servername,
  1964. apiStatus,
  1965. NET_REMOTE_FLAG_NORMAL,
  1966. SERVICE_SERVER)
  1967. //
  1968. // No downlevel call.
  1969. //
  1970. apiStatus = ERROR_NOT_SUPPORTED;
  1971. NET_REMOTE_END
  1972. }
  1973. else
  1974. {
  1975. // If they want level 1, we need to use the new RPC interface. See
  1976. // the comment in the TransportDelEx code above
  1977. apiStatus = NetServerTransportDelEx( servername, level, bufptr );
  1978. }
  1979. return(apiStatus);
  1980. } // NetServerTransportDel
  1981. NET_API_STATUS NET_API_FUNCTION
  1982. NetServerTransportEnum (
  1983. IN LPTSTR servername,
  1984. IN DWORD level,
  1985. OUT LPBYTE *bufptr,
  1986. IN DWORD prefmaxlen,
  1987. OUT LPDWORD entriesread,
  1988. OUT LPDWORD totalentries,
  1989. IN OUT LPDWORD resume_handle
  1990. )
  1991. /*++
  1992. Routine Description:
  1993. This is the DLL entrypoint for NetServerTransportEnum
  1994. Arguments:
  1995. Return Value:
  1996. --*/
  1997. {
  1998. NET_API_STATUS apiStatus;
  1999. GENERIC_INFO_CONTAINER genericInfoContainer;
  2000. GENERIC_ENUM_STRUCT infoStruct;
  2001. genericInfoContainer.Buffer = NULL;
  2002. genericInfoContainer.EntriesRead = 0;
  2003. infoStruct.Container = &genericInfoContainer;
  2004. infoStruct.Level = level;
  2005. NET_REMOTE_TRY_RPC
  2006. apiStatus = NetrServerTransportEnum (
  2007. servername,
  2008. (LPSERVER_XPORT_ENUM_STRUCT) &infoStruct,
  2009. prefmaxlen,
  2010. totalentries,
  2011. resume_handle);
  2012. if (genericInfoContainer.Buffer != NULL) {
  2013. *bufptr = (LPBYTE)genericInfoContainer.Buffer;
  2014. *entriesread = genericInfoContainer.EntriesRead;
  2015. } else {
  2016. *bufptr = NULL;
  2017. *entriesread = 0;
  2018. }
  2019. NET_REMOTE_RPC_FAILED(
  2020. "NetServerTransportEnum",
  2021. servername,
  2022. apiStatus,
  2023. NET_REMOTE_FLAG_NORMAL,
  2024. SERVICE_SERVER)
  2025. //
  2026. // No downlevel call.
  2027. //
  2028. apiStatus = ERROR_NOT_SUPPORTED;
  2029. NET_REMOTE_END
  2030. if ( apiStatus == ERROR_SUCCESS ) {
  2031. if (bufptr == NULL) {
  2032. return RPC_X_BAD_STUB_DATA;
  2033. }
  2034. }
  2035. return(apiStatus);
  2036. } // NetServerTransportEnum
  2037. NET_API_STATUS NET_API_FUNCTION
  2038. NetRemoteTOD (
  2039. IN LPCWSTR servername,
  2040. OUT LPBYTE *bufptr
  2041. )
  2042. /*++
  2043. Routine Description:
  2044. This is the DLL entrypoint for NetRemoteTOD
  2045. Arguments:
  2046. servername - name of the server on which the API so to be executed.
  2047. bufptr - the location where the address of the buffer allocated
  2048. for the time-of-day information is placed.
  2049. Return Value:
  2050. NERR_SUCCESS if there was no error. Otherwise, the error code is
  2051. returned.
  2052. --*/
  2053. {
  2054. NET_API_STATUS apiStatus;
  2055. //
  2056. // Call API
  2057. //
  2058. *bufptr = NULL; // Must be NULL so RPC knows to fill it in.
  2059. NET_REMOTE_TRY_RPC
  2060. apiStatus = NetrRemoteTOD (
  2061. (LPWSTR)servername,
  2062. (TIME_OF_DAY_INFO **) bufptr);
  2063. NET_REMOTE_RPC_FAILED(
  2064. "NetRemoteTOD",
  2065. servername,
  2066. apiStatus,
  2067. NET_REMOTE_FLAG_NORMAL,
  2068. SERVICE_TIMESOURCE )
  2069. apiStatus = RxNetRemoteTOD (
  2070. (LPWSTR)servername,
  2071. (LPBYTE *) bufptr);
  2072. NET_REMOTE_END
  2073. if ( apiStatus == ERROR_SUCCESS ) {
  2074. if (bufptr == NULL) {
  2075. return RPC_X_BAD_STUB_DATA;
  2076. }
  2077. }
  2078. return(apiStatus);
  2079. }
  2080. NET_API_STATUS
  2081. I_NetServerSetServiceBitsEx (
  2082. IN LPWSTR ServerName,
  2083. IN LPWSTR EmulatedServerName OPTIONAL,
  2084. IN LPTSTR TransportName OPTIONAL,
  2085. IN DWORD ServiceBitsOfInterest,
  2086. IN DWORD ServiceBits,
  2087. IN DWORD UpdateImmediately
  2088. )
  2089. /*++
  2090. Routine Description:
  2091. This is the DLL entrypoint for I_NetServerSetServiceBitsEx. This
  2092. routine sets the value of the Server Type as sent in server
  2093. announcement messages. It is an internal API used only by the
  2094. service controller.
  2095. Arguments:
  2096. ServerName - Used by RPC to direct the call. This API may only be
  2097. issued locally. This is enforced by the client stub.
  2098. EmulatedServerName - the name server using for accepting connections
  2099. on the network and for announcements. If null, use the priamary
  2100. server name.
  2101. TransportName - the name of one of the transports the server is bound
  2102. on. If null, set the bits for all the transports.
  2103. ServiceBitsOfInterest - a mask indicating which bits are significant
  2104. in 'ServiceBits'
  2105. ServiceBits - Bits (preassigned to various components by Microsoft)
  2106. indicating which services are active. This field is not
  2107. interpreted by the server service.
  2108. Return Value:
  2109. NET_API_STATUS - NO_ERROR or ERROR_NOT_SUPPORTED.
  2110. --*/
  2111. {
  2112. NET_API_STATUS apiStatus;
  2113. DWORD localOrRemote;
  2114. //
  2115. // Don't let this API go remote.
  2116. //
  2117. if ((ServerName != NULL) && (*ServerName != '\0')) {
  2118. apiStatus = NetpIsRemote(ServerName, &localOrRemote, NULL, 0, 0);
  2119. if (apiStatus != NERR_Success) {
  2120. return apiStatus;
  2121. }
  2122. if (localOrRemote == ISREMOTE) {
  2123. return ERROR_NOT_SUPPORTED;
  2124. }
  2125. }
  2126. //
  2127. // Do the call.
  2128. //
  2129. NET_REMOTE_TRY_RPC
  2130. apiStatus = I_NetrServerSetServiceBitsEx (
  2131. ServerName,
  2132. EmulatedServerName,
  2133. TransportName,
  2134. ServiceBitsOfInterest,
  2135. ServiceBits,
  2136. UpdateImmediately);
  2137. NET_REMOTE_RPC_FAILED(
  2138. "I_NetServerSetServiceBitsEx",
  2139. ServerName,
  2140. apiStatus,
  2141. NET_REMOTE_FLAG_NORMAL,
  2142. SERVICE_SERVER)
  2143. //
  2144. // No downlevel call.
  2145. //
  2146. apiStatus = ERROR_NOT_SUPPORTED;
  2147. NET_REMOTE_END
  2148. return(apiStatus);
  2149. } // I_NetServerSetServiceBitsEx
  2150. NET_API_STATUS
  2151. I_NetServerSetServiceBits (
  2152. IN LPTSTR servername,
  2153. IN LPTSTR transportname,
  2154. IN DWORD servicebits,
  2155. IN DWORD updateimmediately
  2156. )
  2157. /*++
  2158. Routine Description:
  2159. This is the DLL entrypoint for I_NetServerSetServiceBits. This
  2160. routine sets the value of the Server Type as sent in server
  2161. announcement messages. It is an internal API used only by the
  2162. service controller.
  2163. Arguments:
  2164. ServerName - Used by RPC to direct the call. This API may only be
  2165. issued locally. This is enforced by the client stub.
  2166. ServiceBits - Bits (preassigned to various components by Microsoft)
  2167. indicating which services are active. This field is not
  2168. interpreted by the server service.
  2169. Return Value:
  2170. NET_API_STATUS - NO_ERROR or ERROR_NOT_SUPPORTED.
  2171. --*/
  2172. {
  2173. NET_API_STATUS apiStatus;
  2174. DWORD localOrRemote;
  2175. //
  2176. // Don't let this API go remote.
  2177. //
  2178. if ((servername != NULL) && (*servername != '\0')) {
  2179. apiStatus = NetpIsRemote(servername, &localOrRemote, NULL, 0, 0);
  2180. if (apiStatus != NERR_Success) {
  2181. return apiStatus;
  2182. }
  2183. if (localOrRemote == ISREMOTE) {
  2184. return ERROR_NOT_SUPPORTED;
  2185. }
  2186. }
  2187. //
  2188. // Do the call.
  2189. //
  2190. NET_REMOTE_TRY_RPC
  2191. apiStatus = I_NetrServerSetServiceBits (
  2192. servername,
  2193. transportname,
  2194. servicebits,
  2195. updateimmediately);
  2196. //
  2197. // This API is called by the Service Controller only. Don't let
  2198. // the failure path call any SCM APIs since that may deadlock
  2199. // services.exe in the loopback.
  2200. //
  2201. NET_REMOTE_RPC_FAILED(
  2202. "I_NetServerSetServiceBits",
  2203. servername,
  2204. apiStatus,
  2205. NET_REMOTE_FLAG_SVC_CTRL,
  2206. SERVICE_SERVER)
  2207. //
  2208. // No downlevel call.
  2209. //
  2210. apiStatus = ERROR_NOT_SUPPORTED;
  2211. NET_REMOTE_END
  2212. return(apiStatus);
  2213. } // I_NetServerSetServiceBits
  2214. //
  2215. // Netps canonicalization functions. These are essentially private functions
  2216. // and are called from the API stubs in canonapi.c. The canonicalization
  2217. // functions have to be usable locally without going via the server service
  2218. // hence they live in NETAPI.DLL, but call local functions in NETLIB if the
  2219. // ServerName parameter is NULL (or designates the local machine). If the
  2220. // ServerName parameter is not NULL and designates a remote computer then the
  2221. // RPC function (here) will be called, hence the remote server must be
  2222. // running in order to make remote canonicalization requests
  2223. //
  2224. NET_API_STATUS
  2225. NET_API_FUNCTION
  2226. NetpsNameCanonicalize(
  2227. IN LPTSTR ServerName,
  2228. IN LPTSTR Name,
  2229. OUT LPTSTR Outbuf,
  2230. IN DWORD OutbufLen,
  2231. IN DWORD NameType,
  2232. IN DWORD Flags
  2233. )
  2234. /*++
  2235. Routine Description:
  2236. Canonicalizes a name
  2237. Arguments:
  2238. ServerName - where to run this API
  2239. Name - name to canonicalize
  2240. Outbuf - where to put canonicalized name
  2241. OutbufLen - length of Outbuf
  2242. NameType - type of name to canonicalize
  2243. Flags - control flags
  2244. Return Value:
  2245. NET_API_STATUS
  2246. --*/
  2247. {
  2248. NET_API_STATUS apiStatus;
  2249. NET_REMOTE_TRY_RPC
  2250. apiStatus = NetprNameCanonicalize(ServerName,
  2251. Name,
  2252. Outbuf,
  2253. OutbufLen,
  2254. NameType,
  2255. Flags
  2256. );
  2257. NET_REMOTE_RPC_FAILED("NetpsNameCanonicalize",
  2258. ServerName,
  2259. apiStatus,
  2260. NET_REMOTE_FLAG_NORMAL,
  2261. SERVICE_SERVER)
  2262. //
  2263. // RPC call didn't work - try down-level routine
  2264. //
  2265. apiStatus = RxNetpNameCanonicalize(ServerName,
  2266. Name,
  2267. Outbuf,
  2268. OutbufLen,
  2269. NameType,
  2270. Flags
  2271. );
  2272. NET_REMOTE_END
  2273. return apiStatus;
  2274. }
  2275. LONG
  2276. NET_API_FUNCTION
  2277. NetpsNameCompare(
  2278. IN LPTSTR ServerName,
  2279. IN LPTSTR Name1,
  2280. IN LPTSTR Name2,
  2281. IN DWORD NameType,
  2282. IN DWORD Flags
  2283. )
  2284. /*++
  2285. Routine Description:
  2286. Compares two names. Must be of same type
  2287. Arguments:
  2288. ServerName - where to run this API
  2289. Name1 - 1st name to compare
  2290. Name2 - 2nd
  2291. NameType - type of names
  2292. Flags - control flags
  2293. Return Value:
  2294. LONG
  2295. --*/
  2296. {
  2297. NET_API_STATUS apiStatus;
  2298. NET_REMOTE_TRY_RPC
  2299. apiStatus = NetprNameCompare(ServerName, Name1, Name2, NameType, Flags);
  2300. NET_REMOTE_RPC_FAILED("NetpsNameCompare",
  2301. ServerName,
  2302. apiStatus,
  2303. NET_REMOTE_FLAG_NORMAL,
  2304. SERVICE_SERVER)
  2305. //
  2306. // RPC call didn't work - try down-level routine
  2307. //
  2308. apiStatus = RxNetpNameCompare(ServerName, Name1, Name2, NameType, Flags);
  2309. NET_REMOTE_END
  2310. return apiStatus;
  2311. }
  2312. NET_API_STATUS
  2313. NET_API_FUNCTION
  2314. NetpsNameValidate(
  2315. IN LPTSTR ServerName,
  2316. IN LPTSTR Name,
  2317. IN DWORD NameType,
  2318. IN DWORD Flags
  2319. )
  2320. /*++
  2321. Routine Description:
  2322. Validates a name - checks whether a name of a certain type conforms to
  2323. canonicalization rules for that name type. Canonicalization rules mean
  2324. character set, name syntax and length
  2325. Arguments:
  2326. ServerName - where to perform this function
  2327. Name - name to validate
  2328. NameType - what type of name it is
  2329. Flags - MBZ
  2330. Return Value:
  2331. NET_API_STATUS
  2332. --*/
  2333. {
  2334. NET_API_STATUS apiStatus;
  2335. NET_REMOTE_TRY_RPC
  2336. apiStatus = NetprNameValidate(ServerName, Name, NameType, Flags);
  2337. NET_REMOTE_RPC_FAILED("NetpsNameValidate",
  2338. ServerName,
  2339. apiStatus,
  2340. NET_REMOTE_FLAG_NORMAL,
  2341. SERVICE_SERVER)
  2342. //
  2343. // RPC call didn't work - try down-level routine
  2344. //
  2345. apiStatus = RxNetpNameValidate(ServerName, Name, NameType, Flags);
  2346. NET_REMOTE_END
  2347. return apiStatus;
  2348. }
  2349. NET_API_STATUS
  2350. NET_API_FUNCTION
  2351. NetpsPathCanonicalize(
  2352. IN LPTSTR ServerName,
  2353. IN LPTSTR PathName,
  2354. OUT LPTSTR Outbuf,
  2355. IN DWORD OutbufLen,
  2356. IN LPTSTR Prefix OPTIONAL,
  2357. IN OUT LPDWORD PathType,
  2358. IN DWORD Flags
  2359. )
  2360. /*++
  2361. Routine Description:
  2362. Canonicalizes a directory path or a device name
  2363. Arguments:
  2364. ServerName - where to run this API
  2365. PathName - path to canonicalize
  2366. Outbuf - where to write the canonicalized version
  2367. OutbufLen - length of Outbuf in bytes
  2368. Prefix - optional prefix which will be prepended to Path
  2369. PathType - the type of path to canonicalize. May be different at output
  2370. Flags - control flags
  2371. Return Value:
  2372. NET_API_STATUS
  2373. --*/
  2374. {
  2375. NET_API_STATUS apiStatus;
  2376. NET_REMOTE_TRY_RPC
  2377. apiStatus = NetprPathCanonicalize(ServerName,
  2378. PathName,
  2379. (LPBYTE)Outbuf,
  2380. OutbufLen,
  2381. Prefix,
  2382. PathType,
  2383. Flags
  2384. );
  2385. NET_REMOTE_RPC_FAILED("NetpsPathCanonicalize",
  2386. ServerName,
  2387. apiStatus,
  2388. NET_REMOTE_FLAG_NORMAL,
  2389. SERVICE_SERVER)
  2390. //
  2391. // RPC call didn't work - try down-level routine
  2392. //
  2393. apiStatus = RxNetpPathCanonicalize(ServerName,
  2394. PathName,
  2395. Outbuf,
  2396. OutbufLen,
  2397. Prefix,
  2398. PathType,
  2399. Flags
  2400. );
  2401. NET_REMOTE_END
  2402. return apiStatus;
  2403. }
  2404. LONG
  2405. NET_API_FUNCTION
  2406. NetpsPathCompare(
  2407. IN LPTSTR ServerName,
  2408. IN LPTSTR PathName1,
  2409. IN LPTSTR PathName2,
  2410. IN DWORD PathType,
  2411. IN DWORD Flags
  2412. )
  2413. /*++
  2414. Routine Description:
  2415. Compares two paths. The paths are assumed to be of the same type
  2416. Arguments:
  2417. ServerName - where to run this API
  2418. PathName1 - 1st path to compare
  2419. PathName2 - 2nd
  2420. PathType - types of paths
  2421. Flags - control flags
  2422. Return Value:
  2423. LONG
  2424. --*/
  2425. {
  2426. NET_API_STATUS apiStatus;
  2427. NET_REMOTE_TRY_RPC
  2428. apiStatus = NetprPathCompare(ServerName,
  2429. PathName1,
  2430. PathName2,
  2431. PathType,
  2432. Flags
  2433. );
  2434. NET_REMOTE_RPC_FAILED("NetpsPathCompare",
  2435. ServerName,
  2436. apiStatus,
  2437. NET_REMOTE_FLAG_NORMAL,
  2438. SERVICE_SERVER)
  2439. //
  2440. // RPC call didn't work - try down-level routine
  2441. //
  2442. apiStatus = RxNetpPathCompare(ServerName,
  2443. PathName1,
  2444. PathName2,
  2445. PathType,
  2446. Flags
  2447. );
  2448. NET_REMOTE_END
  2449. return apiStatus;
  2450. }
  2451. NET_API_STATUS
  2452. NET_API_FUNCTION
  2453. NetpsPathType(
  2454. IN LPTSTR ServerName,
  2455. IN LPTSTR PathName,
  2456. OUT LPDWORD PathType,
  2457. IN DWORD Flags
  2458. )
  2459. /*++
  2460. Routine Description:
  2461. Determines the type of a path
  2462. Arguments:
  2463. ServerName - where to run this API
  2464. PathName - to find type of
  2465. PathType - returned path type
  2466. Flags - control flags
  2467. Return Value:
  2468. NET_API_STATUS
  2469. --*/
  2470. {
  2471. NET_API_STATUS apiStatus;
  2472. NET_REMOTE_TRY_RPC
  2473. apiStatus = NetprPathType(ServerName, PathName, PathType, Flags);
  2474. NET_REMOTE_RPC_FAILED("NetpsPathType",
  2475. ServerName,
  2476. apiStatus,
  2477. NET_REMOTE_FLAG_NORMAL,
  2478. SERVICE_SERVER)
  2479. //
  2480. // RPC call didn't work - try down-level routine
  2481. //
  2482. apiStatus = RxNetpPathType(ServerName, PathName, PathType, Flags);
  2483. NET_REMOTE_END
  2484. return apiStatus;
  2485. }
  2486. NET_API_STATUS NET_API_FUNCTION
  2487. NetServerTransportAddEx (
  2488. IN LPTSTR servername,
  2489. IN DWORD level,
  2490. IN LPBYTE bufptr
  2491. )
  2492. /*++
  2493. Routine Description:
  2494. This is the DLL entrypoint for NetServerTransportAddEx. It functions
  2495. just like NetServerTransportAdd, but it supports level 1 as well as 0
  2496. --*/
  2497. {
  2498. NET_API_STATUS apiStatus;
  2499. NET_REMOTE_TRY_RPC
  2500. apiStatus = NetrServerTransportAddEx (
  2501. servername,
  2502. level,
  2503. (LPTRANSPORT_INFO) bufptr);
  2504. NET_REMOTE_RPC_FAILED(
  2505. "NetServerTransportAddEx",
  2506. servername,
  2507. apiStatus,
  2508. NET_REMOTE_FLAG_NORMAL,
  2509. SERVICE_SERVER)
  2510. //
  2511. // No downlevel call.
  2512. //
  2513. apiStatus = ERROR_NOT_SUPPORTED;
  2514. NET_REMOTE_END
  2515. if( apiStatus == RPC_NT_PROCNUM_OUT_OF_RANGE ) {
  2516. apiStatus = NERR_InvalidAPI;
  2517. }
  2518. return(apiStatus);
  2519. } // NetServerTransportAddEx
  2520. NET_API_STATUS NET_API_FUNCTION
  2521. NetServerComputerNameAdd(
  2522. IN LPWSTR ServerName OPTIONAL,
  2523. IN LPWSTR EmulatedDomainName OPTIONAL,
  2524. IN LPWSTR EmulatedServerName
  2525. )
  2526. /*++
  2527. Routine Description:
  2528. This is the DLL entrypoint for NetServerComputerNameAdd. This api
  2529. causes 'ServerName' to respond to requests for 'EmulatedServerName'.
  2530. Arguments:
  2531. servername --A pointer to an ASCIIZ string containing the name of
  2532. the remote server on which the function is to execute. A NULL
  2533. pointer or string specifies the local machine.
  2534. EmulatedServerName --A pointer to the ASCIIZ string containing the
  2535. name which the server should stop supporting
  2536. EmulatedDomainName --A pointer to the ASCIIZ string containing the
  2537. domain name the server should use when announcing the presence of
  2538. 'EmulatedServerName'
  2539. Return Value:
  2540. NERR_Success, or reason for failure
  2541. --*/
  2542. {
  2543. DWORD resumehandle = 0;
  2544. NET_API_STATUS retval;
  2545. DWORD entriesread, totalentries;
  2546. DWORD i, j;
  2547. BOOLEAN AddedOne = FALSE;
  2548. UCHAR NetBiosName[ MAX_PATH ];
  2549. OEM_STRING NetBiosNameString;
  2550. UNICODE_STRING UniName;
  2551. //
  2552. // Ensure a valid EmulatedServerName was passed in
  2553. //
  2554. if( EmulatedServerName == NULL ) {
  2555. return ERROR_INVALID_PARAMETER;
  2556. }
  2557. //
  2558. // Convert the EmulatedServerName to an OEM string
  2559. //
  2560. RtlInitUnicodeString( &UniName, EmulatedServerName );
  2561. NetBiosNameString.Buffer = (PCHAR)NetBiosName;
  2562. NetBiosNameString.MaximumLength = sizeof( NetBiosName );
  2563. (VOID) RtlUpcaseUnicodeStringToOemString(
  2564. &NetBiosNameString,
  2565. &UniName,
  2566. FALSE
  2567. );
  2568. if( ARGUMENT_PRESENT( EmulatedDomainName ) ) {
  2569. //
  2570. // The caller wants to set a new computer name and domain name to the
  2571. // server. This requires level 1, which is new in 4.0
  2572. //
  2573. PSERVER_TRANSPORT_INFO_1 psti1;
  2574. //
  2575. // Enumerate all the transports so we can add the name and domain
  2576. // to each one.
  2577. //
  2578. retval = NetServerTransportEnum ( ServerName,
  2579. 1,
  2580. (LPBYTE *)&psti1,
  2581. (DWORD)-1,
  2582. &entriesread,
  2583. &totalentries,
  2584. &resumehandle );
  2585. if( retval == NERR_Success ) {
  2586. //
  2587. // Add the new name and domain to all of the transports
  2588. //
  2589. for( i=0; i < entriesread; i++ ) {
  2590. //
  2591. // Make sure we haven't already added to this transport
  2592. //
  2593. for( j = 0; j < i; j++ ) {
  2594. if( wcscmp( psti1[j].svti1_transportname, psti1[i].svti1_transportname ) == 0 )
  2595. break;
  2596. }
  2597. if( i != j )
  2598. continue;
  2599. psti1[i].svti1_transportaddress = NetBiosName;
  2600. psti1[i].svti1_transportaddresslength = strlen( NetBiosName );
  2601. psti1[i].svti1_domain = EmulatedDomainName;
  2602. retval = NetServerTransportAddEx( ServerName, 1, (LPBYTE)&psti1[ i ] );
  2603. if( retval == NERR_Success ) {
  2604. AddedOne = TRUE;
  2605. }
  2606. }
  2607. MIDL_user_free( psti1 );
  2608. }
  2609. } else {
  2610. //
  2611. // The caller just wants to set an alternate server name. Use level 0,
  2612. // since 3.51 servers support level 0
  2613. //
  2614. PSERVER_TRANSPORT_INFO_0 psti0;
  2615. //
  2616. // Enumerate all the transports so we can add the name and domain
  2617. // to each one.
  2618. //
  2619. retval = NetServerTransportEnum ( ServerName,
  2620. 0,
  2621. (LPBYTE *)&psti0,
  2622. (DWORD)-1,
  2623. &entriesread,
  2624. &totalentries,
  2625. &resumehandle );
  2626. if( retval == NERR_Success ) {
  2627. //
  2628. // Add the new name to all of the transports
  2629. //
  2630. for( i=0; i < entriesread; i++ ) {
  2631. //
  2632. // Make sure we haven't already added to this transport
  2633. //
  2634. for( j = 0; j < i; j++ ) {
  2635. if( wcscmp( psti0[j].svti0_transportname, psti0[i].svti0_transportname ) == 0 )
  2636. break;
  2637. }
  2638. if( i != j )
  2639. continue;
  2640. psti0[i].svti0_transportaddress = NetBiosName;
  2641. psti0[i].svti0_transportaddresslength = strlen( NetBiosName );
  2642. retval = NetServerTransportAdd( ServerName, 0, (LPBYTE)&psti0[ i ] );
  2643. if( retval == NERR_Success ) {
  2644. AddedOne = TRUE;
  2645. }
  2646. }
  2647. MIDL_user_free( psti0 );
  2648. }
  2649. }
  2650. return AddedOne ? NERR_Success : retval;
  2651. }
  2652. NET_API_STATUS NET_API_FUNCTION
  2653. NetServerComputerNameDel (
  2654. IN LPWSTR ServerName OPTIONAL,
  2655. IN LPWSTR EmulatedServerName
  2656. )
  2657. /*++
  2658. Routine Description:
  2659. This is the DLL entrypoint for NetServerComputerNameDel. This api
  2660. causes 'ServerName' to cease responding to requests for 'EmulatedServerName'
  2661. Arguments:
  2662. servername --A pointer to an ASCIIZ string containing the name of
  2663. the remote server on which the function is to execute. A NULL
  2664. pointer or string specifies the local machine.
  2665. EmulatedServerName --A pointer to the ASCIIZ string containing the
  2666. name which the server should stop supporting
  2667. Return Value:
  2668. NERR_Success, or reason for failure
  2669. --*/
  2670. {
  2671. DWORD resumehandle = 0;
  2672. NET_API_STATUS retval, tmpretval;
  2673. DWORD entriesread, totalentries;
  2674. DWORD i;
  2675. UCHAR NetBiosName[MAX_PATH];
  2676. OEM_STRING NetBiosNameString;
  2677. UNICODE_STRING UniName;
  2678. PSERVER_TRANSPORT_INFO_0 psti0;
  2679. BOOLEAN nameDeleted = FALSE;
  2680. //
  2681. // Ensure a valid EmulatedServerName was passed in
  2682. //
  2683. if( EmulatedServerName == NULL ) {
  2684. return ERROR_INVALID_PARAMETER;
  2685. }
  2686. //
  2687. // Convert the EmulatedServerName to an OEM string
  2688. //
  2689. RtlInitUnicodeString( &UniName, EmulatedServerName );
  2690. NetBiosNameString.Buffer = (PCHAR)NetBiosName;
  2691. NetBiosNameString.MaximumLength = sizeof( NetBiosName );
  2692. (VOID) RtlUpcaseUnicodeStringToOemString(
  2693. &NetBiosNameString,
  2694. &UniName,
  2695. FALSE
  2696. );
  2697. //
  2698. // Enumerate all the transports so we can delete the name from each one
  2699. //
  2700. retval = NetServerTransportEnum ( ServerName,
  2701. 0,
  2702. (LPBYTE *)&psti0,
  2703. (DWORD)-1,
  2704. &entriesread,
  2705. &totalentries,
  2706. &resumehandle );
  2707. if( retval != NERR_Success ) {
  2708. return retval;
  2709. }
  2710. retval = ERROR_BAD_NET_NAME;
  2711. //
  2712. // Delete the name from all of the transports. If we were successful at least once,
  2713. // then we return success.
  2714. //
  2715. for( i=0; i < entriesread; i++ ) {
  2716. if( psti0[i].svti0_transportaddresslength != NetBiosNameString.Length ) {
  2717. continue;
  2718. }
  2719. if( RtlCompareMemory( psti0[i].svti0_transportaddress,
  2720. NetBiosName,
  2721. NetBiosNameString.Length) != NetBiosNameString.Length ) {
  2722. continue;
  2723. }
  2724. tmpretval = NetServerTransportDel( ServerName, 0, (LPBYTE)&psti0[ i ] );
  2725. if( nameDeleted == FALSE ) {
  2726. retval = tmpretval;
  2727. if( retval == NERR_Success ) {
  2728. nameDeleted = TRUE;
  2729. }
  2730. }
  2731. }
  2732. if( entriesread ) {
  2733. MIDL_user_free( psti0 );
  2734. }
  2735. return retval;
  2736. }