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.

298 lines
6.7 KiB

  1. /* demdir.c - SVC handlers for directory calls
  2. *
  3. * DemCreateDir
  4. * DemDeleteDir
  5. * DemQueryCurrentDir
  6. * DemSetCurrentDir
  7. *
  8. * Modification History:
  9. *
  10. * Sudeepb 04-Apr-1991 Created
  11. */
  12. #include "dem.h"
  13. #include "demmsg.h"
  14. #include <softpc.h>
  15. /* demCreateDir - Create a directory
  16. *
  17. *
  18. * Entry - Client (DS:DX) directory name to create
  19. * Client (BX:SI) EAs (NULL if no EAs)
  20. *
  21. * Exit
  22. * SUCCESS
  23. * Client (CY) = 0
  24. *
  25. * FAILURE
  26. * Client (CY) = 1
  27. * Client (AX) = system status code
  28. *
  29. *
  30. * Notes : Extended Attributes is not yet taken care of.
  31. */
  32. VOID demCreateDir (VOID)
  33. {
  34. LPSTR lpDir;
  35. #ifdef DBCS /* demCreateDir() for CSNW */
  36. CHAR achPath[MAX_PATH];
  37. #endif /* DBCS */
  38. // EAs not yet implemented
  39. if (getBX() || getSI()){
  40. demPrintMsg (MSG_EAS);
  41. return;
  42. }
  43. lpDir = (LPSTR) GetVDMAddr (getDS(),getDX());
  44. #ifdef DBCS /* demCreateDir() for CSNW */
  45. /*
  46. * convert Netware path to Dos path
  47. */
  48. ConvNwPathToDosPath(achPath,lpDir, sizeof(achPath));
  49. lpDir = achPath;
  50. #endif /* DBCS */
  51. if(CreateDirectoryOem (lpDir,NULL) == FALSE){
  52. demClientError(INVALID_HANDLE_VALUE, *lpDir);
  53. return;
  54. }
  55. setCF(0);
  56. return;
  57. }
  58. /* demDeleteDir - Create a directory
  59. *
  60. *
  61. * Entry - Client (DS:DX) directory name to create
  62. *
  63. * Exit
  64. * SUCCESS
  65. * Client (CY) = 0
  66. *
  67. * FAILURE
  68. * Client (CY) = 1
  69. * Client (AX) = system status code
  70. *
  71. */
  72. VOID demDeleteDir (VOID)
  73. {
  74. LPSTR lpDir;
  75. lpDir = (LPSTR) GetVDMAddr (getDS(),getDX());
  76. if (RemoveDirectoryOem(lpDir) == FALSE){
  77. demClientError(INVALID_HANDLE_VALUE, *lpDir);
  78. return;
  79. }
  80. setCF(0);
  81. return;
  82. }
  83. /* demQueryCurrentDir - Verifies current dir provided in CDS structure
  84. * for $CURRENT_DIR
  85. *
  86. * First Validates Media, if invalid -> i24 error
  87. * Next Validates Path, if invalid set path to root (not an error)
  88. *
  89. * Entry - Client (DS:SI) Buffer to CDS path to verify
  90. * Client (AL) Physical Drive in question (A=0, B=1, ...)
  91. *
  92. * Exit
  93. * SUCCESS
  94. * Client (CY) = 0
  95. *
  96. * FAILURE
  97. * Client (CY) = 1 , I24 drive invalid
  98. */
  99. VOID demQueryCurrentDir (VOID)
  100. {
  101. PCDS pcds;
  102. DWORD dw;
  103. CHAR chDrive;
  104. CHAR pPath[]="?:\\";
  105. CHAR EnvVar[] = "=?:";
  106. pcds = (PCDS)GetVDMAddr(getDS(),getSI());
  107. // validate media
  108. chDrive = getAL() + 'A';
  109. pPath[0] = chDrive;
  110. dw = GetFileAttributesOemSys(pPath, TRUE);
  111. if (dw == 0xFFFFFFFF || !(dw & FILE_ATTRIBUTE_DIRECTORY))
  112. {
  113. demClientError(INVALID_HANDLE_VALUE, chDrive);
  114. return;
  115. }
  116. // if invalid path, set path to the root
  117. // reset CDS, and win32 env for win32
  118. dw = GetFileAttributesOemSys(pcds->CurDir_Text, TRUE);
  119. if (dw == 0xFFFFFFFF || !(dw & FILE_ATTRIBUTE_DIRECTORY))
  120. {
  121. strcpy(pcds->CurDir_Text, pPath);
  122. pcds->CurDir_End = 2;
  123. EnvVar[1] = chDrive;
  124. SetEnvironmentVariableOem(EnvVar,pPath);
  125. }
  126. setCF(0);
  127. return;
  128. }
  129. /* demSetCurrentDir - Set the current directory
  130. *
  131. *
  132. * Entry - Client (DS:DX) directory name
  133. * Client (ES:DI) CDS structure
  134. * Dos default drive (AL) , CurDrv, where 1 == A.
  135. *
  136. * Exit
  137. * SUCCESS
  138. * Client (CY) = 0
  139. *
  140. * FAILURE
  141. * Client (CY) = 1
  142. * Client (AX) = system status code
  143. *
  144. */
  145. VOID demSetCurrentDir (VOID)
  146. {
  147. DWORD dw;
  148. LPSTR lpBuf;
  149. CHAR EnvVar[] = "=?:";
  150. CHAR ch;
  151. PCDS pCDS;
  152. BOOL bLongDirName;
  153. lpBuf = (LPSTR) GetVDMAddr (getDS(),getDX());
  154. ch = (CHAR) toupper(*(PCHAR)lpBuf);
  155. if (ch < 'A' || ch > 'Z'){
  156. setCF(1);
  157. return;
  158. }
  159. // got the darn cds ptr
  160. pCDS = (PCDS)GetVDMAddr(getES(), getDI());
  161. // now see if the directory name is too long
  162. bLongDirName = (strlen(lpBuf) > DIRSTRLEN);
  163. //
  164. // if the current dir is for the default drive
  165. // set the win32 process's current drive,dir. This
  166. // will open an NT dir handle, and verify that it
  167. // exists.
  168. //
  169. if (ch == getAL() + 'A') {
  170. if (SetCurrentDirectoryOem (lpBuf) == FALSE){
  171. demClientError(INVALID_HANDLE_VALUE, ch);
  172. return;
  173. }
  174. }
  175. //
  176. // if its not for the default drive, we still need
  177. // to verify that the dir\drive combinations exits.
  178. //
  179. else {
  180. dw = GetFileAttributesOemSys(lpBuf, TRUE);
  181. if (dw == 0xFFFFFFFF || !(dw & FILE_ATTRIBUTE_DIRECTORY))
  182. {
  183. demClientError(INVALID_HANDLE_VALUE, ch);
  184. return;
  185. }
  186. }
  187. EnvVar[1] = *(PCHAR)lpBuf;
  188. if(SetEnvironmentVariableOem ((LPSTR)EnvVar,lpBuf) == FALSE)
  189. setCF(1);
  190. else {
  191. // this is what '95 is doing for dos apps.
  192. // upon a getcurdir call -- it is going to be invalid
  193. strncpy(pCDS->CurDir_Text, lpBuf, DIRSTRLEN);
  194. pCDS->CurDir_Text[DIRSTRLEN-1] = 0;
  195. if (bLongDirName) {
  196. setCF(1);
  197. }
  198. else {
  199. setCF(0);
  200. }
  201. }
  202. return;
  203. }
  204. #ifdef DBCS /* ConvNwPathToDosPath() for CSNW */
  205. //
  206. // TO BT LATER and IT SHOULD BE...
  207. //
  208. // This routine does change Novell-J-laized file name to
  209. // our well-known filename, but this code is only for the
  210. // request from Novell utilities. these code should be
  211. // laied onto nw16.exe (nw\nw16\tsr\resident.asm).
  212. //
  213. VOID ConvNwPathToDosPath(CHAR *lpszDos,CHAR *lpszNw, ULONG uDosSize)
  214. {
  215. /*
  216. * check parameter
  217. */
  218. if((lpszDos == NULL) || (lpszNw == NULL)) return;
  219. /*
  220. * copy data from vdm buffer to our local buffer
  221. */
  222. strncpy(lpszDos,lpszNw, uDosSize);
  223. lpszDos[uDosSize-1] = 0;
  224. /*
  225. * replace the specified character
  226. */
  227. while(*lpszDos) {
  228. if(IsDBCSLeadByte(*lpszDos)) {
  229. /*
  230. * This is a DBCS character, check trailbyte is 0x5C or not.
  231. */
  232. lpszDos++;
  233. if( *lpszDos == 0x13 ) {
  234. *lpszDos++ = (UCHAR)0x5C;
  235. continue;
  236. }
  237. }
  238. switch((UCHAR)*lpszDos) {
  239. case 0x10 :
  240. *lpszDos = (UCHAR)0xBF;
  241. break;
  242. case 0x11 :
  243. *lpszDos = (UCHAR)0xAE;
  244. break;
  245. case 0x12 :
  246. *lpszDos = (UCHAR)0xAA;
  247. break;
  248. }
  249. /*
  250. * next char
  251. */
  252. lpszDos++;
  253. }
  254. }
  255. #endif /* DBCS */