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.

145 lines
3.5 KiB

  1. /* Copyright (c) 1996, Microsoft Corporation, all rights reserved
  2. **
  3. ** rnk.c
  4. ** Remote Access shortcut file (.RNK) library
  5. **
  6. ** 02/15/96 Steve Cobb
  7. */
  8. #include <windows.h> // Win32 core
  9. #include <debug.h> // TRACE/ASSERT macros
  10. #include <nouiutil.h> // Heap macros
  11. #include <rnk.h> // Our public header
  12. VOID
  13. FreeRnkInfo(
  14. IN RNKINFO* pInfo )
  15. /* Destroys 'pInfo' buffer returned from ReadShortcutFile.
  16. */
  17. {
  18. if (pInfo)
  19. {
  20. Free0( pInfo->pszEntry );
  21. Free0( pInfo->pszPhonebook );
  22. Free( pInfo );
  23. }
  24. }
  25. RNKINFO*
  26. ReadShortcutFile(
  27. IN TCHAR* pszRnkPath )
  28. /* Reads shortcut file at 'pszRnkPath' returning a RNKINFO buffer. Caller
  29. ** should eventually call FreeRnkInfo on the returned buffer.
  30. **
  31. ** Returns 0 or an error code.
  32. */
  33. {
  34. RNKINFO* pInfo;
  35. TCHAR szBuf[ 1024 ];
  36. TRACE("ReadShortcutFile");
  37. pInfo = (RNKINFO* )Malloc( sizeof(RNKINFO) );
  38. if (!pInfo)
  39. return NULL;
  40. ZeroMemory( pInfo, sizeof(*pInfo) );
  41. GetPrivateProfileString( TEXT(RNK_SEC_Main), TEXT(RNK_KEY_Entry),
  42. TEXT(""), szBuf, sizeof(szBuf) / sizeof(TCHAR), pszRnkPath );
  43. pInfo->pszEntry = StrDup( szBuf );
  44. GetPrivateProfileString( TEXT(RNK_SEC_Main), TEXT(RNK_KEY_Phonebook),
  45. TEXT(""), szBuf, sizeof(szBuf) / sizeof(TCHAR), pszRnkPath );
  46. pInfo->pszPhonebook = StrDup( szBuf );
  47. return pInfo;
  48. }
  49. DWORD
  50. WriteShortcutFile(
  51. IN TCHAR* pszRnkPath,
  52. IN TCHAR* pszPbkPath,
  53. IN TCHAR* pszEntry )
  54. /* Write the shortcut file 'pszRnkPath' with a command line to dial entry
  55. ** 'pszEntry' from phonebook 'pszPath'.
  56. **
  57. ** Returns 0 if succesful or an error code.
  58. */
  59. {
  60. DWORD dwErr;
  61. HANDLE hFile;
  62. CHAR* pszRnkPathA;
  63. CHAR* pszEntryA;
  64. CHAR* pszPbkPathA;
  65. TRACE("WriteShortcutFile");
  66. /* The file is written in ANSI to
  67. ** avoid potential portability/compatibility problems with Windows 95.
  68. */
  69. dwErr = 0;
  70. pszRnkPathA = StrDupAFromT( pszRnkPath );
  71. if (!pszRnkPathA)
  72. {
  73. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  74. }
  75. else
  76. {
  77. hFile = CreateFileA( pszRnkPathA, GENERIC_WRITE, 0, NULL,
  78. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  79. if (hFile == INVALID_HANDLE_VALUE)
  80. {
  81. dwErr = GetLastError();
  82. }
  83. else
  84. {
  85. CloseHandle( hFile );
  86. pszEntryA = StrDupAFromT( pszEntry );
  87. pszPbkPathA = StrDupAFromT( pszPbkPath );
  88. if (!pszEntryA || !pszPbkPathA)
  89. {
  90. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  91. }
  92. else
  93. {
  94. BOOL f;
  95. CHAR szBuf[ (2 * MAX_PATH) + 100 ];
  96. CHAR* pszKey;
  97. ZeroMemory( szBuf, sizeof(szBuf) );
  98. pszKey = szBuf;
  99. wsprintfA( pszKey, "%s=%s",
  100. RNK_KEY_Entry, pszEntryA );
  101. pszKey += lstrlenA( pszKey ) + 1;
  102. wsprintfA( pszKey, "%s=%s",
  103. RNK_KEY_Phonebook, pszPbkPathA );
  104. f = WritePrivateProfileSectionA(
  105. RNK_SEC_Main, szBuf, pszRnkPathA );
  106. if (!f)
  107. dwErr = GetLastError();
  108. }
  109. Free0( pszPbkPathA );
  110. Free0( pszEntryA );
  111. }
  112. Free( pszRnkPathA );
  113. }
  114. return dwErr;
  115. }