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.

341 lines
8.9 KiB

  1. /*************************************************************************
  2. *
  3. * PARSPATH.C
  4. *
  5. * NetWare parsing routines, ported from DOS
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\PARSPATH.C $
  10. *
  11. * Rev 1.3 22 Jan 1996 16:48:38 terryt
  12. * Add automatic attach query during map
  13. *
  14. * Rev 1.2 22 Dec 1995 14:26:16 terryt
  15. * Add Microsoft headers
  16. *
  17. * Rev 1.1 22 Dec 1995 11:08:50 terryt
  18. * Fixes
  19. *
  20. * Rev 1.0 15 Nov 1995 18:07:48 terryt
  21. * Initial revision.
  22. *
  23. * Rev 1.1 25 Aug 1995 16:23:34 terryt
  24. * Capture support
  25. *
  26. * Rev 1.0 15 May 1995 19:11:00 terryt
  27. * Initial revision.
  28. *
  29. *************************************************************************/
  30. /*++
  31. Copyright (c) 1994 Micro Computer Systems, Inc.
  32. Module Name:
  33. nwlibs\parspath.c
  34. Abstract:
  35. Directory APIs.
  36. Author:
  37. Shawn Walker (v-swalk) 10-10-1994
  38. Revision History:
  39. --*/
  40. #include "common.h"
  41. #include <ctype.h>
  42. #include <direct.h>
  43. #include "inc\nwlibs.h"
  44. /*++
  45. *******************************************************************
  46. ParsePath
  47. Routine Description:
  48. Parse the path string.
  49. Arguments:
  50. pPath = The pointer to the path to parse.
  51. pServerName = The pointer to return the server name.
  52. pVolumeName = The pointer to return the volume name.
  53. pDirPath = The pointer to return the directory path.
  54. Return Value:
  55. 0x0000 SUCCESSFUL
  56. 0x000F INVALID_DRIVE
  57. 0x8800 Unknown error
  58. *******************************************************************
  59. --*/
  60. unsigned int
  61. ParsePath(
  62. unsigned char *pPath,
  63. unsigned char *pServerName, //OPTIONAL
  64. unsigned char *pVolumeName, //OPTIONAL
  65. unsigned char *pDirPath //OPTIONAL
  66. )
  67. {
  68. unsigned char *p, *p2;
  69. unsigned int Result;
  70. unsigned int Remote;
  71. unsigned int NcpError = 0;
  72. unsigned char DriveNumber = (unsigned char)-1;
  73. unsigned char CurrentPath[64];
  74. unsigned char RootPath[NCP_MAX_PATH_LENGTH];
  75. unsigned char ServerName[NCP_MAX_PATH_LENGTH];
  76. unsigned char *pRootDir;
  77. unsigned char NetWarePath[NCP_MAX_PATH_LENGTH];
  78. unsigned char VolumeName[NCP_VOLUME_LENGTH];
  79. unsigned int LocalDriveForce = FALSE;
  80. RootPath[0] = 0;
  81. VolumeName[0] = 0;
  82. ServerName[0] = 0;
  83. if ( pServerName )
  84. *pServerName = '\0';
  85. /** See if there is a volume on the path **/
  86. p = pPath;
  87. while (*p != ':' && *p) {
  88. p++;
  89. }
  90. if (*p == ':') {
  91. *p = 0;
  92. /**
  93. Check to see if this is a drive letter. The volume must
  94. be 2 characters or more.
  95. **/
  96. if ((p - pPath) == 1) {
  97. /** Make sure it is a valid alpha char **/
  98. if (!isalpha((int) *pPath)) {
  99. return 0x000F;
  100. }
  101. *pPath = (unsigned char) toupper((int) *pPath);
  102. /** Make it a drive number **/
  103. DriveNumber = (unsigned char) (*pPath - 'A');
  104. GetDriveStatus ((unsigned short)(DriveNumber+1),
  105. NETWARE_FORMAT_SERVER_VOLUME,
  106. NULL,
  107. NULL,
  108. RootPath,
  109. NULL,
  110. NULL);
  111. pRootDir = strchr (RootPath, ':');
  112. if (pRootDir)
  113. {
  114. /*
  115. * Setup the pServerName here
  116. */
  117. pRootDir[0] = '\0';
  118. p2 = RootPath;
  119. while (*p2)
  120. {
  121. if (*p2 == '\\' || *p2 == '/')
  122. {
  123. *p2++ = 0;
  124. strcpy(ServerName, RootPath);
  125. if (pServerName) {
  126. strcpy(pServerName, RootPath);
  127. }
  128. break;
  129. }
  130. p2++;
  131. }
  132. strcpy (RootPath, pRootDir+1);
  133. }
  134. else
  135. RootPath[0] = 0;
  136. }
  137. else {
  138. DriveNumber = 0;
  139. LocalDriveForce = TRUE;
  140. /**
  141. If there is a server name, save the server name
  142. and set the error code to 0x880F but still parse
  143. the path. This just means that there is no connection
  144. for this server. Even if we do have one.
  145. **/
  146. p2 = pPath;
  147. while (*p2) {
  148. if (*p2 == '\\' || *p2 == '/') {
  149. *p2++ = 0;
  150. strcpy(ServerName, pPath);
  151. if (pServerName) {
  152. strcpy(pServerName, pPath);
  153. }
  154. pPath = p2;
  155. NcpError = 0x880F;
  156. break;
  157. }
  158. p2++;
  159. }
  160. if (NcpError == 0x880F) {
  161. /**
  162. Do any attach processing.
  163. **/
  164. NcpError = DoAttachProcessing( ServerName );
  165. }
  166. strcpy(VolumeName, pPath);
  167. }
  168. /** Get the directory **/
  169. p++;
  170. pPath = p;
  171. }
  172. /**
  173. If we did not get the drive letter of volume name
  174. from above, then get the current drive we are on.
  175. **/
  176. if (DriveNumber == (unsigned char) -1) {
  177. DriveNumber = (UCHAR) _getdrive();
  178. }
  179. /*
  180. * Use the PREFERRED_SERVER for 3X logins if no server name
  181. * was specified.
  182. */
  183. if (pServerName && !fNDS && !pServerName[0] ) {
  184. strcpy( pServerName, PREFERRED_SERVER );
  185. }
  186. if (pVolumeName) {
  187. /**
  188. Check if the drive is remote, if so, then go get the path
  189. from the server.
  190. **/
  191. if ( LocalDriveForce ) {
  192. Result = 0;
  193. Remote = 0;
  194. }
  195. else {
  196. Result = IsDriveRemote(DriveNumber, &Remote);
  197. }
  198. if (NcpError != 0x880F && !VolumeName[0] && (Result || !Remote)) {
  199. pVolumeName[0] = (unsigned char) (DriveNumber + 'A');
  200. pVolumeName[1] = 0;
  201. }
  202. else {
  203. if (VolumeName[0]) {
  204. strcpy(pVolumeName, VolumeName);
  205. }
  206. else {
  207. Result = NTGetNWDrivePath( DriveNumber, NULL, NetWarePath );
  208. if (Result) {
  209. return Result;
  210. }
  211. p = NetWarePath;
  212. while (*p != ':' && *p) {
  213. p++;
  214. }
  215. if (*p == ':') {
  216. *p = 0;
  217. }
  218. strcpy(pVolumeName, NetWarePath);
  219. }
  220. }
  221. }
  222. if (pDirPath) {
  223. memset(CurrentPath, 0, sizeof(CurrentPath));
  224. if (VolumeName[0]) {
  225. strcpy(pDirPath, pPath);
  226. }
  227. else {
  228. Result = NTGetCurrentDirectory(DriveNumber, CurrentPath);
  229. if (Result) {
  230. CurrentPath[0] = 0;
  231. }
  232. else {
  233. /*
  234. * Skip the drive letter
  235. */
  236. if ( CurrentPath[0] ) {
  237. int i;
  238. for ( i = 0; ;i++ ) {
  239. CurrentPath[i] = CurrentPath[i+3];
  240. if ( !CurrentPath[i] )
  241. break;
  242. }
  243. }
  244. }
  245. if (CurrentPath[0] == 0) {
  246. if ( (*pPath == '\\') || ( *pPath == '/' ) ) {
  247. sprintf(pDirPath, "%s%s", RootPath, pPath);
  248. }
  249. else if ( !(*pPath) ) {
  250. sprintf(pDirPath, "%s", RootPath);
  251. }
  252. else {
  253. sprintf(pDirPath, "%s\\%s", RootPath, pPath);
  254. }
  255. }
  256. else {
  257. if (*pPath) {
  258. if ( (*pPath == '\\') || ( *pPath == '/' ) ) {
  259. strcpy (pDirPath, RootPath);
  260. if (pPath[1]) {
  261. strcat(pDirPath, pPath);
  262. }
  263. }
  264. else {
  265. sprintf(pDirPath, "%s\\%s\\%s", RootPath, CurrentPath, pPath);
  266. }
  267. }
  268. else {
  269. sprintf(pDirPath, "%s\\%s", RootPath, CurrentPath);
  270. }
  271. }
  272. }
  273. /** Convert the / in the path to \ **/
  274. for (p = pDirPath; ( p && ( *p != 0 ) ) ; p++)
  275. {
  276. if (*p == '/')
  277. *p = '\\';
  278. }
  279. }
  280. return NcpError;
  281. }