
BefaDuDesert
|
'liste des variables globales cheminFichierDroits = "C:\tst.txt" ligne = nbLignesDansFichier (cheminFichierDroits)
Dim tab() Redim tab(ligne,8)
Dim ligneCourante ligneCourante = -1
Function nbLignesDansFichier(cheminFichier) 'déclaration file system object Dim FSO 'instanciation Set FSO = CreateObject("Scripting.FileSystemObject") 'on instance le fichier texte Set Ftxt = FSO.OpenTextFile(cheminFichier) Dim cpt cpt = 0 'on parcours chaque ligne du fichier texte Do While Not Ftxt.AtEndOfStream MaVariable = Ftxt.Readline if MaVariable <> "" Then cpt=cpt+1 traitementLigne MaVariable,tab End If Loop nbLignesDansFichier = cpt Ftxt.Close End Function
'_________________________LECTURE d'un fichier_____________________________ 'déclaration file system object Dim FSO 'instanciation Set FSO = CreateObject("Scripting.FileSystemObject") 'on instancie le fichier texte Set Ftxt = FSO.OpenTextFile(cheminFichierDroits) 'on parcours chaque ligne du fichier texte Do While Not Ftxt.AtEndOfStream MaVariable = Ftxt.Readline if MaVariable <> "" Then traitementLigne MaVariable, tab End If Loop Ftxt.Close
'Entête tab tab(0,0) = "chemin" tab(0,1) = "utilisateur" tab(0,2) = "heritage" tab(0,3) = "lecture" tab(0,4) = "ecriture" tab(0,5) = "modification" tab(0,6) = "execution" tab(0,7) = "appropriation"
'__________________________Traitement de chaque ligne_________________________ Sub traitementLigne(ligne, byref tableau) 'si ligne normale WScript.echo tableau(0,0) If left(ligne,1) <> " " Then 'on passe à une nouvelle ligne ligneCourante = ligneCourante + 1 chemin = motChoisi(ligne," ",1) cheminRelatif = "\\" + NomMachine + right(chemin, len(chemin)-2) tab(ligneCourante,0) = cheminRelatif repertoireCourant = cheminRelatif 'on crée une nouvelle ligne 'on remplit la premiere ligne à savoir le chemin relatif reste = right(ligne,len(ligne)-len(cheminRelatif)-1) util = motChoisi(motChoisi(reste,"\",2),":",1) 'on remplit la 2è colonne tab(ligneCourante,1) = util domaineEtUtil=motChoisi(reste,":",1) droits = right(reste,len(reste)-len(domaineEtUtil)-1) 'On s'occupe maintenant des droits If Instr(droits,"(CI)") <> 0 OR Instr(droits,"(IO)") <> 0 OR Instr(droits,"(OI)") <> 0 Then tab(ligneCourante,2) = "X" End If If Instr(droits,"F") <> 0 Then tableau(ligneCourante,3) = "X" tableau(ligneCourante,4) = "X" tableau(ligneCourante,5) = "X" tableau(ligneCourante,6) = "X" tableau(ligneCourante,7) = "X" Else If Instr(droits,"C") <> 0 Then tableau(ligneCourante,3) = "X" tableau(ligneCourante,4) = "X" tableau(ligneCourante,5) = "X" tableau(ligneCourante,6) = "X" Else If Instr(droits,"(acc¦s sp,cialÿ") <> 0 Then WScript.echo "ligne suivante" End If End If End If 'pas ligne normale donc soit ligne utilisateur sup. soit ligne de droits Else 'dans ce cas la nous sommes dans le cas d'une ligne d'un nouvel utilisateur If Instr(ligne,"\") <> 0 OR Instr(ligne,"Tout le monde") <> 0 OR Instr(ligne,"CREATEUR PROPRIETAIRE") <> 0 Then WScript.echo "ligneCourante " & ligneCourante If ligneCourante <> 0 Then tableau(ligneCourante,0) = tableau(ligneCourante-1,0) End If ligne=sansEspaces(ligne) 'on vérifie les utilisateurs spéciaux If Instr(ligne,"Tout le monde") <> 0 Then util = "Tout le monde" Else If Instr(ligne,"CREATEUR PROPRIETAIRE") <> 0 Then util = "CREATEUR PROPRIETAIRE" Else util=motChoisi(motChoisi(ligne,"\",2),":",1) End If End If tab(ligneCourante,1) = util domaineEtUtil=motChoisi(reste,":",1) droits = motChoisi(ligne,":",2) 'heritage If Instr(droits,"(CI)") <> 0 OR Instr(droits,"(IO)") <> 0 OR Instr(droits,"(OI)") <> 0 Then tableau(ligneCourante,2) = "X" End If If Instr(ligne,"F") <> 0 Then tableau(ligneCourante,3) = "X" tableau(ligneCourante,4) = "X" tableau(ligneCourante,5) = "X" tableau(ligneCourante,6) = "X" tableau(ligneCourante,7) = "X" Else If Instr(ligne,"C") <> 0 Then tableau(ligneCourante,3) = "X" tableau(ligneCourante,4) = "X" tableau(ligneCourante,5) = "X" tableau(ligneCourante,6) = "X" Else If Instr(ligne,"(acc¦s sp,cialÿ") <> 0 Then 'il faut analyser les lignes suivantes afin de connaitre les droits de cet utilisateur WScript.echo "cas special" End If End If End If 'ligne de droits Else 'ici nous sommes dans les cas d'une ligne de droit pure ligneM=sansEspaces(ligne) If ligneM = "" Then If ligneM = "READ_CONTROL" Then tableau(ligneCourante,3) = "X" Else If ligneM = "FILE_WRITE_DATA" Then tableau(ligneCourante,4) = "X" Else If ligneM = "DELETE" Then tableau(ligneCourante,5) = "X" Else If ligneM = "FILE_EXECUTE" Then tableau(ligneCourante,6) = "X" Else If ligneM = "WRITE_OWNER" Then tableau(ligneCourante,7) = "X" End If End If End If End If End If End If End If End If End Sub
Function motChoisi(chaine,separateur,numMot) chaineU=chaine cpt = 1 nb = -1 Do While nb <> 0 'nb renvoie le premier caractère " " trouvé dans la chaine nb=Instr(chaineU,separateur) 'si aucun espace a été trouvé If nb <> 0 Then 'un espace est trouvé comme mot If nb = 1 Then cpt = cpt-1 chaineU = right(chaineU, len(chaineU)-1) Else mot_courant = left(chaineU, nb-1) If numMot=cpt Then motChoisi=mot_courant End If End If chaineU=right(chaineU, len(chaineU) - nb+1) cpt = cpt+1 Else If numMot=cpt Then motChoisi=chaineU End If End If Loop End Function
Function sansEspaces(mot) Do While left(mot,1) = " " mot=right(mot,len(mot)-1) Loop sansEspaces=mot End Function
Sub affichage (byref tab) ligneTemp = 0 colonneTemp = 0 Do While ligneTemp < ligne Do While colonneTemp < 8 WScript.echo tab(ligneTemp, colonneTemp) colonneTemp = colonneTemp + 1 Loop ligneTemp = ligneTemp + 1 colonneTemp = 0 Loop End Sub
Avec le C:\tst.txt, E:\ BUILTIN\Administrateurs:(OI)(CI)F AUTORITE NT\SYSTEM:(OI)(CI)C
CREATEUR PROPRIETAIRE:(OI)(CI)(IO)F
|