Exemplo n.º 1
0
    public void BuildGroupsFromGroupsString(string groupsString)
    {
        if (groupsString == "NONE" || groupsString == "" || groupsString == null)
        {
            return;
        }

        string[] groupStringList = IGC_Utils.SplitString("\n", groupsString);

        //foreach group in groupstring
        for (int i = 0; i < groupStringList.Length; i++)
        {
            string[]
            group = IGC_Utils.SplitString(":", groupStringList[i]),
            groupUsers  = IGC_Utils.SplitString("~", group[2]),
            groupAdmins = IGC_Utils.SplitString("~", group[3]);

            //create group
            IGC_UserGroup newGroup = AddGroup(group[0], users[group[1]]);
            //add users
            foreach (string user in groupUsers)
            {
                newGroup.AddUser(users[user], false);
            }
            //add admins
            foreach (string admin in groupAdmins)
            {
                newGroup.AddUser(users[admin], true);
            }
        }
    }
Exemplo n.º 2
0
    private string GroupInfo()
    {
        if (argv.Length != 3)
        {
            return(malformed_error + "\n" + "usage: groups info <group_name>");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group != null)
        {
            string[] users = new string[group.users.Count];
            int      i     = 0;

            foreach (IGC_User user in group.users)
            {
                if (!group.admins.Contains(user))
                {
                    users[i++] = user.name;
                }
            }

            string[] admins = new string[group.admins.Count];
            i = 0;

            foreach (IGC_User user in group.admins)
            {
                admins[i++] = user.name;
            }

            return("ADMINS: " + string.Join(", ", admins) + "\nUSERS: " + string.Join(", ", users.Where(s => !string.IsNullOrEmpty(s)).ToArray()));
        }
        return("group " + argv[2] + " does not exist");
    }
Exemplo n.º 3
0
    private IEnumerator GetGroupsAndFileOwner()
    {
        while (true)
        {
            if (virtualSystem.userRegistry != null)
            {
                if (virtualSystem.userRegistry.ready)
                {
                    break;
                }
            }
            yield return(null);
        }

        IGC_UserRegistry ur = virtualSystem.userRegistry;

        if (fileAccessGroups != null)
        {
            int i = 0;
            foreach (string groupName in fileAccessGroups)
            {
                IGC_UserGroup group = ur.GetGroup(groupName);
                if (group != null)
                {
                    accessGroups.Add(group);
                }
                else
                {
                    fileAccessGroups[i] = "GROUP IS NULL. CHECK /groups";
                    Debug.LogWarning("group " + groupName + " assigned to IGC_File @ " + virtualSystem.transform.name + " " + path + " does not exist. it was not assigned.");
                } i++;
            }
        }

        if (fileEditGroups != null)
        {
            int i = 0;
            foreach (string groupName in fileEditGroups)
            {
                IGC_UserGroup group = ur.GetGroup(groupName);
                if (group != null)
                {
                    editGroups.Add(group);
                }
                else
                {
                    fileEditGroups[i] = "GROUP IS NULL. CHECK /groups";
                    Debug.LogWarning("group " + groupName + " assigned to IGC_File @ " + virtualSystem.transform.name + " " + path + " does not exist. it was not assigned.");
                } i++;
            }
        }
    }
Exemplo n.º 4
0
    public bool RemoveEditGroup(IGC_UserGroup group)
    {
        if (editGroups.Contains(group))
        {
            editGroups.Remove(group);

            if (virtualSystem.networkReady)
            {
                virtualSystem.GetComponent <NetworkView>().RPC("RemoveEditGroupRPC", RPCMode.Others, this.path, group.name);
            }

            return(true);
        }
        return(false);
    }
Exemplo n.º 5
0
    public IGC_UserGroup ApplyEditGroup(IGC_UserGroup group)
    {
        if (!editGroups.Contains(group))
        {
            editGroups.Add(group);

            if (virtualSystem.networkReady)
            {
                virtualSystem.GetComponent <NetworkView>().RPC("AddEditGroupRPC", RPCMode.Others, this.path, group.name);
            }

            return(group);
        }
        return(null);
    }
Exemplo n.º 6
0
    public bool RemoveGroup(IGC_UserGroup group, IGC_User user)
    {
        //add perms stuff later
        if (groups.ContainsKey(group.name))
        {
            groups.Remove(group.name);

            if (virtualSystem.networkReady)
            {
                GetComponent <NetworkView>().RPC("RemoveGroupRPC", RPCMode.Others, group.name);
            }

            return(true);
        }
        return(false);
    }
