Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


NetWareX_UDF_Library

Keywords: 	 NetWareX_UDF_Library

; NetWareX_UDF_Library.wbt
; 32-bit
;
; This is a WinBatch script file intended to be included via "#include" in another
; script.  This file contains UDFs defined to provide additional functionality for
; the NetWareX extender.
;
; The account under which this is run must have appropriate rights in NDS to read
; the "App:FS Rights Path" and "App:FS Rights Volume" attributes on the specified
; application object.
;
;
; This UDF library requires that the NetWareX extender "WWNWX34I.DLL" and the WILX
; extender "WILX34I.DLL" be loaded in the script that includes this library.  The
; script must have loaded these extenders prior to the "#include" command that 
; includes this library or else an error will occur.
;
;
; UDFs defined in this library:
;
; nwGetAppFileRightsUDF(AppObjSpec,Flags)
;
;   Parameters:
;
;     AppObjSpec = specification of an application object in NDS
;     Flags = bit mask of flags that control how this function operates
;
;       If bit #0 [value = 1 when enabled] is enabled then directory trustee
;       assignments will be returned.
;
;       If bit #1 [value = 2 when enabled] is enabled then file trustee
;       assignments will be returned.
;
;       If neither bit #0 not bit #1 are enabled, or if both of those bits
;       are enabled, then both directory and file trustee assignments will
;       be returned.
;
;   Returns:
;
;     A value delimited list of field delimited records will be returned.  The
;     value delimiter will default to @TAB, unless the NetWareX extender's
;     value delimiter has been changed to some other value.  Likewise, the field
;     delimiter used within a record will default to the pipe "|" character unless
;     the NetWareX extender's field delimiter has been changed to some other value.
;
;     The following record layout will exist:
;
;     |||
;
;     Where the following conditions apply:
;
;        is the complete volume spec & path information in UNC format.
;
;        will be either "D" [for directories] or "F" [for files].
;
;        will be the actual integer value [decimal] for the
;       trustee rights that have been assigned.
;
;        will be a character string containing one letter
;       [in upper case] for each particular trustee right that is enabled.
;
;       Refer to the help text in the NetWareX extender's help file for the functions
;       nwGetDirInfo() and nwGetFileInfo() for a full description of the trustee
;       rights bit mask values and their corresponding mnemonic codes.
;
;
;
; Minor Error codes used by this UDF library:
;
; 7000 = 'AppObjSpec is not an application object'
; 7001 = 'Unable to get object class of AppObjSpec'
; 7002 = 'Cannot get "App:FS Rights Path" value for AppObjSpec'
; 7003 = 'Cannot get "App:FS Rights Volume" value for AppObjSpec'
; 7004 = 'Cannot get tree name for AppObjSpec'
; 7005 = 'A required extender is not loaded'
;
;


; Get the list of loaded extenders...

TempUDF_LoadedExtenders = IntControl(77,42,0,0,0)

for TempUDF_I = 1 to ItemCount(TempUDF_LoadedExtenders,@TAB)
  TempUDF_Item = ItemExtract(TempUDF_I,TempUDF_LoadedExtenders,@TAB)
  TempUDF_Item = StrUpper(StrCat(FileRoot(TempUDF_Item),'.',FileExtension(TempUDF_Item)))
  TempUDF_LoadedExtenders = ItemReplace(TempUDF_Item,TempUDF_I,TempUDF_LoadedExtenders,@TAB)
next


; Add in a required extender [if it is not already loaded]

if (ItemLocate('WWNWX34I.DLL',TempUDF_LoadedExtenders,@TAB) == 0)
  IntControl(79,-1,7005,'A required extender is not loaded',0)
endif


; Add in a required extender [if it is not already loaded]

if (ItemLocate('WILX34I.DLL',TempUDF_LoadedExtenders,@TAB) == 0)
  IntControl(79,-1,7005,'A required extender is not loaded',0)
endif


; Done with some temporary variables that we don't want to leave hanging around in the main script...

DropWild('TempUDF_*')


#DefineFunction nwVersionUDF(Flags)

return 1

#EndFunction



#DefineFunction nwGetAppFileRightsUDF(AppObjSpec,Flags)


; Parse the flags...

if (Flags & 1)
  bGetDirs = @TRUE
else
  bGetDirs = @FALSE
endif

if (Flags & 2)
  bGetFiles = @TRUE
else
  bGetFiles = @FALSE
endif

if (!(bGetDirs || bGetFiles))
  bGetDirs = @TRUE
  bGetFiles = @TRUE
endif


; Determine if the object is an application object...

ErrorMode(@OFF)
ObjectClass = nwGetObjInfo(AppObjSpec,1)
RC = LastError()
ErrorMode(@CANCEL)

if (RC)
  IntControl(79,-1,7001,'Unable to get object class of AppObjSpec',0)
endif

if (ObjectClass != 'App:Application')
  IntControl(79,-1,7000,'AppObjSpec is not an application object',0)
endif


; Get the NDS tree name associated with AppObjSpec...

ErrorMode(@OFF)
TreeName = nwNameConvert(AppObjSpec,8)
RC = LastError()
ErrorMode(@CANCEL)

