Esempio n. 1
0
    def test_usernames(self):
        """
        CompleteUsernames produces zsh shell-code that completes system
        usernames.
        """
        c = usage.CompleteUsernames()
        out = c._shellCode('some-option', usage._ZSH)
        self.assertEqual(out, ':some-option:_users')

        c = usage.CompleteUsernames(descr='some action', repeat=True)
        out = c._shellCode('some-option', usage._ZSH)
        self.assertEqual(out, '*:some action:_users')
Esempio n. 2
0
File: manhole.py Progetto: DT021/wau
class Options(usage.Options):
    synopsis = "[options]"
    optParameters = [
        ["user", "u", "admin", "Name of user to allow to log in"],
        ["port", "p", str(pb.portno), "Port to listen on"],
    ]

    optFlags = [
        ["tracebacks", "T", "Allow tracebacks to be sent over the network"],
    ]

    compData = usage.Completions(
        optActions={"user": usage.CompleteUsernames()})

    def opt_password(self, password):
        """Required.  '-' will prompt or read a password from stdin.
        """
        # If standard input is a terminal, I prompt for a password and
        # confirm it.  Otherwise, I use the first line from standard
        # input, stripping off a trailing newline if there is one.
        if password in ('', '-'):
            self['password'] = util.getPassword(confirm=1)
        else:
            self['password'] = password

    opt_w = opt_password

    def postOptions(self):
        if not self.has_key('password'):
            self.opt_password('-')
Esempio n. 3
0
class ServerOptions(app.ServerOptions):
    synopsis = "Usage: twistd [options]"

    optFlags = [
        ["nodaemon", "n", "don't daemonize, don't use default umask of 0077"],
        ["originalname", None, "Don't try to change the process name"],
        ["syslog", None, "Log to syslog, not to file"],
        [
            "euid",
            "",
            "Set only effective user-id rather than real user-id. "
            "(This option has no effect unless the server is running as "
            "root, in which case it means not to shed all privileges "
            "after binding ports, retaining the option to regain "
            "privileges in cases such as spawning processes. "
            "Use with caution.)",
        ],
    ]

    optParameters = [
        ["prefix", None, "twisted", "use the given prefix when syslogging"],
        ["pidfile", "", "twistd.pid", "Name of the pidfile"],
        ["chroot", None, None, "Chroot to a supplied directory before running"],
        ["uid", "u", None, "The uid to run as.", uidFromString],
        [
            "gid",
            "g",
            None,
            "The gid to run as.  If not specified, the default gid "
            "associated with the specified --uid is used.",
            gidFromString,
        ],
        ["umask", None, None, "The (octal) file creation mask to apply.", _umask],
    ]

    compData = usage.Completions(
        optActions={
            "pidfile": usage.CompleteFiles("*.pid"),
            "chroot": usage.CompleteDirs(descr="chroot directory"),
            "gid": usage.CompleteGroups(descr="gid to run as"),
            "uid": usage.CompleteUsernames(descr="uid to run as"),
            "prefix": usage.Completer(descr="syslog prefix"),
        },
    )

    def opt_version(self):
        """
        Print version information and exit.
        """
        print(
            "twistd (the Twisted daemon) {}".format(copyright.version), file=self.stdout
        )
        print(copyright.copyright, file=self.stdout)
        sys.exit()

    def postOptions(self):
        app.ServerOptions.postOptions(self)
        if self["pidfile"]:
            self["pidfile"] = os.path.abspath(self["pidfile"])
Esempio n. 4
0
class ServerOptions(app.ServerOptions):
    synopsis = "Usage: twistd [options]"

    optFlags = [
        ['nodaemon', 'n', "don't daemonize, don't use default umask of 0077"],
        ['originalname', None, "Don't try to change the process name"],
        ['syslog', None, "Log to syslog, not to file"],
        [
            'euid', '', "Set only effective user-id rather than real user-id. "
            "(This option has no effect unless the server is running as "
            "root, in which case it means not to shed all privileges "
            "after binding ports, retaining the option to regain "
            "privileges in cases such as spawning processes. "
            "Use with caution.)"
        ],
    ]

    optParameters = [
        ['prefix', None, 'twisted', "use the given prefix when syslogging"],
        ['pidfile', '', 'twistd.pid', "Name of the pidfile"],
        [
            'chroot', None, None,
            'Chroot to a supplied directory before running'
        ],
        ['uid', 'u', None, "The uid to run as.", uidFromString],
        ['gid', 'g', None, "The gid to run as.", gidFromString],
        [
            'umask', None, None, "The (octal) file creation mask to apply.",
            _umask
        ],
    ]

    compData = usage.Completions(optActions={
        "pidfile":
        usage.CompleteFiles("*.pid"),
        "chroot":
        usage.CompleteDirs(descr="chroot directory"),
        "gid":
        usage.CompleteGroups(descr="gid to run as"),
        "uid":
        usage.CompleteUsernames(descr="uid to run as"),
        "prefix":
        usage.Completer(descr="syslog prefix"),
    }, )

    def opt_version(self):
        """Print version information and exit.
        """
        print 'twistd (the Twisted daemon) %s' % copyright.version
        print copyright.copyright
        sys.exit()

    def postOptions(self):
        app.ServerOptions.postOptions(self)
        if self['pidfile']:
            self['pidfile'] = os.path.abspath(self['pidfile'])
