home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lsmt213c.zip / lsdcdb.cmd < prev    next >
OS/2 REXX Batch file  |  2000-04-17  |  10KB  |  279 lines

  1. /*---------------------------------------------------------------------------*\
  2. |  Check DCDB's                               (C) Alain Rykaert - MAR96-FEB00 |
  3. \*---------------------------------------------------------------------------*/
  4.     Version = '3.10a'
  5.     Say '* LSDCDB Version' Version
  6.  
  7.     Signal On Halt Name Quit
  8.  
  9.  /*=============================*/
  10.     LogFileName = 'LSDCDB.LOG'                             /* LOG File name*/
  11.     DefaultACP = 'RWCXDAP'               /* default ACP for userdirectories*/
  12.  /*=============================*/
  13.  
  14.     Call Init                                                 /* init dll's*/
  15.  
  16.     Parse Upper Arg DCName Option              /* option can only be '/FIX'*/
  17.  
  18.     If DCName = ''
  19.       Then Do
  20.              Say '*'
  21.              Say '* Check Domain Controller Access Control Profiles'
  22.              Say '*'
  23.              Say '* Usage: LSDCDB {DCName} {/FIX}'
  24.              Say '*'
  25.              Say '* Sample: LSDCDB \\BEDDC01'
  26.              Say '*'
  27.              Exit X2D('1600')
  28.            End
  29.       Else Nop
  30.  
  31.     If Option = '/FIX'              /* check if the fix option is specified*/
  32.       Then Fix = 1
  33.       Else Fix = 0
  34.  
  35.     DCName = Strip(DCName,'L','\')
  36.  
  37.     Say '* Server Name:' '\\'DCName
  38.  
  39.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'DCName)
  40.     If RC = 0
  41.       Then Do
  42.              ServerRole = ServerModalInfo.Role
  43.              Say '* Role:' ServerRole
  44.              If WordPos('Primary', ServerRole) > 0 |,  /* check server role*/
  45.                 WordPos('Backup', ServerRole) > 0
  46.                Then Nop
  47.                Else Do
  48.                       Say '! This is not a Domain Controller' '07'x
  49.                       Exit X2D('1600')
  50.                     End
  51.            End
  52.       Else Call ChkError RC
  53.  
  54.     Say '* Getting all users from: \\'DCName
  55.     AllDefinedUsers = ''
  56.  /* RC = NetEnumerate(280, 'UserID', '\\'DCName) */
  57.     RC = WfrxUserEnum('\\'DCNAME,'USERID')
  58.     If RC = 0
  59.       Then Do i = 1 to UserID.0
  60.              AllDefinedUsers = AllDefinedUsers || UserID.i || ';'
  61.            End
  62.       Else Call ChkError RC
  63.     Say '* Total users:' UserID.0
  64.  
  65.     Say '* Getting SysFileTree from: \\'DCName'\ibmlan$\users'
  66.     Call SysFileTree '\\'DCName'\ibmlan$\dcdb\users\', 'DCDBDirs', 'DO'
  67.     If DCDBDirs.0 > 0
  68.       Then Do
  69.              Say '* Total directories:' DCDBDirs.0
  70.              Call RxStemSort 'DCDBDirs'                   /* sort all trees*/
  71.              Do i = 1 to DCDBDirs.0
  72.                Counter = '('Right(i,Length(DCDBDirs.0))'/'Right(DCDBDirs.0,Length(DCDBDirs.0))')'
  73.                UserDir = Translate(SubStr(DCDBDirs.i, LastPos('\', DCDBDirs.i) + 1))
  74.                Say Counter DCDBDirs.i
  75.  
  76.                If Pos(UserDir || ';', AllDefinedUsers) = 0
  77.                  Then Do                          /* check if dir may exist*/
  78.                         Say '! Error: directory found with no user'
  79.                         If Fix = 1
  80.                           Then Do
  81.                                  Text = 'RD DIR' DCDBDirs.i
  82.                                  Say '09'x Text
  83.                                  If SysDestroyObject(DCDBDirs.i) = 1
  84.                                    Then Call Logit Text
  85.                                    Else Do
  86.                                           Say '! Error:' Text
  87.                                           Call Logit '! Error:' Text
  88.                                         End
  89.                                End
  90.  
  91.                           Else Nop
  92.                         Iterate
  93.                       End
  94.                  Else Do                        /* check if batch dir exist*/
  95.                         BatchDir = DCDBDirs.i || '\BATCH'
  96.                         Call SysFileTree BatchDir, 'DirExist', 'DO'
  97.                         If DirExist.0 = 0
  98.                           Then Do
  99.                                  Say '! Error: no BatchDir found on' DCDBDirs.i
  100.                                  If Fix = 1
  101.                                    Then Do
  102.                                           Text = 'MD DIR' BatchDir
  103.                                           Say '09'x Text
  104.                                           If SysMKDir(BatchDir) = 0
  105.                                             Then Call Logit Text
  106.                                             Else Do
  107.                                                    Say '! Error:' Text
  108.                                                    Call Logit '! Error:' Text
  109.                                                  End
  110.                                         End
  111.                                    Else Nop
  112.                                End
  113.                           Else Nop
  114.                       End
  115.  
  116.             /* get ACP */
  117.                RC = NetGetInfo(10, 'Access', '\\'DCName, DCDBDirs.i)
  118.                If RC = 0 & Access.Count = 1
  119.                  Then Do
  120.                         If Access.1.UgName = UserDir & Access.1.Access = DefaultACP
  121.                           Then Nop
  122.                           Else Do
  123.                                  Say '! Error: bad ACP found on' DCDBDirs.i
  124.                                  Say '09'x UserDir || ':' || Access.1.Access
  125.                                  If Fix = 1
  126.                                    Then Call SetACL DCDBDirs.i UserDir
  127.                                    Else Nop
  128.                                End
  129.                       End
  130.                  Else Do
  131.                         If RC <> 0
  132.                           Then Do
  133.                                  Say '! Error: no ACP found on' DCDBDirs.i
  134.                                  If Fix = 1
  135.                                    Then Call SetACL DCDBDirs.i UserDir
  136.                                    Else Nop
  137.                                End
  138.                           Else Do
  139.                                  Say '! Error: multiple ACP found on' DCDBDirs.i
  140.                                  Do j = 1 to Access.Count
  141.                                    Say '09'x Access.j.UgName || ':' || Access.j.Access
  142.                                  End
  143.                                  If Fix = 1
  144.                                    Then Call SetACL DCDBDirs.i UserDir
  145.                                    Else Nop
  146.                                End
  147.                       End
  148.              End
  149.            End
  150.       Else Say '! Error: no directories exist on the DCDB\USERS tree'
  151.  
  152.     If Fix
  153.       Then Say '0A08'x '* Done, look at the Log File' LogFileName
  154.       Else Nop
  155.  
  156.     Exit X2D('FE00')
  157.  
  158.  SETACL:/* ------------------------------------------------------------------*/
  159.  
  160.     Parse Arg PathToSet UserID
  161.  
  162.     DirToSet.0 = 2
  163.     DirToSet.1 = PathToSet
  164.     DirToSet.2 = PathToSet || '\BATCH'
  165.  
  166.     Do j = 1 to DirToSet.0
  167.    /* Delete */
  168.       LogText = 'Del ACL on' DirToSet.j
  169.       Say '09'x LogText
  170.       RC = NetDelete(10, '\\'DCName, DirToSet.j)
  171.       Call Logit LogText RC
  172.  
  173.    /* Set */
  174.       Call Logit 'Adding ACL on:' DirToSet.j UserID':'DefaultACP
  175.       ACL.Count    = 1
  176.       ACL.1.Ugname = UserID
  177.       ACL.1.Access = DefaultACP
  178.  
  179.       LogText = 'Set ACL on' DirToSet.j ACL.1.UgName || ':' || ACL.1.Access
  180.       Say '09'x LogText
  181.       RC = NetAdd(10, 'ACL', '\\'ServerName, DirToSet.j)
  182.       If RC = 0
  183.         Then Call Logit LogText
  184.         Else Do
  185.                Say '!' LogText
  186.                Call Logit '! Error:' LogText RC
  187.              End
  188.     End
  189.  
  190.     Return
  191.  
  192.  INIT:/* --------------------------------------------------------------------*/
  193.  
  194.    '@echo off'
  195.     BootDrive = Left(Value('ComSpec',,'OS2Environment'),2)
  196.  
  197.     If RxFuncQuery('SysLoadFuncs')
  198.       Then Do
  199.              Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  200.              Call SysLoadFuncs
  201.            End
  202.       Else Nop
  203.  
  204.     LSRDrive = Left(SysSearchPath('PATH', 'NET.EXE'), 2)    /* IBMLAN Drive*/
  205.     If LSRDrive <> ''
  206.       Then Nop
  207.       Else Do
  208.              Say '! Could not determine the Lan Requester path' '07'x
  209.              Exit X2D('1604')
  210.            End
  211.  
  212.     Call ChkFile LSRDrive'\ibmlan\netlib\lsrxut.dll'
  213.     If RxFuncQuery('LoadLSRXUTFuncs')
  214.       Then Do
  215.              Call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  216.              Call LoadLsRxutFuncs
  217.            End
  218.       Else Nop
  219.  
  220.     Call ChkFile BootDrive'\os2\dll\rxutils.dll'
  221.     If RxFuncQuery('RxLoadFuncs')
  222.       Then Do
  223.              Call RxFuncAdd 'RxLoadFuncs', 'RXUTILS', 'RxLoadFuncs'
  224.              Call RxLoadFuncs
  225.            End
  226.       Else Nop
  227.  
  228.     If Stream(LSRDrive'\ibmlan\netlib\wfrxutil.dll', 'C', 'Query Exists') <> ''
  229.       Then Do
  230.              Call RxFuncAdd 'WfrxLoadFuncs', 'WfrxUtil', 'WfrxLoadFuncs'
  231.              Call WfrxLoadFuncs
  232.            End
  233.       Else Do
  234.              Say '! Could not find' LSRDrive'\IBMLAN\NETLIB\WFRXUTIL.DLL' '07'x
  235.              Exit X2D('0800')
  236.            End
  237.  
  238.     Return
  239.  
  240.  CHKERROR:/* ----------------------------------------------------------------*/
  241.  
  242.     Parse Arg RCode
  243.  
  244.     Say '! Error:' RCode '07'x
  245.     Exit
  246.  
  247.     Return
  248.  
  249.  CHKFILE:/* -----------------------------------------------------------------*/
  250.  
  251.     Parse Arg File_To_Check
  252.  
  253.     If Stream(File_To_Check, 'C', 'Query Exists') = ''
  254.       Then Do
  255.              Say '! File not found:' File_To_Check '07'x
  256.              Exit X2D('0800')
  257.            End
  258.       Else Nop
  259.  
  260.     Return
  261.  
  262.  LOGIT:/* ------------------------------------------------------------------*/
  263.  
  264.     Parse Arg Log_Text
  265.  
  266.     Log_Text = Date('E') Time() Log_Text
  267.  
  268.     Call LineOut LogFileName, Log_Text
  269.     Call Stream LogFileName, 'C', 'Close'
  270.  
  271.     Return
  272.  
  273.  QUIT:/* --------------------------------------------------------------------*/
  274.  
  275.     Say '...Interupted by User...'
  276.  
  277.     Exit X2D('1604')
  278.  
  279.