....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 195.3.193.33  /  Your IP : 216.73.216.125
Web Server : Apache
System : Linux server3 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User : web032 ( 1035)
PHP Version : 7.3.33
Disable Function : show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /usr/sbin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/sbin/dpkg-fsys-usrunmess
#!/usr/bin/perl
#
# dpkg-fsys-usrunmess - Undoes the merged-/usr-via-aliased-dirs mess
#
# Copyright © 2020-2021 Guillem Jover <guillem@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>

use strict;
use warnings;
use feature qw(state);

our ($PROGNAME) = $0 =~ m{(?:.*/)?([^/]*)};
our $PROGVERSION = '1.20.13';
our $ADMINDIR = '/var/lib/dpkg';

use POSIX;
use File::Find;
use Getopt::Long qw(:config posix_default bundling_values no_ignorecase);

eval q{
    pop @INC if $INC[-1] eq '.';
    use File::FcntlLock;
};
if ($@) {
    fatal('missing File::FcntlLock module; please install libfile-fcntllock-perl');
}

my $opt_noact = length $ENV{DPKG_USRUNMESS_NOACT} ? 1 : 0;
my $opt_prompt = 0;

my @options_spec = (
    'help|?' => sub { usage(); exit 0; },
    'version' => sub { version(); exit 0; },
    'dry-run|no-act|n' => \$opt_noact,
    'prompt|p' => \$opt_prompt,
);

{
    local $SIG{__WARN__} = sub { usageerr($_[0]) };
    GetOptions(@options_spec);
}

# Set a known umask.
umask 0022;

my @aliased_dirs;

#
# Scan all dirs under / and check whether any are aliased to /usr.
#

foreach my $path (glob '/*') {
    debug("checking symlink? $path");
    next unless -l $path;
    debug("checking merged-usr symlink? $path");
    my $symlink = readlink $path;
    next unless $symlink eq "usr$path" or $symlink eq "/usr$path";
    debug("merged-usr breakage, queueing $path");
    push @aliased_dirs, $path;
}

if (@aliased_dirs == 0) {
    print "System is fine, no aliased directories found, congrats!\n";
    exit 0;
}

#
# dpkg consistency checks
#

debug('checking dpkg database consistency');
system(qw(dpkg --audit)) == 0
    or fatal("cannot audit the dpkg database: $!");

debug('checking whether dpkg has been interrupted');
if (glob "$ADMINDIR/updates/*") {
    fatal('dpkg is in an inconsistent state, please fix that');
}

my $aliased_regex = '^(' . join('|', @aliased_dirs) . ')/';

#
# Get a list of all paths (including diversion) under the aliased dirs.
#

my @search_args;
my %aliased_pathnames;
foreach my $dir (@aliased_dirs) {
    push @search_args, "$dir/*";
}

# We also need to track /usr/lib/modules to then be able to compute its
# complement when looking for untracked kernel module files under aliased
# dirs.
my %usr_mod_pathnames;
push @search_args, '/usr/lib/modules/*';

open my $fh_paths, '-|', 'dpkg-query', '--search', @search_args
    or fatal("cannot execute dpkg-query --search: $!");
while (<$fh_paths>) {
    if (m/^diversion by [^ ]+ from: .*$/) {
        # Ignore.
    } elsif (m/^diversion by [^ ]+ to: (.*)$/) {
        if (-e $1) {
            add_pathname($1, 'diverted pathname');
        }
    } elsif (m/^.*: (.*)$/) {
        add_pathname($1, 'pathname');
    }
}
close $fh_paths;

#
# Get a list of all update-alternatives under the aliased dirs.
#

my @selections = qx(update-alternatives --get-selections);
foreach my $selection (@selections) {
    my $name = (split(' ', $selection))[0];
    my $slaves = 0;

    open my $fh_alts, '-|', 'update-alternatives', '--query', $name
        or fatal("cannot execute update-alternatives --query: $!");
    while (<$fh_alts>) {
        if (m/^\s*$/) {
            last;
        } elsif (m/^Link: (.*)$/) {
            add_pathname($1, 'alternative link');
        } elsif (m/^Slaves:\s*$/) {
            $slaves = 1;
        } elsif ($slaves and m/^\s\S+\s(\S+)$/) {
            add_pathname($1, 'alternative slave');
        } else {
            $slaves = 0;
        }
    }
    close $fh_alts;
}

