home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 4.ddi / NETBIOS / CTSMSGX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  9.0 KB  |  385 lines

  1. /*
  2.  *    System Dependent Server Message Handling
  3.  *    server extension version
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1987, 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *    4006 West Broadway
  15.  *    Columbia, MO 65203
  16.  *
  17.  *
  18.  *    c-tree(R)    Version 4.3
  19.  *            Release C
  20.  *            February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24.  
  25. #include "ctstdr.h"
  26. #include "ctoptn.h"
  27. #include "ctstrc.h"
  28. #include "cterrc.h"
  29. #include "ctcomm.h"
  30.  
  31. #include "ctnbio.h"        /* for ncb struct */
  32. #include "ctsxcfg.h"
  33.  
  34. #define UNKNOWN    9898
  35.  
  36. #define SMB_CMD   (                (((UTEXT far *) srvx_smb) + SMBcmd) )
  37. #define SMB_CMDX  (                (((UTEXT far *) srvx_smb) + SMBcmdx) )
  38. #define SMB_DATA  (                (((UTEXT far *) srvx_smb) + SMBdata) )
  39. #define SMB_BCT   ( (UCOUNT far *) (((UTEXT far *) srvx_smb) + SMBbct) )
  40. #define SMB_BLKID (                (((UTEXT far *) srvx_smb) + SMBblkid) )
  41. #define SMB_DATSZ ( (UCOUNT far *) (((UTEXT far *) srvx_smb) + SMBdatsz) )
  42.  
  43. #define NOT_A_SESN 0xff        /* illegal value for session number */
  44.  
  45. #ifdef DEBUG
  46.  #ifdef LOCAL
  47.   #undef LOCAL
  48.   #define LOCAL /* */
  49.  #endif
  50. #endif
  51.  
  52.  
  53.  
  54. typedef struct xncb
  55. {
  56.     UCOUNT f;        /* completed flag, set to 1 by anr */
  57.     NCB    n;
  58. } XNCB;
  59.  
  60. #ifdef DEBUG
  61.       UTEXT act_ses[256];    /* 1 if session number of active session */
  62. #endif
  63.  
  64. LOCAL UTEXT *usr_to_ses;    /* xlate ctree user number to netbios ses */
  65. LOCAL TEXT *usr_to_name;    /* xlate to netbios name */
  66. LOCAL TEXT lastname[16];    /* name rcvd on TST_MSGSIZ message */
  67. LOCAL UCOUNT msgsiz;        /* max message size */
  68. LOCAL COUNT usrmax;            /* max number of users */
  69.  
  70.  
  71. extern UCOUNT far srvx_wait();
  72. extern UCOUNT far srvx_init(UTEXT far *, UCOUNT);
  73. extern UCOUNT far srvx_preinit(UCOUNT);
  74. extern UCOUNT far farcpybuf(UTEXT far *, UTEXT far *, UCOUNT);
  75.  
  76. extern SMB far *srvx_smb;    /* ptr to smb */
  77. extern NCB far *srvx_ncb;    /* ptr to ncb */
  78. extern UCOUNT srvx_ses;        /* session number (0 if local user) */
  79. extern UCOUNT srvx_smbmax;    /* max len of response smb */
  80. extern srvx_eventcode;        /* reason for wakup */
  81.  
  82. /* srvx_eventcodes */
  83.  
  84. #define SXEVinit  1    /* initial state to lock out others */
  85. #define SXEVlusmb 2    /* got a request from local user */
  86. #define SXEVrusmb 3    /* got a request from remote user */
  87. #define SXEVludis 4    /* local user disconnect signal */
  88. #define SXEVrudis 5    /* remote user disconnect signal */
  89.  
  90.  
  91. extern COUNT uerr_cod;
  92. extern TEXT  ct_buf[];
  93.  
  94.  
  95. TEXT *mballc();
  96.  
  97.  
  98. /*
  99.  * hook up to the network.
  100.  */
  101.  
  102. TEXT *getmid(sizmsg, maxusr)
  103. UCOUNT         sizmsg;
  104. COUNT             maxusr;
  105. {
  106.     TEXT *retval;
  107.     UCOUNT e, i, t;
  108.     UTEXT *memcush;        /* holds alloc'd mem to be freed */
  109.                 /*   before term/stay resident */
  110.  
  111.     uerr_cod = 0;        /* in case no error */
  112.  
  113.     usrmax = maxusr;    /* save (used when cvrting sesn to usrn) */
  114.  
  115.     /* check for netbios installed */
  116.  
  117.     msgsiz = sizmsg;    /* local max msg size for start_recv's */
  118.  
  119.     /* see if okay to install */
  120.     if (e = srvx_preinit(SRV_MUXID)) {
  121.         /*
  122.          * err codes: 1-wrong dos ver, 2-no network
  123.          * 3-not a file server, 4-ctree server already installed
  124.          */
  125.         uerr_cod = SSID_ERR;
  126.         return (NULL);
  127.     }
  128.  
  129.     /* get current dir */
  130.     if (get_default_dir())
  131.         return (NULL);
  132.  
  133.     /*
  134.      * allocate
  135.      *  retval - return to ctsrvr for message buffer
  136.      *  usr_to_ses - logical user to netbios session xlate table
  137.      *  usr_to_name - logical user to netbios name table
  138.      *  memcush - reserve some space for alloc's after asm lang
  139.      *            cuts off ability to get mem from OS (will be
  140.      *            freed before returning)
  141.      */
  142.     if ( (usr_to_ses = (UTEXT *) mballc(maxusr + 1, sizeof(UTEXT))) == NULL
  143.         || (usr_to_name = (TEXT *) mballc(maxusr, 16)) == NULL
  144.         || (retval = (UTEXT *) mballc(1, sizmsg + sizeof(UCOUNT))) == NULL
  145.         || (memcush = (UTEXT *) mballc(1, MEM_CUSHION)) == NULL  ) {
  146.          uerr_cod = SSPC_ERR;
  147.          return (NULL);
  148.      }
  149.  
  150.     /*
  151.      * init the usernum/sesnum xlate table
  152.      */
  153.  
  154.     memset(usr_to_ses, NOT_A_SESN, maxusr+1);
  155.  
  156.     /* first word of ctsrvr's buffer is hidden and used here to
  157.      * remember which session for last recv
  158.      */
  159.  
  160.     retval += sizeof(UCOUNT);
  161.  
  162.     /* fix up to allow eventual term/stay resident */
  163.  
  164.     srvx_init((UTEXT far *) SRV_SMBNAME, SRV_MUXID);
  165.  
  166.     free(memcush);    /* return mem for alloc users */
  167.  
  168.     return (retval);        
  169. }
  170.  
  171. /*
  172.  * undo the comm link
  173.  */
  174.  
  175. COUNT ridmid()
  176. {
  177.     return (0);
  178. }
  179.  
  180.  
  181. /*
  182.  * getumsg associates logical user number with session number
  183.  * of last recv'd message.  ctsrvr use's 0 to max-1 for logged in
  184.  * users.  uses the max-th entry for temporarily remembering a user
  185.  * that, for examp., may not 'log in'.
  186.  */
  187.  
  188. LONG getumsg(pmsg, usrn, msgptr)
  189. MESSAGE     *pmsg;
  190. COUNT           usrn;
  191. TEXT            *msgptr;
  192. {
  193.     if (usrn >= 0)
  194.         usr_to_ses[usrn] = (UTEXT) * ( ((UCOUNT *) msgptr) - 1 );
  195.     if (usrn < usrmax)
  196.         cpybuf(&usr_to_name[usrn*16], lastname, 16);
  197.     return ((LONG) usr_to_ses[usrn]);
  198. }
  199.  
  200. /*
  201.  * if disconnect, call stop user
  202.  */
  203.  
  204. stpses(sesnum)
  205. UCOUNT sesnum;
  206. {
  207.     FAST COUNT usrn;
  208.  
  209.     for (usrn = 0; usrn < usrmax; usrn++)
  210.         if (sesnum == usr_to_ses[usrn]) {
  211.             usr_to_ses[usrn] = NOT_A_SESN;
  212.             stpusr(usrn);
  213.             break;
  214.         }
  215. }
  216.  
  217. /*
  218.  * when new user, stop previous login of same
  219.  */
  220.  
  221. stpname(name)
  222. TEXT * name;
  223. {
  224.     FAST COUNT usrn;
  225.  
  226.     for (usrn = 0; usrn < usrmax; usrn++)
  227.         if (NOT_A_SESN != usr_to_ses[usrn]
  228.                && !strncmp(name, &usr_to_name[usrn*16], 16)) {
  229.             usr_to_ses[usrn] = NOT_A_SESN;
  230.             stpusr(usrn);
  231.             break;
  232.         }
  233. }
  234.  
  235.  
  236. COUNT dedusr(msgid)
  237. LONG         msgid;
  238. {
  239.     return(-1);
  240. }
  241.  
  242. /*
  243.  * wait for request from user
  244.  */
  245.  
  246. COUNT ctrqst(msgadr,pmsg)
  247. PFAST TEXT **msgadr;        /* ptr to message area */
  248. MESSAGE           *pmsg;    /* ptr to message header */
  249. {
  250.     FAST UCOUNT i;
  251.     FAST UCOUNT j;
  252.     FILEPARM   *fpm;
  253.  
  254.     do {    /* until message for server */
  255.         do {    /* until any message */
  256.             srvx_wait();
  257.             switch (srvx_eventcode) {
  258.             case SXEVludis:        /* local user disconnected */
  259.                 srvx_ses = 0;    /* psuedo session 0 */
  260.             case SXEVrudis:        /* remote disconnected */
  261. #ifdef DEBUG
  262.                 act_ses[srvx_ses] = 0;
  263. #endif
  264.                 stpses(srvx_ses); /* make sure server informed */
  265.                 break;
  266.             case SXEVlusmb:        /* message from local user */
  267.                 srvx_ses = 0;    /* psuedo ses 0 */
  268.             case SXEVrusmb:
  269. #ifdef DEBUG
  270.                 act_ses[srvx_ses] = 1;
  271. #endif
  272.                 break;
  273.             default:        /* shouldn't happen */
  274.                 ;
  275.             }
  276.     
  277.         } while (srvx_eventcode != SXEVrusmb
  278.                     && srvx_eventcode != SXEVlusmb);
  279.  
  280.         /* a receive has completed */
  281.  
  282.         /* save the session number in hidden (to ctsrvr) part of
  283.          * buffer in case ctsrvr wants to associate this session
  284.          * with a user id
  285.          */
  286.  
  287.         *( ((UCOUNT *) (*msgadr)) - 1 ) = srvx_ses;
  288.  
  289.         /* copy message to ctsrvr's buffer */
  290.  
  291.         farcpybuf((UTEXT far *) *msgadr, SMB_DATA, *SMB_DATSZ);
  292.  
  293.         /* copy to ctsrvr's msg header buffer */
  294.  
  295.         cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
  296.  
  297.         /* check for logical hangup
  298.          * (private message from ctamsg)
  299.          */
  300.  
  301.         if (pmsg->mfunc == TST_SMSG) {
  302.             stpses(srvx_ses);
  303.             /* note: SMSG will be echoed to user */
  304.         }
  305.     } while (pmsg->mfunc == TST_SMSG);
  306.  
  307.  
  308.     /* got a message and its not private, however, if its a
  309.      * login (TST_MSGSIZ), then the user's machine name has
  310.      * been appended on the end by ctamsgx.  If so, use it to
  311.      * search for duplicate user.
  312.      */
  313.  
  314.     if (pmsg->mfunc == TST_MSGSIZ && pmsg->mdlen >= 16)
  315.     {
  316.         pmsg->mdlen -= 16;
  317.         ((MESSAGE *)(*msgadr))->mdlen -=16;
  318.         /* save name for later association with usrn in getumsg */
  319.         cpybuf(lastname, *msgadr + sizeof(MESSAGE) + pmsg->mdlen, 16);
  320.         stpname(lastname);    /* kill any with same name */
  321.     }
  322.  
  323.     /* check for file name conversion to absolute */
  324.  
  325.     if (pmsg->mfunc == FN_OPNFIL || pmsg->mfunc == FN_CREDAT ||
  326.         pmsg->mfunc == FN_CREIDX || pmsg->mfunc == FN_CREMEM) {
  327.         fpm = (FILEPARM *) (((TEXT *) *msgadr) + sizeof(MESSAGE));
  328.         strcpy(ct_buf,fpm->fpnam);
  329.         fulnam(fpm->fpnam,ct_buf,MAX_NAME);
  330.     }
  331.  
  332.     return (NO_ERROR);
  333. }
  334.  
  335. /*
  336.  * send data to user
  337.  */
  338.  
  339. COUNT ctrspn(msgadr, pmsg, sizmsg, usrn)
  340. PFAST TEXT  *msgadr;
  341. MESSAGE                 *pmsg;
  342. UCOUNT               sizmsg;
  343. COUNT                   usrn;
  344. {
  345.  
  346.     FAST UCOUNT i;
  347.     UCOUNT e;
  348.  
  349.     if (usrn < 0) {         /* signals a call from TST_STPUSR */
  350.         usrn = - (usrn + 1);
  351.         if (usrn < usrmax)
  352.             usr_to_ses[usrn] = NOT_A_SESN;    /* user logged out */
  353.     }
  354.  
  355.     cpybuf(msgadr, pmsg, sizeof(MESSAGE));
  356.  
  357.     *SMB_BCT = sizmsg + 3;
  358.     *SMB_DATSZ = sizmsg;
  359.     farcpybuf(SMB_DATA, (UTEXT far *) msgadr, sizmsg);
  360.  
  361.     return (NO_ERROR);
  362. }
  363.  
  364. /*
  365.  * check status of user - return YES if session lost
  366.  */
  367.  
  368. COUNT norspn(usrn)
  369. COUNT         usrn;
  370. {
  371.     return NO;    /* session lost always caught elsewhere */
  372. }
  373.  
  374. chkusrtim(usrtim,usrmap,usrtrn)
  375. LONG     *usrtim;
  376. COUNT        *usrmap;
  377. LONG               *usrtrn;
  378. {
  379.     /* called from login */
  380.     /* note, sessions lost & duplicate sessions caught elsewhere */
  381.     return(NO_ERROR);
  382. }
  383.  
  384. /* end of ctsmsgx.c */
  385.