Exemple #1
0
        public string[] GetRightsSubset(CallerInfo caller, InvokerData invoker, TeamspeakControl ts, params string[] requestedRights)
        {
            var ctx = GetRightsContext(caller, invoker, ts);
            var normalizedRequest = ExpandRights(requestedRights);

            return(ctx.DeclAdd.Intersect(normalizedRequest).ToArray());
        }
Exemple #2
0
        // TODO: b_client_permissionoverview_view
        public bool HasAllRights(CallerInfo caller, InvokerData invoker, TeamspeakControl ts, params string[] requestedRights)
        {
            var ctx = GetRightsContext(caller, invoker, ts);
            var normalizedRequest = ExpandRights(requestedRights);

            return(ctx.DeclAdd.IsSupersetOf(normalizedRequest));
        }
Exemple #3
0
        private ExecuteContext GetRightsContext(CallerInfo caller, InvokerData invoker, TeamspeakControl ts)
        {
            if (needsRecalculation)
            {
                cachedRights.Invalidate();
                needsRecalculation = false;
                ReadFile();
            }

            ExecuteContext execCtx;

            if (invoker != null)
            {
                if (cachedRights.TryGetValue(invoker.ClientUid, out execCtx))
                {
                    // TODO check if all fields are same
                    // if yes => returen
                    // if no => delete from cache
                    return(execCtx);
                }

                execCtx = new ExecuteContext();

                // Get Required Matcher Data:
                // In this region we will iteratively go through different possibilities to obtain
                // as much data as we can about our invoker.
                // For this step we will prefer query calls which can give us more than one information
                // at once and lazily fall back to other calls as long as needed.

                ulong[] availableGroups = null;
                if (ts != null)
                {
                    if (invoker.ClientId.HasValue &&
                        (needsAvailableGroups || needsAvailableChanGroups))
                    {
                        var result = ts.GetClientInfoById(invoker.ClientId.Value);
                        if (result.Ok)
                        {
                            availableGroups        = result.Value.ServerGroups;
                            execCtx.ChannelGroupId = result.Value.ChannelGroupId;
                        }
                    }

                    if (needsAvailableGroups && invoker.DatabaseId.HasValue && availableGroups == null)
                    {
                        var result = ts.GetClientServerGroups(invoker.DatabaseId.Value);
                        if (result.Ok)
                        {
                            availableGroups = result.Value;
                        }
                    }
                }

                if (availableGroups != null)
                {
                    execCtx.AvailableGroups = availableGroups;
                }
                execCtx.ClientUid = invoker.ClientUid;
                execCtx.Visibiliy = invoker.Visibiliy;
                execCtx.ApiToken  = invoker.Token;
            }
            else
            {
                execCtx = new ExecuteContext();
            }
            execCtx.IsApi = caller.ApiCall;

            ProcessNode(rootRule, execCtx);

            if (execCtx.MatchingRules.Count == 0)
            {
                return(execCtx);
            }

            foreach (var rule in execCtx.MatchingRules)
            {
                execCtx.DeclAdd.UnionWith(rule.DeclAdd);
            }

            if (invoker != null)
            {
                cachedRights.Store(invoker.ClientUid, execCtx);
            }

            return(execCtx);
        }