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.

182 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. disk.c
  5. Abstract:
  6. This module contains support for the NetServerDiskEnum API for the NT
  7. OS/2 server service.
  8. Author:
  9. Johnson Apacible (johnsona) 19-March-1992
  10. Revision History:
  11. --*/
  12. #include "srvsvcp.h"
  13. #include "nturtl.h"
  14. #include "winbase.h"
  15. NET_API_STATUS NET_API_FUNCTION
  16. NetrServerDiskEnum(
  17. IN LPTSTR ServerName,
  18. IN DWORD Level,
  19. IN OUT DISK_ENUM_CONTAINER *DiskInfoStruct,
  20. IN DWORD PrefMaxLen,
  21. OUT LPDWORD TotalEntries,
  22. IN OUT LPDWORD ResumeHandle
  23. )
  24. /*++
  25. Routine Description:
  26. This routine communicates with the server FSD to implement the
  27. server half of the NetServerDiskEnum function.
  28. Arguments:
  29. ServerName - optional name of server.
  30. Level - must be 0
  31. DiskInfoStruct - the output buffer.
  32. PrefMaxLen - the preferred maximum length of the output buffer.
  33. TotalEntries - total number of drive entries in the output buffer.
  34. ResumeHandle - ignored.
  35. Return Value:
  36. NET_API_STATUS - NO_ERROR or reason for failure.
  37. --*/
  38. {
  39. NET_API_STATUS error;
  40. TCHAR diskName[4];
  41. UINT i;
  42. UINT driveType;
  43. UINT totalBytes = 0;
  44. LPTSTR tempBuffer;
  45. LPTSTR currentDiskInfo;
  46. ServerName, PrefMaxLen, ResumeHandle;
  47. //
  48. // The only valid level is 0.
  49. //
  50. if ( Level != 0 ) {
  51. return ERROR_INVALID_LEVEL;
  52. }
  53. if (DiskInfoStruct->Buffer != NULL) {
  54. // The InfoStruct is defined as a parameter. However the Buffer
  55. // parameter is only used as out. In these cases we need to free
  56. // the buffer allocated by RPC if the client had specified a non
  57. // NULL value for it.
  58. MIDL_user_free(DiskInfoStruct->Buffer);
  59. DiskInfoStruct->Buffer = NULL;
  60. }
  61. //
  62. // Make sure that the caller is allowed to get disk information from
  63. // the server.
  64. //
  65. error = SsCheckAccess(
  66. &SsDiskSecurityObject,
  67. SRVSVC_DISK_ENUM
  68. );
  69. if ( error != NO_ERROR ) {
  70. return ERROR_ACCESS_DENIED;
  71. }
  72. //
  73. // Go through all the driver letters, get those that does not return
  74. // an error.
  75. //
  76. tempBuffer = MIDL_user_allocate(
  77. (SRVSVC_MAX_NUMBER_OF_DISKS * (3 * sizeof(TCHAR))) +
  78. sizeof(TCHAR)
  79. );
  80. if ( tempBuffer == NULL ) {
  81. return ERROR_NOT_ENOUGH_MEMORY;
  82. }
  83. currentDiskInfo = tempBuffer;
  84. diskName[0] = 'A';
  85. diskName[1] = ':';
  86. diskName[2] = '\\';
  87. diskName[3] = '\0';
  88. *TotalEntries = 0;
  89. for ( i = 0; i < SRVSVC_MAX_NUMBER_OF_DISKS; i++ ) {
  90. driveType = SsGetDriveType( diskName );
  91. if ( driveType == DRIVE_FIXED ||
  92. driveType == DRIVE_CDROM ||
  93. driveType == DRIVE_REMOVABLE ||
  94. driveType == DRIVE_RAMDISK ) {
  95. //
  96. // This is a valid disk
  97. //
  98. (*TotalEntries)++;
  99. *(currentDiskInfo++) = diskName[0];
  100. *(currentDiskInfo++) = ':';
  101. *(currentDiskInfo++) = '\0';
  102. }
  103. diskName[0]++;
  104. }
  105. #ifdef UNICODE
  106. *currentDiskInfo = UNICODE_NULL;
  107. #else
  108. *currentDiskInfo = '\0';
  109. #endif
  110. //
  111. // EntriesRead must be one greater than TotalEntries so RPC can
  112. // marshal the output strings back to the client correctly.
  113. //
  114. totalBytes = ((*TotalEntries) * (3 * sizeof(TCHAR))) + sizeof(TCHAR);
  115. DiskInfoStruct->EntriesRead = (*TotalEntries) + 1;
  116. DiskInfoStruct->Buffer = MIDL_user_allocate( totalBytes );
  117. if ( DiskInfoStruct->Buffer != NULL ) {
  118. RtlCopyMemory(
  119. DiskInfoStruct->Buffer,
  120. tempBuffer,
  121. totalBytes
  122. );
  123. } else {
  124. MIDL_user_free(tempBuffer);
  125. return ERROR_NOT_ENOUGH_MEMORY;
  126. }
  127. MIDL_user_free( tempBuffer );
  128. return NO_ERROR;
  129. } // NetrServerDiskEnum
  130.