home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dsfind.exe
/
FINDUSER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
9KB
|
328 lines
/****************************************************************************
** File: FINDUSER.C
**
** Desc: Finds objects in the tree.
**
** This was designed only to find "User" Objects into the tree.
**
**
** 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.
*/
/***************************************************************************
** 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>
/*-----------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwcalls.h>
#include <nwlocale.h>
/*-----------------------------------------------------------------------
** Program Global storage
*/
struct
{
NWDSContextHandle context;
char ncontext[MAX_DN_CHARS];
}gs;
extern unsigned _stklen=8000;
/***************************************************************************
** Function Prototypes
*/
void Proc(char *objectName);
void FatalError(int errorCode);
void InitDS(void);
int UninitDS(void);
/***************************************************************************
** Main Program
*/
void main(int argc, char *argv[])
{
if(argc < 2)
{
printf("Usage:\n\tFINDUSER <USERNAME>\n");
}
else
{
InitDS();
Proc(argv[1]);
UninitDS();
}
}
/***************************************************************************
** This will search for the username that is passed
** in the tree.
*/
void Proc(char *objectName)
{
NWDS_ITERATION iterHandle=-1L;
NWOBJECT_INFO objInfo;
NWDS_BUFFER *filter, *outBuf;
NWDS_FILTER_CURSOR NWFAR *cur;
NWCOUNT totalObjs, totalAttrs, x;
NWDSCCODE ccode;
char targetName[MAX_DN_CHARS];
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &filter);
if(ccode < 0)
goto Exit0;
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &outBuf);
if(ccode < 0)
goto Exit1;
ccode = NWDSInitBuf(gs.context, DSV_SEARCH_FILTER, filter);
if(ccode < 0)
goto Exit2;
ccode = NWDSAllocFilter(&cur);
if(ccode < 0)
goto Exit2;
ccode = NWDSAddFilterToken(cur, FTOK_ANAME,
"Object Class", SYN_CLASS_NAME);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_EQ,
NULL, SYN_UNKNOWN);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_AVAL,
"User", SYN_CLASS_NAME);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_AND,
NULL, SYN_UNKNOWN);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_ANAME,
"CN", SYN_CI_STRING);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_EQ,
NULL, SYN_UNKNOWN);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_AVAL,
objectName, SYN_CI_STRING);
if(ccode < 0)
goto Exit3;
ccode = NWDSAddFilterToken(cur, FTOK_END,
NULL, SYN_UNKNOWN);
if(ccode < 0)
goto Exit3;
ccode = NWDSPutFilter(gs.context, filter, cur, NULL);
if(ccode <0)
goto Exit3;
do
{
/* if you want to search the entire tree, substiture "[Root]" in for the
variable gs.ncontext and it will search everything but it could be
time consuming!!! */
ccode = NWDSSearch(gs.context,
gs.ncontext, /* base object (current context) (IN) */
DS_SEARCH_SUBTREE, /* scope of the search (IN) */
TRUE, /* derefence aliases (IN) */
filter, /* filter for search (IN) */
DS_ATTRIBUTE_VALUES, /* get the names and values (IN) */
FALSE, /* only specified attributes (IN) */
NULL, /* All attributes (IN) */
&iterHandle, /* flag for more to read (OUT)*/
0, /* (IN) */
(NWDS_NUM_OBJ NWFAR *)NULL,
outBuf); /* information goes here (OUT)*/
if(ccode < 0)
{
goto Exit2;
}
ccode = NWDSGetObjectCount(gs.context, outBuf, &totalObjs);
if(ccode < 0)
{
goto Exit2;
}
if((NWCOUNT)0 == totalObjs)
{
goto Exit2;
}
for(x=totalObjs;x;x--)
{
ccode = NWDSGetObjectName(gs.context, outBuf, targetName, &totalAttrs, &objInfo);
if(ccode < 0)
{
goto Exit2;
}
printf("%s\n",targetName);
}
}
while(iterHandle != NO_MORE_ITERATIONS);
ccode=SUCCESSFUL;
goto Exit2;
Exit3:
NWDSFreeFilter(cur, NULL);
Exit2:
NWDSFreeBuf(outBuf);
Exit1:
NWDSFreeBuf(filter);
Exit0:
}
/***************************************************************************
** 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;
DWORD flags;
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);
}
dsCcode = NWDSGetContext(gs.context, DCK_NAME_CONTEXT, gs.ncontext);
if(gs.context)
{
printf("FatalError during NWDSCreateContext %X\n",gs.context);
FatalError(FAILURE);
}
dsCcode = NWDSGetContext(gs.context, DCK_FLAGS, &flags);
if(dsCcode < 0)
{
printf("NWDSGetContext() returned: %04X\n", dsCcode);
FatalError(FAILURE);
}
flags |= DCV_TYPELESS_NAMES;
flags &= ~DCV_CANONICALIZE_NAMES;
dsCcode = NWDSSetContext(gs.context, DCK_FLAGS, &flags);
if(dsCcode < 0)
{
printf("NWDSSetContext() returned: %04X\n", dsCcode);
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);
}