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

  1. /*---------------------------------------------------------------------------*\
  2. |  Check HomeDirectories for proper ACL's     (C) Alain Rykaert - MAR96-FEB00 |
  3. \*---------------------------------------------------------------------------*/
  4.     Version = '4.04a (C) AR - FEB2000'
  5.     Say '* LSHOME Version' Version
  6.  
  7.     Signal On Halt Name Quit
  8.  
  9.  /*=============================*/
  10.     LogFileName = 'LSHOME.LOG'                             /* LOG File name*/
  11.     DefaultACP = 'RWCXDAP'               /* default ACP for homedirectories*/
  12.  /*=============================*/
  13.  
  14.     Call Init                                                 /* init dll's*/
  15.  
  16.     Parse Upper Arg DCName Option              /* option can only be '/FIX'*/
  17.     Parse Var Option '/U:' UserID .
  18.     Parse Var Option '/F' Fix .
  19.  
  20.     If DCName = ''
  21.       Then Do
  22.              Say '*'
  23.              Say '* Check Home Directories for proper ACLS`s'
  24.              Say '*'
  25.              Say '* Usage: LSHOME DCName {/U:UserID} {/FIX}'
  26.              Say '*'
  27.              Say '* Sample: LSHOME \\DC01'
  28.              Say '*'
  29.              Exit X2D('1600')
  30.            End
  31.       Else Nop
  32.  
  33.     If Fix = 'IX'                   /* check if the fix option is specified*/
  34.       Then Fix = 1
  35.       Else Fix = 0
  36.  
  37.     DCName = Strip(DCName,'L','\')
  38.  
  39.     Say '* Server Name:' '\\'DCName
  40.     Say '* UserID:' UserID
  41.     Say '* FIX:' Fix
  42.  
  43.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'DCName)
  44.     If RC = 0
  45.       Then Do
  46.              ServerRole = ServerModalInfo.Role
  47.              If WordPos('Primary', ServerRole) > 0     /* check server role*/
  48.                Then Nop
  49.                Else Do
  50.                       Say '! This is not a Primary Domain Controller' '07'x
  51.                       Exit X2D('1600')
  52.                     End
  53.            End
  54.       Else Call ChkError RC
  55.  
  56.     Counter = ''                                       /* Reset the Counter*/
  57.  
  58.     If UserID = ''                  /* If no user specified, scan all users*/
  59.       Then Do
  60.              RC = NetEnumerate(280, 'UserID', '\\'DCName)  /* get all users*/
  61.              RC = WfrxUserEnum('\\'DCNAME,'USERID')
  62.              If RC = 0
  63.                Then Do
  64.                       Call RxStemSort 'UserID'            /* sort all users*/
  65.                       Say '* Total Users:' UserID.0
  66.                       Do i = 1 to UserID.0
  67.                         Counter = '('Right(i,Length(UserID.0))'/'Right(UserID.0,Length(UserID.0))')'
  68.                         Call ChkUser UserID.i Counter
  69.                       End
  70.                     End
  71.                Else Call ChkError RC
  72.            End
  73.       Else Do                                        /* If a user specified*/
  74.              RC = NetGetInfo(280, 'UserInfo', '\\'DCName, UserID)
  75.              If RC = 0
  76.                Then Call ChkUser UserID Counter
  77.                Else Call ChkError RC
  78.            End
  79.  
  80.     If Fix Then Say '* Done, look at the Log File' LogFilename
  81.  
  82.     Exit X2D('FE00')
  83.  
  84.  CHKUSER:/* -----------------------------------------------------------------*/
  85.  
  86.     Parse Arg UserID Counter
  87.  
  88.     Call NetGetInfo 280, 'UserInfo', '\\'DCName, UserID
  89.     If UserInfo.Home_Dir = '-none-'
  90.       Then Say ' ' Counter Left(UserID,15)                      /* '-none-'*/
  91.       Else Do
  92.              If Left(UserInfo.Home_Dir,2) = '\\'
  93.                Then Do
  94.                       Resource = UserInfo.Home_Dir
  95.                       Drive = '*:'
  96.                     End
  97.                Else Do
  98.                       Parse Var UserInfo.Home_Dir Drive '\' HSName '\' Resource
  99.                       HSName = Strip(HSName,'L','\')
  100.                       Resource = '\\'HSName'\'Resource
  101.                     End
  102.              Say ' ' Counter Left(UserID, 15) Drive '->' Resource
  103.  
  104.           /* check if dir exist*/
  105.              Call SysFileTree Resource, 'DirExist', 'DO'
  106.              If DirExist.0 = 0
  107.                Then Do
  108.                       Say '! Error: no DIR on' Resource
  109.                       If Fix = 1
  110.                         Then Do
  111.                                CheckDir = Resource
  112.                                Parse Var CheckDir UNCPath '$\' Rest
  113.                                DirPath = UNCPath'$'
  114.                                Do While Rest <> ''
  115.                                  Parse Var Rest Temp '\' Rest
  116.                                  DirPath = DirPath'\'Temp
  117.                                  Call SysFileTree DirPath, 'DirCheck', 'DO'
  118.                                  If DirCheck.0 = 0
  119.                                    Then Do
  120.                                           Text = 'Make Directory' DirPath
  121.                                           Say '09'x Text
  122.                                           If SysMKDir(DirPath) = 0
  123.                                             Then Call Logit Text
  124.                                             Else Do
  125.                                                    Say '! Error:' Text
  126.                                                    Call Logit '! Error:' Text
  127.                                                  End
  128.                                         End
  129.                                    Else Nop
  130.                                End
  131.                              End
  132.                         Else Nop
  133.                     End
  134.                Else Nop
  135.  
  136.           /* check for proper acl */
  137.              If NetGetInfo(10, 'Access', '\\'HSName, Resource) = 0
  138.                Then Do
  139.                       If Access.Count > 1
  140.                         Then Do
  141.                                Say '! Error: Multiple ACP on' Resource
  142.                                Do j = 1 to Access.Count
  143.                                  Say '09'x Access.j.UgName || ':' || Access.j.Access
  144.                                End
  145.                                If Fix = 1
  146.                                  Then Do
  147.                                         Say '09'x 'Delete & Create a default ACP ? (Y/N)'
  148.                                         If Translate(SysGetKey('NoEcho')) = 'Y'
  149.                                           Then Do
  150.                                                  Call Logit 'Del multiple ACP' Resource
  151.                                                  Call SetHome UserID HSName Resource
  152.                                                End
  153.                                           Else Nop
  154.                                       End
  155.                                  Else Nop
  156.                              End
  157.                         Else Do
  158.                                If Access.1.Access = DefaultACP &,
  159.                                   Access.1.UgName = UserID
  160.                                  Then Nop
  161.                                  Else Do
  162.                                         Say '! Error: mismatch ACP on' Resource Access.1.UgName || ':' || Access.1.Access
  163.                                         If Fix = 1
  164.                                           Then Do
  165.                                                  Call Logit 'Del matcherror ACP' Resource Access.1.UgName || ':' || Access.1.Access
  166.                                                  Call SetHome UserID HSName Resource
  167.                                                End
  168.                                           Else Nop
  169.                                       End
  170.                              End
  171.                     End
  172.                Else Do
  173.                       Say '! Error: no ACP on' Resource
  174.                       If Fix = 1
  175.                         Then Call SetHome UserID HSName Resource
  176.                         Else Nop
  177.                     End
  178.            End
  179.     Return
  180.  
  181.  SETHOME:/* -----------------------------------------------------------------*/
  182.  
  183.     Parse Arg UserID ServerName UNCSource
  184.  
  185.  /* server presence check*/
  186.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'ServerName)
  187.     If RC = 0
  188.       Then Do
  189.           /* Delete */
  190.              LogText = 'Del ACL on' UNCSource
  191.              Say '09'x LogText
  192.              RC = NetDelete(10, '\\'ServerName, UNCSource)
  193.              Call Logit LogText RC
  194.  
  195.           /* Set */
  196.              ACL.Count    = 1
  197.              ACL.1.Ugname = UserID
  198.              ACL.1.Access = DefaultACP
  199.              LogText = 'Set ACL on' UNCSource ACL.1.UgName || ':' || ACL.1.Access
  200.              Say '09'x LogText
  201.              RC = NetAdd(10, 'ACL', '\\'ServerName, UNCSource)
  202.              If RC = 0
  203.                Then Do
  204.                       Call Logit LogText
  205.                    /* Apply */
  206.                       LogText = 'Apply ACL on' UNCSource
  207.                       Say '09'x LogText
  208.                       RC = NetMisc(520, 'ApplyInfo', '\\'ServerName, UNCSource)
  209.                       If RC = 0
  210.                         Then Call Logit LogText
  211.                         Else Do
  212.                                LogText = '! Error: Apply' ApplyInfo.Error_Buf ApplyInfo.Error_Code
  213.                                Say '!' LogText
  214.                                Call Logit LogText
  215.                              End
  216.                     End
  217.                Else Do
  218.                       Say '!' LogText
  219.                       Call Logit '! Error:' LogText
  220.                     End
  221.  
  222.            End
  223.       Else Do
  224.              LogText = '! Server not found:' ServerName
  225.              Say LogText '07'x
  226.              Call Logit LogText
  227.            End
  228.  
  229.     Return
  230.  
  231.  INIT:/* --------------------------------------------------------------------*/
  232.  
  233.    '@echo off'
  234.     BootDrive = Left(Value('ComSpec',,'OS2Environment'),2)
  235.  
  236.     If RxFuncQuery('SysLoadFuncs')
  237.       Then Do
  238.              Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  239.              Call SysLoadFuncs
  240.            End
  241.       Else Nop
  242.  
  243.     LSRDrive = Left(SysSearchPath('PATH', 'NET.EXE'), 2)    /* IBMLAN Drive*/
  244.     If LSRDrive <> ''
  245.       Then Nop
  246.       Else Do
  247.              Say '! Could not determine the Lan Requester path' '07'x
  248.              Exit X2D('1604')
  249.            End
  250.  
  251.     If Stream(LSRDrive'\ibmlan\netlib\lsrxut.dll', 'C', 'Query Exists') <> ''
  252.       Then Do
  253.              If RxFuncQuery('LoadLSRXUTFuncs')
  254.                Then Do
  255.                       Call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  256.                       Call LoadLsRxutFuncs
  257.                     End
  258.                Else Nop
  259.            End
  260.       Else Do
  261.              Say '! Could not find' LSRDrive'\IBMLAN\NETLIB\LSRXUT.DLL' '07'x
  262.              Exit X2D('0800')
  263.            End
  264.  
  265.     Call ChkFile BootDrive'\os2\dll\rxutils.dll'
  266.     If RxFuncQuery('RxLoadFuncs')
  267.       Then Do
  268.              Call RxFuncAdd 'RxLoadFuncs', 'RXUTILS', 'RxLoadFuncs'
  269.              Call RxLoadFuncs
  270.            End
  271.       Else Nop
  272.  
  273.     If Stream(LSRDrive'\ibmlan\netlib\wfrxutil.dll', 'C', 'Query Exists') <> ''
  274.       Then Do
  275.              Call RxFuncAdd 'WfrxLoadFuncs', 'WfrxUtil', 'WfrxLoadFuncs'
  276.              Call WfrxLoadFuncs
  277.            End
  278.       Else Do
  279.              Say '! Could not find' LSRDrive'\IBMLAN\NETLIB\WFRXUTIL.DLL' '07'x
  280.              Exit X2D('0800')
  281.            End
  282.  
  283.     Return
  284.  
  285.  CHKERROR:/* ----------------------------------------------------------------*/
  286.  
  287.     Parse Arg RCode
  288.  
  289.     Say '! Error:' RCode '07'x
  290.     Exit X2D('1604')
  291.  
  292.     Return
  293.  
  294.  CHKFILE:/* -----------------------------------------------------------------*/
  295.  
  296.     Parse Arg File_To_Check
  297.  
  298.     If Stream(File_To_Check, 'C', 'Query Exists') = ''
  299.       Then Do
  300.              Say '! File not found:' File_To_Check '07'x
  301.              Exit X2D('0800')
  302.            End
  303.       Else Nop
  304.  
  305.     Return
  306.  
  307.  LOGIT:/* ------------------------------------------------------------------*/
  308.  
  309.     Parse Arg Log_Text
  310.  
  311.     Log_Text = Date('E') Time() Log_Text
  312.  
  313.     Call LineOut LogFileName, Log_Text
  314.     Call Stream LogFileName, 'C', 'Close'
  315.  
  316.     Return
  317.  
  318.  QUIT:/* --------------------------------------------------------------------*/
  319.  
  320.     Say '...Interupted by User...'
  321.  
  322.     Exit X2D('1604')
  323.  
  324.