if (RC)
  IntControl(79,-1,7004,'Cannot get tree name for AppObjSpec',0)
endif


; Get the delimiters that are in use...

ValueDelim = nwGetOptions(8)
FieldDelim = nwGetOptions(9)


; Temporarily modify some NetWareX extender options to meet our needs...

bSaveBinStringCvt = nwGetOptions(11)

nwSetOptions(11,@FALSE)


; Get the app object's "App:FS Rights Path" attribute value...

ErrorMode(@OFF)
AppFSRightsPath = nwGetObjValue(AppObjSpec,'App:FS Rights Path',0,0,1)
RC = LastError()
ErrorMode(@CANCEL)

if (RC)
  nwSetOptions(11,bSaveBinStringCvt)
  if ((RC == 274) || (RC == 275))
    ; The attribute does not exist on the specified object.
    return ''
  else
    IntControl(79,-1,7002,'Cannot get "App:FS Rights Path" value for AppObjSpec',0)
  endif
endif


; Get the app object's "App:FS Rights Volume" attribute value...

ErrorMode(@OFF)
AppFSRightsVolume = nwGetObjValue(AppObjSpec,'App:FS Rights Volume',0,0,1)
RC = LastError()
ErrorMode(@CANCEL)

if (RC)
  nwSetOptions(11,bSaveBinStringCvt)
  if ((RC == 274) || (RC == 275))
    ; The attribute does not exist on the specified object.
    return ''
  else
    IntControl(79,-1,7003,'Cannot get "App:FS Rights Volume" value for AppObjSpec',0)
  endif
endif


; Restore this setting as we are done with it...

nwSetOptions(11,bSaveBinStringCvt)


; Parse the volume list and remove unneeded field values from it...

for i = 1 to ItemCount(AppFSRightsVolume,ValueDelim)
  Volume = ItemExtract(i,AppFSRightsVolume,ValueDelim)
  Volume = ItemExtract(1,Volume,FieldDelim)
  AppFSRightsVolume = ItemReplace(Volume,i,AppFSRightsvolume,ValueDelim)
next


; Initialize the return string...

RightsList = ''


; Now we do some serious work tearing apart the AppFSRightsPath hex strings...

for i = 1 to ItemCount(AppFSRightsPath,FieldDelim)
  PathHEX = ItemExtract(i,AppFSRightsPath,FieldDelim)

  FileFlagHEX = StrSub(PathHEX,25,2)
  bFileFlag = xBaseConvert(FileFlagHEX,16,10)

  ; Only return the types of paths that were requested...

  if (!((bGetFiles && bFileFlag) || (bGetDirs && !bFileFlag))) then next

  if (bFileFlag)
    DirFileFlag = 'F'
  else
    DirFileFlag = 'D'
  endif

  VolNumHEX = StrCat(StrSub(PathHEX,7,2),StrSub(PathHEX,5,2),StrSub(PathHEX,3,2),StrSub(PathHEX,1,2))
  VolNum = xBaseConvert(VolNumHEX,16,10) + 1  ; Add one so that we can use it in ItemExtract()...

  Field2HEX = StrCat(StrSub(PathHEX,15,2),StrSub(PathHEX,13,2),StrSub(PathHEX,11,2),StrSub(PathHEX,9,2))
  Field2 = xBaseConvert(Field2HEX,16,10)

  RightsHEX = StrCat(StrSub(PathHEX,23,2),StrSub(PathHEX,21,2),StrSub(PathHEX,19,2),StrSub(PathHEX,17,2))
  Rights = xBaseConvert(RightsHEX,16,10)

  VolName = ItemExtract(VolNum,AppFSRightsVolume,ValueDelim)

  RightsCodes = ''

  ; Put the rights codes in the order that RIGHTS.EXE and NWADMN32.EXE put them in...

  if (Rights & 256) then RightsCodes = StrCat(RightsCodes,'S')
  if (Rights & 1) then RightsCodes = StrCat(RightsCodes,'R')
  if (Rights & 2) then RightsCodes = StrCat(RightsCodes,'W')
  if (Rights & 8) then RightsCodes = StrCat(RightsCodes,'C')
  if (Rights & 16) then RightsCodes = StrCat(RightsCodes,'E')
  if (Rights & 128) then RightsCodes = StrCat(RightsCodes,'M')
  if (Rights & 64) then RightsCodes = StrCat(RightsCodes,'F')
  if (Rights & 32) then RightsCodes = StrCat(RightsCodes,'A')

  ; Build the path specification...

  PathSpec = ''

  for j = 27 to (StrLen(PathHEX) / 2) by 2
    CharVal = xBaseConvert(StrSub(PathHEX,j,2),16,10)
    if (CharVal != 0)
      PathSpec = StrCat(PathSpec,Num2Char(CharVal))
    else
      break
    endif
  next

  RightsRec = StrCat(TreeName,'\',VolName,PathSpec,FieldDelim,DirFileFlag,FieldDelim,Rights,FieldDelim,RightsCodes)

  RightsList = ItemInsert(RightsRec,-1,RightsList,ValueDelim)
next


return RightsList

#EndFunction