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.

224 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. tktrenew.cxx
  5. Abstract:
  6. tktrenew
  7. Author:
  8. Larry Zhu (LZhu) January 14, 2002 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include "tktrenew.hxx"
  16. typedef
  17. VOID
  18. (* PFuncKerbTgtRenewalTrigger)(
  19. VOID * TaskHandle,
  20. VOID * TaskItem
  21. );
  22. typedef
  23. VOID
  24. (* PFuncKerbTgtRenewalReaper)(
  25. VOID * TaskItem
  26. );
  27. typedef
  28. NTSTATUS
  29. (* PFunKerbAddScavengerTask)(
  30. IN BOOLEAN Periodic,
  31. IN LONG Interval,
  32. IN ULONG Flags,
  33. IN PFuncKerbTgtRenewalTrigger pfnTrigger,
  34. IN PFuncKerbTgtRenewalReaper pfnDestroy,
  35. IN VOID * TaskItem,
  36. OUT OPTIONAL VOID ** TaskHandle
  37. );
  38. typedef struct _KERBEROS_LIST_ENTRY {
  39. LIST_ENTRY Next;
  40. ULONG ReferenceCount;
  41. } KERBEROS_LIST_ENTRY, *PKERBEROS_LIST_ENTRY;
  42. typedef struct _KERB_TICKET_CACHE_ENTRY {
  43. KERBEROS_LIST_ENTRY ListEntry;
  44. volatile LONG Linked;
  45. PKERB_INTERNAL_NAME ServiceName;
  46. PKERB_INTERNAL_NAME TargetName;
  47. UNICODE_STRING DomainName;
  48. UNICODE_STRING TargetDomainName;
  49. UNICODE_STRING AltTargetDomainName;
  50. UNICODE_STRING ClientDomainName;
  51. PKERB_INTERNAL_NAME ClientName;
  52. PKERB_INTERNAL_NAME AltClientName;
  53. ULONG TicketFlags;
  54. ULONG CacheFlags;
  55. KERB_ENCRYPTION_KEY SessionKey;
  56. KERB_ENCRYPTION_KEY CredentialKey; // used for pkiint only.
  57. TimeStamp StartTime;
  58. TimeStamp EndTime;
  59. TimeStamp RenewUntil;
  60. KERB_TICKET Ticket;
  61. TimeStamp TimeSkew;
  62. void * ScavengerHandle;
  63. #if DBG
  64. LIST_ENTRY GlobalListEntry;
  65. #endif
  66. } KERB_TICKET_CACHE_ENTRY, *PKERB_TICKET_CACHE_ENTRY;
  67. BOOL
  68. DllMain(
  69. IN HANDLE hModule,
  70. IN DWORD dwReason,
  71. IN DWORD dwReserved
  72. )
  73. {
  74. return DllMainDefaultHandler(hModule, dwReason, dwReason);
  75. }
  76. #if 0
  77. Return Values for Start():
  78. ERROR_NO_MORE_USER_HANDLES unload repeatedly
  79. ERROR_SERVER_HAS_OPEN_HANDLES no unload at all
  80. others unload once
  81. #endif 0
  82. int
  83. Start(
  84. IN ULONG cbParameters,
  85. IN VOID* pvParameters
  86. )
  87. {
  88. // do your stuff
  89. THResult hRetval;
  90. PFunKerbAddScavengerTask pFuncAddScan = NULL;
  91. PFuncKerbTgtRenewalTrigger pFuncTrig = NULL;
  92. PFuncKerbTgtRenewalReaper pFuncReaper = NULL;
  93. KERB_TICKET_CACHE_ENTRY* pCacheEntry = NULL;
  94. hRetval DBGCHK = (cbParameters == (4 * sizeof(long) + 1)) ? S_OK : E_INVALIDARG;
  95. if (SUCCEEDED(hRetval))
  96. {
  97. UCHAR* pParam = (UCHAR*) pvParameters;
  98. pFuncAddScan = (PFunKerbAddScavengerTask) (ULONG_PTR) *((ULONG*) pvParameters);
  99. pFuncTrig = (PFuncKerbTgtRenewalTrigger) (ULONG_PTR) *((ULONG*) (pParam + sizeof(long)) );
  100. pFuncReaper = (PFuncKerbTgtRenewalReaper) (ULONG_PTR) *((ULONG*) (pParam + 2 * sizeof(long)) );
  101. pCacheEntry = (KERB_TICKET_CACHE_ENTRY*) (ULONG_PTR) *((ULONG*) (pParam + 3 * sizeof(long)) );
  102. SspiPrint(SSPI_LOG, TEXT("pFuncAddScan %p, pFuncTrig %p, pFuncReaper %p, pCacheEntry %p\n"),
  103. pFuncAddScan, pFuncTrig, pFuncReaper, pCacheEntry);
  104. }
  105. if (SUCCEEDED(hRetval))
  106. {
  107. hRetval DBGCHK = (*pFuncAddScan)(
  108. FALSE,
  109. 0,
  110. 0,
  111. pFuncTrig,
  112. pFuncReaper,
  113. pCacheEntry,
  114. &pCacheEntry->ScavengerHandle
  115. );
  116. }
  117. return HRESULT_CODE(hRetval);
  118. }
  119. int
  120. RunIt(
  121. IN ULONG cbParameters,
  122. IN VOID* pvParameters
  123. )
  124. {
  125. //
  126. // RunItDefaultHandler calls Start() and adds try except
  127. //
  128. return RunItDefaultHandler(cbParameters, pvParameters);
  129. }
  130. int
  131. Init(
  132. IN ULONG argc,
  133. IN PCSTR argv[],
  134. OUT ULONG* pcbParameters,
  135. OUT VOID** ppvParameters
  136. )
  137. {
  138. DWORD dwErr = ERROR_SUCCESS;
  139. CHAR Parameters[REMOTE_PACKET_SIZE] = {0};
  140. ULONG cbBuffer = sizeof(Parameters);
  141. ULONG cbParameter = 0;
  142. DebugPrintf(SSPI_LOG, "Init: Hello world!\n");
  143. *pcbParameters = 0;
  144. *ppvParameters = NULL;
  145. if (argc == 4)
  146. {
  147. for (ULONG i = 0; i < argc; i++)
  148. {
  149. ULONG temp = strtol(argv[i], NULL, 0);
  150. memcpy(Parameters + cbParameter, &temp, sizeof(long));
  151. cbParameter += sizeof(long);
  152. }
  153. cbParameter++; // add a NULL
  154. dwErr = ERROR_SUCCESS;
  155. }
  156. else // return "Usage" in ppvParameters, must be a NULL terminated string
  157. {
  158. strcpy(Parameters, "<KerbAddScavengerTask> <KerbTgtRenewalTrigger> <KerbTgtRenewalReaper> <CacheEntry>");
  159. cbParameter = strlen(Parameters) + 1;
  160. dwErr = ERROR_INVALID_PARAMETER; // will display usage
  161. }
  162. *ppvParameters = new CHAR[cbParameter];
  163. if (*ppvParameters)
  164. {
  165. *pcbParameters = cbParameter;
  166. memcpy(*ppvParameters, Parameters, *pcbParameters);
  167. }
  168. else
  169. {
  170. dwErr = ERROR_OUTOFMEMORY;
  171. goto Cleanup;
  172. }
  173. #if 0
  174. dwErr = ERROR_CONTINUE; // use the default Init handler in injecter
  175. #endif
  176. Cleanup:
  177. return dwErr;
  178. }