summaryrefslogtreecommitdiff
path: root/src/leap/eip/config.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-08-08 07:22:36 +0900
committerkali <kali@leap.se>2012-08-08 07:22:36 +0900
commitc217bd1f1456cf10ceabf698ea6f4dd8f636f454 (patch)
tree84bb8244c99c56b2c02e0c53162956dad8c46498 /src/leap/eip/config.py
parente81ddf7648e1075a15d8add11cd975a73aa09926 (diff)
check for validity of the remote_ip entry (is ip?)
Diffstat (limited to 'src/leap/eip/config.py')
-rw-r--r--src/leap/eip/config.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py
index 91c3953b..6118c9de 100644
--- a/src/leap/eip/config.py
+++ b/src/leap/eip/config.py
@@ -3,6 +3,7 @@ import grp
import logging
import os
import platform
+import socket
from leap.util.fileutil import (which, mkdir_p,
check_and_fix_urw_only)
@@ -24,6 +25,14 @@ class EIPNoPolkitAuthAgentAvailable(Exception):
pass
+class EIPInitNoProviderError(Exception):
+ pass
+
+
+class EIPInitBadProviderError(Exception):
+ pass
+
+
class EIPInitNoKeyFileError(Exception):
pass
@@ -90,6 +99,14 @@ def get_default_provider_path():
return default_provider_path
+def validate_ip(ip_str):
+ """
+ raises exception if the ip_str is
+ not a valid representation of an ip
+ """
+ socket.inet_aton(ip_str)
+
+
def check_or_create_default_vpnconf(config):
"""
checks that a vpn config file
@@ -118,10 +135,18 @@ def check_or_create_default_vpnconf(config):
# by now. Get it from a list of gateways
# instead.
- remote_ip = config.get('provider',
- 'remote_ip')
+ try:
+ remote_ip = config.get('provider',
+ 'remote_ip')
+ validate_ip(remote_ip)
+
+ except ConfigParser.NoOptionError:
+ raise EIPInitNoProviderError
+
+ except socket.error:
+ # this does not look like an ip, dave
+ raise EIPInitBadProviderError
- # XXX check that IT LOOKS LIKE AN IP!!!
if config.has_option('provider', 'remote_port'):
remote_port = config.get('provider',
'remote_port')