home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rxnet2.zip
/
SETPERM.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-10-11
|
6KB
|
282 lines
/*
SetPerm.CMD
Set Network Permissions for Files and Directory
Written: Steven Elliott, September 1993
Requires REXXNET.DLL
Usage: SetPerm [-SD] resource [user:perm ...]
SetPerm -F filename
Apply the permissions to the resource
if -S is given apply to all subdirs as well
if -D is given the delete all permissions
if -F is given then the permissions in the file are set
*/
/*
**********************************************************************
GLOBAL VARIABLES
*/
version = 1.1
tab = D2C(9)
cr = D2C(13)
recursive = 0
delete = 0
fromfile = 0
delfirst = 0
/*********************************************/
call rxfuncadd SysLoadFuncs, "RexxUtil", SysLoadFuncs
call SysLoadFuncs
call rxfuncadd NetLoadFuncs, "RexxNet", NetLoadFuncs
call NetLoadFuncs
signal on syntax
signal on halt
if arg() = 0 then
signal usage
parse upper arg opt cmdline
if left(opt, 1) = '-' then do
if pos('S', opt) \= 0 then
recursive = 1
if pos('D', opt) \= 0 then
delete = 1
if pos('F', opt) \= 0 then
fromfile = 1
end
else
cmdline = opt cmdline
if \ fromfile then
call main
else
call dofile
say "Command completed successfully"
done:
call NetDropFuncs
call SysDropFuncs
exit
halt:
say "SetPerm interrupted"
signal done
syntax:
say ""
say "Sorry, I've got a headache,"
say "I don't think I can help you at the moment"
say ""
say "Line:" sigl " Error:" rc ':' errortext(rc)
signal done
usage:
say "Usage: SetPerm [-sd] drive:path [user:perm ...]"
say " SetPerm -f filename"
say " -s - Include Subdirectories"
say " -d - Delete Permissions"
say " -f - read drive:path permissions from file"
signal done
main:
parse upper var cmdline resource userlist
Server = ''
retc = NetAccessGetInfo(Server, resource, 1, aInfo)
if retc \= 0 & retc \= 2222 then /* Not found */
signal neterr
if delete then do
say 'Removing Permissions on' resource
retc = NetAccessDel(Server, resource)
if retc \= 0 & retc \= 2222 then
signal neterr
if recursive then do
retc = SysFileTree(resource'\*', SubDirs, 'DSO')
if retc \= 0 then do
say "Sorry, there are too many sub-directories for this command"
say "You'll have to use NET"
return
end
do i = 1 to SubDirs.0
say 'Removing Permissions on' SubDirs.i
retc = NetAccessDel(Server, SubDirs.i)
if retc \= 0 & retc \= 2222 then
call neterr
end
end
return
end
ainfo.resource_name = resource
ainfo.attr = 0
ainfo.count = 0
do forever
parse var userlist next userlist
if next = '' then
leave
parse var next user ':' perm
add = ainfo.count
ainfo.access_list.add.ugname = user
ainfo.access_list.add.access = stoa(perm)
ainfo.count = add + 1
end
if \ change() then
return
if recursive \= 0 then do
retc = SysFileTree(aInfo.resource_name'\*', SubDirs, 'DOS')
if retc \= 0 then do
say "Sorry, there are too many sub-directories for this command"
say "You'll have to use NET"
return
end
do i = 1 to SubDirs.0
aInfo.resource_name = SubDirs.i
if \ change() then
leave
end
end
return
change:
say "Setting" aInfo.resource_name
if delfirst then
retc = NetAccessDel(Server, aInfo.resource_name)
retc = NetAccessAdd(Server, 1, aInfo)
if retc = 0 then
return 1
if retc = 2225 then do /* Resource exists */
rect = NetAccessGetInfo(Server, aInfo.resource_name, 1, gInfo)
call charout '', "Permissions already exist for" aInfo.resource_name "-"
do j = 0 to gInfo.count - 1
call charout '', ' 'gInfo.access_list.j.ugname':'atos(gInfo.access_list.j.access)
end
say ""
call charout '', "R)eplace, Replace A)ll, S)kip or Q)uit (R/A/S/Q) --> "
parse upper pull option
option = left(option, 1)
select
when option = 'A' then do
delfirst = 1
retc = NetAccessDel(Server, aInfo.resource_name)
retc = NetAccessAdd(Server, 1, aInfo)
if retc \= 0 then
call neterr
return 1
end
when option = 'S' then
return 1
when option = 'R' then do
retc = NetAccessDel(Server, aInfo.resource_name)
retc = NetAccessAdd(Server, 1, aInfo)
if retc \= 0 then
call neterr
end
when option = 'Q' then
return 0
end
end
else
call neterr
return 1
dofile:
filename = cmdline
if stream(filename, 'C', 'OPEN') \= 'READY:' then do
say "Unable to access" cmdline
return
end
recursive = 0
do forever
cmdline = linein(filename)
if stream(filename, 'S') \= 'READY' then
leave
call main
end
return
/*
S T O A - String to Access
Convert a string of letters into the appropriate number
*/
stoa: procedure
access = 0
string = arg(1)
if string = 'ALL' then
return 255
if pos('R', string) \= 0 then
access = access + 1
if pos('W', string) \= 0 then
access = access + 2
if pos('C', string) \= 0 then
access = access + 4
if pos('X', string) \= 0 then
access = access + 8
if pos('D', string) \= 0 then
access = access + 16
if pos('A', string) \= 0 then
access = access + 32
if pos('P', string) \= 0 then
access = access + 64
if pos('Y', string) \= 0 then
access = 4
return access
atos: procedure
if arg(1) < 0 then
access = 32768 + arg(1)
else
access = arg(1)
string = ''
if access = 127 then
return 'RWCXDAP'
if access > 63 then do
string = 'P'
access = access - 64
end
if access > 31 then do
string = 'A'string
access = access - 32
end
if access > 15 then do
string = 'D'string
access = access - 16
end
if access > 7 then do
string = 'X'string
access = access - 8
end
if access > 3 then do
string = 'C'string
access = access - 4
end
if access > 1 then do
string = 'W'string
access = access - 2
end
if access > 0 then do
string = 'R'string
end
return string
neterr:
if retc \= 0 then do
if retc < 2100 then
say NetGetMessage(retc)
else
say NetGetMessage(retc, "NET.MSG")
end
call charout '', "Hit ENTER to continue "
parse pull operation
return