home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxnet2.zip / SETPERM.CMD < prev    next >
OS/2 REXX Batch file  |  1993-10-11  |  6KB  |  282 lines

  1. /*
  2.     SetPerm.CMD
  3.  
  4.     Set Network Permissions for Files and Directory
  5.  
  6.     Written: Steven Elliott, September 1993
  7.  
  8.     Requires REXXNET.DLL
  9.  
  10.  
  11.     Usage: SetPerm [-SD] resource [user:perm ...]
  12.        SetPerm -F filename
  13.  
  14.     Apply the permissions to the resource
  15.     if -S is given apply to all subdirs as well
  16.     if -D is given the delete all permissions
  17.     if -F is given then the permissions in the file are set
  18. */
  19.  
  20. /*
  21. **********************************************************************
  22.   GLOBAL VARIABLES
  23. */
  24.  
  25. version = 1.1
  26. tab = D2C(9)
  27. cr = D2C(13)
  28. recursive = 0
  29. delete = 0
  30. fromfile = 0
  31. delfirst = 0
  32.  
  33. /*********************************************/
  34.  
  35. call rxfuncadd SysLoadFuncs, "RexxUtil", SysLoadFuncs
  36. call SysLoadFuncs
  37. call rxfuncadd NetLoadFuncs, "RexxNet", NetLoadFuncs
  38. call NetLoadFuncs
  39. signal on syntax
  40. signal on halt
  41.  
  42. if arg() = 0 then
  43.   signal usage
  44. parse upper arg opt cmdline
  45. if left(opt, 1) = '-' then do
  46.   if pos('S', opt) \= 0 then
  47.     recursive = 1
  48.   if pos('D', opt) \= 0 then
  49.     delete = 1
  50.   if pos('F', opt) \= 0 then
  51.     fromfile = 1
  52. end
  53. else
  54.     cmdline = opt cmdline
  55. if \ fromfile then
  56.   call main
  57. else
  58.   call dofile
  59. say "Command completed successfully"
  60.  
  61. done:
  62. call NetDropFuncs
  63. call SysDropFuncs
  64. exit
  65.  
  66. halt:
  67. say "SetPerm interrupted"
  68. signal done
  69.  
  70. syntax:
  71. say ""
  72. say "Sorry, I've got a headache,"
  73. say "I don't think I can help you at the moment"
  74. say ""
  75. say "Line:" sigl " Error:" rc ':' errortext(rc)
  76. signal done
  77.  
  78. usage:
  79. say "Usage: SetPerm [-sd] drive:path [user:perm ...]"
  80. say "       SetPerm -f filename"
  81. say "       -s - Include Subdirectories"
  82. say "       -d - Delete Permissions"
  83. say "       -f - read drive:path permissions from file"
  84. signal done
  85.  
  86.  
  87. main:
  88.   parse upper var cmdline resource userlist
  89.   Server = ''
  90.   retc = NetAccessGetInfo(Server, resource, 1, aInfo)
  91.   if retc \= 0 & retc \= 2222 then  /* Not found */
  92.     signal neterr
  93.   if delete then do
  94.     say 'Removing Permissions on' resource
  95.     retc = NetAccessDel(Server, resource)
  96.     if retc \= 0 & retc \= 2222 then
  97.       signal neterr
  98.     if recursive then do
  99.       retc = SysFileTree(resource'\*', SubDirs, 'DSO')
  100.       if retc \= 0 then do
  101.     say "Sorry, there are too many sub-directories for this command"
  102.     say "You'll have to use NET"
  103.     return
  104.       end
  105.       do i = 1 to SubDirs.0
  106.     say 'Removing Permissions on' SubDirs.i
  107.     retc = NetAccessDel(Server, SubDirs.i)
  108.     if retc \= 0 & retc \= 2222 then
  109.         call neterr
  110.       end
  111.     end
  112.     return
  113.   end
  114.   ainfo.resource_name = resource
  115.   ainfo.attr = 0
  116.   ainfo.count = 0
  117.   do forever
  118.     parse var userlist next userlist
  119.     if next = '' then
  120.       leave
  121.     parse var next user ':' perm
  122.     add = ainfo.count
  123.     ainfo.access_list.add.ugname = user
  124.     ainfo.access_list.add.access = stoa(perm)
  125.     ainfo.count = add + 1
  126.   end
  127.   if \ change() then
  128.     return
  129.   if recursive \= 0 then do
  130.     retc = SysFileTree(aInfo.resource_name'\*', SubDirs, 'DOS')
  131.     if retc \= 0 then do
  132.       say "Sorry, there are too many sub-directories for this command"
  133.       say "You'll have to use NET"
  134.       return
  135.     end
  136.     do i = 1 to SubDirs.0
  137.       aInfo.resource_name = SubDirs.i
  138.       if \ change() then
  139.     leave
  140.     end
  141.   end
  142. return
  143.  
  144.  
  145. change:
  146.   say "Setting" aInfo.resource_name
  147.   if delfirst then
  148.     retc = NetAccessDel(Server, aInfo.resource_name)
  149.   retc = NetAccessAdd(Server, 1, aInfo)
  150.   if retc = 0 then
  151.     return 1
  152.   if retc = 2225 then do /* Resource exists */
  153.     rect = NetAccessGetInfo(Server, aInfo.resource_name, 1, gInfo)
  154.     call charout '', "Permissions already exist for" aInfo.resource_name "-"
  155.     do j = 0 to gInfo.count - 1
  156.       call charout '', ' 'gInfo.access_list.j.ugname':'atos(gInfo.access_list.j.access)
  157.     end
  158.     say ""
  159.     call charout '', "R)eplace, Replace A)ll, S)kip or Q)uit (R/A/S/Q) --> "
  160.     parse upper pull option
  161.     option = left(option, 1)
  162.     select
  163.     when option = 'A' then do
  164.       delfirst = 1
  165.       retc = NetAccessDel(Server, aInfo.resource_name)
  166.       retc = NetAccessAdd(Server, 1, aInfo)
  167.       if retc \= 0 then
  168.     call neterr
  169.       return 1
  170.     end
  171.     when option = 'S' then
  172.       return 1
  173.     when option = 'R' then do
  174.       retc = NetAccessDel(Server, aInfo.resource_name)
  175.       retc = NetAccessAdd(Server, 1, aInfo)
  176.       if retc \= 0 then
  177.     call neterr
  178.     end
  179.     when option = 'Q' then
  180.       return 0
  181.     end
  182.   end
  183.   else
  184.     call neterr
  185. return 1
  186.  
  187. dofile:
  188.   filename = cmdline
  189.   if stream(filename, 'C', 'OPEN') \= 'READY:' then do
  190.     say "Unable to access" cmdline
  191.     return
  192.   end
  193.   recursive = 0
  194.   do forever
  195.     cmdline = linein(filename)
  196.     if stream(filename, 'S') \= 'READY' then
  197.     leave
  198.     call main
  199.   end
  200. return
  201.  
  202.  
  203.  
  204. /*
  205.     S T O A - String to Access
  206.  
  207.     Convert a string of letters into the appropriate number
  208. */
  209. stoa: procedure
  210.   access = 0
  211.   string = arg(1)
  212.   if string = 'ALL' then
  213.     return 255
  214.   if pos('R', string) \= 0 then
  215.     access = access + 1
  216.   if pos('W', string) \= 0 then
  217.     access = access + 2
  218.   if pos('C', string) \= 0 then
  219.     access = access + 4
  220.   if pos('X', string) \= 0 then
  221.     access = access + 8
  222.   if pos('D', string) \= 0 then
  223.     access = access + 16
  224.   if pos('A', string) \= 0 then
  225.     access = access + 32
  226.   if pos('P', string) \= 0 then
  227.     access = access + 64
  228.   if pos('Y', string) \= 0 then
  229.     access = 4
  230. return access
  231.  
  232.  
  233. atos: procedure
  234.   if arg(1) < 0 then
  235.     access = 32768 + arg(1)
  236.   else
  237.     access = arg(1)
  238.   string = ''
  239.   if access = 127 then
  240.     return 'RWCXDAP'
  241.   if access > 63 then do
  242.     string = 'P'
  243.     access = access - 64
  244.   end
  245.   if access > 31 then do
  246.     string = 'A'string
  247.     access = access - 32
  248.   end
  249.   if access > 15 then do
  250.     string = 'D'string
  251.     access = access - 16
  252.   end
  253.   if access > 7 then do
  254.     string = 'X'string
  255.     access = access - 8
  256.   end
  257.   if access > 3 then do
  258.     string = 'C'string
  259.     access = access - 4
  260.   end
  261.   if access > 1 then do
  262.     string = 'W'string
  263.     access = access - 2
  264.   end
  265.   if access > 0 then do
  266.     string = 'R'string
  267.   end
  268. return string
  269.  
  270.  
  271. neterr:
  272. if retc \= 0 then do
  273.     if retc < 2100 then
  274.     say NetGetMessage(retc)
  275.     else
  276.     say NetGetMessage(retc, "NET.MSG")
  277. end
  278. call charout '', "Hit ENTER to continue "
  279. parse pull operation
  280. return
  281.  
  282.