home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Server Message Handling
- * server extension version
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
-
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
-
- #include "ctnbio.h" /* for ncb struct */
- #include "ctsxcfg.h"
-
- #define UNKNOWN 9898
-
- #define SMB_CMD ( (((UTEXT far *) srvx_smb) + SMBcmd) )
- #define SMB_CMDX ( (((UTEXT far *) srvx_smb) + SMBcmdx) )
- #define SMB_DATA ( (((UTEXT far *) srvx_smb) + SMBdata) )
- #define SMB_BCT ( (UCOUNT far *) (((UTEXT far *) srvx_smb) + SMBbct) )
- #define SMB_BLKID ( (((UTEXT far *) srvx_smb) + SMBblkid) )
- #define SMB_DATSZ ( (UCOUNT far *) (((UTEXT far *) srvx_smb) + SMBdatsz) )
-
- #define NOT_A_SESN 0xff /* illegal value for session number */
-
- #ifdef DEBUG
- #ifdef LOCAL
- #undef LOCAL
- #define LOCAL /* */
- #endif
- #endif
-
-
-
- typedef struct xncb
- {
- UCOUNT f; /* completed flag, set to 1 by anr */
- NCB n;
- } XNCB;
-
- #ifdef DEBUG
- UTEXT act_ses[256]; /* 1 if session number of active session */
- #endif
-
- LOCAL UTEXT *usr_to_ses; /* xlate ctree user number to netbios ses */
- LOCAL TEXT *usr_to_name; /* xlate to netbios name */
- LOCAL TEXT lastname[16]; /* name rcvd on TST_MSGSIZ message */
- LOCAL UCOUNT msgsiz; /* max message size */
- LOCAL COUNT usrmax; /* max number of users */
-
-
- extern UCOUNT far srvx_wait();
- extern UCOUNT far srvx_init(UTEXT far *, UCOUNT);
- extern UCOUNT far srvx_preinit(UCOUNT);
- extern UCOUNT far farcpybuf(UTEXT far *, UTEXT far *, UCOUNT);
-
- extern SMB far *srvx_smb; /* ptr to smb */
- extern NCB far *srvx_ncb; /* ptr to ncb */
- extern UCOUNT srvx_ses; /* session number (0 if local user) */
- extern UCOUNT srvx_smbmax; /* max len of response smb */
- extern srvx_eventcode; /* reason for wakup */
-
- /* srvx_eventcodes */
-
- #define SXEVinit 1 /* initial state to lock out others */
- #define SXEVlusmb 2 /* got a request from local user */
- #define SXEVrusmb 3 /* got a request from remote user */
- #define SXEVludis 4 /* local user disconnect signal */
- #define SXEVrudis 5 /* remote user disconnect signal */
-
-
- extern COUNT uerr_cod;
- extern TEXT ct_buf[];
-
-
- TEXT *mballc();
-
-
- /*
- * hook up to the network.
- */
-
- TEXT *getmid(sizmsg, maxusr)
- UCOUNT sizmsg;
- COUNT maxusr;
- {
- TEXT *retval;
- UCOUNT e, i, t;
- UTEXT *memcush; /* holds alloc'd mem to be freed */
- /* before term/stay resident */
-
- uerr_cod = 0; /* in case no error */
-
- usrmax = maxusr; /* save (used when cvrting sesn to usrn) */
-
- /* check for netbios installed */
-
- msgsiz = sizmsg; /* local max msg size for start_recv's */
-
- /* see if okay to install */
- if (e = srvx_preinit(SRV_MUXID)) {
- /*
- * err codes: 1-wrong dos ver, 2-no network
- * 3-not a file server, 4-ctree server already installed
- */
- uerr_cod = SSID_ERR;
- return (NULL);
- }
-
- /* get current dir */
- if (get_default_dir())
- return (NULL);
-
- /*
- * allocate
- * retval - return to ctsrvr for message buffer
- * usr_to_ses - logical user to netbios session xlate table
- * usr_to_name - logical user to netbios name table
- * memcush - reserve some space for alloc's after asm lang
- * cuts off ability to get mem from OS (will be
- * freed before returning)
- */
- if ( (usr_to_ses = (UTEXT *) mballc(maxusr + 1, sizeof(UTEXT))) == NULL
- || (usr_to_name = (TEXT *) mballc(maxusr, 16)) == NULL
- || (retval = (UTEXT *) mballc(1, sizmsg + sizeof(UCOUNT))) == NULL
- || (memcush = (UTEXT *) mballc(1, MEM_CUSHION)) == NULL ) {
- uerr_cod = SSPC_ERR;
- return (NULL);
- }
-
- /*
- * init the usernum/sesnum xlate table
- */
-
- memset(usr_to_ses, NOT_A_SESN, maxusr+1);
-
- /* first word of ctsrvr's buffer is hidden and used here to
- * remember which session for last recv
- */
-
- retval += sizeof(UCOUNT);
-
- /* fix up to allow eventual term/stay resident */
-
- srvx_init((UTEXT far *) SRV_SMBNAME, SRV_MUXID);
-
- free(memcush); /* return mem for alloc users */
-
- return (retval);
- }
-
- /*
- * undo the comm link
- */
-
- COUNT ridmid()
- {
- return (0);
- }
-
-
- /*
- * getumsg associates logical user number with session number
- * of last recv'd message. ctsrvr use's 0 to max-1 for logged in
- * users. uses the max-th entry for temporarily remembering a user
- * that, for examp., may not 'log in'.
- */
-
- LONG getumsg(pmsg, usrn, msgptr)
- MESSAGE *pmsg;
- COUNT usrn;
- TEXT *msgptr;
- {
- if (usrn >= 0)
- usr_to_ses[usrn] = (UTEXT) * ( ((UCOUNT *) msgptr) - 1 );
- if (usrn < usrmax)
- cpybuf(&usr_to_name[usrn*16], lastname, 16);
- return ((LONG) usr_to_ses[usrn]);
- }
-
- /*
- * if disconnect, call stop user
- */
-
- stpses(sesnum)
- UCOUNT sesnum;
- {
- FAST COUNT usrn;
-
- for (usrn = 0; usrn < usrmax; usrn++)
- if (sesnum == usr_to_ses[usrn]) {
- usr_to_ses[usrn] = NOT_A_SESN;
- stpusr(usrn);
- break;
- }
- }
-
- /*
- * when new user, stop previous login of same
- */
-
- stpname(name)
- TEXT * name;
- {
- FAST COUNT usrn;
-
- for (usrn = 0; usrn < usrmax; usrn++)
- if (NOT_A_SESN != usr_to_ses[usrn]
- && !strncmp(name, &usr_to_name[usrn*16], 16)) {
- usr_to_ses[usrn] = NOT_A_SESN;
- stpusr(usrn);
- break;
- }
- }
-
-
- COUNT dedusr(msgid)
- LONG msgid;
- {
- return(-1);
- }
-
- /*
- * wait for request from user
- */
-
- COUNT ctrqst(msgadr,pmsg)
- PFAST TEXT **msgadr; /* ptr to message area */
- MESSAGE *pmsg; /* ptr to message header */
- {
- FAST UCOUNT i;
- FAST UCOUNT j;
- FILEPARM *fpm;
-
- do { /* until message for server */
- do { /* until any message */
- srvx_wait();
- switch (srvx_eventcode) {
- case SXEVludis: /* local user disconnected */
- srvx_ses = 0; /* psuedo session 0 */
- case SXEVrudis: /* remote disconnected */
- #ifdef DEBUG
- act_ses[srvx_ses] = 0;
- #endif
- stpses(srvx_ses); /* make sure server informed */
- break;
- case SXEVlusmb: /* message from local user */
- srvx_ses = 0; /* psuedo ses 0 */
- case SXEVrusmb:
- #ifdef DEBUG
- act_ses[srvx_ses] = 1;
- #endif
- break;
- default: /* shouldn't happen */
- ;
- }
-
- } while (srvx_eventcode != SXEVrusmb
- && srvx_eventcode != SXEVlusmb);
-
- /* a receive has completed */
-
- /* save the session number in hidden (to ctsrvr) part of
- * buffer in case ctsrvr wants to associate this session
- * with a user id
- */
-
- *( ((UCOUNT *) (*msgadr)) - 1 ) = srvx_ses;
-
- /* copy message to ctsrvr's buffer */
-
- farcpybuf((UTEXT far *) *msgadr, SMB_DATA, *SMB_DATSZ);
-
- /* copy to ctsrvr's msg header buffer */
-
- cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
-
- /* check for logical hangup
- * (private message from ctamsg)
- */
-
- if (pmsg->mfunc == TST_SMSG) {
- stpses(srvx_ses);
- /* note: SMSG will be echoed to user */
- }
- } while (pmsg->mfunc == TST_SMSG);
-
-
- /* got a message and its not private, however, if its a
- * login (TST_MSGSIZ), then the user's machine name has
- * been appended on the end by ctamsgx. If so, use it to
- * search for duplicate user.
- */
-
- if (pmsg->mfunc == TST_MSGSIZ && pmsg->mdlen >= 16)
- {
- pmsg->mdlen -= 16;
- ((MESSAGE *)(*msgadr))->mdlen -=16;
- /* save name for later association with usrn in getumsg */
- cpybuf(lastname, *msgadr + sizeof(MESSAGE) + pmsg->mdlen, 16);
- stpname(lastname); /* kill any with same name */
- }
-
- /* check for file name conversion to absolute */
-
- if (pmsg->mfunc == FN_OPNFIL || pmsg->mfunc == FN_CREDAT ||
- pmsg->mfunc == FN_CREIDX || pmsg->mfunc == FN_CREMEM) {
- fpm = (FILEPARM *) (((TEXT *) *msgadr) + sizeof(MESSAGE));
- strcpy(ct_buf,fpm->fpnam);
- fulnam(fpm->fpnam,ct_buf,MAX_NAME);
- }
-
- return (NO_ERROR);
- }
-
- /*
- * send data to user
- */
-
- COUNT ctrspn(msgadr, pmsg, sizmsg, usrn)
- PFAST TEXT *msgadr;
- MESSAGE *pmsg;
- UCOUNT sizmsg;
- COUNT usrn;
- {
-
- FAST UCOUNT i;
- UCOUNT e;
-
- if (usrn < 0) { /* signals a call from TST_STPUSR */
- usrn = - (usrn + 1);
- if (usrn < usrmax)
- usr_to_ses[usrn] = NOT_A_SESN; /* user logged out */
- }
-
- cpybuf(msgadr, pmsg, sizeof(MESSAGE));
-
- *SMB_BCT = sizmsg + 3;
- *SMB_DATSZ = sizmsg;
- farcpybuf(SMB_DATA, (UTEXT far *) msgadr, sizmsg);
-
- return (NO_ERROR);
- }
-
- /*
- * check status of user - return YES if session lost
- */
-
- COUNT norspn(usrn)
- COUNT usrn;
- {
- return NO; /* session lost always caught elsewhere */
- }
-
- chkusrtim(usrtim,usrmap,usrtrn)
- LONG *usrtim;
- COUNT *usrmap;
- LONG *usrtrn;
- {
- /* called from login */
- /* note, sessions lost & duplicate sessions caught elsewhere */
- return(NO_ERROR);
- }
-
- /* end of ctsmsgx.c */
-