Ejemplo n.º 1
0
    def set_credentials(self, user, pw):
        """
        Store or update username and password for account
        """
        # Note: attrs is used to look up the account for old user credentials
        attrs = {"server": self._host, "protocol": self._protocol}

        LOGGER.debug("Updating credentials for %s" % self._host)

        keyring = matekeyring.get_default_keyring_sync()

        # Look up all accounts registered for this service and realm and delete
        # them. We get weird errors if more than one account is present
        try:
            items = matekeyring.find_items_sync(matekeyring.ITEM_NETWORK_PASSWORD, attrs)
        except matekeyring.NoMatchError:
            LOGGER.debug("No existing accounts for %s" % self._host)
            items = []

        for item in items:
            LOGGER.debug("Purging account %s@%s" % (item.attributes["user"], item.attributes["server"]))
            matekeyring.item_delete_sync(keyring, item.item_id)

        # Add the 'user' attribute to attrs and commit it to the keyring
        LOGGER.debug("Creating new account %s@%s" % (user, self._host))
        attrs["user"] = user
        matekeyring.item_create_sync(keyring, matekeyring.ITEM_NETWORK_PASSWORD, self._realm, attrs, pw, True)

        LOGGER.debug("Credential update success")
Ejemplo n.º 2
0
    def get_credentials(self):
        """
        @return: A tuple C{(user, password)} or throws an exception if the
            credentials for the account are not known
        """
        attrs = {"server": self._host, "protocol": self._protocol}
        items = matekeyring.find_items_sync(matekeyring.ITEM_NETWORK_PASSWORD, attrs)

        if len(items) > 1:
            LOGGER.warn("More than one account found for %s" % self._host)

        return (items[0].attributes["user"], items[0].secret)
Ejemplo n.º 3
0
    def __try_connect(self):
        import mpd
        try:
            full_key = self.__plugin._conf.resolve_plugin_key(
                self.__plugin, "host")
            host = self.__plugin._conf.client.get_string(full_key)
            if host == "":
                host = "localhost"
                self.host = os.environ.get("MPD_HOST", "localhost")
                if "@" in self.host:
                    self.host = (self.host.split("@", 1))[1]
            else:
                self.host = host

            full_key = self.__plugin._conf.resolve_plugin_key(
                self.__plugin, "port")
            port = self.__plugin._conf.client.get_int(full_key)
            if port <= 0:
                port = 6600
                self.port = int(os.environ.get("MPD_PORT", 6600))
            else:
                self.port = port

            self.__mpd = mpd.MPDClient()
            self.__mpd.connect(host, port)

            if not self.__authenticate():
                try:
                    import matekeyring
                    keyring = matekeyring.get_default_keyring_sync()
                    found = matekeyring.find_items_sync(
                        matekeyring.ITEM_NETWORK_PASSWORD, {
                            "server": self.host,
                            "port": self.port,
                            "protocol": "mpd"
                        })
                    for item in found:
                        if self.__authenticate(item.secret, False):
                            break
                except ImportError:
                    print "MPD plugin: unable to check for saved passwords"
                except matekeyring.DeniedError:
                    print "MPD plugin: no passwords found"
                except AttributeError:
                    print "MPD plugin: password lookup requires matekeyring >= 2.18.0"

            if not self.__authenticated:
                gobject.idle_add(self.__plugin._show_password_dialog)

        except socket.error:
            # Thrown if connect fails.
            self.__mpd = None
Ejemplo n.º 4
0
    def get_credentials(self):
        """
        @return: A tuple C{(user, password)} or throws an exception if the
            credentials for the account are not known
        """
        attrs = {"server": self._host, "protocol": self._protocol}
        items = matekeyring.find_items_sync(matekeyring.ITEM_NETWORK_PASSWORD,
                                            attrs)

        if (len(items) > 1):
            LOGGER.warn("More than one account found for %s" % self._host)

        return (items[0].attributes["user"], items[0].secret)
