home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / ALIASMOV.ZIP / ALIASMOV.CMD next >
OS/2 REXX Batch file  |  1992-05-11  |  9KB  |  267 lines

  1. /**************** REXX *************************************************/
  2. /* Moves an alias between servers or between paths on a server or both */
  3. /***********************************************************************/
  4.  
  5. parse upper arg AliasName DestUNC
  6.  
  7. if DestUNC = '' then
  8.   do
  9.   say ' '
  10.   say 'Usage is: aliasmov <Alias Name> <Dest UNC name>'
  11.   say 'Function: To move an alias between paths and preserve the access '
  12.   say '          control profile for all subdirectories'
  13.   exit
  14.   end
  15.  
  16. call ParseDestUNC
  17. call GetAliasInfo
  18. call StopShare
  19. call CreateNewAlias
  20. call SetAccess
  21. call CopyData
  22.  
  23. exit
  24.  
  25. /***********************************************************************/
  26. /* ParseDestUNC: Parse dest UNC name and break into server and         */
  27. /*                 path parts                                          */
  28. /*           Replace the $ in the path with a :                        */
  29. /***********************************************************************/
  30. ParseDestUNC:
  31.  
  32.   /* Get server name */
  33.   DestServer = left(DestUNC, pos('\', DestUNC, 3) - 1)
  34.   /* Get path and translate $ to : */
  35.   DestPath   = right(DestUNC, length(DestUNC) - pos('\', DestUNC, 3))
  36.   DestPath   = translate(DestPath, ':', '$') 
  37. return
  38.  
  39. /***********************************************************************/
  40. /* GetAliasInfo: Get information on the source alias                   */
  41. /***********************************************************************/
  42. GetAliasInfo:
  43.   'rxqueue /clear'
  44.   /* Get Alias info */
  45.   'net alias 'AliasName' | rxqueue /FIFO'
  46.   if queued() = 0 then
  47.     /* Alias doesn't exist */
  48.     do
  49.     say 'Alias 'AliasName' does not exist in this domain'
  50.     exit 2
  51.     end
  52.   parse pull junk                                  /* Alias name line */
  53.   parse pull junk':' AliasDesc                     /* Alias description line */
  54.   AliasDesc = strip(AliasDesc)
  55.   /* Translate " to ' in the description */
  56.   AliasDesc = translate(AliasDesc, '''', '"') ;
  57.   parse pull junk':' SourceServer                  /* Alias Server line */
  58.   SourceServer = strip(SourceServer)
  59.   parse pull junk':' SourcePath                    /* Alias path line */
  60.   SourcePath = strip(SourcePath)
  61.   parse upper pull junk':' AliasWhenShare          /* When shared line */
  62.   AliasWhenShare = strip(AliasWhenShare)
  63.   parse upper pull junk':' AliasUserLimit          /* Max users line */
  64.   AliasUserLimit = strip(AliasUserLimit)
  65.   parse pull junk
  66.   SourceUNC = SourceServer||'\'||SourcePath
  67.   SourceUNC = translate(SourceUNC, '$', ':')
  68. return
  69.  
  70. /***********************************************************************/
  71. /* StopShare: Turn off the share on the Source Server                  */
  72. /***********************************************************************/
  73. StopShare:
  74.   'net admin 'SourceServer' /c net share 'AliasName' /d'
  75. return
  76.  
  77. /***********************************************************************/
  78. /* CreateNewAlias: Creates the new alias and sets initial access       */
  79. /***********************************************************************/
  80. CreateNewAlias:
  81.   /* Delete old alias */
  82.   'net alias 'AliasName' /d'
  83.   /* Create new alias */
  84.   Command = 'net alias 'AliasName DestServer DestPath 
  85.   /* Set "remark" parameter */
  86.   if AliasDesc \= '' then
  87.     Command = Command '/REMARK:"'AliasDesc'"'
  88.  
  89.   /* Set "when shared" parameter */
  90.   select
  91.     when AliasWhenShare = 'AS REQUIRED BY USER' then
  92.       Command = Command '/WHEN:REQUESTED'
  93.     when AliasWhenShare = 'AT SERVER STARTUP' then
  94.       Command = Command '/WHEN:STARTUP'
  95.     when AliasWhenShare = 'BY ADMINISTRATOR' then
  96.       Command = Command '/WHEN:ADMIN'
  97.     otherwise
  98.    end
  99.  
  100.   /* Set "number of users" parameter */
  101.   if AliasUserLimit = 'NO LIMIT' then
  102.     Command = Command '/UNLIMITED'
  103.     else
  104.     Command = Command '/USERS:'AliasUserLimit
  105.  
  106.   Command
  107. return
  108.  
  109. /***********************************************************************/
  110. /* CopyData: Copy the data between paths                               */
  111. /*           This does not use NET COPY because NET COPY will not copy */
  112. /*           subdirectories                                            */
  113. /***********************************************************************/
  114. CopyData:
  115.   SourceDrive = left(SourceUNC, pos('$', SourceUNC))
  116.   DestDrive   = left(DestUNC, pos('$', DestUNC))
  117.   SourceSubPath = right(SourceUNC, length(SourceUNC) - pos('$', SourceUNC))
  118.   DestSubPath   = right(DestUNC, length(DestUNC) - pos('$', DestUNC))
  119.  
  120.   'net use s: /d'
  121.   'net use t: /d'
  122.   'net use s: 'SourceDrive
  123.   'net use t: 'DestDrive
  124.   'echo y | xcopy s:'SourceSubPath' t:'DestSubPath' /s /e'
  125.   'net use s: /d'
  126.   'net use t: /d'
  127. return
  128.  
  129. /***********************************************************************/
  130. /* SetAccess: Get access permissions from source and set them for the  */
  131. /*            destination                                              */
  132. /***********************************************************************/
  133. SetAccess:
  134.   'rxqueue /clear'
  135.   /* Get Access Control Profile info */
  136.   'net admin 'SourceServer' /c net access 'SourcePath' | rxqueue /FIFO'
  137.  
  138.   /* Get first line */
  139.   parse upper pull junk
  140.  
  141.   /* Error handling */
  142.   if junk = 'NO ENTRIES IN LIST.' then
  143.     do
  144.     say 'Could not find access control profile info for Alias 'AliasName
  145.     say 'Aborting...'
  146.     exit
  147.     end
  148.   if word(junk,1) = 'NET2222:' then
  149.     do
  150.     say 'Could not find the alias when trying to get access control info for'
  151.     say ' alias 'AliasName
  152.     say 'Aborting...'
  153.     exit
  154.     end
  155.  
  156.   /* Get dashed line */
  157.   parse pull junk
  158.  
  159.   /* Get resources and access info until done. Blank line delimits resources */
  160.   linecount = queued()
  161.   i = 0
  162.   /* Get info on resource */
  163.   parse upper pull Resource Auditing
  164.   i = i + 1
  165.  
  166.   /* Get access control info until end of input */
  167.   parse pull line
  168.   i = i + 1
  169.   AccCnt = 0
  170.   do while line \= '' & i < linecount
  171.     temp = word(line, 1)
  172.     temp = strip(temp)
  173.     if temp \= '' then
  174.       do
  175.       AccCnt = AccCnt + 1
  176.       Access.AccCnt = AccessCleanup(temp)
  177.       end
  178.     temp = word(line,2)
  179.     if temp \= '' then
  180.       do
  181.       AccCnt = AccCnt + 1
  182.       Access.AccCnt = AccessCleanup(temp)
  183.       end
  184.     parse pull line
  185.     i = i + 1
  186.     end
  187.   Access.0 = AccCnt
  188.  
  189.   /* Create Access Control profile in new position */
  190.   do j = 1 to Access.0
  191.     if AccessGrant(DestServer, DestPath, Access.j) = 'Not OK' then
  192.       if AccessAdd(DestServer, DestPath, Access.j) = 'Not OK' then
  193.         say 'Could not set access permissions of 'Access.j' for 'DestPath
  194.   end
  195.  
  196.   /* Set auditing setting */
  197.   if Auditing \= '' then
  198.     do
  199.     select
  200.       when Auditing = '( AUDITED )' then
  201.         'net admin 'DestServer' /c net access 'DestPath' /trail:yes'
  202.       when Auditing = '( AUDITED - FAILURE:ALL )' then
  203.         'net admin 'DestServer' /c net access 'DestPath' /failure:all'
  204.       when Auditing = '( AUDITED - SUCCESS:ALL   )' then
  205.         'net admin 'DestServer' /c net access 'DestPath' /success:all'
  206.       otherwise
  207.     end
  208.     end
  209. return
  210.  
  211. /***********************************************************************/
  212. /* Access Cleanup: Remove the * and cleanup the access information     */
  213. /***********************************************************************/
  214. AccessCleanup: procedure
  215.   Access = arg(1)
  216.  
  217.   Access = translate(Access, '', '*')
  218.   /* Convert the word (none) to access rights of N */
  219.   if right(Access, length(Access) - pos(':', Access)) = '(none)' then
  220.     Access = left(Access, pos(':', Access)) || 'N'
  221.   return Access
  222.  
  223. /***********************************************************************/
  224. /* AccessAdd: Do net access with Add parameter                         */
  225. /***********************************************************************/
  226. AccessAdd: procedure
  227.   Server = arg(1)
  228.   Path   = arg(2)
  229.   Access = arg(3)
  230.  
  231.   NewQ = rxqueue('Create')
  232.   OldQ = rxqueue('Set', NewQ)
  233.   'net admin 'Server' /c net access 'Path' /add 'Access' | rxqueue 'NewQ' /FIFO'
  234.   parse pull line
  235. say line
  236.   call rxqueue 'Delete', NewQ
  237.   call rxqueue 'Set', OldQ
  238.   if word(line, 1) = 'The' then
  239.     return 'OK'
  240.   else
  241.     return 'Not OK'
  242.  
  243. /***********************************************************************/
  244. /* AccessGrant: Do net access with Grant parameter                     */
  245. /***********************************************************************/
  246. AccessGrant: procedure
  247.   Server = arg(1)
  248.   Path   = arg(2)
  249.   Access = arg(3)
  250.  
  251.   NewQ = rxqueue('Create')
  252.   OldQ = rxqueue('Set', NewQ)
  253.   'net admin 'Server' /c net access 'Path' /grant 'Access' | rxqueue 'NewQ' /FIFO'
  254.   parse pull line
  255. say line
  256.   call rxqueue 'Delete', NewQ
  257.   call rxqueue 'Set', OldQ
  258.  
  259.   /* Check to see if the  */
  260.   if word(line,1) = 'The' then
  261.     return 'OK'
  262.   else
  263.     return 'Not OK'
  264.  
  265.  
  266.  
  267.