Leaked source code of windows server 2003
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.

133 lines
4.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: getpbk.cpp
  4. //
  5. // Module: Common Code
  6. //
  7. // Synopsis: Implements the function GetPhoneBookPath.
  8. //
  9. // Copyright (c) 1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Heaser 08/19/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. //+----------------------------------------------------------------------------
  15. //
  16. // Function: GetPhoneBookPath
  17. //
  18. // Synopsis: This function will return the proper path to the phonebook. If
  19. // used on a legacy platform this is NULL. On NT5, the function
  20. // depends on the proper Install Directory being inputted so that
  21. // the function can use this as a base to determine the phonebook path.
  22. // If the inputted pointer to a string buffer is filled with a path,
  23. // then the directory path will be created as will the pbk file itself.
  24. // The caller should always call CmFree on the pointer passed into this
  25. // API when done with the path, because it will either free the memory
  26. // or do nothing (NULL case).
  27. //
  28. // Arguments: LPCTSTR pszInstallDir - path to the CM profile dir
  29. // LPTSTR* ppszPhoneBook - pointer to accept a newly allocated and filled pbk string
  30. // BOOL fAllUser - TRUE if this an All-User profile
  31. //
  32. // Returns: BOOL - returns TRUE if successful
  33. //
  34. // History: quintinb Created 11/12/98
  35. // tomkel 06/28/2001 Changed the ACLs when the phonebook gets
  36. // createdfor an All-User profile
  37. //
  38. //+----------------------------------------------------------------------------
  39. BOOL GetPhoneBookPath(LPCTSTR pszInstallDir, LPTSTR* ppszPhonebook, BOOL fAllUser)
  40. {
  41. if (NULL == ppszPhonebook)
  42. {
  43. CMASSERTMSG(FALSE, TEXT("GetPhoneBookPath -- Invalid Parameter"));
  44. return FALSE;
  45. }
  46. CPlatform plat;
  47. if (plat.IsAtLeastNT5())
  48. {
  49. if ((NULL == pszInstallDir) || (TEXT('\0') == pszInstallDir[0]))
  50. {
  51. CMASSERTMSG(FALSE, TEXT("GetPhoneBookPath -- Invalid Install Dir parameter."));
  52. return FALSE;
  53. }
  54. //
  55. // Now Create the path to the phonebook.
  56. //
  57. LPTSTR pszPhonebook;
  58. TCHAR szInstallDir[MAX_PATH+1];
  59. ZeroMemory(szInstallDir, CELEMS(szInstallDir));
  60. if (TEXT('\\') == pszInstallDir[lstrlen(pszInstallDir) - 1])
  61. {
  62. //
  63. // Then the path ends in a backslash. Thus we won't properly
  64. // remove CM from the path. Remove the backslash.
  65. //
  66. lstrcpyn(szInstallDir, pszInstallDir, lstrlen(pszInstallDir));
  67. }
  68. else
  69. {
  70. lstrcpy(szInstallDir, pszInstallDir);
  71. }
  72. CFileNameParts InstallDirPath(szInstallDir);
  73. pszPhonebook = (LPTSTR)CmMalloc(lstrlen(InstallDirPath.m_Drive) +
  74. lstrlen(InstallDirPath.m_Dir) +
  75. lstrlen(c_pszPbk) + lstrlen(c_pszRasPhonePbk) + 1);
  76. if (NULL != pszPhonebook)
  77. {
  78. wsprintf(pszPhonebook, TEXT("%s%s%s"), InstallDirPath.m_Drive,
  79. InstallDirPath.m_Dir, c_pszPbk);
  80. //
  81. // Use CreateLayerDirectory to recursively create the directory structure as
  82. // necessary (will create all the directories in a full path if necessary).
  83. //
  84. MYVERIFY(FALSE != CreateLayerDirectory(pszPhonebook));
  85. MYVERIFY(NULL != lstrcat(pszPhonebook, c_pszRasPhonePbk));
  86. HANDLE hPbk = INVALID_HANDLE_VALUE;
  87. hPbk = CreateFile(pszPhonebook, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, NULL, CREATE_NEW,
  88. FILE_ATTRIBUTE_NORMAL, NULL);
  89. if (hPbk != INVALID_HANDLE_VALUE)
  90. {
  91. MYVERIFY(0 != CloseHandle(hPbk));
  92. //
  93. // Give everyone read and write permissions to the phonebook
  94. //
  95. if (fAllUser)
  96. {
  97. AllowAccessToWorld(pszPhonebook);
  98. }
  99. }
  100. *ppszPhonebook = pszPhonebook;
  101. }
  102. else
  103. {
  104. CMASSERTMSG(FALSE, TEXT("CmMalloc returned NULL"));
  105. return FALSE;
  106. }
  107. }
  108. else
  109. {
  110. *ppszPhonebook = NULL;
  111. }
  112. return TRUE;
  113. }