ó
E®Uc           @   sÙ   d  d l  j Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z m Z m Z m Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t	   provision(   t   SamDB(   t   system_session(   t   _get_user_realm_domain(   t   Commandt   CommandErrort   SuperCommandt   Optiont   cmd_spn_listc           B   sS   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z d g Z	 d d d d „ Z RS(   s   List spns of a given user.s   %prog <user> [options]t	   sambaoptst   credoptst   versionoptst   userc         C   si  | j  ƒ  } | j | ƒ } t j | | j d ƒ ƒ } t | j d t ƒ  d | d | ƒ} t | ƒ \ }	 }
 } |  j	 j
 |	 d ƒ | j d d t j |	 ƒ d t j d	 d
 g ƒ } t | ƒ d k rU| d j d
 ƒ } t } t j } | d  k	 r7|  j	 j
 d | d j ƒ x@ | D] } |  j	 j
 d | ƒ qWqe|  j	 j
 d | d j ƒ n t d | ƒ ‚ d  S(   Nt   realmt   session_infot   credentialst   lps   
t
   expressions   samaccountname=%st   scopet   attrst   servicePrincipalNamei    s1   User %s has the following servicePrincipalName: 
s   	 %s
s#   User %s has no servicePrincipalNames   User %s not found(   t   get_loadparmt   get_credentialsR    t   provision_paths_from_lpt   getR   t   samdbR   R   t   outft   writet   searcht   ldbt   binary_encodet   SCOPE_SUBTREEt   lent   Falset   FLAG_MOD_ADDt   Nonet   dnR   (   t   selfR   R
   R	   R   R   t   credst   pathst   samt   cleaneduserR   t   domaint   rest   spnst   foundt   flagt   e(    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyt   run.   s.    			N(   t   __name__t
   __module__t   __doc__t   synopsist   optionst   SambaOptionst   CredentialsOptionst   VersionOptionst   takes_optiongroupst
   takes_argsR#   R0   (    (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyR   !   s   

	t   cmd_spn_addc           B   st   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z e	 d d d d d	 ƒg Z
 d
 d g Z e d d d d „ Z RS(   s   Create a new spn.s   %prog <name> <user> [options]R	   R
   R   s   --forcet   helps4   Force the addition of the spn even it exists alreadyt   actiont
   store_truet   nameR   c         C   s  | j  ƒ  } | j | ƒ } t j | | j d ƒ ƒ }	 t |	 j d t ƒ  d | d | ƒ}
 |
 j d d t	 j
 | ƒ d t	 j ƒ } t | ƒ d k r® | r® t d	 | ƒ ‚ n  t | ƒ \ } } } |
 j d d
 t	 j
 | ƒ d t	 j d d g ƒ } t | ƒ d k r| d j t	 j ƒ  } | d j d ƒ } g  } t } t	 j } | d  k	 rœx< | D]4 } t | ƒ | k ryt } n  | j t | ƒ ƒ qXWt	 j } n  | j | ƒ | d j | _ t	 j | | d ƒ | d <| sè|
 j | ƒ qt d | | f ƒ ‚ n t d | ƒ ‚ d  S(   NR   R   R   R   R   s   servicePrincipalName=%sR   i    s5   Service principal %s already affected to another users   samaccountname=%sR   R   s+   Service principal %s already affected to %ss   User %s not found(   R   R   R    R   R   R   R   R   R   R   R   R   R    R   R   R$   t   MessageR!   R"   R#   t   strt   Truet   appendt   FLAG_MOD_REPLACEt   MessageElementt   modify(   R%   R?   R   t   forceR
   R	   R   R   R&   R'   R(   R+   R)   R   R*   t   msgR,   t   tabR-   R.   R/   (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyR0   \   sJ    				N(   R1   R2   R3   R4   R5   R6   R7   R8   R9   R   t   takes_optionsR:   R!   R#   R0   (    (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyR;   L   s   

	t   cmd_spn_deletec           B   sY   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z d d g Z	 d d d d d „ Z RS(	   s   Delete a spn.s   %prog <name> [user] [options]R	   R
   R   R?   s   user?c         C   sE  | j  ƒ  } | j | ƒ } t j | | j d ƒ ƒ } t | j d t ƒ  d | d | ƒ}	 |	 j d d t	 j
 | ƒ d t	 j d d	 d
 g ƒ }
 t |
 ƒ d k r1d  } | d  k	 r%t | ƒ \ } } } x3 |
 D]+ } t | d
 ƒ j ƒ  | k rÎ | } qÎ qÎ W| d  k rŠt d | | f ƒ ‚ qŠne t |
 ƒ d k r€d } x' |
 D] } d | t | j ƒ f } qDWt d | | f ƒ ‚ n
 |
 d } t	 j ƒ  } | j d	 ƒ } g  } | d  k	 rüx6 | D]. } t | ƒ | k r¾| j t | ƒ ƒ q¾q¾Wt	 j } n  | j | _ t	 j | | d	 ƒ | d	 <|	 j | ƒ n t d | ƒ ‚ d  S(   NR   R   R   R   R   s   servicePrincipalName=%sR   R   R   t   samAccountNamei    s"   Unable to find user %s with spn %si   t    s   %s
%ssd   More than one user has the spn %s and no specific user was specified, list of users with this spn:%ss!   Service principal %s not affected(   R   R   R    R   R   R   R   R   R   R   R   R   R    R#   R   RA   t   lowerR   R$   R@   RC   RD   RE   RF   (   R%   R?   R   R
   R	   R   R   R&   R'   R(   R+   t   resultR)   R   R*   t   elemt   listUsert   rRH   R,   RI   R/   R.   (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyR0   •   sN    		
N(   R1   R2   R3   R4   R5   R6   R7   R8   R9   R:   R#   R0   (    (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyRK   ˆ   s   

	t   cmd_spnc           B   s;   e  Z d  Z i  Z e ƒ  e d <e ƒ  e d <e ƒ  e d <RS(   s(   Service Principal Name (SPN) management.t   addt   listt   delete(   R1   R2   R3   t   subcommandsR;   R   RK   (    (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyRS   Æ   s
   (   t   samba.getoptt   getoptR5   R   t   sambaR    t   samba.samdbR   t
   samba.authR   t   samba.netcmd.commonR   t   samba.netcmdR   R   R   R   R   R;   RK   RS   (    (    (    s4   /usr/lib/python2.7/dist-packages/samba/netcmd/spn.pyt   <module>   s   "+<>