home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
xflg1.exe
/
FLAG.C
next >
Wrap
Text File
|
1995-08-30
|
9KB
|
319 lines
/****************************************************************************
** File: FLAG.C
**
** Desc: Sample code showing how to use ChangeDirectoryEntry().
**
** 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. Developer support for this software
** may be provided at the discretion of Novell.
**
** QMK386 options used:
**
** None
**
** Programmers:
**
** Ini Who Firm
** -----------------------------------------------------------------------
** ABJ Adam B. Jerome Novell Developer Support.
**
** History:
**
** When Who What
** -----------------------------------------------------------------------
** 08-29-95 ABJ First code.
*/
/****************************************************************************
** Compiler setup
*/
/*------------------------------------------------------------------------
** ANSI
*/
#include <stdio.h> /* printf() */
#include <string.h> /* memset() */
#include <errno.h> /* ESUCCESS */
#include <sys\stat.h> /* stat(), stat */
/*------------------------------------------------------------------------
** NetWare
*/
#include <nwdir.h> /* ChangeDirectoryEntry(), MFileAttributesBit, direct.h */
/****************************************************************************
** Program help
*/
void NLM_Help(void)
{
printf("\n");
printf("Usage: LOAD FLAG {path}filename {flag{+|-}\n");
printf("\n");
printf("Flags:\n");
printf("\n");
printf(" R Read-Only\n");
printf(" H Hidden\n");
printf(" Y System\n");
printf(" E Execute-Only\n");
printf(" A Archive\n");
printf(" S Sharable\n");
printf(" XT Transactional\n");
printf(" XR Read-Audit\n");
printf(" XW Write-Audit\n");
printf(" XI Purge-Immediate\n");
printf(" XN MAC No-Rename\n");
printf(" XD MAC No-Delete\n");
printf(" XC MAC No-Copy\n");
printf("\n");
printf("Example: LOAD FLAG sys:system\\autoexec.ncf S+ XI- \n");
printf("\n");
return;
}
/****************************************************************************
** Set one bit of mask & attr as specified.
*/
void NLM_SetAttrAndMask(LONG *attr, LONG *mask, LONG bit, char value)
{
*mask |= bit;
if(value == '+')
*attr |= bit;
else
*attr = *attr & !(bit);
return;
}
/****************************************************************************
** Program start
*/
void main(int argC, char *argV[])
{
char *path = NULL;
int nCnt;
int cCode;
struct ModifyStructure des;
struct stat ss;
/*------------------------------------------------------------------------
** Initialize storage.
*/
memset(&des, 0x00, sizeof(struct ModifyStructure));
/*------------------------------------------------------------------------
** Parse command line.
*/
if(argC < 2)
{
NLM_Help();
goto END_ERR;
}
path=argV[1];
for(nCnt=2; nCnt < argC; ++nCnt)
{
switch(argV[nCnt][1])
{
case '-':
case '+':
break;
default:
switch(argV[nCnt][2])
{
case '-':
case '+':
break;
default:
NLM_Help();
goto END_ERR;
}
}
switch(argV[nCnt][0])
{
case 'R':
case 'r':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_RDONLY, argV[nCnt][1]);
break;
case 'H':
case 'h':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_HIDDEN, argV[nCnt][1]);
break;
case 'Y':
case 'y':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_SYSTEM, argV[nCnt][1]);
break;
case 'E':
case 'e':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_EXECUTE, argV[nCnt][1]);
break;
case 'A':
case 'a':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_ARCH, argV[nCnt][1]);
break;
case 'S':
case 's':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_SHARE, argV[nCnt][1]);
break;
case 'X':
case 'x':
switch(argV[nCnt][1])
{
case 'T':
case 't':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_TRANS, argV[nCnt][2]);
break;
case 'R':
case 'r':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_READAUD, argV[nCnt][2]);
break;
case 'W':
case 'w':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_WRITAUD, argV[nCnt][2]);
break;
case 'I':
case 'i':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_IMMPURG, argV[nCnt][2]);
break;
case 'N':
case 'n':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NORENAM, argV[nCnt][2]);
break;
case 'D':
case 'd':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NODELET, argV[nCnt][2]);
break;
case 'C':
case 'c':
NLM_SetAttrAndMask(&des.MFileAttributes, &des.MFileAttributesMask, _A_NOCOPY, argV[nCnt][2]);
break;
default:
NLM_Help();
goto END_ERR;
}
break;
default:
NLM_Help();
goto END_ERR;
}
}
/*------------------------------------------------------------------------
** If the user has specfied any flags, set them.
*/
if(des.MFileAttributesMask != 0L)
{
cCode=ChangeDirectoryEntry(
/* I- pathName */ path,
/* I- modifyVector */ &des,
/* I- modifyBits */ MFileAttributesBit,
/* I- allowWildCardsFlag */ 0 /* 0=No wildcards allowed */
);
if(cCode != ESUCCESS)
{
switch(cCode)
{
case 0x01:
printf("ERROR: ChangeDirectoryEntry() reports any one of the following:\n");
printf("\n");
printf(" Invalid MOwnerID in modify structure.\n");
printf(" Invalid MLastUpdateID in modify structure.\n");
printf(" Invalid MLastArchiveID in modify structure.\n");
printf(" Invalid MMaximumSpace in modify structure.\n");
printf("\n");
break;
case 0xFF:
printf("ERROR: ChangeDirectoryEntry() reports 255 (Invalid path).\n");
break;
default:
printf("ERROR: ChangeDirectoryEntry() reports %d:\n", cCode);
break;
}
goto END_ERR;
}
}
/*------------------------------------------------------------------------
** Display files flags.
*/
cCode=stat(
/* I- path */ path,
/* I- statblk */ &ss
);
if(cCode != 0)
{
printf("ERROR: stat() reports %d, errno=%d\n", cCode, errno);
goto END_ERR;
}
printf("File: %s\n", path);
printf("\n");
printf("Attributes: %s\n", (ss.st_attr & _A_RDONLY) ? "Read-Only" : "Read-Write");
printf(" %s\n", (ss.st_attr & _A_HIDDEN) ? "Hidden" : "Not-Hidden");
printf(" %s\n", (ss.st_attr & _A_SYSTEM) ? "System" : "Not-System");
printf(" %s\n", (ss.st_attr & _A_EXECUTE) ? "Execute-Only or VolumeID" : "Not Execute-Only");
printf(" %s\n", (ss.st_attr & _A_SUBDIR) ? "Directory" : "File");
printf(" %s\n", (ss.st_attr & _A_ARCH) ? "Archive" : "Not-Archive");
printf(" %s\n", (ss.st_attr & _A_SHARE) ? "Shareable" : "Non-Sharable");
printf(" %s\n", (ss.st_attr & _A_TRANS) ? "Transactional" : "Not-Transactional");
printf(" %s\n", (ss.st_attr & _A_READAUD) ? "Read-Audit" : "Non Read-Audit");
printf(" %s\n", (ss.st_attr & _A_WRITAUD) ? "Write-Audit" : "Non Write-Audit");
printf(" %s\n", (ss.st_attr & _A_IMMPURG) ? "Purge-Immediate" : "Non Purge-Immediate");
printf(" %s\n", (ss.st_attr & _A_NORENAM) ? "(MAC) No-Rename" : "(MAC) Rename");
printf(" %s\n", (ss.st_attr & _A_NODELET) ? "(MAC) No-Delete" : "(MAC) Delete");
printf(" %s\n", (ss.st_attr & _A_NOCOPY) ? "(MAC) No-Copy" : "(MAC) Copy");
printf("\n");
END_ERR:
return;
}