home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
wndsvw.exe
/
WDSVIEW.C
next >
Wrap
Text File
|
1995-03-27
|
33KB
|
1,018 lines
/****************************************************************************
** File: WDSVIEW.C
**
** Desc: This program is used as a viewer for Novell's Directory Services.
** The objects shown may vary depending on users rights to 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.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 03-07-95 CRG Original code adapted from dsview.c
*/
#define NWWIN
#define wm_initwindow (WM_USER + 1)
/***************************************************************************
** Libraries Linked in for .exe
**
** NWCALLS.LIB
** NWNET.LIB
**
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <windows.h>
#include <dos.h>
#include <io.h>
#include <toolhelp.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwcalls.h>
/*------------------------------------------------------------------------
** Program
*/
#include "wdsview.h"
/*------------------------------------------------------------------------
** Prototypes
*/
long FAR PASCAL _export WndProc(HWND, UINT, UINT, LONG);
long InitDSStuff(HWND hwnd);
long InitMainDialog(HWND hwnd);
long FreeDSStuff(void);
long RefreshObjects(HWND hwnd);
long HandleCcode(HWND hwnd, NWDSCCODE ccode, char *procName);
long RefreshAttributes(HWND hwnd);
void DecodeRights(char *attrName, char *rightsstring, NWDS_PRIVILEGES privs);
WORD UpdateValueListBox(HWND hwnd);
WORD ShowChangeContextDialog(HWND hDlg);
BOOL CALLBACK CContextDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam);
WORD UpdateCContextDialog(HWND hDlg);
WORD UpdateChangedContext(HWND hDlg);
WORD ShowAboutDialog(HWND hDlg);
BOOL CALLBACK AboutDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam);
/*------------------------------------------------------------------------
** Globals
*/
char nContext[MAX_DN_CHARS];
NWDSContextHandle gContext;
HANDLE hInst;
/***************************************************************************
** This is the main entry point. This is standard for all Windows Apps.
*/
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "WDSView";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
if(!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, szAppName);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = COLOR_WINDOW + 1;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
}
hInst = hInstance;
hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
SendMessage(hwnd, wm_initwindow, NULL, NULL);
ShowWindow(hwnd, nCmdShow);
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/***************************************************************************
** This is the process to handle all messages for the main window.
*/
long FAR PASCAL _export WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
switch(message)
{
case WM_CREATE:
if(InitDSStuff(hwnd))
{
DestroyWindow(hwnd);
}
break;
case wm_initwindow:
InitMainDialog(hwnd);
break;
case WM_COMMAND :
switch (wParam)
{
case CM_FILEEXIT:
DestroyWindow(hwnd);
break;
case CM_CHANGECON:
case IDC_CCONTEXT:
ShowChangeContextDialog(hwnd);
RefreshObjects(hwnd);
break;
case IDC_OBJECTS:
if (HIWORD (lParam) == LBN_SELCHANGE)
{
RefreshAttributes(hwnd);
}
break;
case IDC_ATTRIBUTES:
if (HIWORD (lParam) == LBN_SELCHANGE)
{
UpdateValueListBox(hwnd);
}
break;
case CM_HELPABOUT:
ShowAboutDialog(hwnd);
break;
}
return 0;
case WM_DESTROY :
FreeDSStuff();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
/***************************************************************************
** This procedure will create the context used globaly in this application
** and set the context flags to the appropriate settings. No unicode
** table operations are performed because this app uses the defualt
** which is loaded by the NetWare.drv.
*/
long InitDSStuff(HWND hwnd)
{
NWDSCCODE ccode;
DWORD flags;
gContext = NWDSCreateContext();
if((int)gContext == ERR_CONTEXT_CREATION)
{
MessageBox(hwnd, "Create Context Failed with 'ERR_CONTEXT_CREATION'", "WDSVIEW Error", MB_OK);
return((WORD)gContext);
}
ccode = NWDSGetContext(gContext, DCK_FLAGS, &flags);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetContext");
return(ccode);
}
/* Turning off Types for all names. (ie: is.novell not ou=is.o=novell) */
flags |= DCV_TYPELESS_NAMES;
ccode = NWDSSetContext(gContext, DCK_FLAGS, &flags);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSSetContext");
return(ccode);
}
ccode = NWDSGetContext(gContext, DCK_NAME_CONTEXT, nContext);
if(ccode <0)
{
HandleCcode(hwnd, ccode, "NWDSGetContext");
return(ccode);
}
return 0;
}
/***************************************************************************
** Freeing up the context at the end of the application.
*/
long FreeDSStuff(void)
{
NWDSCCODE ccode;
ccode = NWDSFreeContext(gContext);
if(ccode < 0)
{
return(ccode);
}
return 0;
}
/***************************************************************************
** This is used to initialize the controls on the main window. The current
** context field is set here and the list of objects in the current container
** (or context) is filled.
*/
long InitMainDialog(HWND hwnd)
{
SetDlgItemText(hwnd, IDC_CONTAINER, nContext);
RefreshObjects(hwnd);
return 0;
}
/***************************************************************************
** This is a generic error handling routine. It pops up a windows showing
** the message and error code passed in.
*/
long HandleCcode(HWND hwnd, NWDSCCODE ccode, char *procName)
{
char message[100];
sprintf(message,"%s returned code: 0x%X", procName, ccode);
MessageBox(hwnd, message, "WDSVIEW Error", MB_OK);
return 0;
};
/***************************************************************************
** This creates a process to handle a second dialog window and then creates
** the dialog. Used here to change the context.
*/
WORD ShowChangeContextDialog(HWND hDlg)
{
static FARPROC lpfnCContextDlgProc;
lpfnCContextDlgProc = MakeProcInstance((FARPROC)CContextDlgProc, hInst);
DialogBox(hInst, "ChangeContext", GetActiveWindow(), lpfnCContextDlgProc);
FreeProcInstance(lpfnCContextDlgProc);
return FALSE;
}
/***************************************************************************
** This process handles all messages sent to the popup dialog windows used
** to change the context.
*/
BOOL CALLBACK CContextDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
{
char container[MAX_DN_CHARS];
switch (message)
{
case WM_CLOSE:
GetDlgItemText(hDlg, IDC_CURRENT_CONTEXT, container, MAX_DN_CHARS);
SetDlgItemText(GetParent(hDlg), IDC_CONTAINER, container);
EndDialog (hDlg, 0);
return TRUE;
case WM_INITDIALOG:
UpdateCContextDialog(hDlg);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDC_CONTAINER_LIST:
if (HIWORD (lParam) == LBN_DBLCLK) /* Double Click*/
{
UpdateChangedContext(hDlg);
UpdateCContextDialog(hDlg);
}
break;
case SELECT_BUT:
GetDlgItemText(hDlg, IDC_CURRENT_CONTEXT, container, MAX_DN_CHARS);
SetDlgItemText(GetParent(hDlg), IDC_CONTAINER, container);
EndDialog (hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
/***************************************************************************
** Updates the popup dialog for Change Context so that the current list of
** Containers is displayed.
*/
WORD UpdateCContextDialog(HWND hDlg)
{
NWDS_BUFFER *outBuf;
NWDS_ITERATION iterationHandle = -1L;
NWDSCCODE ccode;
NWCOUNT objectCount, attrCount,i;
NWOBJECT_INFO objectInfo;
char objectName[MAX_DN_CHARS];
SendDlgItemMessage(hDlg, IDC_CONTAINER_LIST, LB_RESETCONTENT, 0, 0);
SetDlgItemText(hDlg, IDC_CURRENT_CONTEXT, nContext);
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &outBuf);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSAllocBuf");
return(TRUE);
}
do
{
ccode = NWDSList(gContext,
"",
&iterationHandle,
outBuf);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSList");
NWDSFreeBuf(outBuf);
return(TRUE);
}
ccode = NWDSGetObjectCount(gContext,
outBuf,
&objectCount);
if(ccode < 0)
{
HandleCcode(hDlg, ccode ,"NWDSGetObjectCount");
NWDSFreeBuf(outBuf);
return(TRUE);
}
for(i=0; i<objectCount; i++)
{
ccode = NWDSGetObjectName(gContext,
outBuf,
objectName,
&attrCount,
&objectInfo);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSGetObjectName");
NWDSFreeBuf(outBuf);
return(TRUE);
}
if(objectInfo.objectFlags & DS_CONTAINER_ENTRY)
SendDlgItemMessage(hDlg, IDC_CONTAINER_LIST, LB_ADDSTRING, 0,
(LONG) (LPSTR) objectName);
}
}
while(iterationHandle != -1);
if(strcmp("[Root]", nContext))
SendDlgItemMessage(hDlg, IDC_CONTAINER_LIST, LB_ADDSTRING, 0,
(LONG) (LPSTR) "..");
NWDSFreeBuf(outBuf);
return(FALSE);
}
/***************************************************************************
** Changes the global context for the app when a new container is selected
*/
WORD UpdateChangedContext(HWND hDlg)
{
NWDSCCODE ccode;
char contextName[MAX_DN_CHARS];
char contextCName[MAX_DN_CHARS];
WORD n;
n = (WORD) SendDlgItemMessage(hDlg, IDC_CONTAINER_LIST, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hDlg, IDC_CONTAINER_LIST, LB_GETTEXT, n,
(LONG) (LPSTR) contextName);
if(!strcmp("..", contextName))
strcpy(contextName, ".");
ccode = NWDSCanonicalizeName(gContext, contextName, contextCName);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSCanonicalizeName");
return(ccode);
}
ccode = NWDSSetContext(gContext, DCK_NAME_CONTEXT, (void *)contextCName);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSSetContext");
return(ccode);
}
ccode = NWDSGetContext(gContext, DCK_NAME_CONTEXT, (void *)nContext);
if(ccode < 0)
{
HandleCcode(hDlg, ccode, "NWDSGetContext");
return(ccode);
}
return(FALSE);
}
/***************************************************************************
** Reads all objects listed under the current container and fills in the
** list box on the main windows with the names of all of the objects.
*/
long RefreshObjects(HWND hwnd)
{
NWDSCCODE ccode;
NWDS_ITERATION iterHandle = -1L;
NWDS_BUFFER *outBuf;
char objectName[MAX_DN_CHARS];
NWOBJECT_INFO objectInfo;
NWCOUNT objCount;
NWCOUNT attrCount;
NWCOUNT counter=0;
SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(hwnd, IDC_ATTRIBUTES, LB_RESETCONTENT, 0, 0);
SetDlgItemText(hwnd, IDC_VALUES , "");
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &outBuf);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSAllocBuf");
return 1;
}
do
{
/* "" is being passing in as the object Name because to read
all of the objects in the current context.*/
ccode = NWDSList(gContext, /* Context Handle (IN) */
"", /* Object Name (IN) */
&iterHandle, /* Iteration Handle (OUT)*/
outBuf); /* Buffer to be filled (OUT)*/
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSList");
NWDSFreeBuf(outBuf);
return 1;
}
ccode = NWDSGetObjectCount(gContext, /* Context Handle (IN) */
outBuf, /* Buffer full of info (IN) */
&objCount); /* var for # of objects (OUT)*/
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetObjectCount");
NWDSFreeBuf(outBuf);
return 1;
}
for(counter=0; counter<objCount; counter++)
{
ccode = NWDSGetObjectName(gContext, /* Context Handle (IN) */
outBuf, /* Buffer with info (IN)*/
objectName, /* object name (OUT)*/
&attrCount, /* # of attributes (OUT)*/
&objectInfo); /* Object Info (OUT)*/
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetObjectName");
NWDSFreeBuf(outBuf);
return 1;
}
SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_ADDSTRING, 0,
(LONG) (LPSTR) objectName);
}
}while(iterHandle != -1L);
SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_ADDSTRING, 0,
(LONG) (LPSTR) ".");
NWDSFreeBuf(outBuf);
return 0;
}
/***************************************************************************
** Reads all of the Attributes for the currently selected object in the
** main windows. Then fills the names of the attributes into the list
** of attributes on the main window. Note that only the Attributes that
** users have access to and that contain values will be shown.
*/
long RefreshAttributes(HWND hwnd)
{
NWDS_BUFFER *outBuf;
NWDS_ITERATION iterationHandle = -1L;
NWDSCCODE ccode;
char attrName[MAX_DN_CHARS];
char objectName[MAX_DN_CHARS];
NWCOUNT attrCount;
int i;
NWSYNTAX_ID syntax;
NWCOUNT valCount;
WORD n;
n = (WORD) SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_GETCURSEL, 0, 0L);
if(n == (WORD) LB_ERR)
{
MessageBox(hwnd, "Error", "No Object Selected!", MB_OK);
return 1;
}
SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_GETTEXT, n,
(LONG) (LPSTR) objectName);
if(!strcmp(objectName, "."))
{
strcat(objectName, nContext);
}
SendDlgItemMessage(hwnd, IDC_ATTRIBUTES, LB_RESETCONTENT, 0, 0);
SetDlgItemText(hwnd, IDC_VALUES , "");
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &outBuf);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSAllocBuf");
return 1;
}
do
{
ccode = NWDSRead(gContext, /* Context Handle (IN) */
objectName, /* name of object (IN) */
DS_ATTRIBUTE_NAMES, /* a #define (IN) */
TRUE, /* #define as 1 (IN) */
NULL, /* Attribute names (IN) */
&iterationHandle, /* iteration Handle (OUT) */
outBuf); /* Output Buffer (OUT) */
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSRead");
NWDSFreeBuf(outBuf);
return 1;
}
ccode = NWDSGetAttrCount(gContext, outBuf, &attrCount);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetAttrCount");
NWDSFreeBuf(outBuf);
return 1;
}
for(i = 0; i < attrCount; i++)
{
ccode = NWDSGetAttrName(gContext, outBuf, attrName, &valCount, &syntax);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetAttrName");
NWDSFreeBuf(outBuf);
return 1;
}
SendDlgItemMessage(hwnd, IDC_ATTRIBUTES, LB_ADDSTRING, 0,
(LONG) (LPSTR) attrName);
}
}
while(iterationHandle != -1L);
NWDSFreeBuf(outBuf);
return 0;
}
/***************************************************************************
** Reads the value of the currently selected attribute from the main window.
** Then displays the value in the text box on the main window.
*/
WORD UpdateValueListBox(HWND hwnd)
{
NWDS_BUFFER *outBuf,*inBuf;
NWDS_ITERATION iterationHandle;
NWDSCCODE ccode;
char attrName[MAX_DN_CHARS];
char objectName[MAX_DN_CHARS];
int j;
NWSIZE attrSize;
NWSYNTAX_ID syntax;
NWCOUNT valCount;
NWCOUNT totalAttrs;
char currAttr[MAX_DN_CHARS];
HANDLE htxtBuffer, htmpBuffer, hattrValue;
void *attrValue;
char *txtBuffer;
char *tmpBuffer;
char rightsstr[9];
struct date dt;
struct time tm;
WORD n;
int fHandle;
SetDlgItemText(hwnd, IDC_VALUES, "");
n = (WORD) SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hwnd, IDC_OBJECTS, LB_GETTEXT, n,
(LONG) (LPSTR) objectName);
if(!strcmp(objectName, "."))
{
strcat(objectName, nContext);
}
n = (WORD) SendDlgItemMessage(hwnd, IDC_ATTRIBUTES, LB_GETCURSEL, 0, 0L);
SendDlgItemMessage(hwnd, IDC_ATTRIBUTES, LB_GETTEXT, n,
(LONG) (LPSTR) attrName);
strset(rightsstr, '\x0');
iterationHandle = -1L;
if((htxtBuffer = GlobalAlloc(LHND, DEFAULT_MESSAGE_LEN))==NULL)
{
MessageBox(hwnd, "Could not Allocate Memory", "Error", MB_OK);
return 1;
}
if((htmpBuffer = GlobalAlloc(LHND, DEFAULT_MESSAGE_LEN))==NULL)
{
GlobalFree(htxtBuffer);
MessageBox(hwnd, "Could not Allocate Memory", "Error", MB_OK);
return 1;
}
(void *)txtBuffer = GlobalLock(htxtBuffer);
(void *)tmpBuffer = GlobalLock(htmpBuffer);
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inBuf);
if(ccode < 0)
{
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
HandleCcode(hwnd, ccode, "NWDSAllocBuf");
return(ccode);
}
ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &outBuf);
if(ccode < 0)
{
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
HandleCcode(hwnd, ccode, "NWDSAllocBuf");
NWDSFreeBuf(inBuf);
return(ccode);
}
ccode = NWDSInitBuf(gContext,DSV_READ,inBuf);
if(ccode <0)
{
HandleCcode(hwnd, ccode, "NWDSInitBuf");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
ccode = NWDSPutAttrName(gContext,inBuf,attrName);
if(ccode <0)
{
HandleCcode(hwnd, ccode, "NWDSPutAttrName");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
do
{
ccode = NWDSRead(gContext, /* Context Handle (IN) */
objectName, /* name of object (IN) */
DS_ATTRIBUTE_VALUES, /* a #define (IN) */
FALSE, /* #define as 1 (IN) */
inBuf, /* Attribute names (IN) */
&iterationHandle, /* iteration Handle (OUT) */
outBuf); /* Output Buffer (OUT) */
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSRead");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
ccode = NWDSGetAttrCount(gContext, outBuf, &totalAttrs);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetAttrCount");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
if((NWCOUNT)0 == totalAttrs)
{
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(TRUE);
}
else
{
ccode = NWDSGetAttrName(gContext, outBuf, currAttr, &valCount, &syntax);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSGetAttrName");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
for(j = 0; j < valCount; j++)
{
/* Note that the attribute value size is computed each time a value
is read. Each attribute may have multiple values and each value
may be a different size */
ccode = NWDSComputeAttrValSize(gContext, outBuf, syntax, &attrSize);
if(ccode < 0)
{
HandleCcode(hwnd, ccode, "NWDSComputeAttrValSize");
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
if((hattrValue = LocalAlloc(LHND, (UINT) attrSize))==NULL)
{
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return(ccode);
}
attrValue = LocalLock(hattrValue);
ccode = NWDSGetAttrVal(gContext, outBuf, syntax, attrValue);
if(ccode < 0)
break;
switch(syntax) /* for syntax reference see the */
{ /* NDS Schema Specification */
case SYN_BACK_LINK :
sprintf(tmpBuffer,"%lu\r\n%s\r\n",((Back_Link_T *)attrValue)->remoteID,((Back_Link_T *)attrValue)->objectName);
break;
case SYN_BOOLEAN :
sprintf(tmpBuffer,"%s\r\n", ((*((uint8 *)attrValue)) ? "TRUE" : "FALSE"));
break;
case SYN_CI_LIST :
sprintf(tmpBuffer,"%s\r\n", ((CI_List_T *)attrValue)->s);
break;
case SYN_COUNTER :
sprintf(tmpBuffer,"%lu\r\n", *((uint32 *)attrValue));
break;
case SYN_CE_STRING : /* All of these are strings */
case SYN_CI_STRING : /* and therefore are all */
case SYN_NU_STRING : /* printed the same way */
case SYN_PR_STRING :
case SYN_TEL_NUMBER :
case SYN_CLASS_NAME :
case SYN_DIST_NAME :
sprintf(tmpBuffer,"%s\r\n",(char *)attrValue);
break;
case SYN_EMAIL_ADDRESS :
sprintf(tmpBuffer,"%lu, %s\r\n", ((EMail_Address_T *)attrValue)->type, ((EMail_Address_T *)attrValue)->address);
break;
case SYN_FAX_NUMBER :
sprintf(tmpBuffer,"%s\r\n",((Fax_Number_T *)attrValue)->telephoneNumber);
break;
case SYN_HOLD :
sprintf(tmpBuffer,"%s, %lu\r\n",((Hold_T *)attrValue)->objectName,((Hold_T *)attrValue)->amount);
break;
case SYN_INTEGER :
case SYN_INTERVAL :
sprintf(tmpBuffer,"%lu\r\n",*((uint32 *)attrValue));
break;
case SYN_NET_ADDRESS :
sprintf(tmpBuffer,"Address Type:%lu\r\nAddress Length:%lu\r\nAddress:%02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X\r\n", ((Net_Address_T *)attrValue)->addressType,((Net_Address_T *)attrValue)->addressLength,((Net_Address_T *)attrValue)->address[0],((Net_Address_T *)attrValue)->address[1],((Net_Address_T *)attrValue)->address[2],((Net_Address_T *)attrValue)->address[3],((Net_Address_T *)attrValue)->address[4],((Net_Address_T *)attrValue)->address[5],((Net_Address_T *)attrValue)->address[6],((Net_Address_T *)attrValue)->address[7],((Net_Address_T *)attrValue)->address[8],((Net_Address_T *)attrValue)->address[9]);
break;
case SYN_OBJECT_ACL :
DecodeRights(((Object_ACL_T *)attrValue)->protectedAttrName, rightsstr, ((Object_ACL_T *)attrValue)->privileges);
sprintf(tmpBuffer,"%s %s %s\r\n",((Object_ACL_T *)attrValue)->protectedAttrName,rightsstr,((Object_ACL_T *)attrValue)->subjectName);
break;
case SYN_OCTET_LIST :
sprintf(tmpBuffer,"Because the syntax SYN_OCTET_LIST is a linked list\r\nit is not shown here\r\n");
break;
case SYN_OCTET_STRING :
sprintf(tmpBuffer,"Length: 0x%x\r\nData: 0x%x\r\n",((Octet_String_T *)attrValue)->length, (uint8 *)((Octet_String_T *)attrValue)->data);
break;
case SYN_PATH :
sprintf(tmpBuffer,"Name Space Type: %lu\r\n%s:%s\r\n",((Path_T *)attrValue)->nameSpaceType,((Path_T *)attrValue)->volumeName,((Path_T *)attrValue)->path);
break;
case SYN_PO_ADDRESS :
sprintf(tmpBuffer,"%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n",((char **)attrValue)[0],((char **)attrValue)[1],((char **)attrValue)[2],((char **)attrValue)[3],((char **)attrValue)[4],((char **)attrValue)[5]);
break;
case SYN_REPLICA_POINTER :
sprintf(tmpBuffer,"serverName: %s\r\nreplicaType: %lu\r\nreplicaNumber: %u\r\ncount: %lu\r\nReplica_Pointer_T.Net_Address_T not shown\r\n", ((Replica_Pointer_T *)attrValue)->serverName,((Replica_Pointer_T *)attrValue)->replicaType,((Replica_Pointer_T *)attrValue)->replicaNumber,((Replica_Pointer_T *)attrValue)->count);
break;
case SYN_STREAM :
ccode = NWDSOpenStream(gContext, objectName, currAttr, (NWDS_FLAGS)1, &fHandle);
if(!ccode)
_lread(fHandle, (void *)tmpBuffer, DEFAULT_MESSAGE_LEN);
else
{
sprintf(tmpBuffer,"NWDSOpenStream returned: %d",ccode);
MessageBox(hwnd, tmpBuffer, "View Attributes Error", MB_OK);
}
close(fHandle);
break;
case SYN_TIME :
unixtodos(*((uint32 *)attrValue), &dt, &tm);
sprintf(tmpBuffer,"%d-%d-%d %d:%d:%d\r\n", dt.da_mon, dt.da_day, dt.da_year, tm.ti_hour, tm.ti_min, tm.ti_sec);
break;
case SYN_TIMESTAMP :
unixtodos(((NWDS_TimeStamp_T *)attrValue)->wholeSeconds, &dt, &tm);
sprintf(tmpBuffer,"%d-%d-%d %d:%d:%d\r\n%lu\r\n", dt.da_mon, dt.da_day, dt.da_year, tm.ti_hour, tm.ti_min, tm.ti_sec, ((NWDS_TimeStamp_T *)attrValue)->eventID);
break;
case SYN_TYPED_NAME :
sprintf(tmpBuffer,"0x%x, 0x%x, 0x%x\r\n", ((Typed_Name_T *)attrName)->objectName, ((Typed_Name_T *)attrName)->level, ((Typed_Name_T *)attrName)->interval);
break;
default :
sprintf(tmpBuffer,"Unrecognized Sytax\r\n");
break;
}
if(!((strlen(txtBuffer)) + (strlen(txtBuffer)) > DEFAULT_MESSAGE_LEN))
strcat(txtBuffer,tmpBuffer);
else
{
MessageBox(hwnd, "The Attribute you are reading holds more information\nthan is displayed but cannot be shown here.", "Memory Limit Reached", MB_OK);
j= (int) valCount;
iterationHandle = -1L;
}
SetDlgItemText(hwnd, IDC_VALUES, txtBuffer);
LocalUnlock(hattrValue);
LocalFree(hattrValue);
}
}
}
while(iterationHandle != -1L);
GlobalUnlock(htxtBuffer);
GlobalFree(htxtBuffer);
GlobalUnlock(htmpBuffer);
GlobalFree(htmpBuffer);
NWDSFreeBuf(inBuf);
NWDSFreeBuf(outBuf);
return 0;
}
/***************************************************************************
** This procedure takes a list of rights (normally from an ACL) and
** translates then from the variable "privs" to a text format that is
** common to most network utilities.
*/
void DecodeRights(char *attrName, char *rightsstring, NWDS_PRIVILEGES privs)
{
strset(rightsstring, '\x0');
strcat(rightsstring, "[");
if(!strcmp(attrName, "[Entry Rights]"))
{
if(privs & 0x01) /* DS_ENTRY_BROWSE */
strcat(rightsstring, "B");
if(privs & 0x02) /* DS_ENTRY_ADD */
strcat(rightsstring, "A");
if(privs & 0x04) /* DS_ENTRY_DELETE */
strcat(rightsstring, "D");
if(privs & 0x08) /* DS_ENTRY_RENAME */
strcat(rightsstring, "R");
if(privs & 0x10) /* DS_ENTRY_SUPERVISOR */
strcat(rightsstring, "S");
}
else
{
if(!strcmp(attrName, "[SMS Rights]"))
{
if(privs & 0x01) /* DS_SMS_SCAN */
strcat(rightsstring, "S");
if(privs & 0x02) /* DS_SMS_BACKUP */
strcat(rightsstring, "B");
if(privs & 0x04) /* DS_SMS_RESTORE */
strcat(rightsstring, "R");
if(privs & 0x08) /* DS_SMS_RENAME */
strcat(rightsstring, "C");
if(privs & 0x10) /* DS_SMS_DELETE */
strcat(rightsstring, "D");
if(privs & 0x20) /* DS_SMS_ADMIN */
strcat(rightsstring, "A");
}
else /* Attribute Rights which applies to all others */
{
if(privs & 0x01) /* DS_ATTR_COMPARE */
strcat(rightsstring, "C");
if(privs & 0x02) /* DS_ATTR_READ */
strcat(rightsstring, "R");
if(privs & 0x04) /* DS_ATTR_WRITE */
strcat(rightsstring, "W");
if(privs & 0x08) /* DS_ATTR_SELF */
strcat(rightsstring, "A");
if(privs & 0x20) /* DS_ATTR_SUPERVISOR */
strcat(rightsstring, "S");
}
}
strcat(rightsstring,"]\x0");
}
/***************************************************************************
** This creates a process to handle an About dialog window and then creates
** the dialog. Used here to change the context.
*/
WORD ShowAboutDialog(HWND hDlg)
{
static FARPROC lpfnAboutDlgProc;
lpfnAboutDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst);
DialogBox(hInst, "About", GetActiveWindow(), lpfnAboutDlgProc);
FreeProcInstance(lpfnAboutDlgProc);
return FALSE;
}
/***************************************************************************
** This process handles all messages sent to the popup About dialog.
*/
BOOL CALLBACK AboutDlgProc (HWND hDlg, WORD message, WORD wParam, LONG lParam)
{
char aboutBox[1024];
switch (message)
{
case WM_CLOSE:
EndDialog (hDlg, 0);
return TRUE;
case WM_INITDIALOG:
strcpy(aboutBox, "This program is a viewer for Novell Directory Services (NDS)");
strcat(aboutBox, "The objects and attributes shown may vary depending rights to NDS.");
strcat(aboutBox, "Only attributes containing values are shown with this program.");
strcat(aboutBox, "\r\n\r\nDISCLAIMER\r\n\r\n");
strcat(aboutBox, "Novell, Inc. makes no representations or warranties with respect to ");
strcat(aboutBox, "any NetWare software, and specifically disclaims any express or ");
strcat(aboutBox, "implied warranties of merchantability, title, or fitness for a ");
strcat(aboutBox, "particular purpose.");
strcat(aboutBox, "\r\n\r\nDistribution of any NetWare software is forbidden without the ");
strcat(aboutBox, "express written consent of Novell, Inc. Further, Novell reserves ");
strcat(aboutBox, "the right to discontinue distribution of any NetWare software. ");
strcat(aboutBox, "\r\n\r\nNovell is not responsible for lost profits or revenue, loss of use ");
strcat(aboutBox, "of the software, loss of data, costs of re-creating lost data, the ");
strcat(aboutBox, "cost of any substitute equipment or program, or claims by any party ");
strcat(aboutBox, "other than you. Novell strongly recommends a backup be made before ");
strcat(aboutBox, "any software is installed. Technical support for this software ");
strcat(aboutBox, "may be provided at the discretion of Novell. ");
SetDlgItemText(hDlg, IDC_ABOUTBOX, aboutBox);
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDC_ABOUTOK:
EndDialog (hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}