--- mstools/samples/ddeml/server/dde.c 2018/08/09 18:21:28 1.1.1.2 +++ mstools/samples/ddeml/server/dde.c 2018/08/09 18:23:25 1.1.1.3 @@ -1,3 +1,14 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + /* * This module serves to demonstrate one way a sophisticated DDE server * that uses enumerable topics and items might be implemented. It takes @@ -37,7 +48,8 @@ PCONVCONTEXT pCC) // old DDE app client case...pCC == NULL if (pCC == NULL && CCFilter.dwSecurity == 0 && // were nonsecure - CCFilter.iCodePage == CP_WINANSI // were normal cp + CCFilter.iCodePage == CP_WINANSI && // were normal cp + CCFilter.qos.ImpersonationLevel == SecurityImpersonation ) { return(TRUE); } @@ -45,7 +57,8 @@ PCONVCONTEXT pCC) if (pCC && pCC->wFlags == CCFilter.wFlags && // no special flags needed pCC->iCodePage == CCFilter.iCodePage && // codepages match - pCC->dwSecurity == CCFilter.dwSecurity) { // security passes + pCC->dwSecurity == CCFilter.dwSecurity && // security passes + pCC->qos.ImpersonationLevel >= CCFilter.qos.ImpersonationLevel) { // dont care about language and country. return(TRUE); } @@ -114,7 +127,7 @@ DWORD lData2) */ if (wFmt) { for (iFmt = 0; iFmt < CFORMATS; iFmt++) { - if (wFmt == aFormats[iFmt].atom) + if ((ATOM)wFmt == aFormats[iFmt].atom) break; } if (iFmt == CFORMATS) @@ -199,18 +212,47 @@ DWORD lData2) for (j = 0; j < cItems; j++) { if (DdeCmpStringHandles(pItemList[j].hszItem, hszItem) == 0) { XFERINFO xi; + /* - * Make call to worker function here... + * If Win32s - security isn't supported */ - xi.wType = wType; - xi.wFmt = wFmt; - xi.hConv = hConv; - xi.hszTopic = hszTopic; - xi.hszItem = hszItem; - xi.hData = hData; - xi.lData1 = lData1; - xi.lData2 = lData2; - hDataRet = (*pItemList[j].npfnCallback)(&xi, iFmt); + if(GetVersion() & 0x80000000) { + /* + * Make call to worker function here... + */ + xi.wType = wType; + xi.wFmt = wFmt; + xi.hConv = hConv; + xi.hszTopic = hszTopic; + xi.hszItem = hszItem; + xi.hData = hData; + xi.lData1 = lData1; + xi.lData2 = lData2; + hDataRet = (*pItemList[j].npfnCallback)(&xi, iFmt); + } else { + /* + * Windows NT - impersonate client here + */ + if (DdeImpersonateClient(hConv)) { + /* + * Make call to worker function here... + */ + xi.wType = wType; + xi.wFmt = wFmt; + xi.hConv = hConv; + xi.hszTopic = hszTopic; + xi.hszItem = hszItem; + xi.hData = hData; + xi.lData1 = lData1; + xi.lData2 = lData2; + hDataRet = (*pItemList[j].npfnCallback)(&xi, iFmt); + RevertToSelf(); + } else { + pszComment = "Impersonation failed."; + InvalidateRect(hwndServer, &rcComment, TRUE); + hDataRet = 0; + } + } ReturnSpot: /* @@ -633,7 +675,7 @@ WORD iFmt) VOID Hszize() { register ITEMLIST *pItemList; - WORD iTopic, iItem; + int iTopic, iItem; hszAppName = DdeCreateStringHandle(idInst, szServer, 0); @@ -641,7 +683,7 @@ VOID Hszize() topicList[iTopic].hszTopic = DdeCreateStringHandle(idInst, topicList[iTopic].pszTopic, 0); pItemList = topicList[iTopic].pItemList; - for (iItem = 0; iItem < topicList[iTopic].cItems; iItem++) { + for (iItem = 0; iItem < (int)topicList[iTopic].cItems; iItem++) { pItemList[iItem].hszItem = DdeCreateStringHandle(idInst, pItemList[iItem].pszItem, 0); } @@ -659,14 +701,14 @@ VOID Hszize() VOID UnHszize() { register ITEMLIST *pItemList; - WORD iTopic, iItem; + int iTopic, iItem; DdeFreeStringHandle(idInst, hszAppName); for (iTopic = 0; iTopic < CTOPICS; iTopic++) { DdeFreeStringHandle(idInst, topicList[iTopic].hszTopic); pItemList = topicList[iTopic].pItemList; - for (iItem = 0; iItem < topicList[iTopic].cItems; iItem++) { + for (iItem = 0; iItem < (int)topicList[iTopic].cItems; iItem++) { DdeFreeStringHandle(idInst, pItemList[iItem].hszItem); } }