예제 #1
0
        }// AddPermissionSet

        private CSecurityPolicy CreatePolicyNode(PolicyLevelType nType, PolicyLevel pl)
        {
            int             iCookie = 0;
            int             nIndex  = 0;
            CSecurityPolicy node;

            // This node's ordering of the children nodes it inserts is very important
            if (m_iChildren == null || m_iChildren.Length != 3)
            {
                m_iChildren = new int[3];
            }

            switch (nType)
            {
            case PolicyLevelType.Enterprise:
                node = new CSecurityPolicy("Enterprise", pl);
                break;

            case PolicyLevelType.Machine:
                node = new CSecurityPolicy("Machine", pl);
                break;

            case PolicyLevelType.User:
                node = new CSecurityPolicy("User", pl);
                break;

            default:
                throw new Exception("I don't know about this type");
            }

            nIndex = GetNodeIndexNumber(nType);
            CNode gennode = (CNode)node;

            iCookie             = CNodeManager.AddNode(ref gennode);
            m_iChildren[nIndex] = iCookie;

            return(node);
        }// CreatePolicyNode
예제 #2
0
        }// AddMenuItems

        internal override void MenuCommand(int iCommandID)
        {
            // All these menu commands are going to require the policy nodes to be created and expanded.
            // Let's check to see if we've done that already....
            if (NumChildren == 0)
            {
                CNodeManager.CNamespace.Expand(HScopeItem);
            }

            if (iCommandID == COMMANDS.NEW_SECURITYPOLICY)
            {
                CNewSecurityPolicyDialog          nspd = new CNewSecurityPolicyDialog();
                System.Windows.Forms.DialogResult dr   = nspd.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    // To get a 'New' Security policy, we just load a policy from a file that doesn't exist
                    CSecurityPolicy secpolnode = GetSecurityPolicyNode(nspd.SecPolType);

                    // Ok, this is really dumb. I need to create a security file where the user
                    // wants to store the policy before I can tell the Security Manager about it.
                    File.Copy(secpolnode.MyPolicyLevel.StoreLocation, nspd.Filename, true);
                    PolicyLevel pl = SecurityManager.LoadPolicyLevelFromFile(nspd.Filename, nspd.SecPolType);
                    pl.Reset();
                    secpolnode.SetNewSecurityPolicyLevel(pl);
                    secpolnode.SecurityPolicyChanged();
                    // Select the policy node the user just mucked with
                    CNodeManager.SelectScopeItem(secpolnode.HScopeItem);
                }
            }
            else if (iCommandID == COMMANDS.OPEN_SECURITYPOLICY)
            {
                COpenSecurityPolicyDialog ospd = new COpenSecurityPolicyDialog(new String[] { EnterpriseNode.ComputerPolicyFilename,
                                                                                              MachineNode.ComputerPolicyFilename,
                                                                                              UserNode.ComputerPolicyFilename });
                System.Windows.Forms.DialogResult dr = ospd.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    // Try and load the given security policy
                    PolicyLevel pl;
                    try
                    {
                        pl = SecurityManager.LoadPolicyLevelFromFile(ospd.Filename, ospd.SecPolType);
                    }
                    catch
                    {
                        MessageBox(String.Format(CResourceStore.GetString("CGenSecurity:isNotASecurityFile"), ospd.Filename),
                                   CResourceStore.GetString("CGenSecurity:isNotASecurityFileTitle"),
                                   MB.ICONEXCLAMATION);
                        return;
                    }
                    CSecurityPolicy secpolnode = GetSecurityPolicyNode(ospd.SecPolType);
                    secpolnode.SetNewSecurityPolicyLevel(pl);
                    // Select the policy node the user just mucked with
                    CNodeManager.SelectScopeItem(secpolnode.HScopeItem);
                }
            }
            else if (iCommandID == COMMANDS.EVALUATE_ASSEMBLY)
            {
                CWizard wiz = new CEvalAssemWizard();
                wiz.LaunchWizard(Cookie);
            }
            else if (iCommandID == COMMANDS.TRUST_ASSEMBLY)
            {
                // Let's create a new wizard now to dump any old settings we have
                CFullTrustWizard wiz = new CFullTrustWizard(MachineNode.ReadOnly, UserNode.ReadOnly);

                wiz.LaunchWizard(Cookie);

                // See if it updated anything a codegroup
                if (wiz.MadeChanges)
                {
                    CSecurityPolicy sp = GetSecurityPolicyNode(Security.GetPolicyLevelTypeFromLabel(wiz.PolLevel.Label));
                    sp.RedoChildren();
                    sp.SecurityPolicyChanged();
                }
            }
            else if (iCommandID == COMMANDS.ADJUST_SECURITYPOLICY)
            {
                CSecurityAdjustmentWizard wiz = new CSecurityAdjustmentWizard(MachineNode.ReadOnly, UserNode.ReadOnly);
                wiz.LaunchWizard(Cookie);

                // Check to see if we need to tell any policies that we changed them
                if (wiz.didUserPolicyChange)
                {
                    UserNode.RedoChildren();
                    UserNode.SecurityPolicyChanged();
                }

                if (wiz.didMachinePolicyChange)
                {
                    MachineNode.RedoChildren();
                    MachineNode.SecurityPolicyChanged();
                }
            }
            else if (iCommandID == COMMANDS.CREATE_MSI)
            {
                CWizard wiz = new CCreateDeploymentPackageWizard(this);
                wiz.LaunchWizard(Cookie);
            }
            else if (iCommandID == COMMANDS.RESET_POLICY)
            {
                int nRes = MessageBox(CResourceStore.GetString("CGenSecurity:ConfirmResetAll"),
                                      CResourceStore.GetString("CGenSecurity:ConfirmResetAllTitle"),
                                      MB.YESNO | MB.ICONQUESTION);
                if (nRes == MB.IDYES)
                {
                    if (!EnterpriseNode.ReadOnly)
                    {
                        EnterpriseNode.ResetSecurityPolicy();
                    }
                    if (!MachineNode.ReadOnly)
                    {
                        MachineNode.ResetSecurityPolicy();
                    }
                    if (!UserNode.ReadOnly)
                    {
                        UserNode.ResetSecurityPolicy();
                    }
                    MessageBox(CResourceStore.GetString("CGenSecurity:PoliciesResetAll"),
                               CResourceStore.GetString("CGenSecurity:PoliciesResetAllTitle"),
                               MB.ICONINFORMATION);
                }
            }
        }// MenuCommand
