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.

312 lines
9.5 KiB

  1. /*---------------------------------------------------------------------------
  2. File: PwdSvc.cpp
  3. Comments: entry point functions and other exported functions for ADMT's
  4. password migration Lsa notification package.
  5. REVISION LOG ENTRY
  6. Revision By: Paul Thompson
  7. Revised on 09/06/00
  8. ---------------------------------------------------------------------------
  9. */
  10. #include "Pwd.h"
  11. #include "PwdSvc.h"
  12. #include "PwdSvc_s.c"
  13. // These global variables can be changed if required
  14. #define gsPwdProtoSeq TEXT("ncacn_np")
  15. #define gsPwdEndPoint TEXT("\\pipe\\PwdMigRpc")
  16. DWORD gPwdRpcMinThreads = 1;
  17. DWORD gPwdRpcMaxThreads = RPC_C_LISTEN_MAX_CALLS_DEFAULT;
  18. #ifndef STATUS_SUCCESS
  19. #define STATUS_SUCCESS ((NTSTATUS) 0x00000000L)
  20. #endif
  21. extern "C"
  22. {
  23. BOOL WINAPI _CRT_INIT( HANDLE hInstance, DWORD nReason, LPVOID pReserved );
  24. }
  25. /*********************************************************************
  26. * *
  27. * Written by: Paul Thompson *
  28. * Date: 7 SEPT 2000 *
  29. * *
  30. * This function is called by Lsa when trying to load all *
  31. * registered Lsa password filter notification dlls. Here we will *
  32. * initialize the RPC run-time library to handle our ADMT password *
  33. * migration RPC interface and to begin looking for RPC calls. If we*
  34. * fail to successfully setup our RPC, we will return FALSE from this*
  35. * function which will cause Lsa not to load this password filter *
  36. * Dll. *
  37. * Note that the other two password filter dll functions: *
  38. * PasswordChangeNotify and PasswordFilter do nothing at this point *
  39. * in time. *
  40. * *
  41. *********************************************************************/
  42. //BEGIN InitializeChangeNotify
  43. BOOLEAN __stdcall InitializeChangeNotify()
  44. {
  45. /* local variables */
  46. RPC_STATUS rc = 0;
  47. BOOLEAN bSuccess = FALSE;
  48. // FILE * dbgFile;
  49. /* function body */
  50. // dbgFile = _wfopen(L"c:\\aa.txt", L"w+");
  51. // fwprintf(dbgFile, L"Entering InitializeChangeNotify\n");
  52. // MessageBeep(-1);
  53. // specify protocol sequence and endpoint
  54. // for receiving remote procedure calls
  55. rc = RpcServerUseProtseqEp(gsPwdProtoSeq,
  56. RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
  57. gsPwdEndPoint,
  58. NULL );
  59. if (rc == RPC_S_OK)
  60. {
  61. // fwprintf(dbgFile, L"RpcServerUseProtseqEp Succeeded!\n");
  62. // register an interface with the RPC run-time library
  63. rc = RpcServerRegisterIf(PwdMigRpc_ServerIfHandle, NULL, NULL);
  64. if (rc == RPC_S_OK)
  65. {
  66. // fwprintf(dbgFile, L"RpcServerRegisterIf Succeeded!\n");
  67. //set the authenification for this RPC interface
  68. rc = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
  69. if (rc == RPC_S_OK)
  70. {
  71. // fwprintf(dbgFile, L"RpcServerRegisterAuthInfo Succeeded!\n");
  72. // listen for remote procedure calls
  73. rc = RpcServerListen(gPwdRpcMinThreads,
  74. gPwdRpcMaxThreads,
  75. FALSE );
  76. if (rc != RPC_S_OK)
  77. {
  78. // fwprintf(dbgFile, L"RpcServerListen Failed!\n");
  79. switch (rc)
  80. {
  81. case RPC_S_ALREADY_LISTENING:
  82. // fwprintf(dbgFile, L"RPC_S_ALREADY_LISTENING\n");
  83. //if already listening, that's fine
  84. bSuccess = TRUE;
  85. break;
  86. case RPC_S_NO_PROTSEQS_REGISTERED:
  87. // fwprintf(dbgFile, L"RPC_S_NO_PROTSEQS_REGISTERED\n");
  88. break;
  89. case RPC_S_MAX_CALLS_TOO_SMALL:
  90. // fwprintf(dbgFile, L"RPC_S_MAX_CALLS_TOO_SMALL\n");
  91. break;
  92. default:
  93. // fwprintf(dbgFile, L"Unknown\n");
  94. break;
  95. }
  96. }
  97. //else success, set return value to load this dll as an
  98. //Lsa password filter dll
  99. else
  100. // {
  101. // fwprintf(dbgFile, L"RpcServerListen Succeeded!\n");
  102. bSuccess = TRUE;
  103. // }
  104. }
  105. // else
  106. // fwprintf(dbgFile, L"RpcServerRegisterAuthInfo Failed!\n");
  107. // unregister an interface with the RPC run-time library
  108. // rc = RpcServerUnregisterIf(PwdMigRpc_ServerIfHandle, NULL, NULL);
  109. }
  110. // else
  111. // fwprintf(dbgFile, L"RpcServerRegisterIf Failed!\n");
  112. }//end if set protocal sequence and end point set
  113. else
  114. {
  115. // fwprintf(dbgFile, L"RpcServerUseProtseqEp Failed!\n");
  116. switch (rc)
  117. {
  118. case RPC_S_PROTSEQ_NOT_SUPPORTED:
  119. // fwprintf(dbgFile, L"RPC_S_PROTSEQ_NOT_SUPPORTED\n");
  120. break;
  121. case RPC_S_INVALID_RPC_PROTSEQ:
  122. // fwprintf(dbgFile, L"RPC_S_INVALID_RPC_PROTSEQ\n");
  123. break;
  124. case RPC_S_INVALID_ENDPOINT_FORMAT:
  125. // fwprintf(dbgFile, L"RPC_S_INVALID_ENDPOINT_FORMAT\n");
  126. break;
  127. case RPC_S_OUT_OF_MEMORY:
  128. // fwprintf(dbgFile, L"RPC_S_OUT_OF_MEMORY\n");
  129. break;
  130. case RPC_S_DUPLICATE_ENDPOINT:
  131. // fwprintf(dbgFile, L"RPC_S_DUPLICATE_ENDPOINT\n");
  132. break;
  133. case RPC_S_INVALID_SECURITY_DESC:
  134. // fwprintf(dbgFile, L"RPC_S_INVALID_SECURITY_DESC\n");
  135. break;
  136. default:
  137. // fwprintf(dbgFile, L"Unknown\n");
  138. break;
  139. }
  140. }
  141. //if we successfully initialized our RPC interface, now open SAM
  142. //handles used later in our Interface function CopyPassword
  143. // if (bSuccess)
  144. // bSuccess = ConnectToSam();
  145. // fwprintf(dbgFile, L"Leaving InitializeChangeNotify\n");
  146. // fclose(dbgFile);
  147. //initialize a critical section to be used on the very first RPC call
  148. __try
  149. {
  150. InitializeCriticalSection (&csADMTCriticalSection);
  151. }
  152. __except (EXCEPTION_EXECUTE_HANDLER)
  153. {
  154. ;
  155. }
  156. return bSuccess;
  157. }
  158. //END InitializeChangeNotify
  159. /*********************************************************************
  160. * *
  161. * Written by: Paul Thompson *
  162. * Date: 7 SEPT 2000 *
  163. * *
  164. * This function is called by Lsa for all registered Lsa password*
  165. * filter notification dlls when a password in the domain has been *
  166. * modified. We will simply return STATUS_SUCCESS and do nothing. *
  167. * *
  168. *********************************************************************/
  169. //BEGIN PasswordChangeNotify
  170. NTSTATUS __stdcall PasswordChangeNotify(PUNICODE_STRING UserName, ULONG RelativeId,
  171. PUNICODE_STRING NewPassword)
  172. {
  173. return STATUS_SUCCESS;
  174. }
  175. /*********************************************************************
  176. * *
  177. * Written by: Paul Thompson *
  178. * Date: 7 SEPT 2000 *
  179. * *
  180. * This function is called by Lsa for all registered Lsa password*
  181. * filter notification dlls when a password in the domain is being *
  182. * modified. This function is designed to indicate to Lsa if the new*
  183. * password is acceptable. We will simply return TRUE (indicating it*
  184. * is acceptable) and do nothing. *
  185. * *
  186. *********************************************************************/
  187. //BEGIN PasswordFilter
  188. BOOLEAN __stdcall PasswordFilter(PUNICODE_STRING AccountName, PUNICODE_STRING FullName,
  189. PUNICODE_STRING Password, BOOLEAN SetOperation)
  190. {
  191. return TRUE;
  192. }
  193. //END PasswordFilter
  194. /***************************/
  195. /* Internal DLL functions. */
  196. /***************************/
  197. static BOOL Initialize(void)
  198. {
  199. return TRUE;
  200. }
  201. static BOOL Terminate(BOOL procterm)
  202. {
  203. if (!procterm)
  204. return TRUE;
  205. /* XXX Do stuff here */
  206. return TRUE;
  207. }
  208. BOOL WINAPI
  209. DllMain(HINSTANCE hinst, DWORD reason, VOID *rsvd)
  210. /*++
  211. Routine description:
  212. Dynamic link library entry point. Does nothing meaningful.
  213. Arguments:
  214. hinst = handle for the DLL
  215. reason = code indicating reason for call
  216. rsvd = for process attach: non-NULL => process startup
  217. for process detach: non-NULL => process termination
  218. Return value:
  219. status = success/failure
  220. Side effects:
  221. None
  222. --*/
  223. {
  224. switch (reason) {
  225. case DLL_PROCESS_ATTACH:
  226. {
  227. _CRT_INIT(hinst, reason, rsvd);
  228. return Initialize();
  229. break;
  230. }
  231. case DLL_PROCESS_DETACH:
  232. {
  233. BOOL bStat = Terminate(rsvd != NULL);
  234. _CRT_INIT(hinst, reason, rsvd);
  235. return bStat;
  236. break;
  237. }
  238. case DLL_THREAD_ATTACH:
  239. case DLL_THREAD_DETACH:
  240. return TRUE;
  241. default:
  242. return FALSE;
  243. }
  244. }
  245. ///////////////////////////////////////////////////////////////////////////////
  246. // Midl allocate memory
  247. ///////////////////////////////////////////////////////////////////////////////
  248. void __RPC_FAR * __RPC_USER
  249. midl_user_allocate(
  250. size_t len )
  251. {
  252. return new char[len];
  253. }
  254. ///////////////////////////////////////////////////////////////////////////////
  255. // Midl free memory
  256. ///////////////////////////////////////////////////////////////////////////////
  257. void __RPC_USER
  258. midl_user_free(
  259. void __RPC_FAR * ptr )
  260. {
  261. delete [] ptr;
  262. }