Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/user/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/user/provider.pyc

ó
ÍÿŠTc@s¶ddlmZddlmZddlZddlZddlZdefd„ƒYZdefd„ƒYZ	defd	„ƒYZ
d
efd„ƒYZdefd
„ƒYZ
dS(iÿÿÿÿ(t
struct_passwd(tstruct_groupNtUserManagementErrorcBseZdZRS(s2Catch all error for problems with User Management.(t__name__t
__module__t__doc__(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyRstUserNotFoundErrorcBseZdZRS(s5Raised when a user couldn't be found by uid/username.(RRR(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyRstGroupNotFoundErrorcBseZdZRS(s7Raised when a group couldn't be found by gid/groupname.(RRR(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyRstUserProviderBasecBs>eZdZdd„Zd„Zd„Zd„Zd„ZRS(s(This is a base class for user Providers.cCs%|p	g|_d|_d|_dS(Nièi`ê(tlocked_userst_min_uidt_max_uid(tselfR	((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyt__init__s	cCsFg}tƒ}x0|jƒD]"}t|tƒs@t|ƒ}n|j|krUqng|jjdƒd D]}|jddƒp‡d
^ql}x#t	|ƒdkrµ|j
d
ƒq“Wt|ƒ\}}}}	|j|jk}
|j
i|jd6|d6|j
d6|
d6|d	6|d
6|	d6|jd6ƒ|j|jƒqW|S(sàReturns a list of all local users on the computer.

        Each user is represented as a dict with the keys: C{username},
        C{name}, C{uid}, C{enabled}, C{location}, C{work-phone} and
        C{home-phone}.  
        t,isutf-8treplacetusernametnametuidtenabledtlocations
work-phones
home-phonesprimary-gidN(tsett
get_user_datat
isinstanceRtpw_nametpw_gecostsplittdecodetNonetlentappendttupleR	tpw_uidtpw_gidtadd(Rtuserstfound_usernamestusertxt
gecos_dataRRt
work_phonet
home_phoneR((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyt	get_userss(	8cCsÖtg|jƒD]}|d^qƒ}g}tƒ}x—|jƒD]‰}t|tƒsit|ƒ}n|j|kr~qEn|j|jƒ}|ji|jd6|j	d6t
|ƒd6ƒ|j|jƒqEW|S(s–Returns a list of groups on the computer.

        Each group is represented as a dict with the keys: C{name},
        C{gid} and C{members}.
        RRtgidtmembers(RR*tget_group_dataRRtgr_nametintersectiontgr_memRtgr_gidtlistR"(RR&t
user_namestgroupstfound_groupnamestgrouptmember_names((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyt
get_groups9s)	cCsCx,|jƒD]}|d|kr
|dSq
Wtd|ƒ‚dS(s•Returns the UID for C{username}.

        @raises UserNotFoundError: Raised if C{username} doesn't match a
            user on the computer.
        RRsUID not found for user %s.N(R*R(RRtdata((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pytget_uidMscCsCx,|jƒD]}|d|kr
|dSq
Wtd|ƒ‚dS(sšReturns the GID for C{groupname}.

        @raises UserManagementError: Raised if C{groupname} doesn't
            match a group on the computer.
        RR+sGroup not found for group %s.N(R8R(Rt	groupnameR9((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pytget_gidXsN(	RRRRR
R*R8R:R<(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyRs			tUserProvidercBsbeZejZdddddddgZdddd	gZgd
dd„Zd
„Zd„Z	RS(RtpasswdRsprimary-gidtgecosthometshellRR+R,s/etc/passwds
/etc/groupcCs,tt|ƒj|ƒ||_||_dS(N(tsuperR=R
t_passwd_filet_group_file(RR	tpasswd_filet
group_file((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyR
ks	cCsg}t|jdƒ}tj|d|jdddtjƒ}d}xÆ|D]¾}|d7}|djd	ƒsL|djd
ƒrˆqLnyN|j|d|dt|dƒt|d
ƒ|d|d|dfƒWqLt	t
fk
r	tjd|j|fƒqLXqLW|j
ƒ|S(sÎ
        Parse passwd(5) formatted files and return tuples of user data in the
        form (username, password, uid, primary-group-id, gecos data, home
        directory, path to the user's shell)
        trt
fieldnamest	delimitert:tquotingiiRt+t-R>Rsprimary-gidR?R@RAs1passwd file %s is incorrectly formatted: line %d.(topenRCtcsvt
DictReadert
passwd_fieldst
QUOTE_NONEt
startswithRtintt
ValueErrort	TypeErrortloggingtwarntclose(Rt	user_dataREtreadertcurrent_linetrow((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyRqs&

 	
cCs
g}t|jdƒ}tj|d|jdddtjƒ}d}x´|D]¬}|d7}|djd	ƒsL|djd
ƒrˆqLny<|j|d|dt|dƒ|d
j	dƒfƒWqLt
tfk
r÷tj
d|j|fƒqLXqLW|jƒ|S(s²
        Parse group(5) formatted files and return tuples of group data in the
        form (groupname, group password, group id and a list of member
        usernames).
        RGRHRIRJRKiiRRLRMR>R+R,Rs0group file %s is incorrectly formatted: line %d.(RNRDRORPtgroup_fieldsRRRSRRTRtAttributeErrorRURWRXRY(Rt
group_dataRFR[R\R]((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyR-Žs$

!	
(
RRt
subprocesstPopentpopenRQR^R
RR-(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyR=cs		(tpwdRtgrpRRORaRWt	ExceptionRRRtobjectRR=(((s;/usr/lib/python2.7/dist-packages/landscape/user/provider.pyt<module>sO