Esempio n. 5
0
class Options(usage.Options):
    synopsis = "[options]"
    longdesc = "Makes a telnet server to a Python shell."
    optParameters = [
        ["username", "u", "admin", "set the login username"],
        ["password", "w", "changeme", "set the password"],
        ["port", "p", "4040", "port to listen on"],
    ]

    compData = usage.Completions(
        optActions={"username": usage.CompleteUsernames()})
Esempio n. 6
0
class MyOptions(usage.Options):
    optParameters = [("user", "u", "guest", "username"),
                     ("password", "w", "guest"),
                     ("service", "s", "twisted.manhole", "PB Service"),
                     ("host", "h", "localhost"), ("port", "p", str(pbportno)),
                     ("perspective", "P", "", "PB Perspective to ask for "
                      "(if different than username)")]

    compData = usage.Completions(optActions={
        "host": usage.CompleteHostnames(),
        "user": usage.CompleteUsernames()
    })
Esempio n. 7
0
class ConchOptions(usage.Options):

    optParameters = [
        ['user', 'l', None, 'Log in using this user name.'],
        ['identity', 'i', None],
        ['ciphers', 'c', None],
        ['macs', 'm', None],
        [
            'port', 'p', None,
            'Connect to this port.  Server must be on the same port.'
        ],
        ['option', 'o', None, 'Ignored OpenSSH options'],
        ['host-key-algorithms', '', None],
        ['known-hosts', '', None, 'File to check for host keys'],
        [
            'user-authentications', '', None,
            'Types of user authentications to use.'
        ],
        ['logfile', '', None, 'File to log to, or - for stdout'],
    ]  # type: List[List[Optional[Union[str, int]]]]

    optFlags = [
        ['version', 'V', 'Display version number only.'],
        ['compress', 'C', 'Enable compression.'],
        ['log', 'v', 'Enable logging (defaults to stderr)'],
        ['nox11', 'x', 'Disable X11 connection forwarding (default)'],
        ['agent', 'A', 'Enable authentication agent forwarding'],
        ['noagent', 'a', 'Disable authentication agent forwarding (default)'],
        [
            'reconnect', 'r',
            'Reconnect to the server if the connection is lost.'
        ],
    ]

    compData = usage.Completions(
        mutuallyExclusive=[("agent", "noagent")],
        optActions={
            "user":
            usage.CompleteUsernames(),
            "ciphers":
            usage.CompleteMultiList(SSHCiphers.cipherMap.keys(),
                                    descr='ciphers to choose from'),
            "macs":
            usage.CompleteMultiList(SSHCiphers.macMap.keys(),
                                    descr='macs to choose from'),
            "host-key-algorithms":
            usage.CompleteMultiList(
                SSHClientTransport.supportedPublicKeys,
                descr='host key algorithms to choose from'),
            #"user-authentications": usage.CompleteMultiList(?
            # descr='user authentication types' ),
        },
        extraActions=[
            usage.CompleteUserAtHost(),
            usage.Completer(descr="command"),
            usage.Completer(descr='argument', repeat=True)
        ])

    def __init__(self, *args, **kw):
        usage.Options.__init__(self, *args, **kw)
        self.identitys = []
        self.conns = None

    def opt_identity(self, i):
        """Identity for public-key authentication"""
        self.identitys.append(i)

    def opt_ciphers(self, ciphers):
        "Select encryption algorithms"
        ciphers = ciphers.split(',')
        for cipher in ciphers:
            if cipher not in SSHCiphers.cipherMap:
                sys.exit("Unknown cipher type '%s'" % cipher)
        self['ciphers'] = ciphers

    def opt_macs(self, macs):
        "Specify MAC algorithms"
        if isinstance(macs, unicode):
            macs = macs.encode("utf-8")
        macs = macs.split(b',')
        for mac in macs:
            if mac not in SSHCiphers.macMap:
                sys.exit("Unknown mac type '%r'" % mac)
        self['macs'] = macs

    def opt_host_key_algorithms(self, hkas):
        "Select host key algorithms"
        if isinstance(hkas, unicode):
            hkas = hkas.encode("utf-8")
        hkas = hkas.split(b',')
        for hka in hkas:
            if hka not in SSHClientTransport.supportedPublicKeys:
                sys.exit("Unknown host key type '%r'" % hka)
        self['host-key-algorithms'] = hkas

    def opt_user_authentications(self, uas):
        "Choose how to authenticate to the remote server"
        if isinstance(uas, unicode):
            uas = uas.encode("utf-8")
        self['user-authentications'] = uas.split(b',')