예제 #3
0
        }// DoesNodeBelongToAnApplication

        static private String TranslateMenuCommandToString(CNode node, int iResultNum, int iMenuCommand)
        {
            switch (iMenuCommand)
            {
            case COMMANDS.ADD_GACASSEMBLY:
                return(CResourceStore.GetString("CCommandHistory:AddGacAssembly"));

            case COMMANDS.ADD_APPLICATION:
                return(CResourceStore.GetString("CCommandHistory:AddApplication"));

            case COMMANDS.NEW_PERMISSIONSET:
                // We need to figure out what policy level this is for
                // The node should be a CPermissionSet node
                if (node is CPermissionSet)
                {
                    // The parent should be a CSecurityPolicyNode....
                    CSecurityPolicy spn = CNodeManager.GetNodeByHScope(node.ParentHScopeItem) as CSecurityPolicy;
                    if (spn != null)
                    {
                        return(String.Format(CResourceStore.GetString("CCommandHistory:NewPermissionSet"), spn.LocalizedPolicyName));
                    }
                }
                return(null);

            case COMMANDS.NEW_SECURITYPOLICY:
                return(CResourceStore.GetString("CCommandHistory:CreateNewSecurityPolicy"));

            case COMMANDS.OPEN_SECURITYPOLICY:
                return(CResourceStore.GetString("CCommandHistory:OpenSecurityPolicy"));

            case COMMANDS.EVALUATE_ASSEMBLY:
                return(CResourceStore.GetString("CCommandHistory:EvaluatePolicy"));

            case COMMANDS.ADJUST_SECURITYPOLICY:
                return(CResourceStore.GetString("CCommandHistory:AdjustPolicy"));

            case COMMANDS.CREATE_MSI:
                return(CResourceStore.GetString("CCommandHistory:CreateDeploymentPackage"));

            case COMMANDS.TRUST_ASSEMBLY:
                return(CResourceStore.GetString("CCommandHistory:TrustAssembly"));

            case COMMANDS.FIX_APPLICATION:
                // See if they're doing a generic fix or fixing a specific application
                if (node is CApplication)
                {
                    return(String.Format(CResourceStore.GetString("CCommandHistory:FixApplication"), node.DisplayName));
                }
                else     // This is just the generic fix application
                {
                    return(CResourceStore.GetString("CCommandHistory:FixGenApplication"));
                }

            case COMMANDS.RESET_POLICY:
                // See if we're resetting all of them or just a specific one
                if (node is CSecurityPolicy)
                {
                    return(String.Format(CResourceStore.GetString("CCommandHistory:ResetSinglePolicy"), ((CSecurityPolicy)node).LocalizedPolicyName));
                }
                else
                {
                    // We're resetting all of them
                    return(CResourceStore.GetString("CCommandHistory:ResetAllPolicy"));
                }
            }
            return(null);
        }// TranslateMenuCommandToString