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.

314 lines
8.1 KiB

  1. /*
  2. * LSPARSE.C - NetWare Login Script processing routines for our Win32
  3. * NetWare 3.x LOGIN clone.
  4. *
  5. * Based on code contained in NWPARSE.C, written by Xiao Ying Ding.
  6. *
  7. * Modified and re-written for Win32 by J. SOUZA, February 1994.
  8. *
  9. * Modified for NT by Terry Treder
  10. *
  11. * Copyright (C)1994 Microsoft Corporation.
  12. *
  13. */
  14. #include <common.h>
  15. /********************************************************************
  16. ConverNDSPathToNetWarePathA
  17. Routine Description:
  18. Convert a NDS path to a Netware format path
  19. Arguments:
  20. ndspath - origninal NDS path
  21. objclass - type of NDS object, NULL if unknown
  22. nwpath - Netware format path
  23. Return Value:
  24. error
  25. *******************************************************************/
  26. unsigned int
  27. ConverNDSPathToNetWarePathA(char *ndspath, char *objclass, char *nwpath)
  28. {
  29. CHAR szDN[MAX_PATH];
  30. CHAR szObjName[MAX_PATH];
  31. CHAR cSave;
  32. CHAR className[MAX_PATH];
  33. LPSTR lpDelim = NULL;
  34. LPSTR lpFilePath = "";
  35. LPSTR lpszValue;
  36. LPSTR path;
  37. LPSTR volume;
  38. DWORD dwRet;
  39. DWORD length;
  40. UINT NWStatus;
  41. char bufAttribute[2048];
  42. // optimize for path beginning with drive letter
  43. // This assumes NDS volume and dir map names are at least 2 chars
  44. if (ndspath[1] == ':')
  45. return 1;
  46. // strip ':' from path before this call
  47. if ( ( lpDelim = strchr(ndspath,':') ) != NULL
  48. || ((lpDelim = strchr(ndspath,'\\')) != NULL)) {
  49. cSave = *lpDelim;
  50. *lpDelim = '\0';
  51. lpFilePath = lpDelim+1;
  52. }
  53. if ( objclass == NULL ) {
  54. NWStatus = NDSCanonicalizeName( ndspath, szObjName, MAX_PATH, TRUE );
  55. if ( NWStatus != 0 ) {
  56. #ifdef DEBUG
  57. printf("can't canonicalize [%s] (0x%x)\n",
  58. ndspath, NWStatus );
  59. #endif
  60. if (lpDelim) {
  61. *lpDelim = cSave;
  62. }
  63. return 1;
  64. }
  65. NWStatus = NDSGetClassName( szObjName, className );
  66. if ( NWStatus != 0 ||
  67. strcmp ( className, DSCL_SERVER ) &&
  68. strcmp ( className, DSCL_NCP_SERVER ) &&
  69. strcmp ( className, DSCL_VOLUME ) &&
  70. strcmp ( className, DSCL_QUEUE ) &&
  71. strcmp ( className, DSCL_DIRECTORY_MAP )) {
  72. #ifdef DEBUG
  73. printf("no path DSOBJ: %d (%s) (%s)\n",
  74. NWStatus, szObjName, className );
  75. #endif
  76. if (lpDelim) {
  77. *lpDelim = cSave;
  78. }
  79. return 1;
  80. }
  81. objclass = className;
  82. }
  83. else
  84. strcpy ( szObjName, ndspath );
  85. if (lpDelim) {
  86. *lpDelim = cSave;
  87. }
  88. #ifdef DEBUG
  89. printf("ConvertNDSPath BEFORE [%s]\n", szObjName);
  90. #endif
  91. //
  92. // Is f this is the server class object , we only need
  93. // to extract it's common name and put into netware format
  94. //
  95. if ((strcmp(objclass,DSCL_SERVER) == 0 ) ||
  96. (strcmp(objclass,DSCL_NCP_SERVER) == 0 )) {
  97. // Abbreaviate first to remove type qualifiers
  98. *szDN = '\0';
  99. if (0 != NDSAbbreviateName(FLAGS_LOCAL_CONTEXT,(LPSTR)szObjName,szDN)) {
  100. return 1;
  101. }
  102. lpDelim = strchr(szDN,'.');
  103. if (lpDelim) {
  104. *lpDelim = '\0';
  105. }
  106. strcpy(nwpath,szDN);
  107. #ifdef DEBUG
  108. printf("Returning Netware path:%s\n",nwpath);
  109. #endif
  110. return 0;
  111. } /* endif server class */
  112. //
  113. // If this is share class object ( volume or queue), we need
  114. // to find it's host server name and host resource name
  115. //
  116. if ((strcmp(objclass,DSCL_VOLUME) == 0 ) ||
  117. (strcmp(objclass,DSCL_QUEUE) == 0 )
  118. ) {
  119. //
  120. // Read host server name first. It comes back as distinguished
  121. // directory name, so we will need to extract server name from it
  122. //
  123. NWStatus = NDSGetProperty ( szObjName,
  124. DSAT_HOST_SERVER,
  125. bufAttribute,
  126. sizeof(bufAttribute),
  127. NULL );
  128. if (NWStatus != 0) {
  129. #ifdef DEBUG
  130. printf("Get host server failed. err=0x%x\n",NWStatus);
  131. #endif
  132. return 1;
  133. }
  134. lpszValue = bufAttribute;
  135. ConvertUnicodeToAscii( lpszValue );
  136. //
  137. // Now copy server distinguished name into temporary buffer
  138. // and call ourselves to convert it to Netware
  139. //
  140. strcpy(szDN,lpszValue);
  141. dwRet = ConverNDSPathToNetWarePathA(szDN, DSCL_SERVER, nwpath);
  142. if (dwRet) {
  143. #ifdef DEBUG
  144. printf("Resolving server DN failed\n");
  145. #endif
  146. //Break();
  147. return 1;
  148. }
  149. //
  150. // Get volume name itself
  151. //
  152. NWStatus = NDSGetProperty ( szObjName,
  153. DSAT_HOST_RESOURCE_NAME,
  154. bufAttribute,
  155. sizeof(bufAttribute),
  156. NULL );
  157. if (NWStatus != 0) {
  158. #ifdef DEBUG
  159. printf("Get host resource name failed. err=0x%x\n",NWStatus);
  160. #endif
  161. return 1;
  162. }
  163. lpszValue = bufAttribute;
  164. ConvertUnicodeToAscii( lpszValue );
  165. //
  166. // Now we already have server name in the user buffer,
  167. // append share name to it
  168. strcat(nwpath,"/");
  169. strcat(nwpath,lpszValue);
  170. strcat(nwpath,":");
  171. strcat(nwpath, lpFilePath );
  172. #ifdef DEBUG
  173. printf("Returning Netware path:%s\n",nwpath);
  174. #endif
  175. return 0;
  176. } /* endif Volume class */
  177. //
  178. // For directory maps we need to find host volume NDS name and
  179. // append relative directory path
  180. //
  181. if (strcmp(objclass,DSCL_DIRECTORY_MAP) == 0 ) {
  182. //
  183. // First get NDS name for host volume object
  184. //
  185. NWStatus = NDSGetProperty ( szObjName,
  186. DSAT_PATH,
  187. bufAttribute,
  188. sizeof(bufAttribute),
  189. NULL );
  190. if (NWStatus != 0) {
  191. #ifdef DEBUG
  192. printf("Get path %s failed. err=0x%x\n", szObjName, NWStatus);
  193. #endif
  194. return 1;
  195. }
  196. volume = bufAttribute;
  197. volume += sizeof(DWORD);
  198. volume += sizeof(DWORD);
  199. ConvertUnicodeToAscii( volume );
  200. // Path is next
  201. path = bufAttribute;
  202. path += sizeof(DWORD);
  203. length = ROUNDUP4(*(DWORD *)path);
  204. path += sizeof(DWORD);
  205. path += length;
  206. //
  207. // Check for 0 length paths
  208. //
  209. if ( *(DWORD *)path == 0 ) {
  210. path = "";
  211. }
  212. else {
  213. path += sizeof(DWORD);
  214. ConvertUnicodeToAscii( path );
  215. }
  216. #ifdef DEBUG
  217. printf("path is %s\n",path);
  218. #endif
  219. //
  220. // Now copy volume distinguished name into temporary buffer
  221. // and call ourselves to convert it to NetWare
  222. //
  223. strcpy(szDN,volume);
  224. dwRet = ConverNDSPathToNetWarePathA(szDN, DSCL_VOLUME, nwpath);
  225. if (dwRet) {
  226. #ifdef DEBUG
  227. printf("Resolving volume DN failed\n");
  228. #endif
  229. //Break();
  230. return 1;
  231. }
  232. //
  233. // Now we already have NetWare server\volume name in the user buffer,
  234. // append directory path to it
  235. //strcat(nwpath,"\\");
  236. // we want only one '\'
  237. if (path[0] == '\\' || path[0] == '/') path++;
  238. strcat(nwpath,path);
  239. // append non-NDS part of path, if any
  240. if (*lpFilePath) {
  241. strcat(nwpath,"/");
  242. strcat(nwpath, lpFilePath );
  243. }
  244. #ifdef DEBUG
  245. printf("Returning NetWare path:%s\n",nwpath);
  246. #endif
  247. return 0;
  248. } /* endif DirectoryMap class */
  249. return(1);
  250. }