home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dbsamp.exe
/
DBINST
/
DBINST.C
next >
Wrap
Text File
|
1995-01-12
|
16KB
|
550 lines
/****************************************************************************
** File: DBINST.C
**
** Desc: Defines the following new classes in the tree:
** DBServer - a class that is used for a Database Server
** to authenticate to the tree.
** Database - a class that is used as an object to represent
** a database in a Database Server.
** Defines the following new Attributes in the tree:
** DBAdmin - an attribute that is used to hold the name of
** a NDS group. This will be used to hold the
** administrators of the Database.
** DBOperator- an attribute that is used to hold the name of
** a NDS group. This will be used to hold the
** operators of the Database.
** DBName- an attribute that is added to the class "User"
** that will be used to hold the name of the default
** database the user wants to use.
**
** NOTE - Administrators and Operators of a database are not
** the same as end users. There is an attribute already
** defined calles "User" that will be added to the Database
** class to hold the end users. Administrators and Operators
** were both added to allow for different types of
** administration.
** THE ATTRBUTE DBNAME WILL NOT BE ABLE TO BE REMOVED BECAUSE
** IT IS BEING ADDED TO A CLASS IN THE BASE SCHEMA. THE ONLY
** WAY TO GET RID OF IT IS TO UNINSTALL DIRECTORY SERVICES AND
** REINSTALL.
**
** DISCLAIMER
**
** Novell, Inc. makes no representations or warranties with respect to
** any NetWare software, and specifically disclaims any express or
** implied warranties of merchantability, title, or fitness for a
** particular purpose.
**
** Distribution of any NetWare software is forbidden without the
** express written consent of Novell, Inc. Further, Novell reserves
** the right to discontinue distribution of any NetWare software.
**
** Novell is not responsible for lost profits or revenue, loss of use
** of the software, loss of data, costs of re-creating lost data, the
** cost of any substitute equipment or program, or claims by any party
** other than you. Novell strongly recommends a backup be made before
** any software is installed. Technical support for this software
** may be provided at the discretion of Novell.
**
** Programmers:
**
** Ini Who Firm
** --- ----------------- ------------------------------------------------
** CRG Calvin Gaisford Novell Developer Support.
**
** History:
**
** When Who What
** -------- --- ---------------------------------------------------------
** 10-21-94 CRG First code.
** 1-04-95 CRG Modified to be generic as an example.
*/
/***************************************************************************
** Libraries Linked in for .exe
**
** NWCALLS.LIB
** NWLOCALE.LIB
** NWNET.LIB
**
*/
/***************************************************************************
** #defines
*/
#define FAILURE 0xFF
#define SUCCESS 0x00
/****************************************************************************
** Include headers, macros, etc.
*/
/*-----------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
/*-----------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwcalls.h>
#include <nwlocale.h>
/*-----------------------------------------------------------------------
** Program Global storage
*/
struct
{
NWDSContextHandle context;
}gs;
extern unsigned _stklen=8000;
/***************************************************************************
** Function Prototypes
*/
void processCode(NWDSCCODE ccode);
void addAttr(void);
void defineDBS(void);
void defineDB(void);
void modifyUser(void);
void FatalError(int errorCode);
void InitDS(void);
int UninitDS(void);
/***************************************************************************
** Main Program
*/
//void main(int argc, char *argv[])
void main(void)
{
InitDS();
addAttr();
defineDBS();
defineDB();
modifyUser();
UninitDS();
}
/***************************************************************************
** Processes the Codes returned after extending the Schema. The most common
** errors were inlcuded here. The error codes are at the end of the
** second programming manual.
*/
void processCode(NWDSCCODE ccode)
{
switch(ccode)
{
case 0 : printf("Successfully Added\n");
break;
case -615 :
case -645 : printf("Failed -- Already Exists\n");
break;
default : printf("Failed -- Returned Error: %d\n", ccode);
break;
}
}
/***************************************************************************
** Adds the following Attributes to the Schema: "DBS", "DB", "DBT", "DBV".
*/
void addAttr(void)
{
Attr_Info_T attrInfo;
char attrName[MAX_SCHEMA_NAME_CHARS+2];
NWDSCCODE ccode;
/*---------------------------------------------------------------
** Creating two new attributes: DBAdmin and DBOperator. These two
** attributes will hold the name of NDS groups that allow for
** multiple Administrators and Operators. These are different from
** Users of the database.
*/
memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
attrInfo.asn1ID.length = 0;
memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
attrInfo.attrSyntaxID = SYN_CI_STRING;
strcpy(attrName, "DBAdmin");
printf("Adding attribute \"%s\" to Schema...",attrName);
ccode = NWDSDefineAttr(gs.context, attrName, &attrInfo);
processCode(ccode);
memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
attrInfo.asn1ID.length = 0;
memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
attrInfo.attrSyntaxID = SYN_CI_STRING;
strcpy(attrName, "DBOperator");
printf("Adding attribute \"%s\" to Schema...",attrName);
ccode = NWDSDefineAttr(gs.context, attrName, &attrInfo);
processCode(ccode);
memset(&attrInfo, (int) '\0', sizeof(Attr_Info_T));
attrInfo.asn1ID.length = 0;
memset(attrInfo.asn1ID.data, 0, MAX_ASN1_NAME);
attrInfo.attrFlags = DS_SINGLE_VALUED_ATTR;
attrInfo.attrSyntaxID = SYN_DIST_NAME;
strcpy(attrName, "DBName");
printf("Adding attribute \"%s\" to Schema...",attrName);
ccode = NWDSDefineAttr(gs.context, attrName, &attrInfo);
processCode(ccode);
}
/***************************************************************************
** Defines the new DBServer Class
** This class is based on the "Top" class. It is defined so that it
** can be contained by Organization or Organizational Unit. It is
** defined as an object for a Database
** Server to authenticate to the Tree. (therefore the public and private
** keys) Also, the Network Address Attribute was added so clients could
** find the server through DS and no have to look for SAPs.
*/
void defineDBS(void)
{
NWCLASS_INFO classInfo;
NWDS_BUFFER *classBuf;
NWDSCCODE ccode;
char *className="DBServer";
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
if(ccode)
goto _EndProc;
ccode = NWDSInitBuf(gs.context, DSV_DEFINE_CLASS, classBuf);
if(ccode)
goto _FreeBuf;
classInfo.classFlags = (DS_EFFECTIVE_CLASS);
classInfo.asn1ID.length = 8;
memset(classInfo.asn1ID.data, 0x00, 8);
/*-----------------------------------------------------------------------
** Define super class
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Top");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new containment classes
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Organization");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Organizational Unit");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new naming attributes.
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "CN");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new manditory attributes
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "CN");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define optional attributes. These attributes can be changed to fit
** any need but to maintain login capabilities, the Private and Public
** keys but remain. The Network Address should also remain to allow
** clients to locate the actual server.
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Description");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Full Name");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Private Key");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Public Key");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "See Also");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Serial Number");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Host Server");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Version");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "User");
if(ccode)
goto _FreeBuf;
printf("Adding Class \"%s\" to Schema...",className);
ccode = NWDSDefineClass(gs.context,
className,
&classInfo,
classBuf);
processCode(ccode);
_FreeBuf:
NWDSFreeBuf(classBuf);
_EndProc:
}
/***************************************************************************
** Defines the new Database Class. This class is defined to represent
** an an object that represents a database. It can only
** be contained by a Organization or Organizational Unit.
*/
void defineDB(void)
{
NWCLASS_INFO classInfo;
NWDS_BUFFER *classBuf;
NWDSCCODE ccode;
char *className="Database";
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
if(ccode)
goto _EndProc;
ccode = NWDSInitBuf(gs.context, DSV_DEFINE_CLASS, classBuf);
if(ccode)
goto _FreeBuf;
classInfo.classFlags = (DS_EFFECTIVE_CLASS);
classInfo.asn1ID.length = 8;
memset(classInfo.asn1ID.data, 0x00, 8);
/*-----------------------------------------------------------------------
** Define super class
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Top");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new containment classes
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Organizational Unit");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Organization");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new naming attributes.
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "CN");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new manditory attributes
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "CN");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Host Server");
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define optional attributes
*/
ccode = NWDSBeginClassItem(gs.context, classBuf);
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Description");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "Full Name");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "See Also");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "User");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "DBAdmin");
if(ccode)
goto _FreeBuf;
ccode = NWDSPutClassItem(gs.context, classBuf, "DBOperator");
if(ccode)
goto _FreeBuf;
printf("Adding Class \"%s\" to Schema...",className);
ccode = NWDSDefineClass(gs.context,
className,
&classInfo,
classBuf);
processCode(ccode);
_FreeBuf:
NWDSFreeBuf(classBuf);
_EndProc:
}
/***************************************************************************
** Modifies the class User
** This adds a new attribute to the User class called DBName. This is
** so that users can store their default database in their user object
** and avoid having to look up the database every time they run the
** application.
*/
void modifyUser(void)
{
NWDS_BUFFER *classBuf;
NWDSCCODE ccode;
char *className="User";
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &classBuf);
if(ccode)
goto _EndProc;
ccode = NWDSInitBuf(gs.context, DSV_MODIFY_CLASS_DEF, classBuf);
if(ccode)
goto _FreeBuf;
/*-----------------------------------------------------------------------
** Define new attribute to add
** This will be an optional attribute because the class is already
** defined.
*/
ccode = NWDSPutAttrName(gs.context, classBuf, "DBName");
if(ccode)
goto _FreeBuf;
printf("Adding attribute \"DBName\" to Class \"%s\"...",className);
ccode = NWDSModifyClassDef(gs.context,
className,
classBuf);
processCode(ccode);
_FreeBuf:
NWDSFreeBuf(classBuf);
_EndProc:
}
/***************************************************************************
** FatalError is the common exit point for errors.
*/
void FatalError(int errorCode)
{
exit(errorCode);
}
/***************************************************************************
** Establish context. These are the standard initializations for DS calls
*/
void InitDS(void)
{
NWDSCCODE dsCcode;
LCONV lconvInfo;
dsCcode=NWCallsInit(NULL,NULL);
if(dsCcode) /* initialize allowing to call nwcalls functions */
{
printf("FatalError during NWCallsInit %X\n",dsCcode);
FatalError(FAILURE);
}
NWLlocaleconv(&lconvInfo);
dsCcode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
if(dsCcode)
{
printf("NWInitUnicodeTables() returned: %04X\n", dsCcode);
FatalError(FAILURE);
}
gs.context=NWDSCreateContext();
if(gs.context)
{
printf("FatalError during NWDSCreateContext %X\n",gs.context);
FatalError(FAILURE);
}
}
/***************************************************************************
** Release context and clean up.
*/
int UninitDS()
{
NWDSCCODE dsCcode;
dsCcode=NWDSFreeContext(gs.context);
if(dsCcode)
{
printf("FatalError during NWDSFreeContext %X\n",dsCcode);
FatalError (FAILURE);
}
dsCcode=NWFreeUnicodeTables();
if(dsCcode)
{
printf("Error during NWFreeUnicodeTables()\n");
FatalError (FAILURE);
}
return(0);
}