예제 #1
0
파일: module.py 프로젝트: neoclust/mss
 def authenticate(self, user, password):
     """ Authenticate mss-www to the agent """
     if not user or not password:
         return False
     # Logout the current user
     self.logout()
     # Local auth with PAM
     if user == "root":
         logger.debug("PAM authentication")
         from mss.agent.lib import pam
         result = pam.authenticate(user, password, service="passwd")
         if result:
             logger.debug("Logged with PAM.")
             # Generate an uuid for this session
             self._token = str(uuid.uuid4())
             self._mode = "local"
             self.load()
             return self._token
         logger.error("Login failed against PAM.")
         return False
     # API auth
     else:
         logger.debug("ServicePlace authentication")
         url = Config().tokenUrl
         result, code = self.request(url, {'username': user, 'password': password.encode('utf-8')})
         if code == 200:
             if 'token' in result:
                 logger.debug("Logged with the ServicePlace !")
                 self._token = result['token']
                 self._mode = "api"
                 self.load()
                 return self._token
         logger.error("Login failed against the ServicePlace.")
         return False
예제 #2
0
 def authenticate(self, user, password):
     """ Authenticate mss-www to the agent """
     if not user or not password:
         return False
     # Logout the current user
     self.logout()
     # Local auth with PAM
     if user == "root":
         logger.debug("PAM authentication")
         from mss.agent.lib import pam
         result = pam.authenticate(user, password, service="passwd")
         if result:
             logger.debug("Logged with PAM.")
             # Generate an uuid for this session
             self._token = str(uuid.uuid4())
             self._mode = "local"
             self.load()
             return self._token
         logger.error("Login failed against PAM.")
         return False
     # API auth
     else:
         logger.debug("ServicePlace authentication")
         url = Config().tokenUrl
         result, code = self.request(url, {'username': user, 'password': password.encode('utf-8')})
         if code == 200:
             if 'token' in result:
                 logger.debug("Logged with the ServicePlace !")
                 self._token = result['token']
                 self._mode = "api"
                 self.load()
                 return self._token
         logger.error("Login failed against the ServicePlace.")
         return False
예제 #3
0
#!/usr/bin/python

import sys
from mss.agent.lib import pam

password = sys.argv[1]

result = pam.authenticate("root", password, service="passwd")
if result:
    print 0
    sys.exit(0)
print 1
sys.exit(1)