§ Rl¾j»ãóÆ—dZddlZddlZddlZddlmZddlmZeje ¦«Z dZ ddl Z n #e $rdZ YnwxYwd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„ZdS)uË Thin Python wrapper around the _lvdmap C extension (backed by liblve). Public interface is unchanged — callers (lveapi.py, lvectllib.py) continue to import and use these functions exactly as before. éNé)Údomain_lve_sentry_extra)ÚLvdErrorz/etc/container/lvd_idscó2—t€td¦«‚dS)Nz$_lvdmap C extension is not installed)Ú_lvdmapr©óúS/opt/cloudlinux/venv/lib64/python3.11/site-packages/websiteisolation/id_registry.pyÚ_require_lvdmapr s€Ý€ÝÐ=Ñ>Ô>Ð>ð€r có— tj|¦«j}n#t$rYdSwxYwtj tt|¦«¦«}tj  |¦«sdS|S)zmReturn the registry file path for *username*, or None if the user does not exist or has no registry file.N) ÚpwdÚgetpwnamÚpw_uidÚKeyErrorÚosÚpathÚjoinÚ LVD_IDS_DIRÚstrÚexists)ÚusernameÚuidrs r Úregistry_path_by_usernamer"sx€ðÝŒl˜8Ñ$Ô$Ô+ˆˆøÝ ððð؈tˆtðøøøå Œ7�<Š<� ¥S¨¡X¤XÑ .Ô .€DÝ Œ7�>Š>˜$Ñ Ô ð؈tØ €Ks ‚œ *©*cóÒ—tj¦«dkrtd¦«‚t¦«t j||¦«}t  d|||¦«|S)zzAssign a domain ID for a docroot. Returns existing ID if already assigned, otherwise allocates the next sequential ID.rú"domain ID assignment requires rootz0assigned domain_id %d to docroot '%s' for uid %d)rÚgeteuidrr rÚassignÚlogÚinfo)rÚdocrootÚ domain_ids r Úassign_domain_idr"/sg€õ „z�|„|�qÒÐÝÐ;Ñ<Ô<Ð<ÝÑÔÐÝ”˜s GÑ,Ô,€I݇H‚HÐ ?Ø ˜ ñ&ô&ð&à Ðr cóR—t€dStj||¦«}|dkr|ndS)z;Look up domain ID by docroot. Returns None if not assigned.Nr)rÚlookup)rr Úrs r Ú get_domain_idr&;s/€å€ØˆtÝŒ�s˜GÑ$Ô$€AØ�Q’�ˆ1ˆ1˜DÐ r có<—t€iStj|¦«S)z/Return dict of docroot -> domain_id for a user.)rÚget_all_entries)rs r r(r(Cs€å€Øˆ Ý Ô " 3Ñ 'Ô 'Ð'r cóR—t€t¦«Stj¦«S)z@Return the set of every assigned domain LVE ID across all users.)rÚsetÚget_all_domain_idsrr r r+r+Js€å€Ý‰uŒuˆ Ý Ô %Ñ 'Ô 'Ð'r có:—t€dStj¦«S)zÒReturn the minimum domain LVE ID. Delegates to the C library which reads UID_MAX from /etc/login.defs and returns max(UID_MAX, 60000). Falls back to 60000 if the C extension is not available. Ni`ê)rÚmin_idrr r r-r-Qs€õ€ØˆuÝ Œ>Ñ Ô Ðr có^—tj¦«dkrtd¦«‚t¦«t j||¦«}|€-t  d||td¦«¬¦«dSt j ||¦«}t   d|||||¦«|S)zÅMove a domain mapping from *old_docroot* to *new_docroot*. Uses remove + assign via _lvdmap; the domain_id will be newly allocated (the C API does not support specifying a target ID). rz$domain ID reassignment requires rootNuUreassign_docroot: old_docroot '%s' not in registry for uid %d — nothing to reassignzreassign-missing-entry)Úextraz?reassigned docroot from '%s' (id=%d) to '%s' (id=%d) for uid %d) rrrr rÚremoverÚerrorrrr)rÚ old_docrootÚ new_docrootÚold_idÚnew_ids r Úreassign_docrootr6]s€õ  „z�|„|�qÒÐÝÐ=Ñ>Ô>Ð>ÝÑÔÐå Œ^˜C Ñ -Ô -€FØ €~õ � Š ð7Ø8CÀSÝ/Ð0HÑIÔIð ñ Kô Kð Kðˆtå Œ^˜C Ñ -Ô -€F݇H‚HðØ&¨° ¸VÀSñJôJðJà €Mr cóÖ—tj¦«dkrtd¦«‚t¦«t j||¦«}|�t  d|||¦«|S)z?Remove a docroot from the registry. Returns the old ID or None.rúdomain ID removal requires rootNz,removed domain_id %d for docroot '%s' uid %d)rrrr rr0rr)rr r4s r Úremove_domain_idr9wsj€å „z�|„|�qÒÐÝÐ8Ñ9Ô9Ð9ÝÑÔÐÝ Œ^˜C Ñ )Ô )€FØ ÐÝ �ŠÐ?ؘ #ñ 'ô 'ð 'à €Mr cóì—tj¦«dkrtd¦«‚t¦«t j|¦«}|r)t  d|t|¦«¦«|S)z@Remove all domain IDs for a user. Returns list of (docroot, id).rr8z.removed all domain IDs for uid %d (%d entries)) rrrr rÚ remove_allrrÚlen)rÚremoveds r Úremove_all_entriesr>ƒso€å „z�|„|�qÒÐÝÐ8Ñ9Ô9Ð9ÝÑÔÐÝÔ  Ñ%Ô%€GØð$Ý �ŠÐAØ•c˜'‘l”lñ $ô $ð $à €Nr cóX—tj¦«dkrtd¦«‚tjtdd¬¦« tjt¦«}|jdzdkrtjtd¦«n#t$rYnwxYwtj   tt|¦«¦«}tj   |¦«sCtj |tjtjzd¦«}tj|¦«dSdS) a™Mark *uid* as domain-isolated by touching its per-user file. The file acts as a marker so that ``find_all_lve_ids_with_config()`` (which lists ``LVD_IDS_DIR``) can detect the user before any domains are assigned. The C library's ``lvd_map_assign()`` will later atomically replace this empty file with a proper hash-table via rename(2), so the marker never interferes with real data. rriÉT)ÚmodeÚexist_okiÿi€N)rrrÚmakedirsrÚstatÚst_modeÚchmodÚOSErrorrrrrÚopenÚO_CREATÚO_WRONLYÚclose)rÚstÚmarkerÚfds r Úcreate_empty_registryrN�sü€õ „z�|„|�qÒÐÝÐ;Ñ<Ô<Ð<Ý„K•  %°$Ð7Ñ7Ô7Ð7ð Ý ŒW•[Ñ !Ô !ˆØ Œ:˜Ñ  Ò &Ð &Ý ŒH•[ %Ñ (Ô (Ð (øøÝ ð ð ð Ø ˆð øøøå ŒW�\Š\�+¥s¨3¡x¤xÑ 0Ô 0€FÝ Œ7�>Š>˜&Ñ !Ô !ðÝ ŒW�V�RœZ­"¬+Ñ5°uÑ =Ô =ˆÝ Œ�‰ Œ ˆ ˆ ˆ ððsÁAB BÂB)Ú__doc__r ÚloggingrÚrÚ exceptionsrÚ getLoggerÚ__name__rrrÚ ImportErrorr rr"r&r(r+r-r6r9r>rNrr r úrVsJðð ðð  € € € Ø€€€Ø € € € à%Ð%Ð%Ð%Ð%Ð%Ø Ð Ð Ð Ð Ð à€gÔ˜Ñ!Ô!€à&€ ðØ€N€N€N€NøØðððØ€G€G€Gðøøøð?ð?ð?ð ð ð ð ð ð ð!ð!ð!ð(ð(ð(ð(ð(ð(ð ð ð ðððð4 ð ð ð ð ð ðððððs ®3³=¼=