Esempio n. 8
0
class ConchOptions(usage.Options):

    optParameters: List[List[Optional[Union[str, int]]]] = [
        ["user", "l", None, "Log in using this user name."],
        ["identity", "i", None],
        ["ciphers", "c", None],
        ["macs", "m", None],
        ["port", "p", None, "Connect to this port.  Server must be on the same port."],
        ["option", "o", None, "Ignored OpenSSH options"],
        ["host-key-algorithms", "", None],
        ["known-hosts", "", None, "File to check for host keys"],
        ["user-authentications", "", None, "Types of user authentications to use."],
        ["logfile", "", None, "File to log to, or - for stdout"],
    ]

    optFlags = [
        ["version", "V", "Display version number only."],
        ["compress", "C", "Enable compression."],
        ["log", "v", "Enable logging (defaults to stderr)"],
        ["nox11", "x", "Disable X11 connection forwarding (default)"],
        ["agent", "A", "Enable authentication agent forwarding"],
        ["noagent", "a", "Disable authentication agent forwarding (default)"],
        ["reconnect", "r", "Reconnect to the server if the connection is lost."],
    ]

    compData = usage.Completions(
        mutuallyExclusive=[("agent", "noagent")],
        optActions={
            "user": usage.CompleteUsernames(),
            "ciphers": usage.CompleteMultiList(
                [v.decode() for v in SSHCiphers.cipherMap.keys()],
                descr="ciphers to choose from",
            ),
            "macs": usage.CompleteMultiList(
                [v.decode() for v in SSHCiphers.macMap.keys()],
                descr="macs to choose from",
            ),
            "host-key-algorithms": usage.CompleteMultiList(
                [v.decode() for v in SSHClientTransport.supportedPublicKeys],
                descr="host key algorithms to choose from",
            ),
            # "user-authentications": usage.CompleteMultiList(?
            # descr='user authentication types' ),
        },
        extraActions=[
            usage.CompleteUserAtHost(),
            usage.Completer(descr="command"),
            usage.Completer(descr="argument", repeat=True),
        ],
    )

    def __init__(self, *args, **kw):
        usage.Options.__init__(self, *args, **kw)
        self.identitys = []
        self.conns = None

    def opt_identity(self, i):
        """Identity for public-key authentication"""
        self.identitys.append(i)

    def opt_ciphers(self, ciphers):
        "Select encryption algorithms"
        ciphers = ciphers.split(",")
        for cipher in ciphers:
            if cipher not in SSHCiphers.cipherMap:
                sys.exit("Unknown cipher type '%s'" % cipher)
        self["ciphers"] = ciphers

    def opt_macs(self, macs):
        "Specify MAC algorithms"
        if isinstance(macs, str):
            macs = macs.encode("utf-8")
        macs = macs.split(b",")
        for mac in macs:
            if mac not in SSHCiphers.macMap:
                sys.exit("Unknown mac type '%r'" % mac)
        self["macs"] = macs

    def opt_host_key_algorithms(self, hkas):
        "Select host key algorithms"
        if isinstance(hkas, str):
            hkas = hkas.encode("utf-8")
        hkas = hkas.split(b",")
        for hka in hkas:
            if hka not in SSHClientTransport.supportedPublicKeys:
                sys.exit("Unknown host key type '%r'" % hka)
        self["host-key-algorithms"] = hkas

    def opt_user_authentications(self, uas):
        "Choose how to authenticate to the remote server"
        if isinstance(uas, str):
            uas = uas.encode("utf-8")
        self["user-authentications"] = uas.split(b",")