Ejemplo n.º 1
0
        }// PutValuesinPage

        void onBrowse(Object o, EventArgs e)
        {
            // Pop up a file dialog so the user can find an assembly
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = CResourceStore.GetString("CEvalAssemWiz1:FDTitle");
            fd.Filter = CResourceStore.GetString("CEvalAssemWiz1:FDMask");
            System.Windows.Forms.DialogResult dr = fd.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                if (Fusion.isManaged(fd.FileName))
                {
                    m_txtFilename.Text = fd.FileName;
                    onTextChange(null, null);

                    // Get a jump on the loading of this assembly
                    if (m_tEvidence != null)
                    {
                        m_tEvidence.Abort();
                    }

                    m_tEvidence = new Thread(new ThreadStart(NewAssembly));
                    m_tEvidence.Start();
                }
                else
                {
                    MessageBox(CResourceStore.GetString("isNotManagedCode"),
                               CResourceStore.GetString("isNotManagedCodeTitle"),
                               MB.ICONEXCLAMATION);
                }
            }
        }// onBrowse
Ejemplo n.º 2
0
        }// onTextChange

        void onBrowse(Object o, EventArgs e)
        {
            // Pop up a file dialog so the user can find an assembly
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = CResourceStore.GetString("CTrustAppWiz2:ChooseAssemFDTitle");
            fd.Filter = CResourceStore.GetString("AssemFDMask");
            System.Windows.Forms.DialogResult dr = fd.ShowDialog();
            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                if (Fusion.isManaged(fd.FileName))
                {
                    m_txtFilename.Text = fd.FileName;
                    // Inform our wizard that we have a new assembly for it to try and load
                    CFullTrustWizard wiz = (CFullTrustWizard)CNodeManager.GetNode(m_iCookie);
                    wiz.NewAssembly();
                }
                else
                {
                    MessageBox(CResourceStore.GetString("isNotManagedCode"),
                               CResourceStore.GetString("isNotManagedCodeTitle"),
                               MB.ICONEXCLAMATION);
                }
            }
        } // onBrowse
Ejemplo n.º 3
0
        internal CApplicationDepends(String sAppFile)
        {
            m_sGuid        = "96821C0B-CBE2-4dc9-AC52-756A3361B07F";
            m_sHelpSection = "";
            m_hIcon        = CResourceStore.GetHIcon("sharedassemblies_ico");
            DisplayName    = CResourceStore.GetString("CApplicationDepends:DisplayName");
            Name           = "Assembly Dependencies";

            m_taskPadWaiting = new CGenericTaskPad(this, "WAITINGDEPENDASSEM_HTML");
            m_taskPad        = new CGenericTaskPad(this, "DEPENDASSEM_HTML");

            m_fIKnowMyDependencies     = false;
            m_fAllowListView           = false;
            m_fAllowMultiSelectResults = true;


            m_fReadShowHTML = false;
            m_oResults      = m_taskPadWaiting;
            m_olAssems      = null;

            m_sAppFile = sAppFile;

            // Get icons for the assemblies we show
            m_hAssemIcon      = CResourceStore.GetHIcon("gac_ico");
            m_iAssemIconIndex = CResourceStore.GetIconCookie(m_hAssemIcon);


            // If we're not managed, then don't bother trying to have our dependencies
            // found
            if (!Fusion.isManaged(m_sAppFile))
            {
                m_taskPad              = new CGenericTaskPad(this, "UNMANAGEDDEPENDASSEM_HTML");
                m_oResults             = m_taskPad;
                m_fIKnowMyDependencies = true;
            }
            else
            {
                // Get ourselves in a queue to have our dependent assemblies discovered....
                if (m_alNodes == null)
                {
                    m_alNodes = ArrayList.Synchronized(new ArrayList());
                }

                m_alNodes.Add(this);

                if (m_thread == null)
                {
                    m_thread = new Thread(new ThreadStart(DependencyFinder));
                }
                if (!m_thread.IsAlive)
                {
                    m_thread.Priority = ThreadPriority.Lowest;
                    m_thread.Start();
                }
            }
        }// CApplicationDepends
        }// Paste

        private bool AddAssemToFusion(String sFilename)
        {
            if (Fusion.isManaged(sFilename))
            {
                int hr = Fusion.AddAssemblytoGac(sFilename);
                if (hr != HRESULT.S_OK)
                {
                    if (hr == HRESULT.E_ACCESSDENIED)
                    {
                        MessageBox(CResourceStore.GetString("CSharedAssemblies:AddAssemFailNoAccess"),
                                   CResourceStore.GetString("CSharedAssemblies:AddAssemFailNoAccessTitle"),
                                   MB.ICONEXCLAMATION);
                        // If this happens, they won't be able to add any items to the gac
                        return(false);
                    }
                    else
                    {
                        MessageBox(CResourceStore.GetString("CSharedAssemblies:AddAssemFail"),
                                   CResourceStore.GetString("CSharedAssemblies:AddAssemFailTitle"),
                                   MB.ICONEXCLAMATION);
                    }
                }
                // Don't bother refreshing the screen unless we added an assembly
                else
                {
                    m_olAssems = Fusion.ReadFusionCache();
                    CNodeManager.Console.SelectScopeItem(HScopeItem);
                }
            }
            else
            {
                MessageBox(CResourceStore.GetString("isNotManagedCode"),
                           CResourceStore.GetString("isNotManagedCodeTitle"),
                           MB.ICONEXCLAMATION);
            }
            return(true);
        }// AddAssemToFusion
