ABSTRACT:
This sample code demonstrates how to implement the function NWDSGetEffectiveRights(). Included executable is for DOS.
/*WARNING: This code has been marked up for HTML*/ /*DSGETRTS*/ /****************************************************************************
/****************************************************************************
/*------------------------------------------------------------------------ ** MACROS */ #define NWDOS unsigned _stklen = 8192;
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*------------------------------------------------------------------------ ** NetWare */ #include <nwnet.h> #include <nwlocale.h> #include <nwcalls.h>
/****************************************************************************
void main(int argC, char *argV[]) { NWDSCCODE cCode; NWCCODE ccode; LCONV lconvInfo; DWORD flags; NWDSContextHandle dContext; char far *countryPtr; NWDS_PRIVILEGES privs; NWCONN_HANDLE lastConnection; NWCONN_HANDLE targetHandle; char serverName[48];
if(argC < 3)
{
printf("
Usage: GETRIGHT <Object DN> <Target Object DN> <Target Server>
");
exit(1);
}
countryPtr = NWLsetlocale(LC_ALL, "");
NWLlocaleconv(&lconvInfo);
cCode = NWInitUnicodeTables(lconvInfo.country_id, lconvInfo.code_page);
if(cCode) { printf("NWInitUnicodeTables() returned: %04X ", cCode); goto _FreeUnicodeTables; }
dContext = NWDSCreateContext();
if (dContext == ERR_CONTEXT_CREATION) { printf("NWDSCreateContext returned: %04X ", cCode); goto _FreeContext; }
/*-------------------------------------------------------------------
** Get the current directory context flags so we can modify them.
*/
cCode = NWDSGetContext( /* Contxt Handle */ dContext, /* Key */ DCK_FLAGS, /* Context Flags */ &flags );
if (cCode < 0) { printf("NWDSGetContext returned: %04X ", cCode); goto _FreeContext; }
/*------------------------------------------------------------------- ** Turn typeless naming on. ** Turn canonicalize names off. This means we will get full names. */
flags |= DCV_TYPELESS_NAMES; flags &= ~DCV_CANONICALIZE_NAMES;
/*------------------------------------------------------------------- ** Set the directory context flags so they take effect. */
cCode = NWDSSetContext( /* Context Handle */ dContext, /* Key */ DCK_FLAGS, /* Set Flag Value */ &flags );
if (cCode < 0) { printf("NWDSSetContext returned: %04X ", cCode); goto _FreeContext; }
cCode = NWDSSetContext( /* Context Handle */ dContext, /* Key */ DCK_NAME_CONTEXT, /* Set Flag Value */ "[Root]" );
if (cCode < 0) { printf("NWDSSetContext returned: %04X ", cCode); goto _FreeContext; }
ccode = NWGetConnectionHandle( /* server name */ strupr(argV[3]), /* reserved */ 0, /* connection handle*/ &targetHandle, /* reserved2 */ NULL );
if (ccode) { printf("NWGetConnectionHandle returned: %04X ", cCode); printf(" Ensure that you are connection to target server!"); goto _FreeContext; }
cCode = NWDSSetContext( /* Context Handle */ dContext, /* Key */ DCK_LAST_CONNECTION, /* Set Flag Value */ &targetHandle );
if (cCode < 0) { printf("NWDSSetContext returned: %04X ", cCode); goto _FreeContext; }
cCode = NWDSGetEffectiveRights(
/* Context handle */ dContext, /* Subject Name */ argV[1], /* Object Name */ argV[2], /* Attr Name */ "[Entry Rights]", /* privileges */ &privs );
if (cCode < 0) { printf("NWDSGetEffectiveRights returned: %04X ", cCode); goto _FreeContext; }
printf("
%s has [%c%c%c%c%c] rights to %s object.", argV[1],
(privs & DS_ENTRY_BROWSE) ? 'B' : ' ',
(privs & DS_ENTRY_ADD) ? 'A' : ' ',
(privs & DS_ENTRY_DELETE) ? 'D' : ' ',
(privs & DS_ENTRY_RENAME) ? 'R' : ' ',
(privs & DS_ENTRY_SUPERVISOR) ? 'S' : ' ',
argV[2]
);
cCode = NWDSGetContext( /* Contxt Handle */ dContext, /* Key */ DCK_LAST_CONNECTION, /* Context Flags */ &lastConnection );
if (cCode < 0) { printf("NWDSGetContext returned: %04X ", cCode); goto _FreeContext; }
NWGetFileServerName( /* connection handle */ lastConnection, /* server name */ serverName );
printf(" Last Server Connection Used: %s", serverName);
_FreeContext:
NWDSFreeContext(dContext);
_FreeUnicodeTables:
NWFreeUnicodeTables();
}
�
| dsgetrts.exe | 90.3 K | 2005-04-06 |
--devsup
Categories: Sample Code | C | Directory | Developer Library | General
© 2009 Novell, Inc. All Rights Reserved.