home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dslist.exe
/
DSLIST.C
next >
Wrap
Text File
|
1994-11-29
|
9KB
|
384 lines
/****************************************************************************
** File: DSLIST.C
**
** Desc: This program lists all the objects that exist at
** the current context in the tree and then demonstrates how to
** read the attribute values of "Common Name" and "Surname" of each
** object. Be aware that the "Surname" attribute is only applicable
** for "User" objects and will not be displayed for other types of
** objects.
**
** 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
** -----------------------------------------------------------------------
** KLB Karl Bunnell Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 09-07-94 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** MACROS
*/
#define NWDOS
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <conio.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwcalls.h>
#include <nwlocale.h>
/*------------------------------------------------------------------------
** Prototypes
*/
int ReadAttributes(NWDSContextHandle dContext, char *objectName);
int DisplayAttributes(NWDSContextHandle dContext, NWDS_BUFFER *buf);
/****************************************************************************
** The entire program is contained in Function main().
**
*/
void main(int argc, char *argv[])
{
NWDSContextHandle dContext;
NWDS_ITERATION iterHandle = -1L;
NWOBJECT_INFO objectInfo;
NWDS_BUFFER *outBuf, *inBuf;
NWDSCCODE cCode;
NWCOUNT objectCount, attrCount;
LCONV lconvInfo;
char objectName[MAX_DN_CHARS];
char nContext[MAX_DN_CHARS];
char far *countryPtr;
int i;
int rval;
char c;
cCode = NWCallsInit(NULL, NULL);
if (cCode)
{
printf("\nCall to NWCallsInit returned: %04X", cCode);
exit(1);
}
countryPtr = NWLsetlocale(LC_ALL, "");
NWLlocaleconv(&lconvInfo);
cCode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
if(cCode)
{
printf("NWInitUnicodeTables() returned: %04X\n", cCode);
goto _FreeUnicodeTables;
}
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION)
{
printf("NWDSCreateContext returned: %04X\n", cCode);
goto _FreeContext;
}
if (argc == 2)
{
cCode = NWDSSetContext(
/* Context handle */ dContext,
/* Key */ DCK_NAME_CONTEXT,
/* Context value */ argv[1]
);
if (cCode < 0)
{
printf("NWDSSetContext returned: %04X\n", cCode);
goto _FreeContext;
}
}
cCode = NWDSGetContext(
/* Context to query */ dContext,
/* Context variable */ DCK_NAME_CONTEXT,
/* Context returned */ (void *) nContext
);
if (cCode)
{
printf("NWDSGetContext returned: %04X\n", cCode);
goto _FreeContext;
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
printf("NWDSAllocBuf returned: %04X\n", cCode);
goto _FreeContext;
}
do
{
cCode = NWDSList(
/* Req. Context */ dContext,
/* Object Name */ "",
/* Iter. handle */ &iterHandle,
/* Subordinates */ outBuf
);
if (cCode < 0)
{
printf("\nNWDSList returned : %04X\n", cCode);
break;
}
cCode = NWDSGetObjectCount(
/* Req. Context */ dContext,
/* P. to read buf.*/ outBuf,
/* Num. of OBJs */ &objectCount
);
if (cCode < 0)
{
printf("\nNWDSGetObjectCount returned : %04X\n", cCode);
break;
}
printf("\nObjects found under %s : \n", nContext);
for (i = 0; i < objectCount; i++)
{
cCode = NWDSGetObjectName(
/* Req. Context */ dContext,
/* P. to result buf */ outBuf,
/* object name */ objectName,
/* Attribute count */ &attrCount,
/* object Info */ &objectInfo
);
if (cCode < 0)
{
printf("\nNWDSGetObjectName returned: %04X\n", cCode);
goto _FreeContext;
}
printf("%d. %s\n", (i + 1), objectName);
rval = ReadAttributes(dContext, objectName);
c = getch();
}
} while(iterHandle != -1);
_FreeContext:
NWDSFreeContext(dContext);
_FreeUnicodeTables:
NWFreeUnicodeTables();
}
int ReadAttributes(NWDSContextHandle dContext, char *objectName)
{
NWDSCCODE cCode;
NWDS_BUFFER *outBuf, *inBuf;
NWDS_ITERATION iterHandle = -1L;
char *attrName[] = { "Common Name",
"Surname" };
int i;
int rval = 0;
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &inBuf
);
if (cCode < 0)
{
printf("NWDSAllocBuf returned: %04X\n", cCode);
return(1);
}
cCode = NWDSInitBuf(
/* Context */ dContext,
/* Operation*/ DSV_READ,
/* buffer */ inBuf
);
if (cCode < 0)
{
printf("NWDSInitBuf returned: %04X\n", cCode);
NWDSFreeBuf(inBuf);
return(1);
}
cCode = NWDSAllocBuf(
/* Buffer Size */ DEFAULT_MESSAGE_LEN,
/* Buff. Point.*/ &outBuf
);
if (cCode < 0)
{
printf("NWDSAllocBuf returned: %04X\n", cCode);
NWDSFreeBuf(inBuf);
return(1);
}
for(i = 0; i < 2; i++)
{
cCode = NWDSPutAttrName(
/* context */ dContext,
/* in buffer */ inBuf,
/* attr. name*/ (char NWFAR*)attrName[i]
);
if (cCode < 0)
{
printf("NWDSPutAttrName returned: %04X\n", cCode);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(1);
}
}
cCode = NWDSRead(
/* Context */ dContext,
/* Object name */ objectName,
/* Info. Type */ DS_ATTRIBUTE_VALUES,
/* All Attrib ?*/ FALSE,
/* Attri. names*/ inBuf,
/* Iter. Handle*/ &iterHandle,
/* Object info */ outBuf
);
if (cCode < 0)
{
printf("\nNWDSRead returned: %04X\n", cCode);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(1);
}
rval = DisplayAttributes(dContext, outBuf);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
if (rval)
return(1);
return(0);
}
int DisplayAttributes(NWDSContextHandle dContext, NWDS_BUFFER *buf)
{
NWSYNTAX_ID syntax;
NWDSCCODE cCode;
NWCOUNT attrCount;
NWCOUNT valCount;
char attrName[MAX_DN_CHARS + 1];
char attrVal[MAX_DN_CHARS + 1];
int i, j;
cCode = NWDSGetAttrCount(
/* Context */ dContext,
/* attr. buff */ buf,
/* num of attr*/ &attrCount
);
if (cCode < 0)
{
printf("\nNWDSGetAttrCount returned: %04X\n", cCode);
return(1);
}
for (i = 0; i < attrCount; i++)
{
cCode = NWDSGetAttrName(
/* Context */ dContext,
/* attrib. buf */ buf,
/* attrib name */ attrName,
/* attr. val. cnt */ &valCount,
/* Syntax ID */ &syntax
);
if (cCode < 0)
{
printf("\nNWDSGetAttrName returned: %04X\n", cCode);
return(1);
}
printf("\nAttribute Name : %s", attrName);
printf("\nAttribute Value(s):\n");
for (j = 0; j < valCount; j++)
{
cCode = NWDSGetAttrVal(
/* Context */ dContext,
/* read buf */ buf,
/* syntax id*/ syntax,
/* attr. val*/ attrVal
);
if (cCode < 0)
{
printf("\nNWDSGetAttrVal returned: %04X\n", cCode);
return(1);
}
printf("%s\n ", attrVal);
free(attrVal);
}
}
}