def test_require_valid_shell(self):

        def get_fake_shell_user():
            for user in self.get_users():
                shell = pwd.getpwnam(user).pw_shell
                # On linux fake shell is usually /bin/false, on
                # freebsd /usr/sbin/nologin;  in case of other
                # UNIX variants test needs to be adjusted.
                if '/false' in shell or '/nologin' in shell:
                    return user
            self.fail("no user found")

        user = get_fake_shell_user()
        self.assertRaisesWithMsg(
            AuthorizerError,
            "user %s has not a valid shell" % user,
            UnixAuthorizer, allowed_users=[user])
        # commented as it first fails for invalid home
        # self.assertRaisesWithMsg(
        #     ValueError,
        #     "user %s has not a valid shell" % user,
        #     UnixAuthorizer, anonymous_user=user)
        auth = UnixAuthorizer()
        self.assertTrue(auth._has_valid_shell(self.get_current_user()))
        self.assertFalse(auth._has_valid_shell(user))
        self.assertRaisesWithMsg(AuthorizerError,
                                 "User %s doesn't have a valid shell." % user,
                                 auth.override_user, user, perm='r')
Beispiel #2
0
 def test_validate_authentication(self):
     # we can only test for invalid credentials
     auth = UnixAuthorizer(require_valid_shell=False)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       '?!foo', '?!foo', None)
     auth = UnixAuthorizer(require_valid_shell=True)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       '?!foo', '?!foo', None)
Beispiel #3
0
 def test_validate_authentication_anonymous(self):
     current_user = self.get_current_user()
     auth = UnixAuthorizer(anonymous_user=current_user,
                           require_valid_shell=False)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       'foo', 'passwd', None)
     self.assertRaises(AuthenticationFailed, auth.validate_authentication,
                       current_user, 'passwd', None)
     auth.validate_authentication('anonymous', 'passwd', None)
 def test_validate_authentication_anonymous(self):
     current_user = self.get_current_user()
     auth = UnixAuthorizer(anonymous_user=current_user,
                           require_valid_shell=False)
     self.assertRaises(AuthenticationFailed,
                       auth.validate_authentication, 'foo', 'passwd', None)
     self.assertRaises(
         AuthenticationFailed,
         auth.validate_authentication, current_user, 'passwd', None)
     auth.validate_authentication('anonymous', 'passwd', None)
Beispiel #5
0
 def test_has_perm_anonymous(self):
     auth = UnixAuthorizer(global_perm='elr',
                           anonymous_user=self.get_current_user())
     self.assertTrue(auth.has_perm(self.get_current_user(), 'r'))
     self.assertFalse(auth.has_perm(self.get_current_user(), 'w'))
     self.assertTrue(auth.has_perm('anonymous', 'e'))
     self.assertFalse(auth.has_perm('anonymous', 'w'))
     warnings.filterwarnings("ignore")
     auth.override_user('anonymous', perm='w')
     warnings.resetwarnings()
     self.assertTrue(auth.has_perm('anonymous', 'w'))
Beispiel #6
0
def get_server():
    """Return a pre-configured FTP server instance."""
    handler = FTPHandler
    handler.authorizer = UnixAuthorizer()
    handler.abstracted_fs = UnixFilesystem
    server = FTPServer((HOST, PORT), handler)
    return server
Beispiel #7
0
def main():
    authorizer = UnixAuthorizer(rejected_users=["root"],
                                require_valid_shell=True)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    server = FTPServer(('', 21), handler)
    server.serve_forever()
 def test_has_perm_anonymous(self):
     auth = UnixAuthorizer(
         global_perm='elr', anonymous_user=self.get_current_user())
     self.assertTrue(auth.has_perm(self.get_current_user(), 'r'))
     self.assertFalse(auth.has_perm(self.get_current_user(), 'w'))
     self.assertTrue(auth.has_perm('anonymous', 'e'))
     self.assertFalse(auth.has_perm('anonymous', 'w'))
     warnings.filterwarnings("ignore")
     auth.override_user('anonymous', perm='w')
     warnings.resetwarnings()
     self.assertTrue(auth.has_perm('anonymous', 'w'))
