home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
snapx2.exe
/
SNAPX1.EXE
/
SNAPPETS.C
< prev
next >
Wrap
Text File
|
1995-02-16
|
17KB
|
649 lines
/****************************************************************************
** File: SNAPPETS.C
**
** Desc: This is a NWAdmin SNAPIN DLL module which allows the Administrator
** to add the pets that a user has. A button named "User Pets" appears
** as an NWAdmin page when "Details" is selected for a User object.
**
**
** 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
** -----------------------------------------------------------------------
** 10-03-94 klb First code.
*/
/****************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------------
** MACROS
*/
#define NWWIN
/*------------------------------------------------------------------------
** ANSI
*/
#include <windows.h>
#include <toolhelp.h>
#include <string.h>
#include <stdio.h>
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwnet.h>
#include <nwsnapin.h>
#include "snappets.h"
/*------------------------------------------------------------------------
** Prototypes
*/
#ifdef __cplusplus
extern "C"
{
#endif
N_EXTERN_LIBRARY( NWRCODE )
SnapinPetsProc(pnstr8 name, nuint16 msg, nparam p1, nparam p2);
BOOL _export FAR PASCAL petsSnapinPageDlg(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);
int ModifyUserAttrib(char *objectName);
int ReadObjectData(void);
#ifdef __cplusplus
}
#endif
/*------------------------------------------------------------------------
** Globals
*/
#define NWWIN
#define NUM_PETS_PAGES 1
char petList[20][256];
int petCount;
int petDeltaCount;
char petDeltaList[20][256];
int petChange=0;
char userObjectName[80];
HINSTANCE hDLL;
NWAPageStruct petsPages[NUM_PETS_PAGES];
/*************************************************************************
** DLL Entry Point
*/
int FAR PASCAL LibMain (HINSTANCE hInstance, WORD wDataSeg,
WORD cbHeapSize, LPSTR lpCmdLine)
{
hDLL = hInstance;
if(cbHeapSize != 0)
UnlockData (0);
return 1;
};
/*************************************************************************
** Function : InitSnapin(void)
** Description :
** Every Snapin DLL must provide this function. In this function,
** snapin menu items (under Tools) are registered. Also, object procs
** are registered.
**
*/
int _export FAR PASCAL InitSnapin()
{
/*---------------------------------------------------------------------
** Registering User class procedure
*/
NWARegisterObjectProc(
/* Class type */ NWA_DS_OBJECT_TYPE,
/* Class name */ C_USER,
/* Devel. Info */ "Novell, Inc. (C) All rights reserved.",
/* HINSTANCE */ hDLL,
/* Obj Call back */ (NWASnapinObjectProc) SnapinPetsProc,
/* Version */ NWA_SNAPIN_VERSION
);
return NWA_RET_SUCCESS;
}
/*************************************************************************
** Function : SnapinPetsProc
** Description : Snapin Procedure
** Snapin AFP Server Object Class Proc
*/
N_GLOBAL_LIBRARY( NWRCODE ) _export
SnapinPetsProc(pnstr8 objectName, nuint16 msg, nparam p1, nparam p2)
{
int err;
char returnBuf[80];
switch(msg)
{
case NWA_MSG_INITSNAPIN:
{
/*-----------------------------------------------------------
** initialize pages
*/
petsPages[0].dlgProc = (DLGPROC)petsSnapinPageDlg;
petsPages[0].resName = "SNAPPETS";
petsPages[0].pageTitle = "User Pets";
return NWA_RET_SUCCESS;
}
case NWA_MSG_GETPAGECOUNT:
{
lstrcpy(userObjectName, objectName);
petCount = 0;
petDeltaCount = 0;
err = ReadObjectData();
wsprintf(returnBuf, "ReadObjectData returned :%04X", err);
MessageBox(NULL, returnBuf,
"ReadObjectData() Returned:", MB_OK);
return NUM_PETS_PAGES;
}
case NWA_MSG_REGISTERPAGE:
{
NWAPageStruct *pageInfo = (NWAPageStruct *)p2;
pageInfo->dlgProc = petsPages[p1].dlgProc;
pageInfo->resName = petsPages[p1].resName;
pageInfo->pageTitle = petsPages[p1].pageTitle;
pageInfo->hDLL = hDLL;
pageInfo->initParam = 0;
return NWA_RET_SUCCESS;
}
case NWA_MSG_MODIFY:
{
MessageBox(NULL, "NWA_MSG_MODIFY received",
"Pets Proc", MB_OK);
err = ModifyUserAttrib(objectName);
wsprintf(returnBuf, "ModifyUserAttrib returned :%04X", err);
MessageBox(NULL, returnBuf,
"ModifyUserAttrib() Returned:", MB_OK);
return NWA_RET_SUCCESS;
}
case NWA_MSG_CLOSESNAPIN:
{
MessageBox(NULL, "NWA_MSG_CLOSESNAPIN received",
"Pets proc", MB_OK);
return NWA_RET_SUCCESS;
}
default:
break;
}
return NWA_RET_SUCCESS;
}
/*************************************************************************
** Function : PetsSnapinPageDlg
** Description :
** Page dialog to enhance User Details.
*/
BOOL _export FAR PASCAL petsSnapinPageDlg(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
char petName[255];
int numOfChars;
switch(message)
{
case WM_INITDIALOG:
{
int i;
petChange = 0;
for ( i=0; i<petCount; i++)
SendDlgItemMessage(hwnd, IDC_PETLIST, LB_ADDSTRING, 0,
(LPARAM) petList[i] );
return TRUE;
}
case NWA_WM_F1HELP:
{
MessageBox(NULL, "Enter Pets name in Edit Field!", "Snapin Help", MB_OK);
return TRUE;
}
case WM_COMMAND:
switch (wParam)
{
case IDC_ADDPET :
{
memset(petName, 0, 255);
numOfChars = GetDlgItemText(hwnd, IDC_EDITNAME, petName, 255);
if (numOfChars > 0)
{
SendMessage(hwnd, NWA_WM_SETPAGEMODIFY, (WORD)hwnd,
MAKELONG(0,TRUE));
SendDlgItemMessage(hwnd, IDC_PETLIST, LB_ADDSTRING, -1,
(LPARAM)petName);
}
}
break;
case IDC_DELETEPET :
{
int selCount, i;
int *pIndex;
HGLOBAL hmem;
selCount=SendDlgItemMessage(hwnd, IDC_PETLIST,
LB_GETSELCOUNT, 0, 0L );
if ( selCount !=LB_ERR )
{
SendMessage(hwnd, NWA_WM_SETPAGEMODIFY, (WORD) hwnd,
MAKELONG(0,TRUE));
hmem= GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT,
selCount * sizeof(int));
pIndex= (int *) GlobalLock( hmem );
selCount= SendDlgItemMessage(hwnd, IDC_PETLIST,
LB_GETSELITEMS, selCount,
(long) (int FAR *) pIndex );
for(i=selCount; i > 0 ; i--)
SendDlgItemMessage(hwnd, IDC_PETLIST, LB_DELETESTRING,
pIndex[i-1], 0L);
GlobalUnlock(hmem);
GlobalFree(hmem);
}
}
break;
}
return TRUE;
case NWA_WM_CANCLOSE:
/*-------------------------------------------------------------
** xfer data from dialog memory to program memory
** so NWA_MSG_MODIFY can save it in DS if required.
*/
{
int itemCount, i;
petChange = 1;
itemCount = SendDlgItemMessage(hwnd, IDC_PETLIST, LB_GETCOUNT,
0, 0L);
petDeltaCount=itemCount;
for(i=0; ( i<petDeltaCount ) &&
( i < MAX_PETS ) ; i++ )
SendDlgItemMessage(hwnd, IDC_PETLIST, LB_GETTEXT,
i, (LPARAM) petDeltaList[i]);
return TRUE;
}
}
return FALSE ;
}
/*************************************************************************
** Function : ModifyUserAttrib(char *name)
** Description :
** Modifys user pet values
*/
int ModifyUserAttrib(char *name)
{
NWDSContextHandle context;
int err=0, i, j;
Buf_T *inpBuf;
uint32 flags;
uint32 syntaxID;
context = NWDSCreateContext();
if ( context == ERR_CONTEXT_CREATION )
return ((int) context);
err=NWDSSetContext(context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
err = NWDSGetContext(context, DCK_FLAGS, (void *)&flags);
flags |= DCV_TYPELESS_NAMES;
flags |= DCV_XLATE_STRINGS;
flags |= DCV_DEREF_ALIASES;
flags |= DCV_DEREF_BASE_CLASS;
err = NWDSSetContext (context, DCK_FLAGS, (void *)&flags );
err=NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &inpBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
err=NWDSInitBuf(context, DSV_MODIFY_ENTRY, inpBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
/*---------------------------------------------------------------------
** Get syntaxID of Pets
*/
err = NWDSGetSyntaxID(context, "Pets", &syntaxID);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
/*---------------------------------------------------------------------
** Modify Pet Attribute values
*/
if ( petChange )
{
if ( petCount )
{
/*-----------------------------------------------------------------
** There were some Pets for the object, remove them first
*/
err = NWDSPutChange(context, inpBuf, DS_REMOVE_VALUE, "Pets");
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
for(j=0; j<petCount; j++)
{
err = NWDSPutAttrVal(context, inpBuf, syntaxID,
petList[j]);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
}
/*-------------------------------------------------------------------
** Add new list of pets selected if any
*/
if ( petDeltaCount )
{
err = NWDSPutChange(context, inpBuf, DS_ADD_VALUE, "Pets");
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
for(j=0; j<petDeltaCount; j++)
{
err = NWDSPutAttrVal(context, inpBuf, syntaxID,
petDeltaList[j]);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
}
}
}
else
{
/*------------------------------------------------------------------
** There were no pets for the object to start with.
** Add new list of pets selected ( if any )
*/
if ( petDeltaCount )
{
err = NWDSPutChange(context, inpBuf, DS_ADD_VALUE, "Pets");
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
for(j=0; j<petDeltaCount; j++)
{
err = NWDSPutAttrVal(context, inpBuf, syntaxID,
petDeltaList[j]);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
}
}
}
}
err= NWDSModifyObject(context, name, NULL, 0, inpBuf);
NWDSFreeContext(context);
NWDSFreeBuf(inpBuf);
return err;
}
/*************************************************************************
** Function : ReadObjectData
** Description :
** Function for reading
*/
int ReadObjectData()
{
NWDSContextHandle context;
int err=0, i, j;
int32 iterHandle=-1L;
Buf_T *resBuf, *nameBuf;
char *attributes[]={"Pets"};
uint32 totAttr, valCount, synID;
char attrName[MAX_DN_CHARS+1];
uint32 flags;
context = NWDSCreateContext();
if ( context == ERR_CONTEXT_CREATION )
return ( (int) context );
err=NWDSSetContext(context, DCK_NAME_CONTEXT, DS_ROOT_NAME);
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
err = NWDSGetContext(context, DCK_FLAGS, (void *)&flags);
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
flags |= DCV_TYPELESS_NAMES;
flags |= DCV_XLATE_STRINGS;
flags |= DCV_DEREF_ALIASES;
flags |= DCV_DEREF_BASE_CLASS;
err = NWDSSetContext (context, DCK_FLAGS, (void *)&flags );
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
err=NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &resBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
return err;
}
err=NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &nameBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
return err;
}
/*----------------------------------------------------------------------
** Initialize input buffer and check for errors. The output buffer does
** not need to be initialized. This buffer will be initialized to
** DSV_READ operations
*/
err=NWDSInitBuf(context, DSV_READ, nameBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
/*----------------------------------------------------------------------
** Put object attributes that are to be read into input buffer.
** Check for errors.
*/
for(i=0; i < 1; i++)
{
err= NWDSPutAttrName(context, nameBuf, attributes[i]);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
}
/*----------------------------------------------------------------------
** Read the data.
*/
iterHandle=NO_MORE_ITERATIONS;
do
{
err=NWDSRead(context, userObjectName, DS_ATTRIBUTE_VALUES,
FALSE, nameBuf, &iterHandle, resBuf);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
/*--------------------------------------------------------------------
** pull stuff out of the output buffer, checking for errors.
** First, get total no of attributes in the buffer.
*/
err=NWDSGetAttrCount(context, resBuf, &totAttr);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
for(i=0; i< totAttr; i++)
{
err=NWDSGetAttrName(context, resBuf, attrName, &valCount, &synID);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
if ( lstrcmp(attrName, "Pets") == 0 )
{
petCount = valCount;
for ( j=0; j<valCount; j++)
{
err=NWDSGetAttrVal(context, resBuf, synID,
petList[j]);
if ( err < 0 )
{
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return err;
}
}
}
}
} while ( iterHandle != NO_MORE_ITERATIONS );
NWDSFreeContext(context);
NWDSFreeBuf(resBuf);
NWDSFreeBuf(nameBuf);
return 0;
}