
Sample Group Addition Commands
The following procedures describe how to perform some of the most common code group addition tasks.
To add a code group that targets code from the intranet
Use the -zone option, and specify Intranet as the membership value.
The following command associates the Everything permission set with code from the intranet. The code group is also given the name Intranet_CG. You can use this name to refer to the newly created code group, rather than using its numeric labels.
caspol –addgroup 1.1. –zone Intranet Everything –name "Intranet_CG"
To add a code group that targets code from the Internet Explorer Trusted sites
Use the –zone option, and specify Trusted as the membership value.
The following command associates the LocalIntranet permission set with code from the trusted zone and inserts the new code group as a child of the root of the code group hierarchy.
caspol -addgroup All_Code -zone Trusted LocalIntranet
To add a code group that targets a specific software publisher
Use the –pub option, and specify a certificate file, a signed file, or the hexadecimal representation of an X.509 certificate.
Files from a software publisher must be signed appropriately for this membership condition to work. The membership condition can be constructed on the basis of either an actual certificate file or a signed .exe file.
Suppose the certificate file for FourthCoffee (FourthCoffee.cer) is available. The following command adds a code group in the machine policy for code published by FourthCoffee and associates the Nothing permission set with the new group. The code group is added as a child code group of the root.
caspol –machine –addgroup 1 –pub –cert FourthCoffee.cer Nothing
To add a code group that targets code from a particular Web site
Use the –site option, and specify the URL of the Web site.
Note: |
|---|
Due to the possibility of DNS name spoofing, using a Web site as a membership condition is not an effective way to ascertain the identity of code. Where possible, use a strong name membership condition, publisher membership condition, or the hash membership condition.
|
The following command associates the Intranet permission set with code from www.microsoft.com.
caspol –addgroup 1 –site www.microsoft.com Intranet
To add a code group that targets code from a particular URL
Use the –url option, and specify the URL of the site.
The URL must include a protocol, such as http://, http://, or ftp://. Additionally, a wildcard character (*) can be used to specify multiple assemblies from a particular URL.
Note: |
|---|
Because a URL can be identified using multiple names, using a URL as a membership condition is not a safe way to ascertain the identity of code. Where possible, use a strong name membership condition, a publisher membership condition, or the hash membership condition.
|
caspol –user –addgroup 1 –url http://www.contoso.com/bin/* FullTrust
caspol –user –addgroup 1 –url http://www.contoso.com/bin/MyAssembly.dll FullTrust
To add a code group that overrides other permissions at a policy level
Set the –exclusive flag for the new code group.
The following command adds a code group under the Intranet_cg code group. The new code group grants the Everything permission set if the zone is trusted, overriding any other permissions that other code groups might grant.
caspol –addgroup "Intranet_cg" –zone Trusted Everything –exclusive on
To add a code group with a custom membership condition
Use the –custom option, and specify an XML file that contains the XML serialization of the custom membership condition.
Caspol.exe supports the use of custom membership conditions in policy, which makes the policy system highly extensible.
The following command adds a new code group to the root of the user policy. This new code group contains a custom membership condition found in the NewMembershipCondition.xml file and grants full trust to assemblies matching this membership condition.
caspol –user –addgroup All_Code –custom NewMembershipCondition.xml FullTrust
To add a code group with a name and description
Use the –name option, and specify a name for the code group. Double quotes (" ") are required around names that contain spaces.
Use the –description option, and specify a description for the code group.
You can use the name later to refer to a code group. The name provides better support than numeric labels for scripting policy changes.
Default policy is shipped with default names. If not explicitly changed by an administrator, the default names make it easy for administrators using Caspol.exe to access specific code groups across policies and computers.
The following command adds a code group under the All_Code group in the machine policy. The new code group checks for a FourthCoffee strong name (as found on Signed.exe) and grants FullTrust to all code that is so signed. The code group is named FouthCoffeeStrongName and is given an appropriate description.
caspol –machine –addgroup All_Code –strong –file signed.exe FullTrust –name FouthCoffeeStrongName –description "Code group granting trust to code signed by FourthCoffee"
Note: |
|---|
If the same name is present in more than one code group, Caspol.exe resolves to the first code group it can find with the given name. It searches all the child code groups of a code group before searching sibling groups.
|