home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xdsa1.exe
/
DSACDEMO.C
< prev
next >
Wrap
Text File
|
1994-10-21
|
12KB
|
412 lines
/*****************************************************************************
** File: DSACDEMO.C (shows usage of search.h streams type DS calls)
**
** Description:
** Provides an example of using DSSearchOpen, DSSearchSeek, DSRead, and
** DSClose. These functions provide a streams like interface to the NDS
** x/open style x.500 interface NDS is pattered after. It simplifying
** access to NDS by allocating all resources for the working of the NWDS
** calls.
**
** 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.
**
** Syntax: load DSACDEMO <base object to find telephone numbers from>
**
** Output: Search results-showing telephone numbers of all user objects
** found below the base object; read results-showing the telephone
** numbers of the first object found in the search results; and list
** results-showing all objects below the base object specified.
**
** Special Considerations:
** When running on a pre 4.1 version of netware, it is required that you
** use a full typed distinguished name for the user. 4.1 does not have
** this constraint.
**
** QMK386 options used:
**
** /csDSACDEMO Include source DSACDEMO.C
** /csDSACCESS Include source DSACCESS.C
** /id Include import statement for Directory Services symbols.
**
** Programmers:
**
** Ini Who Firm
** ------------------------------------------------------------------------
** MDO Mark D. Oberg Novell Developer Support
**
**
** History:
**
** When Who What
** ------------------------------------------------------------------------
** 09-22-94 MDO Begin
** 10-03-94 MDO Tested
**
*/
/*****************************************************************************
** Include files and macro definitions
*/
/*-------------------------------------------------------------------------
** ANSI Includes
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
/*-------------------------------------------------------------------------
** NetWare Includes
*/
#include <nwdsapi.h>
#include <nwdsmisc.h>
#include <nwdsdc.h>
#include <nwconn.h>
#include <nwenvrn.h>
#include <nwcntask.h>
/*-------------------------------------------------------------------------
** DSACDEMO
*/
#include "dsaccess.h"
/*****************************************************************************
** DisplayUsage
*/
void DisplayUsage(void)
{
printf("Syntax: load dsacdemo <ds-context to list tel#'s from>\n");
printf("Example: load dsacdemo ou=services.o=novell\n");
exit(0);
}
/*****************************************************************************
** GetPassword prompts the user with "Password:" and accepts a string marking
** each entered position with an asterisk.
*/
void GetPassword(char *password, int size)
{
int index=0;
WORD x,y;
printf("Password: ");
y=wherey(); /* find current row */
do
{
x=wherex(); /* find current column */
password[index]=getch();
if(0x0D==password[index])
password[index]='\0';
else if(0x08==password[index] && 0<=index-1) /* Backspace */
{
index-=2;
gotoxy(x-1,y); /* backup */
putch(' '); /* clear output */
gotoxy(x-1,y); /* backup */
}
else
putch('*');
index++;
x++; /* follow cursor position */
}while (password[index-1] && index<size);
if(password[index-1])
password=NULL;
putch('\n');
}
/*****************************************************************************
** GetText prompts the user with promptMsg and takes input from
** user placing it in rtext. Size specifies the maximum string length
** allowed by the buffer passed in.
**/
void GetText(char *promptMsg, char *rtext, int size)
{
int index=0;
WORD x,y;
printf("%s",promptMsg);
y=wherey();
do
{
x=wherex();
rtext[index]=getch();
if(0x0D==rtext[index])
rtext[index]='\0';
else if(0x08==rtext[index] && 0<=index-1) /* Backspace */
{
index-=2;
gotoxy(x-1,y); /* backup */
putch(' '); /* clear output */
gotoxy(x-1,y); /* backup */
}
else putch(rtext[index]);
index++;
}while (rtext[index-1] && index<size);
if(rtext[index-1]) rtext=NULL;
putch('\n');
}
/*****************************************************************************
** main
*/
void main(int argc, char *argv[])
{
NWDSContextHandle cx;
DS_HANDLE *dsHandle;
READ_DATA *readData;
NWDSCCODE ccode;
char password[255+1];
char administrator[255+1];
char objectName[MAX_DN_CHARS]="";
/*-------------------------------------------------------------------------
** Specify to return Telephone Number's and only User's and if telephone
** number exists.
*/
char *attrNames[]={"Telephone Number",NULL};
/* TOKEN, VALUE. SYNTAX, */
/* ---------- -------------- ---------------- */
TOKEN_ENTRY tokens[]={ {FTOK_ANAME, "Object Class", SYN_CLASS_NAME },
{FTOK_EQ, NULL, SYN_UNKNOWN },
{FTOK_AVAL, "User", SYN_CLASS_NAME },
{FTOK_AND, NULL, SYN_UNKNOWN },
{FTOK_PRESENT,NULL, SYN_UNKNOWN },
{FTOK_ANAME, "Telephone Number", SYN_TEL_NUMBER },
{FTOK_END, NULL, SYN_UNKNOWN } };
if(argc!=2)
DisplayUsage(); /*display usage and exit nlm*/
/*-------------------------------------------------------------------------
** pre 4.1 requires using typed names with default context flags.
*/
GetText("Enter user's typed distinguished name for login: ",administrator,255); /*get admin name*/
GetPassword(password, 255); /*get password for user*/
clrscr(); /* clear off password prompt */
cx=NWDSCreateContext();
if(ERR_CONTEXT_CREATION==cx)
{
printf("Failed NWDSCreateContext.\n");
goto Exit0;
}
ccode=NWDSLogin(
/* NWDSContextHandle context, */ cx,
/* uint32 optionsFlag, */ 0,
/* char NWFAR *objectName, */ administrator,
/* char NWFAR *password, */ password,
/* uint32 validityPeriod */ 60
);
memset(password,0x00,255); /* clear password from memory */
if(ccode)
{
printf("Login failed. Check administrator name and password.\n");
goto Exit1;
}
/*-------------------------------------------------------------------------
** search section.
*/
printf("Results of search.\n");
/*-------------------------------------------------------------------------
** Opens a dsHandle to use for search
*/
dsHandle=DSSearchOpen(cx, attrNames, tokens);
if(NULL==dsHandle)
{
printf("Failed DSSearchOpen.\n");
goto Exit2;
}
/*-------------------------------------------------------------------------
** Initiates the search
*/
ccode=DSSearchSeek(
/* DS_HANDLE *searchHandle, */ dsHandle,
/* char *baseObjectName, */ argv[1], /* start from context specified */
/* NWDS_SEARCH_SCOPE scope, */ DS_SEARCH_SUBTREE,
/* NWFLAGS searchAliases, */ FALSE,
/* NWDS_TYPE infoType ) */ 1 ); /* attribute names and values */
if(ccode)
{
printf("Failed DSSearchSeek: %d\n",ccode);
goto Exit3;
}
/*-------------------------------------------------------------------------
** DSRead returns data until EOF is returned.
*/
for(readData=DSRead(dsHandle);NULL !=readData && EOF != readData;readData=DSRead(dsHandle))
{
switch (readData->readType)
{
case OBJECT:
if(0x00 == strlen(objectName))
strcpy(objectName,readData->read.object.name); /* used in read example */
printf("\n\n%s\n",readData->read.object.name); /* print user name */
break;
case ATTR:
printf("%s\n",readData->read.attr.name); /* print attribute name */
break;
case ATTR_VALUE:
printf("%s\n",(char *)readData->read.attrVal.value);
}
free(readData);
}
if(NULL==readData)
{
printf("Failed DSRead.\n");
}
/*-------------------------------------------------------------------------
** close the handle.
*/
DSClose(dsHandle); /* deallocate resources from DSSearchOpen */
/*-------------------------------------------------------------------------
** read section.
*/
printf("Results of read on object %s.\n",objectName);
/*-------------------------------------------------------------------------
** Opens a dsHandle to use for read
*/
dsHandle=DSReadOpen(cx, attrNames);
if(NULL==dsHandle)
{
printf("Failed DSReadOpen.\n");
goto Exit2;
}
/*-------------------------------------------------------------------------
** Initiates the read
*/
ccode=DSReadSeek(
/* DS_HANDLE *searchHandle,*/ dsHandle,
/* char *baseObjectName, */ objectName, /*read first object found on search */
/* NWDS_TYPE infoType ) */ 1 ); /* attribute names and values */
if(ccode)
{
printf("Failed DSReadSeek: %d\n",ccode);
goto Exit3;
}
/*-------------------------------------------------------------------------
** DSRead returns data until EOF is returned.
*/
for(readData=DSRead(dsHandle);NULL !=readData && EOF != readData;readData=DSRead(dsHandle))
{
switch (readData->readType)
{
case ATTR:
printf("%s\n",readData->read.attr.name); /* print attribute name */
break;
case ATTR_VALUE:
printf("%s\n",(char *)readData->read.attrVal.value);
}
free(readData);
}
if(NULL==readData)
{
printf("Failed DSRead.\n");
}
/*-------------------------------------------------------------------------
** close the handle.
*/
DSClose(dsHandle); /* deallocate resources from DSSearchOpen */
/*-------------------------------------------------------------------------
** list section.
*/
printf("Results of list.\n");
/*-------------------------------------------------------------------------
** Opens a dsHandle to use for list
*/
dsHandle=DSListOpen(cx);
if(NULL==dsHandle)
{
printf("Failed DSListOpen.\n");
goto Exit2;
}
/*-------------------------------------------------------------------------
** Initiates the list
*/
ccode=DSListSeek(
/* DS_HANDLE *searchHandle, */ dsHandle,
/* char *baseObjectName, */ argv[1] ); /* start from context specified */
if(ccode)
{
printf("Failed DSListSeek: %d\n",ccode);
goto Exit3;
}
/*-------------------------------------------------------------------------
** DSRead returns data until EOF is returned.
*/
for(readData=DSRead(dsHandle);NULL !=readData && EOF != readData;readData=DSRead(dsHandle))
{
switch (readData->readType)
{
case OBJECT :
printf("%s\n",readData->read.object.name); /* print user name */
break;
default:
printf("Invalid type received from DSRead by List.\n");
}
free(readData);
}
if(NULL==readData)
{
printf("Failed DSList.\n");
}
Exit3:
DSClose(dsHandle); /* deallocate resources from DSSearchOpen */
Exit2:
NWDSLogout(cx);
Exit1:
NWDSFreeContext(cx);
Exit0:
exit(0);
}