Novell Home

TID100411 (dsgetrts) NWDSGetEffectiveRights() Sample Code

From Developer Community

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*/ /****************************************************************************

    • File: GETRIGHT.C
    • Desc: This sample code demonstrates how to perform a read operation on
    • a Directory Services object by using NWDSRead.
    • 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
    • -----------------------------------------------------------------------
    • 11-02-95 klb First code.
  • /

/****************************************************************************

    • Include headers, macros, function prototypes, etc.
  • /

/*------------------------------------------------------------------------ ** 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>


/****************************************************************************

    • Function: Main (int argC, char *argV[])
    • Initialize Unicode Tables and Create Context.
  • /

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

dsgetrts.exe90.3 K2005-04-06

--devsup

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.