home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / remote / jservr / environ.c next >
Encoding:
C/C++ Source or Header  |  1990-01-15  |  15.1 KB  |  400 lines

  1. /***************************************************************************** 
  2.  *                                                                           *       
  3.  * Program Name: jsubmit and jserver                                         *  
  4.  *                                                                           *
  5.  * Filename:   environ.c                                                      *
  6.  *                                                                           *       
  7.  * Date Created: 3/2/89                                                      *
  8.  *                                                                           * 
  9.  * Version:                                                                   *
  10.  *                                                                           * 
  11.  * Programmers:  Gregory J. Peto                                             *
  12.  *                                                                           *  
  13.  * Files used:                                                               *
  14.  *                                                                           *   
  15.  * Date Modified:                                                            *
  16.  *                                                                           *
  17.  * Modifications:                                                            *
  18.  *                                                                           *   
  19.  * Comments:                                                                  *
  20.  *       This file contains routines to save a copy of the workstation        *
  21.  *       environment in a JOBFILE structure.  By keeping only one version     *
  22.  *       of the routines to get and set workstation environment they are      *
  23.  *       easier to maintain and use.                                          *
  24.  *                                                                           *
  25.  ****************************************************************************/ 
  26.  
  27. /* functions in this file: */ 
  28. #include "genjob.h" 
  29.  
  30. /* constants definitions */ 
  31. /* global variables and data types */ 
  32. /* module specific varables and data types */ 
  33. /* macro definitions */ 
  34.  
  35. /*****************************************************************************/ 
  36.  
  37. GetJobEnviron(envp,jobFile) 
  38.  /* Descrip: 
  39.          This routine fills the jobFile structure with all the local 
  40.              environment information so it can be rebuilt later. 
  41.          Avoids using global variables directly so that more than one 
  42.              environment can be maintained by the same program. 
  43.     Algorithm: 
  44.     BUGS: 
  45.          It should verify users passwords to make sure typed correctly 
  46.              and give chance if not typed correctly.  Perhaps make login 
  47.              function call to verify. 
  48.  */ 
  49.  /* Input: */ 
  50. char *envp[];                     /* optional environment array from main() */ 
  51.  /* Output: */ 
  52. JOBFILE      *jobFile;        /* JOBFILE to be filled with local environment */ 
  53.   
  54. {        /* GetJobEnviron // */ 
  55.  int     drive;           /* drive number checking */ 
  56.  WORD        conID;           /* connection ID for drive (1-8) */ 
  57.  int     numServers;      /* number of server connection ID's found */ 
  58.  WORD        conNumber; 
  59.  int     objectType; 
  60.  long        objectID; 
  61.  BYTE        loginTime[7]; 
  62.  BYTE        dirHandle;       /* NOVELL directory handle on server */ 
  63.  BYTE        status;          /* drive status flags */ 
  64.  int     j,k; 
  65.  char        serverName[MAX_FSERVER_NAME]; 
  66.  int     ch; 
  67.  extern BYTE GetCurrentDrive(); 
  68.  /*--------------------------------------------------main body */ 
  69.  jobFile->curDrive   = GetCurrentDrive(); 
  70.  
  71.  GetSearchDriveVector( jobFile->svector ); 
  72.  /* GetDriveInformation starts with A=0 (is 0 indexed) so the next drive 
  73.     is number of total local drives */ 
  74.  drive = GetNumberOfLocalDrives(); 
  75.  for(;drive < MAX_LOGICAL_DRIVES; ++drive) 
  76.  { 
  77.     if ((status = GetDriveinformation( drive, &conID, &dirHandle )) == 0) 
  78.          continue;   /* do next, this drive not mapped */ 
  79.      
  80.     GetFullPath( drive, jobFile->mapInfo[drive].fullPath); 
  81.     StripFileServerFromPath(jobFile->mapInfo[drive].fullPath,serverName); 
  82.      
  83.     if (status == TEMP_DIR_HANDLE)            /* temporary drive */ 
  84.          jobFile->mapInfo[drive].isTemp = TRUE; 
  85.  
  86.     /* mark search vector as not mapped, then look for it */ 
  87.     jobFile->mapInfo[drive].searchVector = NOT_SEARCH_MAPPED; 
  88.     for (k=0; jobFile->svector[k] NOT= NOT_SEARCH_MAPPED; k++) 
  89.          if (jobFile->svector[k] == drive) 
  90.              jobFile->mapInfo[drive].searchVector = k+1; /* MapDrive starts at 1 */ 
  91.  } 
  92.   
  93.  
  94.  /* if multiple attachments, ask for password-figure out which user name */ 
  95.  /* and password belong to which file server attachment */ 
  96.  for (conID = 1,numServers = 0; 
  97.       conID <= MAX_SERVER_ATTACHES; 
  98.       ++conID) 
  99.  { 
  100.     if (conID NOT= jobServerConID AND IsConnectionIDInUse(conID)) 
  101.     { 
  102.          GetFileServerName(conID,serverName); 
  103.          SetPreferredConnectionID(conID); 
  104.          conNumber   = GetConnectionNumber(); 
  105.          if (GetConnectionInformation(conNumber,jobFile->serverInfo[ 
  106.                  numServers].userName,&objectType,&objectID,loginTime)) 
  107.          { 
  108.              printf("Internal error: Get connection Information for \n   server %s failed,aborting\n", 
  109.                  serverName); 
  110.              exit(1); 
  111.          } 
  112.          if (objectType NOT= OT_USER) 
  113.          { 
  114.              printf("Logged in as other than type user on server %s, aborting\n", 
  115.                  serverName); 
  116.              exit(1); 
  117.          } 
  118.  
  119.          printf("\nEnter your password as %s on server %s: ", 
  120.              jobFile->serverInfo[numServers].userName,serverName); 
  121.          for (j = 0; 
  122.                (ch = getch()) NOT= 0x0D AND j < MAX_PASSWORD AND 
  123.                      ch NOT= EOF; 
  124.                ++j) 
  125.              jobFile->serverInfo[numServers].password[j] = toupper(ch); 
  126.          jobFile->serverInfo[numServers].password[j] = '\0'; 
  127.          printf("\n"); 
  128.  
  129.          ++numServers; 
  130.     }   /* end of if conID */ 
  131.  }   /* end of for conID */ 
  132.  
  133.  jobFile->numServers = numServers; 
  134.  
  135.  if (envp == NULL) 
  136.     /* array or environment entries was not passed in */ 
  137.     jobFile->numEntries   = 0; 
  138.  else 
  139.  { 
  140.     /* put task environment variables in jobfile structure */ 
  141.     for (j = 0; *envp AND j < MAX_ENV_ENTRIES; ++j, ++envp) 
  142.     { 
  143.          if (strlen(*envp) > ENV_ENTRY_SIZE) 
  144.          { 
  145.              printf("Environment variable %s \n   too long, jub submit failed.\n", 
  146.                  *envp); 
  147.              exit(1); 
  148.          } 
  149.          strcpy(jobFile->envEntries[j],*envp); 
  150.     } 
  151.  
  152.     if (j == MAX_ENV_ENTRIES) 
  153.     {    /* dropped out for for loop before finished envp */ 
  154.          printf("Too many environment variables to pass to job, submit failed.\n"); 
  155.          exit(1); 
  156.     } 
  157.     jobFile->numEntries   = j; 
  158.  } 
  159. }        /* end of GetJobEnviron */ 
  160.   
  161. /********************************************************************/ 
  162.  
  163. BOOLEAN SetJobEnviron(jobFile,serverConID) 
  164.  /* Descrip: 
  165.          This function uses the information contained in the jobFile 
  166.              structure to reconstruct the job's environment. 
  167.          Returns TRUE if successful, else FALSE. 
  168.     Algorithm:   // 
  169.          Setup file servers for job. 
  170.          Search drives must be mapped in same order as pulled off, so 
  171.              map them first. 
  172.          Map remaining drives 
  173.          Set current drive 
  174.  */ 
  175.  /* Input: */ 
  176. JOBFILE      *jobFile; 
  177. BYTE         serverConID;     /* ID of server with queue, dont do log in */ 
  178.  
  179.  /* Output: */ 
  180.   
  181. {        /* SetJobEnviron // */ 
  182.  reg int i; 
  183.  /*--------------------------------------------------main body */ 
  184.  for (i = 0; i < jobFile->numServers; ++i) 
  185.     if (jobFile->serverInfo[i].serverName[0]) 
  186.          if (SetupServer(&jobFile->serverInfo[i],serverConID) == FALSE) 
  187.              return(FALSE); 
  188.  
  189. printf("loop on MapJobSDrive commented out\n"); 
  190. #if 0 
  191.  for (i = 0; jobFile->svector[i] NOT= NOT_SEARCH_MAPPED; ++i) 
  192.     if (MapJobSDrive(jobFile->svector[i], 
  193.              &jobFile->mapInfo[jobFile->svector[i]]) == FALSE) 
  194.          return(FALSE); 
  195. #endif 
  196.  
  197.  for (i = 0; i < MAX_LOGICAL_DRIVES; ++i) 
  198.     if (jobFile->mapInfo[i].fullPath[0]) 
  199.          /* path not empty, assume was mapped */ 
  200.          if (MapJobDrive(i,&jobFile->mapInfo[i]) == FALSE) 
  201.              return(FALSE); 
  202.   
  203.  if (SetCurrentDrive(jobFile->curDrive) == FALSE) 
  204.  { 
  205.     printf("Internal error, unable to set default drive for job.\n"); 
  206.     return(FALSE); 
  207.  } 
  208.  return(TRUE); 
  209. }        /* end of SetJobEnviron */ 
  210.   
  211. /********************************************************************/ 
  212.  
  213. BOOLEAN SetupServer(serverInfo,serverConID) 
  214.  /* Descrip: 
  215.          This function attaches to the server in serverInfo structure with 
  216.              rights if necessary. 
  217.     Algorithm:   // 
  218.  */ 
  219.  /* Input: */ 
  220. SERVERINFO   *serverInfo;     /* server information to be restored */ 
  221. BYTE         serverConID;     /* ID of server with queue, dont do log in */ 
  222.   
  223. {        /* // */ 
  224.  int     ccode; 
  225.  WORD        conID;               /* connection ID to server */ 
  226.  /*--------------------------------------------------main body */ 
  227.  if (GetConnectionID(serverInfo->serverName,&conID) == SUCCESSFUL) 
  228.     if (conID == serverConID) 
  229.          /* this is server with job queue, dont login again */ 
  230.          return(TRUE); 
  231.  
  232.  if (ccode = AttachToFileServer(serverInfo->serverName,&conID)) 
  233.  { 
  234.     switch(ccode) 
  235.     { 
  236.          case ALREADY_ATTACHED_TO_SERVER: 
  237.              /* this should not happen if detach from servers to make 
  238.                  slots available */ 
  239.              goto server_OK; 
  240.          case NO_FREE_CONNECTION_SLOTS: 
  241.              printf("No more available connections on server %s.\n", 
  242.                  serverInfo->serverName ); 
  243.              break; 
  244.          case NO_MORE_SERVER_SLOTS: 
  245.              /* this should not happen if queue server detached from servers */ 
  246.              printf("Job Server is already attached to max. of 8 servers.\n"); 
  247.              break; 
  248.          case UNKNOWN_FILE_SERVER: 
  249.          case NO_RESPONSE_FROM_SERVER: 
  250.              printf("File server \"%s\" is not available.\n", 
  251.                  serverInfo->serverName ); 
  252.              break; 
  253.          default: 
  254.              printf("Unable to attach to server \"%s\".\n",serverInfo->serverName ); 
  255.              break; 
  256.     } 
  257.     return(FALSE); 
  258.  } 
  259.  
  260. server_OK: 
  261.  SetPreferredConnectionID(conID); 
  262.  if (ccode = LoginToFileServer(serverInfo->userName,OT_USER, 
  263.                      serverInfo->password)) 
  264.  { 
  265.     printf("Job server unable to login as %s on server %s.\n", 
  266.          serverInfo->userName,serverInfo->serverName); 
  267.     return(FALSE); 
  268.  } 
  269.  return(TRUE); 
  270. }        /* end of SetupServer */ 
  271.   
  272. /********************************************************************/ 
  273.  
  274. BOOLEAN MapJobSDrive(driveNum,mapInfo) 
  275.  /* Descrip: 
  276.          This function remaps the job search drive. 
  277.          Returns TRUE if successful, else FALSE. 
  278.     Algorithm:   // 
  279.  */ 
  280.  /* Input: */ 
  281. int      driveNum;        /* dirve number from search vector */ 
  282. MAPINFO  *mapInfo;        /* corresponding drive map information */ 
  283.   
  284. {        /* // */ 
  285.  char        serverName[MAX_FSERVER_NAME]; 
  286.  char        *volPath;            /* path for drive starting with volume name */ 
  287.  WORD        conID; 
  288.  int     ccode; 
  289.  BYTE        newDirectoryHandle; 
  290.  BYTE        effectiveRightsMask; 
  291.  /*--------------------------------------------------main body */ 
  292.  /* must strip off server name or will fail */ 
  293.  volPath = StripFileServerFromPath(mapInfo->fullPath,serverName); 
  294.  if (GetConnectionID(serverName,&conID)) 
  295.  { 
  296.     printf("Internal error: could not get connection ID to %s.\n", 
  297.          serverName); 
  298.     return(FALSE); 
  299.  } 
  300.  
  301.  /* attempt to map drive, no relative directory handle specified */ 
  302.  if (ccode = MapDrive(conID,0,volPath,DRIVE_INSERT, 
  303.                      mapInfo->searchVector,'A' + driveNum, 
  304.                      &newDirectoryHandle,&effectiveRightsMask)) 
  305.  { 
  306.     printf("Unable to map search drive %c to path:\n\"%s\".\n", 
  307.          'A' + driveNum,mapInfo->fullPath); 
  308.     return(FALSE); 
  309.  } 
  310.  return(TRUE); 
  311. }        /* end of MapJobSDrive */ 
  312.   
  313. /********************************************************************/ 
  314.  
  315. BOOLEAN MapJobDrive(driveNum,mapInfo) 
  316.  /* Descrip: 
  317.          This function remaps the job drive specified. 
  318.          Returns TRUE if successful, else FALSE. 
  319.     Algorithm:   // 
  320.  */ 
  321.  /* Input: */ 
  322. int      driveNum;        /* drive number from search vector */ 
  323. MAPINFO  *mapInfo;        /* corresponding drive map information */ 
  324.   
  325. {        /* // */ 
  326.  char        serverName[MAX_FSERVER_NAME]; 
  327.  char        *volPath;            /* path for drive starting with volume name */ 
  328.  WORD        conID; 
  329.  int     ccode; 
  330.  BYTE        newDirectoryHandle; 
  331.  BYTE        effectiveRightsMask; 
  332.  /*--------------------------------------------------main body */ 
  333.  volPath = StripFileServerFromPath(mapInfo->fullPath,serverName); 
  334.  if (GetConnectionID(serverName,&conID)) 
  335.  { 
  336.     printf("Internal error: could not get connection ID to %s.\n", 
  337.          serverName); 
  338.     return(FALSE); 
  339.  } 
  340.  SetPreferredConnectionID(conID); 
  341.  
  342.  /* attempt to map drive, no relative directory handle specified */ 
  343.  if (mapInfo->isTemp) 
  344.  { 
  345.     if (ccode = AllocTemporaryDirectoryHandle(conID,0,volPath, 
  346.                           'A' + driveNum,&newDirectoryHandle,&effectiveRightsMask)) 
  347.     { 
  348.          printf("Unable to map temporary drive %c to path:\n\"%s\".\n", 
  349.              'A' + driveNum,mapInfo->fullPath); 
  350.          return(FALSE); 
  351.     } 
  352.  } else if (ccode = AllocPermanentDirectoryHandle(0,volPath, 
  353.                           'A' + driveNum,&newDirectoryHandle,&effectiveRightsMask)) 
  354.     { 
  355.          printf("Unable to map permanent drive %c to path:\n\"%s\".\n", 
  356.              'A' + driveNum,mapInfo->fullPath); 
  357.          return(FALSE); 
  358.     } 
  359.  
  360.  return(TRUE); 
  361. }        /* end of MapJobDrive */ 
  362.   
  363. /********************************************************************/ 
  364.  
  365. BYTE GetCurrentDrive() 
  366.  /* Descrip: 
  367.     Algorithm:   // 
  368.  */ 
  369.  /* Input: */ 
  370.  /* Output: */ 
  371.   
  372. {        /* GetCurrentDrive // */ 
  373.  union REGS inregs, outregs; 
  374.  /*--------------------------------------------------main body */ 
  375.  inregs.h.ah = 0x19;          /* DOS get current drive */ 
  376.  intdos(&inregs, &outregs ); 
  377.  return(outregs.h.al ); 
  378. }        /* end of GetCurrentDrive */ 
  379.   
  380. /********************************************************************/ 
  381.  
  382. BOOLEAN SetCurrentDrive(drive) 
  383.  /* Descrip: 
  384.     Algorithm:   // 
  385.  */ 
  386.  /* Input: */ 
  387. BYTE     drive; 
  388.   
  389. {        /* SetCurrentDrive // */ 
  390.  union REGS inregs, outregs; 
  391.  /*--------------------------------------------------main body */ 
  392.  inregs.h.ah = 0x0E;          /* DOS select drive */ 
  393.  inregs.h.dl = drive; 
  394.  intdos(&inregs,&outregs); 
  395.  if (outregs.x.cflag) 
  396.     return(FALSE); 
  397.  return(TRUE); 
  398. }        /* end of SetCurrentDrive */ 
  399.   
  400. /********************************************************************/