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 >
Wrap
C/C++ Source or Header
|
1993-11-23
|
8KB
|
233 lines
/*
████████████████████████████████████████████████████████████████████████████
█ █
█ install.c █
█ █
█ Creates a job server and job queue to process DOS commands submitted by █
█ submit.exe █
████████████████████████████████████████████████████████████████████████████
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include <dir.h>
#include <nwcalls.h>
#include "..\doit.h"
#include "..\doitacct.h"
#define NWDOS
void main()
{
NWCCODE cCode;
struct ffblk ffblk;
int found;
DWORD queueID;
NWCONN_HANDLE connID;
NWCONN_NUM connNumber;
char serverName[48];
char userName[48];
char response;
NWFLAGS installed;
NWSEGMENT_DATA segment;
NWOBJ_ID oID;
FILE *logFile;
long balance;
found = findfirst(JOBSERV_PATH, &ffblk, FA_DIREC);
if (found != 0) {
printf("You must create the queue directory\n");
printf("%s before installing the job server.\n", JOBSERV_PATH);
exit(-1);
}
cCode = NWCallsInit(NULL, NULL);
if (cCode != 0) {
printf("Unable to initialize NetWare interface\n");
exit(-1);
}
/* get the connection ID of the server you're installing on */
cCode = NWGetDefaultConnectionID(&connID);
if (cCode != 0) {
printf("Unable to get connection ID of default server\n");
exit(-1);
}
/* create job server object */
cCode = NWCreateObject(connID, JOBSERV_NAME, OT_DOIT, BF_STATIC, BS_LOGGED_READ | BS_OBJECT_WRITE);
if (cCode == 0)
printf("Created job server bindery object\n");
else {
switch (cCode) {
case 0x89EE : printf("Job server bindery object already created on default server\n");
response = ' ';
do {
printf("Continue anyway? (y/n)");
response = toupper(getche());
printf("\n");
} while ((response != 'Y') && (response != 'N'));
if (response == 'N')
exit(-1);
break;
case 0x89F5 : printf("You must be supervisor or supervisor-equivalent to install job server\n");
exit(-1);
break;
default : printf("Call to NWCreateObject failed\n");
exit(-1);
break;
}
}
/* create a password for the job server */
cCode = NWChangeObjectPassword(connID, JOBSERV_NAME, OT_DOIT, "", JOBSERV_PWORD);
if (cCode == 0)
printf("Set job server password\n");
else {
printf("Call to NWChangeObjectPassword failed, cCode = %X\n", cCode);
exit(-1);
}
/* see if accounting is installed; if so, create account balance property */
cCode = NWQueryAccountingInstalled(connID, &installed);
if (installed == 1) {
cCode = NWCreateProperty(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", BF_ITEM | BF_STATIC, BS_OBJECT_READ | BS_SUPER_WRITE);
if (cCode != SUCCESSFUL) {
printf("Unable to create Account Balance property for job server object\n");
exit(-1);
}
/* set account balance to allow unlimited credit */
segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
segment[4] = 0x80;
cCode = NWWritePropertyValue(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", 1, segment, 0);
if (cCode != SUCCESSFUL) {
printf("Unable to set account balance for job server object\n");
exit(-1);
}
}
/* set up job server to charge for services */
/* first get name of default server */
cCode = NWGetFileServerName(connID, serverName);
if (cCode != SUCCESSFUL) {
printf("Unable to get name of default server\n");
exit(-1);
}
/* create DOIT_ACCT_SERV property of server object */
cCode = NWCreateProperty(connID, serverName, OT_FILE_SERVER, "DOIT_ACCT_SERV", BF_SET | BF_STATIC, BS_LOGGED_READ | BS_SUPER_WRITE);
if (cCode != SUCCESSFUL) {
printf("Unable to create DOIT_ACCT_SERV property\n");
exit(-1);
}
/* then add job server to server's DOIT_ACCT_SERV property */
cCode = NWAddObjectToSet(connID, serverName, OT_FILE_SERVER, "DOIT_ACCT_SERV", JOBSERV_NAME, OT_DOIT);
if (cCode != SUCCESSFUL) {
printf("Unable to add job server to accounting servers set\n");
exit(-1);
}
/* create log file and grant job server rights to it */
logFile = fopen("SYS:\\SYSTEM\\DOIT.LOG", "w+");
fclose(logFile);
cCode = NWGetObjectID(connID, JOBSERV_NAME, OT_DOIT, &oID);
if (cCode != SUCCESSFUL)
printf("Unable to get object ID of job server\n");
else {
cCode = NWAddTrustee(connID, 0, "SYS:\\SYSTEM\\DOIT.LOG", oID, TA_ALL);
if (cCode != SUCCESSFUL)
printf("Unable to grant job server rights to log file\n");
/* submit account note about creating the job server */
cCode = DoItSubmitAccountNote(connID, OT_DOIT, JOBSERV_NAME, 0L, "Created job server object");
if (cCode != SUCCESSFUL)
printf("Unable to submit account note about creating job server\n");
}
/* create a job queue */
cCode = NWCreateQueue(connID, JOBSERV_NAME, OT_DOIT_Q, 0, JOBSERV_PATH, &queueID);
if (cCode == 0)
printf("Created job queue\n");
else {
printf("Call to NWCreateQueue failed, cCode = %X\n", cCode);
if ((cCode == 0x8998) || (cCode == 0x899C))
printf("Invalid queue directory path\n");
exit(-1);
}
/* get your connection number */
cCode = NWGetConnectionNumber(connID, &connNumber);
if (cCode != 0) {
printf("Unable to get your connection number to default server\n");
exit(-1);
}
/* get your user name */
cCode = NWGetConnectionInformation(connID, connNumber, userName, NULL, NULL, NULL);
if (cCode != 0) {
printf("Unable to get your user name\n");
exit(-1);
}
/* add your user to the set of queue users */
cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_USERS", userName, OT_USER);
if (cCode == 0)
printf("Added your object to queue users set\n");
else {
printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
exit(-1);
}
/* add your user to the set of queue operators */
cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_OPERATORS", userName, OT_USER);
if (cCode == 0)
printf("Added your object to queue operators set\n");
else {
printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
exit(-1);
}
/* add DOIT_ACCT_BAL property to your user */
cCode = NWCreateProperty(connID, userName, OT_USER, "DOIT_ACCT_BAL", BF_ITEM | BF_STATIC, BS_LOGGED_READ | BS_SUPER_WRITE);
if (cCode != SUCCESSFUL) {
printf("Unable to create DOIT_ACCT_BAL property\n");
exit(-1);
}
/* set account balance and limit */
segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
printf("Account balance for your user: ");
scanf("%ld", &balance);
segment[0] = balance; /* set account balance */
/* leave credit limit (segment[4]) set to 0 */
cCode = NWWritePropertyValue(connID, userName, OT_USER, "DOIT_ACCT_BAL", 1, segment, 0);
if (cCode != SUCCESSFUL) {
printf("Unable to set account balance\n");
exit(-1);
}
/* submit account note about setting your user balance */
cCode = DoItSubmitAccountNote(connID, OT_USER, userName, balance, "Set balance for job server account");
if (cCode != SUCCESSFUL)
printf("Unable to submit account note about creating job server\n");
/* add your new server to the set of queue servers */
cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_SERVERS", JOBSERV_NAME, OT_DOIT);
if (cCode == 0)
printf("Added job server to queue servers set\n");
else {
printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
exit(-1);
}
printf("Job server installed\n");
}