home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / remote.srv / rabrpc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  18.6 KB  |  527 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  File Name 
  4. //      RABRPC.CPP
  5. //
  6. //  Description
  7. //      This file implements all the remote functions available to client
  8. //      WINDS address book providers. 
  9. //      
  10. //  Author
  11. //      Irving De la Cruz
  12. //
  13. //  Revision: 1.7
  14. //
  15. // Written for Microsoft Windows Developer Support
  16. // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
  17. //
  18. #include "_WINDS.H"
  19. #include <RPC.H>
  20. #include "WINDS.H"      // Header file generated by the MIDL compiler
  21. #include "WDSADM.H"     // Header file generated by the MIDL compiler
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////
  24. //    RemoteChangePasswordA()
  25. //
  26. //    Parameters
  27. //
  28. //    Purpose
  29. //
  30. //    Return Value
  31. //
  32. long RemoteChangePasswordA (unsigned char *  szMailbox,
  33.                             unsigned char *  szOldPassword,
  34.                             unsigned char *  szNewPassword)
  35. {
  36.     long lResult = GetServiceState();
  37.     if (lResult)
  38.     {
  39.         return lResult;
  40.     }
  41.     MAILBOX_INFO MBInfo = { 0 };
  42.     if (S_OK != GlobalObjectMap.FindObjFromName (SERVER_USER_MAILBOX, (LPSTR)szMailbox, &MBInfo.dwObjID))
  43.     {
  44.         TraceMessage ("RemoteChangePasswordA: Invalid mailbox");
  45.         return HRESULT_FROM_WIN32(ERROR_NO_SUCH_USER);
  46.     }
  47.     lstrcpy (MBInfo.szMailboxName, (LPSTR)szMailbox);
  48.     
  49.     HANDLE hWaitEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  50.     if (!hWaitEvent)
  51.     {
  52.         lResult = HRESULT_FROM_WIN32(GetLastError());
  53.         TraceResult ("RemoteChangePasswordA: Failed to create I/O event", lResult);
  54.         return lResult;
  55.     }
  56.     EnterCriticalSection (&g_csIOInfo);
  57.     SetEvent (g_IOInfo.hResumeEvent);
  58.     g_IOInfo.Action           = IO_GET_MAILBOX_PROPERTIES;
  59.     g_IOInfo.hActionCompleted = hWaitEvent;
  60.     g_IOInfo.phLastError      = &lResult;
  61.     g_IOInfo.pMBInfo          = &MBInfo;
  62.     LeaveCriticalSection (&g_csIOInfo);
  63.     WaitForSingleObject (hWaitEvent, GENERAL_TIME_OUT);
  64.     if (S_OK == lResult)
  65.     {
  66.         if (0 == lstrcmp (MBInfo.szPassword, (LPSTR)szOldPassword))
  67.         {
  68.             lstrcpy (MBInfo.szPassword, (LPSTR)szNewPassword);
  69.             EnterCriticalSection (&g_csIOInfo);
  70.             SetEvent (g_IOInfo.hResumeEvent);
  71.             g_IOInfo.Action           = IO_SET_MAILBOX_PROPERTIES;
  72.             g_IOInfo.hActionCompleted = hWaitEvent;
  73.             g_IOInfo.phLastError      = &lResult;
  74.             g_IOInfo.pMBInfo          = &MBInfo;
  75.             LeaveCriticalSection (&g_csIOInfo);
  76.             WaitForSingleObject (hWaitEvent, GENERAL_TIME_OUT);
  77.         }
  78.         else
  79.         {
  80.             lResult = HRESULT_FROM_WIN32(ERROR_WRONG_PASSWORD);
  81.         }
  82.     }
  83.     CloseHandle (hWaitEvent);
  84.     TraceResult ("RemoteChangePasswordA", lResult);
  85.     return lResult;
  86. }
  87.  
  88. ///////////////////////////////////////////////////////////////////////////////
  89. //    RemoteGetRecipientPropsA()
  90. //
  91. //    Parameters
  92. //
  93. //    Purpose
  94. //
  95. //    Return Value
  96. //
  97. long RemoteGetRecipientPropsA (unsigned long    dwObjID,
  98.                                unsigned long *  pdwObjType,
  99.                                unsigned char *  szMailboxName,
  100.                                unsigned char *  szFullName,
  101.                                unsigned char *  szJobTitle,
  102.                                unsigned char *  szOffice,
  103.                                unsigned char *  szPhone,
  104.                                unsigned char *  szAltPhone,
  105.                                unsigned char *  szFax,
  106.                                unsigned char *  szComments,
  107.                                unsigned char *  szCompany,
  108.                                unsigned char *  szDepartment,
  109.                                unsigned char *  szManagerName,
  110.                                unsigned char *  szManagerAlias,
  111.                                unsigned long *  pdwManagerID)
  112. {
  113.     long lResult = GetServiceState();
  114.     if (lResult)
  115.     {
  116.         return lResult;
  117.     }
  118.     MAILBOX_INFO_A MBInfo = { 0 };
  119.     MBInfo.dwObjID = dwObjID;
  120.     lResult = GetObjectProp (dwObjID, pdwObjType, &MBInfo);
  121.     if (S_OK == lResult)
  122.     {
  123.         lstrcpy ((LPSTR)szMailboxName,  MBInfo.szMailboxName);
  124.         lstrcpy ((LPSTR)szFullName,     MBInfo.szFullName);
  125.         lstrcpy ((LPSTR)szJobTitle,     MBInfo.szJobTitle);
  126.         lstrcpy ((LPSTR)szOffice,       MBInfo.szOffice);
  127.         lstrcpy ((LPSTR)szPhone,        MBInfo.szPhone);
  128.         lstrcpy ((LPSTR)szFax,          MBInfo.szFax);
  129.         lstrcpy ((LPSTR)szComments,     MBInfo.szComments);
  130.         lstrcpy ((LPSTR)szAltPhone,     MBInfo.szAltPhone);
  131.         lstrcpy ((LPSTR)szCompany,      MBInfo.szCompany);
  132.         lstrcpy ((LPSTR)szDepartment,   MBInfo.szDepartment);
  133.         lstrcpy ((LPSTR)szManagerName,  MBInfo.szManagerName);
  134.         lstrcpy ((LPSTR)szManagerAlias, MBInfo.szManagerAlias);
  135.         *pdwManagerID = MBInfo.dwManagerID;
  136.     }
  137.     return lResult;
  138. }
  139.  
  140. ///////////////////////////////////////////////////////////////////////////////
  141. //    GetObjectProp()
  142. //
  143. //    Parameters
  144. //
  145. //    Purpose
  146. //
  147. //    Return Value
  148. //
  149. HRESULT WINAPI GetObjectProp (DWORD             dwObjID,
  150.                               DWORD *           pdwObjType,
  151.                               MAILBOX_INFO *    pMailboxInfo)
  152. {
  153.     if (dwObjID == 0)
  154.     {
  155.         TraceMessage ("GetObjectProp: Invoked with Object ID = 0, cannot accept");
  156.         return HRESULT_FROM_WIN32 (ERROR_NO_SUCH_USER);
  157.     }
  158.  
  159.     MAILBOX_INFO MBInfo = { 0 };
  160.     WINDS_AB_OBJTYPE Type = UNDEFINED_OBJECT_TYPE;
  161.     // If an object with the given ID is not found or if the
  162.     // found object is not the expected, the fail the client request
  163.     if ((S_OK != GlobalObjectMap.FindObjFromID (dwObjID, MBInfo.szMailboxName, &Type)) ||
  164.         (!(SERVER_USER_MAILBOX == Type || GATEWAY_RECIPIENT == Type)))
  165.     {
  166.         return HRESULT_FROM_WIN32 (ERROR_NO_SUCH_USER);
  167.     }
  168.     ASSERT (SERVER_USER_MAILBOX == Type || GATEWAY_RECIPIENT == Type);
  169.     *pdwObjType = (unsigned long)Type;
  170.     HRESULT hResult;
  171.  
  172.     HANDLE hWaitEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  173.     if (!hWaitEvent)
  174.     {
  175.         hResult = HRESULT_FROM_WIN32(GetLastError());
  176.         TraceResult ("GetMailboxProp: Failed to create I/O event", hResult);
  177.         return hResult;
  178.     }
  179.     EnterCriticalSection (&g_csIOInfo);
  180.     SetEvent (g_IOInfo.hResumeEvent);
  181.     if (SERVER_USER_MAILBOX == Type)
  182.     {
  183.         g_IOInfo.Action = IO_GET_MAILBOX_PROPERTIES;
  184.     }
  185.     else
  186.     {
  187.         ASSERT (FALSE); // We haven't implemented gateway yet
  188.         g_IOInfo.Action = IO_GET_MAILBOX_PROPERTIES;
  189.     }
  190.     g_IOInfo.hActionCompleted = hWaitEvent;
  191.     g_IOInfo.phLastError      = &hResult;
  192.     g_IOInfo.pMBInfo          = &MBInfo;
  193.     LeaveCriticalSection (&g_csIOInfo);
  194.     WaitForSingleObject (hWaitEvent, GENERAL_TIME_OUT);
  195.     CloseHandle (hWaitEvent);
  196.     if (!hResult)
  197.     {
  198.         if (SERVER_USER_MAILBOX == Type)
  199.         {
  200.             *pMailboxInfo = MBInfo;
  201.         }
  202.         else
  203.         {
  204.             ASSERT (FALSE);
  205.             hResult = E_FAIL;
  206.         }
  207.     }
  208.     return hResult;
  209. }
  210.  
  211. ///////////////////////////////////////////////////////////////////////////////
  212. //    RemoteGetDistListPropsA()
  213. //
  214. //    Parameters
  215. //
  216. //    Purpose
  217. //
  218. //    Return Value
  219. //
  220. long RemoteGetDistListPropsA (unsigned long     dwObjID,
  221.                               unsigned char *   szDLAlias,
  222.                               unsigned char *   szDLFullName,
  223.                               unsigned long *   pdwContentCount,
  224.                               unsigned char *   szOwnerAlias,
  225.                               unsigned char *   szOwnerName,
  226.                               unsigned char *   szComments)
  227. {
  228.     long lResult = GetServiceState();
  229.     if (lResult)
  230.     {
  231.         return lResult;
  232.     }
  233.     DIST_LIST_INFO DLInfo = { 0 };
  234.     WINDS_AB_OBJTYPE Type = UNDEFINED_OBJECT_TYPE;
  235.     if ((S_OK != GlobalObjectMap.FindObjFromID (dwObjID, DLInfo.szDLAlias, &Type)) ||
  236.         (SERVER_DISTRIBUTION_LIST != Type))
  237.     {
  238.         return HRESULT_FROM_WIN32 (ERROR_NO_SUCH_GROUP);
  239.     }
  240.  
  241.     HANDLE hWaitEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  242.     if (!hWaitEvent)
  243.     {
  244.         lResult = HRESULT_FROM_WIN32(GetLastError());
  245.         TraceResult ("RemoteGetDistListPropsA: Failed to create I/O event", lResult);
  246.         return HRESULT_FROM_WIN32(lResult);
  247.     }
  248.     EnterCriticalSection (&g_csIOInfo);
  249.     SetEvent (g_IOInfo.hResumeEvent);
  250.     g_IOInfo.Action           = IO_GET_DL_PROPERTIES;
  251.     g_IOInfo.hActionCompleted = hWaitEvent;
  252.     g_IOInfo.phLastError      = &lResult;
  253.     g_IOInfo.pDLInfo          = &DLInfo;
  254.     LeaveCriticalSection (&g_csIOInfo);
  255.     WaitForSingleObject (hWaitEvent, GENERAL_TIME_OUT);
  256.     CloseHandle (hWaitEvent);
  257.     if (!lResult)
  258.     {
  259.         lstrcpy ((LPSTR)szDLAlias, DLInfo.szDLAlias);
  260.         lstrcpy ((LPSTR)szDLFullName, DLInfo.szDLFullName);
  261.         lstrcpy ((LPSTR)szOwnerAlias, DLInfo.szOwnerAlias);
  262.         lstrcpy ((LPSTR)szOwnerName, DLInfo.szOwnerName);
  263.         lstrcpy ((LPSTR)szComments, DLInfo.szComments);
  264.         *pdwContentCount = DLInfo.dwMemberCount;
  265.     }
  266.     return lResult;
  267. }
  268.  
  269. ///////////////////////////////////////////////////////////////////////////////
  270. //    RemoteGetContainerProps()
  271. //
  272. //    Parameters
  273. //
  274. //    Purpose
  275. //
  276. //    Return Value
  277. //
  278. long RemoteGetContainerProps (unsigned long     dwContainerID,
  279.                               unsigned long *   pdwContentCount)
  280. {
  281.     long lResult = GetServiceState();
  282.     if (lResult)
  283.     {
  284.         return lResult;
  285.     }
  286.     switch (dwContainerID)
  287.     {
  288.         case ROOT_CONTAINER_ID :
  289.         case GATEWAY_CONTAINERS_ID :
  290.         case GAL_CONTAINER_ID :
  291.             *pdwContentCount = 0;
  292.             if (GAL_CONTAINER_ID == dwContainerID)
  293.             {
  294.                 *pdwContentCount = 0;
  295.             }
  296.             return S_OK;
  297.         case FAX_CONTAINER_ID :
  298.         case SMTP_CONTAINER_ID :
  299.         case EXCHANGE_CONTAINER_ID :
  300.             break;
  301.         
  302.         default :
  303.             TraceMessage ("RemoteGetContainerProps: Invalid container ID passed in");
  304.             return HRESULT_FROM_WIN32(ERROR_NO_SUCH_GROUP);
  305.     }
  306.     HANDLE hWaitEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  307.     if (!hWaitEvent)
  308.     {
  309.         lResult = HRESULT_FROM_WIN32(GetLastError());
  310.         TraceResult ("RemoteGetContainerProps: Failed to create I/O event", lResult);
  311.         return lResult;
  312.     }
  313.     EnterCriticalSection (&g_csIOInfo);
  314.     SetEvent (g_IOInfo.hResumeEvent);
  315.     g_IOInfo.Action           = IO_GET_GW_CONTAINER_COUNT;
  316.     g_IOInfo.hActionCompleted = hWaitEvent;
  317.     g_IOInfo.phLastError      = &lResult;
  318.     g_IOInfo.pdwData          = pdwContentCount;
  319.     LeaveCriticalSection (&g_csIOInfo);
  320.     WaitForSingleObject (hWaitEvent, GENERAL_TIME_OUT);
  321.     CloseHandle (hWaitEvent);
  322.     return lResult;
  323. }
  324.  
  325. ///////////////////////////////////////////////////////////////////////////////
  326. //    RemoteGetContainerRecipients()
  327. //
  328. //    Parameters
  329. //
  330. //    Purpose
  331. //
  332. //    Return Value
  333. //
  334. long RemoteGetContainerRecipients (unsigned long    dwFlags,
  335.                                    unsigned long    dwContainerID,
  336.                                    long *           pPipeNumber)
  337. {
  338.     long lResult = GetServiceState();
  339.     if (lResult)
  340.     {
  341.         return lResult;
  342.     }
  343.     
  344.     *pPipeNumber = GetNextPipeID();
  345.  
  346.     SECURITY_ATTRIBUTES sa;
  347.     SECURITY_DESCRIPTOR sd;
  348.  
  349.     // Initialize the new security descriptor.
  350.     InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
  351.  
  352.     // Add a NULL descriptor ACL to the security descriptor.
  353.     SetSecurityDescriptorDacl (&sd, TRUE, (PACL)NULL, FALSE);
  354.  
  355.     sa.nLength = sizeof(sa);
  356.     sa.lpSecurityDescriptor = &sd;
  357.     sa.bInheritHandle = TRUE;
  358.  
  359.     // Create a pipe where we will expect the transport to send the data
  360.     TCHAR szPipeName[64];
  361.     wsprintf (szPipeName, SERVER_PIPE_NAME_FORMAT, *pPipeNumber);
  362.     HANDLE hPipe;
  363.     hPipe = CreateNamedPipe (szPipeName,
  364.                              PIPE_ACCESS_OUTBOUND | FILE_FLAG_OVERLAPPED,
  365.                              PIPE_WAIT | PIPE_READMODE_BYTE | PIPE_TYPE_BYTE,
  366.                              1,
  367.                              IO_BUFFERSIZE,
  368.                              IO_BUFFERSIZE,
  369.                              0,
  370.                              &sa);
  371.     if (INVALID_HANDLE_VALUE == hPipe || ERROR_INVALID_PARAMETER == (DWORD)hPipe)
  372.     {
  373.         lResult = HRESULT_FROM_WIN32(GetLastError());
  374.         TraceResult ("RemoteGetContainerRecipients: Failed to create pipe", lResult);
  375.         goto ErrorExit;
  376.     }
  377.  
  378.     EnterCriticalSection (&g_csIOInfo);
  379.     SetEvent (g_IOInfo.hResumeEvent);
  380.     g_IOInfo.Action           = IO_GET_CONTAINER_RECIPIENTS;
  381.     g_IOInfo.hActionCompleted = NULL;
  382.     g_IOInfo.phLastError      = NULL;
  383.     g_IOInfo.dwObjID          = dwContainerID;
  384.     g_IOInfo.hTmpFile         = hPipe;
  385.     LeaveCriticalSection (&g_csIOInfo);
  386.  
  387. ErrorExit:
  388.     return lResult;
  389. }
  390.  
  391. ///////////////////////////////////////////////////////////////////////////////
  392. //    RemoteIsServerRunning()
  393. //
  394. //    Parameters
  395. //
  396. //    Purpose
  397. //
  398. //    Return Value
  399. //
  400. long RemoteIsServerRunning()
  401. {
  402.     return GetServiceState();
  403. }
  404.  
  405. ///////////////////////////////////////////////////////////////////////////////
  406. //    RemoteGetAllAccounts()
  407. //
  408. //    Parameters
  409. //
  410. //    Purpose
  411. //
  412. //    Return Value
  413. //
  414. long RemoteGetAllAccounts (long * pPipeNumber)
  415. {
  416.     return RemoteAdmGetServerMailboxes (pPipeNumber);
  417. }
  418.  
  419. ///////////////////////////////////////////////////////////////////////////////
  420. //    RemoteLogonMailBoxA()
  421. //
  422. //    Parameters
  423. //
  424. //    Purpose
  425. //
  426. //    Return Value
  427. //
  428. long RemoteLogonMailBoxA (unsigned char *    szMailbox,
  429.                           unsigned char *    szPassword,
  430.                           unsigned char *    szFullName,
  431.                           unsigned long *    pdwMailboxID)
  432. {
  433.     long lResult = GetServiceState();
  434.     if (lResult)
  435.     {
  436.         return lResult;
  437.     }
  438.     if (S_OK != GlobalObjectMap.FindObjFromName (SERVER_USER_MAILBOX, (LPSTR)szMailbox, pdwMailboxID))
  439.     {
  440.         return HRESULT_FROM_WIN32(ERROR_NO_SUCH_USER);
  441.     }
  442.  
  443.     DWORD dwObjType;
  444.     MAILBOX_INFO_A MBInfo = { 0 };
  445.     lResult = GetObjectProp (*pdwMailboxID, &dwObjType, &MBInfo);
  446.     if (lstrcmp (MBInfo.szPassword, (LPSTR)szPassword))
  447.     {
  448.         return HRESULT_FROM_WIN32(ERROR_INVALID_PASSWORD);
  449.     }
  450.     lstrcpy ((LPSTR)szMailbox, MBInfo.szMailboxName);
  451.     lstrcpy ((LPSTR)szFullName, MBInfo.szFullName);
  452.     return S_OK;
  453. }
  454.  
  455. // The UNICODE version of these function, has not been implemented yet.
  456. long RemoteChangePasswordW (wchar_t *       szMailbox,
  457.                             wchar_t *       szOldPassword,
  458.                             wchar_t *       szNewPassword)
  459. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  460. long RemoteLogonMailBoxW (wchar_t *          szMailbox,
  461.                           wchar_t *          szPassword,
  462.                           wchar_t *          szFullName,
  463.                           unsigned long *    pdwMailboxID)
  464. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  465. long RemoteLogonMailBoxAndSetNotifW (wchar_t *          szMailbox,
  466.                                      wchar_t *          szPassword,
  467.                                      wchar_t *          szFullName,
  468.                                      unsigned long *    pdwMailboxID,
  469.                                      wchar_t *          szComputerName,
  470.                                      unsigned long      ulNotifMask,
  471.                                      unsigned long *    pulConnectionID)
  472. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  473. long RemoteTerminateNotifW (wchar_t *       szComputerName,
  474.                             unsigned long   ulConnectionID)
  475. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  476. long RemoteValidateNotifW (wchar_t *        szComputerName,
  477.                            wchar_t *        szMailboxName,
  478.                            unsigned long    ulNotifMask,
  479.                            unsigned long *  pulConnectionID)
  480. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  481. long RemoteOpenMsgUploadPipeW (wchar_t *        szSenderMailbox,
  482.                                long *           pPipeNumber,
  483.                                unsigned char *  szCookie)
  484. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  485. long RemoteSendMsgToAccountW (wchar_t * szRecipAccount,
  486.                               wchar_t * szHeaderInfo,
  487.                               wchar_t * szCookie)
  488. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  489. long RemoteOpenMsgDownloadPipeW (wchar_t *          szMailbox,
  490.                                  unsigned long *    pPipeNumber)
  491. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  492. long RemoteOpenHeaderDownloadPipeW (wchar_t *   szMailbox,
  493.                                     long *      pPipeNumber)
  494. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  495. long RemoteCheckNewMailW (wchar_t *         szMailbox,
  496.                           unsigned long *   pulPending)
  497. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  498. long RemoteOpenOneMsgDownloadPipeW (wchar_t *   szMailbox,
  499.                                     long *      pPipeNumber)
  500. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  501. long RemoteGetRecipientPropsW (unsigned long    dwObjID,
  502.                                unsigned long *  pdwObjType,
  503.                                wchar_t *        szMailboxName,
  504.                                wchar_t *        szFullName,
  505.                                wchar_t *        szJobTitle,
  506.                                wchar_t *        szOffice,
  507.                                wchar_t *        szPhone,
  508.                                wchar_t *        szAltPhone,
  509.                                wchar_t *        szFax,
  510.                                wchar_t *        szComments,
  511.                                wchar_t *        szCompany,
  512.                                wchar_t *        szDepartment,
  513.                                wchar_t *        szManagerName,
  514.                                wchar_t *        szManagerAlias,
  515.                                unsigned long *  pdwManagerID)
  516. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  517. long RemoteGetDistListPropsW (unsigned long     dwObjID,
  518.                               wchar_t *         szDLAlias,
  519.                               wchar_t *         szDLFullName,
  520.                               unsigned long *   pdwContentCount,
  521.                               wchar_t *         szOwnerAlias,
  522.                               wchar_t *         szOwnerName,
  523.                               wchar_t *         szComments)
  524. { return HRESULT_FROM_WIN32(E_NOTIMPL); }
  525.  
  526. // End of file for RABRPC.CPP
  527.