Esempio n. 1
0
configLoggingModule(args.debug)

# use command line to initialize IPC client

ipc = InternalSocketClient(args.IPC_SERVER_URL)

queried = InitConfigWaiter(ipc).wait()
if not queried:
    error("Configuration timed out. Exit.")
    ipc.close()
    sys.exit(1)

##############################################################################

debug("Drop privilege to %s:%s" % queried["user"])
dropRoot(*queried["user"])

##############################################################################

class SocketXMPPProxyException(Exception): pass

class SocketXMPPProxy:

    def __init__(self, jid, password, peer):
        self.__jid = xmpp.protocol.JID(jid)
        self.__peer = xmpp.protocol.JID(peer)
        self.__peerJIDStripped = self.__peer.getStripped()

        self.xmpp = xmpp.Client(\
            self.__jid.getDomain(),
            debug=["always", "socket", "nodebuilder", "dispatcher"]
Esempio n. 2
0
# drop privilege to ...
parser.add_argument("--uidname", metavar="UID_NAME", type=str, required=True)
parser.add_argument("--gidname", metavar="GID_NAME", type=str, required=True)

# mode for this script to run
parser.add_argument("--mode", type=str, choices=["server", "client"], required=True)

args = parser.parse_args()

##############################################################################

configLoggingModule(args.debug)

##############################################################################

dropRoot(args.uidname, args.gidname)

##############################################################################


class Datagram2Stream:

    __buffer = ""

    def put(self, datagram):
        self.__buffer += datagram.encode("base64").strip() + "\n"

    def get(self, size=32768):
        ret = self.__buffer[:size]
        self.__buffer = self.__buffer[size:]
        return ret
Esempio n. 3
0
    except Exception,e:
        exception(e)
        error("We cannot answer an init query.")
        return False
    return True
ipc.onQuery('init', ipcOnQueryInit)

# ---------- initialize proxy processes

for proxyName in config.listProxies():
    proxyCommand = config.getProxyInitParameters(proxyName, ipc, args.debug)
    processes.new(proxyName, proxyCommand)

# ---------- drop root privileges

dropRoot(coreConfig.uid, coreConfig.gid)

##############################################################################

# register exit function, and start IO loop

reads = [ipc, tun] # for `select` function

def doExit(signum, frame):
    global reads, processes 
    info("Exit now.")
    # first close TUN devices
    for each in reads: each.close()
    # kill processes
    t = 1.0 # second(s) waiting for exit
    try:
Esempio n. 4
0
parser.add_argument(\
    "--mode",
    type=str,
    choices=["server", "client"],
    required=True
                    )

args = parser.parse_args()

##############################################################################

configLoggingModule(args.debug)

##############################################################################

dropRoot(args.uidname, args.gidname)

##############################################################################


class Datagram2Stream:

    __buffer = ""

    def put(self, datagram):
        self.__buffer += datagram.encode('base64').strip() + '\n'

    def get(self, size=32768):
        ret = self.__buffer[:size]
        self.__buffer = self.__buffer[size:]
        return ret