home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / netware.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  12KB  |  360 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/netware.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:32:29 $
  18.  * 
  19.  * Code to get the user's login name from netware
  20.  * 
  21.  * $Log: netware.c $
  22.  * Revision 2.0  1995/02/27  11:32:29  john
  23.  * New version 2.0, which has no anonymous unions, builds with
  24.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25.  * 
  26.  * Revision 1.2  1994/07/23  23:53:56  matt
  27.  * Code to get the user's name, not usable until we find a way to check
  28.  * that the user is attached and logged into a Novell network.
  29.  * 
  30.  * Revision 1.1  1994/07/23  19:35:16  matt
  31.  * Initial revision
  32.  * 
  33.  * 
  34.  */
  35.  
  36.  
  37. #pragma off (unreferenced)
  38. static char rcsid[] = "$Id: netware.c 2.0 1995/02/27 11:32:29 john Exp $";
  39. #pragma on (unreferenced)
  40.  
  41. #include <dos.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45.  
  46. #include "mono.h"
  47.  
  48. typedef unsigned char   BYTE;
  49. typedef unsigned short  WORD;
  50. typedef unsigned long   LONG;
  51. typedef unsigned char   UINT8;
  52. typedef unsigned short  UINT16;
  53. typedef unsigned long   UINT32;
  54. typedef signed   char   SINT8;
  55. typedef signed   short  SINT16;
  56. typedef signed   long   SINT32;
  57.  
  58. #define MAXOBJNAME  48
  59. #define BINDFUNC    227
  60. #define CONNFUNC    220
  61.  
  62. /*----------------------------------------------------------------------*/
  63. /*-- These structures are used by GetBinderyObjectName -----------------*/
  64. /*----------------------------------------------------------------------*/
  65.  
  66. typedef struct {
  67.         UINT16      length;
  68.         UINT8       subfunc;
  69.         UINT32      objID;
  70. }NWGBONS;
  71.  
  72. typedef struct {
  73.         UINT16      length;
  74.         UINT32      objID;
  75.         UINT16      objType;
  76.         BYTE        objName[MAXOBJNAME];
  77. }NWGBONR;
  78.  
  79. extern  SINT16  NWGetBinderyObjectName(UINT32, BYTE *, UINT16 *);
  80.  
  81. /*----------------------------------------------------------------------*/
  82. /*-- These structures are used by GetBinderyObjectID -------------------*/
  83. /*----------------------------------------------------------------------*/
  84.  
  85. typedef struct {
  86.         UINT16      length;
  87.         UINT8       subfunc;
  88.         UINT16      objType;
  89.         UINT8       objNLen;
  90.         BYTE        objName[47];
  91. }NWGBIDS;
  92.  
  93. typedef struct {
  94.         UINT16      length;
  95.         UINT32      objID;
  96.         UINT16      objType;
  97.         BYTE        objName[MAXOBJNAME];
  98. }NWGBIDR;
  99.  
  100. extern  SINT16  NWGetBinderyObjectID(BYTE *, UINT16, UINT32 *);
  101.  
  102. /*----------------------------------------------------------------------*/
  103. /*-- Functions in GETCONN.C --------------------------------------------*/
  104. /*----------------------------------------------------------------------*/
  105.  
  106. extern  SINT16  NWGetConnectionNumber(void);
  107.  
  108. /*----------------------------------------------------------------------*/
  109. /*-- These structures are used by NWGetConnectionInformation -----------*/
  110. /*----------------------------------------------------------------------*/
  111.  
  112. typedef struct {
  113.         UINT16      length;
  114.         UINT8       subfunc;
  115.         UINT8       connNum;
  116. }NWGCIS;
  117.  
  118. typedef struct {
  119.         UINT16      length;
  120.         UINT32      objID;
  121.         UINT16      objType;
  122.         BYTE        objName[MAXOBJNAME];
  123.         BYTE        loginTm[7];
  124.         BYTE        reserved;
  125. }NWGCIR;
  126.  
  127. SINT16  NWGetConnectionInformation(UINT16,BYTE *,UINT16 *,UINT32 *,BYTE *);
  128.  
  129. /*----------------------------------------------------------------------*/
  130. /*-- This information is for the protected to real mode call -----------*/
  131. /*----------------------------------------------------------------------*/
  132.  
  133. //
  134. //  The following structure is passed to the DPMI function which will
  135. //  execute the real-mode interrupt.  It will load these values into
  136. //  the registers and call Btrieve.
  137. //
  138.  
  139. typedef struct REAL_MODE_REGS{
  140.         LONG        edi;            // Real Mode Registers ...
  141.         LONG        esi;            // used for DPMI call 0x300
  142.         LONG        ebp;
  143.         LONG        reserved;
  144.         LONG        ebx;
  145.         LONG        edx;
  146.         LONG        ecx;
  147.         LONG        eax;
  148.         WORD        flags;
  149.         WORD        es;
  150.         WORD        ds;
  151.         WORD        fs;
  152.         WORD        gs;
  153.         WORD        ip;
  154.         WORD        cs;
  155.         WORD        sp;
  156.         WORD        ss;
  157. }RMREG;
  158.  
  159. extern  SINT16  NWRequest(BYTE function, void *request, void *reply);
  160. extern  void    *NWGetRequestBuffer(void);
  161. extern  void    *NWGetReplyBuffer(void);
  162. extern  SINT16  NWInitializeXfaceForDPMICalls(void);
  163.  
  164. /*----------------------------------------------------------------------*/
  165. /*-- These are helper functions ----------------------------------------*/
  166. /*----------------------------------------------------------------------*/
  167.  
  168. UINT32  DWordSwap( UINT32 );
  169. #pragma aux DWordSwap =                                 \
  170.         0x8b 0xd0           /* mov  edx,eax      */     \
  171.         0x86 0xe0           /* xchg ah,al        */     \
  172.         0xb1 0x10           /* mov  cl,16        */     \
  173.         0xd3 0xe0           /* shl  eax,cl       */     \
  174.         0xd3 0xea           /* shr  edx,cl       */     \
  175.         0x86 0xf2           /* xchg dh,dl        */     \
  176.         0x0b 0xc2           /* or   eax,edx      */     \
  177.         parm [eax] value [eax] modify [ecx edx];
  178.  
  179. UINT16  WordSwap( UINT16 );
  180. #pragma aux WordSwap =                              \
  181.         0x86 0xC4           /* xchg AL,AH   */      \
  182.         parm [eax] value [ax];
  183.  
  184. /*----------------------------------------------------------------------*/
  185.  
  186. #define DEFPARA         64                      // 1K of RAM needed
  187. #define DOS_INT         0x21                    // Shell Interrupt
  188. #define TRUE            1
  189. #define FALSE           0
  190. #define DPMI            0x31    /* DPMI Interrupt             */
  191. #define NULL            0
  192.  
  193. static  BYTE    *request;
  194. static  BYTE    *reply;
  195. static  WORD    DOSBuffSeg;             // DOS Buffer Segment
  196. static  WORD    DOSBuffDes;             // DOS Buffer Selector
  197. static  BYTE    IsInitialized;          // have we already setup
  198. static  RMREG   rmreg;                  // the real mode register struct
  199.  
  200. void    *NWGetRequestBuffer()
  201. {
  202.         return request;
  203. }
  204.  
  205. void    *NWGetReplyBuffer()
  206. {
  207.         return reply;
  208. }
  209.  
  210. SINT16  NWInitializeXfaceForDPMICalls()
  211. {
  212.         union   REGS    regs;
  213.         LONG    DOSBuffer;
  214.         //
  215.         //  First, get some DOS memory.  That is, memory that exists in
  216.         //  the first meg of RAM.  This is where we'll store the request
  217.         //  and reply buffers for the shell.  This is necessary since it
  218.         //  can't see extended memory.
  219.         //
  220.         regs.x.eax = 0x100;
  221.         regs.w.bx  = DEFPARA;
  222.         int386(DPMI,®s,®s);
  223.         if( regs.x.cflag ) return -1;
  224.         //
  225.         //  Save the DOS Buffer selector and the segment.
  226.         //
  227.         DOSBuffDes = regs.w.dx;
  228.         DOSBuffSeg = regs.w.ax;
  229.         //
  230.         //  Convert the selector to a linear address so we can use it
  231.         //  for copying data to/from the real mode buffer.
  232.         //
  233.         regs.x.eax = 0x6;
  234.         regs.w.bx  = DOSBuffDes;
  235.         int386(DPMI,®s,®s);
  236.         if( regs.x.cflag ) return -1;
  237.         //
  238.         //  Setup our two pointers so they can be used by the protected mode
  239.         //  application to copy data directly into the request and reply bufs
  240.         //
  241.         request = (BYTE *)((regs.w.cx << 16) | regs.w.dx);
  242.         reply   = request + 512;
  243.         //
  244.         //  Show we have initialized successfully and return.
  245.         //
  246.         IsInitialized = TRUE;
  247.         return 0;
  248. }
  249.  
  250. SINT16  NWRequest(BYTE function, void *request, void *reply)
  251. {
  252.         union   REGS    regs;
  253.         struct  SREGS   sregs;
  254.  
  255.         if( !IsInitialized ) return -1;
  256.         //
  257.         //  Get prepared to do the real mode interrupt.  Load the values
  258.         //  we want loaded into the registers when the interrupt is done.
  259.         //
  260.         rmreg.eax = function << 8;
  261.         rmreg.esi = NULL;                       // always at start of segment
  262.         rmreg.edi = 512;                        // always at 512 from start
  263.         rmreg.sp  = rmreg.ss  = NULL;           // use DPMI stack
  264.         rmreg.ds  = rmreg.es  = DOSBuffSeg;     // our real mode segment
  265.         //
  266.         //  Now do the DPMI request to execute a real mode interrupt.
  267.         //
  268.         regs.w.ax  = 0x300;
  269.         regs.h.bh  = 0;
  270.         regs.h.bl  = DOS_INT;
  271.         regs.w.cx  = NULL;
  272.         regs.x.edi = (UINT32)&rmreg;
  273.         segread(&sregs);
  274.         int386x(DPMI,®s,®s,&sregs);
  275.         //
  276.         //  If carry set, DPMI error occurred, so return -1.
  277.         //
  278.         if( regs.x.cflag ) return -1;
  279.         //
  280.         //  Return whatever is in register AL.
  281.         //
  282.         return (SINT16)rmreg.eax & 255;
  283. }
  284.  
  285. SINT16  NWGetConnectionNumber()
  286. {
  287.         return NWRequest( CONNFUNC, 0, 0 );
  288. }
  289.  
  290. SINT16  NWGetConnectionInformation(UINT16 connNum,
  291.                                    BYTE   *objName,
  292.                                    UINT16 *objType,
  293.                                    UINT32 *objID,
  294.                                    BYTE   *loginTm)
  295. {
  296.         NWGCIS      *rq = (NWGCIS *)NWGetRequestBuffer();   // request packet
  297.         NWGCIR      *rp = (NWGCIR *)NWGetReplyBuffer();     // reply packet
  298.         SINT16      cc;                                     // completion code
  299.  
  300.         rq->subfunc = 22;
  301.         rq->connNum = (UINT8)connNum;
  302.         rq->length  = 2;
  303.         rp->length  = 62;
  304.  
  305.         if( (cc = NWRequest(BINDFUNC, rq, rp)) ) return cc;
  306.  
  307.         if( objID )   *objID   = DWordSwap(rp->objID);
  308.         if( objType ) *objType = WordSwap(rp->objType);
  309.         if( objName ) strcpy(objName,rp->objName);
  310.         if( objName ) memmove(loginTm,rp->loginTm,7);
  311.  
  312.         return cc;
  313. }
  314.  
  315. SINT16  NWGetBinderyObjectName(UINT32 objID, BYTE *objName, UINT16 *objType)
  316. {
  317.         NWGBONS     *rq = (NWGBONS *)NWGetRequestBuffer();  // request packet
  318.         NWGBONR     *rp = (NWGBONR *)NWGetReplyBuffer();    // reply packet
  319.         SINT16      cc;                                     // completion code
  320.  
  321.         rq->subfunc = 54;
  322.         rq->objID   = DWordSwap(objID);
  323.         rq->length  = 5;
  324.         rp->length  = 54;
  325.  
  326.         if( (cc = NWRequest(BINDFUNC, rq, rp)) ) return cc;
  327.  
  328.         if( objType ) *objType = WordSwap(rp->objType);
  329.         if( objName ) strcpy(objName,rp->objName);
  330.  
  331.         return cc;
  332. }
  333.  
  334.  
  335. //returns pointer to user's name, or NULL if unavailable
  336. //NOTE: This code isn't really usable until I find a way to first check
  337. //if you are attached and logged into a Novell network.
  338. char *NW_get_user_name()
  339. {
  340.     int     cc;
  341.     static    char objName[48];
  342.     WORD    objType;
  343.     LONG    objID;
  344.     BYTE    loginTm[7];
  345.     int    conn_num;
  346.  
  347.     if( !IsInitialized )
  348.         if( NWInitializeXfaceForDPMICalls() )
  349.             return NULL;
  350.  
  351.     conn_num = NWGetConnectionNumber();
  352.  
  353.     if( NWGetConnectionInformation(conn_num,objName,&objType,&objID,loginTm) )
  354.         return NULL;
  355.  
  356.     return objName;
  357.  
  358. }
  359.  
  360.