teteve
Messages postés123Date d'inscriptionjeudi 22 avril 2004StatutMembreDernière intervention23 février 2011
-
6 avril 2007 à 10:24
teteve
Messages postés123Date d'inscriptionjeudi 22 avril 2004StatutMembreDernière intervention23 février 2011
-
8 avril 2007 à 10:54
Bonjour à tous,
Après une très légère formation en VBScript et VBA, j'ai voulu me lancer dans la création de scripts d'administration pour mon réseau sous Windows 2003. Malheureusement, j'ai encore quelques notions qui m'échappent. Je vous soumets un petit bout de code pour expliquer ma question :
strPath = "C:\testNTFS"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer ("", "root/cimv2")
Set objFileSecSetting = objService.Get("Win32_LogicalFileSecuritySetting.Path=""" & Replace(strPath,"","\") & """")
Set objOutParams = objFileSecSetting.ExecMethod_("GetSecurityDescriptor")
Set objSecDescriptor = objOutParams.Descriptor
For Each objDACL_Member In objSecDescriptor.DACL
If objDACL_Member.AceType = 0 Then
WScript.Echo objDACL_Member.Trustee.Name
WScript.Echo objDACL_Member.AccessMask
End If
Next
Ce n'est qu'un passage qui, je le conçois, ne parait pas très cohérent, mais c'est juste pour servir d'exemple.
Tout d'abord, je n'arrive pas à exploiter le résultat "objDACL_Member.AccessMask". Comment interpreter le chiffre retourné ? Je voudrais récupérer les noms d'utilisateurs en fonction de leurs autorisations NTFS sur le dossier.
De même, je n'arrive pas à faire un bout de script pour créer une ACE. J'ai trouvé beaucoup d'infos et en ai déduit les principes de base, mais je n'arrive pas à mettre en forme le code.
Quelqu'un pouurrait il m'éclairer ? (je cherche à comprendre et non à faire faire le travail par d'autres, donc merci d'expliquer, même succintement, si vous mettez du code)
Dans l'espoir de savoir un jour scripter...
Teteve
Bit flags that indicate rights granted or denied to the trustee. For more information, see the Remarks section of this topic.
Value |Meaning |----
FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)
1
0x1, Grants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory., ----
FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)
2
0x2, Grants the right to write data to the file. For a directory, this value grants the right to create a file in the directory., ----
FILE_APPEND_DATA (file) or FILE_ADD_SUBDIRECTORY (directory)
4
0x4, Grants the right to append data to the file. For a directory, this value grants the right to create a subdirectory., ----
FILE_READ_EA
8
0x8, Grants the right to read extended attributes., ----
FILE_WRITE_EA
16
0x10, Grants the right to write extended attributes., ----
FILE_EXECUTE (file) or FILE_TRAVERSE (directory)
32
0x20, Grants the right to execute a file. For a directory, the directory can be traversed., ----
FILE_DELETE_CHILD
64
0x40, Grants the right to delete a directory and all the files it contains (its children), even if the files are read-only., ----
FILE_READ_ATTRIBUTES
128
0x80, Grants the right to read file attributes., ----
FILE_WRITE_ATTRIBUTES
256
0x100, Grants the right to change file attributes., ----
DELETE
65536
0x10000, Grants delete access., ----
READ_CONTROL
131072
0x20000, Grants read access to the security descriptor and owner., ----
WRITE_DAC
262144
0x40000, Grants write access to the discretionary ACL., ----
WRITE_OWNER
524288
0x80000, Assigns the write owner., ----
SYNCHRONIZE
1048576
0x100000, Synchronizes access and allows a process to wait for an object to enter the signaled state.
teteve
Messages postés123Date d'inscriptionjeudi 22 avril 2004StatutMembreDernière intervention23 février 2011 6 avril 2007 à 11:17
Merci pour cette réponse rapide. Malheureusement, les liens proposés sont justement ceux qui m'ont servi pour appréhender le script. Et c'est justement la compréhension de ces résultats que je ne comprends pas. Les résultats retournés par le script sont de l'héxa ? Que représentent ils ? la somme de toutes les autorisations en héxa ? Intuitivement c'est ce qu'il me semblait, mais après quelques tests j'ai de gros doutes... (vu mon niveau d'anglais, possible aussi que j'ai zappé une info dans cette si belle et mystérieuse langue...)
If (objDACL_Member.AccessMask And FILE_WRITE_DATA) <> 0 Then
'# L'utilisateur a le droit de créer ou modifier un fichier.
End If
If (objDACL_Member.AccessMask And FILE_DELETE_CHILD) <> 0 Then
'# L'utilisateur a le droit de supprimer un repertoire et les fichier qu'il contient.
End If
...,
----
By Renfield
Renfield
Admin CodeS-SourceS
- MVP Visual Basic
Vous n’avez pas trouvé la réponse que vous recherchez ?
teteve
Messages postés123Date d'inscriptionjeudi 22 avril 2004StatutMembreDernière intervention23 février 2011 6 avril 2007 à 12:37
intéressant comme réponse... Je vais essayer d'intégrer ce principe dans le code et de faire des tests pour voir si j'ai bien assimilé.
Par contre j'comprends pas trop le chiffre donné en résultat par mon script, comment est il "construit" à partir de la liste des constantes (que tu as redonné ci-dessus) et du OR.
FILE_READ_DATA (file) or FILE_LIST_DIRECTORY (directory)
1
0x1, Grants the right to read data from the file. For a directory, this value grants the right to list the contents of the directory., ----
FILE_WRITE_DATA (file) or FILE_ADD_FILE (directory)
2
0x2, Grants the right to write data to the file. For a directory, this value grants the right to create a file in the directory.
=> Un utilisateur qui a les deux autorisations ci-dessus retourne comme chiffre : 1048579... Qu'est ce que cela signifie ???
(et merci beaucoup pour cette disponibilité)
teteve
Messages postés123Date d'inscriptionjeudi 22 avril 2004StatutMembreDernière intervention23 février 2011 8 avril 2007 à 10:54
C'est bon, j'ai tout compris !!! J'ai fait pas mal d'essais de script et j'ai réussi à faire ce qu'il me fallait... Merci énormément Renfield pour tout, et surtout pour ta disponibilité et ta rapidité. Je posterai d'ici peu mon code pour avoir un avis critique dessus.