[VBS] Modification permissions et groupe sécurité

Modification permissions et groupe sécurité [VBS] - VB/VBA/VBS - Programmation

Marsh Posté le 16-04-2007 à 08:53:34    

Bonjour à tous,
 
j'utilise un VBScript pour modifier les permissions sur des dossiers,
mais ca ne fonctionne pas lorsqu'il s'agit d'utiliser le compte "Créateur propriétaire".
 
Est-ce tout simplement impossible?
 
Merci d'avance.  :)

Reply

Marsh Posté le 16-04-2007 à 08:53:34   

Reply

Marsh Posté le 16-04-2007 à 11:08:02    

J'ai pas été très précis.
 
Voici le code que j'utilise ci-dessous.
 
J'ai essayé avec BUILTIN , AUTORITE NT ou . mais vu que "Createur propriétaire" est un compte de sécurité...
J'obtiens une erreur 0x80041002
 
 

Code :
  1. WScript.Echo ModifyFilePerm(".",strFolderName, "CREATEUR PROPRIETAIRE", "BUILTIN", "f", "u", "a" )
  2. Function ModifyFilePerm(strComputer, strFilePath, strUsername, strDomain, strAccessLvl, strUtype, strMode)
  3.     Dim dacl, Services, SecDescClass, SecDesc, intRetVal
  4.     Dim wmiFileSecSetting, wmiFileSetting, wmiSecurityDescriptor
  5.     Set Services = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputer & "\ROOT\CIMV2" )
  6.     Set SecDescClass = Services.Get("Win32_SecurityDescriptor" )
  7.     Set SecDesc = SecDescClass.SpawnInstance_
  8.     strFilePath = replace(strFilePath,"\","\\" )
  9.     Set wmiFileSetting = GetObject("Winmgmts:{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Directory='" & strFilePath & "'" )
  10.     Set wmiFileSecSetting = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}!\\" & strComputer & _
  11.         "\ROOT\CIMV2:Win32_LogicalFileSecuritySetting.path='" & strFilePath & "'" )
  12. 'you can have problems here if you have no descriptor ie only everyone listed.
  13.     intRetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)
  14.     ' Obtain existing security descriptor for folder
  15.     If Err <> 0 Then
  16.      WScript.Echo "GetSecurityDescriptor failed" & VBCRLF & Err.Number & VBCRLF & Err.Description
  17.      WScript.Quit
  18.     End If
  19.     ' Retrieve the content of Win32_SecurityDescriptor DACL property.
  20.     DACL = wmiSecurityDescriptor.dacl
  21.     If strMode = "a" Then    'add user
  22.         AddUserAce dacl, strUsername, strDomain, strUtype, strComputer, strAccessLvl, Services
  23.         SecDesc.Properties_.Item("DACL" ) = dacl
  24.         wscript.echo "adding " & strusername & " to the dacl for " & replace(strFilePath,"\\","\" ) & "." & vbcrlf & _
  25.             "Result of change: " & wmiFileSetting.changesecuritypermissions(SecDesc, 4)       
  26.     ElseIf strMode = "d" Then    'Must mean delete access.
  27.         SecDesc.Properties_.Item("DACL" ) = DeleteUserAce(dacl, strUsername, strDomain, strUtype, strComputer, Services)
  28.         wscript.echo "deleting " & strusername & " to the dacl for " & replace(strFilePath,"\\","\" ) & "." & vbcrlf & _
  29.             "Result of change: " & wmiFileSetting.changesecuritypermissions(SecDesc, 4)       
  30.     Else    'Must mean modify access 8), note this one only returns string, not Ace Array.
  31.         wscript.echo ModifyUserAce(wmiSecurityDescriptor.dacl, strUsername, strAccessLvl)
  32.         'only need this to modify an entry
  33.         intRetVal = wmiFileSecSetting.SetSecurityDescriptor(wmiSecurityDescriptor)
  34.         Wscript.Echo GetResultMessageFile(intretval, replace(strFilePath,"\\","\" ), strUsername)
  35.     End If
  36.     Set Services = nothing
  37.     Set SecDescClass = nothing
  38.     Set SecDesc = Nothing
  39.     Set wmiFileSecSetting = nothing
  40.     Set wmiFileSetting = nothing
  41. End Function
  42. Function AddUserAce( byref dacl, strUsername, strDomain, strUtype, strComputer, strAccessLvl, byref Services )
  43.     'Copy dacl to new ACE array then add specified user/group to ACE array and return it.
  44.     Dim intArrAceMax, arrACE, objACE
  45.     intArrAceMax = UBound(dacl) + 1
  46.     ReDim preserve dacl(intArrAceMax)
  47.    
  48.     Set dacl(intArrAceMax) = Services.Get("Win32_Ace" ).SpawnInstance_
  49.     If strAccessLvl = "r" Then
  50.         dacl(intArrAceMax).Properties_.Item("AccessMask" ) = 1179817
  51.     ElseIf strAccessLvl = "w" Then
  52.         dacl(intArrAceMax).Properties_.Item("AccessMask" ) = 1245631
  53.     Else 'full access
  54.         dacl(intArrAceMax).Properties_.Item("AccessMask" ) = 2032127
  55.     End If
  56.     dacl(intArrAceMax).Properties_.Item("AceFlags" ) = 3
  57.     dacl(intArrAceMax).Properties_.Item("AceType" ) = 0
  58.     dacl(intArrAceMax).Properties_.Item("Trustee" ) = GetObjTrustee(strUsername, strDomain, strUtype, strComputer)
  59.     Set objACE = Nothing
  60. End Function
  61. Function GetObjTrustee(strUsername, strDomain, strUtype, strComputer)
  62.     'Get and user/group object to copy user/group sid to new trustee instance to be returned
  63.     Dim objTrustee, account, accountSID
  64.     Set objTrustee = getObject("Winmgmts:{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Trustee" ).Spawninstance_
  65.     'For some reason you can't seem to be able to connect remotely to get account.
  66.     If strUtype = "g" Then
  67.         'Set account = getObject("Winmgmts:{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Group.Name='" & strUsername & "',Domain='" & strDomain &"'" )
  68.         Set account = getObject("Winmgmts:{impersonationlevel=impersonate}!//./root/cimv2:Win32_Group.Name='" & strUsername & "',Domain='" & strDomain &"'" )
  69.     Else
  70.         'Set account = getObject("Winmgmts:{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_Account.Name='" & strUsername & "',Domain='" & strDomain &"'" )
  71.         Set account = getObject("Winmgmts:{impersonationlevel=impersonate}!//./root/cimv2:Win32_Account.Name='" & strUsername & "',Domain='" & strDomain &"'" )
  72.     End If
  73.     Set accountSID = getObject("Winmgmts:{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2:Win32_SID.SID='" & account.SID &"'" )
  74.     objTrustee.Domain = strDomain
  75.     objTrustee.Name = strUsername
  76.     objTrustee.Properties_.item("SID" ) = accountSID.BinaryRepresentation
  77.     Set GetObjTrustee = objTrustee
  78.     Set accountSID = nothing
  79.     Set account = Nothing
  80.     Set objTrustee = nothing
  81. End Function


Message édité par the_silencer le 16-04-2007 à 11:10:45
Reply

Marsh Posté le 03-05-2007 à 19:06:50    

Bonjour,
 
l'erreur 0x80041002 correspond à un problème de connexion  à un objet (ici le groupe "Createur proprietaire" ).
 
En fait, il apparaît que la connexion à un compte intégré ne peut se faire par un getObject (ligne 75).
 
Il existe un script vbs de Microsoft qui permet d'afficher ou de modifier les autorisations sur un fichier ou un dossier : xcacls.vbs (http://download.microsoft.com/download/f/7/8/f786aaf3-a37b-45ab-b0a2-8c8c18bbf483/xcacls_installer.exe)
 
Dans ce script, ils récupèrent grace à un select case, le sid des comptes "spéciaux". Il faudrait modifier ton script pour intégrer une gestion de ce type. (SID : S-1-3-0 pour le groupe "Createur proprietaire" ).
 
ou utiliser xcacls... ;-)


Message édité par Neuch le 03-05-2007 à 19:09:24
Reply

Marsh Posté le 03-05-2007 à 20:29:04    

Salut, merci pour ta réponse,
 
ce que j'ai fait : j'ai utilisé FileACL finalement :)  
 
  ;)

Reply

Marsh Posté le 04-05-2007 à 10:33:18    

Bonjour,
 
l'erreur 0x80041002 correspond à un problème de connexion  à un objet (ici le groupe "Createur proprietaire" ).
 
En fait, il apparaît que la connexion à un compte intégré ne peut se faire par un getObject (ligne 78).
 
Il existe un script vbs de Microsoft qui permet d'afficher ou de modifier les autorisations sur un fichier ou un dossier : xcacls.vbs
 
Dans ce script il récupère grace à un select case, le sid des comptes "spéciaux". Il faudrait modifier ton script pour intégrer une gestion de ce type. (SID : S-1-3-0 pour le groupe "Createur proprietaire" ).
 
ou utiliser xcacls... ;-)

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed