Fully Trust a share in .Net 2.0, 3.0 and 3.5

Just some quick info for those struggling with the same problems.

When i google for this almost all answers predate the .net 3.0 framework. Everybody knows that 3.0 are a set of libraries that extend 2.0. what i missed was that 3.5 uses the same core assemblies as 2.0 including the same security settings. This means you still use the CasPol installed from the 2.0 to set full trust in 3.5. Be aware thought that you’ll need to run it for the 32-bit version and 64-bit version separately.

There is a nice post on how to do this from the .net security blog from which I included the next fragment:

since network shares by default only get localintranet permissions, it's relatively common to want to use CasPol to fully trust some shares that you control and know are safe.  However, CasPol syntax being what it is, the command to do this isn't immediately obvious.  if i wanted to trust everything on the share \\shawnfa-srv\tools, the command:

caspol.exe -m -ag 1.2 -url file://\\ShawnFa-Srv/Tools/* FullTrust

would setup the policy to do what i needed.  lets break down this command:

  • -m  - modify the machine level of the policy.  this is needed, since the machine level is where all of the default policy lives.  on nt platforms it's also the default level that CasPol works with, however on Win9x, CasPol will default to the user level, so putting -m in the command line explicitly tells CasPol to use the correct level.
  • -ag 1.2  - add a code group under group 1.2.  in the default policy, group 1.2 is the localintranet group, so the new code group that we're creating will only be checked if the file comes from the intranet.
  • -url file://\\ShawnFa-Srv/Tools/- The membership condition for the new code group should be a UrlMembershipCondition, and it should match anything with a URL that starts with file://ShawnFa-Srv/Tools, meaning that any file on the \\ShawnFa-Srv\Tools share will match this code group.
  • fulltrust  - the permission set to grant assemblies that match the code group.  in this case, fulltrust.

Executing the above command will give you a yes/no confirmation prompt which you can suppress by adding the –pp off switch. Now it’s perfectly usable in scripts.

I kept wondering about 2 things:

  • what if the mapped folder was included in the trusted group?
  • where does it store these settings?

Get the code groups.

To get the right -ag argument for the trusted group call:

caspol.exe –lg

which will give you something like this:

Microsoft (R) .NET Framework CasPol 2.0.50727.3053
Copyright (c) Microsoft Corporation.  All rights reserved.

Security is ON
Execution checking is ON
Policy change prompt is ON

Level = Machine

Code Groups:

1.  All code: Nothing
   1.1.  Zone - MyComputer: FullTrust
      1.1.1.  StrongName - 002400000...: FullTrust
      1.1.2.  StrongName - 000000000...: FullTrust
   1.2.  Zone - Intranet: LocalIntranet
      1.2.1.  All code: Same site Web
      1.2.2.  All code: Same directory FileIO - 'Read, PathDiscovery'
   1.3.  Zone - Internet: Internet
      1.3.1.  All code: Same site Web
   1.4.  Zone - Untrusted: Nothing
   1.5.  Zone - Trusted: Internet
      1.5.1.  All code: Same site Web
Success

From this output we now know that we need to use 1.5 as an –ag argument to FullTrust a path from the Trusted group.

Where is it stored?

The security information is stored in the security.config file (duh) in the following location:

%WINDIR%\Microsoft.NET\Framework\v2.0.50727\CONFIG

Our example inserts the following xml under the Trusted codegroup element:

<CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust">
    <IMembershipCondition class="UrlMembershipCondition" version="1" Url="file://\\ShawnFa-Srv/Tools/*"/>
</CodeGroup>

If you don’t want the settings removed by a call to:

CasPol -all –reset

You can copy the security.config to security.config.default

Tags: , , , , , , , , ,

Comments

Vietnam Tours
Vietnam Tours United Kingdom
11/16/2009 9:44:10 AM Permalink

What a nice theme! Thanks for sharing these useful information! Hope that you will continue doing nice article like this. I will be one of your loyal reader if you maintain this kind of post!

Festival Museum Nusantara
Festival Museum Nusantara United States
1/1/2010 11:30:07 PM Permalink

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can’t wait to read lots of your posts.


Bhutan Travel Agents
Bhutan Travel Agents United States
1/23/2010 8:59:16 AM Permalink

Wonderful writing skills you got mate.

Viajes Vietnam
Viajes Vietnam United States
1/23/2010 8:59:50 AM Permalink

Interesting post

stock broker
stock broker United States
2/21/2010 9:43:49 AM Permalink

I wasn't sure where to ask this but I would like to add your website in one of my directories. Please drop me a line me at your convience because I only list sites with the owners consent - thank you.

Daniel Millions
Daniel Millions United States
2/21/2010 10:13:21 PM Permalink

Do have an email system where I can get your blog posts emailed to me?

Inge Miltner
Inge Miltner Australia
3/1/2010 12:47:17 PM Permalink

I was looking at something similar regarding this on another blog. Interesting. Your viewpoint on it is actually diametrically different to what Which i read through initially. I'm now contemplating over the opposite ideas, yet I’m leaning to a great extent towards yours. But regardless, that's exactly what is so superb concerning modern-day democracy and the market place connected with ideas on-line.

zynga facebook
zynga facebook United States
3/1/2010 3:08:12 PM Permalink

lol one or two of the feedback bloggers post are such stoner remarks, repeatedly i wonder if they even read the articles and items before writing or whether they take a moment to read the title of the post and jot down only the first thought that pops into their brain. in any case, it really is enjoyable to look over keen commentary once in a while compared to the very same, classic post vomit which i mostly see on the internet

unsecured loan
unsecured loan United States
3/2/2010 2:05:47 AM Permalink

Can I quote you on my website if I link back to your website?

hd movies
hd movies United States
3/4/2010 4:56:19 PM Permalink

I like watching movies online, it is way easier than going to the theaters.

Niesha Githens
Niesha Githens United States
3/5/2010 5:59:08 PM Permalink

Though I would've loved it much more if you added a relevant video or at least pictures to back up the explanation, I still thought that your write-up quite helpful. It's usually hard to make a complicated matter seem very easy. I enjoy your weblog and will sign up to your feed so I will not miss anything. Fantastic content

Shizuko Micale
Shizuko Micale United States
3/6/2010 12:15:30 PM Permalink

Well said, you just earned another subscriber

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading