Source code of Windows XP (NT5)
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.

102 lines
3.6 KiB

  1. // sfm.cpp : Implementation of shares for Apple Macintosh
  2. #include "stdafx.h"
  3. #include <macfile.h>
  4. #define FUNCNAME_AFPADMINCONNECT "AfpAdminConnect"
  5. #define FUNCNAME_AFPADMINDISCONNECT "AfpAdminDisconnect"
  6. #define FUNCNAME_AFPADMINVOLUMEGETINFO "AfpAdminVolumeGetInfo"
  7. #define FUNCNAME_AFPADMINVOLUMEADD "AfpAdminVolumeAdd"
  8. #define FUNCNAME_AFPADMINBUFFERFREE "AfpAdminBufferFree"
  9. typedef DWORD (CALLBACK *PAFPADMINCONNECT)(LPTSTR, PAFP_SERVER_HANDLE);
  10. typedef VOID (CALLBACK *PAFPADMINDISCONNECT)(AFP_SERVER_HANDLE);
  11. typedef DWORD (CALLBACK *PAFPADMINVOLUMEGETINFO)(AFP_SERVER_HANDLE, LPWSTR, LPBYTE*);
  12. typedef DWORD (CALLBACK *PAFPADMINVOLUMEADD)(AFP_SERVER_HANDLE, LPBYTE);
  13. typedef DWORD (CALLBACK *PAFPADMINBUFFERFREE)(LPVOID);
  14. BOOL
  15. SFMShareNameExists(
  16. IN LPCTSTR lpszServerName,
  17. IN LPCTSTR lpszShareName,
  18. IN HINSTANCE hLib
  19. )
  20. {
  21. BOOL bReturn = FALSE;
  22. DWORD dwRet = NERR_Success;
  23. PAFPADMINCONNECT pAfpAdminConnect = NULL;
  24. PAFPADMINVOLUMEGETINFO pAfpAdminVolumeGetInfo = NULL;
  25. PAFPADMINBUFFERFREE pAfpAdminBufferFree = NULL;
  26. PAFPADMINDISCONNECT pAfpAdminDisconnect = NULL;
  27. if ( (pAfpAdminConnect = (PAFPADMINCONNECT)GetProcAddress(hLib, FUNCNAME_AFPADMINCONNECT)) &&
  28. (pAfpAdminVolumeGetInfo = (PAFPADMINVOLUMEGETINFO)GetProcAddress(hLib, FUNCNAME_AFPADMINVOLUMEGETINFO)) &&
  29. (pAfpAdminBufferFree = (PAFPADMINBUFFERFREE)GetProcAddress(hLib, FUNCNAME_AFPADMINBUFFERFREE)) &&
  30. (pAfpAdminDisconnect = (PAFPADMINDISCONNECT)GetProcAddress(hLib, FUNCNAME_AFPADMINDISCONNECT)) )
  31. {
  32. AFP_SERVER_HANDLE hAfpServerHandle = NULL;
  33. dwRet = (*pAfpAdminConnect)(
  34. const_cast<LPTSTR>(lpszServerName),
  35. &hAfpServerHandle);
  36. if (NERR_Success == dwRet)
  37. {
  38. PAFP_VOLUME_INFO pInfo = NULL;
  39. dwRet = (*pAfpAdminVolumeGetInfo)(
  40. hAfpServerHandle,
  41. const_cast<LPTSTR>(lpszShareName),
  42. (LPBYTE*)&pInfo);
  43. if (NERR_Success == dwRet)
  44. {
  45. bReturn = TRUE;
  46. (*pAfpAdminBufferFree)(pInfo);
  47. }
  48. (*pAfpAdminDisconnect)(hAfpServerHandle);
  49. }
  50. }
  51. return bReturn;
  52. }
  53. DWORD
  54. SFMCreateShare(
  55. IN LPCTSTR lpszServer,
  56. IN LPCTSTR lpszShareName,
  57. IN LPCTSTR lpszSharePath,
  58. IN HINSTANCE hLib
  59. )
  60. {
  61. DWORD dwRet = NERR_Success;
  62. PAFPADMINCONNECT pAfpAdminConnect = NULL;
  63. PAFPADMINDISCONNECT pAfpAdminDisconnect = NULL;
  64. PAFPADMINVOLUMEADD pAfpAdminVolumeAdd = NULL;
  65. if (!(pAfpAdminConnect = (PAFPADMINCONNECT)GetProcAddress(hLib, FUNCNAME_AFPADMINCONNECT)) ||
  66. !(pAfpAdminDisconnect = (PAFPADMINDISCONNECT)GetProcAddress(hLib, FUNCNAME_AFPADMINDISCONNECT)) ||
  67. !(pAfpAdminVolumeAdd = (PAFPADMINVOLUMEADD)GetProcAddress(hLib, FUNCNAME_AFPADMINVOLUMEADD)))
  68. {
  69. dwRet = GetLastError();
  70. } else
  71. {
  72. AFP_SERVER_HANDLE hAfpServerHandle = NULL;
  73. dwRet = (*pAfpAdminConnect)(
  74. const_cast<LPTSTR>(lpszServer),
  75. &hAfpServerHandle);
  76. if (NERR_Success == dwRet)
  77. {
  78. AFP_VOLUME_INFO AfpVolumeInfo;
  79. ZeroMemory(&AfpVolumeInfo, sizeof(AfpVolumeInfo));
  80. AfpVolumeInfo.afpvol_name = const_cast<LPTSTR>(lpszShareName);
  81. AfpVolumeInfo.afpvol_max_uses = AFP_VOLUME_UNLIMITED_USES;
  82. AfpVolumeInfo.afpvol_props_mask = AFP_VOLUME_GUESTACCESS;
  83. AfpVolumeInfo.afpvol_path = const_cast<LPTSTR>(lpszSharePath);
  84. dwRet = (*pAfpAdminVolumeAdd)(hAfpServerHandle, (LPBYTE)&AfpVolumeInfo);
  85. (*pAfpAdminDisconnect)(hAfpServerHandle);
  86. }
  87. }
  88. return dwRet;
  89. }