示例#1
0
        //test complete
        public void IsUsersGroupSane(PwDatabase db, int expectedUsers)
        {
            PwGroup usersGroup = m_database.GetUsersGroup();

            //anzahl angelegter nutzer sollte mit der anzahl der homeverz und proxies überienstimmen
            Assert.AreEqual(expectedUsers, usersGroup.Entries.UCount);
            Assert.AreEqual(expectedUsers, usersGroup.Groups.UCount);

            PwObjectList <PwGroup> usersHomes = usersGroup.GetGroups(false);

            foreach (PwGroup home in usersHomes)
            {
                PwObjectList <PwEntry> entryList = home.GetEntries(false);
                int     rootCounter = 0;
                PwEntry rootNode    = null;

                foreach (PwEntry entry in entryList)
                {
                    if (entry.IsUserRootNode())
                    {
                        rootCounter++;
                        rootNode = entry;
                    }
                }
                //jedes homeverz muss genau einen rootKnoten halten
                Assert.AreEqual(1, rootCounter);
                //name des rootNodes und des homeverz müssen übereinstimmen
                string homeName = home.Name;
                Assert.IsFalse(null == rootNode);
                string userName = rootNode.Strings.ReadSafe(KeeShare.KeeShare.TitleField);
                Assert.AreEqual(homeName, userName);
            }
        }
        public static string CreateSummaryList(PwGroup pgSubGroups, PwEntry[] vEntries)
        {
            int    nMaxEntries = 10;
            string strSummary  = string.Empty;

            if (pgSubGroups != null)
            {
                PwObjectList <PwGroup> vGroups = pgSubGroups.GetGroups(true);
                if (vGroups.UCount > 0)
                {
                    StringBuilder sbGroups = new StringBuilder();
                    sbGroups.Append("- ");
                    uint uToList = Math.Min(3U, vGroups.UCount);
                    for (uint u = 0; u < uToList; ++u)
                    {
                        if (sbGroups.Length > 2)
                        {
                            sbGroups.Append(", ");
                        }
                        sbGroups.Append(vGroups.GetAt(u).Name);
                    }
                    if (uToList < vGroups.UCount)
                    {
                        sbGroups.Append(", ...");
                    }
                    strSummary += sbGroups.ToString();                     // New line below

                    nMaxEntries -= 2;
                }
            }

            int nSummaryShow = Math.Min(nMaxEntries, vEntries.Length);

            if (nSummaryShow == (vEntries.Length - 1))
            {
                --nSummaryShow;                                                   // Plural msg
            }
            for (int iSumEnum = 0; iSumEnum < nSummaryShow; ++iSumEnum)
            {
                if (strSummary.Length > 0)
                {
                    strSummary += MessageService.NewLine;
                }

                PwEntry pe = vEntries[iSumEnum];
                strSummary += ("- " + StrUtil.CompactString3Dots(
                                   pe.Strings.ReadSafe(PwDefs.TitleField), 39));
                if (PwDefs.IsTanEntry(pe))
                {
                    string strTanIdx = pe.Strings.ReadSafe(PwDefs.UserNameField);
                    if (!string.IsNullOrEmpty(strTanIdx))
                    {
                        strSummary += (@" (#" + strTanIdx + @")");
                    }
                }
            }

            return(strSummary);
        }
示例#3
0
 /// <summary>
 /// Recursively adds a group and all its child groups to the combo
 /// </summary>
 private void AddGroupToCombo(PwGroup group, int indentLevel)
 {
     mTargetGroup.Items.Add(new GroupComboItem(mHost, indentLevel, group));
     foreach (var child in group.GetGroups(false))
     {
         AddGroupToCombo(child, indentLevel + 1);
     }
 }
 private void add_sub_groups(PwGroup group, int level, string cur_item_uuid)
 {
     PwObjectList<PwGroup> groups = group.GetGroups(false);
     foreach (PwGroup sub_group in groups)
     {
         StartGroupDropdown item = new StartGroupDropdown(sub_group.Uuid.ToHexString(), sub_group.Name, level + 1);
         if (sub_group.Uuid.ToHexString() == cur_item_uuid)
             drop_cur_item = item;
         drop_items.Add(item);
         add_sub_groups(sub_group, level + 1, cur_item_uuid);
     }
 }
示例#5
0
        private void add_sub_groups(PwGroup group, int level, string cur_item_uuid)
        {
            PwObjectList <PwGroup> groups = group.GetGroups(false);

            foreach (PwGroup sub_group in groups)
            {
                StartGroupDropdown item = new StartGroupDropdown(sub_group.Uuid.ToHexString(), sub_group.Name, level + 1);
                if (sub_group.Uuid.ToHexString() == cur_item_uuid)
                {
                    drop_cur_item = item;
                }
                drop_items.Add(item);
                add_sub_groups(sub_group, level + 1, cur_item_uuid);
            }
        }
