home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
chgrht.exe
/
CHGRGHTS.C
next >
Wrap
C/C++ Source or Header
|
1995-06-08
|
8KB
|
266 lines
/****************************************************************************
** 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.
****************************************************************************
**
** File: chgrghts.c
**
** Desc: This program will change the Inherited rights mask of a specified
** directory then show you the IRM for that directory or if only the
** path is specified it will return the current IRM for that directory.
**
**
** Programmers:
** Ini Who Firm
** ------------------------------------------------------------------
** ARM A. Ray Maxwell Novell Developer Support.
**
** History:
**
** ------------------------------------------------------------------
** 06-08-95 ARM First code.
*/
/***************************************************************************
** Include headers, macros, function prototypes, etc.
*/
/*------------------------------------------------------------------
** ANSI
*/
#include <stdio.h>
#include <string.h> /* printf() */
#include <stdlib.h> /* exit() */
extern unsigned _stklen=8000;
/*------------------------------------------------------------------
** NetWare
*/
#include <nwcalls.h>
/****************************************************************************
** Program Start
*/
void main (int argc, char *argv[])
{
NWCCODE ccode;
NWCONN_HANDLE conn;
NWCONN_NUM connNumber;
NWDIR_HANDLE dirHandle;
NWDIR_HANDLE newDirHandle;
NWFLAGS attrib;
NWSEQUENCE sequence;
NWCHANGE_BITS bits;
NWENTRY_INFO entryInfo;
NWACCESS_RIGHTS maxRightsMask;
NWOBJ_ID objectID;
DWORD currDateTime;
char dir[100];
char newPath[100];
int i;
if (argc == 1)
{
printf("\nUsage: DINFO <PATH> {OPTIONS}\n");
printf("Where options can be zero or more of the following:\n");
printf("__________________________________________________\n");
printf("\nR\t\tREAD\n");
printf("W\t\tWRITE\n");
printf("C\t\tCREATE\n");
printf("D\t\tDELETE\n");
printf("A\t\tACCESS CONTROL\n");
printf("F\t\tFILE SCAN\n");
printf("M\t\tMODIFY\n");
printf("S\t\tSUPERVISOR\n");
printf("If no options given program returns current IRM.\n");
printf("\n\n?\t\tBrings up this help screen\n");
exit(0);
}
ccode=NWCallsInit (NULL,NULL);
if (ccode)
{
printf("NWCallsInit failed: %X\n",ccode);
exit(1);
}
strcpy (dir, strupr(argv[1]));
ccode=NWParseNetWarePath(
/* > path to parse */ dir,
/* < server connection Handle */ &conn,
/* < directory Handle */ &dirHandle,
/* < new path relative to directory Handle*/ newPath);
if (ccode)
{
printf("NWParseNetWarePath failed: %X\n",ccode);
exit(1);
}
/*-----------------------------------------------------------------------
** Get a temporary directory handle
*/
ccode = NWAllocTemporaryDirectoryHandle(
/* > connection Handle */ conn,
/* > Directory Handle */ dirHandle,
/* > pointer to absolute dir path */ newPath,
/* < pointer to new dir handle */ &newDirHandle,
/* <pointer to trustee rights */ NULL);
if (ccode)
{
printf("NWAllocTemporarydirectoryHandle failed: %X\n",ccode);
exit(1);
}
if (argc >= 3)
{
sequence = -1;
ccode=NWScanDirEntryInfo(
/* > Connection Handle */ conn,
/* > directory Handle */ newDirHandle,
/* > Search attrib */ FA_DIRECTORY,
/* > Sequence number */ &sequence,
/* > Search Pattern */ NULL,
/* < Entry info */ &entryInfo);
if (ccode == INVALID_PATH)
printf("\nInvalid Path Specification. Directory does not exist!\n");
else if(ccode)
{
printf("NWScanDirEntryInfo failed: %X\n",ccode);
exit(1);
}
maxRightsMask = 0x00;
for (i=2; i<argc; i++)
{
switch(argv[i][0])
{
case 'S':
case 's':
maxRightsMask = (maxRightsMask | TR_SUPERVISOR);
break;
case 'R':
case 'r':
maxRightsMask = (maxRightsMask | TR_READ);
break;
case 'W':
case 'w':
maxRightsMask = (maxRightsMask | TR_WRITE);
break;
case 'C':
case 'c':
maxRightsMask = (maxRightsMask | TR_CREATE);
break;
case 'D':
case 'd':
maxRightsMask = (maxRightsMask | TR_DELETE);
break;
case 'A':
case 'a':
maxRightsMask = (maxRightsMask | TR_ACCESS_CTRL);
break;
case 'F':
case 'f':
maxRightsMask = (maxRightsMask | TR_FILE_SCAN);
break;
case 'M':
case 'm':
maxRightsMask = (maxRightsMask | TR_MODIFY);
break;
}
}
ccode=NWGetConnectionNumber(
/* > Connection handle */ conn,
/* > Connect. number */ &connNumber
);
if (ccode)
{
printf("NWGetConnectionNumber failed: %X\n",ccode);
exit(1);
}
ccode=NWGetConnectionInformation(
/* > connection handle */ conn,
/* > connection Number */ connNumber,
/* < Object Name */ NULL,
/* < Object Type */ NULL,
/* < Object ID */ &objectID,
/* < Login Time */ NULL
);
if (ccode)
{
printf("NWGetConnectionInformation failed: %X\n",ccode);
exit(1);
}
ccode=NWSetDirectoryInformation(
/* > connection Handle */ conn,
/* > dirHandle */ 0,
/* > dir Path */ newPath,
/* > Packed date and time */ currDateTime,
/* > Object ID */ objectID,
/* > Rights mask */ maxRightsMask
);
if (ccode)
{
printf("NWSetDirectoryInformation failed: %X\n",ccode);
exit(1);
}
}
ccode=NWScanDirEntryInfo(
/* > Connection Handle */ conn,
/* > directory Handle */ newDirHandle,
/* > Search attrib */ FA_DIRECTORY,
/* > Sequence number */ &sequence,
/* > Search Pattern */ NULL,
/* < Entry info */ &entryInfo);
if (ccode)
{
printf("NWScanDirEntryInfo failed: %X\n",ccode);
exit(1);
}
printf("\nDirectory Name: %s", newPath);
printf("\nInherited Rights Mask: [%c%c%c%c%c%c%c%c]\n",
(entryInfo.info.dir.inheritedRightsMask & TR_SUPERVISOR) ? 'S' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_READ) ? 'R' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_WRITE) ? 'W' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_CREATE) ? 'C' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_DELETE) ? 'D' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_ACCESS_CTRL) ? 'A' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_FILE_SCAN) ? 'F' : ' ',
(entryInfo.info.dir.inheritedRightsMask & TR_MODIFY) ? 'M' : ' ');
}