I have looked at this question and got it working to create a repo and add permissions for a user using the WMI interface. The issue I am running into now is this: if I am trying to update a repo I created and add another user to the repo, it clears out the current use (deletes it entirely from the repo) and just adds the one person.
So, I need to figure out how to do two things:
- Add a user to an existing repo
- Remove a user from an existing repo
I think once I have that I will be able to figure out the rest of my interactions. I referred to the wof file and found these entries that I believe I need to implement:
class VisualSVN_Repository
[provider("VisualSVNWMIProvider"), dynamic]
class VisualSVN_Repository
{
[Description ("Repository name"), key]
string Name;
...
[implemented] void GetSecurity([in] string Path,
[out] VisualSVN_PermissionEntry Permissions[]);
[implemented] void SetSecurity([in] string Path,
[in] VisualSVN_PermissionEntry Permissions[],
[in] boolean ResetChildren = false);
}
I am implementing set security like so:
static public void UpdatePermissions(string sid, string repository, AccessLevel level, bool isAdmin = false)
{
ManagementClass repoClass = new ManagementClass("root\\VisualSVN", "VisualSVN_Repository", null);
ManagementObject repoObject = repoClass.CreateInstance();
repoObject.SetPropertyValue("Name", repository);
ManagementBaseObject inParams =
repoClass.GetMethodParameters("SetSecurity");
inParams["Path"] = "/";
inParams["Permissions"] = new object[] { permObject };
ManagementBaseObject outParams =
repoObject.InvokeMethod("SetSecurity", inParams, null);
}
This works, but like I said, only for one user. It seems like it cleans out anything in there and just adds the one user object.
The other method I think I need to interact with is "GetSecurity" which looks like it returns an array of VisualSVN_PermissionEntry
VisualSVN_PermissionEntry
class VisualSVN_PermissionEntry
{
VisualSVN_Account Account;
uint32 AccessLevel;
};
So this one has an AccessLevel property and VisualSVN_Account object
VisualSVN_Account (I am using Windows auth, so I would need to use that one)
[provider("VisualSVNWMIProvider"), dynamic, abstract]
class VisualSVN_Account
{
};
class VisualSVN_WindowsAccount : VisualSVN_Account
{
[key] string SID;
};
So here is where I am lost. I assume I need to call "GetSecurity" and then iterate through those results and add them to an object array of the input parameters for "SetSecurity". I can't seem to get that to work. Some psuedo-code I have played with but am getting various errors (object reference errors mostly):
ManagementBaseObject inSecParams=
repoClass.GetMethodParameters("GetSecurity");
inSecParams["Path"] = "/";
ManagementBaseObject existingPerms =
repoObject.InvokeMethod("GetSecurity");
//now I need to loop through the array existingPerms and add them to an array of VisualSVN_PermissionEntry object.
--or--
//can I take this result and just add the users I need to add to it somehow.