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.

206 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1993-1994 Microsoft Corporation
  3. Module Name:
  4. network.c
  5. Abstract:
  6. This module contains the set of routines that support updating network
  7. drive shares when adding and deleting drive letters.
  8. Author:
  9. Bob Rinne (bobri) 12/26/94
  10. Environment:
  11. User process.
  12. Notes:
  13. Revision History:
  14. --*/
  15. #include "fdisk.h"
  16. #include "shellapi.h"
  17. #include <winbase.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <malloc.h>
  21. #include <lm.h>
  22. // Data area to hold the permissions that are to be assigned to the
  23. // administrative shares C$, D$, etc. This is obtained during initialization
  24. // and not changed, just used when a new administrator share needes to
  25. // be made.
  26. LPBYTE ShareInformationBuffer;
  27. // Only perform network actions if this value is true. This value
  28. // is set if the initialization of this module completes successfully.
  29. BOOLEAN NetworkEnabled;
  30. VOID
  31. NetworkInitialize(
  32. )
  33. /*++
  34. Routine Description:
  35. Intialize the permissions constants for any new administrator
  36. driver letter shares.
  37. Arguments:
  38. None
  39. Return Value:
  40. None
  41. --*/
  42. {
  43. WCHAR shareName[4];
  44. NET_API_STATUS status;
  45. PSHARE_INFO_502 info;
  46. LPTSTR string;
  47. shareName[1] = (WCHAR) '$';
  48. shareName[2] = (WCHAR) 0;
  49. for (shareName[0] = (WCHAR) 'C'; shareName[0] <= (WCHAR) 'Z'; shareName[0]++) {
  50. // Since windisk is still built as a non-unicode application,
  51. // the parameter "shareName" must be unicode, but the prototype
  52. // specifies that it is a (char *). Do the typecast to remove
  53. // warnings.
  54. status = NetShareGetInfo(NULL,
  55. (char *) shareName,
  56. 502,
  57. &ShareInformationBuffer);
  58. if (status == NERR_Success) {
  59. // Update the remarks and password to be NULL.
  60. info = (PSHARE_INFO_502) ShareInformationBuffer;
  61. string = info->shi502_remark;
  62. if (string) {
  63. *string = (TCHAR) 0;
  64. }
  65. string = info->shi502_passwd;
  66. if (string) {
  67. *string = (TCHAR) 0;
  68. }
  69. // Network shares are to be updated.
  70. NetworkEnabled = TRUE;
  71. return;
  72. }
  73. }
  74. // Can't find any network shares - do not attempt updates
  75. // of administrator shares.
  76. NetworkEnabled = FALSE;
  77. }
  78. VOID
  79. NetworkShare(
  80. IN LPCTSTR DriveLetter
  81. )
  82. /*++
  83. Routine Description:
  84. Given a drive letter, construct the default administrator share
  85. for the letter. This is the C$, D$, etc share for the drive.
  86. Arguments:
  87. DriveLetter - the drive letter to share.
  88. Return Value:
  89. None
  90. --*/
  91. {
  92. NET_API_STATUS status;
  93. PSHARE_INFO_502 info;
  94. LPTSTR string;
  95. if (NetworkEnabled) {
  96. info = (PSHARE_INFO_502) ShareInformationBuffer;
  97. // Set up the new network name.
  98. string = info->shi502_netname;
  99. *string = *DriveLetter;
  100. // Set up the path. All that need be added is the drive letter
  101. // the rest of the path (":\") is already in the structure.
  102. string = info->shi502_path;
  103. *string = *DriveLetter;
  104. status = NetShareAdd(NULL,
  105. 502,
  106. ShareInformationBuffer,
  107. NULL);
  108. }
  109. }
  110. VOID
  111. NetworkRemoveShare(
  112. IN LPCTSTR DriveLetter
  113. )
  114. /*++
  115. Routine Description:
  116. Remove the administrator share for the given letter.
  117. Arguments:
  118. DriveLetter - the drive letter to share.
  119. Return Value:
  120. None
  121. --*/
  122. {
  123. NET_API_STATUS status;
  124. WCHAR shareName[4];
  125. if (NetworkEnabled) {
  126. shareName[0] = (WCHAR) *DriveLetter;
  127. shareName[1] = (WCHAR) '$';
  128. shareName[2] = (WCHAR) 0;
  129. // Since windisk is still built as a non-unicode application,
  130. // the parameter "shareName" must be unicode, but the prototype
  131. // specifies that it is a (char *). Do the typecast to remove
  132. // warnings.
  133. status = NetShareDel(NULL,
  134. (char *) shareName,
  135. 0);
  136. }
  137. }