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.

142 lines
3.3 KiB

  1. /*************************************************************************
  2. *
  3. * UNC.C
  4. *
  5. * NetWare format to UNC format
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\UNC.C $
  10. *
  11. * Rev 1.4 10 Apr 1996 14:24:00 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.4 12 Mar 1996 19:56:18 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.3 04 Jan 1996 18:57:26 terryt
  18. * Bug fixes reported by MS
  19. *
  20. * Rev 1.2 22 Dec 1995 14:27:04 terryt
  21. * Add Microsoft headers
  22. *
  23. * Rev 1.1 22 Dec 1995 11:09:18 terryt
  24. * Fixes
  25. *
  26. * Rev 1.0 15 Nov 1995 18:08:14 terryt
  27. * Initial revision.
  28. *
  29. * Rev 1.1 23 May 1995 19:37:24 terryt
  30. * Spruce up source
  31. *
  32. * Rev 1.0 15 May 1995 19:11:10 terryt
  33. * Initial revision.
  34. *
  35. *************************************************************************/
  36. #include <stdio.h>
  37. #include <direct.h>
  38. #include <time.h>
  39. #include <stdlib.h>
  40. #include <nt.h>
  41. #include <ntrtl.h>
  42. #include <nturtl.h>
  43. #include <windows.h>
  44. #include "inc/common.h"
  45. /********************************************************************
  46. NTNWtoUNCFormat
  47. Routine Description:
  48. Given a connection handle and a path, change it to UNC format
  49. if it's in NetWare format. I.E.
  50. SYS:\usr\terryt ==> \\HELIUM\SYS\usr\terryt
  51. Don't do the conversion if it's not in NetWare format.
  52. Arguments:
  53. ConnectionHandle - Connection Handle
  54. NetWarePath - Input original path
  55. Return Value:
  56. UNC string
  57. *******************************************************************/
  58. char *
  59. NTNWtoUNCFormat( char * NetWarePath )
  60. {
  61. static char UNCPath[1024];
  62. unsigned int Result;
  63. char ServerName[48];
  64. char * p;
  65. char * q;
  66. /*
  67. * If it's UNC already, leave it alone
  68. */
  69. if ( ( NetWarePath[0] == '\\' ) && ( NetWarePath[1] == '\\' ) )
  70. return NetWarePath;
  71. if ( ( NetWarePath[0] == '/' ) && ( NetWarePath[1] == '/' ) )
  72. return NetWarePath;
  73. /*
  74. * if it's drive:dir, leave it alone
  75. */
  76. if ( NetWarePath[0] && ( NetWarePath[1] == ':' ) )
  77. return NetWarePath;
  78. /*
  79. * if it's not volume:dir, leave it alone
  80. */
  81. p = strchr( NetWarePath, ':' );
  82. if ( !p )
  83. return NetWarePath;
  84. /*
  85. * if slashes before :, it must be a file server
  86. */
  87. q = strchr( NetWarePath, '\\' );
  88. if ( q && ( q < p ) )
  89. {
  90. strcpy( UNCPath, "\\\\" );
  91. *p = '\0';
  92. strcat( UNCPath, NetWarePath );
  93. if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
  94. strcat( UNCPath, "\\" );
  95. strcat( UNCPath, p + 1 );
  96. *p = ':';
  97. return UNCPath;
  98. }
  99. q = strchr( NetWarePath, '/' );
  100. if ( q && ( q < p ) )
  101. {
  102. strcpy( UNCPath, "\\\\" );
  103. *q = '\\';
  104. *p = '\0';
  105. strcat( UNCPath, NetWarePath );
  106. if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
  107. strcat( UNCPath, "\\" );
  108. strcat( UNCPath, p + 1 );
  109. *q = '/';
  110. *p = ':';
  111. return UNCPath;
  112. }
  113. strcpy( UNCPath, "\\\\" );
  114. strcat( UNCPath, PREFERRED_SERVER );
  115. strcat( UNCPath, "\\" );
  116. *p = '\0';
  117. strcat( UNCPath, NetWarePath );
  118. if (( *(p + 1) != '\\' ) && ( *(p + 1) != '/' ) )
  119. strcat( UNCPath, "\\" );
  120. strcat( UNCPath, p + 1 );
  121. *p = ':';
  122. return UNCPath;
  123. }