Windows NT 4.0 source code leak
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.

318 lines
6.4 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. svrmgmt.c
  5. Abstract:
  6. We implement the server side of the remote management routines in this
  7. file.
  8. Author:
  9. Michael Montague (mikemon) 14-Apr-1993
  10. Revision History:
  11. --*/
  12. #include <sysinc.h>
  13. #include <rpc.h>
  14. #include <mgmt.h>
  15. int
  16. DefaultMgmtAuthorizationFn (
  17. IN RPC_BINDING_HANDLE ClientBinding,
  18. IN unsigned long RequestedMgmtOperation,
  19. OUT RPC_STATUS __RPC_FAR * Status
  20. )
  21. /*++
  22. Routine Description:
  23. This is the default authorization function used to control remote access
  24. to the server's management routines.
  25. Arguments:
  26. ClientBinding - Supplies the client binding handle of the application
  27. which is calling this routine.
  28. RequestedMgmtOperation - Supplies which management routine is being called.
  29. Status - Returns RPC_S_OK.
  30. Return Value:
  31. A value of non-zero will be returned if the client is authorized to
  32. call the management routine; otherwise, zero will be returned.
  33. --*/
  34. {
  35. ((void) ClientBinding);
  36. *Status = RPC_S_OK;
  37. if ( RequestedMgmtOperation != RPC_C_MGMT_STOP_SERVER_LISTEN )
  38. {
  39. return(1);
  40. }
  41. return(0);
  42. }
  43. RPC_MGMT_AUTHORIZATION_FN MgmtAuthorizationFn = DefaultMgmtAuthorizationFn;
  44. RPC_STATUS RPC_ENTRY
  45. RpcMgmtSetAuthorizationFn (
  46. IN RPC_MGMT_AUTHORIZATION_FN AuthorizationFn
  47. )
  48. /*++
  49. Routine Description:
  50. An application can use this routine to set the authorization function
  51. which will be called when a remote call arrives for one of the server's
  52. management routines, or to return to using the default (built-in)
  53. authorizatio function.
  54. Arguments:
  55. AuthorizationFn - Supplies a new authorization function.
  56. The fn may be nil, in which case the built-in auth fn
  57. is used instead.
  58. Return Value:
  59. RPC_S_OK - This will always be returned.
  60. --*/
  61. {
  62. if (AuthorizationFn)
  63. {
  64. MgmtAuthorizationFn = AuthorizationFn;
  65. }
  66. else
  67. {
  68. MgmtAuthorizationFn = DefaultMgmtAuthorizationFn;
  69. }
  70. return(RPC_S_OK);
  71. }
  72. void
  73. rpc_mgmt_inq_if_ids (
  74. RPC_BINDING_HANDLE binding,
  75. rpc_if_id_vector_p_t __RPC_FAR * if_id_vector,
  76. unsigned long __RPC_FAR * status
  77. )
  78. /*++
  79. Routine Description:
  80. This is the management code corresponding to the rpc_mgmt_inq_if_ids
  81. remote operation.
  82. --*/
  83. {
  84. //
  85. // If the auth fn returns false, the op is denied.
  86. //
  87. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_INQ_IF_IDS, status) == 0 )
  88. {
  89. if (0 == *status || RPC_S_OK == *status)
  90. {
  91. *status = RPC_S_ACCESS_DENIED;
  92. }
  93. return;
  94. }
  95. *status = RpcMgmtInqIfIds(0, (RPC_IF_ID_VECTOR **) if_id_vector);
  96. }
  97. void
  98. rpc_mgmt_inq_princ_name (
  99. RPC_BINDING_HANDLE binding,
  100. unsigned long authn_svc,
  101. unsigned long princ_name_size,
  102. unsigned char __RPC_FAR * server_princ_name,
  103. unsigned long __RPC_FAR * status
  104. )
  105. /*++
  106. Routine Description:
  107. This is the management code corresponding to the
  108. rpc_mgmt_inq_server_princ_name remote operation.
  109. --*/
  110. {
  111. unsigned char * ServerPrincName;
  112. //
  113. // If the auth fn returns false, the op is denied.
  114. //
  115. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_INQ_PRINC_NAME, status)
  116. == 0 )
  117. {
  118. if (0 == *status || RPC_S_OK == *status)
  119. {
  120. *status = RPC_S_ACCESS_DENIED;
  121. }
  122. *server_princ_name = '\0';
  123. return;
  124. }
  125. *status = RpcMgmtInqServerPrincNameA(0, authn_svc, &ServerPrincName);
  126. if ( *status == 0 )
  127. {
  128. unsigned int count;
  129. count = strlen(ServerPrincName);
  130. if (count > princ_name_size - 1)
  131. {
  132. *status = RPC_S_BUFFER_TOO_SMALL;
  133. }
  134. else
  135. {
  136. RpcpMemoryCopy(server_princ_name, ServerPrincName, count + 1);
  137. }
  138. RpcStringFree(&ServerPrincName);
  139. }
  140. else
  141. {
  142. *server_princ_name = '\0';
  143. }
  144. }
  145. void
  146. rpc_mgmt_inq_stats (
  147. RPC_BINDING_HANDLE binding,
  148. unsigned long __RPC_FAR * count,
  149. unsigned long __RPC_FAR * statistics,
  150. unsigned long __RPC_FAR * status
  151. )
  152. /*++
  153. Routine Description:
  154. This is the management code corresponding to the rpc_mgmt_inq_stats
  155. remote operation.
  156. --*/
  157. {
  158. RPC_STATS_VECTOR __RPC_FAR * StatsVector;
  159. unsigned long Index;
  160. //
  161. // If the auth fn returns false, the op is denied.
  162. //
  163. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_INQ_STATS, status) == 0 )
  164. {
  165. if (0 == *status || RPC_S_OK == *status)
  166. {
  167. *status = RPC_S_ACCESS_DENIED;
  168. }
  169. return;
  170. }
  171. *status = RpcMgmtInqStats(0, &StatsVector);
  172. if ( *status == RPC_S_OK )
  173. {
  174. for (Index = 0; Index < *count; Index++)
  175. {
  176. statistics[Index] = StatsVector->Stats[Index];
  177. }
  178. *count = Index;
  179. RpcMgmtStatsVectorFree(&StatsVector);
  180. }
  181. }
  182. unsigned long
  183. rpc_mgmt_is_server_listening (
  184. RPC_BINDING_HANDLE binding,
  185. unsigned long __RPC_FAR * status
  186. )
  187. /*++
  188. Routine Description:
  189. This is the management code corresponding to the
  190. rpc_mgmt_is_server_listening remote operation.
  191. --*/
  192. {
  193. //
  194. // If the auth fn returns false, the op is denied.
  195. //
  196. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_IS_SERVER_LISTEN, status)
  197. == 0 )
  198. {
  199. if (0 == *status || RPC_S_OK == *status)
  200. {
  201. *status = RPC_S_ACCESS_DENIED;
  202. }
  203. return 1;
  204. }
  205. *status = RpcMgmtIsServerListening(0);
  206. if ( *status == RPC_S_OK )
  207. {
  208. return(1);
  209. }
  210. if ( *status == RPC_S_NOT_LISTENING )
  211. {
  212. *status = RPC_S_OK;
  213. }
  214. return(0);
  215. }
  216. void
  217. rpc_mgmt_stop_server_listening (
  218. RPC_BINDING_HANDLE binding,
  219. unsigned long __RPC_FAR * status
  220. )
  221. /*++
  222. Routine Description:
  223. This is the management code corresponding to the
  224. rpc_mgmt_stop_server_listening remote operation.
  225. --*/
  226. {
  227. //
  228. // If the auth fn returns false, the op is denied.
  229. //
  230. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_STOP_SERVER_LISTEN, status)
  231. == 0 )
  232. {
  233. if (0 == *status || RPC_S_OK == *status)
  234. {
  235. *status = RPC_S_ACCESS_DENIED;
  236. }
  237. return;
  238. }
  239. // BUGBUG: What if StopServerListening won't return until
  240. // this call completes?
  241. *status = RpcMgmtStopServerListening(0);
  242. }