comparison lisp/net/secrets.el @ 107397:6c48d0b283da

* net/secrets.el (secrets-enabled): New variable. Use it instead of a subfeature.
author Michael Albinus <albinus@detlef>
date Tue, 16 Mar 2010 17:45:07 +0100
parents d5de7ba3f80f
children 9d443ad80849
comparison
equal deleted inserted replaced
107396:d5de7ba3f80f 107397:6c48d0b283da
32 32
33 ;; In order to activate this package, you must add the following code 33 ;; In order to activate this package, you must add the following code
34 ;; into your .emacs: 34 ;; into your .emacs:
35 ;; 35 ;;
36 ;; (require 'secrets) 36 ;; (require 'secrets)
37 37 ;;
38 ;; It can be checked afterwards, whether there is a daemon providing 38 ;; Afterwards, the variable `secrets-enabled' is non-nil when there is
39 ;; this interface: 39 ;; a daemon providing this interface.
40 ;;
41 ;; (featurep 'secrets 'enabled)
42 40
43 ;; The atomic objects to be managed by the Secret Service API are 41 ;; The atomic objects to be managed by the Secret Service API are
44 ;; secret items, which are something an application wishes to store 42 ;; secret items, which are something an application wishes to store
45 ;; securely. A good example is a password that an application needs 43 ;; securely. A good example is a password that an application needs
46 ;; to save and use at a later date. 44 ;; to save and use at a later date.
147 (declare-function dbus-call-method "dbusbind.c") 145 (declare-function dbus-call-method "dbusbind.c")
148 (declare-function dbus-register-signal "dbusbind.c") 146 (declare-function dbus-register-signal "dbusbind.c")
149 (defvar dbus-debug) 147 (defvar dbus-debug)
150 148
151 (require 'dbus) 149 (require 'dbus)
150
151 (defvar secrets-enabled nil
152 "Whether there is a daemon offering the Secret Service API."
152 153
153 (defvar secrets-debug t 154 (defvar secrets-debug t
154 "Write debug messages") 155 "Write debug messages")
155 156
156 (defconst secrets-service "org.freedesktop.secrets" 157 (defconst secrets-service "org.freedesktop.secrets"
662 (secrets-prompt 663 (secrets-prompt
663 (dbus-call-method 664 (dbus-call-method
664 :session secrets-service item-path 665 :session secrets-service item-path
665 secrets-interface-item "Delete"))))) 666 secrets-interface-item "Delete")))))
666 667
667 (if (dbus-ping :session secrets-service 100) 668 (when (dbus-ping :session secrets-service 100)
668 669
669 (progn 670 ;; We must reset all variables, when there is a new instance of the
670 ;; We must reset all variables, when there is a new instance of 671 ;; "org.freedesktop.secrets" service.
671 ;; the "org.freedesktop.secrets" service. 672 (dbus-register-signal
672 (dbus-register-signal 673 :session dbus-service-dbus dbus-path-dbus
673 :session dbus-service-dbus dbus-path-dbus 674 dbus-interface-dbus "NameOwnerChanged"
674 dbus-interface-dbus "NameOwnerChanged" 675 (lambda (&rest args)
675 (lambda (&rest args) 676 (when secrets-debug (message "Secret Service has changed: %S" args))
676 (when secrets-debug (message "Secret Service has changed: %S" args)) 677 (setq secrets-session-path secrets-empty-path
677 (setq secrets-session-path secrets-empty-path 678 secrets-prompt-signal nil
678 secrets-prompt-signal nil 679 secrets-collection-paths nil))
679 secrets-collection-paths nil)) 680 secrets-service)
680 secrets-service) 681
681 682 ;; We want to refresh our cache, when there is a change in
682 ;; We want to refresh our cache, when there is a change in 683 ;; collections.
683 ;; collections. 684 (dbus-register-signal
684 (dbus-register-signal 685 :session secrets-service secrets-path
685 :session secrets-service secrets-path 686 secrets-interface-service "CollectionCreated"
686 secrets-interface-service "CollectionCreated" 687 'secrets-collection-handler)
687 'secrets-collection-handler) 688
688 689 (dbus-register-signal
689 (dbus-register-signal 690 :session secrets-service secrets-path
690 :session secrets-service secrets-path 691 secrets-interface-service "CollectionDeleted"
691 secrets-interface-service "CollectionDeleted" 692 'secrets-collection-handler)
692 'secrets-collection-handler) 693
693 694 ;; We shall inform, whether the secret service is enabled on this
694 ;; We shall inform, whether the secret service is enabled on 695 ;; machine.
695 ;; this machine. 696 (setq secrets-enabled t)))
696 (provide 'secrets '(enabled))) 697
697 698 (provide 'secrets)
698 (provide 'secrets))
699 699
700 ;;; TODO: 700 ;;; TODO:
701 701
702 ;; * secrets-debug should be structured like auth-source-debug to 702 ;; * secrets-debug should be structured like auth-source-debug to
703 ;; prevent leaking sensitive information. Right now I don't see 703 ;; prevent leaking sensitive information. Right now I don't see