示例#6
0
        private JArray GetGroupChildren(PwGroup group)
        {
            var groups = new JArray();

            foreach (var grp in group.GetGroups(false))
            {
                groups.Add(new JObject
                {
                    { "name", grp.Name },
                    { "uuid", grp.Uuid.ToHexString() },
                    { "children", GetGroupChildren(grp) }
                });
            }

            return(groups);
        }
示例#7
0
        internal static void Expire(this PwGroup pg, bool bExpireAll)
        {
            PwObjectList <PwEntry> entries = pg.GetEntries(false);

            foreach (PwEntry pe in entries)
            {
                pe.Expire(bExpireAll);
            }

            PwObjectList <PwGroup> groups = pg.GetGroups(false);

            foreach (PwGroup g in groups)
            {
                g.Expire(bExpireAll);
            }
        }
示例#8
0
        public static string CreateSummaryList(PwGroup pgSubGroups, PwEntry[] vEntries)
        {
            int nMaxEntries = 10;
            string strSummary = string.Empty;

            if(pgSubGroups != null)
            {
                PwObjectList<PwGroup> vGroups = pgSubGroups.GetGroups(true);
                if(vGroups.UCount > 0)
                {
                    StringBuilder sbGroups = new StringBuilder();
                    sbGroups.Append("- ");
                    uint uToList = Math.Min(3U, vGroups.UCount);
                    for(uint u = 0; u < uToList; ++u)
                    {
                        if(sbGroups.Length > 2) sbGroups.Append(", ");
                        sbGroups.Append(vGroups.GetAt(u).Name);
                    }
                    if(uToList < vGroups.UCount) sbGroups.Append(", ...");
                    strSummary += sbGroups.ToString(); // New line below

                    nMaxEntries -= 2;
                }
            }

            int nSummaryShow = Math.Min(nMaxEntries, vEntries.Length);
            if(nSummaryShow == (vEntries.Length - 1)) --nSummaryShow; // Plural msg

            for(int iSumEnum = 0; iSumEnum < nSummaryShow; ++iSumEnum)
            {
                if(strSummary.Length > 0) strSummary += MessageService.NewLine;

                PwEntry pe = vEntries[iSumEnum];
                strSummary += ("- " + StrUtil.CompactString3Dots(
                    pe.Strings.ReadSafe(PwDefs.TitleField), 39));
                if(PwDefs.IsTanEntry(pe))
                {
                    string strTanIdx = pe.Strings.ReadSafe(PwDefs.UserNameField);
                    if(!string.IsNullOrEmpty(strTanIdx))
                        strSummary += (@" (#" + strTanIdx + @")");
                }
            }

            return strSummary;
        }
示例#9
0
        internal static void RecalcExpiry(this PwGroup pg)
        {
            PwObjectList <PwEntry> entries = pg.GetEntries(false);

            foreach (PwEntry pe in entries)
            {
                if (pe.GetPEDValue(false).Inherit)
                {
                    pe.RecalcExpiry(true);
                }
            }

            PwObjectList <PwGroup> groups = pg.GetGroups(false);

            foreach (PwGroup g in groups)
            {
                if (g.GetPEDValue(false).Inherit)
                {
                    RecalcExpiry(g);
                }
            }
        }
示例#10
0
        /// <summary>
        /// a fuction which returns a list of all folder which are shared to a specified user
        /// </summary>
        /// <param name="userRoot">The rootNode of the user you want to export you data to.</param>
        /// <returns>A <c>PwObjectList<PwGroup></c> which contains all PwGroups which are shared to
        /// the given user.</returns>
        public PwObjectList <PwGroup> GetSharedFolders(PwDatabase database, PwEntry userRoot)
        {
            PwObjectList <PwGroup> sharedFolders = new PwObjectList <PwGroup>();

            foreach (PwEntry proxy in database.GetAllProxyNodes())
            {
                if (userRoot.Uuid.ToHexString() == proxy.Strings.ReadSafe(KeeShare.UuidLinkField))
                {
                    PwGroup group = proxy.ParentGroup;
                    //we don't want to share the "Users"-folder, so if we find it, we skip it!
                    if (group == database.GetUsersGroup())
                    {
                        continue;
                    }
                    sharedFolders.Add(group);
                    //include all subfolders
                    sharedFolders.Add(group.GetGroups(true));
                }
            }
            //find the homeFolder and add it to the sharedList
            sharedFolders.Add(database.GetUserHomeFor(userRoot));
            return(sharedFolders);
        }
示例#11
0
        /// <summary>
        /// The <c>GetUsersHome</c> function looks for the home folder of a user.
        /// If it doesn't exist, a new one will be created.
        /// The createIfNotFound parameter is optional.
        /// </summary>
        /// <param name="userRoot">UserRootNode which we want to find the home folder of.</param>
        /// <param name="createIfNotFound">If not set the default value is true. That
        /// means that a home will be created if not found!</param>
        /// <returns>PwGroup homefolder of a user</returns>
        public static PwGroup GetUserHomeFor(this PwDatabase database, PwEntry userRoot, bool createIfNotFound = true)
        {
            Debug.Assert(database != null);
            PwGroup usersGroup = GetUsersGroup(database);
            PwObjectList <PwGroup> usersHomes = usersGroup.GetGroups(false);

            foreach (PwGroup pg in usersHomes)
            {
                if (pg.Notes.Contains(userRoot.Uuid.ToHexString()))
                {
                    return(pg);
                }
            }
            //if home was not found then create it
            if (createIfNotFound)
            {
                string  name         = userRoot.Strings.ReadSafe("Title");
                PwGroup newUserGroup = new PwGroup(true, true, name, PwIcon.UserKey);
                newUserGroup.Notes += userRoot.Uuid.ToHexString();
                newUserGroup.SetParent(usersGroup);
                return(newUserGroup);
            }
            return(null);
        }
示例#12
0
        /// <summary>
        /// The function creates a new PwGroup that represents an export path.
        /// All userProxies that will be placed in that group means taht this
        /// user will use this export path too.
        /// </summary>
        /// <param name="folderName">The path to the folder in your filesystem that should be used
        /// as export destination.</param>
        /// <returns><c>ChangeFlags.CommonChange</c> if the function has made any changes to the
        /// actual database structure (means if we added the expPath). 0 if the expPath allready exists
        /// and we don't have to make any changes anymore.</returns>
        public Changes AddExportPath(string folderName)
        {
            //is it a valid path?
            if (!Directory.Exists(folderName))
            {
                return(Changes.None);
            }
            //check if allready exists
            PwGroup exportGroup = m_database.GetExportGroup();

            foreach (PwGroup exp in exportGroup.GetGroups(false))
            {
                if (exp.Name == folderName)
                {
                    return(Changes.None);
                }
            }

            //create new export path
            PwGroup newExport = new PwGroup(true, true, folderName, PwIcon.NetworkServer);

            newExport.SetParent(exportGroup);
            return(Changes.GroupCreated);
        }
示例#13
0
        private Changes FixHomeFolders()
        {
            //====================================
            //maybe we have some emptyFolders => new homefolders!
            //we can use the same loop to test for illegal shares of
            //foreign homes. that means, a foreign proxy is located
            //in a users homefolder.
            PwGroup usersGroup = m_database.GetUsersGroup();
            PwObjectList <PwGroup> allHomes     = usersGroup.GetGroups(false);
            PwObjectList <PwGroup> foreignHomes = new PwObjectList <PwGroup>();
            PwObjectList <PwGroup> emptyHomes   = new PwObjectList <PwGroup>();

            foreach (PwGroup home in allHomes)
            {
                //we remember the empty folders, so we can later make them new users
                if (home.Entries.UCount == 0)
                {
                    emptyHomes.Add(home);
                }
                //if we have more than 1 entry in a homegroup we have to check for
                //possible foreign shares
                if (home.Entries.UCount > 1)
                {
                    List <PwEntry> entries = home.GetEntries(false).CloneShallowToList();
                    foreach (PwEntry entry in entries)
                    {
                        //is it a userPorxy or a pwdProxy?
                        //the first we have to remove but the second one
                        //is a note that we want to share a pwd with this user,
                        //so we don't touch it!
                        if (m_database.IsUserProxy(entry))
                        {
                            entry.DeleteFrom(home, m_database);
                        }
                    }
                }
                //and maybe we have a foreign home in our homefolder (to share it..)
                //so we have to fix that too.
                foreach (PwGroup foreignHome in home.GetGroups(true))
                {
                    if (foreignHome.IsHome())
                    {
                        foreignHomes.Add(foreignHome);
                    }
                }
            }
            Changes changeFlag = Changes.None;

            foreach (PwGroup home in emptyHomes)
            {
                string userName = home.Name;

                try {
                    changeFlag |= CreateNewUser(userName, home);
                }
                catch (Exception) {
                    // WTF: Why?
                    //should throw the exception and later inform the user...
                }
            }
            foreach (PwGroup home in foreignHomes)
            {
                home.MoveToParent(m_database.GetUsersGroup());
                changeFlag |= Changes.GroupMoved;
            }
            return(changeFlag);
        }