Ejemplo n.º 5
0
        }// HaveCurrentEvidence

        internal Evidence GetEvidence()
        {
            // If we have a thread that is doing this right now, abort
            // it.
            if (m_tEvidence != null)
            {
                m_tEvidence.Abort();
            }
            try
            {
                AssemblyRef ar = m_al.LoadAssemblyInOtherAppDomainFrom(m_txtFilename.Text);
                Evidence    e  = ar.GetEvidence();
                m_al.Finished();
                m_sEvalAssem = m_txtFilename.Text;
                return(e);
            }
            catch (Exception)
            {
                // Let's see if can can figure out what failed...
                if (File.Exists(m_txtFilename.Text) && !Fusion.isManaged(m_txtFilename.Text))
                {
                    MessageBox(CResourceStore.GetString("isNotManagedCode"),
                               CResourceStore.GetString("isNotManagedCodeTitle"),
                               MB.ICONEXCLAMATION);
                }

                else
                {
                    MessageBox(String.Format(CResourceStore.GetString("CantLoadAssembly"), m_txtFilename.Text),
                               CResourceStore.GetString("CantLoadAssemblyTitle"),
                               MB.ICONEXCLAMATION);
                }
                m_al.Finished();
                return(null);
            }
        } // GetEvidence
Ejemplo n.º 6
0
        }// WizBack

        protected override int WizNext(IntPtr hwnd)
        {
            int nIndex      = GetPropPage(hwnd);
            int nReturnCode = 0;

            switch (nIndex)
            {
            // This page corresponds to the "Choose an assembly to trust" page
            case Page2Index:
                // Get our assembly to finish loading
                if (m_tAssemblyLoader != null)
                {
                    m_tAssemblyLoader.Join();
                }

                if (m_ev == null)
                {
                    // We don't have evidence yet. Let's try and get it
                    LoadAssembly();
                    // We had a problem with the load
                    if (m_ev == null)
                    {
                        // Let's see if can can figure out what failed...
                        if (File.Exists(Page2.Filename) && !Fusion.isManaged(Page2.Filename))
                        {
                            MessageBox(CResourceStore.GetString("isNotManagedCode"),
                                       CResourceStore.GetString("isNotManagedCodeTitle"),
                                       MB.ICONEXCLAMATION);
                        }

                        else
                        {
                            MessageBox(String.Format(CResourceStore.GetString("CantLoadAssembly"), Page2.Filename),
                                       CResourceStore.GetString("CantLoadAssemblyTitle"),
                                       MB.ICONEXCLAMATION);
                        }
                        nReturnCode = -1;
                        break;
                    }
                }

                X509Certificate x509 = GetCertificate();
                StrongName      sn   = GetStrongName();
                Hash            hash = GetHash();

                // Check to see if the assembly they've selected has a certificate
                if (x509 != null || sn != null)
                {
                    Page3.x509        = x509;
                    Page3.sn          = sn;
                    m_fHasCertOrSName = true;
                    break;
                }
                else
                {
                    // The assembly doesn't have a certificate or a strong name. We'll go to the
                    // page that let's them choose the permission set they want to assign
                    m_fHasCertOrSName = false;

                    // I'd like to just fall through to the next case statement, but that
                    // isn't allowed in C#. We'll need to use a goto instead
                    goto case Page3Index;
                }

            // This page corresponds to the 'how do you want to trust this assembly' when
            // the assembly has a publisher certificate
            case Page3Index:
                // Let's figure out how we can change the policy.

                // First, let's see what happens if we give this app full trust.

                // If we can't get any permissions, then this severely hampers what
                // the wizard can do. This might occur if the level of trust we can grant is
                // limited by an upper policy level. If this is the case, then we need
                // to bail
                int nLevelFromFullTrust = TryToCreateFullTrust();
                if (nLevelFromFullTrust != PermissionSetType.UNKNOWN && nLevelFromFullTrust != PermissionSetType.NONE)
                {
                    // Now, lets see if we can identify the permission set that it currently gets
                    int nCurPerm = FindCurrentPermissionSet();
                    if (nCurPerm != PermissionSetType.UNKNOWN)
                    {
                        // Go to the Slider bar page
                        Page5.MyTrustLevel  = nCurPerm;
                        Page5.MaxTrustLevel = nLevelFromFullTrust;
                        Page5.PutValuesInPage();
                        m_nPageToGetPermissionLevel = Page5Index;
                    }
                    else
                    {
                        // Go to the 'You can only assign full trust' page
                        m_nPageToGetPermissionLevel = Page4Index;
                    }
                }
                else
                {
                    // Else, we can't do anything. The app's permission level is limited by
                    // an upper policy level. Puke out now.
                    m_nPageToGetPermissionLevel = Page6Index;
                }
                // Head off to the page that will let us get a permission set to assign
                SendMessage(GetParent(hwnd), PSM.SETCURSEL, (IntPtr)m_nPageToGetPermissionLevel, (IntPtr)(-1));
                nReturnCode = -1;
                break;

            // This page is for the "You can only give this assembly full trust" page
            case Page4Index:
            // This page gives the slider and allows the user to choose the permission level
            // they want
            case Page5Index:
                // Head off to the summary page
                SendMessage(GetParent(hwnd), PSM.SETCURSEL, (IntPtr)Page7Index, (IntPtr)(-1));
                nReturnCode = -1;
                break;
            }
            int nBaseRet = base.WizNext(hwnd);

            if (nBaseRet == 0)
            {
                return(nReturnCode);
            }
            else
            {
                return(nBaseRet);
            }
        }// WizNext
