ó
b=0Yc           @   sß  d  d l  Z  d  d l Te j d ƒ Z e j d ƒ Z e Z e Z d e	 f d „  ƒ  YZ
 e e
 ƒ Z e j Z e e e g e _ e e _ e j Z e e g e _ e e _ e j Z e g e _ e e _ e j Z e g e _ e e _ e j Z e g e _ d e _ e j Z e g e _ e e _ e j Z e e g e _ e e _ e g e j _ d e j _ e j Z e g e _ e e _ e j Z e e e g e _ e e _ e e e e g e j _ e e j _ e e e e e g e j _ e e j _ e e e e e e g e j _ e e j _ e e e e e g e j  _ e e j  _ e j! Z! e e g e! _ e e! _ e j" Z" e e g e" _ e e" _ d „  Z# d „  Z d d d	 „ Z d d d
 „ Z d d d „ Z d d „ Z  e$ d „ Z% d „  Z& d S(   iÿÿÿÿN(   t   *s	   libc.so.6s   liblve.so.0t   DIRENTRYc           B   s?   e  Z d  e f d e f d e f d e f d e d f g Z RS(   t   d_inot   d_offt   d_reclent   d_typet   d_namei   (   t   __name__t
   __module__t   ino_tt   off_tt   c_ushortt   c_ubytet   c_chart   _fields_(    (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyR   .   s
   				c         C   s”   t  j |  ƒ } t | ƒ } | s0 t d ƒ ‚ n  t | ƒ g  } x9 t r{ t | ƒ } | s_ Pn  | j } | j | j	 ƒ qC Wt | ƒ t
 | ƒ | S(   Ns   fdopendir error(   t   ost   dupt	   fdopendirt	   Exceptiont	   rewinddirt   Truet   readdirt   contentst   appendR   t   closedir(   t   fdt   fd2t   dirpt   dirlistt   entrypt   entry(    (    s,   /usr/lib/python2.7/site-packages/secureio.pyt   flistdir¨   s    
		

c         C   s8   |  d  k	 r4 y t j |  ƒ Wq4 t k
 r0 q4 Xn  d  S(   N(   t   NoneR   t   closet   OSError(   R   (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyt   closefdÄ   s
    c         C   sd   | d  k r d } n  t j |  | | | ƒ } | d k r= | S| d  k	 r` | d |  t t ƒ n  d  S(   Niÿÿÿÿi    s.   Error: failed to set permissions of directory (   R    t   liblvet   set_perm_dir_securet   FalseR   (   t   patht   permt   parent_pathR   t   logger(    (    s,   /usr/lib/python2.7/site-packages/secureio.pyR%   Ð   s    	c         C   sg   | d  k r d } n  t j |  | | | | ƒ } | d k r@ | S| d  k	 rc | d |  t t ƒ n  d  S(   Niÿÿÿÿi    s(   Error: failed to set owner of directory (   R    R$   t   set_owner_dir_secureR&   R   (   R'   t   uidt   gidR)   R   R*   (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyR+   ß   s    	c         C   sj   | d  k r d } n  t j |  | | | | | ƒ } | d k rC | S| d  k	 rf | d |  t t ƒ n  d  S(   Niÿÿÿÿi    s"   Error: failed to create directory (   R    R$   t   create_dir_secureR&   R   (   R'   R(   R,   R-   R)   R   R*   (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyR.   î   s    	c         C   sB   t  j |  | | | | ƒ } | r> | r> | d |  t t ƒ n  | S(   Ns"   Error: failed to create directory (   R$   t   makedirs_secureR&   R   (   R'   R(   R,   R-   R)   R*   t   res(    (    s,   /usr/lib/python2.7/site-packages/secureio.pyR/   ý   s    c         C   s   |  r t  j ƒ  St  j ƒ  Sd S(   s’   
	Set CAP_SYS_RESOURCE capability

	:param bool clear: Set on if it's true, set off otherwise
	:return: 0 for success, -1 otherwise
	:rtype: int
	N(   R$   t   disable_quota_capabilityt   enable_quota_capability(   t   clear(    (    s,   /usr/lib/python2.7/site-packages/secureio.pyt   set_capability  s    
c         C   s   t  j |  ƒ t ƒ  S(   sý   
	Change effective uid of current process and set CAP_SYS_RESOURCE capbality
	to prevent "Disk quota exceeded" error

	:param int euid: User ID to set it as current effective UID
	:return: 0 if capability was set successfuly, -1 otherwise
	:rtype: int
	(   R   t   setuidR4   (   R,   (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyt
   change_uid  s    	('   R   t   ctypest   cdllt   LoadLibraryt   libcR$   t   c_longR	   R
   t	   StructureR   t   POINTERt
   DIRENTRY_Pt   fchownt   c_intt   argtypest   restypet   fchmodR   t   c_void_pR   R   R    R   t   open_not_symlinkt   c_char_pR#   t	   check_dirt   isdirR%   R+   R.   R/   t   get_path_from_descriptort	   is_subdirR   R&   R4   R6   (    (    (    s,   /usr/lib/python2.7/site-packages/secureio.pyt   <module>#   st   
																									