--- mstools/samples/ddeml/server/dde.c 2018/08/09 18:20:38 1.1.1.1 +++ 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); } @@ -61,8 +74,8 @@ PCONVCONTEXT pCC) * \***************************************************************************/ HDDEDATA CALLBACK DdeCallback( -WORD wType, -WORD wFmt, +UINT wType, +UINT wFmt, HCONV hConv, HSZ hszTopic, HSZ hszItem, @@ -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: /* @@ -283,7 +325,7 @@ WORD iFmt) pszTopicList = (LPSTR)DdeAccessData(hData, NULL); if (pszTopicList) { for (i = 0; i < CTOPICS; i++) { - _fstrcpy(pszTopicList, topicList[i].pszTopic); + strcpy(pszTopicList, topicList[i].pszTopic); pszTopicList += strlen(topicList[i].pszTopic); *pszTopicList++ = '\t'; } @@ -349,7 +391,7 @@ WORD iFmt) pszItemList = (LPSTR)DdeAccessData(hData, NULL); if (pszItemList) { for (i = 0; i < cItems; i++) { - _fstrcpy(pszItemList, pItemList[i].pszItem); + strcpy(pszItemList, pItemList[i].pszItem); pszItemList += strlen(pItemList[i].pszItem); *pszItemList++ = '\t'; } @@ -394,8 +436,8 @@ WORD iFmt) 0L, pXferInfo->hszItem, pXferInfo->wFmt, 0); psz = pszT = DdeAccessData(hData, NULL); for (i = 0; i < CFORMATS; i++) { - _fstrcpy(pszT, aFormats[i].sz); - pszT += _fstrlen(pszT); + strcpy(pszT, aFormats[i].sz); + pszT += strlen(pszT); *pszT++ = '\t'; } *(--pszT) = '\0'; @@ -443,8 +485,9 @@ WORD iFmt) case XTYP_ADVREQ: Delay(RenderDelay, FALSE); if (!hDataRand[iFmt]) { - hDataRand[iFmt] = DdeCreateDataHandle(idInst, NULL, 0, 10, pXferInfo->hszItem, - pXferInfo->wFmt, fAppowned ? HDATA_APPOWNED : 0); + hDataRand[iFmt] = DdeCreateDataHandle(idInst, NULL, 0, 10, + pXferInfo->hszItem, (UINT)pXferInfo->wFmt, + fAppowned ? HDATA_APPOWNED : 0); if (pszData = DdeAccessData(hDataRand[iFmt], NULL)) { wsprintf(pszData, "%d", seed); DdeUnaccessData(hDataRand[iFmt]); @@ -576,9 +619,9 @@ WORD iFmt) pszComment = szComment; InvalidateRect(hwndServer, &rcComment, TRUE); UpdateWindow(hwndServer); - hDataHuge[iFmt] = CreateHugeDataHandle(cbHuge, 4325, 345, 5, + hDataHuge[iFmt] = CreateHugeDataHandle((LONG)cbHuge, 4325, 345, 5, pXferInfo->hszItem, - pXferInfo->wFmt, fAppowned ? HDATA_APPOWNED : 0); + pXferInfo->wFmt, (WORD)(fAppowned ? HDATA_APPOWNED : 0)); pszComment = ""; InvalidateRect(hwndServer, &rcComment, TRUE); InvalidateRect(hwndServer, &rcHugeSize, TRUE); @@ -632,7 +675,7 @@ WORD iFmt) VOID Hszize() { register ITEMLIST *pItemList; - WORD iTopic, iItem; + int iTopic, iItem; hszAppName = DdeCreateStringHandle(idInst, szServer, 0); @@ -640,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); } @@ -658,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); } }