Ejemplo n.º 7
0
        }// AddMenuItems

        internal override void MenuCommand(int iCommandID)
        {
            if (iCommandID == COMMANDS.ADD_APPLICATION)
            {
                // Pop up a dialog so the user can find an assembly
                CChooseAppDialog cad = new CChooseAppDialog();

                System.Windows.Forms.DialogResult dr = cad.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    String sConfigFile  = cad.Filename;
                    String sAppFilename = "";

                    // If this is an executable or Dll, or if it is managed
                    int iLen = sConfigFile.Length;
                    if (iLen > 3)
                    {
                        String sExtension = sConfigFile.Substring(sConfigFile.Length - 3).ToUpper(CultureInfo.InvariantCulture);
                        if (sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("EXE") || sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("DLL") || Fusion.isManaged(sConfigFile))
                        {
                            sAppFilename = sConfigFile;
                            // Let's add a config extension
                            sConfigFile = sConfigFile + ".config";
                        }
                        else if (iLen > 6)
                        {
                            // Check to see if they selected a config file
                            sExtension = sConfigFile.Substring(sConfigFile.Length - 6).ToUpper(CultureInfo.InvariantCulture);

                            if (sExtension.ToUpper(CultureInfo.InvariantCulture).Equals("CONFIG"))
                            {
                                // They've selected a config file. Let's see if there is an assembly around there as well.
                                String sAssemName = sConfigFile.Substring(0, sConfigFile.Length - 7);
                                if (File.Exists(sAssemName))
                                {
                                    sAppFilename = sAssemName;
                                }
                            }
                        }
                    }
                    AppFiles appFile = new AppFiles();
                    appFile.sAppFile       = sAppFilename;
                    appFile.sAppConfigFile = sConfigFile;

                    // Check to see if we already have this app file shown
                    CNode node = CheckForDuplicateApp(appFile);
                    if (node == null)
                    {
                        CConfigStore.SetSetting("AppConfigFiles", appFile);
                        node = new CApplication(appFile);
                        int iCookie = CNodeManager.AddNode(ref node);
                        AddChild(iCookie);
                        InsertSpecificChild(iCookie);
                    }
                    CNodeManager.Console.SelectScopeItem(node.HScopeItem);
                }
            }
            else if (iCommandID == COMMANDS.FIX_APPLICATION)
            {
                PolicyManager(CNodeManager.MMChWnd, null, null, null);
            }
        }// MenuCommand