home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / an401x.exe / INSTALL.C < prev    next >
C/C++ Source or Header  |  1993-11-23  |  8KB  |  233 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ install.c                                                                █
  5.  █                                                                          █
  6.  █ Creates a job server and job queue to process DOS commands submitted by  █
  7.  █ submit.exe                                                               █
  8.  ████████████████████████████████████████████████████████████████████████████
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <nwcalls.h>
  18. #include "..\doit.h"
  19. #include "..\doitacct.h"
  20.  
  21. #define NWDOS
  22.  
  23. void main()
  24. {
  25.     NWCCODE            cCode;
  26.     struct ffblk    ffblk;
  27.     int                found;
  28.     DWORD            queueID;
  29.     NWCONN_HANDLE    connID;
  30.     NWCONN_NUM        connNumber;
  31.     char             serverName[48];
  32.     char             userName[48];
  33.     char            response;
  34.     NWFLAGS         installed;
  35.     NWSEGMENT_DATA    segment;
  36.     NWOBJ_ID        oID;
  37.     FILE            *logFile;
  38.     long            balance;
  39.  
  40.     found = findfirst(JOBSERV_PATH, &ffblk, FA_DIREC);
  41.     if (found != 0) {
  42.         printf("You must create the queue directory\n");
  43.         printf("%s before installing the job server.\n", JOBSERV_PATH);
  44.         exit(-1);
  45.     }
  46.  
  47.     cCode = NWCallsInit(NULL, NULL);
  48.     if (cCode != 0) {
  49.         printf("Unable to initialize NetWare interface\n");
  50.         exit(-1);
  51.     }
  52.  
  53.     /* get the connection ID of the server you're installing on */
  54.     cCode = NWGetDefaultConnectionID(&connID);
  55.     if (cCode != 0) {
  56.         printf("Unable to get connection ID of default server\n");
  57.         exit(-1);
  58.     }
  59.  
  60.     /* create job server object */
  61.     cCode = NWCreateObject(connID, JOBSERV_NAME, OT_DOIT, BF_STATIC, BS_LOGGED_READ | BS_OBJECT_WRITE);
  62.     if (cCode == 0)
  63.         printf("Created job server bindery object\n");
  64.     else {
  65.         switch (cCode) {
  66.             case 0x89EE :    printf("Job server bindery object already created on default server\n");
  67.                     response = ' ';
  68.                     do {
  69.                         printf("Continue anyway?  (y/n)");
  70.                         response = toupper(getche());
  71.                         printf("\n");
  72.                     } while ((response !=  'Y') && (response  !=  'N'));
  73.                     if (response == 'N')
  74.                         exit(-1);
  75.                     break;
  76.             case 0x89F5 :    printf("You must be supervisor or supervisor-equivalent to install job server\n");
  77.                     exit(-1);
  78.                     break;
  79.             default :    printf("Call to NWCreateObject failed\n");
  80.                     exit(-1);
  81.                     break;
  82.         }
  83.     }
  84.  
  85.     /* create a password for the job server */
  86.     cCode = NWChangeObjectPassword(connID, JOBSERV_NAME, OT_DOIT, "", JOBSERV_PWORD);
  87.     if (cCode == 0)
  88.         printf("Set job server password\n");
  89.     else {
  90.         printf("Call to NWChangeObjectPassword failed, cCode = %X\n", cCode);
  91.         exit(-1);
  92.     }
  93.  
  94.     /* see if accounting is installed; if so, create account balance property */
  95.     cCode = NWQueryAccountingInstalled(connID, &installed);
  96.     if (installed == 1) {
  97.         cCode = NWCreateProperty(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", BF_ITEM | BF_STATIC, BS_OBJECT_READ | BS_SUPER_WRITE);
  98.         if (cCode != SUCCESSFUL) {
  99.             printf("Unable to create Account Balance property for job server object\n");
  100.             exit(-1);
  101.         }
  102.  
  103.         /* set account balance to allow unlimited credit */
  104.         segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
  105.         segment[4] = 0x80;
  106.         cCode = NWWritePropertyValue(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", 1, segment, 0);
  107.         if (cCode != SUCCESSFUL) {
  108.             printf("Unable to set account balance for job server object\n");
  109.             exit(-1);
  110.         }
  111.     }
  112.  
  113.     /* set up job server to charge for services */
  114.     /* first get name of default server */
  115.     cCode = NWGetFileServerName(connID, serverName);
  116.     if (cCode != SUCCESSFUL) {
  117.         printf("Unable to get name of default server\n");
  118.         exit(-1);
  119.     }
  120.  
  121.     /* create DOIT_ACCT_SERV property of server object */
  122.     cCode = NWCreateProperty(connID, serverName, OT_FILE_SERVER, "DOIT_ACCT_SERV", BF_SET | BF_STATIC, BS_LOGGED_READ | BS_SUPER_WRITE);
  123.     if (cCode != SUCCESSFUL) {
  124.         printf("Unable to create DOIT_ACCT_SERV property\n");
  125.         exit(-1);
  126.     }
  127.  
  128.     /* then add job server to server's DOIT_ACCT_SERV property */
  129.     cCode = NWAddObjectToSet(connID, serverName, OT_FILE_SERVER, "DOIT_ACCT_SERV", JOBSERV_NAME, OT_DOIT);
  130.     if (cCode != SUCCESSFUL) {
  131.         printf("Unable to add job server to accounting servers set\n");
  132.         exit(-1);
  133.     }
  134.  
  135.     /* create log file and grant job server rights to it */
  136.     logFile = fopen("SYS:\\SYSTEM\\DOIT.LOG", "w+");
  137.     fclose(logFile);
  138.  
  139.     cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT, &oID);
  140.     if (cCode != SUCCESSFUL)
  141.         printf("Unable to get object ID of job server\n");
  142.     else {
  143.  
  144.         cCode = NWAddTrustee(connID, 0, "SYS:\\SYSTEM\\DOIT.LOG", oID, TA_ALL);
  145.         if (cCode != SUCCESSFUL)
  146.             printf("Unable to grant job server rights to log file\n");
  147.  
  148.         /* submit account note about creating the job server */
  149.         cCode = DoItSubmitAccountNote(connID, OT_DOIT, JOBSERV_NAME, 0L, "Created job server object");
  150.         if (cCode != SUCCESSFUL)
  151.             printf("Unable to submit account note about creating job server\n");
  152.     }
  153.  
  154.     /* create a job queue */
  155.     cCode = NWCreateQueue(connID, JOBSERV_NAME, OT_DOIT_Q, 0, JOBSERV_PATH, &queueID);
  156.     if (cCode == 0)
  157.         printf("Created job queue\n");
  158.     else {
  159.         printf("Call to NWCreateQueue failed, cCode = %X\n", cCode);
  160.         if ((cCode == 0x8998) || (cCode == 0x899C))
  161.             printf("Invalid queue directory path\n");
  162.             exit(-1);
  163.     }
  164.  
  165.     /* get your connection number */
  166.     cCode = NWGetConnectionNumber(connID, &connNumber);
  167.     if (cCode != 0) {
  168.         printf("Unable to get your connection number to default server\n");
  169.         exit(-1);
  170.     }
  171.  
  172.     /* get your user name */
  173.     cCode = NWGetConnectionInformation(connID, connNumber, userName, NULL, NULL, NULL);
  174.     if (cCode != 0) {
  175.         printf("Unable to get your user name\n");
  176.         exit(-1);
  177.     }
  178.  
  179.     /* add your user to the set of queue users */
  180.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_USERS", userName, OT_USER);
  181.     if (cCode == 0)
  182.         printf("Added your object to queue users set\n");
  183.     else {
  184.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  185.         exit(-1);
  186.     }
  187.  
  188.     /* add your user to the set of queue operators */
  189.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_OPERATORS", userName, OT_USER);
  190.     if (cCode == 0)
  191.         printf("Added your object to queue operators set\n");
  192.     else {
  193.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  194.         exit(-1);
  195.     }
  196.  
  197.     /* add DOIT_ACCT_BAL property to your user */
  198.     cCode = NWCreateProperty(connID, userName, OT_USER, "DOIT_ACCT_BAL", BF_ITEM | BF_STATIC, BS_LOGGED_READ | BS_SUPER_WRITE);
  199.     if (cCode != SUCCESSFUL) {
  200.         printf("Unable to create DOIT_ACCT_BAL property\n");
  201.         exit(-1);
  202.     }
  203.  
  204.     /* set account balance and limit */
  205.     segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
  206.     printf("Account balance for your user: ");
  207.     scanf("%ld", &balance);
  208.     segment[0] = balance;    /* set account balance */
  209.                             /* leave credit limit (segment[4]) set to 0 */
  210.  
  211.     cCode = NWWritePropertyValue(connID, userName, OT_USER, "DOIT_ACCT_BAL", 1, segment, 0);
  212.     if (cCode != SUCCESSFUL) {
  213.         printf("Unable to set account balance\n");
  214.         exit(-1);
  215.     }
  216.  
  217.     /* submit account note about setting your user balance */
  218.     cCode = DoItSubmitAccountNote(connID, OT_USER, userName, balance, "Set balance for job server account");
  219.     if (cCode != SUCCESSFUL)
  220.         printf("Unable to submit account note about creating job server\n");
  221.  
  222.     /* add your new server to the set of queue servers */
  223.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_SERVERS", JOBSERV_NAME, OT_DOIT);
  224.     if (cCode == 0)
  225.         printf("Added job server to queue servers set\n");
  226.     else {
  227.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  228.         exit(-1);
  229.     }
  230.  
  231.     printf("Job server installed\n");
  232. }
  233.