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.

288 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. context.cxx
  5. Abstract:
  6. Routines implementing the client context API
  7. Author:
  8. Cliff Van Dyke (cliffv) 22-May-2001
  9. --*/
  10. #include "pch.hxx"
  11. DWORD
  12. AzpClientContextInit(
  13. IN PGENERIC_OBJECT ParentGenericObject,
  14. IN PGENERIC_OBJECT ChildGenericObject
  15. )
  16. /*++
  17. Routine Description:
  18. This routine is a worker routine for AzInitializeClientContextFrom*. It does any object specific
  19. initialization that needs to be done.
  20. On entry, AzGlResource must be locked exclusively.
  21. Arguments:
  22. ParentGenericObject - Specifies the parent object to add the child object onto.
  23. The reference count has been incremented on this object.
  24. ChildGenericObject - Specifies the newly allocated child object.
  25. The reference count has been incremented on this object.
  26. Return Value:
  27. NO_ERROR - The operation was successful
  28. ERROR_NOT_ENOUGH_MEMORY - not enough memory
  29. Other exception status codes
  30. --*/
  31. {
  32. PAZP_CLIENT_CONTEXT ClientContext = (PAZP_CLIENT_CONTEXT) ChildGenericObject;
  33. UNREFERENCED_PARAMETER( ParentGenericObject );
  34. //
  35. // Initialization
  36. //
  37. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  38. //
  39. // ClientContexts are referenced by "Applications"
  40. // Let the generic object manager know all of the lists we support
  41. // This is a "back" link so we don't need to define which applications can reference this client context.
  42. //
  43. ChildGenericObject->GenericObjectLists = &ClientContext->backApplications;
  44. // Back link to applications
  45. ObInitObjectList( &ClientContext->backApplications,
  46. NULL,
  47. TRUE, // Backward link
  48. 0, // No link pair id
  49. NULL,
  50. NULL,
  51. NULL );
  52. return NO_ERROR;
  53. }
  54. VOID
  55. AzpClientContextFree(
  56. IN PGENERIC_OBJECT GenericObject
  57. )
  58. /*++
  59. Routine Description:
  60. This routine is a worker routine for ClientContext object free. It does any object specific
  61. cleanup that needs to be done.
  62. On entry, AzGlResource must be locked exclusively.
  63. Arguments:
  64. GenericObject - Specifies a pointer to the object to be deleted.
  65. Return Value:
  66. None
  67. --*/
  68. {
  69. PAZP_CLIENT_CONTEXT ClientContext = (PAZP_CLIENT_CONTEXT) GenericObject;
  70. //
  71. // Initialization
  72. //
  73. ASSERT( AzpIsLockedExclusive( &AzGlResource ) );
  74. //
  75. // Free any local strings
  76. //
  77. //
  78. // Free any authz context
  79. //
  80. if ( ClientContext->AuthzClientContext != NULL ) {
  81. if ( !AuthzFreeContext( ClientContext->AuthzClientContext ) ) {
  82. ASSERT( FALSE );
  83. }
  84. }
  85. }
  86. DWORD
  87. AzpClientContextGetProperty(
  88. IN PGENERIC_OBJECT GenericObject,
  89. IN ULONG PropertyId,
  90. OUT PVOID *PropertyValue
  91. )
  92. /*++
  93. Routine Description:
  94. This routine is a worker routine for AzClientContextGetProperty. It does any object specific
  95. property gets.
  96. On entry, AzGlResource must be locked shared.
  97. Arguments:
  98. GenericObject - Specifies a pointer to the object to be queried
  99. PropertyId - Specifies which property to return.
  100. PropertyValue - Specifies a pointer to return the property in.
  101. The returned pointer must be freed using AzFreeMemory.
  102. The returned value and type depends in PropertyId. The valid values are:
  103. AZ_PROP_CLIENT_CONTEXT_TYPE PULONG - ClientContext type of the group
  104. AZ_PROP_CLIENT_CONTEXT_APP_MEMBERS AZ_STRING_ARRAY - Application groups that are members of this group
  105. ???
  106. Return Value:
  107. Status of the operation
  108. --*/
  109. {
  110. DWORD WinStatus = NO_ERROR;
  111. PAZP_CLIENT_CONTEXT ClientContext = (PAZP_CLIENT_CONTEXT) GenericObject;
  112. //
  113. // Initialization
  114. //
  115. ASSERT( AzpIsLockedShared( &AzGlResource ) );
  116. //
  117. // Return any object specific attribute
  118. //
  119. //
  120. switch ( PropertyId ) {
  121. case 1:
  122. UNREFERENCED_PARAMETER( PropertyValue );
  123. UNREFERENCED_PARAMETER( ClientContext );
  124. break;
  125. default:
  126. AzPrint(( AZD_INVPARM, "AzpClientContextGetProperty: invalid opcode\n", PropertyId ));
  127. WinStatus = ERROR_INVALID_PARAMETER;
  128. break;
  129. }
  130. return WinStatus;
  131. }
  132. DWORD
  133. AzInitializeContextFromToken(
  134. IN AZ_HANDLE ApplicationHandle,
  135. IN HANDLE TokenHandle,
  136. IN DWORD Reserved,
  137. OUT PAZ_HANDLE ClientContextHandle
  138. )
  139. /*++
  140. Routine Description:
  141. This routine is a worker routine for AzGroupCreate. It does any object specific
  142. initialization that needs to be done.
  143. On entry, AzGlResource must be locked exclusively.
  144. Arguments:
  145. ApplicationHandle - Specifies a handle to the application object that
  146. is this client context applies to.
  147. TokenHandle - Handle to the NT token describing the cleint.
  148. NULL implies the impersonation token of the caller's thread.
  149. The token mast have been opened for TOKEN_QUERY, TOKEN_IMPERSONATION, and
  150. TOKEN_DUPLICATE access.
  151. Reserved - Reserved. Must by zero.
  152. ClientContextHandle - Return a handle to the client context
  153. The caller must close this handle by calling AzCloseHandle.
  154. Return Value:
  155. NO_ERROR - The operation was successful
  156. ERROR_NOT_ENOUGH_MEMORY - not enough memory
  157. Other exception status codes
  158. --*/
  159. {
  160. DWORD WinStatus;
  161. LUID Identifier = {0};
  162. PAZP_CLIENT_CONTEXT ClientContext = NULL;
  163. //
  164. // Call the common routine to create our client context object
  165. //
  166. WinStatus = ObCommonCreateObject(
  167. (PGENERIC_OBJECT) ApplicationHandle,
  168. OBJECT_TYPE_APPLICATION,
  169. &(((PAZP_APPLICATION)ApplicationHandle)->ClientContexts),
  170. OBJECT_TYPE_CLIENT_CONTEXT,
  171. NULL,
  172. Reserved,
  173. (PGENERIC_OBJECT *) &ClientContext );
  174. if ( WinStatus != NO_ERROR ) {
  175. goto Cleanup;
  176. }
  177. //
  178. // Initialize Authz
  179. //
  180. if ( !AuthzInitializeContextFromToken(
  181. 0, // No Flags
  182. TokenHandle,
  183. (((PAZP_APPLICATION)ApplicationHandle)->AuthzResourceManager),
  184. NULL, // No expiration time
  185. Identifier,
  186. NULL, // No dynamic group args
  187. &ClientContext->AuthzClientContext ) ) {
  188. WinStatus = GetLastError();
  189. goto Cleanup;
  190. }
  191. WinStatus = NO_ERROR;
  192. *ClientContextHandle = ClientContext;
  193. ClientContext = NULL;
  194. //
  195. // Free any local resources
  196. //
  197. Cleanup:
  198. if ( ClientContext != NULL ) {
  199. AzCloseHandle( ClientContext, 0 );
  200. }
  201. return WinStatus;
  202. }