Esempio n. 1
0
def main():
    # fetch alternate socket path from command line
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', '-d', action='store_true',
                        help="Enable debug logging")
    parser.add_argument('--socket', required=True,
                        help='alternative SSH agent socket')

    args, extra_args = parser.parse_known_args()

    if extra_args and extra_args[0] == '--':
        extra_args = extra_args[1:]

    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    setup_logging("sshagentmux", level)

    LOG.info("Starting sshagentmux")

    # use specified socket if SSH_AUTH_SOCK is not present in environment
    sock_path = args.socket

    if 'SSH_AUTH_SOCK' in os.environ and not same_socket(
            os.environ['SSH_AUTH_SOCK'], args.socket):
        upstream_socket = os.environ['SSH_AUTH_SOCK']

        # Save original parent pid so we can detect when it exits
        parent_pid = os.getppid()
        if extra_args:
            parent_pid = os.getpid()

        # Start proxy process and wait for it to creating auth socket
        # Using a pipe for compatibility with OpenBSD
        ready_pipein, ready_pipeout = multiprocessing.Pipe()
        daemonize(target=start_agent_mux,
                  stderr=os.path.expanduser('~/.sshagentmux.log'),
                  args=(ready_pipeout, parent_pid, upstream_socket,
                        args.socket))

        # Wait for server to setup listening socket
        sock_path = ready_pipein.recv()
        ready_pipein.close()
        ready_pipeout.close()

        if not os.path.exists(sock_path):
            print >>sys.stderr, 'Agent Multiplexer failed to ' \
                'create auth socket'
            sys.exit(1)

    # Behave like ssh-agent(1)
    if extra_args:
        # start command if specified in extra_args
        os.environ['SSH_AUTH_SOCK'] = sock_path
        os.execvp(extra_args[0], extra_args)
    else:
        # print how to setup environment (same behavior as ssh-agent)
        print 'SSH_AUTH_SOCK={:s}; export SSH_AUTH_SOCK;'.format(sock_path)
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug',
                        '-d',
                        action='store_true',
                        help="Enable debug logging")
    parser.add_argument('--database',
                        help='Authorization database',
                        default=os.path.expanduser('~/authorization_proxy.db'))
    parser.add_argument(
        '--pidfile',
        help='PID file',
        default=os.path.expanduser('~/authorization_proxy.pid'))
    parser.add_argument(
        '--socket',
        help='SSH Authentication Socket path',
        default=os.path.expanduser('~/authorization_proxy.sock'))
    parser.add_argument('--logfile', help='Log file', default='/dev/null')
    parser.add_argument('action')

    args = parser.parse_args()

    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    setup_logging("authorization_proxy", level)

    if args.action == 'start':
        daemonize(target=authorization_proxy,
                  pidfile=args.pidfile,
                  stderr=args.logfile,
                  stdout=args.logfile,
                  args=(args, ))
    elif args.action == 'stop':
        if os.path.exists(args.pidfile):
            with open(args.pidfile) as f:
                os.kill(int(f.read()), signal.SIGTERM)
        else:
            print >> sys.stderr, 'Not running'
            raise SystemExit(1)
    elif args.action == 'debug':
        authorization_proxy(args)
    else:
        print >> sys.stderr, 'Unknown command {!r}'.format(sys.argv[1])
        raise SystemExit(1)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', '-d', action='store_true',
                        help="Enable debug logging")
    parser.add_argument('--database', help='Authorization database',
                        default=os.path.expanduser('~/authorization_proxy.db'))
    parser.add_argument('--pidfile', help='PID file',
                        default=os.path.expanduser(
                            '~/authorization_proxy.pid'))
    parser.add_argument('--socket', help='SSH Authentication Socket path',
                        default=os.path.expanduser(
                            '~/authorization_proxy.sock'))
    parser.add_argument('--logfile', help='Log file', default='/dev/null')
    parser.add_argument('action')

    args = parser.parse_args()

    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    setup_logging("authorization_proxy", level)

    if args.action == 'start':
        daemonize(target=authorization_proxy, pidfile=args.pidfile,
                  stderr=args.logfile, stdout=args.logfile,
                  args=(args,))
    elif args.action == 'stop':
        if os.path.exists(args.pidfile):
            with open(args.pidfile) as f:
                os.kill(int(f.read()), signal.SIGTERM)
        else:
            print >>sys.stderr, 'Not running'
            raise SystemExit(1)
    elif args.action == 'debug':
        authorization_proxy(args)
    else:
        print >>sys.stderr, 'Unknown command {!r}'.format(sys.argv[1])
        raise SystemExit(1)
Esempio n. 4
0
def main():
    # fetch alternate socket path from command line
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug',
                        '-d',
                        action='store_true',
                        help="Enable debug logging")
    parser.add_argument('--socket',
                        required=True,
                        help='alternative SSH agent socket')

    args, extra_args = parser.parse_known_args()

    if extra_args and extra_args[0] == '--':
        extra_args = extra_args[1:]

    level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    setup_logging("sshagentmux", level)

    LOG.info("Starting sshagentmux")

    # use specified socket if SSH_AUTH_SOCK is not present in environment
    sock_path = args.socket

    if 'SSH_AUTH_SOCK' in os.environ and not same_socket(
            os.environ['SSH_AUTH_SOCK'], args.socket):
        upstream_socket = os.environ['SSH_AUTH_SOCK']

        # Save original parent pid so we can detect when it exits
        parent_pid = os.getppid()
        if extra_args:
            parent_pid = os.getpid()

        # Start proxy process and wait for it to creating auth socket
        # Using a pipe for compatibility with OpenBSD
        ready_pipein, ready_pipeout = multiprocessing.Pipe()
        daemonize(target=start_agent_mux,
                  stderr=os.path.expanduser('~/.sshagentmux.log'),
                  args=(ready_pipeout, parent_pid, upstream_socket,
                        args.socket))

        # Wait for server to setup listening socket
        sock_path = ready_pipein.recv()
        ready_pipein.close()
        ready_pipeout.close()

        if not os.path.exists(sock_path):
            print >>sys.stderr, 'Agent Multiplexer failed to ' \
                'create auth socket'
            sys.exit(1)

    # Behave like ssh-agent(1)
    if extra_args:
        # start command if specified in extra_args
        os.environ['SSH_AUTH_SOCK'] = sock_path
        os.execvp(extra_args[0], extra_args)
    else:
        # print how to setup environment (same behavior as ssh-agent)
        print 'SSH_AUTH_SOCK={:s}; export SSH_AUTH_SOCK;'.format(sock_path)