Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
6.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1993 - 1999
  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. unsigned32 authn_svc,
  101. unsigned32 princ_name_size,
  102. unsigned char server_princ_name[],
  103. error_status_t * 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. // We have to call the function, even if princ_name_size == 0.
  114. // The call may be using it just to see if it has access
  115. //
  116. //
  117. // If the auth fn returns false, the op is denied.
  118. //
  119. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_INQ_PRINC_NAME, status)
  120. == 0 )
  121. {
  122. if (0 == *status || RPC_S_OK == *status)
  123. {
  124. *status = RPC_S_ACCESS_DENIED;
  125. }
  126. if (princ_name_size)
  127. {
  128. *server_princ_name = '\0';
  129. }
  130. return;
  131. }
  132. *status = RpcMgmtInqServerPrincNameA(0, authn_svc, &ServerPrincName);
  133. if ( *status == 0 )
  134. {
  135. unsigned int count;
  136. if (princ_name_size)
  137. {
  138. count = strlen(ServerPrincName);
  139. if (count > princ_name_size - 1)
  140. {
  141. *status = RPC_S_BUFFER_TOO_SMALL;
  142. }
  143. else
  144. {
  145. RpcpMemoryCopy(server_princ_name, ServerPrincName, count + 1);
  146. }
  147. RpcStringFreeA(&ServerPrincName);
  148. }
  149. }
  150. else
  151. {
  152. if (princ_name_size)
  153. {
  154. *server_princ_name = '\0';
  155. }
  156. }
  157. }
  158. void
  159. rpc_mgmt_inq_stats (
  160. RPC_BINDING_HANDLE binding,
  161. unsigned32 * count,
  162. unsigned32 statistics[],
  163. error_status_t * status
  164. )
  165. /*++
  166. Routine Description:
  167. This is the management code corresponding to the rpc_mgmt_inq_stats
  168. remote operation.
  169. --*/
  170. {
  171. RPC_STATS_VECTOR __RPC_FAR * StatsVector;
  172. unsigned long Index;
  173. //
  174. // If the auth fn returns false, the op is denied.
  175. //
  176. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_INQ_STATS, status) == 0 )
  177. {
  178. if (0 == *status || RPC_S_OK == *status)
  179. {
  180. *status = RPC_S_ACCESS_DENIED;
  181. }
  182. return;
  183. }
  184. *status = RpcMgmtInqStats(0, &StatsVector);
  185. if ( *status == RPC_S_OK )
  186. {
  187. for (Index = 0; Index < StatsVector->Count && Index < *count; Index++)
  188. {
  189. statistics[Index] = StatsVector->Stats[Index];
  190. }
  191. *count = Index;
  192. RpcMgmtStatsVectorFree(&StatsVector);
  193. }
  194. }
  195. unsigned long
  196. rpc_mgmt_is_server_listening (
  197. RPC_BINDING_HANDLE binding,
  198. unsigned long __RPC_FAR * status
  199. )
  200. /*++
  201. Routine Description:
  202. This is the management code corresponding to the
  203. rpc_mgmt_is_server_listening remote operation.
  204. --*/
  205. {
  206. //
  207. // If the auth fn returns false, the op is denied.
  208. //
  209. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_IS_SERVER_LISTEN, status)
  210. == 0 )
  211. {
  212. if (0 == *status || RPC_S_OK == *status)
  213. {
  214. *status = RPC_S_ACCESS_DENIED;
  215. }
  216. return 1;
  217. }
  218. *status = RpcMgmtIsServerListening(0);
  219. if ( *status == RPC_S_OK )
  220. {
  221. return(1);
  222. }
  223. if ( *status == RPC_S_NOT_LISTENING )
  224. {
  225. *status = RPC_S_OK;
  226. }
  227. return(0);
  228. }
  229. void
  230. rpc_mgmt_stop_server_listening (
  231. RPC_BINDING_HANDLE binding,
  232. unsigned long __RPC_FAR * status
  233. )
  234. /*++
  235. Routine Description:
  236. This is the management code corresponding to the
  237. rpc_mgmt_stop_server_listening remote operation.
  238. --*/
  239. {
  240. //
  241. // If the auth fn returns false, the op is denied.
  242. //
  243. if ( (*MgmtAuthorizationFn)(binding, RPC_C_MGMT_STOP_SERVER_LISTEN, status)
  244. == 0 )
  245. {
  246. if (0 == *status || RPC_S_OK == *status)
  247. {
  248. *status = RPC_S_ACCESS_DENIED;
  249. }
  250. return;
  251. }
  252. // N.B. RpcMgmtStopServerListening just flags the global
  253. // server as not listening. There is no danger of deadlock
  254. *status = RpcMgmtStopServerListening(0);
  255. }