home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d026 / 25.ddi / NET / MSNET.AS_ / MSNET.AS
Encoding:
Text File  |  1991-11-16  |  14.2 KB  |  513 lines

  1. page        60, 132
  2. title        Access to MSNET Functions
  3. ;===============================================================================
  4. ;        Filename    MSNET.ASM
  5. ;        Copyright    (C) 1989 by Research Machines
  6. ;        Copyright    (C) 1989-1990 by Microsoft Corporation
  7. ;===============================================================================
  8. ; REVISIONS:    24/02/1989    Initial Version
  9. ;        15/03/1989    Add WNetCreateHandle and WNetCloseHandle
  10. ;        16/03/1989    Change to STANDARD procedures (save si, di, es)
  11. ;        29/03/1989    Change to WNetCancelConnection - allow net path
  12. ;        30/03/1989    Added MSNetGetMachineName. Updated comments.
  13. ;===============================================================================
  14.  
  15.         memM    equ    1                ; Middle memory model
  16.         ?WIN    =    1                ; Windows prolog/epilog
  17.         ?PLM    =    1                ; Pascal calling convention
  18.  
  19.         .xlist
  20. include     cmacros.inc
  21. include     windows.inc
  22. include     wnet.inc
  23. include     msdos.inc
  24.         .list
  25.  
  26.         .sall
  27.  
  28. externFP    UTLStricmpColon                 ; In file UTILS.ASM
  29. externFP    UTLIsSerialDevice                ; In file UTILS.ASM
  30. externFP    UTLIsNetworkPath                ; In file UTILS.ASM
  31. externFP    UTLAppendTrailingColon                ; In file UTILS.ASM
  32.  
  33. externFP    lstrcmp
  34. externFP    lstrcpy
  35. externFP    lstrlen
  36.  
  37. ;===============================================================================
  38. ; ============= DATA SEGMENT ===================================================
  39. ;===============================================================================
  40.  
  41. sBegin        DATA
  42.  
  43. public ErrorXTbl
  44. ErrorXTbl   db    00h, WN_SUCCESS         ; Yay, no error
  45.         db    05h, WN_ACCESS_DENIED        ; access denied
  46.         db    08h, WN_OUT_OF_MEMORY        ; out of memory somewhere
  47.             db  0bh, WN_BAD_NETNAME         ; weirdo dos error.
  48.         db    13h, WN_ACCESS_DENIED        ; write protected disk
  49.         db    18h, WN_BAD_VALUE        ; bad struct length
  50.         db    32h, WN_NOT_SUPPORTED        ; net not supported
  51.         db    35h, WN_BAD_NETNAME        ; network name not found
  52.         db    40h, WN_BAD_NETNAME        ; network name deleted
  53.         db    41h, WN_ACCESS_DENIED        ; network access denied
  54.         db    44h, WN_BAD_NETNAME        ; net name limit exceeded?????
  55.         db    54h, WN_NOT_CONNECTED        ; too many redirections
  56.         db    55h, WN_ALREADY_CONNECTED   ; connection already used
  57.         db    56h, WN_BAD_PASSWORD        ; password is incorrect
  58.  
  59. NERRORS     equ ($-ErrorXTbl)/2
  60.  
  61. sEnd        DATA
  62.  
  63. ;===============================================================================
  64. ; ============= CODE SEGMENT ===================================================
  65. ;===============================================================================
  66.  
  67. createSeg    _MSN, MSNCODE, BYTE, PUBLIC, CODE
  68. sBegin        MSNCODE
  69.         assumes CS, MSNCODE
  70.         assumes DS, DATA
  71.  
  72. ;===============================================================================
  73. subttl        MapMSDOSErrorCode
  74. page
  75. ;===============================================================================
  76. ;
  77. ; DESCRIPTION . Convert MSDOS error code into a Windows errorcode
  78. ; ENTRY ....... carry set => error
  79. ; EXIT ........ ax = Windows error
  80. ; COMMENT .....
  81. ;
  82. ;===============================================================================
  83.  
  84. cProc MapMSDOSError, <NEAR, PUBLIC>
  85. cBegin <nogen>
  86.  
  87.     jnc     maperror_none
  88.  
  89.     mov     ah, 59h        ; get error code
  90.     sub     bx, bx
  91.     call    dos3call
  92.  
  93.     mov     bl, al        ; save dos error code
  94.     push    si
  95.     lea     si, ErrorXTbl    ; point to table
  96.     mov     cx, NERRORS
  97.  
  98. maperror_loop:
  99.     lodsw
  100.     cmp     al,bl
  101.     jz        maperror_exit
  102.     loop    maperror_loop
  103.  
  104.     pop     si
  105.     mov     ax, WN_NET_ERROR    ; generic error code
  106.     ret
  107.  
  108. maperror_exit:
  109.     pop     si
  110.     mov     al,ah
  111.     sub     ah,ah
  112.     ret
  113.  
  114. maperror_none:
  115.  
  116.     sub     ax, ax        ; WN_SUCCESS
  117.     ret
  118.  
  119. cEnd   <nogen>
  120.  
  121. ;===============================================================================
  122. ; ============= PUBLIC FUNTIONS ================================================
  123. ;===============================================================================
  124.  
  125. ;===============================================================================
  126. subttl        MSNetMakeAssignListEntry
  127. page
  128. ;===============================================================================
  129. ;
  130. ; DESCRIPTION . Redirect a local device across the network
  131. ; ENTRY ....... lpszLocalName -> device name
  132. ;        lpszRemoteName -> net path including password
  133. ;        nUserValue = 0 (usually)
  134. ; EXIT ........ AX = SUCCESS or not
  135. ; COMMENT .....
  136. ;
  137. ;===============================================================================
  138.  
  139. cProc        MSNetMakeAssignListEntry, <FAR, PUBLIC>, <si, di>
  140.  
  141.         parmD    lpszLocalName
  142.         parmD    lpszRemoteName
  143.         parmW    nUserValue
  144. cBegin
  145. ;---------------------------------------------------------------
  146. ; Find out if the local name is a printer or disk drive. NULL
  147. ; device names count as drives for now
  148. ;---------------------------------------------------------------
  149.  
  150.         Arg    lpszLocalName                ;
  151.         cCall    UTLIsSerialDevice            ;
  152.         or    ax,ax
  153.         jnz    DeviceIsSerial                ;
  154.  
  155.         mov    bl, 4                    ; Device is block, or NULL
  156.         jmp    short MakeALEntry            ;
  157. DeviceIsSerial: mov    bl, 3
  158.  
  159. ;---------------------------------------------------------------
  160. ; Make the assign list entry
  161. ;---------------------------------------------------------------
  162. MakeALEntry:
  163.         push    ds
  164.         mov    ax, DosMakeAssignListEntry
  165.         mov    cx, nUserValue
  166.         lds    si, ( lpszLocalName )
  167.         les    di, ( lpszRemoteName )
  168.         call    dos3call
  169.         pop    ds
  170.  
  171.         call    MapMSDOSError
  172. cEnd
  173.  
  174. ;===============================================================================
  175. subttl        MSNetCancelAssignListEntry
  176. page
  177. ;===============================================================================
  178. ;
  179. ; DESCRIPTION . Cancel a redirection across the network
  180. ; ENTRY ....... lpszName points to a local / remote name to cancel
  181. ; EXIT ........ AX holds return code
  182. ; COMMENT ..... If szName is a full network path, we must use the local device
  183. ;        name if there is one. NOT IMPLEMENTED YET.
  184. ;
  185. ;===============================================================================
  186.  
  187. cProc        MSNetCancelAssignListEntry, <FAR, PUBLIC>, <si>
  188.  
  189.         parmD    lpszName
  190.  
  191. cBegin
  192.  
  193. WNCECancel:    push    ds
  194.         mov    ax, DosCancelAssignListEntry
  195.         lds    si,lpszName
  196.         call    dos3call
  197.         pop    ds
  198.  
  199.         call    MapMSDOSError
  200. WNCEExit:
  201.  
  202. cEnd
  203.  
  204. ;===============================================================================
  205. subttl        MSNetGetAssignListEntry
  206. page
  207. ;===============================================================================
  208. ;
  209. ; DESCRIPTION . Return an assign list entry
  210. ; ENTRY ....... lpBuffer -> space for a single assign list entry (16+128)
  211. ;        nIndex = index into assign list
  212. ; EXIT ........ AX = SUCCESS or not
  213. ;        BX = 3 for printer, 4 for drive
  214. ;        CX = user value
  215. ; COMMENTS ....
  216. ;
  217. ;===============================================================================
  218.  
  219. cProc        MSNetGetAssignListEntry, <FAR, PUBLIC>, <si, di>
  220.  
  221.         parmD    lpBuffer
  222.         parmW    nIndex
  223. cBegin
  224.         push    ds
  225.         mov    ax, DosGetAssignListEntry
  226.         mov    bx, ( nIndex )
  227.         lds    si, ( lpBuffer )
  228.         les    di, ( lpBuffer )
  229.         add    di, 16
  230.         call    dos3call
  231.         pop    ds
  232.  
  233.         call    MapMSDOSError
  234.  
  235.         mov    bh, 0
  236. cEnd
  237.  
  238. ;===============================================================================
  239. subttl        MSNetFindLocalSession
  240. page
  241. ;===============================================================================
  242. ;
  243. ; DESCRIPTION .
  244. ; ENTRY .......
  245. ; EXIT ........
  246. ; COMMENT .....
  247. ;
  248. ;===============================================================================
  249.  
  250. cProc        MSNetFindLocalSession, <FAR, PUBLIC>, <SI,DI>
  251.  
  252.         parmD    lpszLocalName
  253.  
  254.         localW    nIndex
  255.         localW    nSessionNumber
  256.  
  257.         localV    rgbALE, <size AssignListEntry>
  258. cBegin
  259.         lea    si,rgbALE
  260.  
  261. ;---------------------------------------------------------------
  262. ; Now we need to flip through the assign entry list looking for
  263. ; the local device name.
  264. ;---------------------------------------------------------------
  265.  
  266. WNFLSStart:    mov    ( nIndex ), 0                ; First entry
  267.  
  268.         push    ds
  269.         mov    ax,ss
  270.         mov    ds,ax
  271.         mov    es,ax
  272.  
  273. WNFLSNextEntry:
  274.         mov    ax, DosGetAssignListEntry2        ; As function 5f02h
  275.         mov    bx, ( nIndex )                ; but returns session
  276.         lea    di, rgbALE.aleRemoteName
  277.         lea    si, rgbALE.aleLocalName         ; make ds:si -> local name
  278.         push    bp                    ;
  279.         int    MSDOS                    ; can't use dos3call because of bp
  280.         mov    ax, bp                    ;
  281.         pop    bp                    ;
  282.         mov    ( nSessionNumber ), ax            ; Save session
  283.  
  284.         jnc    CheckLocal                ; A session found.
  285.         jmp    short WNFLSExit             ; End of list.
  286.  
  287. ;---------------------------------------------------------------
  288. ; Does the local name in the assign list match the name we are
  289. ; looking for?
  290. ;---------------------------------------------------------------
  291.  
  292. CheckLocal:    lea    bx, rgbALE.aleLocalName         ;
  293.  
  294.         Arg    lpszLocalName                ; Compare strings
  295.         Arg    RegPairSsBx                ;
  296.         cCall    UTLStricmpColon             ;
  297.         or    ax,ax
  298.         je    WNFLSSuccess                   ;
  299.  
  300. ;---------------------------------------------------------------
  301. ; Try next assign list entry              ;
  302. ;---------------------------------------------------------------
  303.  
  304.         inc    ( nIndex )
  305.         jmp    short WNFLSNextEntry
  306.  
  307. ;---------------------------------------------------------------
  308. ; The local net path has been found in the assign list. The
  309. ; session number is in ( nSessionNumber ).
  310. ;---------------------------------------------------------------
  311.  
  312. WNFLSSuccess:    mov    ax,nSessionNumber
  313.  
  314. WNFLSExit:
  315.         pop    ds
  316.  
  317. cEnd
  318.  
  319. ;===============================================================================
  320. subttl        MSNetFindLocalName
  321. page
  322. ;===============================================================================
  323. ;
  324. ; DESCRIPTION .
  325. ; ENTRY .......
  326. ; EXIT ........
  327. ; COMMENT .....
  328. ;
  329. ;===============================================================================
  330.  
  331. cProc        MSNetFindLocalName, <FAR, PUBLIC>, <si>
  332.  
  333.         parmD    lpszRemoteName
  334.         parmD    lpszLocalName
  335.  
  336.         localW    nIndex
  337.         localW    nReturnCode
  338.  
  339.         localV    rgbALE, <size AssignListEntry>
  340. cBegin
  341.  
  342. ;---------------------------------------------------------------
  343. ; Now we need to flip through the assign entry list looking for
  344. ; the remote device name.
  345. ;---------------------------------------------------------------
  346.  
  347. WNFLNStart:    mov    ( nIndex ), 0                ; First entry
  348.  
  349. WNFLNNextEntry: StandardSave                    ; Save SI, DI, DS
  350.         mov    ax,ss
  351.         mov    ds,ax
  352.         mov    es,ax
  353.         mov    ax, DosGetAssignListEntry        ; Function 5f02h
  354.         mov    bx, ( nIndex )                ;
  355.         lea    si, rgbALE.aleLocalName
  356.         lea    di, rgbALE.aleRemoteName
  357.         call    dos3call
  358.  
  359.         StandardRestore                 ; Restore SI, DI, DS
  360.  
  361.         jnc    CheckForMatch                ; An entry found.
  362.         mov    ax , not WN_SUCCESS            ; End of list.
  363.         jmp    short WNFLNExit
  364.  
  365. ;---------------------------------------------------------------
  366. ; Does the remote name in the assign list match the name we are
  367. ; looking for?
  368. ;---------------------------------------------------------------
  369.  
  370. CheckForMatch:    lea    bx, rgbALE.aleRemoteName        ;
  371.  
  372.         Arg    lpszRemoteName                ; Compare strings
  373.         Arg    RegPairSsBx                ;
  374.         cCall    LStrcmp                  ;
  375.         cmp    ax, 0                    ; Equal ?
  376.         je    WNFLNSuccess                ;
  377.  
  378. ;---------------------------------------------------------------
  379. ; Try next assign list entry
  380. ;---------------------------------------------------------------
  381.  
  382.         inc    ( nIndex )
  383.         jmp    short WNFLNNextEntry
  384.  
  385. ;---------------------------------------------------------------
  386. ; The remote net path has been found in the assign list.
  387. ; Copy the associated local name to the users buffer.
  388. ;---------------------------------------------------------------
  389.  
  390. WNFLNSuccess:    lea    bx, rgbALE.aleLocalName         ;
  391.  
  392.         Arg    lpszLocalName
  393.         Arg    RegPairSsBx
  394.         cCall    LStrcpy
  395.         mov    ax, WN_SUCCESS
  396.  
  397. WNFLNExit:
  398.  
  399. cEnd
  400.  
  401. ;===============================================================================
  402. subttl        MSNetGetMachineName
  403. page
  404. ;===============================================================================
  405. ;
  406. ; DESCRIPTION . Returns the local machine name using DosGetMachineName
  407. ; ENTRY ....... lpszMachineName points to space for machine name
  408. ; EXIT ........ AX hold WN_SUCCESS or not
  409. ;        szMachineName completed with local machine name
  410. ; COMMENT .....
  411. ;
  412. ;===============================================================================
  413.  
  414. cProc        MSNetGetMachineName, <FAR, PUBLIC>, <si, di>
  415.  
  416.         parmD    lpszMachineName
  417.  
  418. cBegin
  419. ;---------------------------------------------------------------
  420. ; Call dos to get the local machine name.
  421. ;---------------------------------------------------------------
  422.  
  423.         push    ds
  424.  
  425.         mov    ax, DosGetMachineName
  426.         lds    dx, ( lpszMachineName )
  427.         call    dos3call
  428.  
  429.         pop    ds
  430.         call    MapMSDOSError
  431.  
  432. cEnd
  433.  
  434. ;===============================================================================
  435. subttl        MSNetCreateHandle
  436. page
  437. ;===============================================================================
  438. ;
  439. ; DESCRIPTION .
  440. ; ENTRY .......
  441. ; EXIT ........
  442. ; COMMENT .....
  443. ;
  444. ;===============================================================================
  445.  
  446. cProc        MSNetCreateHandle, <FAR, PUBLIC>
  447.  
  448.         parmD    lpszName
  449.         parmW    nAttribute
  450.  
  451.         localW    handle
  452. cBegin
  453.         mov    ( nReturnCode ), NULL            ; Ever pessimistic
  454.  
  455.         mov    ah, DosCreateHandle
  456.         lds    dx, ( lpszName )
  457.         mov    cx, ( nAttribute )
  458.         call    dos3call
  459.         jc    ch_nohandle
  460.  
  461.         mov    handle, ax
  462.         xchg    bx, ax            ; handle in bx
  463.         mov    ax, 4400h        ; get device bits
  464.         call    dos3call
  465.         jc    ch_skipbits        ; handle error
  466.         sub    dh, dh
  467.         or    dl, 20h         ; set raw mode bit
  468.         mov    bx, handle
  469.         mov    ax, 4401h        ; set device bits
  470.         call    dos3call
  471. ch_skipbits:
  472.         mov    ax, handle
  473.         jmp    short create_exit
  474.  
  475. ch_nohandle:
  476.         call    MapMSDosError
  477.         neg    ax            ; hack, return negative
  478. create_exit:
  479.  
  480. cEnd
  481.  
  482. ;===============================================================================
  483. subttl        MSNetCloseHandle
  484. page
  485. ;===============================================================================
  486. ;
  487. ; DESCRIPTION .
  488. ; ENTRY .......
  489. ; EXIT ........
  490. ; COMMENT .....
  491. ;
  492. ;===============================================================================
  493.  
  494. cProc        MSNetCloseHandle, <FAR, PUBLIC>, <si, di, ds>
  495.  
  496.         parmW    nHandle
  497.  
  498. cBegin
  499.         mov    ah, DosCloseHandle
  500.         mov    bx, ( nHandle )
  501.         call    dos3call
  502.  
  503.         call    MapMSDOSError
  504.  
  505. cEnd
  506.  
  507. ;===============================================================================
  508. ; ============= END OF MSNET ===================================================
  509. ;===============================================================================
  510.  
  511. sEnd        MSNCODE
  512.         end
  513.