#
# Unfortunately we need to special case untracked kernel module files,
# as these are required for system booting. To reduce potentially moving
# undesired non-kernel module files (such as apache, python or ruby ones),
# we only look for sub-dirs starting with a digit, which should match for
# both Linux and kFreeBSD modules, and also for the modprobe.conf filename.
#

find({
    no_chdir => 1,
    wanted => sub {
        my $path = $_;

        if (exists $aliased_pathnames{$path}) {
            # Ignore pathname already handled.
        } elsif (exists $usr_mod_pathnames{"/usr$path"}) {
            # Ignore pathname owned elsewhere.
        } elsif ($path eq '/lib/modules' or
                 $path eq '/lib/modules/modprobe.conf' or
                 $path =~ m{^/lib/modules/[0-9]}) {
            add_pathname($path, 'untracked modules');
        }
    },
}, '/lib/modules');


my $sroot = '/.usrunmess';
my @relabel;

#
# Create a shadow hierarchy under / for the new unmessed dir:
#

debug("creating shadow dir = $sroot");
mkdir $sroot
    or sysfatal("cannot create directory $sroot");
foreach my $dir (@aliased_dirs) {
    debug("creating shadow dir = $sroot$dir");
    mkdir "$sroot$dir"
        or sysfatal("cannot create directory $sroot$dir");
    chmod 0755, "$sroot$dir"
        or sysfatal("cannot chmod 0755 $sroot$dir");
    chown 0, 0, "$sroot$dir"
        or sysfatal("cannot chown 0 0 $sroot$dir");
    push @relabel, "$sroot$dir";
}

#
# Populate the split dirs with hardlinks or copies of the objects from
# their counter-parts in /usr.
#

foreach my $pathname (sort keys %aliased_pathnames) {
    my (@meta) = lstat $pathname
        or sysfatal("cannot lstat object $pathname for shadow hierarchy");

    if (-d _) {
        my $mode = $meta[2];
        my ($uid, $gid) = @meta[4, 5];
        my ($atime, $mtime, $ctime) = @meta[8, 9, 10];

        debug("creating shadow dir = $sroot$pathname");
        mkdir "$sroot$pathname"
            or sysfatal("cannot mkdir $sroot$pathname");
        chmod $mode, "$sroot$pathname"
            or sysfatal("cannot chmod $mode $sroot$pathname");
        chown $uid, $gid, "$sroot$pathname"
            or sysfatal("cannot chown $uid $gid $sroot$pathname");
        utime $atime, $mtime, "$sroot$pathname"
            or sysfatal("cannot utime $atime $mtime $sroot$pathname");
        push @relabel, "$sroot$pathname";
    } elsif (-f _) {
        debug("creating shadow file = $sroot$pathname");
        copy("/usr$pathname", "$sroot$pathname");
    } elsif (-l _) {
        my $target = readlink "/usr$pathname";

        debug("creating shadow symlink = $sroot$pathname");
        symlink $target, "$sroot$pathname"
            or sysfatal("cannot symlink $target to $sroot$pathname");
        push @relabel, "$sroot$pathname";
    } else {
        fatal("unhandled object type for '$pathname'");
    }
}

#
# Prompt at the point of no return, if the user requested it.
#

if ($opt_prompt) {
    print "Shadow hierarchy created at '$sroot', ready to proceed (y/N)? ";
    my $reply = <STDIN>;
    chomp $reply;

    if ($reply ne 'y' and $reply ne 'yes') {
        print "Aborting migration, shadow hierarchy left in place.\n";
        exit 0;
    }
}

#
# Mark all packages as half-configured so that we can force a mass
# reconfiguration, to trigger any code in maintainer scripts that might
# create files.
#
# XXX: We do this manually by editing the status file.
# XXX: We do this for packages that might not have maintscripts, or might
#      not involve affected directories.
#

