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.

807 lines
21 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. cred.cxx
  5. Abstract:
  6. Shared memory data structures for digest sspi package.
  7. Author:
  8. Adriaan Canter (adriaanc) 01-Aug-1998
  9. --*/
  10. #include "include.hxx"
  11. //////////////////////////////////////////////////////////////////////
  12. //
  13. // CEntry Functions
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. //--------------------------------------------------------------------
  17. // CEntry::Free
  18. // BUGBUG - inline this.
  19. //--------------------------------------------------------------------
  20. DWORD CEntry::Free(CMMFile *pMMFile, CEntry *pEntry)
  21. {
  22. BOOL bFree = pMMFile->FreeEntry(pEntry);
  23. return (bFree ? ERROR_SUCCESS : ERROR_INTERNAL_ERROR);
  24. }
  25. //--------------------------------------------------------------------
  26. // CEntry::GetNext
  27. //--------------------------------------------------------------------
  28. CEntry* CEntry::GetNext(CEntry *pEntry)
  29. {
  30. if (pEntry->dwNext)
  31. return (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwNext);
  32. return NULL;
  33. }
  34. //--------------------------------------------------------------------
  35. // CEntry::GetPrev
  36. //--------------------------------------------------------------------
  37. CEntry* CEntry::GetPrev(CEntry *pEntry)
  38. {
  39. if (pEntry->dwPrev)
  40. return (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwPrev);
  41. return NULL;
  42. }
  43. //////////////////////////////////////////////////////////////////////
  44. //
  45. // CSess Functions
  46. //
  47. //////////////////////////////////////////////////////////////////////
  48. //--------------------------------------------------------------------
  49. // CSess::Create
  50. //--------------------------------------------------------------------
  51. CSess* CSess::Create(CMMFile *pMMFile,
  52. LPSTR szAppCtx, LPSTR szUserCtx, BOOL fHTTP)
  53. {
  54. DIGEST_ASSERT(pMMFile);
  55. // Unaligned Sess lengths.
  56. DWORD cbAppCtx = szAppCtx ? strlen(szAppCtx) + 1 : 0;
  57. DWORD cbUserCtx = szUserCtx ? strlen(szUserCtx) + 1 : 0;
  58. // Aligned Sess lengths.
  59. DWORD cbStructAligned = ROUNDUPDWORD(sizeof(CSess));
  60. DWORD cbAppCtxAligned = ROUNDUPDWORD(cbAppCtx);
  61. DWORD cbUserCtxAligned = ROUNDUPDWORD(cbUserCtx);
  62. // Total number of required bytes (aligned).
  63. DWORD cbEntryAligned = cbStructAligned
  64. + cbAppCtxAligned + cbUserCtxAligned;
  65. // Allocate from mem map.
  66. CSess *pSess = (CSess*) pMMFile->AllocateEntry(cbEntryAligned);
  67. if (!pSess)
  68. {
  69. DIGEST_ASSERT(FALSE);
  70. goto exit;
  71. }
  72. DWORD cbCurrentOffset;
  73. cbCurrentOffset = cbStructAligned;
  74. pSess->dwAppCtx = pSess->dwUserCtx = 0;
  75. // AppCtx
  76. if (szAppCtx)
  77. {
  78. memcpy(OFFSET_TO_POINTER(pSess, cbCurrentOffset), szAppCtx, cbAppCtx);
  79. pSess->dwAppCtx = cbCurrentOffset;
  80. cbCurrentOffset += cbAppCtxAligned;
  81. }
  82. // UserCtx
  83. if (szUserCtx)
  84. {
  85. memcpy(OFFSET_TO_POINTER(pSess, cbCurrentOffset), szUserCtx, cbUserCtx);
  86. pSess->dwUserCtx = cbCurrentOffset;
  87. }
  88. // No need to advance cbCurrentOffset.
  89. pSess->cbSess = cbEntryAligned;
  90. pSess->dwCred = 0;
  91. pSess->dwSig = SIG_SESS;
  92. pSess->fHTTP = fHTTP;
  93. pSess->dwPrev = 0;
  94. pSess->dwNext = 0;
  95. exit:
  96. return pSess;
  97. }
  98. //--------------------------------------------------------------------
  99. // CSess::GetAppCtx
  100. //--------------------------------------------------------------------
  101. LPSTR CSess::GetAppCtx(CSess *pSess)
  102. {
  103. if (pSess->dwAppCtx)
  104. return (LPSTR) OFFSET_TO_POINTER(pSess, pSess->dwAppCtx);
  105. else
  106. return NULL;
  107. }
  108. //--------------------------------------------------------------------
  109. // CSess::GetUserCtx
  110. //--------------------------------------------------------------------
  111. LPSTR CSess::GetUserCtx(CSess *pSess)
  112. {
  113. if (pSess->dwUserCtx)
  114. return (LPSTR) OFFSET_TO_POINTER(pSess, pSess->dwUserCtx);
  115. else
  116. return NULL;
  117. }
  118. //--------------------------------------------------------------------
  119. // CSess::GetCtx
  120. // Allocates a context string in local heap.
  121. //--------------------------------------------------------------------
  122. LPSTR CSess::GetCtx(CSess *pSess)
  123. {
  124. DIGEST_ASSERT(pSess);
  125. LPSTR szAppCtx, szUserCtx, szCtx;
  126. DWORD cbAppCtx, cbUserCtx, cbCtx;
  127. szAppCtx = GetAppCtx(pSess);
  128. szUserCtx = GetUserCtx(pSess);
  129. cbAppCtx = szAppCtx ? strlen(szAppCtx) : 0;
  130. cbUserCtx = szUserCtx ? strlen(szUserCtx) : 0;
  131. cbCtx = cbAppCtx + sizeof(':') + cbUserCtx + sizeof('\0');
  132. szCtx = new CHAR[cbCtx];
  133. if (!szCtx)
  134. {
  135. DIGEST_ASSERT(FALSE);
  136. return NULL;
  137. }
  138. // "appctx:userctx\0"
  139. // bugbug - macro for sizeof -1
  140. memcpy(szCtx, szAppCtx, cbAppCtx);
  141. memcpy(szCtx + cbAppCtx, ":", sizeof(":") - 1);
  142. memcpy(szCtx + cbAppCtx + sizeof(":") - 1, szUserCtx, cbUserCtx);
  143. memcpy(szCtx + cbAppCtx + sizeof(":") - 1 + cbUserCtx, "\0", sizeof("\0") - 1);
  144. return szCtx;
  145. }
  146. //--------------------------------------------------------------------
  147. // CSess::CtxMatch
  148. //--------------------------------------------------------------------
  149. BOOL CSess::CtxMatch(CSess *pSess1, CSess *pSess2)
  150. {
  151. DIGEST_ASSERT(pSess1 && pSess2);
  152. LPSTR szAppCtx1, szAppCtx2, szUserCtx1, szUserCtx2;
  153. szAppCtx1 = CSess::GetAppCtx(pSess1);
  154. szAppCtx2 = CSess::GetAppCtx(pSess2);
  155. szUserCtx1 = CSess::GetUserCtx(pSess1);
  156. szUserCtx2 = CSess::GetUserCtx(pSess2);
  157. // If both AppCtx values are NULL or
  158. // are equal to same string.
  159. if ((!szAppCtx1 && !szAppCtx2)
  160. || ((szAppCtx1 && szAppCtx2)
  161. && !strcmp(szAppCtx1, szAppCtx2)))
  162. {
  163. // And both UserCtx values are NULL or
  164. // are equal to same string.
  165. if ((!szUserCtx1 && !szUserCtx2)
  166. || ((szUserCtx1 && szUserCtx2)
  167. && !strcmp(szUserCtx1, szUserCtx2)))
  168. {
  169. // Credentials are shareable.
  170. return TRUE;
  171. }
  172. }
  173. // Otherwise creds are not shareable.
  174. return FALSE;
  175. }
  176. //--------------------------------------------------------------------
  177. // CSess::GetCred
  178. //--------------------------------------------------------------------
  179. CCred *CSess::GetCred(CSess* pSess)
  180. {
  181. if (!pSess->dwCred)
  182. return NULL;
  183. return (CCred*) OFFSET_TO_POINTER(g_pHeap, pSess->dwCred);
  184. }
  185. //--------------------------------------------------------------------
  186. // CSess::SetCred
  187. //--------------------------------------------------------------------
  188. CCred *CSess::SetCred(CSess* pSess, CCred* pCred)
  189. {
  190. if (!pCred)
  191. pSess->dwCred = 0;
  192. else
  193. pSess->dwCred = POINTER_TO_OFFSET(g_pHeap, pCred);
  194. return pCred;
  195. }
  196. //////////////////////////////////////////////////////////////////////
  197. //
  198. // CList Functions
  199. //
  200. //////////////////////////////////////////////////////////////////////
  201. //--------------------------------------------------------------------
  202. // CList::CList
  203. //--------------------------------------------------------------------
  204. CList::CList()
  205. {
  206. _pHead = NULL;
  207. _pCur = NULL;
  208. _pdwOffset = NULL;
  209. }
  210. //--------------------------------------------------------------------
  211. // CList::Init
  212. //--------------------------------------------------------------------
  213. CEntry* CList::Init(LPDWORD pdwOffset)
  214. {
  215. DIGEST_ASSERT(pdwOffset)
  216. _pdwOffset = pdwOffset;
  217. if (*pdwOffset)
  218. {
  219. _pHead = (CEntry*) OFFSET_TO_POINTER(g_pHeap, *pdwOffset);
  220. _pCur = _pHead;
  221. }
  222. return _pHead;
  223. }
  224. //--------------------------------------------------------------------
  225. // CList::Seek
  226. //--------------------------------------------------------------------
  227. CEntry* CList::Seek()
  228. {
  229. // DIGEST_ASSERT(_pHead);
  230. _pHead = (CEntry*) OFFSET_TO_POINTER(g_pHeap, *_pdwOffset);
  231. _pCur = _pHead;
  232. return _pCur;
  233. }
  234. //--------------------------------------------------------------------
  235. // CList::GetNext
  236. //--------------------------------------------------------------------
  237. CEntry* CList::GetNext()
  238. {
  239. if (! *_pdwOffset)
  240. return NULL;
  241. CEntry *pEntry = _pCur;
  242. if (_pCur)
  243. _pCur = _pCur->dwNext ?
  244. (CEntry*) OFFSET_TO_POINTER(g_pHeap, _pCur->dwNext) : NULL;
  245. return pEntry;
  246. }
  247. //--------------------------------------------------------------------
  248. // CList::GetPrev
  249. //--------------------------------------------------------------------
  250. CEntry* CList::GetPrev()
  251. {
  252. if (! *_pdwOffset)
  253. return NULL;
  254. CEntry *pEntry = _pCur;
  255. if (_pCur)
  256. _pCur = _pCur->dwPrev ?
  257. (CEntry*) OFFSET_TO_POINTER(g_pHeap, _pCur->dwPrev) : NULL;
  258. return pEntry;
  259. }
  260. //--------------------------------------------------------------------
  261. // CList::Insert
  262. //--------------------------------------------------------------------
  263. CEntry* CList::Insert(CEntry *pEntry)
  264. {
  265. // BUGBUG - assert pnext pprev are null
  266. DIGEST_ASSERT(pEntry
  267. && (pEntry->dwPrev == pEntry->dwNext == 0));
  268. if (!_pHead)
  269. {
  270. _pHead = pEntry;
  271. }
  272. else
  273. {
  274. pEntry->dwNext = POINTER_TO_OFFSET(g_pHeap, _pHead);
  275. _pHead->dwPrev = POINTER_TO_OFFSET(g_pHeap, pEntry);
  276. _pHead = pEntry;
  277. }
  278. *_pdwOffset = POINTER_TO_OFFSET(g_pHeap, pEntry);
  279. return pEntry;
  280. }
  281. //--------------------------------------------------------------------
  282. // CList::DeLink
  283. //--------------------------------------------------------------------
  284. CEntry* CList::DeLink(CEntry *pEntry)
  285. {
  286. DIGEST_ASSERT(pEntry);
  287. if (pEntry == _pHead)
  288. {
  289. _pHead = (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwNext);
  290. *_pdwOffset = POINTER_TO_OFFSET(g_pHeap, _pHead);
  291. }
  292. else
  293. {
  294. CEntry *pPrev;
  295. pPrev = (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwPrev);
  296. pPrev->dwNext = pEntry->dwNext;
  297. }
  298. if (pEntry->dwNext)
  299. {
  300. CEntry *pNext;
  301. pNext = (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwNext);
  302. pNext->dwPrev = pEntry->dwPrev;
  303. }
  304. if (_pCur == pEntry)
  305. {
  306. _pCur = (CEntry*) OFFSET_TO_POINTER(g_pHeap, pEntry->dwNext);
  307. }
  308. return pEntry;
  309. }
  310. //////////////////////////////////////////////////////////////////////
  311. //
  312. // CCred Functions
  313. //
  314. //////////////////////////////////////////////////////////////////////
  315. //--------------------------------------------------------------------
  316. // CCred::Create
  317. //--------------------------------------------------------------------
  318. CCred* CCred::Create(CMMFile *pMMFile,
  319. LPSTR szHost, LPSTR szRealm, LPSTR szUser,
  320. LPSTR szPass, LPSTR szNonce, LPSTR szCNonce)
  321. {
  322. // BUGBUG - assert strings non-null. Nonce can be NULL.
  323. DIGEST_ASSERT(pMMFile && szRealm && szUser && szPass);
  324. // Unaligned string sizes.
  325. DWORD cbRealm = szRealm ? strlen(szRealm) + 1 : 0;
  326. DWORD cbUser = szUser ? strlen(szUser) + 1 : 0;
  327. DWORD cbPass = szPass ? strlen(szPass) + 1 : 0;
  328. // Aligned string sizes.
  329. DWORD cbStructAligned = ROUNDUPDWORD(sizeof(CCred));
  330. DWORD cbRealmAligned = ROUNDUPDWORD(cbRealm);
  331. DWORD cbUserAligned = ROUNDUPDWORD(cbUser);
  332. DWORD cbPassAligned = ROUNDUPDWORD(cbPass);
  333. // Total number of required bytes (aligned).
  334. DWORD cbEntryAligned = cbStructAligned
  335. + cbRealmAligned
  336. + cbUserAligned
  337. + cbPassAligned;
  338. // Allocate cred and nonce from memmap
  339. // BUGBUG - MASKING PNONCE
  340. // BUGBUG - no, I'm not.
  341. CCred *pCred;
  342. CNonce *pNonce, *pCNonce;
  343. pNonce = pCNonce = NULL;
  344. // Allocate a credential.
  345. pCred = (CCred*) pMMFile->AllocateEntry(cbEntryAligned);
  346. if (!pCred)
  347. {
  348. DIGEST_ASSERT(FALSE);
  349. goto exit;
  350. }
  351. DWORD cbCurrentOffset;
  352. cbCurrentOffset = cbStructAligned;
  353. // Realm.
  354. memcpy(OFFSET_TO_POINTER(pCred, cbCurrentOffset), szRealm, cbRealm);
  355. pCred->dwRealm = cbCurrentOffset;
  356. cbCurrentOffset += cbRealmAligned;
  357. // User
  358. memcpy(OFFSET_TO_POINTER(pCred, cbCurrentOffset), szUser, cbUser);
  359. pCred->dwUser = cbCurrentOffset;
  360. cbCurrentOffset += cbUserAligned;
  361. // Pass
  362. memcpy(OFFSET_TO_POINTER(pCred, cbCurrentOffset), szPass, cbPass);
  363. pCred->dwPass = cbCurrentOffset;
  364. pCred->cbCred = cbEntryAligned;
  365. pCred->tStamp = GetTickCount();
  366. pCred->dwSig = SIG_CRED;
  367. pCred->dwPrev = NULL;
  368. pCred->dwNext = NULL;
  369. pCred->dwNonce = 0;
  370. pCred->dwCNonce = 0;
  371. // Allocate nonce and client nonce if specified.
  372. if (szNonce)
  373. CCred::SetNonce(pMMFile, pCred, szHost, szNonce, SERVER_NONCE);
  374. if (szCNonce)
  375. CCred::SetNonce(pMMFile, pCred, szHost, szCNonce, CLIENT_NONCE);
  376. exit:
  377. return pCred;
  378. }
  379. //--------------------------------------------------------------------
  380. // CCred::GetRealm
  381. //--------------------------------------------------------------------
  382. LPSTR CCred::GetRealm(CCred* pCred)
  383. {
  384. DIGEST_ASSERT(pCred);
  385. if (pCred->dwRealm)
  386. return (LPSTR) OFFSET_TO_POINTER(pCred, pCred->dwRealm);
  387. else
  388. return NULL;
  389. }
  390. //--------------------------------------------------------------------
  391. // CCred::GetUser
  392. //--------------------------------------------------------------------
  393. LPSTR CCred::GetUser(CCred* pCred)
  394. {
  395. DIGEST_ASSERT(pCred);
  396. if (pCred->dwUser)
  397. return (LPSTR) OFFSET_TO_POINTER(pCred, pCred->dwUser);
  398. else
  399. return NULL;
  400. }
  401. //--------------------------------------------------------------------
  402. // CCred::GetPass
  403. //--------------------------------------------------------------------
  404. LPSTR CCred::GetPass(CCred* pCred)
  405. {
  406. DIGEST_ASSERT(pCred);
  407. if (pCred->dwPass)
  408. return (LPSTR) OFFSET_TO_POINTER(pCred, pCred->dwPass);
  409. else
  410. return NULL;
  411. }
  412. //--------------------------------------------------------------------
  413. // CCred::SetNonce
  414. //--------------------------------------------------------------------
  415. VOID CCred::SetNonce(CMMFile *pMMFile, CCred* pCred,
  416. LPSTR szHost, LPSTR szNonce, DWORD dwType)
  417. {
  418. DIGEST_ASSERT(pCred && szNonce);
  419. // First determine if a nonce for the specified host
  420. // already exists and delete it if it does.
  421. CList NonceList;
  422. NonceList.Init(dwType == SERVER_NONCE ?
  423. &pCred->dwNonce : &pCred->dwCNonce);
  424. CNonce *pNonce;
  425. while (pNonce = (CNonce*) NonceList.GetNext())
  426. {
  427. if (CNonce::IsHostMatch(pNonce, szHost))
  428. {
  429. NonceList.DeLink(pNonce);
  430. CEntry::Free(pMMFile, pNonce);
  431. break;
  432. }
  433. }
  434. // Create a CNonce object and insert it into the list.
  435. pNonce = CNonce::Create(pMMFile, szHost, szNonce);
  436. if (pNonce)
  437. {
  438. NonceList.Seek();
  439. NonceList.Insert(pNonce);
  440. }
  441. else
  442. {
  443. DIGEST_ASSERT(FALSE);
  444. }
  445. }
  446. //--------------------------------------------------------------------
  447. // CCred::GetNonce
  448. //--------------------------------------------------------------------
  449. CNonce *CCred::GetNonce(CCred* pCred, LPSTR szHost, DWORD dwType)
  450. {
  451. CNonce *pNonce;
  452. CList NonceList;
  453. NonceList.Init(dwType == SERVER_NONCE ?
  454. &pCred->dwNonce : &pCred->dwCNonce);
  455. while (pNonce = (CNonce*) NonceList.GetNext())
  456. {
  457. if (CNonce::IsHostMatch(pNonce, szHost))
  458. break;
  459. }
  460. return pNonce;
  461. }
  462. //--------------------------------------------------------------------
  463. // CCred::Free
  464. //--------------------------------------------------------------------
  465. VOID CCred::Free(CMMFile *pMMFile, CSess *pSess, CCred *pCred)
  466. {
  467. CNonce *pNonce;
  468. CList NonceList;
  469. // Free up server nonce.
  470. NonceList.Init(&pCred->dwNonce);
  471. while (pNonce = (CNonce*) NonceList.GetNext())
  472. {
  473. NonceList.DeLink(pNonce);
  474. CEntry::Free(pMMFile, pNonce);
  475. }
  476. // Free up client nonce.
  477. NonceList.Init(&pCred->dwCNonce);
  478. while (pNonce = (CNonce*) NonceList.GetNext())
  479. {
  480. NonceList.DeLink(pNonce);
  481. CEntry::Free(pMMFile, pNonce);
  482. }
  483. // Remove credential from session's list.
  484. CList CredList;
  485. CredList.Init(&pSess->dwCred);
  486. CredList.DeLink(pCred);
  487. CEntry::Free(pMMFile, pCred);
  488. }
  489. //////////////////////////////////////////////////////////////////////
  490. //
  491. // CNonce Functions
  492. //
  493. //////////////////////////////////////////////////////////////////////
  494. //--------------------------------------------------------------------
  495. // CNonce::Create
  496. //--------------------------------------------------------------------
  497. CNonce* CNonce::Create(CMMFile *pMMFile, LPSTR szHost, LPSTR szNonce)
  498. {
  499. DIGEST_ASSERT(pMMFile && szNonce);
  500. // Unaligned string sizes.
  501. DWORD cbNonce = szNonce ? strlen(szNonce) + 1 : 0;
  502. DWORD cbHost = szHost ? strlen(szHost) + 1 : 0;
  503. // Aligned string sizes.
  504. DWORD cbStructAligned = ROUNDUPDWORD(sizeof(CNonce));
  505. DWORD cbNonceAligned = ROUNDUPDWORD(cbNonce);
  506. DWORD cbHostAligned = ROUNDUPDWORD(cbHost);
  507. // Total number of required bytes (aligned).
  508. DWORD cbEntryAligned = cbStructAligned
  509. + cbHostAligned
  510. + cbNonceAligned;
  511. // Allocate from mem map.
  512. CNonce *pNonce = (CNonce*) pMMFile->AllocateEntry(cbEntryAligned);
  513. // Failed to allocate.
  514. if (!pNonce)
  515. {
  516. DIGEST_ASSERT(FALSE);
  517. goto exit;
  518. }
  519. DWORD cbCurrentOffset;
  520. cbCurrentOffset = cbStructAligned;
  521. // Host.
  522. if (szHost)
  523. {
  524. memcpy(OFFSET_TO_POINTER(pNonce, cbCurrentOffset), szHost, cbHost);
  525. pNonce->dwHost = cbCurrentOffset;
  526. cbCurrentOffset += cbHostAligned;
  527. }
  528. else
  529. {
  530. pNonce->dwHost = 0;
  531. }
  532. // Nonce.
  533. memcpy(OFFSET_TO_POINTER(pNonce, cbCurrentOffset), szNonce, cbNonce);
  534. pNonce->dwNonce = cbCurrentOffset;
  535. cbCurrentOffset += cbNonceAligned;
  536. pNonce->cbNonce = cbEntryAligned;
  537. pNonce->cCount = 0;
  538. pNonce->dwSig = SIG_NONC;
  539. pNonce->dwPrev = 0;
  540. pNonce->dwNext = 0;
  541. exit:
  542. return pNonce;
  543. }
  544. //--------------------------------------------------------------------
  545. // CNonce::GetNonce
  546. //--------------------------------------------------------------------
  547. LPSTR CNonce::GetNonce(CNonce* pNonce)
  548. {
  549. if (pNonce && pNonce->dwNonce)
  550. return (LPSTR) OFFSET_TO_POINTER(pNonce, pNonce->dwNonce);
  551. else
  552. return NULL;
  553. }
  554. //--------------------------------------------------------------------
  555. // CNonce::GetCount
  556. // bugbug - what if no nonce?
  557. //--------------------------------------------------------------------
  558. DWORD CNonce::GetCount(CNonce* pNonce)
  559. {
  560. DIGEST_ASSERT(pNonce);
  561. return pNonce->cCount;
  562. }
  563. //--------------------------------------------------------------------
  564. // CNonce::IsHostMatch
  565. //--------------------------------------------------------------------
  566. BOOL CNonce::IsHostMatch(CNonce *pNonce, LPSTR szHost)
  567. {
  568. if (szHost)
  569. {
  570. if (pNonce->dwHost
  571. && !strcmp(szHost, (LPSTR) OFFSET_TO_POINTER(pNonce, pNonce->dwHost)))
  572. return TRUE;
  573. return FALSE;
  574. }
  575. if (!pNonce->dwHost)
  576. return TRUE;
  577. return FALSE;
  578. }
  579. //////////////////////////////////////////////////////////////////////
  580. //
  581. // CCredInfo Functions
  582. //
  583. //////////////////////////////////////////////////////////////////////
  584. //--------------------------------------------------------------------
  585. // CCredInfo::CCredInfo
  586. //--------------------------------------------------------------------
  587. CCredInfo::CCredInfo(CCred* pCred, LPSTR szHost)
  588. {
  589. DIGEST_ASSERT(pCred
  590. && (pCred->dwPass > pCred->dwUser)
  591. && (pCred->dwUser > pCred->dwRealm));
  592. CCredInfo::szHost = NewString(szHost);
  593. szRealm = NewString(CCred::GetRealm(pCred));
  594. szUser = NewString(CCred::GetUser(pCred));
  595. szPass = NewString(CCred::GetPass(pCred));
  596. // Get server nonce. This is always required.
  597. // BUGBUG - what about pre-loading?
  598. CNonce *pNonce;
  599. pNonce = CCred::GetNonce(pCred, szHost, SERVER_NONCE);
  600. if (!pNonce)
  601. {
  602. dwStatus = ERROR_INVALID_PARAMETER;
  603. return;
  604. }
  605. szNonce = NewString(CNonce::GetNonce(pNonce));
  606. cCount = pNonce->cCount;
  607. pNonce = CCred::GetNonce(pCred, szHost, CLIENT_NONCE);
  608. if (pNonce)
  609. szCNonce = NewString(CNonce::GetNonce(pNonce));
  610. else
  611. szCNonce = NULL;
  612. tStamp = pCred->tStamp;
  613. pPrev = NULL;
  614. pNext = NULL;
  615. dwStatus = ERROR_SUCCESS;
  616. }
  617. //--------------------------------------------------------------------
  618. // CCredInfo::CCredInfo
  619. // BUGBUG - special casing for NULLs, especially szNonce.
  620. //--------------------------------------------------------------------
  621. CCredInfo::CCredInfo(LPSTR szHost, LPSTR szRealm, LPSTR szUser,
  622. LPSTR szPass, LPSTR szNonce, LPSTR szCNonce)
  623. {
  624. CCredInfo::szHost = NewString(szHost);
  625. CCredInfo::szRealm = NewString(szRealm);
  626. CCredInfo::szUser = NewString(szUser);
  627. CCredInfo::szPass = NewString(szPass);
  628. CCredInfo::szNonce = NewString(szNonce);
  629. CCredInfo::szCNonce = NewString(szCNonce);
  630. cCount = 0;
  631. tStamp = 0;
  632. pPrev = NULL;
  633. pNext = NULL;
  634. dwStatus = ERROR_SUCCESS;
  635. }
  636. //--------------------------------------------------------------------
  637. // CCredInfo::~CCredInfo
  638. //--------------------------------------------------------------------
  639. CCredInfo::~CCredInfo()
  640. {
  641. if (szHost)
  642. delete [] szHost;
  643. if (szRealm)
  644. delete [] szRealm;
  645. if (szUser)
  646. delete [] szUser;
  647. if (szPass)
  648. delete [] szPass;
  649. if (szNonce)
  650. delete [] szNonce;
  651. if (szCNonce)
  652. delete [] szCNonce;
  653. }