2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-02-05 13:32:12 +00:00

Implement basic functionality under windows

Windows support by removing pid file, daemonizing, locking,
and other features.  Goal is to have a freezeable payload.
This commit is contained in:
Jarrod Johnson 2015-07-30 17:08:52 -04:00
parent a1a61dfdbd
commit b48cd8b685
8 changed files with 66 additions and 22 deletions

View File

@ -41,7 +41,6 @@
# esc-( would interfere with normal esc use too much
# ~ I will not use for now...
import fcntl
import math
import getpass
import optparse
@ -50,9 +49,13 @@ import select
import shlex
import socket
import sys
import termios
import time
import tty
try:
import fcntl
import termios
import tty
except ImportError:
pass
exitcode = 0
consoleonly = False
@ -72,8 +75,11 @@ conserversequence = '\x05c' # ctrl-e, c
oldtcattr = None
fd = sys.stdin
if fd.isatty():
oldtcattr = termios.tcgetattr(fd.fileno())
try:
if fd.isatty():
oldtcattr = termios.tcgetattr(fd.fileno())
except NameError:
pass
netserver = None
laststate = {}

View File

@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@ -19,6 +19,7 @@ import sys
import os
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.realpath(os.path.join(path, '..', 'lib', 'python'))
print(path)
if path.startswith('/opt'):
# if installed into system path, do not muck with things
sys.path.append(path)

View File

@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

View File

@ -26,7 +26,10 @@ import Crypto.Protocol.KDF as KDF
import hashlib
import hmac
import multiprocessing
import PAM
try:
import PAM
except ImportError:
pass
import time
_pamservice = 'confluent'
@ -161,6 +164,8 @@ def check_user_passphrase(name, passphrase, element=None, tenant=False):
pammy.acct_mgmt()
del pammy
return authorize(user, element, tenant, skipuserobj=False)
except NameError:
pass
except PAM.error:
if credobj.haspam:
return None

View File

@ -39,7 +39,10 @@ import confluent.interface.console as console
import confluent.exceptions as exc
import confluent.messages as msg
import confluent.noderange as noderange
import confluent.shellmodule as shellmodule
try:
import confluent.shellmodule as shellmodule
except ImportError:
pass
import itertools
import os
import sys

View File

@ -62,13 +62,21 @@
import collections
import confluent.config.configmanager
import eventlet
import fcntl
import json
import os
import struct
import time
import traceback
try:
from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_SH
except ImportError:
flock = lambda file, flag: True
LOCK_EX = None
LOCK_UN = None
LOCK_SH = None
# on conserving filehandles:
# upon write, if file not open, open it for append
# upon write, schedule/reschedule closing filehandle in 15 seconds
@ -156,7 +164,7 @@ class Logger(object):
elif not self.isconsole:
textdate = time.strftime(
'%b %d %H:%M:%S ', time.localtime(tstamp))
fcntl.flock(self.textfile, fcntl.LOCK_EX)
flock(self.textfile, LOCK_EX)
offset = self.textfile.tell() + len(textdate)
datalen = len(data)
eventaux = entry[4]
@ -176,10 +184,10 @@ class Logger(object):
if not textrecord.endswith('\n'):
textrecord += '\n'
self.textfile.write(textrecord)
fcntl.flock(self.textfile, fcntl.LOCK_UN)
fcntl.flock(self.binfile, fcntl.LOCK_EX)
flock(self.textfile, LOCK_UN)
flock(self.binfile, LOCK_EX)
self.binfile.write(binrecord)
fcntl.flock(self.binfile, fcntl.LOCK_UN)
flock(self.binfile, LOCK_UN)
self.textfile.flush()
self.binfile.flush()
if self.closer is None:
@ -192,7 +200,7 @@ class Logger(object):
binfile = open(self.binpath, mode='r')
except IOError:
return '', 0, 0
fcntl.flock(binfile, fcntl.LOCK_SH)
flock(binfile, LOCK_SH)
binfile.seek(0, 2)
binidx = binfile.tell() - 16
currsize = 0
@ -213,15 +221,15 @@ class Logger(object):
offsets.append((offset, datalen))
if termstate is None:
termstate = eventaux
fcntl.flock(binfile, fcntl.LOCK_UN)
flock(binfile, LOCK_UN)
binfile.close()
textdata = ''
fcntl.flock(textfile, fcntl.LOCK_SH)
flock(textfile, LOCK_SH)
while offsets:
(offset, length) = offsets.pop()
textfile.seek(offset, 0)
textdata += textfile.read(length)
fcntl.flock(textfile, fcntl.LOCK_UN)
flock(textfile, LOCK_UN)
textfile.close()
if termstate is None:
termstate = 0

View File

@ -32,10 +32,18 @@ import confluent.consoleserver as consoleserver
import confluent.core as confluentcore
import confluent.httpapi as httpapi
import confluent.log as log
import confluent.sockapi as sockapi
try:
import confluent.sockapi as sockapi
except ImportError:
#On platforms without pwd, give up on the sockapi in general and be http
#only for now
pass
import eventlet
#import eventlet.backdoor as backdoor
import fcntl
try:
import fcntl
except ImportError:
pass
#import multiprocessing
import sys
import os
@ -44,6 +52,8 @@ import ConfigParser
def _daemonize():
if not 'fork' in os.__dict__:
return
thispid = os.fork()
if thispid > 0:
os.waitpid(thispid, 0)
@ -110,6 +120,8 @@ def terminate(signalname, frame):
def doexit():
if 'fcntl' not in locals():
return
pidfile = open('/var/run/confluent/pid')
pid = pidfile.read()
if pid == str(os.getpid()):
@ -125,7 +137,8 @@ def _initsecurity(config):
def run():
_checkpidfile()
if 'fcntl' in locals():
_checkpidfile()
configfile = "/etc/confluent/service.cfg"
config = ConfigParser.ConfigParser()
config.read(configfile)
@ -141,7 +154,8 @@ def run():
doexit()
raise
_daemonize()
_updatepidfile()
if 'fcntl' in locals():
_updatepidfile()
auth.init_auth()
signal.signal(signal.SIGINT, terminate)
signal.signal(signal.SIGTERM, terminate)
@ -155,8 +169,11 @@ def run():
consoleserver.start_console_sessions()
webservice = httpapi.HttpApi(http_bind_host, http_bind_port)
webservice.start()
sockservice = sockapi.SockApi(sock_bind_host, sock_bind_port)
sockservice.start()
try:
sockservice = sockapi.SockApi(sock_bind_host, sock_bind_port)
sockservice.start()
except NameError:
pass
atexit.register(doexit)
while 1:
eventlet.sleep(100)