Dec012008

SharePoint security access denied permission corruption problem - Edit Item and Access Workflows

Published by waqas at 8:49 PM under SharePoint

During SharePoint migration from WSS 3.0 to MOSS, we experienced a very strange permission problem. After migration, whenever a new list or site was created; its edit access was somehow revoked. Not even system account could edit item??? This was a peculiar problem because user was unable to edit list items and was unable to run associated workflows.

After digging deep into the problem, we eventually found out that "PermMask" field was corrupted. It needed "RenderXMLUsingPattern" attribute to be true.

To fix it, you can refer to the following code which fixed this security problem for us :)

using(SPWebweb = newSPSite(args[1]).RootWeb)

{

web.AllowUnsafeUpdates = true;

bool excludeLists = ContainsSwitch(args, "excludelists"); //switch to exclude lists

SPField permMaskField = web.Fields.GetFieldByInternalName("PermMask"); //this is the culprit field

permMaskField.SchemaXml = UpdateSchema(permMaskField.SchemaXml);

permMaskField.Update();

Console.WriteLine("Root-Web Effective Permission Mask Updated");

if (!excludeLists)

ShowWebTree(web.Url);

web.AllowUnsafeUpdates = false;

}

private string UpdateSchema(string schemaXml)

{

XmlDocument doc = new XmlDocument();

doc.LoadXml(schemaXml);

XmlNode node = doc.SelectSingleNode("/Field");

XmlAttribute att = doc.CreateAttribute("RenderXMLUsingPattern");

att.Value = "TRUE";

node.Attributes.Append(att);

return doc.InnerXml;

}

private void ShowWebTree(string url)

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

using (SPWeb web = new SPSite(url).OpenWeb())

{

foreach (SPWeb subWeb in web.Webs)

ShowWebTree(subWeb.Url);

Console.WriteLine("############### Updating Web : " + web.ServerRelativeUrl + "###############");

for (int i = 0; i < web.Lists.Count; i++)

{

try

{

SPField permMaskField = web.Lists[i].Fields.GetFieldByInternalName("PermMask");

permMaskField.SchemaXml = UpdateSchema(permMaskField.SchemaXml);

permMaskField.Update();

Console.WriteLine("Updating List \"" + web.Lists[i].Title + "\" ......");

}

catch { }

}

}

});

}



[Digg] [Google] [Facebook]

Tags:

E-mail| Permalink | Trackback | Post RSSRSS comment feed 2 Responses

Related posts

Comments


Steve Lineberry

Response by Steve Lineberry us on 1/6/2009 3:05:12 PM

This is awesome! I've been having this issue for over a month now and even opened a case with MS. Your code instantly fixed my issues and now I can move on with our upgrade without fears of this returning and not being able to be fixed. Thank you so much for figuring this out and posting your code.




André Tobiassen

Response by André Tobiassen no on 1/8/2009 8:15:32 AM

This was awesome for us too! We have also been struggeling with this for a month, and finally this solwed the problem. Thanks!



Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading