Ë
    ÖÓ­hº  ã                   óÄ   — d Z dZdZddlZddlmZmZmZ ddlm	Z	m
Z
 dZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZ	 	 dd„Z	 	 dd„Zdd„Zdd„Zedd„«       Zedd„«       Zy)zHProvides access to PolicyKit privilege mangement using gdefer Deferreds.z%Sebastian Heinlein <devel@glatzor.de>)Úcheck_authorization_by_nameÚcheck_authorization_by_pidÚget_pid_from_dbus_nameÚget_uid_from_dbus_nameÚ!CHECK_AUTH_ALLOW_USER_INTERACTIONÚCHECK_AUTH_NONEÚPK_ACTION_ADD_REMOVE_VENDOR_KEYÚPK_ACTION_CANCEL_FOREIGNÚPK_ACTION_CHANGE_REPOSITORYÚPK_ACTION_CHANGE_CONIFGÚ!PK_ACTION_GET_TRUSTED_VENDOR_KEYSÚPK_ACTION_INSTALL_FILEÚ$PK_ACTION_INSTALL_OR_REMOVE_PACKAGESÚ(PK_ACTION_INSTALL_PACKAGES_FROM_NEW_REPOÚ/PK_ACTION_INSTALL_PACKAGES_FROM_HIGH_TRUST_REPOÚ$PK_ACTION_INSTALL_PURCHASED_PACKAGESÚPK_ACTION_UPDATE_CACHEÚPK_ACTION_UPGRADE_PACKAGESÚPK_ACTION_SET_PROXYÚPK_ACTION_CLEANé    N)ÚDeferredÚinline_callbacksÚreturn_valueé   )ÚNotAuthorizedErrorÚAuthorizationFailedz%org.aptkit.install-or-remove-packagesz%org.aptkit.install-purchased-packagesz)org.aptkit.install-packages-from-new-repoz+org.aptkit.install-packages.high-trust-repozorg.aptkit.install-filezorg.aptkit.upgrade-packageszorg.aptkit.update-cachezorg.aptkit.cancel-foreignz"org.aptkit.get-trusted-vendor-keyszorg.aptkit.change-repositoryzorg.aptkit.change-configzorg.aptkit.set-proxyzorg.aptkit.cleanc                 ó,   — dd| if}t        |||||«      S )a¼  Check if the given sender is authorized for the specified action.

    If the sender is not authorized raise NotAuthorizedError.

    Keyword arguments:
    dbus_name -- D-Bus name of the subject
    action_id -- the PolicyKit policy name of the action
    timeout -- time in seconds for the user to authenticate
    bus -- the D-Bus connection (defaults to the system bus)
    flags -- optional flags to control the authentication process
    zsystem-bus-nameÚname©Ú_check_authorization)Ú	dbus_nameÚ	action_idÚtimeoutÚbusÚflagsÚsubjects         ú3/usr/lib/python3/dist-packages/aptkit/policykit1.pyr   r   @   s&   € ð ! 6¨9Ð"5Ð6€GÜ ¨°G¸SÀ%ÓHÐHó    c                 ó,   — dd| if}t        |||||«      S )a¯  Check if the given process is authorized for the specified action.

    If the sender is not authorized raise NotAuthorizedError.

    Keyword arguments:
    pid -- id of the process
    action_id -- the PolicyKit policy name of the action
    timeout -- time in seconds for the user to authenticate
    bus -- the D-Bus connection (defaults to the system bus)
    flags -- optional flags to control the authentication process
    zunix-processÚpidr   )r*   r"   r#   r$   r%   r&   s         r'   r   r   Q   s%   € ð   s˜|Ð,€GÜ ¨°G¸SÀ%ÓHÐHr(   c                 óÚ   ‡ ‡‡— ˆˆˆ fd„}|st        j                  «       }|€t        }t        «       Š|j	                  dd«      }i }|j                  ‰ ‰||dd||‰j                  ¬«	       ‰S )Nc                 ó¬   •— | \  }}}|r‰j                  |«       y |r‰j                  t        ‰‰«      «       y ‰j                  t        ‰‰«      «       y ©N)ÚcallbackÚerrbackr   r   )Úxxx_todo_changemeÚ
authorizedÚ
challengedÚauth_detailsr"   Údeferredr&   s       €€€r'   Úpolicykit_donez,_check_authorization.<locals>.policykit_donec   sO   ø€ Ø1BÑ.ˆ�Z ÙØ×Ñ˜lÕ+ÙØ×ÑÔ0°¸)ÓDÕEà×ÑÔ/°¸ÓCÕDr(   zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/AuthorityÚ z$org.freedesktop.PolicyKit1.Authority)Údbus_interfacer#   Úreply_handlerÚerror_handler)ÚdbusÚ	SystemBusr   r   Ú
get_objectÚCheckAuthorizationr/   )	r&   r"   r#   r$   r%   r5   ÚpkÚdetailsr4   s	   ``      @r'   r    r    b   s|   ú€ öEñ Ü�n‰nÓˆà€}Ü1ˆÜ‹z€HØ	�‰Ð4Ø?ó
A€Bà€GØ×ÑØ�˜G U¨BØ=ØØ$Ø×&Ñ&ð ô (ð €Or(   c                 ó¼   — |st        j                  «       }t        «       }|j                  dd«      }|j	                  | d|j
                  |j                  ¬«       |S )zZReturn a deferred that gets the id of process owning the given
    system D-Bus name.
    zorg.freedesktop.DBusz/org/freedesktop/DBus/Bus)r7   r8   r9   )r:   r;   r   r<   ÚGetConnectionUnixProcessIDr.   r/   )r!   r$   r4   Úbus_objs       r'   r   r   }   s`   € ñ Ü�n‰nÓˆÜ‹z€HØ�n‰nÐ3Ø8ó:€Gà×&Ñ& yØ6LØ5=×5FÑ5FØ5=×5EÑ5Eð 'ô Gð €Or(   c              #   óV  K  — |st        j                  «       }t        | |«      –—}t        d|z  «      5 }|j	                  «       D �cg c]  }|j                  d«      sŒ|‘Œ }}ddd«       t        d   j                  «       d   «      }t        |«       yc c}w # 1 sw Y   Œ9xY w­w)z\Return a deferred that gets the uid of the user owning the given
    system D-Bus name.
    ú/proc/%s/statusúUid:Nr   r   )	r:   r;   r   ÚopenÚ	readlinesÚ
startswithÚintÚsplitr   )r!   r$   r*   ÚprocÚvÚvaluesÚuids          r'   r   r   �   s›   è ø€ ñ
 Ü�n‰nÓˆÜ& y°#Ó6Ñ
6€CÜ	Ð #Ñ%Ó	&ð G¨$Ø!Ÿ^™^Ó-ÖF˜°·±¸fÕ1E’!ÐFˆÐF÷Gä
ˆf�Q‰i�o‰oÓ Ñ"Ó
#€CÜ�Õùò G÷Gð Güs4   ‚3B)µBÁBÁBÁ#BÁ%3B)ÂBÂB&Â"B)c              #   ór  K  — |st        j                  «       }t        | |«      –—}t        d|z  «      5 }|j	                  «       }|D �cg c]  }|j                  d«      sŒ|‘Œ }}|D �cg c]  }|j                  d«      sŒ|‘Œ }}ddd«       t        d|z  d«      5 }|j                  «       j                  d«      }	ddd«       t        d   j                  «       d	   «      }
t        d   j                  «       d	   «      }t        ||
|	f«       yc c}w c c}w # 1 sw Y   Œ˜xY w# 1 sw Y   ŒmxY w­w)
zzReturn a deferred that gets the pid, the uid of the user owning the
    given system D-Bus name and its command line.
    rD   rE   zGid:Nz/proc/%s/cmdlineÚrbzutf-8r   r   )r:   r;   r   rF   rG   rH   ÚreadÚdecoderI   rJ   r   )r!   r$   r*   rK   ÚlinesrL   Ú
uid_valuesÚ
gid_valuesÚcmdline_fileÚcmdlinerN   Úgids               r'   Úget_proc_info_from_dbus_namerY   ›   s*  è ø€ ñ
 Ü�n‰nÓˆÜ& y°#Ó6Ñ
6€CÜ	Ð #Ñ%Ó	&ð @¨$Ø—‘Ó ˆØ!&Ö?˜A¨!¯,©,°vÕ*>’aÐ?ˆ
Ð?Ø!&Ö?˜A¨!¯,©,°vÕ*>’aÐ?ˆ
Ð?÷@ô 
Ð  3Ñ&¨Ó	-ð 6°Ø×#Ñ#Ó%×,Ñ,¨WÓ5ˆ÷6ä
ˆj˜‰m×!Ñ!Ó# AÑ&Ó
'€CÜ
ˆj˜‰m×!Ñ!Ó# AÑ&Ó
'€CÜ�#�s˜C Ð)Õ*ùò @ùÚ?÷@ð @ú÷6ð 6üs_   ‚3D7µDÁ
DÁ!DÁ%DÁ+DÂDÂDÂD7Â D+Â?AD7Ä
DÄD(Ä$D7Ä+D4Ä0D7)i€Q NNr-   ) Ú__doc__Ú
__author__Ú__all__r:   Údeferr   r   r   Úerrorsr   r   r   r   r   r   r   r   r   r	   r   r
   ÚPK_ACTION_CHANGE_CONFIGr   r   r   r   r   r   r    r   r   rY   © r(   r'   ú<module>ra      sá   ðñ Oð" 5€
ð5€ó ç :Ñ :ß ;ð ,ð %ð ,ð %ð 0ð )ð 2ð 0à2Ð Ø:Ð Ø2Ð Ø6Ð Ø$HÐ !Ø<Ð Ø4Ð Ø,Ð Ø$€à€Ø$%Ð !ð JNØ&*óIð" CGØ%)óIó"ó6ð  ò
ó ð
ð ò+ó ñ+r(   