aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/net/secrets.el138
1 files changed, 78 insertions, 60 deletions
diff --git a/lisp/net/secrets.el b/lisp/net/secrets.el
index f7cc011615e..22a4e8c7b0a 100644
--- a/lisp/net/secrets.el
+++ b/lisp/net/secrets.el
@@ -641,8 +641,9 @@ The object labels of the found items are returned as list."
641 641
642(defun secrets-create-item (collection item password &rest attributes) 642(defun secrets-create-item (collection item password &rest attributes)
643 "Create a new item in COLLECTION with label ITEM and password PASSWORD. 643 "Create a new item in COLLECTION with label ITEM and password PASSWORD.
644ATTRIBUTES are key-value pairs set for the created item. The 644The label ITEM must not be unique in COLLECTION. ATTRIBUTES are
645keys are keyword symbols, starting with a colon. Example: 645key-value pairs set for the created item. The keys are keyword
646symbols, starting with a colon. Example:
646 647
647 (secrets-create-item \"Tramp collection\" \"item\" \"geheim\" 648 (secrets-create-item \"Tramp collection\" \"item\" \"geheim\"
648 :method \"sudo\" :user \"joe\" :host \"remote-host\") 649 :method \"sudo\" :user \"joe\" :host \"remote-host\")
@@ -655,67 +656,73 @@ determined by this. If no `:xdg:schema' is given,
655\"org.freedesktop.Secret.Generic\" is used by default. 656\"org.freedesktop.Secret.Generic\" is used by default.
656 657
657The object path of the created item is returned." 658The object path of the created item is returned."
658 (unless (member item (secrets-list-items collection)) 659 (let ((collection-path (secrets-unlock-collection collection))
659 (let ((collection-path (secrets-unlock-collection collection)) 660 result props)
660 result props) 661 (unless (secrets-empty-path collection-path)
661 (unless (secrets-empty-path collection-path) 662 ;; Set default type if needed.
662 ;; Set default type if needed. 663 (unless (member :xdg:schema attributes)
663 (unless (member :xdg:schema attributes) 664 (setq attributes
664 (setq attributes 665 (append
665 (append 666 attributes `(:xdg:schema ,secrets-interface-item-type-generic))))
666 attributes 667 ;; Create attributes list.
667 `(:xdg:schema ,secrets-interface-item-type-generic)))) 668 (while (consp (cdr attributes))
668 ;; Create attributes list. 669 (unless (keywordp (car attributes))
669 (while (consp (cdr attributes)) 670 (error 'wrong-type-argument (car attributes)))
670 (unless (keywordp (car attributes)) 671 (unless (stringp (cadr attributes))
671 (error 'wrong-type-argument (car attributes))) 672 (error 'wrong-type-argument (cadr attributes)))
672 (unless (stringp (cadr attributes)) 673 (setq props (append
673 (error 'wrong-type-argument (cadr attributes))) 674 props
674 (setq props (append 675 `((:dict-entry
675 props 676 ,(substring (symbol-name (car attributes)) 1)
676 `((:dict-entry 677 ,(cadr attributes))))
677 ,(substring (symbol-name (car attributes)) 1) 678 attributes (cddr attributes)))
678 ,(cadr attributes)))) 679 ;; Create the item.
679 attributes (cddr attributes))) 680 (setq result
680 ;; Create the item. 681 (dbus-call-method
681 (setq result 682 :session secrets-service collection-path
682 (dbus-call-method 683 secrets-interface-collection "CreateItem"
683 :session secrets-service collection-path 684 ;; Properties.
684 secrets-interface-collection "CreateItem" 685 (append
685 ;; Properties. 686 `(:array
686 (append 687 (:dict-entry ,(concat secrets-interface-item ".Label")
687 `(:array 688 (:variant ,item)))
688 (:dict-entry ,(concat secrets-interface-item ".Label") 689 (when props
689 (:variant ,item))) 690 `((:dict-entry ,(concat secrets-interface-item ".Attributes")
690 (when props 691 (:variant ,(append '(:array) props))))))
691 `((:dict-entry ,(concat secrets-interface-item ".Attributes") 692 ;; Secret.
692 (:variant ,(append '(:array) props)))))) 693 (append
693 ;; Secret. 694 `(:struct :object-path ,secrets-session-path
694 (append 695 (:array :signature "y") ;; No parameters.
695 `(:struct :object-path ,secrets-session-path 696 ,(dbus-string-to-byte-array password))
696 (:array :signature "y") ;; No parameters. 697 ;; We add the content_type. In backward compatibility
697 ,(dbus-string-to-byte-array password)) 698 ;; mode, nil is appended, which means nothing.
698 ;; We add the content_type. In backward compatibility 699 secrets-struct-secret-content-type)
699 ;; mode, nil is appended, which means nothing. 700 ;; Do not replace. Replace does not seem to work.
700 secrets-struct-secret-content-type) 701 nil))
701 ;; Do not replace. Replace does not seem to work. 702 (secrets-prompt (cadr result))
702 nil)) 703 ;; Return the object path.
703 (secrets-prompt (cadr result)) 704 (car result))))
704 ;; Return the object path.
705 (car result)))))
706 705
707(defun secrets-item-path (collection item) 706(defun secrets-item-path (collection item)
708 "Return the object path of item labeled ITEM in COLLECTION. 707 "Return the object path of item labeled ITEM in COLLECTION.
709If there is no such item, return nil." 708If there are several items labeled ITEM, it is undefined which
709one is returned. If there is no such item, return nil.
710
711ITEM can also be an object path, which is returned if contained in COLLECTION."
710 (let ((collection-path (secrets-unlock-collection collection))) 712 (let ((collection-path (secrets-unlock-collection collection)))
711 (catch 'item-found 713 (or (and (member item (secrets-get-items collection-path)) item)
712 (dolist (item-path (secrets-get-items collection-path)) 714 (catch 'item-found
713 (when (string-equal item (secrets-get-item-property item-path "Label")) 715 (dolist (item-path (secrets-get-items collection-path))
714 (throw 'item-found item-path)))))) 716 (when (string-equal
717 item (secrets-get-item-property item-path "Label"))
718 (throw 'item-found item-path)))))))
715 719
716(defun secrets-get-secret (collection item) 720(defun secrets-get-secret (collection item)
717 "Return the secret of item labeled ITEM in COLLECTION. 721 "Return the secret of item labeled ITEM in COLLECTION.
718If there is no such item, return nil." 722If there are several items labeled ITEM, it is undefined which
723one is returned. If there is no such item, return nil.
724
725ITEM can also be an object path, which is used if contained in COLLECTION."
719 (let ((item-path (secrets-item-path collection item))) 726 (let ((item-path (secrets-item-path collection item)))
720 (unless (secrets-empty-path item-path) 727 (unless (secrets-empty-path item-path)
721 (dbus-byte-array-to-string 728 (dbus-byte-array-to-string
@@ -726,8 +733,11 @@ If there is no such item, return nil."
726 733
727(defun secrets-get-attributes (collection item) 734(defun secrets-get-attributes (collection item)
728 "Return the lookup attributes of item labeled ITEM in COLLECTION. 735 "Return the lookup attributes of item labeled ITEM in COLLECTION.
729If there is no such item, or the item has no attributes, return nil." 736If there are several items labeled ITEM, it is undefined which
730 (unless (stringp collection) (setq collection "default")) 737one is returned. If there is no such item, or the item has no
738attributes, return nil.
739
740ITEM can also be an object path, which is used if contained in COLLECTION."
731 (let ((item-path (secrets-item-path collection item))) 741 (let ((item-path (secrets-item-path collection item)))
732 (unless (secrets-empty-path item-path) 742 (unless (secrets-empty-path item-path)
733 (mapcar 743 (mapcar
@@ -739,11 +749,19 @@ If there is no such item, or the item has no attributes, return nil."
739 749
740(defun secrets-get-attribute (collection item attribute) 750(defun secrets-get-attribute (collection item attribute)
741 "Return the value of ATTRIBUTE of item labeled ITEM in COLLECTION. 751 "Return the value of ATTRIBUTE of item labeled ITEM in COLLECTION.
742If there is no such item, or the item doesn't own this attribute, return nil." 752If there are several items labeled ITEM, it is undefined which
753one is returned. If there is no such item, or the item doesn't
754own this attribute, return nil.
755
756ITEM can also be an object path, which is used if contained in COLLECTION."
743 (cdr (assoc attribute (secrets-get-attributes collection item)))) 757 (cdr (assoc attribute (secrets-get-attributes collection item))))
744 758
745(defun secrets-delete-item (collection item) 759(defun secrets-delete-item (collection item)
746 "Delete ITEM in COLLECTION." 760 "Delete item labeled ITEM in COLLECTION.
761If there are several items labeled ITEM, it is undefined which
762one is deleted.
763
764ITEM can also be an object path, which is used if contained in COLLECTION."
747 (let ((item-path (secrets-item-path collection item))) 765 (let ((item-path (secrets-item-path collection item)))
748 (unless (secrets-empty-path item-path) 766 (unless (secrets-empty-path item-path)
749 (secrets-prompt 767 (secrets-prompt