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.

149 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. netperm.c
  5. Abstract:
  6. This is the main source file for the NETPERM tool, which insures that you
  7. have persistent connections to a set of servers.
  8. Author:
  9. Steve Wood (stevewo) 23-Jan-1996
  10. Revision History:
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. __cdecl
  17. main (
  18. int argc,
  19. char *argv[]
  20. )
  21. {
  22. DWORD Status;
  23. DWORD i, j;
  24. char *Local;
  25. char *Remote;
  26. HANDLE enumHandle;
  27. DWORD numEntries;
  28. BOOL endOfList;
  29. NETRESOURCE netResource[8192/sizeof(NETRESOURCE)];
  30. DWORD bufferSize = sizeof(netResource);
  31. DWORD NumberOfRemoteNamesToCheck;
  32. char *RemoteNamesToCheck[ 16 ];
  33. BOOLEAN RemoteNamesFound[ 16 ];
  34. NumberOfRemoteNamesToCheck = 0;
  35. while (--argc) {
  36. RemoteNamesFound[ NumberOfRemoteNamesToCheck ] = FALSE;
  37. RemoteNamesToCheck[ NumberOfRemoteNamesToCheck ] = *++argv;
  38. NumberOfRemoteNamesToCheck += 1;
  39. }
  40. if (NumberOfRemoteNamesToCheck == 0) {
  41. fprintf( stderr, "List of persistent drive letters currently defined:\n" );
  42. }
  43. Status = WNetOpenEnum(
  44. RESOURCE_REMEMBERED,
  45. RESOURCETYPE_DISK,
  46. RESOURCEUSAGE_CONNECTABLE,
  47. NULL,
  48. &enumHandle );
  49. if (Status != NO_ERROR) {
  50. fprintf( stderr, "Cannot enumerate network connections (%d)\n", Status );
  51. exit( 1 );
  52. }
  53. endOfList = FALSE;
  54. do {
  55. numEntries = 0xFFFFFFFF;
  56. Status = WNetEnumResource( enumHandle, &numEntries, netResource, &bufferSize );
  57. switch( Status ) {
  58. case NO_ERROR:
  59. break;
  60. case ERROR_NO_NETWORK:
  61. //
  62. // If the network has not started we'll continue
  63. // (so users can work in local projects).
  64. //
  65. case ERROR_NO_MORE_ITEMS:
  66. endOfList = TRUE;
  67. numEntries = 0;
  68. break;
  69. case ERROR_EXTENDED_ERROR: {
  70. CHAR ErrorString [256];
  71. CHAR Network[256];
  72. DWORD dwError;
  73. WNetGetLastError(&dwError, ErrorString, 256, Network, 256);
  74. fprintf( stderr,
  75. "Cannot enumerate network connections (%d)\n"
  76. "Net: %s\n"
  77. "Error: (%d) %s\n",
  78. Status,
  79. Network,
  80. dwError,
  81. ErrorString
  82. );
  83. }
  84. break;
  85. default:
  86. fprintf( stderr, "Cannot enumerate network connections (%d)\n", Status );
  87. exit( 1 );
  88. }
  89. for (i = 0; i<numEntries; i++) {
  90. if (netResource[i].lpLocalName != NULL) {
  91. if (NumberOfRemoteNamesToCheck == 0) {
  92. fprintf( stderr,
  93. "%s => %s\n",
  94. netResource[i].lpLocalName,
  95. netResource[i].lpRemoteName
  96. );
  97. }
  98. else {
  99. for (j=0; j<NumberOfRemoteNamesToCheck; j++) {
  100. if (!RemoteNamesFound[ j ] &&
  101. !_stricmp( netResource[i].lpRemoteName, RemoteNamesToCheck[ j ] )
  102. ) {
  103. RemoteNamesFound[ j ] = TRUE;
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. while (!endOfList);
  112. WNetCloseEnum( enumHandle );
  113. Status = 0;
  114. for (j=0; j<NumberOfRemoteNamesToCheck; j++) {
  115. if (!RemoteNamesFound[ j ]) {
  116. fprintf( stderr, "No persistent drive letter found for %s\n", RemoteNamesToCheck[ j ] );
  117. Status = 1;
  118. }
  119. }
  120. exit( Status );
  121. return 0;
  122. }