home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- * *
- * Program Name: jsubmit and jserver *
- * *
- * Filename: environ.c *
- * *
- * Date Created: 3/2/89 *
- * *
- * Version: *
- * *
- * Programmers: Gregory J. Peto *
- * *
- * Files used: *
- * *
- * Date Modified: *
- * *
- * Modifications: *
- * *
- * Comments: *
- * This file contains routines to save a copy of the workstation *
- * environment in a JOBFILE structure. By keeping only one version *
- * of the routines to get and set workstation environment they are *
- * easier to maintain and use. *
- * *
- ****************************************************************************/
-
- /* functions in this file: */
- #include "genjob.h"
-
- /* constants definitions */
- /* global variables and data types */
- /* module specific varables and data types */
- /* macro definitions */
-
- /*****************************************************************************/
-
- GetJobEnviron(envp,jobFile)
- /* Descrip:
- This routine fills the jobFile structure with all the local
- environment information so it can be rebuilt later.
- Avoids using global variables directly so that more than one
- environment can be maintained by the same program.
- Algorithm:
- BUGS:
- It should verify users passwords to make sure typed correctly
- and give chance if not typed correctly. Perhaps make login
- function call to verify.
- */
- /* Input: */
- char *envp[]; /* optional environment array from main() */
- /* Output: */
- JOBFILE *jobFile; /* JOBFILE to be filled with local environment */
-
- { /* GetJobEnviron // */
- int drive; /* drive number checking */
- WORD conID; /* connection ID for drive (1-8) */
- int numServers; /* number of server connection ID's found */
- WORD conNumber;
- int objectType;
- long objectID;
- BYTE loginTime[7];
- BYTE dirHandle; /* NOVELL directory handle on server */
- BYTE status; /* drive status flags */
- int j,k;
- char serverName[MAX_FSERVER_NAME];
- int ch;
- extern BYTE GetCurrentDrive();
- /*--------------------------------------------------main body */
- jobFile->curDrive = GetCurrentDrive();
-
- GetSearchDriveVector( jobFile->svector );
- /* GetDriveInformation starts with A=0 (is 0 indexed) so the next drive
- is number of total local drives */
- drive = GetNumberOfLocalDrives();
- for(;drive < MAX_LOGICAL_DRIVES; ++drive)
- {
- if ((status = GetDriveinformation( drive, &conID, &dirHandle )) == 0)
- continue; /* do next, this drive not mapped */
-
- GetFullPath( drive, jobFile->mapInfo[drive].fullPath);
- StripFileServerFromPath(jobFile->mapInfo[drive].fullPath,serverName);
-
- if (status == TEMP_DIR_HANDLE) /* temporary drive */
- jobFile->mapInfo[drive].isTemp = TRUE;
-
- /* mark search vector as not mapped, then look for it */
- jobFile->mapInfo[drive].searchVector = NOT_SEARCH_MAPPED;
- for (k=0; jobFile->svector[k] NOT= NOT_SEARCH_MAPPED; k++)
- if (jobFile->svector[k] == drive)
- jobFile->mapInfo[drive].searchVector = k+1; /* MapDrive starts at 1 */
- }
-
-
- /* if multiple attachments, ask for password-figure out which user name */
- /* and password belong to which file server attachment */
- for (conID = 1,numServers = 0;
- conID <= MAX_SERVER_ATTACHES;
- ++conID)
- {
- if (conID NOT= jobServerConID AND IsConnectionIDInUse(conID))
- {
- GetFileServerName(conID,serverName);
- SetPreferredConnectionID(conID);
- conNumber = GetConnectionNumber();
- if (GetConnectionInformation(conNumber,jobFile->serverInfo[
- numServers].userName,&objectType,&objectID,loginTime))
- {
- printf("Internal error: Get connection Information for \n server %s failed,aborting\n",
- serverName);
- exit(1);
- }
- if (objectType NOT= OT_USER)
- {
- printf("Logged in as other than type user on server %s, aborting\n",
- serverName);
- exit(1);
- }
-
- printf("\nEnter your password as %s on server %s: ",
- jobFile->serverInfo[numServers].userName,serverName);
- for (j = 0;
- (ch = getch()) NOT= 0x0D AND j < MAX_PASSWORD AND
- ch NOT= EOF;
- ++j)
- jobFile->serverInfo[numServers].password[j] = toupper(ch);
- jobFile->serverInfo[numServers].password[j] = '\0';
- printf("\n");
-
- ++numServers;
- } /* end of if conID */
- } /* end of for conID */
-
- jobFile->numServers = numServers;
-
- if (envp == NULL)
- /* array or environment entries was not passed in */
- jobFile->numEntries = 0;
- else
- {
- /* put task environment variables in jobfile structure */
- for (j = 0; *envp AND j < MAX_ENV_ENTRIES; ++j, ++envp)
- {
- if (strlen(*envp) > ENV_ENTRY_SIZE)
- {
- printf("Environment variable %s \n too long, jub submit failed.\n",
- *envp);
- exit(1);
- }
- strcpy(jobFile->envEntries[j],*envp);
- }
-
- if (j == MAX_ENV_ENTRIES)
- { /* dropped out for for loop before finished envp */
- printf("Too many environment variables to pass to job, submit failed.\n");
- exit(1);
- }
- jobFile->numEntries = j;
- }
- } /* end of GetJobEnviron */
-
- /********************************************************************/
-
- BOOLEAN SetJobEnviron(jobFile,serverConID)
- /* Descrip:
- This function uses the information contained in the jobFile
- structure to reconstruct the job's environment.
- Returns TRUE if successful, else FALSE.
- Algorithm: //
- Setup file servers for job.
- Search drives must be mapped in same order as pulled off, so
- map them first.
- Map remaining drives
- Set current drive
- */
- /* Input: */
- JOBFILE *jobFile;
- BYTE serverConID; /* ID of server with queue, dont do log in */
-
- /* Output: */
-
- { /* SetJobEnviron // */
- reg int i;
- /*--------------------------------------------------main body */
- for (i = 0; i < jobFile->numServers; ++i)
- if (jobFile->serverInfo[i].serverName[0])
- if (SetupServer(&jobFile->serverInfo[i],serverConID) == FALSE)
- return(FALSE);
-
- printf("loop on MapJobSDrive commented out\n");
- #if 0
- for (i = 0; jobFile->svector[i] NOT= NOT_SEARCH_MAPPED; ++i)
- if (MapJobSDrive(jobFile->svector[i],
- &jobFile->mapInfo[jobFile->svector[i]]) == FALSE)
- return(FALSE);
- #endif
-
- for (i = 0; i < MAX_LOGICAL_DRIVES; ++i)
- if (jobFile->mapInfo[i].fullPath[0])
- /* path not empty, assume was mapped */
- if (MapJobDrive(i,&jobFile->mapInfo[i]) == FALSE)
- return(FALSE);
-
- if (SetCurrentDrive(jobFile->curDrive) == FALSE)
- {
- printf("Internal error, unable to set default drive for job.\n");
- return(FALSE);
- }
- return(TRUE);
- } /* end of SetJobEnviron */
-
- /********************************************************************/
-
- BOOLEAN SetupServer(serverInfo,serverConID)
- /* Descrip:
- This function attaches to the server in serverInfo structure with
- rights if necessary.
- Algorithm: //
- */
- /* Input: */
- SERVERINFO *serverInfo; /* server information to be restored */
- BYTE serverConID; /* ID of server with queue, dont do log in */
-
- { /* // */
- int ccode;
- WORD conID; /* connection ID to server */
- /*--------------------------------------------------main body */
- if (GetConnectionID(serverInfo->serverName,&conID) == SUCCESSFUL)
- if (conID == serverConID)
- /* this is server with job queue, dont login again */
- return(TRUE);
-
- if (ccode = AttachToFileServer(serverInfo->serverName,&conID))
- {
- switch(ccode)
- {
- case ALREADY_ATTACHED_TO_SERVER:
- /* this should not happen if detach from servers to make
- slots available */
- goto server_OK;
- case NO_FREE_CONNECTION_SLOTS:
- printf("No more available connections on server %s.\n",
- serverInfo->serverName );
- break;
- case NO_MORE_SERVER_SLOTS:
- /* this should not happen if queue server detached from servers */
- printf("Job Server is already attached to max. of 8 servers.\n");
- break;
- case UNKNOWN_FILE_SERVER:
- case NO_RESPONSE_FROM_SERVER:
- printf("File server \"%s\" is not available.\n",
- serverInfo->serverName );
- break;
- default:
- printf("Unable to attach to server \"%s\".\n",serverInfo->serverName );
- break;
- }
- return(FALSE);
- }
-
- server_OK:
- SetPreferredConnectionID(conID);
- if (ccode = LoginToFileServer(serverInfo->userName,OT_USER,
- serverInfo->password))
- {
- printf("Job server unable to login as %s on server %s.\n",
- serverInfo->userName,serverInfo->serverName);
- return(FALSE);
- }
- return(TRUE);
- } /* end of SetupServer */
-
- /********************************************************************/
-
- BOOLEAN MapJobSDrive(driveNum,mapInfo)
- /* Descrip:
- This function remaps the job search drive.
- Returns TRUE if successful, else FALSE.
- Algorithm: //
- */
- /* Input: */
- int driveNum; /* dirve number from search vector */
- MAPINFO *mapInfo; /* corresponding drive map information */
-
- { /* // */
- char serverName[MAX_FSERVER_NAME];
- char *volPath; /* path for drive starting with volume name */
- WORD conID;
- int ccode;
- BYTE newDirectoryHandle;
- BYTE effectiveRightsMask;
- /*--------------------------------------------------main body */
- /* must strip off server name or will fail */
- volPath = StripFileServerFromPath(mapInfo->fullPath,serverName);
- if (GetConnectionID(serverName,&conID))
- {
- printf("Internal error: could not get connection ID to %s.\n",
- serverName);
- return(FALSE);
- }
-
- /* attempt to map drive, no relative directory handle specified */
- if (ccode = MapDrive(conID,0,volPath,DRIVE_INSERT,
- mapInfo->searchVector,'A' + driveNum,
- &newDirectoryHandle,&effectiveRightsMask))
- {
- printf("Unable to map search drive %c to path:\n\"%s\".\n",
- 'A' + driveNum,mapInfo->fullPath);
- return(FALSE);
- }
- return(TRUE);
- } /* end of MapJobSDrive */
-
- /********************************************************************/
-
- BOOLEAN MapJobDrive(driveNum,mapInfo)
- /* Descrip:
- This function remaps the job drive specified.
- Returns TRUE if successful, else FALSE.
- Algorithm: //
- */
- /* Input: */
- int driveNum; /* drive number from search vector */
- MAPINFO *mapInfo; /* corresponding drive map information */
-
- { /* // */
- char serverName[MAX_FSERVER_NAME];
- char *volPath; /* path for drive starting with volume name */
- WORD conID;
- int ccode;
- BYTE newDirectoryHandle;
- BYTE effectiveRightsMask;
- /*--------------------------------------------------main body */
- volPath = StripFileServerFromPath(mapInfo->fullPath,serverName);
- if (GetConnectionID(serverName,&conID))
- {
- printf("Internal error: could not get connection ID to %s.\n",
- serverName);
- return(FALSE);
- }
- SetPreferredConnectionID(conID);
-
- /* attempt to map drive, no relative directory handle specified */
- if (mapInfo->isTemp)
- {
- if (ccode = AllocTemporaryDirectoryHandle(conID,0,volPath,
- 'A' + driveNum,&newDirectoryHandle,&effectiveRightsMask))
- {
- printf("Unable to map temporary drive %c to path:\n\"%s\".\n",
- 'A' + driveNum,mapInfo->fullPath);
- return(FALSE);
- }
- } else if (ccode = AllocPermanentDirectoryHandle(0,volPath,
- 'A' + driveNum,&newDirectoryHandle,&effectiveRightsMask))
- {
- printf("Unable to map permanent drive %c to path:\n\"%s\".\n",
- 'A' + driveNum,mapInfo->fullPath);
- return(FALSE);
- }
-
- return(TRUE);
- } /* end of MapJobDrive */
-
- /********************************************************************/
-
- BYTE GetCurrentDrive()
- /* Descrip:
- Algorithm: //
- */
- /* Input: */
- /* Output: */
-
- { /* GetCurrentDrive // */
- union REGS inregs, outregs;
- /*--------------------------------------------------main body */
- inregs.h.ah = 0x19; /* DOS get current drive */
- intdos(&inregs, &outregs );
- return(outregs.h.al );
- } /* end of GetCurrentDrive */
-
- /********************************************************************/
-
- BOOLEAN SetCurrentDrive(drive)
- /* Descrip:
- Algorithm: //
- */
- /* Input: */
- BYTE drive;
-
- { /* SetCurrentDrive // */
- union REGS inregs, outregs;
- /*--------------------------------------------------main body */
- inregs.h.ah = 0x0E; /* DOS select drive */
- inregs.h.dl = drive;
- intdos(&inregs,&outregs);
- if (outregs.x.cflag)
- return(FALSE);
- return(TRUE);
- } /* end of SetCurrentDrive */
-
- /********************************************************************/