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

2. December 2008

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 { }

}

}

});

}

For thos who are not aware of how to use this code as is, follow these comments, thanks to Rob:

I came back here to copy the URL to pass on so a friend and noticed Alex's message. I guess I could have provided more information on what I did.

1) I used Visual Studio 2005 (configured with SharePoint DLLs available)
2) I created a C# console application
3) There should be some using statements that appear automatically. In addition to these, I added:
using Microsoft.SharePoint;
using System.XML;
4) The first statement of the code listed above appears as follows:
namespace <MYNAME>
{
class Program
{
static void Main(string[] args)
{
using (SPWeb web = new SPSite(args[1]).RootWeb)
5) If you cut and pasted the original code above from the web, the spacing is off - the colors helped me sort it all out.
6) I had to add the keyword static in front of all the functions in the original code:
private static string UpdateSchema(string schemaXml)
private static void ShowWebTree(string url)
7) The ContainsSwitch call really had me confused because I couldn't find it. I surmised that it must be something that each programmer creates on his/her own. I found a ContainsSwitch function that worked for me at www.java2s.com/.../CommandLine.java.htm I created the function as

private static bool ContainsSwitch(String[] arrArgs, String switch_str)
{
for (int i = 0; i < arrArgs.Length; ++i)
{
if (arrArgs[i].Equals(switch_str))
{
return true;
}
}
return false;
}
8) I then compiled this into an executable.
9) I ran it on the SharePoint server. Note that you need two arguments. The first is supposed to be any exclusions but since I did not have any, I just typed the word none. The second argument is the URL to the SharePoint site.

SharePoint

Comments

2/25/2010 12:04:17 PM #
That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith.
2/26/2010 10:38:18 AM #
Great post! I lookin for this, and I'm found in here. Great site. I will visit here again.
2/28/2010 9:57:13 PM #
Should I get a Virtual Private Server? Right now I am using shared hosting but they keep turning off my websites because of high server overload. Im getting about 2,000 UV a day. What hosting should I get?
3/9/2010 8:54:17 PM #
Hmm, there are some trouble with the first link, as it returns a 404 error.
3/15/2010 10:27:51 AM #
I need to do to get this work work? All works well (I can see the sharepoint list I want to link to) however, when I click finish I get and unhandled error and get kicked out of VISIO.the person who create this post he is a great human..thanks for shared this with us.i found this informative and interesting blog so i think so its very useful and knowledge able
3/20/2010 2:45:10 PM #
A computer network refers to a group of interconnected computers. Networks can be classified according to the network layer in which they operate according to basic reference models.
4/7/2010 11:08:06 AM #
Hello nice blog im from liverpool i found this on  I seen it on the top ten searches i found this blog very interesting good luck with it i will return to this blog soon
4/28/2010 5:43:03 AM #
i like the layout of your blog. hope you don't mind if i do something similar with mine.
5/29/2010 1:36:38 PM #
Good idea, thanks for posting
6/6/2010 11:22:19 PM #
Just thought you might like to know I came to your site from the first page of aBing seach. Great Job. I know how hard it is to get your your site on the first page of a search. Ive purchased program after program and finally got </A><A href="nerfnstrikevulcanebf25blasteryellow.net/.../">listen to music online for free without downloading</A></SPAN></SPAN></SPAN> on the first page. sheesh only took 2weeks!!
6/7/2010 10:29:41 PM #
Good site, where did you come up with the knowledge in this piece of writing? I'm happy I found it though, ill be checking back soon to see what other articles you have.
6/8/2010 3:04:41 PM #
Ha genuine blog how did you get our site to show up in Stumble Upon without paying. I heard its not really hard, OH, fav toy in the world for a 30 yo is got to be a <A href="http://nerfgunsforsale.org/">Nerf guns for sale</A> </SPAN></SPAN>I bought it for my nephew and theyve never got to open it, I shoot up my hamster and its exilrating &lt;-----(spellings?) ;)

6/11/2010 7:32:00 PM #
very nice reading your blog.
6/18/2010 10:20:47 AM #
Here is the 2nd occasion I have come across your blog post in the last couple weeks.  Looks like I should bookmark it.
6/20/2010 9:07:30 AM #
Great blog post, lots of useful information and facts.
7/26/2010 7:15:00 PM #
Thank you for the advice.  I've just resorted to calling for help whenever my files get corrupted.
8/6/2010 4:05:05 PM #
Pingback from thecoolwind.info

Buy Puma Future Cat Shoes Online
8/11/2010 8:30:18 PM #
hi thank you for this wonderful informative blog
8/13/2010 7:38:51 PM #
Contrary to what others are saying I believe your blog could really use some work. I can't even work out how to subscribe to your RSS.
simshall
simshall
8/25/2010 10:25:58 PM #
Great!!! this solution fixed my issue. Thanks

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading