예제 #1
0
        }// CreateDataTable

        protected override void PutValuesinPage()
        {
            // Put in the text for the radio buttons
            m_radUnrestricted.Text             = CResourceStore.GetString("EnvironmentPerm:GrantUnrestrict");
            m_radGrantFollowingPermission.Text = CResourceStore.GetString("EnvironmentPerm:GrantFollowing");

            EnvironmentPermission perm = (EnvironmentPermission)m_perm;

            CheckUnrestricted(perm);

            if (!perm.IsUnrestricted())
            {
                StringCollection scReadVars  = new StringCollection();
                StringCollection scWriteVars = new StringCollection();
                StringCollection scAllVars   = new StringCollection();

                // Get the environment variables the user has access to
                String sReads = perm.GetPathList(EnvironmentPermissionAccess.Read);
                if (sReads != null && sReads.Length > 0)
                {
                    scReadVars.AddRange(sReads.Split(new char[] { ';' }));
                }

                String sWrites = perm.GetPathList(EnvironmentPermissionAccess.Write);
                if (sWrites != null && sWrites.Length > 0)
                {
                    scWriteVars.AddRange(sWrites.Split(new char[] { ';' }));
                }

                // Intersect these to find those variables that can be both read and written
                scAllVars = PathListFunctions.IntersectCollections(ref scReadVars, ref scWriteVars);

                StringCollection[] scCollections = new StringCollection[] { scReadVars, scWriteVars, scAllVars };

                // Ok, let's add these items to our grid
                for (int i = 0; i < scCollections.Length; i++)
                {
                    for (int j = 0; j < scCollections[i].Count; j++)
                    {
                        DataRow newRow = m_dt.NewRow();
                        newRow["Variable"] = scCollections[i][j];
                        newRow["Read"]     = (i == 0 || i == 2);
                        newRow["Write"]    = (i == 1 || i == 2);
                        m_dt.Rows.Add(newRow);
                    }
                }
            }

            // We want at least 1 rows so it looks pretty
            while (m_dt.Rows.Count < 1)
            {
                AddEmptyRow(m_dt);
            }
        }// PutValuesinPage
예제 #2
0
        }// ValidateData

        internal override IPermission GetCurrentPermission()
        {
            // Change cells so we get data committed to the grid
            m_dg.CurrentCell = new DataGridCell(0, 1);
            m_dg.CurrentCell = new DataGridCell(0, 0);

            RegistryPermission perm = null;

            if (m_radUnrestricted.Checked == true)
            {
                perm = new RegistryPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new RegistryPermission(PermissionState.None);
                StringCollection scRead   = new StringCollection();
                StringCollection scWrite  = new StringCollection();
                StringCollection scCreate = new StringCollection();
                for (int i = 0; i < m_dt.Rows.Count; i++)
                {
                    // Make sure we have a registry permission to add
                    if (m_dg[i, 0] is String && ((String)m_dg[i, 0]).Length > 0)
                    {
                        // Does this path have read permissions
                        if ((bool)m_dg[i, 1])
                        {
                            scRead.Add((String)m_dg[i, 0]);
                        }
                        // Does this path have write permissions
                        if ((bool)m_dg[i, 2])
                        {
                            scWrite.Add((String)m_dg[i, 0]);
                        }
                        // Does this have append permissions
                        if ((bool)m_dg[i, 3])
                        {
                            scCreate.Add((String)m_dg[i, 0]);
                        }
                    }
                    else
                    {
                        // Make sure they didn't check any boxes and not include
                        // an empty path
                        bool fCheckedBox = false;
                        for (int j = 1; j <= 3 && !fCheckedBox; j++)
                        {
                            fCheckedBox = (bool)m_dg[i, j];
                        }

                        if (fCheckedBox)
                        {
                            MessageBox(CResourceStore.GetString("RegPerm:NeedRegName"),
                                       CResourceStore.GetString("RegPerm:NeedRegNameTitle"),
                                       MB.ICONEXCLAMATION);
                            return(null);
                        }
                    }
                }
                String sAdd = PathListFunctions.JoinStringCollection(scRead);
                if (sAdd.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Read, sAdd);
                }

                String sWrite = PathListFunctions.JoinStringCollection(scWrite);
                if (sWrite.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Write, sWrite);
                }

                String sCreate = PathListFunctions.JoinStringCollection(scCreate);
                if (sCreate.Length > 0)
                {
                    perm.AddPathList(RegistryPermissionAccess.Create, sCreate);
                }
            }
            return(perm);
        }// GetCurrentPermission
예제 #3
0
        protected override void PutValuesinPage()
        {
            // Put in the text for the radio buttons
            m_radUnrestricted.Text             = CResourceStore.GetString("RegPerm:GrantUnrestrict");
            m_radGrantFollowingPermission.Text = CResourceStore.GetString("RegPerm:GrantFollowing");

            RegistryPermission perm = (RegistryPermission)m_perm;

            CheckUnrestricted(perm);

            if (!perm.IsUnrestricted())
            {
                StringCollection scReadKeys   = new StringCollection();
                StringCollection scWriteKeys  = new StringCollection();
                StringCollection scCreateKeys = new StringCollection();
                StringCollection scRWKeys     = new StringCollection();
                StringCollection scRCKeys     = new StringCollection();
                StringCollection scWCKeys     = new StringCollection();
                StringCollection scRWCKeys    = new StringCollection();

                // Get the paths the user has access to
                if (perm.GetPathList(RegistryPermissionAccess.Read) != null)
                {
                    scReadKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Read).Split(new char[] { ';' }));
                }
                if (perm.GetPathList(RegistryPermissionAccess.Write) != null)
                {
                    scWriteKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Write).Split(new char[] { ';' }));
                }
                if (perm.GetPathList(RegistryPermissionAccess.Create) != null)
                {
                    scCreateKeys.AddRange(perm.GetPathList(RegistryPermissionAccess.Create).Split(new char[] { ';' }));
                }

                // Careful with the order of these calls... make sure the final IntersectAllCollections
                // is the last function to get called. Also, make sure each of the base
                // string collections (Read, Write, and Append) all are the 1st argument in the
                // IntersectCollections call at least once, to clean up any "" that might be floating around
                scRWKeys  = PathListFunctions.CondIntersectCollections(ref scReadKeys, ref scWriteKeys, ref scCreateKeys);
                scRCKeys  = PathListFunctions.CondIntersectCollections(ref scCreateKeys, ref scReadKeys, ref scWriteKeys);
                scWCKeys  = PathListFunctions.CondIntersectCollections(ref scWriteKeys, ref scCreateKeys, ref scReadKeys);
                scRWCKeys = PathListFunctions.IntersectAllCollections(ref scReadKeys, ref scWriteKeys, ref scCreateKeys);

                // Now we have 7 different combinations we have to run through
                String[] sFilePaths = new String[] {
                    PathListFunctions.JoinStringCollection(scReadKeys),
                    PathListFunctions.JoinStringCollection(scWriteKeys),
                    PathListFunctions.JoinStringCollection(scCreateKeys),
                    PathListFunctions.JoinStringCollection(scRWKeys),
                    PathListFunctions.JoinStringCollection(scRCKeys),
                    PathListFunctions.JoinStringCollection(scWCKeys),
                    PathListFunctions.JoinStringCollection(scRWCKeys)
                };

                RegistryPermissionAccess[] fipa = new RegistryPermissionAccess[] {
                    RegistryPermissionAccess.Read,
                    RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Create,
                    RegistryPermissionAccess.Read | RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Create | RegistryPermissionAccess.Read,
                    RegistryPermissionAccess.Create | RegistryPermissionAccess.Write,
                    RegistryPermissionAccess.Read | RegistryPermissionAccess.Write | RegistryPermissionAccess.Create
                };

                for (int i = 0; i < 7; i++)
                {
                    DataRow newRow;
                    // See if we have some info for this one
                    if (sFilePaths[i].Length > 0)
                    {
                        newRow           = m_dt.NewRow();
                        newRow["Key"]    = sFilePaths[i];
                        newRow["Read"]   = (fipa[i] & RegistryPermissionAccess.Read) > 0;
                        newRow["Write"]  = (fipa[i] & RegistryPermissionAccess.Write) > 0;
                        newRow["Create"] = (fipa[i] & RegistryPermissionAccess.Create) > 0;
                        m_dt.Rows.Add(newRow);
                    }
                }
            }

            // We want at least 1 rows so it looks pretty
            while (m_dt.Rows.Count < 1)
            {
                AddEmptyRow(m_dt);
            }
        }// PutValuesinPage