Creating Security Descriptors for MOSS 2007 Managed Protocol Handlers

A few months ago I found this great blog by John Kozell at Microsoft.  He showed us how to build custom SharePoint Search extensions that I though was very innovative and included in my SharePoint 2007 Search Customization course.  Here is a link to the code that I modified to use the new .NET 3.0 classes.

http://blogs.msdn.com/johnkoz/archive/2009/03/05/creating-security-descriptors-for-moss-2007-managed-protocol-handlers.aspx

Enjoy!
Chris

Creating Folders/Users/Permissions Programtically

Set of code to do some cool things programatically…

 

SPSite site = new SPSite("http://sharepoint2007:100");
            site.AllowUnsafeUpdates = true;
            SPWeb web = site.RootWeb;
            web.AllowUnsafeUpdates = true;

            SPListTemplateCollection coll = web.ListTemplates;
            SPList newList = null;

            //create a list
            try
            {
                newList = web.Lists[web.Lists.Add("Assignments", "Student Assignments", coll[1])];
            }
            catch (Exception ex)
            {
                newList = web.Lists["Assignments"];
            }

            string[] users = {"training\administrator","training\student"};

            //iterate all the users (from database?)
            foreach (string s_user in users)
            {
                //add to site
                SPUser user = web.EnsureUser(s_user);                                                              
                string name = s_user;

                if ( user.LoginName.Contains("\"))
                    name = user.LoginName.Substring(user.LoginName.IndexOf("\") + 1);

                //create a folder for each user
                SPListItem folder = newList.Items.Add("", SPFileSystemObjectType.Folder,name);
                try
                {
                    folder.Update();
                    newList.Update();
                }
                catch (Exception ex)
                {                    
                }

                //set permissions            
                SPRoleDefinition RoleDefinitionRdr = web.RoleDefinitions.GetByType(SPRoleType.Administrator);
                SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)user);
                roleAssignment.RoleDefinitionBindings.Add(RoleDefinitionRdr);

                //adds permissions to site
                web.RoleAssignments.Add(roleAssignment);

                if (!folder.HasUniqueRoleAssignments)
                {
                    folder.BreakRoleInheritance(false);
                }

                while (folder.RoleAssignments.Count > 0)
                    folder.RoleAssignments.Remove(0);

                folder.RoleAssignments.Add(roleAssignment);
                folder.Update();
            }

Powershell script to create Active Directory user Profiles and MySites

This is awesome…check it out!  A powershell script that will create a profile for every AD user, then creates there My Site!

 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")

$dom = "LDAP://CN=Users;DC=training;DC=corp"
$root = new-object DirectoryServices.DirectoryEntry $dom

$selector = new-object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root

$adobj = $selector.findall() | where {$_.properties.objectcategory -match "CN=Person"}
$spsite = new-object Microsoft.SharePoint.SPSite("http://sharepoint2007:100")
$context = [Microsoft.Office.Server.ServerContext]::GetContext($spsite)
$pmanager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

ForEach ($person in $adobj)
{
$prop = $person.properties
$prop.cn

$exists = $pmanager.UserExists($prop.cn)

if ($exists -eq $false)
{
$pmanager.CreateUserProfile($prop.cn)
}

$up = $pmanager.GetUserProfile($prop.cn)
$up.CreatePersonalSite()

}

 

Powershell script to backup My Sites!

This one rocks too!

 $ssppath = "http://sharepoint2007:100/personals"

$out = stsadm -o enumsites -url $ssppath
$out = [xml] $out

ForEach ($web in $out.Sites.Site )
{
$url = $web.url

$name = "c:" + $url.SubString($url.LastIndexOf("/")+1).replace(":","") + ".bak"

write-host "stsadm -o backup -url $url -filename $name -overwrite"
stsadm -o backup -url $url -filename $name -overwrite

}

Most Commonly Missed Best Practice with Internet Sites

Wanna know what it is?  It is a disaster waiting to happen!  

Some day an IIS 6.0 vulnerability will come out that allows you to get administrator access to the _vti_bin directory of your SharePoint site.  You will then be able to execute a call to the Lists web service and delete the "Pages" document library!  

To prove it, do a search on Pages/default.aspx in google.  You will get a listing on all the sites on the internet that are running sharepoint as their internet site.  Check their _vti_bin directory access by appending /_vti_bin/lists.asmx

 If you get the web service page for the list service, that company has setup there site WRONG!

The correct way of doing things is to create an extended web application that HAS the _vti_bin and the original with the _vti_bin DELETED!  The original is the internet accessable one and the extended one is accessible only by internal staff (so you can use SharePoint Designer and such).

Anyone feel like writing a vulnerability and the code to delete all the pages  document libraries on the internet to prove my point???  Couldn't be too hard 🙂

CJG

Windows Workflow Foundation Course

Oh yeah, I'm writing it.  And I'll tell you…it's going to be awesome!  I'll post the outline later, but so far, it's looking really good! 

I'll also be posting a Powershell script to backup "My Sites" in the next couple of days!  I would have done it today, but I have had the flu!  Yuk!  Just now getting over it!

Hope everyone is doing great!
Chris

The CJG Office 2007 Object Model

I have been doing alot with Office 2007 documents.  Specifically PowerPoint and Word, basically I am dynamically generating them for all kinds of applications!  Using my Database class builder tool, I have generated an object model around the Office XML schema!

I will be releasing this later in March anyway, so figure I would post about it now!  Maybe some of you will find it helpful!

Chris

 Here's a code example:

 wp p = new wp();
            p.PId = null;
            p.RsidP = null;
            p.RsidR = null;
            p.RsidRDefault = null;
            p.RsidRPr = null;
            p.WsmartTags = null;

            wr r = new wr();
            r.RId = null;
            r.RsidR = null;
            r.RsidRPr = null;
            wbr br = new wbr();
            br.Type = "page";
            r.Wbr = br;
            p.Wrs.Add(r);

Invalid characters for SharePoint titles

This deserves lots of reposting!  Today a student had an issue with the JavaScript not working on a list!  Seems that several different chars will cause SharePoint to fail in soo many different ways!  Check out this Microsoft knowledge base!

 http://support.microsoft.com/default.aspx?scid=kb;en-us;905231

 Yikes!   Three cheers for validation!

 

 

The Only Thing You Can’t Do With the SharePoint Object Model

Can you guess what item I found that you can't do with the SharePoint Object Model?  I have been through the entire API from top to bottom and there seems to be one thing missing!

 A way to add authoratative URLs to your SSP Search Configuration!  In my latest course, SharePoint Search Administration, you explore the Search API looking to perform every task that is available through the web UI.  I was successful in doing everything but add those nice relevance algorithm changes authoritative URLs

 If you have successfully done this, ping me back!  Otherwise, I have to think that it was the ONE AND ONLY THING that got left out of the Object Model (oh, let's not talk about the web services interfaces shall we…).