def run(ip: str = None):
    authorizer = UnixAuthorizer(allowed_users=['mark'],
                                require_valid_shell=False,
                                anonymous_user='******',
                                global_perm='elradfmwM')
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    server = FTPServer((ip, 21), handler)
    server.serve_forever()
Beispiel #10
0
    def __init__(self):
        super().__init__(target=self.serve_forever)

        self.setDaemon(True)
        self.setName("FTP Daemon")

        self.authorizer = UnixAuthorizer(rejected_users=["root"])
        self.handler = FTPHandler
        self.handler.authorizer = self.authorizer
        self.handler.abstracted_fs = UnixFilesystem
        self.server = FTPServer(('127.0.0.1', 10021), self.handler)
Beispiel #11
0
def main():
    #authorizer = DummyAuthorizer()
    authorizer = UnixAuthorizer(rejected_users=["root"],
                                require_valid_shell=False)

    authorizer.override_user('bijan', homedir='/home/share')
    authorizer.override_user('yazdani', homedir='/home/share', perm='elradfmw')
    # authorizer.add_anonymous(homedir='/share/public')

    handler = MyHandler
    handler.authorizer = authorizer
    handler.use_send_file = True
    #handler.abstracted_fs = UnixFilesystem
    server = FTPServer(('', 2121), handler)
    #server = MultiprocessFTPServer(('', 2121), handler)
    server.serve_forever()
Beispiel #12
0
def main():
    # configuracao de log
    logger = logging.getLogger()
    ch = logging.StreamHandler(sys.stdout)
    logger.setLevel(logging.DEBUG)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    # fim configuracao de log

    # usando os usuarios UNIX
    authorizer = UnixAuthorizer(rejected_users=["root"],
                                require_valid_shell=True)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    handler.log_prefix = "%(username)s@%(remote_ip)s"
    #logger.basicConfig(filename='/var/log/pyftpd.log', level=logging.INFO)
    # utilizando o servidor multiprocesso
    server = MultiprocessFTPServer(('', 21), handler)
    server.serve_forever()
Beispiel #13
0
 def setUp(self):
     try:
         UnixAuthorizer()
     except AuthorizerError:  # not root
         self.skipTest("need root access")
Beispiel #14
0
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import UnixAuthorizer
from pyftpdlib.filesystems import UnixFilesystem

if __name__ == "__main__":
    authorizer = UnixAuthorizer(require_valid_shell=False) # anonymous_user="******", allowed_users=["dylan"]
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    server = FTPServer(('', 2121), handler)
    server.serve_forever()
Beispiel #15
0
def exitError(errorcode):
    print("[FATAL]: Exit error code ", errorcode)


def Interrupt():
    try:
        KeyboardInterrupt()
        sys.exit(0)
    except:
        KeyboardInterrupt(print("[INFO]: Server is going down gently!"))
        sys.exit(0)


if os.name == 'posix':
    authorizer = UnixAuthorizer()
# Trying to get Windows to work...
#elif os.name == 'nt':
#    authorizer = WindowsAuthorizer()
else:
    try:
        OperatingSystemError(
            print(
                "[WARN]: Your operating system isn't supported! This software runs only on Unix machines!"
            ))
    except OperatingSystemError:
        print("[WARN]: This shouldn't happen but alrighty then!")
        exitError(str(-1))
        sys.exit(0)

handler = FTPHandler
Beispiel #16
0
#!/usr/bin/env python

from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import UnixAuthorizer
from pyftpdlib.filesystems import UnixFilesystem

authorizer = UnixAuthorizer(rejected_users=["root"], require_valid_shell=True)

handler = FTPHandler
handler.authorizer = authorizer

handler.abstracted_fs = UnixFilesystem

address = ('', 21)
ftpd = FTPServer(address, handler)

ftpd.serve_forever()