Exemple #1
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 #2
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);
        }