home *** CD-ROM | disk | FTP | other *** search
- /*
- * System Dependent Server Message Handling
- *
- * OS/2 Lan Manager using named pipes
- *
- * 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 <memory.h>
- #include "ctstdr.h"
- #include "ctoptn.h"
- #include "ctstrc.h"
- #include "cterrc.h"
- #include "ctcomm.h"
-
- #define INCL_SERVERPIPE
- #include "ctpipes.h"
-
- #define NOT_A_SESN 0xff /* illegal value for session number */
-
- #ifdef DEBUG
- #ifdef LOCAL
- #undef LOCAL
- #define LOCAL /* */
- #endif
- #endif
-
- /*
- * PROTOTYPES
- */
- COUNT stops(COUNT);
- COUNT display_users(COUNT);
-
- unsigned pipe_handle;
- static unsigned pipe_open = 0;
- int log_time = 0;
-
- LOCAL COUNT namenum = 0; /* name's number */
- LOCAL UTEXT *usr_to_ses; /* xlate ctree user number to netbios ses */
- LOCAL TEXT *usr_to_name; /* xlate to netbios name */
- /*LOCAL UTEXT act_ses[256]; * 1 if session number of active session */
- LOCAL UCOUNT msgsiz; /* max message size */
- LOCAL UCOUNT usrmax; /* max number of users */
-
- LOCAL UCOUNT lastsess; /* session number rcvd on TST_MSGSIZ message */
- LOCAL TEXT lastname[USR_NAME_LEN+1]; /* name rcvd on TST_MSGSIZ message */
-
- extern COUNT uerr_cod;
- extern TEXT ct_buf[];
- extern COUNT cts_mxfil;
- extern int fl_backgr_proc;
-
-
- TEXT *mballc();
-
-
- /*
- * hook up to the network.
- */
- TEXT *getmid(sizmsg, maxusr)
- UCOUNT sizmsg;
- COUNT maxusr;
- {
- TEXT *retval;
- UCOUNT e, i;
- UCOUNT ctxsize;
-
- uerr_cod = 0; /* in case no error */
-
- usrmax = maxusr; /* save (used when cvrting sesn to usrn) */
-
- strcpy(pipename, ISAM_PIPENAME);
- if (e = makepipe(&pipe_handle, pipename)) {
- uerr_cod = SSID_ERR;
- return (NULL);
- }
- pipe_open = 1;
-
- msgsiz = sizmsg; /* local max msg size for start_recv's */
-
- /* 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
- */
- if ( (usr_to_ses = (UTEXT *) mballc(maxusr + 1, sizeof(UTEXT))) == NULL
- || (usr_to_name = (TEXT *) mballc(maxusr, USR_NAME_LEN + 1)) == NULL
- || (retval = (UTEXT *) mballc(1, sizmsg + sizeof(UCOUNT))) == 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);
-
- set_max_file_handles(cts_mxfil);
-
- display_menu();
-
- return (retval);
- }
-
- /*
- * undo the comm link
- */
- COUNT ridmid()
- {
- VOID far disconnect();
-
- disconnect();
- 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] = lastsess;
- if (usrn < usrmax)
- cpybuf(&usr_to_name[usrn*(USR_NAME_LEN+1)],
- lastname, (USR_NAME_LEN+1));
- return ((LONG) usr_to_ses[usrn]);
- }
-
- /*
- * if disconnect, call stop user
- */
- stpses(COUNT user_num)
- {
- if (usr_to_ses[user_num] != NOT_A_SESN) {
- if (user_num < usrmax) {
- usr_to_ses[user_num] = NOT_A_SESN; /* user logged out */
- stpusr(user_num);
- }
- }
- }
-
- /*
- * when new user, stop previous login of same
- */
- stpname(TEXT *name, COUNT session)
- {
- FAST COUNT usrn;
- int byte_offs;
- char *this_name;
-
- for (usrn = 0; usrn < usrmax; usrn++) {
- byte_offs = (usrn * USR_NAME_LEN) + 1;
- this_name = &usr_to_name[byte_offs];
- if (NOT_A_SESN != usr_to_ses[usrn] &&
- !strcmp(name, this_name) &&
- usr_to_ses[usrn] == session) {
- usr_to_ses[usrn] = NOT_A_SESN;
- stpusr(usrn);
- break;
- }
- }
- }
-
-
- COUNT dedusr(msgid)
- LONG msgid;
- {
- return(-1);
- }
-
- /*
- * wait for request from user
- */
- COUNT ctrqst(PFAST TEXT **msgadr, MESSAGE *pmsg)
- /* msgadr = ptr to message area */
- /* pmsg = ptr to message header */
- {
- FILEPARM *fpm;
- unsigned bytes, namlen;
- char *tp;
-
- set_exec_priority(0);
- for (;;) {
-
- if (!(bytes = readpipe(pipe_handle, (char far*)*msgadr))) {
- return(uerr_cod = SRQS_ERR);
- }
-
- /*
- * an improvment of system is to implement readpipe
- * to use non-blocking mode
- */
-
- if (bytes == sizeof(long)) { /* check for handshake */
- if (*(long*)*msgadr == PIPE_TEST) {
- if (sendlogonreply(pipe_handle))
- return(uerr_cod = SRQS_ERR);
- else
- continue; /* go, wait for next message */
- }
- else
- if (*(long*)*msgadr == PIPE_TERM_SRV) {
- sendlogonreply(pipe_handle);
- stops(0);
- disconnect();
- srvexit("Ctree server terminated normally",0,0);
- }
- }
-
- break;
-
- } /* end for forever */
-
-
- set_exec_priority(1);
- /* 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 ) = usr_to_ses[pmsg->musrn];
-
- /* copy to ctsrvr's msg header buffer */
- cpybuf(pmsg, *msgadr, sizeof(MESSAGE));
-
- /* got a message. if its a
- * login (TST_MSGSIZ), then the user's machine name has
- * been appended on the end by ctamsg. If so, use it to
- * search for duplicate user.
- */
- if (pmsg->mfunc == TST_MSGSIZ ||
- pmsg->mfunc == TST_SPCLOG) {
- namlen = USR_NAME_LEN + sizeof(int) + 1;
- if (pmsg->mdlen >= namlen) {
- pmsg->mdlen -= namlen;
- ((MESSAGE *)(*msgadr))->mdlen -= namlen;
-
- /* save session number for later association with usrn in getumsg */
- cpybuf((char*)&lastsess,
- *msgadr + sizeof(MESSAGE) + pmsg->mdlen,
- sizeof(int));
- *( ((UCOUNT *) (*msgadr)) - 1 ) = lastsess;
- /* save name for later association with usrn in getumsg */
- memset(lastname, '\0', USR_NAME_LEN);
- cpybuf(lastname,
- *msgadr + sizeof(MESSAGE) + pmsg->mdlen + sizeof(int),
- USR_NAME_LEN);
- stpname(lastname, lastsess); /* kill any with same name an session */
-
- }
- }
-
-
- /* 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);
- tp = konvert_drive_to_local(fpm->fpnam);
- if (tp)
- strcpy(fpm->fpnam,tp);
- }
-
- return (NO_ERROR);
- }
-
- /*
- * send data to user
- */
- COUNT ctrspn(msgadr, pmsg, sizmsg, usrn)
- PFAST TEXT *msgadr;
- MESSAGE *pmsg;
- UCOUNT sizmsg;
- COUNT usrn;
- {
- UCOUNT e = 0;
-
- /* copy message header */
- cpybuf(msgadr, pmsg, sizeof(MESSAGE));
-
- 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 */
- }
-
- set_exec_priority(0);
-
- /* send response */
- if (writepipe(pipe_handle, (char far*)msgadr, sizmsg) != sizmsg) {
- /* only display of a message */
- stpses(pmsg->musrn);
- }
-
- if (pmsg->mfunc == TST_MSGSIZ ||
- pmsg->mfunc == TST_STPUSR ||
- pmsg->mfunc == TST_STPSRV ||
- pmsg->mfunc == TST_DEDUSR ||
- pmsg->mfunc == TST_EXISTS ||
- pmsg->mfunc == TST_SPCLOG)
- display_users(0);
-
- return (e ? (uerr_cod = SRSP_ERR) : NO_ERROR);
- }
-
- /*
- * check status of user - return YES if session lost
- */
- COUNT norspn(usrn)
- COUNT usrn;
- {
- return NO; /* session lost always caught elsewhere */
- }
-
-
- /*
- * close all sessions, cancel async commands and remove name from netbios
- */
- VOID far disconnect()
- {
- FAST COUNT usrn;
- UCOUNT i;
- COUNT had = 0;
-
- set_exec_priority(0);
-
- if (pipe_open) {
- i = disconnect_pipe(pipe_handle);
- if (i)
- srvmesg("COULD NOT CLOSE PIPE",i,0);
- pipe_open = 0;
- }
-
- /* close all active sessions */
- for (usrn = 0; usrn < usrmax; usrn++) {
- if (NOT_A_SESN != usr_to_ses[usrn])
- stpses(usrn);
- }
-
- }
-
- chkusrtim(usrtim,usrmap,usrtrn)
- LONG *usrtim;
- COUNT *usrmap;
- LONG *usrtrn;
- {
- /* called from login */
- /* note, sessions lost & duplicate sessions caught elsewhere */
- return(NO_ERROR);
- }
-
- /*
- * dedicated server console routines
- */
-
- display_menu()
- {
- if (fl_backgr_proc)
- return;
- printf("\n\n\n\n\n\n\n\n\n\n");
- printf("Dedicated server active\n");
- }
-
-
- COUNT stops(mode) /* returns != 0 if answer pending */
- COUNT mode; /* either 0 or answer to y/n */
- {
- FAST COUNT usrn;
- COUNT had = 0;
-
- if (!mode) {
- for (usrn = 0; usrn < usrmax; usrn++)
- if (NOT_A_SESN != usr_to_ses[usrn])
- had ++;
- }
-
- had = stpsrv(0L,1,-1);
- ridmid();
- return (0);
- }
-
- COUNT display_users(COUNT mode) /* mode not used */
- {
- FAST COUNT usrn;
- COUNT had = 0;
-
- if (fl_backgr_proc)
- return;
-
- printf("\n");
- for (usrn = 0; usrn < usrmax; usrn++)
- if (NOT_A_SESN != usr_to_ses[usrn]) {
- had ++;
- if (had == 1) {
- printf("Username session\n");
- printf("-------------------- -------\n");
- }
- printf("%-20.20s %5d\n", &usr_to_name[usrn*(USR_NAME_LEN+1)],
- usr_to_ses[usrn]);
- }
- if (!had)
- printf("No");
- else
- printf("%d", had);
- printf(" active users\n");
- return (0);
- }
-
- /* end of ctsmsg.c */
-