Exemple #1
0
        private void BuilUserToRuleMap(uint ruleId, IRule rule)
        {
            BaseRule baserule = rule as BaseRule;

            if (baserule != null)
            {
                if (myUserToRuleMap.ContainsKey(baserule.UserName))
                {
                    HashSet <uint> ruleSet = null;
                    myUserToRuleMap.TryGetValue(baserule.UserName, out ruleSet);
                    ruleSet.Add(ruleId);
                }
                else
                {
                    HashSet <uint> ruleSet = new HashSet <uint>();
                    ruleSet.Add(ruleId);
                    myUserToRuleMap.Add(baserule.UserName, ruleSet);
                }
            }
        }
Exemple #2
0
        public static bool CreateIPRule(string line, out IPRule rule)
        {
            rule = null;
            //System.Console.WriteLine(line);
            string[] fields = line.Split('|');
            if (fields.Length != RULE_FIELDS_COUNT)
            {
                return(false);
            }

            string[] ipAddressWithMask = fields[1].Split('/');
            if (ipAddressWithMask.Length != 1 && ipAddressWithMask.Length != 2)
            {
                return(false);
            }

            UInt16[] ipAddress = IPUtils.ParseIPAddress(ipAddressWithMask[0]);
            if (ipAddress == null)
            {
                return(false);
            }

            UInt16 mask = NOMASK;

            if (ipAddressWithMask.Length == 2 && !UInt16.TryParse(ipAddressWithMask[1], out mask))
            {
                return(false);
            }

            bool isAllowed = false;

            if (!BaseRule.TryParseIsAllowed(fields[2], out isAllowed))
            {
                return(false);
            }

            string username = fields[0];

            rule = new IPRule(username, ipAddress, mask, isAllowed);
            return(true);
        }
Exemple #3
0
        public static bool CreateHostnameRule(string line, out HostRule rule)
        {
            rule = null;
            //System.Console.WriteLine(line);
            string[] fields = line.Split('|');
            if (fields.Length != RULE_FIELDS_COUNT)
            {
                return(false);
            }

            bool isAllowed = false;

            if (!BaseRule.TryParseIsAllowed(fields[2], out isAllowed))
            {
                return(false);
            }

            string username = fields[0];
            string hostname = fields[1];

            rule = new HostRule(username, hostname, isAllowed);
            return(true);
        }