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.

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