Exemplo n.º 7
0
    private string RemoveUserFromGroup()
    {
        if (argv.Length != 4)
        {
            return(malformed_error + "\n" + "usage: groups rmuser <group_name> <username>");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group == null)
        {
            return("group " + argv[2] + " does not exist");
        }

        IGC_User user = registry.GetUser(argv[3]);

        if (user == null)
        {
            return("user " + argv[3] + " does not exist");
        }

        if (!user.groups.Contains(group))
        {
            return(user.name + " is not in " + group.name);
        }

        if (!group.admins.Contains(issuer) && !issuer.isAdmin)
        {
            return("only system or group administrators can add or remove users");
        }

        if (group.RemoveUser(user, issuer))
        {
            return(user.name + " removed from group " + group.name);
        }
        else
        {
            return("insufficient privilages or user not in group.");
        }
    }
Exemplo n.º 8
0
    private string RemoveGroup()
    {
        if (argv.Length != 3)
        {
            return(malformed_error + "\n" + "usage: groups rm <group_name>");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group != null)
        {
            if (!group.admins.Contains(issuer) && !issuer.isAdmin)
            {
                return("only system or group administrators can remove groups");
            }

            registry.RemoveGroup(group, issuer);

            return("group " + argv[2] + " removed successfully");
        }
        return("group " + argv[2] + " does not exist");
    }
Exemplo n.º 9
0
    private string AddUserToGroup()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\n" + "usage: groups adduser <group_name> <username> <group admin? y|n>");
        }

        IGC_User user = registry.GetUser(argv[3]);

        if (user == null)
        {
            return("user " + argv[3] + " does not exist");
        }

        IGC_UserGroup group = registry.GetGroup(argv [2]);

        if (group == null)
        {
            return("group " + argv[2] + " does not exist");
        }

        if (user.groups.Contains(group))
        {
            return(user.name + " is already in " + group.name);
        }

        if (!group.admins.Contains(issuer) && !issuer.isAdmin)
        {
            return("only system or group administrators can add or remove users");
        }

        bool asAdmin = argv [4] == "y" ? true : false;

        group.AddUser(user, asAdmin);

        return(user.name + " added to group " + group.name + (asAdmin ? " as admin" : ""));
    }
Exemplo n.º 10
0
    private string GroupActions()
    {
        if (argv.Length != 5)
        {
            return(malformed_error + "\nusage: file -r|w <add|rm> <groupname> <filename>");
        }

        string action = argv [2];

        if (action != "add" && action != "rm")
        {
            return("action " + argv[2] + " not understood");
        }

        IGC_UserGroup group = registry.GetGroup(argv [3]);

        if (group == null)
        {
            return(argv[3] + " does not exist");
        }

        IGC_URL  url  = fs.ParseURL(argv [4], issuer.cwd);
        IGC_File file = fs.GetFile(url.fullpath);

        if (file == null)
        {
            return(url.fullpath + " does not exist");
        }

        bool writeGroup = argv [1] == "-w";

        if (fs.CanAccessFile(file, issuer))
        {
            if (action == "add")
            {
                if (writeGroup)
                {
                    if (file.ApplyEditGroup(group) != null)
                    {
                        return(group.name + " added to " + file.path);
                    }
                    else
                    {
                        return(file.path + " already belongs to " + group.name);
                    }
                }
                else
                {
                    if (file.ApplyAccesGroup(group) != null)
                    {
                        return(group.name + " added to " + file.path);
                    }
                    else
                    {
                        return(file.path + " already belongs to " + group.name);
                    }
                }
            }
            else if (action == "rm")              //redundant, but more legible
            {
                if (writeGroup)
                {
                    if (file.RemoveEditGroup(group))
                    {
                        return(group.name + " removed from " + file.path);
                    }
                    else
                    {
                        return(file.path + " does not belong to " + group.name);
                    }
                }
                else
                {
                    if (file.RemoveAccessGroup(group))
                    {
                        return(group.name + " removed from " + file.path);
                    }
                    else
                    {
                        return(file.path + " does not belong to " + group.name);
                    }
                }
            }
        }

        return("you do not have permission to alter this file");
    }