}// TaskPadTaskNotify internal bool AddConfiguredAssembly(BindingRedirInfo bri) { // Let's trace through our parents looking for an Application node // If this node's parent is an Application node, then we know we're // configuring assemblies on a per app basis CNode node = null; if (ParentHScopeItem != -1) { node = CNodeManager.GetNodeByHScope(ParentHScopeItem); } String sPostFix = ""; // If this is an application node, make sure we tell the config store // about it if (node is CApplication) { sPostFix = "," + ((CApplication)node).AppConfigFile; } if (!CConfigStore.SetSetting("ConfiguredAssemblies" + sPostFix, bri)) { return(false); } // Now we'll tell out node to Refresh itself, // but only if we're showing the list view if (m_oResults == this) { RefreshResultView(); } return(true); }// AddConfiguredAssembly
}// AddMenuItems internal override void MenuCommand(int nCommandID, Object oResultItem) { if (nCommandID == COMMANDS.DUPLICATE_PERMISSIONSET) { NamedPermissionSet nps = (NamedPermissionSet)m_psetWrapper.PSet.Copy(); String sBaseName = nps.Name; nps.Name = String.Format(CResourceStore.GetString("CSinglePermissionSet:PrependtoDupPSets"), nps.Name); int nCounter = 1; // make sure it's not already used while (Security.isPermissionSetNameUsed(m_pl, nps.Name)) { nCounter++; nps.Name = String.Format(CResourceStore.GetString("CSinglePermissionSet:NumPrependtoDupPSets"), nCounter.ToString(), sBaseName); } CNode node = CNodeManager.GetNodeByHScope(ParentHScopeItem); CSinglePermissionSet newNode = ((CPermissionSet)node).AddPermissionSet(nps); newNode.SecurityPolicyChanged(); // Put the selection on the new permission set we just created CNodeManager.SelectScopeItem(newNode.HScopeItem); } else if (nCommandID == COMMANDS.VIEW_PERMISSION) { int iResultItem = (int)oResultItem - 1; // Pop up the Dialog Box for this permission (new CReadOnlyPermission((IPermission)m_alPermissions[iResultItem])).ShowDialog(); } else if (nCommandID == COMMANDS.ADD_PERMISSIONS) { CAddPermissionsWizard wiz = new CAddPermissionsWizard(m_psetWrapper); wiz.LaunchWizard(Cookie); if (wiz.didFinish) { SecurityPolicyChanged(); GenerateGivenPermissionsStringList(); CNodeManager.Console.SelectScopeItem(HScopeItem); } } else if (nCommandID == COMMANDS.SHOW_LISTVIEW) { m_oResults = this; RefreshResultView(); m_fShowHTMLPage = false; } else if (nCommandID == COMMANDS.SHOW_TASKPAD) { m_oResults = m_taskpad; m_fShowHTMLPage = true; // The HTML pages comes displayed with this checkbox marked. Make // sure we update the xml setting CConfigStore.SetSetting("ShowHTMLForPermissionSet", "yes"); RefreshResultView(); } }// MenuCommand
}// onDoubleClick internal override int onDelete(Object o) { String sMessage; if (o is ArrayList) { sMessage = CResourceStore.GetString("CVersionPolicy:ConfirmDeleteConfig"); } else { sMessage = String.Format(CResourceStore.GetString("CVersionPolicy:ConfirmDeleteSingleConfig"), ((BindingRedirInfo)o).Name); } int nRes = MessageBox(sMessage, CResourceStore.GetString("CVersionPolicy:ConfirmDeleteConfigTitle"), MB.ICONQUESTION | MB.YESNO); if (nRes == MB.IDYES) { // Let's trace through our parents looking for an Application node CNode node = CNodeManager.GetNode(m_iCookie); // If this node's parent is an Application node, then we know we're // configuring assemblies on a per app basis int iParentHScope = node.ParentHScopeItem; if (iParentHScope != -1) { node = CNodeManager.GetNodeByHScope(iParentHScope); } String sPostFix = ""; // If this is an application node, make sure we tell the config store // about it if (node is CApplication) { sPostFix = "," + ((CApplication)node).AppConfigFile; } if (o is ArrayList) { ArrayList al = (ArrayList)o; int nLen = al.Count; for (int i = 0; i < nLen; i++) { int iResultNum = ((int)al[i]) - 1; CConfigStore.SetSetting("ConfiguredAssembliesDelete" + sPostFix, ((BindingRedirInfo)m_ol[iResultNum])); } } else { CConfigStore.SetSetting("ConfiguredAssembliesDelete" + sPostFix, (BindingRedirInfo)o); } // Now we'll Refresh ourselves RefreshResultView(); } return(HRESULT.S_OK); }// onDelete
protected void SecurityPolicyChanged() { // Let's tell our parent that security policy changed... CNode node = CNodeManager.GetNodeByHScope(ParentHScopeItem); if (node is CSecurityNode) { ((CSecurityNode)node).SecurityPolicyChanged(); } } // SecurityPolicyChanged
}// CreatePropertyPages internal CSinglePermissionSet AddPermissionSet(NamedPermissionSet nps) { // Run up until we come to the policy node CNode node = CNodeManager.GetNodeByHScope(ParentHScopeItem); while (!(node is CSecurityPolicy)) { node = CNodeManager.GetNodeByHScope(node.ParentHScopeItem); } // Ok, we have the policy node. Let's tell it to add this permission set return(((CSecurityPolicy)node).AddPermissionSet(nps)); }// AddPermissionSet
}// AddMenuItems internal override void MenuCommand(int iCommandID, Object oResultNum) { if (iCommandID == COMMANDS.ADD_ASSEMBLY) { CApplicationDepends appDepends = null; // Let's trace through our parents looking for an Application node CNode node = CNodeManager.GetNode(m_iCookie); // If this node's parent is an Application node, then we know we're // configuring assemblies on a per app basis int iParentHScope = node.ParentHScopeItem; if (iParentHScope != -1) { node = CNodeManager.GetNodeByHScope(iParentHScope); } // If this is an application node, make sure we tell the config store // about it if (node is CApplication) { // Cool, we have a dependent assemblies node appDepends = ((CApplication)node).AppDependsNode; } CConfigAssemWizard wiz = new CConfigAssemWizard(appDepends); wiz.LaunchWizard(Cookie); if (wiz.NewAssembly != null) { if (AddConfiguredAssembly(wiz.NewAssembly)) { onDoubleClick(wiz.NewAssembly); } } } else if (iCommandID == COMMANDS.SHOW_LISTVIEW) { m_oResults = this; RefreshResultView(); m_fShowHTMLPage = false; } else if (iCommandID == COMMANDS.SHOW_TASKPAD) { m_oResults = m_taskPad; m_fShowHTMLPage = true; // The HTML pages comes displayed with this checkbox marked. Make // sure we update the xml setting CConfigStore.SetSetting("ShowHTMLForConfigAssem", "yes"); RefreshResultView(); } }// MenuCommand
}// IncrementCommand static private StringCollection BuildPathToNode(CNode node) { StringCollection sc = new StringCollection(); int iParentHScope = node.ParentHScopeItem; sc.Add(node.Name); while (iParentHScope != -1) { node = CNodeManager.GetNodeByHScope(iParentHScope); iParentHScope = node.ParentHScopeItem; sc.Add(node.Name); } return(sc); }// BuildPathToNode
}// Showing internal override int onDelete(Object o) { int nRes = MessageBox(CResourceStore.GetString("CApplication:VerifyRemoveApp"), CResourceStore.GetString("CApplication:VerifyRemoveAppTitle"), MB.ICONQUESTION | MB.YESNO); if (nRes == MB.IDYES) { // Grab our parent node and tell him to remove us CNodeManager.GetNodeByHScope(ParentHScopeItem).RemoveSpecificChild(Cookie); // Change the XML... if (CConfigStore.SetSetting("RemoveAppConfigFile", m_appInfo)) { return(HRESULT.S_OK); } } return(HRESULT.S_FALSE); }// onDelete
}// SecurityPolicyChanged internal virtual void SecurityPolicyChanged(bool fShowDialog) { // Let's tell the policy level node that security policy changed... CNode node = CNodeManager.GetNodeByHScope(ParentHScopeItem); // If this is a Security Policy node, just send it up one if (this is CSecurityPolicy) { ((CSecurityNode)node).SecurityPolicyChanged(fShowDialog); } while (!(node is CRootNode) && !(node is CSecurityPolicy)) { node = CNodeManager.GetNodeByHScope(node.ParentHScopeItem); } if (node is CSecurityPolicy) { ((CSecurityPolicy)node).SecurityPolicyChanged(fShowDialog); } } // PolicyChanged
}// BuildPathToNode static private bool DoesNodeBelongToAnApplication(CNode node, out String sAppName) { int iParentHScope = node.ParentHScopeItem; node = null; while (iParentHScope != -1 && !(node is CApplication)) { node = CNodeManager.GetNodeByHScope(iParentHScope); iParentHScope = node.ParentHScopeItem; } sAppName = node.DisplayName; if (node is CApplication) { return(true); } else { return(false); } }// DoesNodeBelongToAnApplication
}// TaskPadTaskNotify private void RemoveThisCodegroup() { // Grab our parent codegroup and tell him to remove us CNode node = CNodeManager.GetNodeByHScope(ParentHScopeItem); if (node is CSingleCodeGroup) { ((CSingleCodeGroup)node).RemoveChildCodegroup(this); } else { // "Help! I don't know who my parent is!" // In this case, we'll just return and do nothing return; } // Now let's remove ourselves from the tree // Make sure we close all open property pages CloseAllMyPropertyPages(); CNodeManager.GetNodeByHScope(ParentHScopeItem).RemoveSpecificChild(Cookie); m_fIAmDeleted = true; }// RemoveThisCodegroup
}// ResultItemSelected internal override int onDelete(Object o) { // This is for the node if (o == null) { // First, make sure none of the code groups use this permission set CodeGroup cg = m_pl.RootCodeGroup; cg = GetCGUsingPermissionSet(cg); if (cg != null) { MessageBox(String.Format(CResourceStore.GetString("CSinglePermissionSet:isUsingPermissionSet"), cg.Name), CResourceStore.GetString("CSinglePermissionSet:isUsingPermissionSetTitle"), MB.ICONEXCLAMATION); } else { int nRes = MessageBox(CResourceStore.GetString("CSinglePermissionSet:ConfirmDeletePSet"), CResourceStore.GetString("CSinglePermissionSet:ConfirmDeletePSetTitle"), MB.YESNO | MB.ICONQUESTION); if (nRes == MB.IDYES) { m_pl.RemoveNamedPermissionSet(m_psetWrapper.PSet); // Close all the property pages associated with this node CloseAllMyPropertyPages(); // Now let's remove ourselves from the tree CNodeManager.GetNodeByHScope(ParentHScopeItem).RemoveSpecificChild(Cookie); m_fDeleted = true; SecurityPolicyChanged(); // Ok, all references to this node should be gone. return(HRESULT.S_OK); } } return(HRESULT.S_FALSE); } else // this is a result item --- a permission { int nRes = MessageBox(CResourceStore.GetString("CSinglePermissionSet:ConfirmDeletePerm"), CResourceStore.GetString("CSinglePermissionSet:ConfirmDeletePermTitle"), MB.YESNO | MB.ICONQUESTION); if (nRes == MB.IDYES) { int iResultItem = (int)o - 1; m_psetWrapper.PSet.RemovePermission(m_alPermissions[iResultItem].GetType()); m_psetWrapper.PolLevel.ChangeNamedPermissionSet(m_psetWrapper.PSet.Name, m_psetWrapper.PSet); // Remove this from our list of permissions m_alPermissions.RemoveAt(iResultItem); // Now we need to re-create our permissions array String[] newItems = new String[m_sItems.Length - 1]; int nIndex = 0; for (int i = 0; i < m_sItems.Length; i++) { if (i != iResultItem) { newItems[nIndex++] = m_sItems[i]; } } m_sItems = newItems; // Now, re-select this node to update our changes CNodeManager.Console.SelectScopeItem(HScopeItem); SecurityPolicyChanged(); return(HRESULT.S_OK); } } return(HRESULT.S_FALSE); }// onDelete
}// AddMenuItems internal override void MenuCommand(int nCommandID) { if (nCommandID == COMMANDS.CREATE_CODEGROUP) { CNewCodeGroupWizard wiz = new CNewCodeGroupWizard(m_pl); wiz.LaunchWizard(Cookie); // Ok, let's see what goodies we have... String sPermSetName = null; if (wiz.CreatedPermissionSet != null) { sPermSetName = AddPermissionSet(wiz.CreatedPermissionSet).DisplayName; SecurityPolicyChanged(); } if (wiz.CreatedCodeGroup != null) { try { CodeGroup cg = wiz.CreatedCodeGroup; if (sPermSetName != null) { PermissionSet ps = m_pl.GetNamedPermissionSet(sPermSetName); PolicyStatement pols = cg.PolicyStatement; pols.PermissionSet = ps; cg.PolicyStatement = pols; } CSingleCodeGroup node = AddCodeGroup(wiz.CreatedCodeGroup); // Put the focus on the newly created codegroup CNodeManager.SelectScopeItem(node.HScopeItem); } catch (Exception) { MessageBox(CResourceStore.GetString("CSingleCodeGroup:ErrorCreatingCodegroup"), CResourceStore.GetString("CSingleCodeGroup:ErrorCreatingCodegroupTitle"), MB.ICONEXCLAMATION); } } } else if (nCommandID == COMMANDS.DUPLICATE_CODEGROUP) { CNode node; CodeGroup newcg = m_cg.Copy(); // Change this code group's name String sBaseName = newcg.Name; newcg.Name = String.Format(CResourceStore.GetString("CSingleCodeGroup:PrependtoDupCodegroups"), newcg.Name); int nCounter = 1; // make sure it's not already used while (Security.isCodeGroupNameUsed(m_pl.RootCodeGroup, newcg.Name)) { nCounter++; newcg.Name = String.Format(CResourceStore.GetString("CSingleCodeGroup:NumPrependtoDupCodegroups"), nCounter.ToString(), sBaseName); } CNode newCodeGroup = null; // If we are the root codegroup, then we'll add this as a child if (Security.GetRootCodeGroupNode(m_pl) == this) { newCodeGroup = AddCodeGroup(newcg); node = this; } else { node = CNodeManager.GetNodeByHScope(ParentHScopeItem); newCodeGroup = ((CSingleCodeGroup)node).AddCodeGroup(newcg); } // Select the new item CNodeManager.SelectScopeItem(newCodeGroup.HScopeItem); } }// MenuCommand
}// Initialize //------------------------------------------------- // Notify // // This is where most of the interesting stuff happens. // Whenever MMC needs something from the snapin, it will // send a message to Notify, and notify is responsible // to take care (or delegate) whatever MMC wants //------------------------------------------------- public int Notify(IntPtr lpDataObject, uint aevent, IntPtr arg, IntPtr param) { // We don't handle any of the special data objects here if (lpDataObject == (IntPtr)DOBJ.CUSTOMOCX || lpDataObject == (IntPtr)DOBJ.CUSTOMWEB) { return(HRESULT.S_FALSE); } IDataObject ido = null; if (lpDataObject != (IntPtr)0) { ido = (IDataObject)Marshal.GetObjectForIUnknown(lpDataObject); } CDO Data; // This will hold the object MMC wants action performed on // lpDataObject is just a CDO... we're going to obtain the CDO interface. // if lpDataObject is null, then there needs to be action performed on the root // node. if (ido != null) { Data = (CDO)ido; } else { CNode node = CNodeManager.GetNode(CNodeManager.RootNodeCookie); Data = new CDO(node); } switch (aevent) { // The user clicked the 'forward' or 'back' button on the MMC browser. // We need to sync up our node to the new result view case MMCN.RESTORE_VIEW: return(Data.Node.onRestoreView((MMC_RESTORE_VIEW)Marshal.PtrToStructure(arg, typeof(MMC_RESTORE_VIEW)), param)); // We're being asked if we will accept an item to be pasted // (Used here to tell MMC if this node is a valid drag-and-drop // location) case MMCN.QUERY_PASTE: // See if it's asking about result items or scope items return(Data.Node.doAcceptPaste((IDataObject)Marshal.GetObjectForIUnknown((IntPtr)arg))); // We're being given an item to paste. (Used here to tell MMC that // something is being dropped here from a drag and drop operation) case MMCN.PASTE: return(Data.Node.Paste((IDataObject)Marshal.GetObjectForIUnknown((IntPtr)arg))); // The selected item needs to show something in the result pane case MMCN.SHOW: // If we're selecting this item if ((uint)arg == 1) { CNodeManager.SelectedNode = Data.Node; } Data.Node.onShow(m_ucsole, arg, param); break; // If an item is selected, we should set flags for verbs available // for the item (from the dropdown menu) case MMCN.SELECT: bool fEnablePropPages = false; // See if this is selected from the result view if (((uint)arg & 0x0000FFFF) == 0) { // See if we selected it or de-selected it if (((uint)arg & 0xFFFF0000) == 0) { Data.Node.ResultItemUnSelected(m_ucsole, Data.Data); } else { Data.Node.ResultItemSelected(m_ucsole, Data.Data); } // Let's see if this result item has a property page if (Data.Node.DoesResultHavePropertyPage(Data.Data)) { fEnablePropPages = true; } } // This item was selected in the scope view else if (Data.Node.HavePropertyPages) { fEnablePropPages = true; } IConsoleVerb icv; // Get the IConsoleVerb interface from MMC m_ucsole.QueryConsoleVerb(out icv); // See if we need to enable then property sheets item on the popup menu if (fEnablePropPages) { icv.SetVerbState(MMC_VERB.PROPERTIES, MMC_BUTTON_STATE.ENABLED, 1); } else { icv.SetVerbState(MMC_VERB.PROPERTIES, MMC_BUTTON_STATE.ENABLED, 0); } // We'll only call this onSelect method if the user selected the // scope item if (((uint)arg & 0x0000FFFF) > 0 && ((uint)arg & 0xFFFF0000) > 0) { icv.SetVerbState(MMC_VERB.PASTE, MMC_BUTTON_STATE.ENABLED, 1); Data.Node.onSelect(icv); } break; // This is to add images for the result pane case MMCN.ADD_IMAGES: // arg actually contains the IImageList interface. We need to tell // C# that it is a Object and not a integer. IImageList il = (IImageList)Marshal.GetObjectForIUnknown((IntPtr)arg); // param contains the HScopeItem. Let's get the node it represents CNode nLuckyGuy = CNodeManager.GetNodeByHScope((int)param); il.ImageListSetIcon(nLuckyGuy.IconHandle, CResourceStore.GetIconCookie(nLuckyGuy.IconHandle)); // Now add all the children images CNode nChild = null; for (int i = 0; i < nLuckyGuy.NumChildren; i++) { nChild = CNodeManager.GetNode(nLuckyGuy.Child[i]); il.ImageListSetIcon(nChild.IconHandle, CResourceStore.GetIconCookie(nChild.IconHandle)); } // Now add any images that the node might have for it's listview if (nLuckyGuy.m_oResults != null && nLuckyGuy.m_oResults is IColumnResultView) { ((IColumnResultView)nLuckyGuy.m_oResults).AddImages(ref il); } break; // The user double clicked on something case MMCN.DBLCLICK: return(Data.Node.onDoubleClick(Data.Data)); case MMCN.DELETE: return(Data.Node.onDelete(Data.Data)); default: // We don't support the Notification message we got return(HRESULT.S_FALSE); } return(HRESULT.S_OK); }// Notify
}// 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