debug('marking all dpkg packages as half-configured');
if (not $opt_noact) {
    open my $fh_lock, '>', "$ADMINDIR/lock"
        or sysfatal('cannot open dpkg database lock file');
    my $fs = File::FcntlLock->new(l_type => F_WRLCK);
    $fs->lock($fh_lock, F_SETLKW)
        or sysfatal('cannot get a write lock on dpkg database');

    my $file_db = "$ADMINDIR/status";
    my $file_dbnew = $file_db . '.new';

    open my $fh_dbnew, '>', $file_dbnew
        or sysfatal('cannot open new dpkg database');
    open my $fh_db, '<', $file_db
        or sysfatal('cannot open dpkg database');
    while (<$fh_db>) {
        if (m/^Status: /) {
            s/ installed$/ half-configured/;
        }
        print { $fh_dbnew } $_;
    }
    close $fh_db;
    $fh_dbnew->flush() or sysfatal('cannot flush new dpkg database');
    $fh_dbnew->sync() or sysfatal('cannot fsync new dpkg database');
    close $fh_dbnew or sysfatal('cannot close new dpkg database');

    rename $file_dbnew, $file_db
        or sysfatal('cannot rename new dpkg database');
}

#
# Replace things as quickly as possible:
#

foreach my $dir (@aliased_dirs) {
    debug("making dir backup = $dir.aliased");
    if (not $opt_noact) {
        rename $dir, "$dir.aliased"
            or sysfatal("cannot make backup directory $dir.aliased");
    }

    debug("renaming $sroot$dir to $dir");
    if (not $opt_noact) {
        rename "$sroot$dir", $dir
            or sysfatal("cannot install fixed directory $dir");
    }
}

mac_relabel();

#
# Cleanup backup directories.
#

foreach my $dir (@aliased_dirs) {
    debug("removing backup = $dir.aliased");
    if (not $opt_noact) {
        unlink "$dir.aliased"
            or sysfatal("cannot cleanup backup directory $dir.aliased");
    }
}

my %deferred_dirnames;

#
# Cleanup moved objects.
#

foreach my $pathname (sort keys %aliased_pathnames) {
    my (@meta) = lstat $pathname
        or sysfatal("cannot lstat object $pathname for cleanup");

    if (-d _) {
        # Skip directories as this might be shared by a proper path under the
        # aliased hierearchy. And so that we can remove them in reverse order.
        debug("deferring merged dir cleanup = /usr$pathname");
        $deferred_dirnames{"/usr$pathname"} = 1;
    } else {
        debug("cleaning up pathname = /usr$pathname");
        next if $opt_noact;
        unlink "/usr$pathname"
            or sysfatal("cannot unlink object /usr$pathname");
    }
}

#
# Cleanup deferred directories.
#

debug("cleaning up shadow deferred dir = $sroot");
my $arg_max = POSIX::sysconf(POSIX::_SC_ARG_MAX) // POSIX::_POSIX_ARG_MAX;
my @batch_dirs;
my $batch_size = 0;

foreach my $dir (keys %deferred_dirnames) {
    my $dir_size = length($dir) + 1;
    if ($batch_size + $dir_size < $arg_max) {
        $batch_size += length($dir) + 1;
        push @batch_dirs, $dir;

    } else {
        next;
    }
    next if length $batch_size == 0;

    open my $fh_dirs, '-|', 'dpkg-query', '--search', @batch_dirs
        or fatal("cannot execute dpkg-query --search: $!");
    while (<$fh_dirs>) {
        if (m/^.*: (.*)$/) {
            # If the directory is known by its aliased name, it should not be
            # cleaned up.
            if (exists $deferred_dirnames{$1}) {
                delete $deferred_dirnames{$1};
            }
        }
    }
    close $fh_dirs;

    @batch_dirs = ();
    $batch_size = 0;
}

my @dirs_linger;

if (not $opt_noact) {
    foreach my $dirname (reverse sort keys %deferred_dirnames) {
        next if rmdir $dirname;
        warning("cannot remove shadow directory $dirname: $!");

        push @dirs_linger, $dirname;
    }
}

if (not $opt_noact) {
    debug("cleaning up shadow root dir = $sroot");
    rmdir $sroot
        or warning("cannot remove shadow directory $sroot: $!");
}

#
# Re-configure all packages, so that postinst maintscripts are executed.
#

my $policypath = '/usr/sbin/dpkg-fsys-usrunmess-policy-rc.d';