Ejemplo n.º 5
0
 def has_credentials(self):
     """
     @returns: True if and only if the credentials for this account is known
     """
     try:
         attrs = {"server": self._host, "protocol": self._protocol}
         items = matekeyring.find_items_sync(matekeyring.ITEM_NETWORK_PASSWORD, attrs)
         if len(items) > 0:
             if items[0].attributes["user"] != "" and items[0].secret != "":
                 return True
             else:
                 return False
     except matekeyring.DeniedError:
         return False
     except matekeyring.NoMatchError:
         return False
Ejemplo n.º 6
0
    def __try_connect (self):
        import mpd
        try:
            full_key = self.__plugin._conf.resolve_plugin_key (self.__plugin, "host")
            host = self.__plugin._conf.client.get_string (full_key)
            if host == "":
                host = "localhost"
                self.host = os.environ.get ("MPD_HOST", "localhost")
                if "@" in self.host:
                    self.host = (self.host.split ("@", 1))[1]
            else:
                self.host = host

            full_key = self.__plugin._conf.resolve_plugin_key (self.__plugin, "port")
            port = self.__plugin._conf.client.get_int (full_key)
            if port <= 0:
                port = 6600
                self.port = int (os.environ.get ("MPD_PORT", 6600))
            else:
                self.port = port

            self.__mpd = mpd.MPDClient ()
            self.__mpd.connect (host, port)

            if not self.__authenticate ():
                try:
                    import matekeyring
                    keyring = matekeyring.get_default_keyring_sync ()
                    found = matekeyring.find_items_sync (matekeyring.ITEM_NETWORK_PASSWORD,
                                                          { "server":self.host, "port":self.port, "protocol":"mpd" })
                    for item in found:
                        if self.__authenticate (item.secret, False):
                            break
                except ImportError:
                    print "MPD plugin: unable to check for saved passwords"
                except matekeyring.DeniedError:
                    print "MPD plugin: no passwords found"
                except AttributeError:
                    print "MPD plugin: password lookup requires matekeyring >= 2.18.0"

            if not self.__authenticated:
                gobject.idle_add (self.__plugin._show_password_dialog)

        except socket.error:
            # Thrown if connect fails.
            self.__mpd = None
Ejemplo n.º 7
0
 def has_credentials(self):
     """
     @returns: True if and only if the credentials for this account is known
     """
     try:
         attrs = {"server": self._host, "protocol": self._protocol}
         items = matekeyring.find_items_sync(
             matekeyring.ITEM_NETWORK_PASSWORD, attrs)
         if len(items) > 0:
             if items[0].attributes["user"] != "" and \
                items[0].secret != "" :
                 return True
             else:
                 return False
     except matekeyring.DeniedError:
         return False
     except matekeyring.NoMatchError:
         return False
Ejemplo n.º 8
0
    def set_credentials(self, user, pw):
        """
        Store or update username and password for account
        """
        # Note: attrs is used to look up the account for old user credentials
        attrs = {
            "server": self._host,
            "protocol": self._protocol,
        }

        LOGGER.debug("Updating credentials for %s" % self._host)

        keyring = matekeyring.get_default_keyring_sync()

        # Look up all accounts registered for this service and realm and delete
        # them. We get weird errors if more than one account is present
        try:
            items = matekeyring.find_items_sync(
                matekeyring.ITEM_NETWORK_PASSWORD, attrs)
        except matekeyring.NoMatchError:
            LOGGER.debug("No existing accounts for %s" % self._host)
            items = []

        for item in items:
            LOGGER.debug("Purging account %s@%s" %
                         (item.attributes["user"], item.attributes["server"]))
            matekeyring.item_delete_sync(keyring, item.item_id)

        # Add the 'user' attribute to attrs and commit it to the keyring
        LOGGER.debug("Creating new account %s@%s" % (user, self._host))
        attrs["user"] = user
        matekeyring.item_create_sync(keyring,
                                     matekeyring.ITEM_NETWORK_PASSWORD,
                                     self._realm, attrs, pw, True)

        LOGGER.debug("Credential update success")