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.

510 lines
13 KiB

  1. page ,132
  2. ; SCCSID = @(#)tmisc2.asm 4.3 85/06/25
  3. ; SCCSID = @(#)tmisc2.asm 4.3 85/06/25
  4. TITLE Part7 COMMAND Transient Routines
  5. ;/*
  6. ; * Microsoft Confidential
  7. ; * Copyright (C) Microsoft Corporation 1991
  8. ; * All Rights Reserved.
  9. ; */
  10. ; More misc routines
  11. .xlist
  12. .xcref
  13. include comsw.asm
  14. include dossym.inc
  15. include syscall.inc
  16. include pdb.inc
  17. include bpb.inc
  18. include sf.inc
  19. include comseg.asm
  20. include comequ.asm
  21. include ioctl.inc
  22. .list
  23. .cref
  24. CODERES SEGMENT PUBLIC BYTE ;AC000;
  25. CodeRes ENDS
  26. DATARES SEGMENT PUBLIC BYTE ;AC000;
  27. EXTRN IFFlag:BYTE
  28. EXTRN PIPEFLAG:BYTE
  29. EXTRN RE_OUTSTR:BYTE
  30. EXTRN RE_OUT_APP:BYTE
  31. DATARES ENDS
  32. TRANDATA SEGMENT PUBLIC BYTE ;AC000;
  33. EXTRN AccDen_PTR:WORD
  34. EXTRN Extend_buf_ptr:word ;AN000;
  35. EXTRN FULDIR_PTR:WORD
  36. EXTRN msg_disp_class:byte ;AN000;
  37. TRANDATA ENDS
  38. TRANSPACE SEGMENT PUBLIC BYTE ;AC000;
  39. EXTRN DESTINFO:BYTE
  40. EXTRN DESTISDIR:BYTE
  41. EXTRN KPARSE:BYTE ;AC000;
  42. EXTRN ONE_CHAR_VAL:BYTE ;AN011;
  43. EXTRN PATHCNT:WORD
  44. EXTRN PATHPOS:WORD
  45. EXTRN PATHSW:WORD
  46. EXTRN RE_INSTR:BYTE
  47. EXTRN RESSEG:WORD
  48. EXTRN SRCBUF:BYTE
  49. EXTRN SWITCHAR:BYTE
  50. IF IBM
  51. EXTRN ROM_CALL:BYTE
  52. EXTRN ROM_CS:WORD
  53. EXTRN ROM_IP:WORD
  54. ENDIF
  55. TRANSPACE ENDS
  56. TRANCODE SEGMENT PUBLIC byte
  57. ASSUME CS:TRANGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
  58. EXTRN CERROR:NEAR
  59. IF IBM
  60. EXTRN ROM_EXEC:NEAR
  61. EXTRN ROM_SCAN:NEAR
  62. ENDIF
  63. PUBLIC IOSET
  64. PUBLIC MOVE_TO_SRCBUF ;AN000;
  65. PUBLIC PGETARG
  66. PUBLIC SETPATH
  67. PUBLIC TESTDOREIN
  68. PUBLIC TESTDOREOUT
  69. ASSUME DS:TRANGROUP
  70. SETPATH:
  71. ;
  72. ; ENTRY PathPos = ptr to string
  73. ; PathCnt = length of string
  74. ;
  75. ; EXIT PathPos = ptr to string after pathname
  76. ; PathCnt = length of rest of string
  77. ; DX = ptr to pathname in string, made ASCIIZ
  78. ; DestIsDir = 1 if pathname delimiters appeared in pathname, 0 otherwise
  79. ; DestInfo = 2 if wildcards (?, *) appeared in pathname, 0 otherwise
  80. ;
  81. ; A null character is dropped at the end of the pathname. If the
  82. ; character in that spot previously was CR, it is copied into the
  83. ; following byte. So there must be at least two two character
  84. ; positions in the buffer following the pathname.
  85. ;
  86. MOV AX,[PATHCNT] ;AC000; get length of string
  87. MOV SI,[PATHPOS] ;AC000; get start of source buffer
  88. GETPATH:
  89. MOV [DESTINFO],0
  90. MOV [DESTISDIR],0
  91. MOV SI,[PATHPOS] ; SI = ptr to string
  92. MOV CX,[PATHCNT] ; CX = string length
  93. MOV DX,SI ; DX = ptr to string
  94. JCXZ PATHDONE ; string length is zero, we're done
  95. PUSH CX ; save string length
  96. PUSH SI ; save ptr to string
  97. INVOKE SWITCH
  98. ; After Switch, SI has been scanned past any switches, and
  99. ; switches that COMMAND intrinsically recognizes are recorded in AX.
  100. MOV [PATHSW],AX ; PathSw = switch occurrence mask
  101. POP BX ; BX = ptr to original string
  102. SUB BX,SI ; BX = -(# chars scanned by Switch)
  103. POP CX ; CX = string length
  104. ADD CX,BX ; CX = string length from current SI
  105. MOV DX,SI ; DX = ptr to current string
  106. SKIPPATH:
  107. ;;;; IFDEF DBCS 3/3/KK
  108. MOV [KPARSE],0
  109. SKIPPATH2:
  110. ;;;; ENDIF 3/3/KK
  111. JCXZ PATHDONE ; string length is zero, we're done
  112. DEC CX ; CX = length left after next char
  113. LODSB ; AL = next char of string
  114. ; SI = ptr to char after this one
  115. ;;;; IFDEF DBCS 3/3/KK
  116. INVOKE TESTKANJ
  117. JZ TESTPPSEP ; no Kanji, move along
  118. DEC CX
  119. INC SI
  120. INC [KPARSE]
  121. JMP SKIPPATH2
  122. TESTPPSEP:
  123. ;;;; ENDIF 3/3/KK
  124. INVOKE PATHCHRCMP ; compare AL to path delimiter char
  125. JNZ TESTPMETA ; it's not a path delim
  126. INC [DESTISDIR] ; DestIsDir = 1, signalling path char
  127. TESTPMETA:
  128. CMP AL,'?'
  129. JNZ TESTPSTAR ; char is not '?'
  130. OR [DESTINFO],2 ; DestInfo = 2, signalling wildcard
  131. TESTPSTAR:
  132. CMP AL,star
  133. JNZ TESTPDELIM ; char is not '*'
  134. OR [DESTINFO],2 ; DestInfo = 2, signalling wildcard
  135. TESTPDELIM:
  136. INVOKE DELIM ; compare AL to all delimiters
  137. JZ PATHDONEDEC ; delimiter found, back up & leave
  138. CMP AL,[SWITCHAR]
  139. JNZ SKIPPATH ; char isn't switch, go get next char
  140. PATHDONEDEC:
  141. DEC SI ; SI = ptr to char after pathname
  142. PATHDONE:
  143. XOR AL,AL ; AL = NULL
  144. XCHG AL,[SI] ; place NULL after pathname
  145. INC SI ; SI = ptr to byte after NULL
  146. CMP AL,0DH ; were we at end of line?
  147. JNZ NOPSTORE ; not EOL, finish up
  148. MOV [SI],AL ; save EOL after NULL
  149. NOPSTORE:
  150. MOV [PATHPOS],SI ; PathPos = ptr to char after NULL
  151. MOV [PATHCNT],CX ; PathCnt = length of string left
  152. return
  153. PGETARG:
  154. MOV SI,80H
  155. LODSB
  156. OR AL,AL
  157. retz
  158. CALL PSCANOFF
  159. CMP AL,13
  160. return
  161. PSCANOFF:
  162. LODSB
  163. INVOKE DELIM
  164. JNZ PSCANOFFD
  165. CMP AL,';'
  166. JNZ PSCANOFF ; ';' is not a delimiter
  167. PSCANOFFD:
  168. DEC SI ; Point to first non-delimiter
  169. return
  170. IOSET:
  171. ;
  172. ; ALL REGISTERS PRESERVED
  173. ;
  174. ASSUME DS:NOTHING,ES:NOTHING,SS:NOTHING
  175. PUSH DS
  176. PUSH DX
  177. PUSH AX
  178. PUSH BX
  179. PUSH CX
  180. MOV DS,[RESSEG]
  181. ASSUME DS:RESGROUP
  182. CMP [PIPEFLAG],0
  183. JNZ NOREDIR ; Don't muck up the pipe
  184. TEST IFFlag,-1
  185. JNZ NoRedir
  186. CALL TESTDOREIN
  187. CALL TESTDOREOUT
  188. NOREDIR:
  189. POP CX
  190. POP BX
  191. POP AX
  192. POP DX
  193. POP DS
  194. ASSUME DS:NOTHING
  195. return
  196. TESTDOREIN:
  197. ASSUME DS:RESGROUP
  198. CMP [RE_INSTR],0
  199. retz
  200. PUSH DS
  201. PUSH CS
  202. POP DS
  203. MOV DX,OFFSET tranGROUP:RE_INSTR
  204. MOV AX,(OPEN SHL 8)
  205. MOV BX,AX
  206. INT 21h
  207. POP DS
  208. JC REDIRERR
  209. MOV BX,AX
  210. MOV AL,0FFH
  211. ;
  212. ; Mega sleaze!! We move the SFN from the new handle spot into the old stdin
  213. ; spot. We invalidate the new JFN we got.
  214. ;
  215. XCHG AL,[BX.PDB_JFN_Table]
  216. MOV DS:[PDB_JFN_Table],AL
  217. return
  218. ;
  219. ; We had some kind of error on the redirection. Figure out what the
  220. ; appropriate message should be; BX has the system call that failed
  221. ;
  222. REDIRERR:
  223. PUSH CS
  224. POP DS
  225. Call TriageError
  226. ;
  227. ; At this point, we have recognized the network-generated access denied error.
  228. ; The correct message is in DX
  229. ;
  230. CMP AX,65
  231. JZ CERRORJ ;AC000; just issue message returned
  232. CMP BH,OPEN
  233. JZ OpenError
  234. ;
  235. ; The error was for a create operation. Report the error as a creation error.
  236. ;
  237. MOV DX,OFFSET TranGroup:FULDIR_PTR
  238. CERRORJ:
  239. JMP CERROR
  240. ;
  241. ; The system call was an OPEN. Report either file not found or path not found.
  242. ;
  243. OpenError:
  244. mov msg_disp_class,ext_msg_class ;AN000; set up extended error msg class
  245. mov dx,offset TranGroup:Extend_Buf_ptr ;AC000; get extended message pointer
  246. mov Extend_Buf_ptr,ax ;AN000; get message number in control block
  247. JMP CERROR
  248. TESTDOREOUT:
  249. ASSUME DS:RESGROUP
  250. CMP [RE_OUTSTR],0
  251. JNZ REOUTEXISTS ;AN017; need long jump
  252. JMP NOREOUT ;AN017;
  253. REOUTEXISTS:
  254. CMP [RE_OUT_APP],0
  255. JZ REOUTCRT
  256. ;
  257. ; The output redirection was for append. We open for write and seek to the
  258. ; end.
  259. ;
  260. MOV DX,OFFSET RESGROUP:RE_OUTSTR
  261. MOV AX,(OPEN SHL 8) OR 2 ;AC011; Open for read/write
  262. PUSH AX
  263. INT 21h
  264. POP BX
  265. JC OpenWriteError
  266. MOV BX,AX
  267. MOV AX,IOCTL SHL 8 ;AN035; Get attributes of handle
  268. INT 21h ;AN035;
  269. TEST DL,devid_ISDEV ;AN035; Is it a device?
  270. JNZ SET_REOUT ;AN035; Yes, don't read from it
  271. MOV AX,(LSEEK SHL 8) OR 2
  272. MOV CX,-1 ;AC011; MOVE TO EOF -1
  273. MOV DX,CX ;AC011;
  274. INT 21h
  275. PUSH CS ;AN011; Get transient seg to DS
  276. POP DS ;AN011;
  277. assume DS:Trangroup ;AN011;
  278. MOV AX,(READ SHL 8) ;AN011; Read one byte from the
  279. MOV CX,1 ;AN011; file into one_char_val
  280. MOV DX,OFFSET Trangroup:ONE_CHAR_VAL;AN011;
  281. INT 21h ;AN011;
  282. JC OpenWriteError ;AN011; If error, exit
  283. cmp ax,cx ;AN017; Did we read 1 byte?
  284. jnz reout_0_length ;AN017; No - file must be 0 length
  285. cmp one_char_val,01ah ;AN011; Was char an eof mark?
  286. mov DS,[resseg] ;AN011; Get resident segment back
  287. assume DS:Resgroup ;AN011;
  288. JNZ SET_REOUT ;AN011; No, just continue
  289. MOV AX,(LSEEK SHL 8) OR 1 ;AN011; EOF mark found
  290. MOV CX,-1 ;AN011; LSEEK back one byte
  291. MOV DX,CX ;AN011;
  292. INT 21h ;AN011;
  293. JMP SHORT SET_REOUT
  294. reout_0_length: ;AN017; We have a 0 length file
  295. mov DS,[resseg] ;AN017; Get resident segment back
  296. assume DS:Resgroup ;AN017;
  297. MOV AX,(LSEEK SHL 8) ;AN017; Move to beginning of file
  298. XOR CX,CX ;AN017; Offset is 0
  299. MOV DX,CX ;AN017;
  300. INT 21h ;AN017;
  301. JMP SHORT SET_REOUT ;AN017; now finish setting up redirection
  302. OpenWriteError:
  303. CMP AX,error_access_denied
  304. STC ; preserve error
  305. JNZ REOUTCRT ;AN017; need long jump
  306. JMP REDIRERR ;AN017;
  307. REOUTCRT:
  308. MOV DX,OFFSET RESGROUP:RE_OUTSTR
  309. XOR CX,CX
  310. MOV AH,CREAT
  311. PUSH AX
  312. INT 21h
  313. POP BX
  314. JNC NOREDIRERR ;AC011;
  315. JMP REDIRERR ;AC011;
  316. NOREDIRERR: ;AN011;
  317. MOV BX,AX
  318. SET_REOUT:
  319. ;
  320. ; Mega sleaze!! We move the SFN from the new handle spot into the old stdout
  321. ; spot. We invalidate the new JFN we got.
  322. ;
  323. MOV AL,0FFH
  324. XCHG AL,[BX.PDB_JFN_Table]
  325. MOV DS:[PDB_JFN_Table+1],AL
  326. NOREOUT:
  327. return
  328. ;
  329. ; Compute length of string (including NUL) in DS:SI into CX. Change no other
  330. ; registers
  331. ;
  332. Procedure DSTRLEN,NEAR
  333. SaveReg <AX>
  334. XOR CX,CX
  335. CLD
  336. DLoop: LODSB
  337. INC CX
  338. OR AL,AL
  339. JNZ DLoop
  340. SUB SI,CX
  341. RestoreReg <AX>
  342. return
  343. EndProc DSTRLEN
  344. Break <Extended error support>
  345. ;
  346. ; TriageError will examine the return from a carry-set system call and
  347. ; return the correct error if applicable.
  348. ;
  349. ; Inputs: outputs from a carry-settable system call
  350. ; No system calls may be done in the interrim
  351. ; Outputs: If carry was set on input
  352. ; carry set on output
  353. ; DX contains trangroup offset to printf message
  354. ; else
  355. ; No registers changed
  356. ;
  357. Procedure TriageError,NEAR
  358. retnc ; no carry => do nothing...
  359. PUSHF
  360. SaveReg <BX,CX,SI,DI,BP,ES,DS,AX,DX>
  361. MOV AH,GetExtendedError
  362. INT 21h
  363. RestoreReg <CX,BX> ; restore original AX
  364. MOV DX,OFFSET TranGroup:AccDen_PTR
  365. CMP AX,65 ; network access denied?
  366. JZ NoMove ; Yes, return it.
  367. MOV AX,BX
  368. MOV DX,CX
  369. NoMove:
  370. RestoreReg <DS,ES,BP,DI,SI,CX,BX>
  371. popf
  372. return
  373. EndProc TriageError
  374. PUBLIC Triage_Init
  375. Triage_Init proc FAR
  376. call TriageError
  377. ret
  378. Triage_Init endp
  379. ; ****************************************************************
  380. ; *
  381. ; * ROUTINE: MOVE_TO_SRCBUF
  382. ; *
  383. ; * FUNCTION: Move ASCIIZ string from DS:SI to SRCBUF. Change
  384. ; * terminating 0 to 0dH. Set PATHCNT to length of
  385. ; * string. Set PATHPOS to start of SRCBUF.
  386. ; *
  387. ; * INPUT: DS:SI points to ASCIIZ string
  388. ; * ES points to TRANGROUP
  389. ; *
  390. ; * OUTPUT: SRCBUF filled in with string terminated by 0dH
  391. ; * PATHCNT set to length of string
  392. ; * PATHPOS set to start of SRCBUF
  393. ; * CX,AX changed
  394. ; *
  395. ; ****************************************************************
  396. assume es:trangroup,ds:nothing ;AN000;
  397. MOVE_TO_SRCBUF PROC NEAR ;AN000;
  398. push si ;AN000; save si,di
  399. push di ;AN000;
  400. push cx ;AN000;
  401. mov di,offset TRANGROUP:srcbuf ;AN000; set ES:DI to srcbuf
  402. xor cx,cx ;AN000; clear cx for counint
  403. mov ax,cx ;AN000; clear ax
  404. push di ;AN000; save start of srcbuf
  405. lodsb ;AN000; get a character from DS:SI
  406. mts_get_chars: ;AN000;
  407. cmp al,0 ;AN000; was it a null char?
  408. jz mts_end_string ;AN000; yes - exit
  409. stosb ;AN000; no - store it in srcbuf
  410. inc cx ;AN000; increment length count
  411. lodsb ;AN000; get a character from DS:SI
  412. jmp short mts_get_chars ;AN000; go check it
  413. mts_end_string: ;AN000; we've reached the end of line
  414. mov al,end_of_line_in ;AN000; store 0dH in srcbuf
  415. stosb ;AN000;
  416. pop di ;AN000; restore start of srcbuf
  417. push cs ;AN000; set DS to local segment
  418. pop ds ;AN000;
  419. assume ds:trangroup ;AN000;
  420. mov [pathcnt],cx ;AN000; set patchcnt to length count
  421. mov [pathpos],di ;AN000; set pathpos to start of srcbuf
  422. pop cx ;AN000; restore cx,di,si
  423. pop di ;AN000;
  424. pop si ;AN000;
  425. RET ;AN000; exit
  426. MOVE_TO_SRCBUF ENDP ;AN000;
  427. TRANCODE ENDS
  428. END
  429.