debug('installing local policy-rc.d');
if (not $opt_noact) {
    open my $policyfh, '>', $policypath
        or sysfatal("cannot create $policypath");
    print { $policyfh } <<'POLICYRC';
#!/bin/sh
echo "$0: Denied action $2 for service $1"
exit 101
POLICYRC
    close $policyfh or fatal("cannot write $policypath");

    my @alt = (qw(/usr/sbin/policy-rc.d policy-rc.d), $policypath, qw(1000));
    system(qw(update-alternatives --install), @alt) == 0
        or fatal("cannot register $policypath");

    system(qw(update-alternatives --set policy-rc.d), $policypath) == 0
        or fatal("cannot select alternative $policypath");
}

debug('reconfiguring all packages');
if (not $opt_noact) {
    local $ENV{DEBIAN_FRONTEND} = 'noninteractive';
    system(qw(dpkg --configure --pending)) == 0
        or fatal("cannot reconfigure packages: $!");
}

debug('removing local policy-rc.d');
if (not $opt_noact) {
    system(qw(update-alternatives --remove policy-rc.d), $policypath) == 0
        or fatal("cannot unregister $policypath: $!");

    unlink $policypath
        or warning("cannot remove $policypath");

    # Restore the selections we saved initially.
    open my $altfh, '|-', qw(update-alternatives --set-selections)
        or fatal('cannot restore alternatives state');
    print { $altfh } $_ foreach @selections;
    close $altfh or fatal('cannot restore alternatives state');
}

print "\n";

if (@dirs_linger) {
    warning('lingering directories that could not be removed:');
    foreach my $dir (@dirs_linger) {
        warning("  $dir");
    }
}

print "Done, hierarchy unmessed, congrats!\n";
print "Rebooting now is very strongly advised.\n";

print "(Note: you might need to run 'hash -r' in your shell.)\n";

1;

##
## Functions
##

sub debug
{
    my $msg = shift;

    print { \*STDERR } "D: $msg\n";
}

sub warning
{
    my $msg = shift;

    warn "warning: $msg\n";
}

sub fatal
{
    my $msg = shift;

    die "error: $msg\n";
}

sub sysfatal
{
    my $msg = shift;

    fatal("$msg: $!");
}

sub copy
{
    my ($src, $dst) = @_;

    # Try to hardlink first.
    return if link $src, $dst;

    # If we are on different filesystems, try a copy.
    if ($! == POSIX::EXDEV) {
        # XXX: This will not preserve hardlinks, these would get restored
        # after the next package upgrade.
        system('cp', '-a', $src, $dst) == 0
            or fatal("cannot copy file $src to $dst: $?");
    } else {
        sysfatal("cannot link file $src to $dst");
    }
}

sub mac_relabel
{
    my $has_cmd = 0;
    foreach my $path (split /:/, $ENV{PATH}) {
        if (-x "$path/restorecon") {
            $has_cmd = 1;
            last;
        }
    }
    return unless $has_cmd;

    foreach my $pathname (@relabel) {
        system('restorecon', $pathname) == 0
            or fatal("cannot restore MAC context for $pathname: $?");
    }
}

sub add_pathname
{
    my ($pathname, $origin) = @_;

    if ($pathname =~ m{^/usr/lib/modules/}) {
        debug("tracking $origin = $pathname");
        $usr_mod_pathnames{$pathname} = 1;
    } elsif ($pathname =~ m/$aliased_regex/) {
        debug("adding $origin = $pathname");
        $aliased_pathnames{$pathname} = 1;
    }
}

sub version()
{
    printf "Debian %s version %s.\n", $PROGNAME, $PROGVERSION;
}

sub usage
{
    printf
'Usage: %s [<option>...]'
    . "\n\n" .
'Options:
  -p, --prompt      prompt before the point of no return.
  -n, --no-act      just check and create the new structure, no switch.
      --dry-run     ditto.
  -?, --help        show this help message.
      --version     show the version.'
    . "\n", $PROGNAME;
}

sub usageerr
{
    my $msg = shift;

    state $printforhelp = 'Use --help for program usage information.';

    $msg = sprintf $msg, @_ if @_;
    warn "$PROGNAME: error: $msg\n";
    warn "$printforhelp\n";
    exit 2;
}

Youez - 2016 - github.com/yon3zu
LinuXploit