summaryrefslogtreecommitdiffstats
path: root/ipa-python/config.py
blob: a17e585bc9fa20c1188ebf25e4697005d398c6e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Authors: Karl MacMillan <kmacmill@redhat.com>
#
# Copyright (C) 2007  Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 or later
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

import ConfigParser
from optparse import OptionParser

class IPAConfigError(Exception):
    def __init__(self, msg=''):
        self.msg = msg
        Exception.__init__(self, msg)

    def __repr__(self):
        return self.msg

    __str__ = __repr__

class IPAConfig:
    def __init__(self):
        self.default_realm = None
        self.default_server = None

    def get_realm(self):
        if self.default_realm:
            return self.default_realm
        else:
            raise IPAConfigError("no default realm")

    def get_server(self):
        if self.default_server:
            return self.default_server
        else:
            raise IPAConfigError("no default server")

# Global library config
config = IPAConfig()

def __parse_config():
    p = ConfigParser.SafeConfigParser()
    p.read("/etc/ipa/ipa.conf")

    try:
        config.default_realm = p.get("defaults", "realm")
        config.default_server = p.get("defaults", "server")
    except:
        pass

def usage():
    return """  --realm\tset the IPA realm
  --server\tset the IPA server
"""

def __parse_args(args):
    # Can't use option parser because it doesn't easily leave
    # unknown arguments - creating our own seems simpler.
    #
    # should make this more robust and handle --realm=foo syntax
    out_args = []
    i = 0
    while i < len(args):
        if args[i] == "--realm":
            if i == len(args) - 1:
                raise IPAConfigError("missing argument to --realm")
            config.default_realm = args[i + 1]
            i = i + 2
            continue
        if args[i] == "--server":
            if i == len(args) - 1:
                raise IPAConfigError("missing argument to --server")
            config.default_server = args[i + 1]
            i = i + 2
            continue
        out_args.append(args[i])
        i = i + 1
        
    return out_args
                      

def init_config(args=None):
    __parse_config()
    out_args = None
    if args:
        out_args = __parse_args(args)

    if not config.default_realm:
        raise IPAConfigError("realm not specified in config file or on command line")
    if not config.default_server:
        raise IPAConfigError("server not specified in config file or on command line")

    if out_args:
        return out_args
e ICMPV6_ROUTER_PREF_HIGH 0x1 #define ICMPV6_ROUTER_PREF_INVALID 0x2 #define ICMPV6_DEST_UNREACH 1 #define ICMPV6_PKT_TOOBIG 2 #define ICMPV6_TIME_EXCEED 3 #define ICMPV6_PARAMPROB 4 #define ICMPV6_INFOMSG_MASK 0x80 #define ICMPV6_ECHO_REQUEST 128 #define ICMPV6_ECHO_REPLY 129 #define ICMPV6_MGM_QUERY 130 #define ICMPV6_MGM_REPORT 131 #define ICMPV6_MGM_REDUCTION 132 #define ICMPV6_NI_QUERY 139 #define ICMPV6_NI_REPLY 140 #define ICMPV6_MLD2_REPORT 143 #define ICMPV6_DHAAD_REQUEST 144 #define ICMPV6_DHAAD_REPLY 145 #define ICMPV6_MOBILE_PREFIX_SOL 146 #define ICMPV6_MOBILE_PREFIX_ADV 147 /* * Codes for Destination Unreachable */ #define ICMPV6_NOROUTE 0 #define ICMPV6_ADM_PROHIBITED 1 #define ICMPV6_NOT_NEIGHBOUR 2 #define ICMPV6_ADDR_UNREACH 3 #define ICMPV6_PORT_UNREACH 4 /* * Codes for Time Exceeded */ #define ICMPV6_EXC_HOPLIMIT 0 #define ICMPV6_EXC_FRAGTIME 1 /* * Codes for Parameter Problem */ #define ICMPV6_HDR_FIELD 0 #define ICMPV6_UNK_NEXTHDR 1 #define ICMPV6_UNK_OPTION 2 /* * constants for (set|get)sockopt */ #define ICMPV6_FILTER 1 /* * ICMPV6 filter */ #define ICMPV6_FILTER_BLOCK 1 #define ICMPV6_FILTER_PASS 2 #define ICMPV6_FILTER_BLOCKOTHERS 3 #define ICMPV6_FILTER_PASSONLY 4 struct icmp6_filter { __u32 data[8]; }; /* * Definitions for MLDv2 */ #define MLD2_MODE_IS_INCLUDE 1 #define MLD2_MODE_IS_EXCLUDE 2 #define MLD2_CHANGE_TO_INCLUDE 3 #define MLD2_CHANGE_TO_EXCLUDE 4 #define MLD2_ALLOW_NEW_SOURCES 5 #define MLD2_BLOCK_OLD_SOURCES 6 #define MLD2_ALL_MCR_INIT { { { 0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,0x16 } } } #ifdef __KERNEL__ #include <linux/netdevice.h> #include <linux/skbuff.h> extern void icmpv6_send(struct sk_buff *skb, int type, int code, __u32 info, struct net_device *dev); extern int icmpv6_init(void); extern int icmpv6_err_convert(int type, int code, int *err); extern void icmpv6_cleanup(void); extern void icmpv6_param_prob(struct sk_buff *skb, int code, int pos); struct flowi; struct in6_addr; extern void icmpv6_flow_init(struct sock *sk, struct flowi *fl, u8 type, const struct in6_addr *saddr, const struct in6_addr *daddr, int oif); #endif #endif