001-ipkg.patch 423 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738
  1. diff -Nur busybox-1.26.0.orig/archival/ipkg.c busybox-1.26.0/archival/ipkg.c
  2. --- busybox-1.26.0.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ busybox-1.26.0/archival/ipkg.c 2016-12-22 17:08:30.972837164 +0100
  4. @@ -0,0 +1,39 @@
  5. +/* ipkg.c - the itsy package management system
  6. +
  7. + Florina Boor
  8. +
  9. + Copyright (C) 2003 kernel concepts
  10. +
  11. + This program is free software; you can redistribute it and/or
  12. + modify it under the terms of the GNU General Public License as
  13. + published by the Free Software Foundation; either version 2, or (at
  14. + your option) any later version.
  15. +
  16. + This program is distributed in the hope that it will be useful, but
  17. + WITHOUT ANY WARRANTY; without even the implied warranty of
  18. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. + General Public License for more details.
  20. +
  21. + ipkg command line frontend using libipkg
  22. +
  23. +*/
  24. +
  25. +//config:config IPKG
  26. +//config: bool "ipkg"
  27. +//config: default n
  28. +//config: help
  29. +//config: ipkg is a tool to install, build, remove and manage
  30. +//config: packages.
  31. +//config:
  32. +
  33. +//applet:IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  34. +//kbuild:lib-$(CONFIG_IPKG) += ipkg.o
  35. +
  36. +#include "libbb.h"
  37. +#include "libipkg/libipkg.h"
  38. +
  39. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  40. +int ipkg_main(int argc, char **argv)
  41. +{
  42. + return ipkg_op(argc, argv);
  43. +}
  44. diff -Nur busybox-1.26.0.orig/archival/libarchive/Kbuild.src busybox-1.26.0/archival/libarchive/Kbuild.src
  45. --- busybox-1.26.0.orig/archival/libarchive/Kbuild.src 2016-12-12 08:46:14.000000000 +0100
  46. +++ busybox-1.26.0/archival/libarchive/Kbuild.src 2016-12-22 17:08:30.972837164 +0100
  47. @@ -25,6 +25,8 @@
  48. \
  49. data_align.o \
  50. find_list_entry.o \
  51. + get_header_tar.o \
  52. + get_header_tar_gz.o \
  53. init_handle.o
  54. DPKG_FILES:= \
  55. @@ -32,8 +34,6 @@
  56. filter_accept_list_reassign.o \
  57. unsafe_prefix.o \
  58. get_header_ar.o \
  59. - get_header_tar.o \
  60. - get_header_tar_gz.o \
  61. get_header_tar_bz2.o \
  62. get_header_tar_lzma.o \
  63. get_header_tar_xz.o \
  64. diff -Nur busybox-1.26.0.orig/archival/libipkg/args.c busybox-1.26.0/archival/libipkg/args.c
  65. --- busybox-1.26.0.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  66. +++ busybox-1.26.0/archival/libipkg/args.c 2016-12-22 17:08:30.972837164 +0100
  67. @@ -0,0 +1,242 @@
  68. +/* args.c - parse command-line args
  69. +
  70. + Carl D. Worth
  71. +
  72. + Copyright 2001 University of Southern California
  73. +
  74. + This program is free software; you can redistribute it and/or modify
  75. + it under the terms of the GNU General Public License as published by
  76. + the Free Software Foundation; either version 2, or (at your option)
  77. + any later version.
  78. +
  79. + This program is distributed in the hope that it will be useful,
  80. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  81. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  82. + GNU General Public License for more details.
  83. + */
  84. +
  85. +#include <getopt.h>
  86. +#include <stdlib.h>
  87. +#include <string.h>
  88. +#include <unistd.h>
  89. +
  90. +#include "ipkg.h"
  91. +#include "ipkg_message.h"
  92. +
  93. +#include "args.h"
  94. +#include "sprintf_alloc.h"
  95. +
  96. +#include "libbb.h"
  97. +
  98. +
  99. +static void print_version(void);
  100. +
  101. +enum long_args_opt
  102. +{
  103. + ARGS_OPT_FORCE_DEFAULTS = 129,
  104. + ARGS_OPT_FORCE_DEPENDS,
  105. + ARGS_OPT_FORCE_OVERWRITE,
  106. + ARGS_OPT_FORCE_DOWNGRADE,
  107. + ARGS_OPT_FORCE_REINSTALL,
  108. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  109. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  110. + ARGS_OPT_FORCE_SPACE,
  111. + ARGS_OPT_NOACTION,
  112. + ARGS_OPT_NODEPS,
  113. + ARGS_OPT_VERBOSE_WGET,
  114. + ARGS_OPT_VERBOSITY,
  115. + ARGS_OPT_MULTIPLE_PROVIDERS
  116. +};
  117. +
  118. +int args_init(args_t *args)
  119. +{
  120. + const char *conf_file_dir;
  121. +
  122. + memset(args, 0, sizeof(args_t));
  123. +
  124. + args->dest = ARGS_DEFAULT_DEST;
  125. +
  126. + conf_file_dir = getenv("IPKG_CONF_DIR");
  127. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  128. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  129. + }
  130. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  131. + ARGS_DEFAULT_CONF_FILE_NAME);
  132. +
  133. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  134. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  135. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  136. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  137. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  138. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  139. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  140. + args->noaction = ARGS_DEFAULT_NOACTION;
  141. + args->nodeps = ARGS_DEFAULT_NODEPS;
  142. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  143. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  144. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  145. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  146. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  147. + args->multiple_providers = 0;
  148. + args->nocheckfordirorfile = 0;
  149. + args->noreadfeedsfile = 0;
  150. +
  151. + return 1;
  152. +}
  153. +
  154. +void args_deinit(args_t *args)
  155. +{
  156. + free(args->conf_file);
  157. + args->conf_file = NULL;
  158. +}
  159. +
  160. +int args_parse(args_t *args, int argc, char *argv[])
  161. +{
  162. + int c;
  163. + int option_index = 0;
  164. + int parse_err = 0;
  165. + static struct option long_options[] = {
  166. + {"query-all", 0, 0, 'A'},
  167. + {"conf-file", 1, 0, 'f'},
  168. + {"conf", 1, 0, 'f'},
  169. + {"dest", 1, 0, 'd'},
  170. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  171. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  172. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  173. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  174. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  175. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  176. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  177. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  178. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  179. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  180. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  181. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  182. + {"recursive", 0, 0,
  183. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  184. + {"force-removal-of-dependent-packages", 0, 0,
  185. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  186. + {"force_removal_of_dependent_packages", 0, 0,
  187. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  188. + {"force-removal-of-essential-packages", 0, 0,
  189. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  190. + {"force_removal_of_essential_packages", 0, 0,
  191. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  192. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  193. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  194. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  195. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  196. + {"offline", 1, 0, 'o'},
  197. + {"offline-root", 1, 0, 'o'},
  198. + {"test", 0, 0, ARGS_OPT_NOACTION},
  199. + {"tmp-dir", 1, 0, 't'},
  200. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  201. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  202. + {"verbosity", 2, 0, 'V'},
  203. + {"version", 0, 0, 'v'},
  204. + {0, 0, 0, 0}
  205. + };
  206. +
  207. + while (1) {
  208. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  209. + if (c == -1)
  210. + break;
  211. +
  212. + switch (c) {
  213. + case 'A':
  214. + args->query_all = 1;
  215. + break;
  216. + case 'd':
  217. + args->dest = optarg;
  218. + break;
  219. + case 'f':
  220. + free(args->conf_file);
  221. + args->conf_file = strdup(optarg);
  222. + break;
  223. + case 'o':
  224. + args->offline_root = optarg;
  225. + break;
  226. + case 'n':
  227. + args->noaction = 1;
  228. + break;
  229. + case 't':
  230. + args->tmp_dir = strdup(optarg);
  231. + break;
  232. + case 'v':
  233. + print_version();
  234. + exit(0);
  235. + case 'V':
  236. + case ARGS_OPT_VERBOSITY:
  237. + if (optarg)
  238. + args->verbosity = atoi(optarg);
  239. + else
  240. + args->verbosity += 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_DEFAULTS:
  243. + args->force_defaults = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_DEPENDS:
  246. + args->force_depends = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_OVERWRITE:
  249. + args->force_overwrite = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_DOWNGRADE:
  252. + args->force_downgrade = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REINSTALL:
  255. + args->force_reinstall = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  258. + args->force_removal_of_essential_packages = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  261. + args->force_removal_of_dependent_packages = 1;
  262. + break;
  263. + case ARGS_OPT_FORCE_SPACE:
  264. + args->force_space = 1;
  265. + break;
  266. + case ARGS_OPT_VERBOSE_WGET:
  267. + args->verbose_wget = 1;
  268. + break;
  269. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  270. + args->multiple_providers = 1;
  271. + break;
  272. + case ARGS_OPT_NODEPS:
  273. + args->nodeps = 1;
  274. + break;
  275. + case ARGS_OPT_NOACTION:
  276. + args->noaction = 1;
  277. + break;
  278. + case ':':
  279. + parse_err++;
  280. + break;
  281. + case '?':
  282. + parse_err++;
  283. + break;
  284. + default:
  285. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  286. + }
  287. + }
  288. +
  289. + if (parse_err) {
  290. + return -parse_err;
  291. + } else {
  292. + return optind;
  293. + }
  294. +}
  295. +
  296. +void args_usage(const char *complaint)
  297. +{
  298. + if (complaint) {
  299. + bb_error_msg("%s\n", complaint);
  300. + }
  301. + print_version();
  302. + bb_show_usage();
  303. + exit(1);
  304. +}
  305. +
  306. +static void print_version(void)
  307. +{
  308. + bb_error_msg("version %s\n", IPKG_VERSION);
  309. +}
  310. diff -Nur busybox-1.26.0.orig/archival/libipkg/args.h busybox-1.26.0/archival/libipkg/args.h
  311. --- busybox-1.26.0.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  312. +++ busybox-1.26.0/archival/libipkg/args.h 2016-12-22 17:08:30.976839427 +0100
  313. @@ -0,0 +1,72 @@
  314. +/* args.h - parse command-line args
  315. +
  316. + Carl D. Worth
  317. +
  318. + Copyright 2001 University of Southern California
  319. +
  320. + This program is free software; you can redistribute it and/or modify
  321. + it under the terms of the GNU General Public License as published by
  322. + the Free Software Foundation; either version 2, or (at your option)
  323. + any later version.
  324. +
  325. + This program is distributed in the hope that it will be useful,
  326. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  327. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  328. + GNU General Public License for more details.
  329. +*/
  330. +
  331. +#ifndef ARGS_H
  332. +#define ARGS_H
  333. +
  334. +struct args
  335. +{
  336. + char *conf_file;
  337. + char *dest;
  338. + char *tmp_dir;
  339. + int force_defaults;
  340. + int force_depends;
  341. + int force_overwrite;
  342. + int force_downgrade;
  343. + int force_reinstall;
  344. + int force_removal_of_essential_packages;
  345. + int force_removal_of_dependent_packages;
  346. + int force_space;
  347. + int noaction;
  348. + int nodeps;
  349. + int multiple_providers;
  350. + int query_all;
  351. + int verbose_wget;
  352. + int verbosity;
  353. + int nocheckfordirorfile;
  354. + int noreadfeedsfile;
  355. + char *offline_root;
  356. + char *offline_root_pre_script_cmd;
  357. + char *offline_root_post_script_cmd;
  358. +};
  359. +typedef struct args args_t;
  360. +
  361. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  362. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  363. +#define ARGS_DEFAULT_DEST NULL
  364. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  365. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  366. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  367. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  368. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  369. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  370. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  371. +#define ARGS_DEFAULT_FORCE_SPACE 0
  372. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  373. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  374. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  375. +#define ARGS_DEFAULT_NOACTION 0
  376. +#define ARGS_DEFAULT_NODEPS 0
  377. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  378. +#define ARGS_DEFAULT_VERBOSITY 1
  379. +
  380. +int args_init(args_t *args);
  381. +void args_deinit(args_t *args);
  382. +int args_parse(args_t *args, int argc, char *argv[]);
  383. +void args_usage(const char *complaint);
  384. +
  385. +#endif
  386. diff -Nur busybox-1.26.0.orig/archival/libipkg/conffile.c busybox-1.26.0/archival/libipkg/conffile.c
  387. --- busybox-1.26.0.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  388. +++ busybox-1.26.0/archival/libipkg/conffile.c 2016-12-22 17:08:30.976839427 +0100
  389. @@ -0,0 +1,65 @@
  390. +/* conffile.c - the itsy package management system
  391. +
  392. + Carl D. Worth
  393. +
  394. + Copyright (C) 2001 University of Southern California
  395. +
  396. + This program is free software; you can redistribute it and/or
  397. + modify it under the terms of the GNU General Public License as
  398. + published by the Free Software Foundation; either version 2, or (at
  399. + your option) any later version.
  400. +
  401. + This program is distributed in the hope that it will be useful, but
  402. + WITHOUT ANY WARRANTY; without even the implied warranty of
  403. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  404. + General Public License for more details.
  405. +*/
  406. +
  407. +#include <string.h>
  408. +#include <stdlib.h>
  409. +
  410. +#include "libbb.h"
  411. +#include "ipkg.h"
  412. +#include "ipkg_message.h"
  413. +
  414. +#include "conffile.h"
  415. +#include "file_util.h"
  416. +#include "sprintf_alloc.h"
  417. +
  418. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  419. +{
  420. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  421. +}
  422. +
  423. +void conffile_deinit(conffile_t *conffile)
  424. +{
  425. + nv_pair_deinit(conffile);
  426. +}
  427. +
  428. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  429. +{
  430. + uint8_t *md5sum;
  431. + char *filename = conffile->name;
  432. + char *root_filename;
  433. + int ret;
  434. +
  435. + if (conffile->value == NULL) {
  436. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  437. + return 1;
  438. + }
  439. +
  440. + root_filename = root_filename_alloc(conf, filename);
  441. +
  442. + md5sum = file_md5sum_alloc(root_filename);
  443. +
  444. + ret = strcmp((char *)md5sum, conffile->value);
  445. + if (ret) {
  446. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  447. + conffile->name, md5sum, conffile->value);
  448. + }
  449. +
  450. + free(root_filename);
  451. + free(md5sum);
  452. +
  453. + return ret;
  454. +}
  455. diff -Nur busybox-1.26.0.orig/archival/libipkg/conffile.h busybox-1.26.0/archival/libipkg/conffile.h
  456. --- busybox-1.26.0.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  457. +++ busybox-1.26.0/archival/libipkg/conffile.h 2016-12-22 17:08:30.976839427 +0100
  458. @@ -0,0 +1,30 @@
  459. +/* conffile.h - the itsy package management system
  460. +
  461. + Carl D. Worth
  462. +
  463. + Copyright (C) 2001 University of Southern California
  464. +
  465. + This program is free software; you can redistribute it and/or
  466. + modify it under the terms of the GNU General Public License as
  467. + published by the Free Software Foundation; either version 2, or (at
  468. + your option) any later version.
  469. +
  470. + This program is distributed in the hope that it will be useful, but
  471. + WITHOUT ANY WARRANTY; without even the implied warranty of
  472. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  473. + General Public License for more details.
  474. +*/
  475. +
  476. +#ifndef CONFFILE_H
  477. +#define CONFFILE_H
  478. +
  479. +#include "nv_pair.h"
  480. +
  481. +typedef struct nv_pair conffile_t;
  482. +
  483. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  484. +void conffile_deinit(conffile_t *conffile);
  485. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  486. +
  487. +#endif
  488. +
  489. diff -Nur busybox-1.26.0.orig/archival/libipkg/conffile_list.c busybox-1.26.0/archival/libipkg/conffile_list.c
  490. --- busybox-1.26.0.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  491. +++ busybox-1.26.0/archival/libipkg/conffile_list.c 2016-12-22 17:08:30.984843942 +0100
  492. @@ -0,0 +1,47 @@
  493. +/* conffile_list.c - the itsy package management system
  494. +
  495. + Carl D. Worth
  496. +
  497. + Copyright (C) 2001 University of Southern California
  498. +
  499. + This program is free software; you can redistribute it and/or
  500. + modify it under the terms of the GNU General Public License as
  501. + published by the Free Software Foundation; either version 2, or (at
  502. + your option) any later version.
  503. +
  504. + This program is distributed in the hope that it will be useful, but
  505. + WITHOUT ANY WARRANTY; without even the implied warranty of
  506. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  507. + General Public License for more details.
  508. +*/
  509. +
  510. +#include "ipkg.h"
  511. +
  512. +#include "conffile_list.h"
  513. +
  514. +int conffile_list_init(conffile_list_t *list)
  515. +{
  516. + return nv_pair_list_init(list);
  517. +}
  518. +
  519. +void conffile_list_deinit(conffile_list_t *list)
  520. +{
  521. + nv_pair_list_deinit(list);
  522. +}
  523. +
  524. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  525. + const char *md5sum)
  526. +{
  527. + return nv_pair_list_append(list, file_name, md5sum);
  528. +}
  529. +
  530. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  531. +{
  532. + return nv_pair_list_push(list, data);
  533. +}
  534. +
  535. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  536. +{
  537. + return nv_pair_list_pop(list);
  538. +}
  539. +
  540. diff -Nur busybox-1.26.0.orig/archival/libipkg/conffile_list.h busybox-1.26.0/archival/libipkg/conffile_list.h
  541. --- busybox-1.26.0.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  542. +++ busybox-1.26.0/archival/libipkg/conffile_list.h 2016-12-22 17:08:30.984843942 +0100
  543. @@ -0,0 +1,36 @@
  544. +/* conffile_list.h - the itsy package management system
  545. +
  546. + Carl D. Worth
  547. +
  548. + Copyright (C) 2001 University of Southern California
  549. +
  550. + This program is free software; you can redistribute it and/or
  551. + modify it under the terms of the GNU General Public License as
  552. + published by the Free Software Foundation; either version 2, or (at
  553. + your option) any later version.
  554. +
  555. + This program is distributed in the hope that it will be useful, but
  556. + WITHOUT ANY WARRANTY; without even the implied warranty of
  557. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  558. + General Public License for more details.
  559. +*/
  560. +
  561. +#ifndef CONFFILE_LIST_H
  562. +#define CONFFILE_LIST_H
  563. +
  564. +#include "conffile.h"
  565. +#include "nv_pair_list.h"
  566. +
  567. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  568. +typedef struct nv_pair_list conffile_list_t;
  569. +
  570. +int conffile_list_init(conffile_list_t *list);
  571. +void conffile_list_deinit(conffile_list_t *list);
  572. +
  573. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  574. + const char *root_dir);
  575. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  576. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  577. +
  578. +#endif
  579. +
  580. diff -Nur busybox-1.26.0.orig/archival/libipkg/file_util.c busybox-1.26.0/archival/libipkg/file_util.c
  581. --- busybox-1.26.0.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  582. +++ busybox-1.26.0/archival/libipkg/file_util.c 2016-12-22 17:08:30.984843942 +0100
  583. @@ -0,0 +1,186 @@
  584. +/* file_util.c - convenience routines for common stat operations
  585. +
  586. + Carl D. Worth
  587. +
  588. + Copyright (C) 2001 University of Southern California
  589. +
  590. + This program is free software; you can redistribute it and/or
  591. + modify it under the terms of the GNU General Public License as
  592. + published by the Free Software Foundation; either version 2, or (at
  593. + your option) any later version.
  594. +
  595. + This program is distributed in the hope that it will be useful, but
  596. + WITHOUT ANY WARRANTY; without even the implied warranty of
  597. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  598. + General Public License for more details.
  599. +*/
  600. +
  601. +#include "ipkg.h"
  602. +#include <sys/types.h>
  603. +#include <sys/stat.h>
  604. +
  605. +#include "sprintf_alloc.h"
  606. +#include "file_util.h"
  607. +#include "libbb.h"
  608. +#undef strlen
  609. +
  610. +int file_exists(const char *file_name)
  611. +{
  612. + int err;
  613. + struct stat stat_buf;
  614. +
  615. + err = stat(file_name, &stat_buf);
  616. + if (err == 0) {
  617. + return 1;
  618. + } else {
  619. + return 0;
  620. + }
  621. +}
  622. +
  623. +int file_is_dir(const char *file_name)
  624. +{
  625. + int err;
  626. + struct stat stat_buf;
  627. +
  628. + err = stat(file_name, &stat_buf);
  629. + if (err) {
  630. + return 0;
  631. + }
  632. +
  633. + return S_ISDIR(stat_buf.st_mode);
  634. +}
  635. +
  636. +/* read a single line from a file, stopping at a newline or EOF.
  637. + If a newline is read, it will appear in the resulting string.
  638. + Return value is a malloc'ed char * which should be freed at
  639. + some point by the caller.
  640. +
  641. + Return value is NULL if the file is at EOF when called.
  642. +*/
  643. +#define FILE_READ_LINE_BUF_SIZE 1024
  644. +char *file_read_line_alloc(FILE *file)
  645. +{
  646. + char buf[FILE_READ_LINE_BUF_SIZE];
  647. + int buf_len;
  648. + char *line = NULL;
  649. + int line_size = 0;
  650. +
  651. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  652. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  653. + buf_len = strlen(buf);
  654. + if (line) {
  655. + line_size += buf_len;
  656. + line = realloc(line, line_size);
  657. + if (line == NULL) {
  658. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  659. + break;
  660. + }
  661. + strcat(line, buf);
  662. + } else {
  663. + line_size = buf_len + 1;
  664. + line = strdup(buf);
  665. + }
  666. + if (buf[buf_len - 1] == '\n') {
  667. + break;
  668. + }
  669. + }
  670. +
  671. + return line;
  672. +}
  673. +
  674. +int file_move(const char *src, const char *dest)
  675. +{
  676. + int err;
  677. +
  678. + err = rename(src, dest);
  679. +
  680. + if (err && errno == EXDEV) {
  681. + err = file_copy(src, dest);
  682. + unlink(src);
  683. + } else if (err) {
  684. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  685. + __FUNCTION__, src, dest, strerror(errno));
  686. + }
  687. +
  688. + return err;
  689. +}
  690. +
  691. +/* I put these here to keep libbb dependencies from creeping all over
  692. + the ipkg code */
  693. +int file_copy(const char *src, const char *dest)
  694. +{
  695. + int err;
  696. +
  697. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  698. + if (err) {
  699. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  700. + __FUNCTION__, src, dest);
  701. + }
  702. +
  703. + return err;
  704. +}
  705. +
  706. +int file_mkdir_hier(char *path, long mode)
  707. +{
  708. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  709. +}
  710. +
  711. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  712. + unsigned hash_length)
  713. +{
  714. + /* xzalloc zero-terminates */
  715. + char *hex_value = xzalloc((hash_length * 2) + 1);
  716. + bin2hex(hex_value, (char*)hash_value, hash_length);
  717. + return (unsigned char *)hex_value;
  718. +}
  719. +
  720. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  721. +{
  722. + int src_fd, hash_len, count;
  723. + union _ctx_ {
  724. + sha1_ctx_t sha1;
  725. + md5_ctx_t md5;
  726. + } context;
  727. + uint8_t *hash_value = NULL;
  728. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  729. + void FAST_FUNC (*update)(void*, const void*, size_t);
  730. + void FAST_FUNC (*final)(void*, void*);
  731. +
  732. + src_fd = open_or_warn_stdin(filename);
  733. + if (src_fd < 0) {
  734. + return NULL;
  735. + }
  736. +
  737. + /* figure specific hash algorithims */
  738. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  739. + md5_begin(&context.md5);
  740. + update = (void*)md5_hash;
  741. + final = (void*)md5_end;
  742. + hash_len = 16;
  743. + } else {
  744. + bb_error_msg_and_die("algorithm not supported");
  745. + }
  746. +
  747. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  748. + update(&context, in_buf, count);
  749. + }
  750. +
  751. + if (count == 0) {
  752. + final(&context, in_buf);
  753. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  754. + }
  755. +
  756. + RELEASE_CONFIG_BUFFER(in_buf);
  757. +
  758. + if (src_fd != STDIN_FILENO) {
  759. + close(src_fd);
  760. + }
  761. +
  762. + return hash_value;
  763. +}
  764. +
  765. +uint8_t *file_md5sum_alloc(const char *file_name)
  766. +{
  767. + return hash_file(file_name, HASH_MD5);
  768. +}
  769. +
  770. diff -Nur busybox-1.26.0.orig/archival/libipkg/file_util.h busybox-1.26.0/archival/libipkg/file_util.h
  771. --- busybox-1.26.0.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  772. +++ busybox-1.26.0/archival/libipkg/file_util.h 2016-12-22 17:08:30.984843942 +0100
  773. @@ -0,0 +1,29 @@
  774. +/* file_util.h - convenience routines for common file operations
  775. +
  776. + Carl D. Worth
  777. +
  778. + Copyright (C) 2001 University of Southern California
  779. +
  780. + This program is free software; you can redistribute it and/or
  781. + modify it under the terms of the GNU General Public License as
  782. + published by the Free Software Foundation; either version 2, or (at
  783. + your option) any later version.
  784. +
  785. + This program is distributed in the hope that it will be useful, but
  786. + WITHOUT ANY WARRANTY; without even the implied warranty of
  787. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  788. + General Public License for more details.
  789. +*/
  790. +
  791. +#ifndef FILE_UTIL_H
  792. +#define FILE_UTIL_H
  793. +
  794. +int file_exists(const char *file_name);
  795. +int file_is_dir(const char *file_name);
  796. +char *file_read_line_alloc(FILE *file);
  797. +int file_move(const char *src, const char *dest);
  798. +int file_copy(const char *src, const char *dest);
  799. +int file_mkdir_hier(char *path, long mode);
  800. +uint8_t *file_md5sum_alloc(const char *file_name);
  801. +
  802. +#endif
  803. diff -Nur busybox-1.26.0.orig/archival/libipkg/hash_table.c busybox-1.26.0/archival/libipkg/hash_table.c
  804. --- busybox-1.26.0.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  805. +++ busybox-1.26.0/archival/libipkg/hash_table.c 2016-12-22 17:08:30.984843942 +0100
  806. @@ -0,0 +1,155 @@
  807. +/* hash.c - hash tables for ipkg
  808. +
  809. + Steven M. Ayer, Jamey Hicks
  810. +
  811. + Copyright (C) 2002 Compaq Computer Corporation
  812. +
  813. + This program is free software; you can redistribute it and/or
  814. + modify it under the terms of the GNU General Public License as
  815. + published by the Free Software Foundation; either version 2, or (at
  816. + your option) any later version.
  817. +
  818. + This program is distributed in the hope that it will be useful, but
  819. + WITHOUT ANY WARRANTY; without even the implied warranty of
  820. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  821. + General Public License for more details.
  822. +*/
  823. +
  824. +#include <errno.h>
  825. +#include <stdio.h>
  826. +#include <stdlib.h>
  827. +#include <string.h>
  828. +#include "hash_table.h"
  829. +#include "ipkg_message.h"
  830. +
  831. +
  832. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  833. +static int rotating(const char *key, int len, int prime);
  834. +
  835. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  836. +{
  837. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  838. +}
  839. +
  840. +static int rotating(const char *key, int len, int prime)
  841. +{
  842. + unsigned int hash, i;
  843. + for (hash=len, i=0; i<len; ++i)
  844. + hash = (hash<<4)^(hash>>28)^key[i];
  845. + return (hash % prime);
  846. +}
  847. +
  848. +
  849. +/*
  850. + * this is an open table keyed by strings
  851. + */
  852. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  853. +{
  854. + static int primes_table[] = {
  855. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  856. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  857. + };
  858. + int *picker;
  859. +
  860. + if (hash->entries != NULL) {
  861. + /* we have been here already */
  862. + return 0;
  863. + }
  864. +
  865. + hash->name = name;
  866. + hash->entries = NULL;
  867. + hash->n_entries = 0;
  868. + hash->hash_entry_key = NULL;
  869. +
  870. + picker = primes_table;
  871. + while(*picker && (*picker++ < len));
  872. + if(!*picker)
  873. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  874. + --picker;
  875. +
  876. + hash->n_entries = *picker;
  877. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  878. + if (hash->entries == NULL) {
  879. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  880. + return ENOMEM;
  881. + }
  882. + return 0;
  883. +}
  884. +
  885. +void hash_table_deinit(hash_table_t *hash)
  886. +{
  887. + free(hash->entries);
  888. + hash->entries = NULL;
  889. + hash->n_entries = 0;
  890. +}
  891. +
  892. +void *hash_table_get(hash_table_t *hash, const char *key)
  893. +{
  894. + int ndx= hash_index(hash, key);
  895. + hash_entry_t *hash_entry = hash->entries + ndx;
  896. + while (hash_entry)
  897. + {
  898. + if (hash_entry->key)
  899. + {
  900. + if (strcmp(key, hash_entry->key) == 0) {
  901. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  902. + return hash_entry->data;
  903. + }
  904. + }
  905. + hash_entry = hash_entry->next;
  906. + }
  907. + return NULL;
  908. +}
  909. +
  910. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  911. +{
  912. + int ndx= hash_index(hash, key);
  913. + hash_entry_t *hash_entry = hash->entries + ndx;
  914. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  915. + if (hash_entry->key) {
  916. + if (strcmp(hash_entry->key, key) == 0) {
  917. + /* alread in table, update the value */
  918. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  919. + hash_entry->data = value;
  920. + return 0;
  921. + } else {
  922. + /*
  923. + * if this is a collision, we have to go to the end of the ll,
  924. + * then add a new entry
  925. + * before we can hook up the value
  926. + */
  927. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  928. + while (hash_entry->next)
  929. + hash_entry = hash_entry->next;
  930. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  931. + if (!hash_entry->next) {
  932. + return -ENOMEM;
  933. + }
  934. + hash_entry = hash_entry->next;
  935. + hash_entry->next = NULL;
  936. + }
  937. + }
  938. + hash->n_elements++;
  939. + hash_entry->key = strdup(key);
  940. + hash_entry->data = value;
  941. +
  942. + return 0;
  943. +}
  944. +
  945. +
  946. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  947. +{
  948. + int i;
  949. + if (!hash || !f)
  950. + return;
  951. +
  952. + for (i = 0; i < hash->n_entries; i++) {
  953. + hash_entry_t *hash_entry = (hash->entries + i);
  954. + do {
  955. + if(hash_entry->key) {
  956. + f(hash_entry->key, hash_entry->data, data);
  957. + }
  958. + } while((hash_entry = hash_entry->next));
  959. + }
  960. +}
  961. +
  962. diff -Nur busybox-1.26.0.orig/archival/libipkg/hash_table.h busybox-1.26.0/archival/libipkg/hash_table.h
  963. --- busybox-1.26.0.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  964. +++ busybox-1.26.0/archival/libipkg/hash_table.h 2016-12-22 17:08:30.984843942 +0100
  965. @@ -0,0 +1,44 @@
  966. +/* hash.h - hash tables for ipkg
  967. +
  968. + Steven M. Ayer, Jamey Hicks
  969. +
  970. + Copyright (C) 2002 Compaq Computer Corporation
  971. +
  972. + This program is free software; you can redistribute it and/or
  973. + modify it under the terms of the GNU General Public License as
  974. + published by the Free Software Foundation; either version 2, or (at
  975. + your option) any later version.
  976. +
  977. + This program is distributed in the hope that it will be useful, but
  978. + WITHOUT ANY WARRANTY; without even the implied warranty of
  979. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  980. + General Public License for more details.
  981. +*/
  982. +
  983. +#ifndef _HASH_TABLE_H_
  984. +#define _HASH_TABLE_H_
  985. +
  986. +typedef struct hash_entry hash_entry_t;
  987. +typedef struct hash_table hash_table_t;
  988. +
  989. +struct hash_entry {
  990. + const char * key;
  991. + void * data;
  992. + struct hash_entry * next;
  993. +};
  994. +
  995. +struct hash_table {
  996. + const char *name;
  997. + hash_entry_t * entries;
  998. + int n_entries; /* number of buckets */
  999. + int n_elements;
  1000. + const char * (*hash_entry_key)(void * data);
  1001. +};
  1002. +
  1003. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1004. +void hash_table_deinit(hash_table_t *hash);
  1005. +void *hash_table_get(hash_table_t *hash, const char *key);
  1006. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1007. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1008. +
  1009. +#endif /* _HASH_TABLE_H_ */
  1010. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_cmd.c busybox-1.26.0/archival/libipkg/ipkg_cmd.c
  1011. --- busybox-1.26.0.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1012. +++ busybox-1.26.0/archival/libipkg/ipkg_cmd.c 2016-12-22 17:08:30.992848456 +0100
  1013. @@ -0,0 +1,1367 @@
  1014. +/* ipkg_cmd.c - the itsy package management system
  1015. +
  1016. + Carl D. Worth
  1017. +
  1018. + Copyright (C) 2001 University of Southern California
  1019. +
  1020. + This program is free software; you can redistribute it and/or
  1021. + modify it under the terms of the GNU General Public License as
  1022. + published by the Free Software Foundation; either version 2, or (at
  1023. + your option) any later version.
  1024. +
  1025. + This program is distributed in the hope that it will be useful, but
  1026. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1027. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1028. + General Public License for more details.
  1029. +*/
  1030. +
  1031. +#include <string.h>
  1032. +
  1033. +#include "ipkg.h"
  1034. +#include <libgen.h>
  1035. +#include <glob.h>
  1036. +#include <errno.h>
  1037. +#include <stdlib.h>
  1038. +#include <unistd.h>
  1039. +#include <signal.h>
  1040. +#include <stdio.h>
  1041. +#include <dirent.h>
  1042. +
  1043. +#include "ipkg_conf.h"
  1044. +#include "ipkg_cmd.h"
  1045. +#include "ipkg_message.h"
  1046. +#include "pkg.h"
  1047. +#include "pkg_dest.h"
  1048. +#include "pkg_parse.h"
  1049. +#include "sprintf_alloc.h"
  1050. +#include "pkg.h"
  1051. +#include "file_util.h"
  1052. +#include "str_util.h"
  1053. +#include "bb_archive.h"
  1054. +
  1055. +#include <fnmatch.h>
  1056. +
  1057. +
  1058. +#include "ipkg_download.h"
  1059. +#include "ipkg_install.h"
  1060. +#include "ipkg_upgrade.h"
  1061. +#include "ipkg_remove.h"
  1062. +#include "ipkg_configure.h"
  1063. +#include "ipkg_message.h"
  1064. +
  1065. +#include "libipkg.h"
  1066. +static void *p_userdata = NULL;
  1067. +
  1068. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1069. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1074. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1092. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +
  1094. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1095. + array for easier maintenance */
  1096. +static ipkg_cmd_t cmds[] = {
  1097. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1098. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1099. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1100. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1101. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1102. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1103. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1104. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1105. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1106. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1107. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1108. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1109. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1110. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1111. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1112. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1113. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1114. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1115. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1116. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1117. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1118. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1119. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1120. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1121. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1122. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1123. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1124. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1125. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1126. +};
  1127. +
  1128. +int ipkg_state_changed;
  1129. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1130. +{
  1131. + if (ipkg_state_changed && !conf->noaction) {
  1132. + ipkg_message(conf, IPKG_INFO,
  1133. + " writing status file\n");
  1134. + ipkg_conf_write_status_files(conf);
  1135. + pkg_write_changed_filelists(conf);
  1136. + } else {
  1137. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1138. + }
  1139. +}
  1140. +
  1141. +
  1142. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1143. +
  1144. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1145. +{
  1146. + int i;
  1147. + ipkg_cmd_t *cmd;
  1148. +
  1149. + for (i=0; i < num_cmds; i++) {
  1150. + cmd = &cmds[i];
  1151. + if (strcmp(name, cmd->name) == 0) {
  1152. + return cmd;
  1153. + }
  1154. + }
  1155. +
  1156. + return NULL;
  1157. +}
  1158. +
  1159. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1160. +{
  1161. + int result;
  1162. + p_userdata = userdata;
  1163. +
  1164. +
  1165. + result = (cmd->fun)(conf, argc, argv);
  1166. + if ( result == 0 ) {
  1167. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1168. + } else {
  1169. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1170. +
  1171. + }
  1172. + if ( error_list ) {
  1173. + reverse_error_list(&error_list);
  1174. +
  1175. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1176. + /* Here we print the errors collected and free the list */
  1177. + while (error_list != NULL) {
  1178. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1179. + error_list = error_list->next;
  1180. +
  1181. + }
  1182. + free_error_list(&error_list);
  1183. +
  1184. + }
  1185. +
  1186. + p_userdata = NULL;
  1187. + return result;
  1188. +}
  1189. +
  1190. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1191. +{
  1192. + int err;
  1193. + int failures;
  1194. + char *lists_dir;
  1195. + pkg_src_list_elt_t *iter;
  1196. + pkg_src_t *src;
  1197. +
  1198. +
  1199. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1200. +
  1201. + if (! file_is_dir(lists_dir)) {
  1202. + if (file_exists(lists_dir)) {
  1203. + ipkg_message(conf, IPKG_ERROR,
  1204. + "%s: ERROR: %s exists, but is not a directory\n",
  1205. + __FUNCTION__, lists_dir);
  1206. + free(lists_dir);
  1207. + return EINVAL;
  1208. + }
  1209. + err = file_mkdir_hier(lists_dir, 0755);
  1210. + if (err) {
  1211. + ipkg_message(conf, IPKG_ERROR,
  1212. + "%s: ERROR: failed to make directory %s: %s\n",
  1213. + __FUNCTION__, lists_dir, strerror(errno));
  1214. + free(lists_dir);
  1215. + return EINVAL;
  1216. + }
  1217. + }
  1218. +
  1219. + failures = 0;
  1220. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1221. + char *url, *list_file_name;
  1222. +
  1223. + src = iter->data;
  1224. +
  1225. + if (src->extra_data) /* debian style? */
  1226. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1227. + src->gzip ? "Packages.gz" : "Packages");
  1228. + else
  1229. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1230. +
  1231. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1232. + if (src->gzip) {
  1233. + char *tmp;
  1234. + char *tmp_file_name;
  1235. + FILE *in, *out;
  1236. +
  1237. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1238. +
  1239. + if (mkdtemp (tmp) == NULL) {
  1240. + perror ("mkdtemp");
  1241. + failures++;
  1242. + continue;
  1243. + }
  1244. +
  1245. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1246. + err = ipkg_download(conf, url, tmp_file_name);
  1247. + if (err == 0) {
  1248. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1249. + in = fopen (tmp_file_name, "r");
  1250. + out = fopen (list_file_name, "w");
  1251. + if (in && out) {
  1252. + transformer_state_t xstate;
  1253. + init_transformer_state(&xstate);
  1254. + inflate_unzip (&xstate);
  1255. + } else
  1256. + err = 1;
  1257. + if (in)
  1258. + fclose (in);
  1259. + if (out)
  1260. + fclose (out);
  1261. + unlink (tmp_file_name);
  1262. + rmdir (tmp);
  1263. + free (tmp);
  1264. + }
  1265. + } else
  1266. + err = ipkg_download(conf, url, list_file_name);
  1267. + if (err) {
  1268. + failures++;
  1269. + } else {
  1270. + ipkg_message(conf, IPKG_NOTICE,
  1271. + "Updated list of available packages in %s\n",
  1272. + list_file_name);
  1273. + }
  1274. + free(url);
  1275. + free(list_file_name);
  1276. + }
  1277. + free(lists_dir);
  1278. +
  1279. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1280. +#warning here
  1281. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1282. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1283. + * -Jamey 3/1/03
  1284. + */
  1285. + {
  1286. + int i;
  1287. + int changed = 0;
  1288. + pkg_vec_t *available = pkg_vec_alloc();
  1289. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1290. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1291. + for (i = 0; i < available->len; i++) {
  1292. + pkg_t *pkg = available->pkgs[i];
  1293. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1294. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1295. + pkg->state_want = SW_UNKNOWN;
  1296. + changed = 1;
  1297. + }
  1298. + }
  1299. + pkg_vec_free(available);
  1300. + if (changed) {
  1301. + write_status_files_if_changed(conf);
  1302. + }
  1303. + }
  1304. +#endif
  1305. +
  1306. + return failures;
  1307. +}
  1308. +
  1309. +
  1310. +/* scan the args passed and cache the local filenames of the packages */
  1311. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1312. +{
  1313. + int i;
  1314. + int err;
  1315. +
  1316. + /*
  1317. + * First scan through package names/urls
  1318. + * For any urls, download the packages and install in database.
  1319. + * For any files, install package info in database.
  1320. + */
  1321. + for (i = 0; i < argc; i ++) {
  1322. + char *filename = argv [i];
  1323. + //char *tmp = basename (tmp);
  1324. + //int tmplen = strlen (tmp);
  1325. +
  1326. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1327. + // continue;
  1328. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1329. + // continue;
  1330. +
  1331. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1332. +
  1333. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1334. + if (err)
  1335. + return err;
  1336. + }
  1337. + return 0;
  1338. +}
  1339. +
  1340. +struct ipkg_intercept
  1341. +{
  1342. + char *oldpath;
  1343. + char *statedir;
  1344. +};
  1345. +
  1346. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1347. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1348. +
  1349. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1350. +{
  1351. + ipkg_intercept_t ctx;
  1352. + char *newpath;
  1353. + int gen;
  1354. +
  1355. + ctx = malloc (sizeof (*ctx));
  1356. + ctx->oldpath = strdup (getenv ("PATH"));
  1357. +
  1358. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1359. + setenv ("PATH", newpath, 1);
  1360. + free (newpath);
  1361. +
  1362. + gen = 0;
  1363. + retry:
  1364. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1365. + if (mkdir (ctx->statedir, 0770) < 0) {
  1366. + if (errno == EEXIST) {
  1367. + free (ctx->statedir);
  1368. + gen++;
  1369. + goto retry;
  1370. + }
  1371. + perror (ctx->statedir);
  1372. + return NULL;
  1373. + }
  1374. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1375. + return ctx;
  1376. +}
  1377. +
  1378. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1379. +
  1380. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1381. +{
  1382. + char *cmd;
  1383. + DIR *dir;
  1384. + int err = 0;
  1385. +
  1386. + setenv ("PATH", ctx->oldpath, 1);
  1387. + free (ctx->oldpath);
  1388. +
  1389. + dir = opendir (ctx->statedir);
  1390. + if (dir) {
  1391. + struct dirent *de;
  1392. + while (de = readdir (dir), de != NULL) {
  1393. + char *path;
  1394. +
  1395. + if (de->d_name[0] == '.')
  1396. + continue;
  1397. +
  1398. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1399. + if (access (path, X_OK) == 0) {
  1400. + if (system (path)) {
  1401. + err = errno;
  1402. + perror (de->d_name);
  1403. + }
  1404. + }
  1405. + free (path);
  1406. + }
  1407. + } else
  1408. + perror (ctx->statedir);
  1409. +
  1410. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1411. + system (cmd);
  1412. + free (cmd);
  1413. +
  1414. + free (ctx->statedir);
  1415. + free (ctx);
  1416. +
  1417. + return err;
  1418. +}
  1419. +
  1420. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1421. +{
  1422. + pkg_vec_t *all;
  1423. + int i;
  1424. + pkg_t *pkg;
  1425. + ipkg_intercept_t ic;
  1426. + int r, err = 0;
  1427. +
  1428. + ipkg_message(conf, IPKG_INFO,
  1429. + "Configuring unpacked packages\n");
  1430. + fflush( stdout );
  1431. +
  1432. + all = pkg_vec_alloc();
  1433. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1434. +
  1435. + ic = ipkg_prep_intercepts();
  1436. +
  1437. + for(i = 0; i < all->len; i++) {
  1438. + pkg = all->pkgs[i];
  1439. +
  1440. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1441. + continue;
  1442. +
  1443. + if (pkg->state_status == SS_UNPACKED) {
  1444. + ipkg_message(conf, IPKG_NOTICE,
  1445. + "Configuring %s\n", pkg->name);
  1446. + fflush( stdout );
  1447. + r = ipkg_configure(conf, pkg);
  1448. + if (r == 0) {
  1449. + pkg->state_status = SS_INSTALLED;
  1450. + pkg->parent->state_status = SS_INSTALLED;
  1451. + pkg->state_flag &= ~SF_PREFER;
  1452. + } else {
  1453. + if (!err)
  1454. + err = r;
  1455. + }
  1456. + }
  1457. + }
  1458. +
  1459. + r = ipkg_finalize_intercepts (ic);
  1460. + if (r && !err)
  1461. + err = r;
  1462. +
  1463. + pkg_vec_free(all);
  1464. + return err;
  1465. +}
  1466. +
  1467. +static void sigint_handler(int sig)
  1468. +{
  1469. + signal(sig, SIG_DFL);
  1470. + ipkg_message(NULL, IPKG_NOTICE,
  1471. + "ipkg: interrupted. writing out status database\n");
  1472. + write_status_files_if_changed(global_conf);
  1473. + exit(128 + sig);
  1474. +}
  1475. +
  1476. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1477. +{
  1478. + int i;
  1479. + char *arg;
  1480. + int err=0;
  1481. +
  1482. + global_conf = conf;
  1483. + signal(SIGINT, sigint_handler);
  1484. +
  1485. + /*
  1486. + * Now scan through package names and install
  1487. + */
  1488. + for (i=0; i < argc; i++) {
  1489. + arg = argv[i];
  1490. +
  1491. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1492. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1493. + if (err != EINVAL && err != 0)
  1494. + return err;
  1495. + }
  1496. + pkg_info_preinstall_check(conf);
  1497. +
  1498. + for (i=0; i < argc; i++) {
  1499. + arg = argv[i];
  1500. + if (conf->multiple_providers)
  1501. + err = ipkg_install_multi_by_name(conf, arg);
  1502. + else{
  1503. + err = ipkg_install_by_name(conf, arg);
  1504. + }
  1505. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1506. + ipkg_message(conf, IPKG_ERROR,
  1507. + "Cannot find package %s.\n"
  1508. + "Check the spelling or perhaps run 'ipkg update'\n",
  1509. + arg);
  1510. + }
  1511. + }
  1512. +
  1513. + /* recheck to verify that all dependences are satisfied */
  1514. + if (0) ipkg_satisfy_all_dependences(conf);
  1515. +
  1516. + ipkg_configure_packages(conf, NULL);
  1517. +
  1518. + write_status_files_if_changed(conf);
  1519. +
  1520. + return err;
  1521. +}
  1522. +
  1523. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1524. +{
  1525. + int i;
  1526. + pkg_t *pkg;
  1527. + int err;
  1528. +
  1529. + global_conf = conf;
  1530. + signal(SIGINT, sigint_handler);
  1531. +
  1532. + if (argc) {
  1533. + for (i=0; i < argc; i++) {
  1534. + char *arg = argv[i];
  1535. +
  1536. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1537. + if (err != EINVAL && err != 0)
  1538. + return err;
  1539. + }
  1540. + pkg_info_preinstall_check(conf);
  1541. +
  1542. + for (i=0; i < argc; i++) {
  1543. + char *arg = argv[i];
  1544. + if (conf->restrict_to_default_dest) {
  1545. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1546. + argv[i],
  1547. + conf->default_dest);
  1548. + if (pkg == NULL) {
  1549. + ipkg_message(conf, IPKG_NOTICE,
  1550. + "Package %s not installed in %s\n",
  1551. + argv[i], conf->default_dest->name);
  1552. + continue;
  1553. + }
  1554. + } else {
  1555. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1556. + argv[i]);
  1557. + }
  1558. + if (pkg)
  1559. + ipkg_upgrade_pkg(conf, pkg);
  1560. + else {
  1561. + ipkg_install_by_name(conf, arg);
  1562. + }
  1563. + }
  1564. + } else {
  1565. + pkg_vec_t *installed = pkg_vec_alloc();
  1566. +
  1567. + pkg_info_preinstall_check(conf);
  1568. +
  1569. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1570. + for (i = 0; i < installed->len; i++) {
  1571. + pkg = installed->pkgs[i];
  1572. + ipkg_upgrade_pkg(conf, pkg);
  1573. + }
  1574. + pkg_vec_free(installed);
  1575. + }
  1576. +
  1577. + /* recheck to verify that all dependences are satisfied */
  1578. + if (0) ipkg_satisfy_all_dependences(conf);
  1579. +
  1580. + ipkg_configure_packages(conf, NULL);
  1581. +
  1582. + write_status_files_if_changed(conf);
  1583. +
  1584. + return 0;
  1585. +}
  1586. +
  1587. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1588. +{
  1589. + int i, err;
  1590. + char *arg;
  1591. + pkg_t *pkg;
  1592. +
  1593. + pkg_info_preinstall_check(conf);
  1594. + for (i = 0; i < argc; i++) {
  1595. + arg = argv[i];
  1596. +
  1597. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1598. + if (pkg == NULL) {
  1599. + ipkg_message(conf, IPKG_ERROR,
  1600. + "Cannot find package %s.\n"
  1601. + "Check the spelling or perhaps run 'ipkg update'\n",
  1602. + arg);
  1603. + continue;
  1604. + }
  1605. +
  1606. + err = ipkg_download_pkg(conf, pkg, ".");
  1607. +
  1608. + if (err) {
  1609. + ipkg_message(conf, IPKG_ERROR,
  1610. + "Failed to download %s\n", pkg->name);
  1611. + } else {
  1612. + ipkg_message(conf, IPKG_NOTICE,
  1613. + "Downloaded %s as %s\n",
  1614. + pkg->name, pkg->local_filename);
  1615. + }
  1616. + }
  1617. +
  1618. + return 0;
  1619. +}
  1620. +
  1621. +
  1622. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1623. +{
  1624. + int i ;
  1625. + pkg_vec_t *available;
  1626. + pkg_t *pkg;
  1627. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1628. + char *newline;
  1629. + char *pkg_name = NULL;
  1630. + char *version_str;
  1631. +
  1632. + if (argc > 0) {
  1633. + pkg_name = argv[0];
  1634. + }
  1635. + available = pkg_vec_alloc();
  1636. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1637. + for (i=0; i < available->len; i++) {
  1638. + pkg = available->pkgs[i];
  1639. + /* if we have package name or pattern and pkg does not match, then skip it */
  1640. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1641. + continue;
  1642. + if (pkg->description) {
  1643. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1644. + } else {
  1645. + desc_short[0] = '\0';
  1646. + }
  1647. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1648. + newline = strchr(desc_short, '\n');
  1649. + if (newline) {
  1650. + *newline = '\0';
  1651. + }
  1652. + if (ipkg_cb_list) {
  1653. + version_str = pkg_version_str_alloc(pkg);
  1654. + ipkg_cb_list(pkg->name,desc_short,
  1655. + version_str,
  1656. + pkg->state_status,
  1657. + p_userdata);
  1658. + free(version_str);
  1659. + }
  1660. + }
  1661. + pkg_vec_free(available);
  1662. +
  1663. + return 0;
  1664. +}
  1665. +
  1666. +
  1667. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1668. +{
  1669. + int i ;
  1670. + pkg_vec_t *available;
  1671. + pkg_t *pkg;
  1672. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1673. + char *newline;
  1674. + char *pkg_name = NULL;
  1675. + char *version_str;
  1676. +
  1677. + if (argc > 0) {
  1678. + pkg_name = argv[0];
  1679. + }
  1680. + available = pkg_vec_alloc();
  1681. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1682. + for (i=0; i < available->len; i++) {
  1683. + pkg = available->pkgs[i];
  1684. + /* if we have package name or pattern and pkg does not match, then skip it */
  1685. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1686. + continue;
  1687. + if (pkg->description) {
  1688. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1689. + } else {
  1690. + desc_short[0] = '\0';
  1691. + }
  1692. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1693. + newline = strchr(desc_short, '\n');
  1694. + if (newline) {
  1695. + *newline = '\0';
  1696. + }
  1697. + if (ipkg_cb_list) {
  1698. + version_str = pkg_version_str_alloc(pkg);
  1699. + ipkg_cb_list(pkg->name,desc_short,
  1700. + version_str,
  1701. + pkg->state_status,
  1702. + p_userdata);
  1703. + free(version_str);
  1704. + }
  1705. + }
  1706. +
  1707. + return 0;
  1708. +}
  1709. +
  1710. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1711. +{
  1712. + int i;
  1713. + pkg_vec_t *available;
  1714. + pkg_t *pkg;
  1715. + char *pkg_name = NULL;
  1716. + char **pkg_fields = NULL;
  1717. + int n_fields = 0;
  1718. + char *buff ; // = (char *)malloc(1);
  1719. +
  1720. + if (argc > 0) {
  1721. + pkg_name = argv[0];
  1722. + }
  1723. + if (argc > 1) {
  1724. + pkg_fields = &argv[1];
  1725. + n_fields = argc - 1;
  1726. + }
  1727. +
  1728. + available = pkg_vec_alloc();
  1729. + if (installed_only)
  1730. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1731. + else
  1732. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1733. + for (i=0; i < available->len; i++) {
  1734. + pkg = available->pkgs[i];
  1735. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1736. + continue;
  1737. + }
  1738. + buff = pkg_formatted_info(pkg);
  1739. + if ( buff ) {
  1740. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1741. + pkg->state_status,
  1742. + buff,
  1743. + p_userdata);
  1744. + free(buff);
  1745. + }
  1746. + if (conf->verbosity > 1) {
  1747. + conffile_list_elt_t *iter;
  1748. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1749. + conffile_t *cf = iter->data;
  1750. + int modified = conffile_has_been_modified(conf, cf);
  1751. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1752. + cf->name, cf->value, modified);
  1753. + }
  1754. + }
  1755. + }
  1756. + pkg_vec_free(available);
  1757. +
  1758. + return 0;
  1759. +}
  1760. +
  1761. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1762. +{
  1763. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1764. +}
  1765. +
  1766. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1767. +{
  1768. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1769. +}
  1770. +
  1771. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1772. +{
  1773. +
  1774. + int err;
  1775. + if (argc > 0) {
  1776. + char *pkg_name = NULL;
  1777. +
  1778. + pkg_name = argv[0];
  1779. +
  1780. + err = ipkg_configure_packages (conf, pkg_name);
  1781. +
  1782. + } else {
  1783. + err = ipkg_configure_packages (conf, NULL);
  1784. + }
  1785. +
  1786. + write_status_files_if_changed(conf);
  1787. +
  1788. + return err;
  1789. +}
  1790. +
  1791. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1792. +{
  1793. + int i, err;
  1794. + char *globpattern;
  1795. + glob_t globbuf;
  1796. +
  1797. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1798. + err = glob(globpattern, 0, NULL, &globbuf);
  1799. + free(globpattern);
  1800. + if (err) {
  1801. + return 0;
  1802. + }
  1803. +
  1804. + ipkg_message(conf, IPKG_NOTICE,
  1805. + "The following packages in %s will now be installed.\n",
  1806. + conf->pending_dir);
  1807. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1808. + ipkg_message(conf, IPKG_NOTICE,
  1809. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1810. + }
  1811. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1812. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1813. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1814. + if (err == 0) {
  1815. + err = unlink(globbuf.gl_pathv[i]);
  1816. + if (err) {
  1817. + ipkg_message(conf, IPKG_ERROR,
  1818. + "%s: ERROR: failed to unlink %s: %s\n",
  1819. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1820. + return err;
  1821. + }
  1822. + }
  1823. + }
  1824. + globfree(&globbuf);
  1825. +
  1826. + return err;
  1827. +}
  1828. +
  1829. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1830. +{
  1831. + int i,a,done;
  1832. + pkg_t *pkg;
  1833. + pkg_t *pkg_to_remove;
  1834. + pkg_vec_t *available;
  1835. + char *pkg_name = NULL;
  1836. + global_conf = conf;
  1837. + signal(SIGINT, sigint_handler);
  1838. +
  1839. +// ENH: Add the "no pkg removed" just in case.
  1840. +
  1841. + done = 0;
  1842. +
  1843. + available = pkg_vec_alloc();
  1844. + pkg_info_preinstall_check(conf);
  1845. + if ( argc > 0 ) {
  1846. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1847. + for (i=0; i < argc; i++) {
  1848. + pkg_name = malloc(strlen(argv[i])+2);
  1849. + strcpy(pkg_name,argv[i]);
  1850. + for (a=0; a < available->len; a++) {
  1851. + pkg = available->pkgs[a];
  1852. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1853. + continue;
  1854. + }
  1855. + if (conf->restrict_to_default_dest) {
  1856. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1857. + pkg->name,
  1858. + conf->default_dest);
  1859. + } else {
  1860. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1861. + }
  1862. +
  1863. + if (pkg == NULL) {
  1864. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1865. + continue;
  1866. + }
  1867. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1868. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1869. + continue;
  1870. + }
  1871. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1872. + done = 1;
  1873. + }
  1874. + free (pkg_name);
  1875. + }
  1876. + pkg_vec_free(available);
  1877. + } else {
  1878. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1879. + int flagged_pkg_count = 0;
  1880. + int removed;
  1881. +
  1882. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1883. +
  1884. + for (i = 0; i < installed_pkgs->len; i++) {
  1885. + pkg = installed_pkgs->pkgs[i];
  1886. + if (pkg->state_flag & SF_USER) {
  1887. + flagged_pkg_count++;
  1888. + } else {
  1889. + if (!pkg_has_installed_dependents(pkg, NULL))
  1890. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1891. + }
  1892. + }
  1893. + if (!flagged_pkg_count) {
  1894. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1895. + "so refusing to uninstall unflagged non-leaf packages\n");
  1896. + return 0;
  1897. + }
  1898. +
  1899. + /* find packages not flagged SF_USER (i.e., installed to
  1900. + * satisfy a dependence) and not having any dependents, and
  1901. + * remove them */
  1902. + do {
  1903. + removed = 0;
  1904. + for (i = 0; i < installed_pkgs->len; i++) {
  1905. + pkg = installed_pkgs->pkgs[i];
  1906. + if (!(pkg->state_flag & SF_USER)
  1907. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1908. + removed++;
  1909. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1910. + ipkg_remove_pkg(conf, pkg,0);
  1911. + done = 1;
  1912. + }
  1913. + }
  1914. + } while (removed);
  1915. + pkg_vec_free(installed_pkgs);
  1916. + }
  1917. +
  1918. + if ( done == 0 )
  1919. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1920. +
  1921. + write_status_files_if_changed(conf);
  1922. + return 0;
  1923. +}
  1924. +
  1925. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1926. +{
  1927. + int i;
  1928. + pkg_t *pkg;
  1929. +
  1930. + global_conf = conf;
  1931. + signal(SIGINT, sigint_handler);
  1932. +
  1933. + pkg_info_preinstall_check(conf);
  1934. +
  1935. + for (i=0; i < argc; i++) {
  1936. + if (conf->restrict_to_default_dest) {
  1937. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1938. + argv[i],
  1939. + conf->default_dest);
  1940. + } else {
  1941. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1942. + }
  1943. +
  1944. + if (pkg == NULL) {
  1945. + ipkg_message(conf, IPKG_ERROR,
  1946. + "Package %s is not installed.\n", argv[i]);
  1947. + continue;
  1948. + }
  1949. + ipkg_purge_pkg(conf, pkg);
  1950. + }
  1951. +
  1952. + write_status_files_if_changed(conf);
  1953. + return 0;
  1954. +}
  1955. +
  1956. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1957. +{
  1958. + int i;
  1959. + pkg_t *pkg;
  1960. + char *flags = argv[0];
  1961. +
  1962. + global_conf = conf;
  1963. + signal(SIGINT, sigint_handler);
  1964. +
  1965. + for (i=1; i < argc; i++) {
  1966. + if (conf->restrict_to_default_dest) {
  1967. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1968. + argv[i],
  1969. + conf->default_dest);
  1970. + } else {
  1971. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1972. + }
  1973. +
  1974. + if (pkg == NULL) {
  1975. + ipkg_message(conf, IPKG_ERROR,
  1976. + "Package %s is not installed.\n", argv[i]);
  1977. + continue;
  1978. + }
  1979. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1980. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1981. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1982. + }
  1983. +/* pb_ asked this feature 03292004 */
  1984. +/* Actually I will use only this two, but this is an open for various status */
  1985. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1986. + pkg->state_status = pkg_state_status_from_str(flags);
  1987. + }
  1988. + ipkg_state_changed++;
  1989. + ipkg_message(conf, IPKG_NOTICE,
  1990. + "Setting flags for package %s to %s\n",
  1991. + pkg->name, flags);
  1992. + }
  1993. +
  1994. + write_status_files_if_changed(conf);
  1995. + return 0;
  1996. +}
  1997. +
  1998. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1999. +{
  2000. + pkg_t *pkg;
  2001. + str_list_t *installed_files;
  2002. + str_list_elt_t *iter;
  2003. + char *pkg_version;
  2004. + size_t buff_len = 8192;
  2005. + size_t used_len;
  2006. + char *buff ;
  2007. +
  2008. + buff = (char *)malloc(buff_len);
  2009. + if ( buff == NULL ) {
  2010. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2011. + return ENOMEM;
  2012. + }
  2013. +
  2014. + if (argc < 1) {
  2015. + return EINVAL;
  2016. + }
  2017. +
  2018. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2019. + argv[0]);
  2020. + if (pkg == NULL) {
  2021. + ipkg_message(conf, IPKG_ERROR,
  2022. + "Package %s not installed.\n", argv[0]);
  2023. + return 0;
  2024. + }
  2025. +
  2026. + installed_files = pkg_get_installed_files(pkg);
  2027. + pkg_version = pkg_version_str_alloc(pkg);
  2028. +
  2029. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2030. + pkg->name, pkg_version, pkg->dest->name);
  2031. + for (iter = installed_files->head; iter; iter = iter->next) {
  2032. + puts(iter->data);
  2033. + }
  2034. +
  2035. + free(pkg_version);
  2036. + pkg_free_installed_files(pkg);
  2037. +
  2038. + return 0;
  2039. +}
  2040. +
  2041. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2042. +{
  2043. +
  2044. + if (argc > 0) {
  2045. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2046. + const char *rel_str = "depends on";
  2047. + int i;
  2048. +
  2049. + pkg_info_preinstall_check(conf);
  2050. +
  2051. + if (conf->query_all)
  2052. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2053. + else
  2054. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2055. + for (i = 0; i < argc; i++) {
  2056. + const char *target = argv[i];
  2057. + int j;
  2058. +
  2059. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2060. +
  2061. + for (j = 0; j < available_pkgs->len; j++) {
  2062. + pkg_t *pkg = available_pkgs->pkgs[j];
  2063. + if (fnmatch(target, pkg->name, 0) == 0) {
  2064. + int k;
  2065. + int count = pkg->depends_count + pkg->pre_depends_count;
  2066. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2067. + target, pkg->architecture, rel_str);
  2068. + for (k = 0; k < count; k++) {
  2069. + compound_depend_t *cdepend = &pkg->depends[k];
  2070. + int l;
  2071. + for (l = 0; l < cdepend->possibility_count; l++) {
  2072. + depend_t *possibility = cdepend->possibilities[l];
  2073. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2074. + if (conf->verbosity > 0) {
  2075. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2076. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2077. + if (possibility->version) {
  2078. + const char *typestr = NULL;
  2079. + switch (possibility->constraint) {
  2080. + case NONE: typestr = "none"; break;
  2081. + case EARLIER: typestr = "<"; break;
  2082. + case EARLIER_EQUAL: typestr = "<="; break;
  2083. + case EQUAL: typestr = "="; break;
  2084. + case LATER_EQUAL: typestr = ">="; break;
  2085. + case LATER: typestr = ">"; break;
  2086. + }
  2087. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2088. + }
  2089. + // free(ver);
  2090. + }
  2091. + ipkg_message(conf, IPKG_ERROR, "\n");
  2092. + }
  2093. + }
  2094. + }
  2095. + }
  2096. + }
  2097. + pkg_vec_free(available_pkgs);
  2098. + }
  2099. + return 0;
  2100. +}
  2101. +
  2102. +enum what_field_type {
  2103. + WHATDEPENDS,
  2104. + WHATCONFLICTS,
  2105. + WHATPROVIDES,
  2106. + WHATREPLACES,
  2107. + WHATRECOMMENDS,
  2108. + WHATSUGGESTS
  2109. +};
  2110. +
  2111. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2112. +{
  2113. +
  2114. + if (argc > 0) {
  2115. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2116. + const char *rel_str = NULL;
  2117. + int i;
  2118. + int changed;
  2119. +
  2120. + switch (what_field_type) {
  2121. + case WHATDEPENDS: rel_str = "depends on"; break;
  2122. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2123. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2124. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2125. + case WHATPROVIDES: rel_str = "provides"; break;
  2126. + case WHATREPLACES: rel_str = "replaces"; break;
  2127. + }
  2128. +
  2129. + if (conf->query_all)
  2130. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2131. + else
  2132. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2133. +
  2134. + /* mark the root set */
  2135. + pkg_vec_clear_marks(available_pkgs);
  2136. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2137. + for (i = 0; i < argc; i++) {
  2138. + const char *dependee_pattern = argv[i];
  2139. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2140. + }
  2141. + for (i = 0; i < available_pkgs->len; i++) {
  2142. + pkg_t *pkg = available_pkgs->pkgs[i];
  2143. + if (pkg->state_flag & SF_MARKED) {
  2144. + /* mark the parent (abstract) package */
  2145. + pkg_mark_provides(pkg);
  2146. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2147. + }
  2148. + }
  2149. +
  2150. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2151. + do {
  2152. + int j;
  2153. + changed = 0;
  2154. +
  2155. + for (j = 0; j < available_pkgs->len; j++) {
  2156. + pkg_t *pkg = available_pkgs->pkgs[j];
  2157. + int k;
  2158. + int count = ((what_field_type == WHATCONFLICTS)
  2159. + ? pkg->conflicts_count
  2160. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2161. + /* skip this package if it is already marked */
  2162. + if (pkg->parent->state_flag & SF_MARKED) {
  2163. + continue;
  2164. + }
  2165. + for (k = 0; k < count; k++) {
  2166. + compound_depend_t *cdepend =
  2167. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2168. + int l;
  2169. + for (l = 0; l < cdepend->possibility_count; l++) {
  2170. + depend_t *possibility = cdepend->possibilities[l];
  2171. + if (possibility->pkg->state_flag & SF_MARKED) {
  2172. + /* mark the depending package so we won't visit it again */
  2173. + pkg->state_flag |= SF_MARKED;
  2174. + pkg_mark_provides(pkg);
  2175. + changed++;
  2176. +
  2177. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2178. + if (conf->verbosity > 0) {
  2179. + char *ver = pkg_version_str_alloc(pkg);
  2180. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2181. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2182. + if (possibility->version) {
  2183. + const char *typestr = NULL;
  2184. + switch (possibility->constraint) {
  2185. + case NONE: typestr = "none"; break;
  2186. + case EARLIER: typestr = "<"; break;
  2187. + case EARLIER_EQUAL: typestr = "<="; break;
  2188. + case EQUAL: typestr = "="; break;
  2189. + case LATER_EQUAL: typestr = ">="; break;
  2190. + case LATER: typestr = ">"; break;
  2191. + }
  2192. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2193. + }
  2194. + free(ver);
  2195. + if (!pkg_dependence_satisfiable(possibility))
  2196. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2197. + }
  2198. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2199. + goto next_package;
  2200. + }
  2201. + }
  2202. + }
  2203. + next_package:
  2204. + ;
  2205. + }
  2206. + } while (changed && recursive);
  2207. + pkg_vec_free(available_pkgs);
  2208. + }
  2209. +
  2210. + return 0;
  2211. +}
  2212. +
  2213. +int pkg_mark_provides(pkg_t *pkg)
  2214. +{
  2215. + int provides_count = pkg->provides_count;
  2216. + abstract_pkg_t **provides = pkg->provides;
  2217. + int i;
  2218. + pkg->parent->state_flag |= SF_MARKED;
  2219. + for (i = 0; i < provides_count; i++) {
  2220. + provides[i]->state_flag |= SF_MARKED;
  2221. + }
  2222. + return 0;
  2223. +}
  2224. +
  2225. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2226. +{
  2227. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2228. +}
  2229. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2230. +{
  2231. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2232. +}
  2233. +
  2234. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2235. +{
  2236. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2237. +}
  2238. +
  2239. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2240. +{
  2241. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2242. +}
  2243. +
  2244. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2245. +{
  2246. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2247. +}
  2248. +
  2249. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2250. +{
  2251. +
  2252. + if (argc > 0) {
  2253. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2254. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2255. + int i;
  2256. +
  2257. + pkg_info_preinstall_check(conf);
  2258. +
  2259. + if (conf->query_all)
  2260. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2261. + else
  2262. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2263. + for (i = 0; i < argc; i++) {
  2264. + const char *target = argv[i];
  2265. + int j;
  2266. +
  2267. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2268. + rel_str, target);
  2269. + for (j = 0; j < available_pkgs->len; j++) {
  2270. + pkg_t *pkg = available_pkgs->pkgs[j];
  2271. + int k;
  2272. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2273. + for (k = 0; k < count; k++) {
  2274. + abstract_pkg_t *apkg =
  2275. + ((what_field_type == WHATPROVIDES)
  2276. + ? pkg->provides[k]
  2277. + : pkg->replaces[k]);
  2278. + if (fnmatch(target, apkg->name, 0) == 0) {
  2279. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2280. + if (strcmp(target, apkg->name) != 0)
  2281. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2282. + ipkg_message(conf, IPKG_ERROR, "\n");
  2283. + }
  2284. + }
  2285. + }
  2286. + }
  2287. + pkg_vec_free(available_pkgs);
  2288. + }
  2289. + return 0;
  2290. +}
  2291. +
  2292. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2293. +{
  2294. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2295. +}
  2296. +
  2297. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2298. +{
  2299. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2300. +}
  2301. +
  2302. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2303. +{
  2304. + int i;
  2305. +
  2306. + pkg_vec_t *installed;
  2307. + pkg_t *pkg;
  2308. + str_list_t *installed_files;
  2309. + str_list_elt_t *iter;
  2310. + char *installed_file;
  2311. +
  2312. + if (argc < 1) {
  2313. + return EINVAL;
  2314. + }
  2315. +
  2316. + installed = pkg_vec_alloc();
  2317. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2318. +
  2319. + for (i=0; i < installed->len; i++) {
  2320. + pkg = installed->pkgs[i];
  2321. +
  2322. + installed_files = pkg_get_installed_files(pkg);
  2323. +
  2324. + for (iter = installed_files->head; iter; iter = iter->next) {
  2325. + installed_file = iter->data;
  2326. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2327. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2328. + installed_file,
  2329. + pkg_version_str_alloc(pkg),
  2330. + pkg->state_status, p_userdata);
  2331. + }
  2332. + }
  2333. +
  2334. + pkg_free_installed_files(pkg);
  2335. + }
  2336. +
  2337. + /* XXX: CLEANUP: It's not obvious from the name of
  2338. + pkg_hash_fetch_all_installed that we need to call
  2339. + pkg_vec_free to avoid a memory leak. */
  2340. + pkg_vec_free(installed);
  2341. +
  2342. + return 0;
  2343. +}
  2344. +
  2345. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2346. +{
  2347. + if (argc == 3) {
  2348. + /* this is a bit gross */
  2349. + struct pkg p1, p2;
  2350. + parseVersion(&p1, argv[0]);
  2351. + parseVersion(&p2, argv[2]);
  2352. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2353. + } else {
  2354. + ipkg_message(conf, IPKG_ERROR,
  2355. + "ipkg compare_versions <v1> <op> <v2>\n"
  2356. + "<op> is one of <= >= << >> =\n");
  2357. + return -1;
  2358. + }
  2359. +}
  2360. +
  2361. +#ifndef HOST_CPU_STR
  2362. +#define HOST_CPU_STR__(X) #X
  2363. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2364. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2365. +#endif
  2366. +
  2367. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2368. +{
  2369. + nv_pair_list_elt_t *l;
  2370. +
  2371. + l = conf->arch_list.head;
  2372. + while (l) {
  2373. + nv_pair_t *nv = l->data;
  2374. + printf("arch %s %s\n", nv->name, nv->value);
  2375. + l = l->next;
  2376. + }
  2377. + return 0;
  2378. +}
  2379. +
  2380. +
  2381. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_cmd.h busybox-1.26.0/archival/libipkg/ipkg_cmd.h
  2382. --- busybox-1.26.0.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2383. +++ busybox-1.26.0/archival/libipkg/ipkg_cmd.h 2016-12-22 17:08:30.992848456 +0100
  2384. @@ -0,0 +1,41 @@
  2385. +/* ipkg_cmd.h - the itsy package management system
  2386. +
  2387. + Carl D. Worth
  2388. +
  2389. + Copyright (C) 2001 University of Southern California
  2390. +
  2391. + This program is free software; you can redistribute it and/or
  2392. + modify it under the terms of the GNU General Public License as
  2393. + published by the Free Software Foundation; either version 2, or (at
  2394. + your option) any later version.
  2395. +
  2396. + This program is distributed in the hope that it will be useful, but
  2397. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2398. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2399. + General Public License for more details.
  2400. +*/
  2401. +
  2402. +#ifndef IPKG_CMD_H
  2403. +#define IPKG_CMD_H
  2404. +
  2405. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2406. +
  2407. +struct ipkg_cmd
  2408. +{
  2409. + const char *name;
  2410. + int requires_args;
  2411. + ipkg_cmd_fun_t fun;
  2412. +};
  2413. +typedef struct ipkg_cmd ipkg_cmd_t;
  2414. +
  2415. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2416. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2417. + const char **argv, void *userdata);
  2418. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2419. +/* install any packges with state_want == SW_INSTALL */
  2420. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2421. +/* ensure that all dependences are satisfied */
  2422. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2423. +int pkg_mark_provides(pkg_t *pkg);
  2424. +
  2425. +#endif
  2426. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_conf.c busybox-1.26.0/archival/libipkg/ipkg_conf.c
  2427. --- busybox-1.26.0.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2428. +++ busybox-1.26.0/archival/libipkg/ipkg_conf.c 2016-12-22 17:08:30.996850708 +0100
  2429. @@ -0,0 +1,739 @@
  2430. +/* ipkg_conf.c - the itsy package management system
  2431. +
  2432. + Carl D. Worth
  2433. +
  2434. + Copyright (C) 2001 University of Southern California
  2435. +
  2436. + This program is free software; you can redistribute it and/or
  2437. + modify it under the terms of the GNU General Public License as
  2438. + published by the Free Software Foundation; either version 2, or (at
  2439. + your option) any later version.
  2440. +
  2441. + This program is distributed in the hope that it will be useful, but
  2442. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2443. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2444. + General Public License for more details.
  2445. +*/
  2446. +
  2447. +#include <glob.h>
  2448. +
  2449. +#include "ipkg.h"
  2450. +#include "ipkg_conf.h"
  2451. +
  2452. +#include "xregex.h"
  2453. +#include "sprintf_alloc.h"
  2454. +#include "ipkg_conf.h"
  2455. +#include "ipkg_message.h"
  2456. +#include "file_util.h"
  2457. +#include "str_util.h"
  2458. +#include "xsystem.h"
  2459. +
  2460. +
  2461. +ipkg_conf_t *global_conf;
  2462. +
  2463. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2464. + pkg_src_list_t *pkg_src_list,
  2465. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2466. + char **tmp_lists_dir);
  2467. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2468. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2469. + const char *name, const char *value);
  2470. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2471. + const char *default_dest_name);
  2472. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2473. + pkg_src_list_t *nv_pair_list);
  2474. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2475. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2476. +
  2477. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2478. +{
  2479. + ipkg_option_t tmp[] = {
  2480. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2481. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2482. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2483. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2484. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2485. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2486. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2487. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2488. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2489. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2490. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2491. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2492. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2493. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2494. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2495. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2496. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2497. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2498. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2499. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2500. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2501. + { NULL }
  2502. + };
  2503. +
  2504. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2505. + if ( options == NULL ){
  2506. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2507. + return -1;
  2508. + }
  2509. +
  2510. + memcpy(*options, tmp, sizeof(tmp));
  2511. + return 0;
  2512. +};
  2513. +
  2514. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2515. +{
  2516. + if (arg_str) {
  2517. + if (*conf_str) {
  2518. + free(*conf_str);
  2519. + }
  2520. + *conf_str = strdup(arg_str);
  2521. + }
  2522. +}
  2523. +
  2524. +static void ipkg_conf_free_string(char **conf_str)
  2525. +{
  2526. + if (*conf_str) {
  2527. + free(*conf_str);
  2528. + *conf_str = NULL;
  2529. + }
  2530. +}
  2531. +
  2532. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2533. +{
  2534. + int err;
  2535. + int remountroot;
  2536. + struct mntent *mnt;
  2537. + FILE *f;
  2538. + char *tmp_dir_base;
  2539. + nv_pair_list_t tmp_dest_nv_pair_list;
  2540. + char * lists_dir =NULL;
  2541. + glob_t globbuf;
  2542. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2543. + char *pending_dir =NULL;
  2544. +
  2545. + memset(conf, 0, sizeof(ipkg_conf_t));
  2546. +
  2547. + pkg_src_list_init(&conf->pkg_src_list);
  2548. +
  2549. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2550. + pkg_dest_list_init(&conf->pkg_dest_list);
  2551. +
  2552. + nv_pair_list_init(&conf->arch_list);
  2553. +
  2554. + conf->restrict_to_default_dest = 0;
  2555. + conf->default_dest = NULL;
  2556. +
  2557. +
  2558. + if (args->tmp_dir)
  2559. + tmp_dir_base = args->tmp_dir;
  2560. + else
  2561. + tmp_dir_base = getenv("IPKGTMPDIR");
  2562. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2563. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2564. + IPKG_CONF_TMP_DIR_SUFFIX);
  2565. +
  2566. + remountroot = 0;
  2567. + /* check if /dev/root is mounted read-only */
  2568. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  2569. + fprintf (stderr, "Checking /proc/mounts failed\n");
  2570. + while ((mnt = getmntent(f)) != NULL) {
  2571. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  2572. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  2573. + remountroot = 1;
  2574. + }
  2575. + }
  2576. + endmntent(f);
  2577. +
  2578. + if (remountroot) {
  2579. + /* mount rootfs read-write */
  2580. + if (mount("","/",0,MS_REMOUNT,0)<0)
  2581. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  2582. + }
  2583. + mkdir(tmp_dir_base, S_IRWXU);
  2584. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2585. + if (conf->tmp_dir == NULL) {
  2586. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2587. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2588. + return errno;
  2589. + }
  2590. + if (remountroot) {
  2591. + sync();
  2592. + /* mount rootfs read-only */
  2593. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  2594. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  2595. + }
  2596. +
  2597. + conf->force_depends = 0;
  2598. + conf->force_defaults = 0;
  2599. + conf->force_overwrite = 0;
  2600. + conf->force_downgrade = 0;
  2601. + conf->force_reinstall = 0;
  2602. + conf->force_space = 0;
  2603. + conf->force_removal_of_essential_packages = 0;
  2604. + conf->force_removal_of_dependent_packages = 0;
  2605. + conf->nodeps = 0;
  2606. + conf->verbose_wget = 0;
  2607. + conf->offline_root = NULL;
  2608. + conf->offline_root_pre_script_cmd = NULL;
  2609. + conf->offline_root_post_script_cmd = NULL;
  2610. + conf->multiple_providers = 0;
  2611. + conf->verbosity = 1;
  2612. + conf->noaction = 0;
  2613. +
  2614. + conf->http_proxy = NULL;
  2615. + conf->ftp_proxy = NULL;
  2616. + conf->no_proxy = NULL;
  2617. + conf->proxy_user = NULL;
  2618. + conf->proxy_passwd = NULL;
  2619. +
  2620. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2621. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2622. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2623. + lists_dir=(char *)malloc(1);
  2624. + lists_dir[0]='\0';
  2625. + if (args->conf_file) {
  2626. + struct stat stat_buf;
  2627. + err = stat(args->conf_file, &stat_buf);
  2628. + if (err == 0)
  2629. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2630. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2631. + /* Memory leakage from ipkg_conf_parse-file */
  2632. + return -1;
  2633. + }
  2634. +
  2635. + }
  2636. +
  2637. + /* if (!lists_dir ){*/
  2638. + if (strlen(lists_dir)<=1 ){
  2639. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2640. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2641. + }
  2642. +
  2643. + if (args->offline_root) {
  2644. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2645. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2646. + free(lists_dir);
  2647. + lists_dir = tmp;
  2648. + }
  2649. +
  2650. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2651. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2652. +
  2653. + conf->lists_dir = strdup(lists_dir);
  2654. + conf->pending_dir = strdup(pending_dir);
  2655. +
  2656. + if (args->offline_root)
  2657. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2658. + memset(&globbuf, 0, sizeof(globbuf));
  2659. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2660. + if (!err) {
  2661. + int i;
  2662. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2663. + if (globbuf.gl_pathv[i])
  2664. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2665. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2666. + /* Memory leakage from ipkg_conf_parse-file */
  2667. + return -1;
  2668. + }
  2669. + }
  2670. + }
  2671. + globfree(&globbuf);
  2672. +
  2673. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2674. + if (nv_pair_list_empty(&conf->arch_list)) {
  2675. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2676. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2677. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2678. + }
  2679. +
  2680. + /* Even if there is no conf file, we'll need at least one dest. */
  2681. + if (tmp_dest_nv_pair_list.head == NULL) {
  2682. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2683. + IPKG_CONF_DEFAULT_DEST_NAME,
  2684. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2685. + }
  2686. +
  2687. + /* After parsing the file, set options from command-line, (so that
  2688. + command-line arguments take precedence) */
  2689. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2690. + really needs to be cleaned up. There is so much duplication
  2691. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2692. + a pointer to args_t (which could then not be freed), rather
  2693. + than duplicating every field here? */
  2694. + if (args->force_depends) {
  2695. + conf->force_depends = 1;
  2696. + }
  2697. + if (args->force_defaults) {
  2698. + conf->force_defaults = 1;
  2699. + }
  2700. + if (args->force_overwrite) {
  2701. + conf->force_overwrite = 1;
  2702. + }
  2703. + if (args->force_downgrade) {
  2704. + conf->force_downgrade = 1;
  2705. + }
  2706. + if (args->force_reinstall) {
  2707. + conf->force_reinstall = 1;
  2708. + }
  2709. + if (args->force_removal_of_dependent_packages) {
  2710. + conf->force_removal_of_dependent_packages = 1;
  2711. + }
  2712. + if (args->force_removal_of_essential_packages) {
  2713. + conf->force_removal_of_essential_packages = 1;
  2714. + }
  2715. + if (args->nodeps) {
  2716. + conf->nodeps = 1;
  2717. + }
  2718. + if (args->noaction) {
  2719. + conf->noaction = 1;
  2720. + }
  2721. + if (args->query_all) {
  2722. + conf->query_all = 1;
  2723. + }
  2724. + if (args->verbose_wget) {
  2725. + conf->verbose_wget = 1;
  2726. + }
  2727. + if (args->multiple_providers) {
  2728. + conf->multiple_providers = 1;
  2729. + }
  2730. + if (args->verbosity != conf->verbosity) {
  2731. + conf->verbosity = args->verbosity;
  2732. + }
  2733. +
  2734. + ipkg_conf_override_string(&conf->offline_root,
  2735. + args->offline_root);
  2736. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2737. + args->offline_root_pre_script_cmd);
  2738. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2739. + args->offline_root_post_script_cmd);
  2740. +
  2741. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2742. + read anything from there.
  2743. +*/
  2744. + if ( !(args->nocheckfordirorfile)){
  2745. + /* need to run load the source list before dest list -Jamey */
  2746. + if ( !(args->noreadfeedsfile))
  2747. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2748. +
  2749. + /* Now that we have resolved conf->offline_root, we can commit to
  2750. + the directory names for the dests and load in all the package
  2751. + lists. */
  2752. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2753. +
  2754. + if (args->dest) {
  2755. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2756. + if (err) {
  2757. + return err;
  2758. + }
  2759. + }
  2760. + }
  2761. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2762. + free(lists_dir);
  2763. + free(pending_dir);
  2764. +
  2765. + return 0;
  2766. +}
  2767. +
  2768. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2769. +{
  2770. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2771. +#error
  2772. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2773. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2774. + __FUNCTION__, conf->tmp_dir);
  2775. +#else
  2776. + int err;
  2777. +
  2778. + err = rmdir(conf->tmp_dir);
  2779. + if (err) {
  2780. + if (errno == ENOTEMPTY) {
  2781. + char *cmd;
  2782. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2783. + err = xsystem(cmd);
  2784. + free(cmd);
  2785. + }
  2786. + if (err)
  2787. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2788. + }
  2789. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2790. +
  2791. + free(conf->tmp_dir); /*XXX*/
  2792. +
  2793. + pkg_src_list_deinit(&conf->pkg_src_list);
  2794. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2795. + nv_pair_list_deinit(&conf->arch_list);
  2796. + if (&conf->pkg_hash)
  2797. + pkg_hash_deinit(&conf->pkg_hash);
  2798. + if (&conf->file_hash)
  2799. + hash_table_deinit(&conf->file_hash);
  2800. + if (&conf->obs_file_hash)
  2801. + hash_table_deinit(&conf->obs_file_hash);
  2802. +
  2803. + ipkg_conf_free_string(&conf->offline_root);
  2804. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2805. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2806. +
  2807. + if (conf->verbosity > 1) {
  2808. + int i;
  2809. + hash_table_t *hashes[] = {
  2810. + &conf->pkg_hash,
  2811. + &conf->file_hash,
  2812. + &conf->obs_file_hash };
  2813. + for (i = 0; i < 3; i++) {
  2814. + hash_table_t *hash = hashes[i];
  2815. + int c = 0;
  2816. + int n_conflicts = 0;
  2817. + int j;
  2818. + for (j = 0; j < hash->n_entries; j++) {
  2819. + int len = 0;
  2820. + hash_entry_t *e = &hash->entries[j];
  2821. + if (e->next)
  2822. + n_conflicts++;
  2823. + while (e && e->key) {
  2824. + len++;
  2825. + e = e->next;
  2826. + }
  2827. + if (len > c)
  2828. + c = len;
  2829. + }
  2830. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2831. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2832. + hash_table_deinit(hash);
  2833. + }
  2834. + }
  2835. +}
  2836. +
  2837. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2838. + const char *default_dest_name)
  2839. +{
  2840. + pkg_dest_list_elt_t *iter;
  2841. + pkg_dest_t *dest;
  2842. +
  2843. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2844. + dest = iter->data;
  2845. + if (strcmp(dest->name, default_dest_name) == 0) {
  2846. + conf->default_dest = dest;
  2847. + conf->restrict_to_default_dest = 1;
  2848. + return 0;
  2849. + }
  2850. + }
  2851. +
  2852. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2853. +
  2854. + return 1;
  2855. +}
  2856. +
  2857. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2858. +{
  2859. + pkg_src_list_elt_t *iter;
  2860. + pkg_src_t *src;
  2861. + char *list_file;
  2862. +
  2863. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2864. + src = iter->data;
  2865. + if (src == NULL) {
  2866. + continue;
  2867. + }
  2868. +
  2869. + sprintf_alloc(&list_file, "%s/%s",
  2870. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2871. + src->name);
  2872. +
  2873. + if (file_exists(list_file)) {
  2874. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2875. + }
  2876. + free(list_file);
  2877. + }
  2878. +
  2879. + return 0;
  2880. +}
  2881. +
  2882. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2883. +{
  2884. + nv_pair_list_elt_t *iter;
  2885. + nv_pair_t *nv_pair;
  2886. + pkg_dest_t *dest;
  2887. + char *root_dir;
  2888. +
  2889. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2890. + nv_pair = iter->data;
  2891. +
  2892. + if (conf->offline_root) {
  2893. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2894. + } else {
  2895. + root_dir = strdup(nv_pair->value);
  2896. + }
  2897. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2898. + free(root_dir);
  2899. + if (dest == NULL) {
  2900. + continue;
  2901. + }
  2902. + if (conf->default_dest == NULL) {
  2903. + conf->default_dest = dest;
  2904. + }
  2905. + if (file_exists(dest->status_file_name)) {
  2906. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2907. + NULL, dest, 1);
  2908. + }
  2909. + }
  2910. +
  2911. + return 0;
  2912. +}
  2913. +
  2914. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2915. + pkg_src_list_t *pkg_src_list,
  2916. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2917. + char **lists_dir)
  2918. +{
  2919. + ipkg_option_t * options;
  2920. + FILE *file = fopen(filename, "r");
  2921. + regex_t valid_line_re, comment_re;
  2922. +#define regmatch_size 12
  2923. + regmatch_t regmatch[regmatch_size];
  2924. +
  2925. + if (ipkg_init_options_array(conf, &options)<0)
  2926. + return ENOMEM;
  2927. +
  2928. + if (file == NULL) {
  2929. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2930. + __FUNCTION__, filename, strerror(errno));
  2931. + free(options);
  2932. + return errno;
  2933. + }
  2934. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2935. +
  2936. + xregcomp(&comment_re,
  2937. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2938. + REG_EXTENDED);
  2939. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2940. +
  2941. + while(1) {
  2942. + int line_num = 0;
  2943. + char *line;
  2944. + char *type, *name, *value, *extra;
  2945. +
  2946. + line = file_read_line_alloc(file);
  2947. + line_num++;
  2948. + if (line == NULL) {
  2949. + break;
  2950. + }
  2951. +
  2952. + str_chomp(line);
  2953. +
  2954. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2955. + goto NEXT_LINE;
  2956. + }
  2957. +
  2958. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2959. + str_chomp(line);
  2960. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2961. + filename, line_num, line);
  2962. + goto NEXT_LINE;
  2963. + }
  2964. +
  2965. + /* This has to be so ugly to deal with optional quotation marks */
  2966. + if (regmatch[2].rm_so > 0) {
  2967. + type = strndup(line + regmatch[2].rm_so,
  2968. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2969. + } else {
  2970. + type = strndup(line + regmatch[3].rm_so,
  2971. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2972. + }
  2973. + if (regmatch[5].rm_so > 0) {
  2974. + name = strndup(line + regmatch[5].rm_so,
  2975. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2976. + } else {
  2977. + name = strndup(line + regmatch[6].rm_so,
  2978. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2979. + }
  2980. + if (regmatch[8].rm_so > 0) {
  2981. + value = strndup(line + regmatch[8].rm_so,
  2982. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2983. + } else {
  2984. + value = strndup(line + regmatch[9].rm_so,
  2985. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2986. + }
  2987. + extra = NULL;
  2988. + if (regmatch[11].rm_so > 0) {
  2989. + extra = strndup (line + regmatch[11].rm_so,
  2990. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2991. + }
  2992. +
  2993. + /* We use the tmp_dest_nv_pair_list below instead of
  2994. + conf->pkg_dest_list because we might encounter an
  2995. + offline_root option later and that would invalidate the
  2996. + directories we would have computed in
  2997. + pkg_dest_list_init. (We do a similar thing with
  2998. + tmp_src_nv_pair_list for sake of symmetry.) */
  2999. + if (strcmp(type, "option") == 0) {
  3000. + ipkg_conf_set_option(options, name, value);
  3001. + } else if (strcmp(type, "src") == 0) {
  3002. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3003. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3004. + } else {
  3005. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3006. + name, value);
  3007. + }
  3008. + } else if (strcmp(type, "src/gz") == 0) {
  3009. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3010. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3011. + } else {
  3012. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3013. + name, value);
  3014. + }
  3015. + } else if (strcmp(type, "dest") == 0) {
  3016. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3017. + } else if (strcmp(type, "lists_dir") == 0) {
  3018. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3019. + if (*lists_dir == NULL) {
  3020. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3021. + free(options);
  3022. + return EINVAL;
  3023. + }
  3024. + sprintf (*lists_dir,"%s",value);
  3025. + } else if (strcmp(type, "arch") == 0) {
  3026. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3027. + if (!value) {
  3028. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3029. + value = strdup("10");
  3030. + }
  3031. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3032. + } else {
  3033. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3034. + "parameter: %s %s %s\n", type, name, value);
  3035. + free(options);
  3036. + return EINVAL;
  3037. + }
  3038. +
  3039. + free(type);
  3040. + free(name);
  3041. + free(value);
  3042. + if (extra)
  3043. + free (extra);
  3044. +
  3045. + NEXT_LINE:
  3046. + free(line);
  3047. + }
  3048. +
  3049. + free(options);
  3050. + regfree(&comment_re);
  3051. + regfree(&valid_line_re);
  3052. + fclose(file);
  3053. +
  3054. + return 0;
  3055. +}
  3056. +
  3057. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3058. + const char *name, const char *value)
  3059. +{
  3060. + int i = 0;
  3061. + while (options[i].name) {
  3062. + if (strcmp(options[i].name, name) == 0) {
  3063. + switch (options[i].type) {
  3064. + case IPKG_OPT_TYPE_BOOL:
  3065. + *((int *)options[i].value) = 1;
  3066. + return 0;
  3067. + case IPKG_OPT_TYPE_INT:
  3068. + if (value) {
  3069. + *((int *)options[i].value) = atoi(value);
  3070. + return 0;
  3071. + } else {
  3072. + printf("%s: Option %s need an argument\n",
  3073. + __FUNCTION__, name);
  3074. + return EINVAL;
  3075. + }
  3076. + case IPKG_OPT_TYPE_STRING:
  3077. + if (value) {
  3078. + *((char **)options[i].value) = strdup(value);
  3079. + return 0;
  3080. + } else {
  3081. + printf("%s: Option %s need an argument\n",
  3082. + __FUNCTION__, name);
  3083. + return EINVAL;
  3084. + }
  3085. + }
  3086. + }
  3087. + i++;
  3088. + }
  3089. +
  3090. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3091. + __FUNCTION__, name, value);
  3092. + return EINVAL;
  3093. +}
  3094. +
  3095. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3096. +{
  3097. + pkg_dest_list_elt_t *iter;
  3098. + pkg_dest_t *dest;
  3099. + pkg_vec_t *all;
  3100. + pkg_t *pkg;
  3101. + register int i;
  3102. + int err;
  3103. +
  3104. + if (conf->noaction)
  3105. + return 0;
  3106. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3107. + dest = iter->data;
  3108. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3109. + if (dest->status_file == NULL) {
  3110. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3111. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3112. + }
  3113. + }
  3114. +
  3115. + all = pkg_vec_alloc();
  3116. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3117. +
  3118. + for(i = 0; i < all->len; i++) {
  3119. + pkg = all->pkgs[i];
  3120. + /* We don't need most uninstalled packages in the status file */
  3121. + if (pkg->state_status == SS_NOT_INSTALLED
  3122. + && (pkg->state_want == SW_UNKNOWN
  3123. + || pkg->state_want == SW_DEINSTALL
  3124. + || pkg->state_want == SW_PURGE)) {
  3125. + continue;
  3126. + }
  3127. + if (!pkg) {
  3128. + fprintf(stderr, "Null package\n");
  3129. + }
  3130. + if (pkg->dest == NULL) {
  3131. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3132. + "package %s since it has a NULL dest\n",
  3133. + __FUNCTION__, pkg->name);
  3134. + continue;
  3135. + }
  3136. + if (pkg->dest->status_file) {
  3137. + pkg_print_status(pkg, pkg->dest->status_file);
  3138. + }
  3139. + }
  3140. +
  3141. + pkg_vec_free(all);
  3142. +
  3143. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3144. + dest = iter->data;
  3145. + if (dest->status_file) {
  3146. + err = ferror(dest->status_file);
  3147. + fclose(dest->status_file);
  3148. + dest->status_file = NULL;
  3149. + if (!err) {
  3150. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3151. + } else {
  3152. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3153. + "retaining old %s\n", __FUNCTION__,
  3154. + dest->status_file_tmp_name, dest->status_file_name);
  3155. + }
  3156. + }
  3157. + }
  3158. +
  3159. + return 0;
  3160. +}
  3161. +
  3162. +
  3163. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3164. +{
  3165. + char *root_filename;
  3166. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3167. + return root_filename;
  3168. +}
  3169. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_conf.h busybox-1.26.0/archival/libipkg/ipkg_conf.h
  3170. --- busybox-1.26.0.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3171. +++ busybox-1.26.0/archival/libipkg/ipkg_conf.h 2016-12-22 17:08:30.996850708 +0100
  3172. @@ -0,0 +1,107 @@
  3173. +/* ipkg_conf.h - the itsy package management system
  3174. +
  3175. + Carl D. Worth
  3176. +
  3177. + Copyright (C) 2001 University of Southern California
  3178. +
  3179. + This program is free software; you can redistribute it and/or
  3180. + modify it under the terms of the GNU General Public License as
  3181. + published by the Free Software Foundation; either version 2, or (at
  3182. + your option) any later version.
  3183. +
  3184. + This program is distributed in the hope that it will be useful, but
  3185. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3186. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3187. + General Public License for more details.
  3188. +*/
  3189. +
  3190. +#ifndef IPKG_CONF_H
  3191. +#define IPKG_CONF_H
  3192. +
  3193. +typedef struct ipkg_conf ipkg_conf_t;
  3194. +
  3195. +#include "hash_table.h"
  3196. +#include "ipkg.h"
  3197. +#include "args.h"
  3198. +#include "pkg.h"
  3199. +#include "pkg_hash.h"
  3200. +#include "pkg_src_list.h"
  3201. +#include "pkg_dest_list.h"
  3202. +#include "nv_pair_list.h"
  3203. +
  3204. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3205. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3206. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3207. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3208. +
  3209. +/* In case the config file defines no dest */
  3210. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3211. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3212. +
  3213. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3214. +
  3215. +struct ipkg_conf
  3216. +{
  3217. + pkg_src_list_t pkg_src_list;
  3218. + pkg_dest_list_t pkg_dest_list;
  3219. + nv_pair_list_t arch_list;
  3220. +
  3221. + int restrict_to_default_dest;
  3222. + pkg_dest_t *default_dest;
  3223. +
  3224. + char *tmp_dir;
  3225. + char *lists_dir;
  3226. + char *pending_dir;
  3227. +
  3228. + /* options */
  3229. + int force_depends;
  3230. + int force_defaults;
  3231. + int force_overwrite;
  3232. + int force_downgrade;
  3233. + int force_reinstall;
  3234. + int force_space;
  3235. + int force_removal_of_dependent_packages;
  3236. + int force_removal_of_essential_packages;
  3237. + int nodeps; /* do not follow dependences */
  3238. + int verbose_wget;
  3239. + int multiple_providers;
  3240. + char *offline_root;
  3241. + char *offline_root_pre_script_cmd;
  3242. + char *offline_root_post_script_cmd;
  3243. + int query_all;
  3244. + int verbosity;
  3245. + int noaction;
  3246. +
  3247. + /* proxy options */
  3248. + char *http_proxy;
  3249. + char *ftp_proxy;
  3250. + char *no_proxy;
  3251. + char *proxy_user;
  3252. + char *proxy_passwd;
  3253. +
  3254. + hash_table_t pkg_hash;
  3255. + hash_table_t file_hash;
  3256. + hash_table_t obs_file_hash;
  3257. +};
  3258. +
  3259. +enum ipkg_option_type {
  3260. + IPKG_OPT_TYPE_BOOL,
  3261. + IPKG_OPT_TYPE_INT,
  3262. + IPKG_OPT_TYPE_STRING
  3263. +};
  3264. +typedef enum ipkg_option_type ipkg_option_type_t;
  3265. +
  3266. +typedef struct ipkg_option ipkg_option_t;
  3267. +struct ipkg_option {
  3268. + const char *name;
  3269. + const ipkg_option_type_t type;
  3270. + const void *value;
  3271. +};
  3272. +
  3273. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3274. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3275. +
  3276. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3277. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3278. +
  3279. +#endif
  3280. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_configure.c busybox-1.26.0/archival/libipkg/ipkg_configure.c
  3281. --- busybox-1.26.0.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3282. +++ busybox-1.26.0/archival/libipkg/ipkg_configure.c 2016-12-22 17:08:30.996850708 +0100
  3283. @@ -0,0 +1,40 @@
  3284. +/* ipkg_configure.c - the itsy package management system
  3285. +
  3286. + Carl D. Worth
  3287. +
  3288. + Copyright (C) 2001 University of Southern California
  3289. +
  3290. + This program is free software; you can redistribute it and/or
  3291. + modify it under the terms of the GNU General Public License as
  3292. + published by the Free Software Foundation; either version 2, or (at
  3293. + your option) any later version.
  3294. +
  3295. + This program is distributed in the hope that it will be useful, but
  3296. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3297. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3298. + General Public License for more details.
  3299. +*/
  3300. +
  3301. +#include "ipkg.h"
  3302. +
  3303. +#include "ipkg_configure.h"
  3304. +
  3305. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3306. +{
  3307. + int err;
  3308. +
  3309. + /* DPKG_INCOMPATIBILITY:
  3310. + dpkg actually does some conffile handling here, rather than at the
  3311. + end of ipkg_install(). Do we care? */
  3312. + /* DPKG_INCOMPATIBILITY:
  3313. + dpkg actually includes a version number to this script call */
  3314. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3315. + if (err) {
  3316. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3317. + return err;
  3318. + }
  3319. +
  3320. + ipkg_state_changed++;
  3321. + return 0;
  3322. +}
  3323. +
  3324. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_configure.h busybox-1.26.0/archival/libipkg/ipkg_configure.h
  3325. --- busybox-1.26.0.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3326. +++ busybox-1.26.0/archival/libipkg/ipkg_configure.h 2016-12-22 17:08:30.996850708 +0100
  3327. @@ -0,0 +1,25 @@
  3328. +/* ipkg_configure.h - the itsy package management system
  3329. +
  3330. + Carl D. Worth
  3331. +
  3332. + Copyright (C) 2001 University of Southern California
  3333. +
  3334. + This program is free software; you can redistribute it and/or
  3335. + modify it under the terms of the GNU General Public License as
  3336. + published by the Free Software Foundation; either version 2, or (at
  3337. + your option) any later version.
  3338. +
  3339. + This program is distributed in the hope that it will be useful, but
  3340. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3341. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3342. + General Public License for more details.
  3343. +*/
  3344. +
  3345. +#ifndef IPKG_CONFIGURE_H
  3346. +#define IPKG_CONFIGURE_H
  3347. +
  3348. +#include "ipkg_conf.h"
  3349. +
  3350. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3351. +
  3352. +#endif
  3353. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_download.c busybox-1.26.0/archival/libipkg/ipkg_download.c
  3354. --- busybox-1.26.0.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3355. +++ busybox-1.26.0/archival/libipkg/ipkg_download.c 2016-12-22 17:08:30.996850708 +0100
  3356. @@ -0,0 +1,195 @@
  3357. +/* ipkg_download.c - the itsy package management system
  3358. +
  3359. + Carl D. Worth
  3360. +
  3361. + Copyright (C) 2001 University of Southern California
  3362. +
  3363. + This program is free software; you can redistribute it and/or
  3364. + modify it under the terms of the GNU General Public License as
  3365. + published by the Free Software Foundation; either version 2, or (at
  3366. + your option) any later version.
  3367. +
  3368. + This program is distributed in the hope that it will be useful, but
  3369. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3370. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3371. + General Public License for more details.
  3372. +*/
  3373. +
  3374. +#include "ipkg.h"
  3375. +#include "ipkg_download.h"
  3376. +#include "ipkg_message.h"
  3377. +
  3378. +#include "sprintf_alloc.h"
  3379. +#include "xsystem.h"
  3380. +#include "file_util.h"
  3381. +#include "str_util.h"
  3382. +
  3383. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3384. +{
  3385. + int err = 0;
  3386. +
  3387. + char *src_basec = strdup(src);
  3388. + char *src_base = bb_basename(src_basec);
  3389. + char *tmp_file_location;
  3390. + char *cmd;
  3391. +
  3392. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3393. +
  3394. + fflush(stdout);
  3395. +
  3396. + if (str_starts_with(src, "file:")) {
  3397. + int ret;
  3398. + const char *file_src = src + 5;
  3399. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3400. + ret = file_copy(src + 5, dest_file_name);
  3401. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3402. + return ret;
  3403. + }
  3404. +
  3405. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3406. + err = unlink(tmp_file_location);
  3407. + if (err && errno != ENOENT) {
  3408. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3409. + __FUNCTION__, tmp_file_location, strerror(errno));
  3410. + free(tmp_file_location);
  3411. + return errno;
  3412. + }
  3413. +
  3414. + if (conf->http_proxy) {
  3415. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3416. + setenv("http_proxy", conf->http_proxy, 1);
  3417. + }
  3418. + if (conf->ftp_proxy) {
  3419. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3420. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3421. + }
  3422. + if (conf->no_proxy) {
  3423. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3424. + setenv("no_proxy", conf->no_proxy, 1);
  3425. + }
  3426. +
  3427. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3428. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3429. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3430. + conf->proxy_user ? "--proxy-user=" : "",
  3431. + conf->proxy_user ? conf->proxy_user : "",
  3432. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3433. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3434. + conf->verbose_wget ? "" : "-q",
  3435. + conf->tmp_dir,
  3436. + src);
  3437. + err = xsystem(cmd);
  3438. + if (err) {
  3439. + if (err != -1) {
  3440. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3441. + __FUNCTION__, err, cmd);
  3442. + }
  3443. + unlink(tmp_file_location);
  3444. + free(tmp_file_location);
  3445. + free(src_basec);
  3446. + free(cmd);
  3447. + return EINVAL;
  3448. + }
  3449. + free(cmd);
  3450. +
  3451. + err = file_move(tmp_file_location, dest_file_name);
  3452. +
  3453. + free(tmp_file_location);
  3454. + free(src_basec);
  3455. +
  3456. + if (err) {
  3457. + return err;
  3458. + }
  3459. +
  3460. + return 0;
  3461. +}
  3462. +
  3463. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3464. +{
  3465. + int err;
  3466. + char *url;
  3467. +
  3468. + if (pkg->src == NULL) {
  3469. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3470. + pkg->name, pkg->parent->name);
  3471. + return -1;
  3472. + }
  3473. +
  3474. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3475. +
  3476. + /* XXX: BUG: The pkg->filename might be something like
  3477. + "../../foo.ipk". While this is correct, and exactly what we
  3478. + want to use to construct url above, here we actually need to
  3479. + use just the filename part, without any directory. */
  3480. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3481. +
  3482. + err = ipkg_download(conf, url, pkg->local_filename);
  3483. + free(url);
  3484. +
  3485. + return err;
  3486. +}
  3487. +
  3488. +/*
  3489. + * Downloads file from url, installs in package database, return package name.
  3490. + */
  3491. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3492. +{
  3493. + int err = 0;
  3494. + pkg_t *pkg;
  3495. + pkg = pkg_new();
  3496. + if (pkg == NULL)
  3497. + return ENOMEM;
  3498. +
  3499. + if (str_starts_with(url, "http://")
  3500. + || str_starts_with(url, "ftp://")) {
  3501. + char *tmp_file;
  3502. + char *file_basec = strdup(url);
  3503. + char *file_base = bb_basename(file_basec);
  3504. +
  3505. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3506. + err = ipkg_download(conf, url, tmp_file);
  3507. + if (err)
  3508. + return err;
  3509. +
  3510. + err = pkg_init_from_file(pkg, tmp_file);
  3511. + if (err)
  3512. + return err;
  3513. + pkg->local_filename = strdup(tmp_file);
  3514. +
  3515. + free(tmp_file);
  3516. + free(file_basec);
  3517. +
  3518. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3519. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3520. +
  3521. + err = pkg_init_from_file(pkg, url);
  3522. + if (err)
  3523. + return err;
  3524. + pkg->local_filename = strdup(url);
  3525. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3526. + pkg->provided_by_hand = 1;
  3527. +
  3528. + } else {
  3529. + pkg_deinit(pkg);
  3530. + free(pkg);
  3531. + return 0;
  3532. + }
  3533. +
  3534. + if (!pkg->architecture) {
  3535. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3536. + return -EINVAL;
  3537. + }
  3538. +
  3539. + pkg->dest = conf->default_dest;
  3540. + pkg->state_want = SW_INSTALL;
  3541. + pkg->state_flag |= SF_PREFER;
  3542. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3543. + if ( pkg == NULL ){
  3544. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3545. + return 0;
  3546. + }
  3547. + if (namep) {
  3548. + *namep = strdup(pkg->name);
  3549. + }
  3550. + return 0;
  3551. +}
  3552. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_download.h busybox-1.26.0/archival/libipkg/ipkg_download.h
  3553. --- busybox-1.26.0.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3554. +++ busybox-1.26.0/archival/libipkg/ipkg_download.h 2016-12-22 17:08:30.996850708 +0100
  3555. @@ -0,0 +1,30 @@
  3556. +/* ipkg_download.h - the itsy package management system
  3557. +
  3558. + Carl D. Worth
  3559. +
  3560. + Copyright (C) 2001 University of Southern California
  3561. +
  3562. + This program is free software; you can redistribute it and/or
  3563. + modify it under the terms of the GNU General Public License as
  3564. + published by the Free Software Foundation; either version 2, or (at
  3565. + your option) any later version.
  3566. +
  3567. + This program is distributed in the hope that it will be useful, but
  3568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3570. + General Public License for more details.
  3571. +*/
  3572. +
  3573. +#ifndef IPKG_DOWNLOAD_H
  3574. +#define IPKG_DOWNLOAD_H
  3575. +
  3576. +#include "ipkg_conf.h"
  3577. +
  3578. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3579. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3580. +/*
  3581. + * Downloads file from url, installs in package database, return package name.
  3582. + */
  3583. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3584. +
  3585. +#endif
  3586. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg.h busybox-1.26.0/archival/libipkg/ipkg.h
  3587. --- busybox-1.26.0.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3588. +++ busybox-1.26.0/archival/libipkg/ipkg.h 2016-12-22 17:08:31.000852971 +0100
  3589. @@ -0,0 +1,68 @@
  3590. +/* ipkg.h - the itsy package management system
  3591. +
  3592. + Carl D. Worth
  3593. +
  3594. + Copyright (C) 2001 University of Southern California
  3595. +
  3596. + This program is free software; you can redistribute it and/or
  3597. + modify it under the terms of the GNU General Public License as
  3598. + published by the Free Software Foundation; either version 2, or (at
  3599. + your option) any later version.
  3600. +
  3601. + This program is distributed in the hope that it will be useful, but
  3602. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3603. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3604. + General Public License for more details.
  3605. +*/
  3606. +
  3607. +#ifndef IPKG_H
  3608. +#define IPKG_H
  3609. +
  3610. +#include "libbb.h"
  3611. +
  3612. +#include "ipkg_includes.h"
  3613. +#include "ipkg_conf.h"
  3614. +#include "ipkg_message.h"
  3615. +
  3616. +#define IPKG_PKG_EXTENSION ".ipk"
  3617. +#define DPKG_PKG_EXTENSION ".deb"
  3618. +
  3619. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3620. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3621. +
  3622. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3623. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3624. +#define IPKG_INFO_DIR_SUFFIX "info"
  3625. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3626. +
  3627. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3628. +
  3629. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3630. +
  3631. +#define IPKG_VERSION "1.00"
  3632. +
  3633. +
  3634. +enum ipkg_error {
  3635. + IPKG_SUCCESS = 0,
  3636. + IPKG_PKG_DEPS_UNSATISFIED,
  3637. + IPKG_PKG_IS_ESSENTIAL,
  3638. + IPKG_PKG_HAS_DEPENDENTS,
  3639. + IPKG_PKG_HAS_NO_CANDIDATE
  3640. +};
  3641. +typedef enum ipkg_error ipkg_error_t;
  3642. +
  3643. +extern int ipkg_state_changed;
  3644. +
  3645. +
  3646. +struct errlist {
  3647. + char * errmsg;
  3648. + struct errlist * next;
  3649. +} ;
  3650. +
  3651. +extern struct errlist* error_list;
  3652. +
  3653. +extern ipkg_conf_t *global_conf;
  3654. +
  3655. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3656. +
  3657. +#endif
  3658. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_includes.h busybox-1.26.0/archival/libipkg/ipkg_includes.h
  3659. --- busybox-1.26.0.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3660. +++ busybox-1.26.0/archival/libipkg/ipkg_includes.h 2016-12-22 17:08:31.000852971 +0100
  3661. @@ -0,0 +1,82 @@
  3662. +#ifndef IPKG_INCLUDES_H
  3663. +#define IPKG_INCLUDES_H
  3664. +
  3665. +/* Define to 1 if you have the <memory.h> header file. */
  3666. +#define HAVE_MEMORY_H 1
  3667. +
  3668. +/* Define to 1 if you have the <regex.h> header file. */
  3669. +#define HAVE_REGEX_H 1
  3670. +
  3671. +/* Define to 1 if you have the <stdlib.h> header file. */
  3672. +#define HAVE_STDLIB_H 1
  3673. +
  3674. +/* Define to 1 if you have the <strings.h> header file. */
  3675. +#define HAVE_STRINGS_H 1
  3676. +
  3677. +/* Define to 1 if you have the <string.h> header file. */
  3678. +#define HAVE_STRING_H 1
  3679. +
  3680. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3681. +#define HAVE_SYS_STAT_H 1
  3682. +
  3683. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3684. +#define HAVE_SYS_WAIT_H 1
  3685. +
  3686. +/* Define to 1 if you have the <unistd.h> header file. */
  3687. +#define HAVE_UNISTD_H 1
  3688. +
  3689. +/* Define to 1 if you have the ANSI C header files. */
  3690. +#define STDC_HEADERS 1
  3691. +
  3692. +
  3693. +#include <stdio.h>
  3694. +
  3695. +#if STDC_HEADERS
  3696. +# include <stdlib.h>
  3697. +# include <stdarg.h>
  3698. +# include <stddef.h>
  3699. +# include <ctype.h>
  3700. +# include <errno.h>
  3701. +#else
  3702. +# if HAVE_STDLIB_H
  3703. +# include <stdlib.h>
  3704. +# endif
  3705. +#endif
  3706. +
  3707. +#if HAVE_REGEX_H
  3708. +# include <regex.h>
  3709. +#endif
  3710. +
  3711. +#if HAVE_STRING_H
  3712. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3713. +# include <memory.h>
  3714. +# endif
  3715. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3716. +# if __GNUC__
  3717. +# define __USE_GNU 1
  3718. +# endif
  3719. +# include <string.h>
  3720. +# undef __USE_GNU
  3721. +#endif
  3722. +
  3723. +#if HAVE_STRINGS_H
  3724. +# include <strings.h>
  3725. +#endif
  3726. +
  3727. +#if HAVE_SYS_STAT_H
  3728. +# include <sys/stat.h>
  3729. +#endif
  3730. +
  3731. +#if HAVE_SYS_WAIT_H
  3732. +# include <sys/wait.h>
  3733. +#endif
  3734. +
  3735. +#if HAVE_UNISTD_H
  3736. +# include <sys/types.h>
  3737. +# include <unistd.h>
  3738. +#endif
  3739. +
  3740. +#include <sys/mount.h>
  3741. +#include <mntent.h>
  3742. +
  3743. +#endif /* IPKG_INCLUDES_H */
  3744. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_install.c busybox-1.26.0/archival/libipkg/ipkg_install.c
  3745. --- busybox-1.26.0.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3746. +++ busybox-1.26.0/archival/libipkg/ipkg_install.c 2016-12-22 17:08:31.004855223 +0100
  3747. @@ -0,0 +1,1982 @@
  3748. +/* ipkg_install.c - the itsy package management system
  3749. +
  3750. + Carl D. Worth
  3751. +
  3752. + Copyright (C) 2001 University of Southern California
  3753. +
  3754. + This program is free software; you can redistribute it and/or
  3755. + modify it under the terms of the GNU General Public License as
  3756. + published by the Free Software Foundation; either version 2, or (at
  3757. + your option) any later version.
  3758. +
  3759. + This program is distributed in the hope that it will be useful, but
  3760. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3761. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3762. + General Public License for more details.
  3763. +*/
  3764. +
  3765. +#include "ipkg.h"
  3766. +#include <errno.h>
  3767. +#include <dirent.h>
  3768. +#include <glob.h>
  3769. +#include <time.h>
  3770. +#include <signal.h>
  3771. +typedef void (*sighandler_t)(int);
  3772. +
  3773. +#include "pkg.h"
  3774. +#include "pkg_hash.h"
  3775. +#include "pkg_extract.h"
  3776. +
  3777. +#include "ipkg_install.h"
  3778. +#include "ipkg_configure.h"
  3779. +#include "ipkg_download.h"
  3780. +#include "ipkg_remove.h"
  3781. +
  3782. +#include "ipkg_utils.h"
  3783. +#include "ipkg_message.h"
  3784. +
  3785. +#include "sprintf_alloc.h"
  3786. +#include "file_util.h"
  3787. +#include "str_util.h"
  3788. +#include "xsystem.h"
  3789. +#include "user.h"
  3790. +
  3791. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3792. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3793. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3794. +
  3795. +/*
  3796. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3797. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3798. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3799. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3800. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3802. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3803. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3804. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3805. +*/
  3806. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3807. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3808. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3809. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3810. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3811. +
  3812. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3813. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3814. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3815. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3816. +
  3817. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3818. +
  3819. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3820. +
  3821. +static char *backup_filename_alloc(const char *file_name);
  3822. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3823. +static int backup_exists_for(const char *file_name);
  3824. +static int backup_remove(const char *file_name);
  3825. +
  3826. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3827. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3828. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3829. +
  3830. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3831. +{
  3832. + int err, cmp;
  3833. + pkg_t *pkg, *old;
  3834. + char *old_version, *new_version;
  3835. +
  3836. + pkg = pkg_new();
  3837. + if (pkg == NULL) {
  3838. + return ENOMEM;
  3839. + }
  3840. +
  3841. + err = pkg_init_from_file(pkg, filename);
  3842. + if (err) {
  3843. + return err;
  3844. + }
  3845. +
  3846. + if (!pkg->architecture) {
  3847. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3848. + return -EINVAL;
  3849. + }
  3850. +
  3851. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3852. + freeing the pkg that we pass in. It might be nice to clean this up
  3853. + if possible. */
  3854. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3855. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3856. +
  3857. + pkg->local_filename = strdup(filename);
  3858. +
  3859. + if (old) {
  3860. + old_version = pkg_version_str_alloc(old);
  3861. + new_version = pkg_version_str_alloc(pkg);
  3862. +
  3863. + cmp = pkg_compare_versions(old, pkg);
  3864. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3865. + cmp = -1 ; /* then we force ipkg to downgrade */
  3866. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3867. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3868. + }
  3869. + if (cmp > 0) {
  3870. + ipkg_message(conf, IPKG_NOTICE,
  3871. + "Not downgrading package %s on %s from %s to %s.\n",
  3872. + old->name, old->dest->name, old_version, new_version);
  3873. + pkg->state_want = SW_DEINSTALL;
  3874. + pkg->state_flag |= SF_OBSOLETE;
  3875. + free(old_version);
  3876. + free(new_version);
  3877. + return 0;
  3878. + } else {
  3879. + free(old_version);
  3880. + free(new_version);
  3881. + }
  3882. + }
  3883. +
  3884. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3885. + return ipkg_install_pkg(conf, pkg,0);
  3886. +}
  3887. +
  3888. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3889. +{
  3890. + int cmp;
  3891. + pkg_t *old, *new;
  3892. + char *old_version, *new_version;
  3893. +
  3894. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3895. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3896. + if ( old )
  3897. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3898. +
  3899. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3900. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3901. + if ( new )
  3902. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3903. +
  3904. +/* Pigi Basically here is broken the version stuff.
  3905. + What's happening is that nothing provide the version to differents
  3906. + functions, so the returned struct is always the latest.
  3907. + That's why the install by name don't work.
  3908. +*/
  3909. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3910. +
  3911. + if ( old )
  3912. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3913. + if ( new )
  3914. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3915. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3916. +
  3917. + if (new == NULL) {
  3918. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3919. + }
  3920. +
  3921. + new->state_flag |= SF_USER;
  3922. + if (old) {
  3923. + old_version = pkg_version_str_alloc(old);
  3924. + new_version = pkg_version_str_alloc(new);
  3925. +
  3926. + cmp = pkg_compare_versions(old, new);
  3927. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3928. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3929. + cmp = -1 ; /* then we force ipkg to downgrade */
  3930. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3931. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3932. + }
  3933. + ipkg_message(conf, IPKG_DEBUG,
  3934. + "Comparing visible versions of pkg %s:"
  3935. + "\n\t%s is installed "
  3936. + "\n\t%s is available "
  3937. + "\n\t%d was comparison result\n",
  3938. + pkg_name, old_version, new_version, cmp);
  3939. + if (cmp == 0 && !conf->force_reinstall) {
  3940. + ipkg_message(conf, IPKG_NOTICE,
  3941. + "Package %s (%s) installed in %s is up to date.\n",
  3942. + old->name, old_version, old->dest->name);
  3943. + free(old_version);
  3944. + free(new_version);
  3945. + return 0;
  3946. + } else if (cmp > 0) {
  3947. + ipkg_message(conf, IPKG_NOTICE,
  3948. + "Not downgrading package %s on %s from %s to %s.\n",
  3949. + old->name, old->dest->name, old_version, new_version);
  3950. + free(old_version);
  3951. + free(new_version);
  3952. + return 0;
  3953. + } else if (cmp < 0) {
  3954. + new->dest = old->dest;
  3955. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3956. + }
  3957. + }
  3958. +
  3959. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3960. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3961. + return any kind of integer, (might be errno from a syscall,
  3962. + etc.). This is a real mess and will need to be cleaned up if
  3963. + anyone ever wants to make a nice libipkg. */
  3964. +
  3965. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3966. + return ipkg_install_pkg(conf, new,0);
  3967. +}
  3968. +
  3969. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3970. +{
  3971. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3972. + int i;
  3973. + ipkg_error_t err;
  3974. + abstract_pkg_t *ppkg ;
  3975. +
  3976. + if (providers == NULL)
  3977. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3978. +
  3979. + for (i = 0; i < providers->len; i++) {
  3980. + ppkg = abstract_pkg_vec_get(providers, i);
  3981. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3982. + err = ipkg_install_by_name(conf, ppkg->name);
  3983. + if (err)
  3984. + return err;
  3985. +/* XXX Maybe ppkg should be freed ? */
  3986. + }
  3987. + return 0;
  3988. +}
  3989. +
  3990. +/*
  3991. + * Walk dependence graph starting with pkg, collect packages to be
  3992. + * installed into pkgs_needed, in dependence order.
  3993. + */
  3994. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3995. +{
  3996. + int i, err;
  3997. + pkg_vec_t *depends = pkg_vec_alloc();
  3998. + char **unresolved = NULL;
  3999. + int ndepends;
  4000. +
  4001. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4002. + pkg, depends,
  4003. + &unresolved);
  4004. +
  4005. + if (unresolved) {
  4006. + ipkg_message(conf, IPKG_ERROR,
  4007. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4008. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4009. + while (*unresolved) {
  4010. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4011. + unresolved++;
  4012. + }
  4013. + ipkg_message(conf, IPKG_ERROR, "\n");
  4014. + if (! conf->force_depends) {
  4015. + ipkg_message(conf, IPKG_INFO,
  4016. + "This could mean that your package list is out of date or that the packages\n"
  4017. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4018. + "of this problem try again with the '-force-depends' option.\n");
  4019. + pkg_vec_free(depends);
  4020. + return IPKG_PKG_DEPS_UNSATISFIED;
  4021. + }
  4022. + }
  4023. +
  4024. + if (ndepends <= 0) {
  4025. + pkg_vec_free(depends);
  4026. + return 0;
  4027. + }
  4028. +
  4029. + for (i = 0; i < depends->len; i++) {
  4030. + pkg_t *dep = depends->pkgs[i];
  4031. + /* The package was uninstalled when we started, but another
  4032. + dep earlier in this loop may have depended on it and pulled
  4033. + it in, so check first. */
  4034. + if ((dep->state_status != SS_INSTALLED)
  4035. + && (dep->state_status != SS_UNPACKED)
  4036. + && (dep->state_want != SW_INSTALL)) {
  4037. +
  4038. + /* Mark packages as to-be-installed */
  4039. + dep->state_want = SW_INSTALL;
  4040. +
  4041. + /* Dependencies should be installed the same place as pkg */
  4042. + if (dep->dest == NULL) {
  4043. + dep->dest = pkg->dest;
  4044. + }
  4045. +
  4046. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4047. + if (err) {
  4048. + pkg_vec_free(depends);
  4049. + return err;
  4050. + }
  4051. + }
  4052. + }
  4053. + if (pkgs_needed)
  4054. + pkg_vec_insert(pkgs_needed, pkg);
  4055. +
  4056. + pkg_vec_free(depends);
  4057. +
  4058. + return 0;
  4059. +}
  4060. +
  4061. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4062. +{
  4063. + int cmp;
  4064. + pkg_t *old, *new;
  4065. + char *old_version, *new_version;
  4066. +
  4067. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4068. +
  4069. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4070. + if (new == NULL) {
  4071. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4072. + }
  4073. + if (old) {
  4074. + old_version = pkg_version_str_alloc(old);
  4075. + new_version = pkg_version_str_alloc(new);
  4076. +
  4077. + cmp = pkg_compare_versions(old, new);
  4078. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4079. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4080. + cmp = -1 ; /* then we force ipkg to downgrade */
  4081. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4082. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4083. + }
  4084. + ipkg_message(conf, IPKG_DEBUG,
  4085. + "comparing visible versions of pkg %s:"
  4086. + "\n\t%s is installed "
  4087. + "\n\t%s is available "
  4088. + "\n\t%d was comparison result\n",
  4089. + pkg_name, old_version, new_version, cmp);
  4090. + if (cmp == 0 && !conf->force_reinstall) {
  4091. + ipkg_message(conf, IPKG_NOTICE,
  4092. + "Package %s (%s) installed in %s is up to date.\n",
  4093. + old->name, old_version, old->dest->name);
  4094. + free(old_version);
  4095. + free(new_version);
  4096. + return 0;
  4097. + } else if (cmp > 0) {
  4098. + ipkg_message(conf, IPKG_NOTICE,
  4099. + "Not downgrading package %s on %s from %s to %s.\n",
  4100. + old->name, old->dest->name, old_version, new_version);
  4101. + free(old_version);
  4102. + free(new_version);
  4103. + return 0;
  4104. + } else if (cmp < 0) {
  4105. + new->dest = old->dest;
  4106. + old->state_want = SW_DEINSTALL;
  4107. + old->state_flag |= SF_OBSOLETE;
  4108. + }
  4109. + }
  4110. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4111. +}
  4112. +
  4113. +
  4114. +
  4115. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4116. +{
  4117. + int i, err;
  4118. + pkg_vec_t *depends = pkg_vec_alloc();
  4119. + pkg_t *dep;
  4120. + char **unresolved = NULL;
  4121. + int ndepends;
  4122. +
  4123. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4124. + pkg, depends,
  4125. + &unresolved);
  4126. +
  4127. + if (unresolved) {
  4128. + ipkg_message(conf, IPKG_ERROR,
  4129. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4130. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4131. + while (*unresolved) {
  4132. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4133. + unresolved++;
  4134. + }
  4135. + ipkg_message(conf, IPKG_ERROR, "\n");
  4136. + if (! conf->force_depends) {
  4137. + ipkg_message(conf, IPKG_INFO,
  4138. + "This could mean that your package list is out of date or that the packages\n"
  4139. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4140. + "of this problem try again with the '-force-depends' option.\n");
  4141. + pkg_vec_free(depends);
  4142. + return IPKG_PKG_DEPS_UNSATISFIED;
  4143. + }
  4144. + }
  4145. +
  4146. + if (ndepends <= 0) {
  4147. + return 0;
  4148. + }
  4149. +
  4150. + /* Mark packages as to-be-installed */
  4151. + for (i=0; i < depends->len; i++) {
  4152. + /* Dependencies should be installed the same place as pkg */
  4153. + if (depends->pkgs[i]->dest == NULL) {
  4154. + depends->pkgs[i]->dest = pkg->dest;
  4155. + }
  4156. + depends->pkgs[i]->state_want = SW_INSTALL;
  4157. + }
  4158. +
  4159. + for (i = 0; i < depends->len; i++) {
  4160. + dep = depends->pkgs[i];
  4161. + /* The package was uninstalled when we started, but another
  4162. + dep earlier in this loop may have depended on it and pulled
  4163. + it in, so check first. */
  4164. + if ((dep->state_status != SS_INSTALLED)
  4165. + && (dep->state_status != SS_UNPACKED)) {
  4166. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4167. + err = ipkg_install_pkg(conf, dep,0);
  4168. + if (err) {
  4169. + pkg_vec_free(depends);
  4170. + return err;
  4171. + }
  4172. + }
  4173. + }
  4174. +
  4175. + pkg_vec_free(depends);
  4176. +
  4177. + return 0;
  4178. +}
  4179. +
  4180. +
  4181. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4182. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4183. +{
  4184. + if (conf->nodeps == 0) {
  4185. + int i;
  4186. + pkg_vec_t *installed = pkg_vec_alloc();
  4187. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4188. + for (i = 0; i < installed->len; i++) {
  4189. + pkg_t *pkg = installed->pkgs[i];
  4190. + satisfy_dependencies_for(conf, pkg);
  4191. + }
  4192. + pkg_vec_free(installed);
  4193. + }
  4194. + return 0;
  4195. +}
  4196. +
  4197. +
  4198. +
  4199. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4200. +{
  4201. + int i;
  4202. + pkg_vec_t *conflicts = NULL;
  4203. + int level;
  4204. + const char *prefix;
  4205. + if (conf->force_depends) {
  4206. + level = IPKG_NOTICE;
  4207. + prefix = "Warning";
  4208. + } else {
  4209. + level = IPKG_ERROR;
  4210. + prefix = "ERROR";
  4211. + }
  4212. +
  4213. + if (!conf->force_depends)
  4214. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4215. +
  4216. + if (conflicts) {
  4217. + ipkg_message(conf, level,
  4218. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4219. + i = 0;
  4220. + while (i < conflicts->len)
  4221. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4222. + ipkg_message(conf, level, "\n");
  4223. + pkg_vec_free(conflicts);
  4224. + return IPKG_PKG_DEPS_UNSATISFIED;
  4225. + }
  4226. + return 0;
  4227. +}
  4228. +
  4229. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4230. +{
  4231. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4232. + str_list_elt_t *iter;
  4233. +
  4234. + for (iter = new_list->head; iter; iter = iter->next) {
  4235. + char *new_file = iter->data;
  4236. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4237. + if (!new_file)
  4238. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4239. + if (!owner || (owner == old_pkg))
  4240. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4241. + }
  4242. + if (old_pkg) {
  4243. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4244. + for (iter = old_list->head; iter; iter = iter->next) {
  4245. + char *old_file = iter->data;
  4246. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4247. + if (owner == old_pkg) {
  4248. + /* obsolete */
  4249. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4250. + }
  4251. + }
  4252. + }
  4253. + return 0;
  4254. +}
  4255. +
  4256. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4257. +{
  4258. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4259. +
  4260. + /* sma 6.20.02: yup; here's the first bit */
  4261. + /*
  4262. + * XXX: BUG easy for cworth
  4263. + * 1) please point the call below to the correct current root destination
  4264. + * 2) we need to resolve how to check the required space for a pending pkg,
  4265. + * my diddling with the .ipk file size below isn't going to cut it.
  4266. + * 3) return a proper error code instead of 1
  4267. + */
  4268. + int comp_size, blocks_available;
  4269. +
  4270. + if (!conf->force_space && pkg->installed_size != NULL) {
  4271. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4272. +
  4273. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4274. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4275. + comp_size = (int)((comp_size + 1023) / 1024);
  4276. +
  4277. + if (comp_size >= blocks_available) {
  4278. + ipkg_message(conf, IPKG_ERROR,
  4279. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4280. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4281. + return ENOSPC;
  4282. + }
  4283. + }
  4284. + return 0;
  4285. +}
  4286. +
  4287. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4288. +{
  4289. + int err;
  4290. + char *conffiles_file_name;
  4291. + char *root_dir;
  4292. + FILE *conffiles_file;
  4293. +
  4294. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4295. +
  4296. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4297. + if (pkg->tmp_unpack_dir == NULL) {
  4298. + ipkg_message(conf, IPKG_ERROR,
  4299. + "%s: Failed to create temporary directory '%s': %s\n",
  4300. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4301. + return errno;
  4302. + }
  4303. +
  4304. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4305. + if (err) {
  4306. + return err;
  4307. + }
  4308. +
  4309. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4310. + conffiles. Seems like I should be able to get everything to go
  4311. + through pkg_init_from_file. If so, maybe it would make sense to
  4312. + move all of unpack_pkg_control_files to that function. */
  4313. +
  4314. + /* Don't need to re-read conffiles if we already have it */
  4315. + if (pkg->conffiles.head) {
  4316. + return 0;
  4317. + }
  4318. +
  4319. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4320. + if (! file_exists(conffiles_file_name)) {
  4321. + free(conffiles_file_name);
  4322. + return 0;
  4323. + }
  4324. +
  4325. + conffiles_file = fopen(conffiles_file_name, "r");
  4326. + if (conffiles_file == NULL) {
  4327. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4328. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4329. + free(conffiles_file_name);
  4330. + return errno;
  4331. + }
  4332. + free(conffiles_file_name);
  4333. +
  4334. + while (1) {
  4335. + char *cf_name;
  4336. + char *cf_name_in_dest;
  4337. +
  4338. + cf_name = file_read_line_alloc(conffiles_file);
  4339. + if (cf_name == NULL) {
  4340. + break;
  4341. + }
  4342. + str_chomp(cf_name);
  4343. + if (cf_name[0] == '\0') {
  4344. + continue;
  4345. + }
  4346. +
  4347. + /* Prepend dest->root_dir to conffile name.
  4348. + Take pains to avoid multiple slashes. */
  4349. + root_dir = pkg->dest->root_dir;
  4350. + if (conf->offline_root)
  4351. + /* skip the offline_root prefix */
  4352. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4353. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4354. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4355. +
  4356. + /* Can't get an md5sum now, (file isn't extracted yet).
  4357. + We'll wait until resolve_conffiles */
  4358. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4359. +
  4360. + free(cf_name);
  4361. + free(cf_name_in_dest);
  4362. + }
  4363. +
  4364. + fclose(conffiles_file);
  4365. +
  4366. + return 0;
  4367. +}
  4368. +
  4369. +/* returns number of installed replacees */
  4370. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4371. +{
  4372. + abstract_pkg_t **replaces = pkg->replaces;
  4373. + int replaces_count = pkg->replaces_count;
  4374. + int i, j;
  4375. + for (i = 0; i < replaces_count; i++) {
  4376. + abstract_pkg_t *ab_pkg = replaces[i];
  4377. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4378. + if (pkg_vec) {
  4379. + for (j = 0; j < pkg_vec->len; j++) {
  4380. + pkg_t *replacee = pkg_vec->pkgs[j];
  4381. + if (!pkg_conflicts(pkg, replacee))
  4382. + continue;
  4383. + if (replacee->state_status == SS_INSTALLED) {
  4384. + pkg_vec_insert(installed_replacees, replacee);
  4385. + }
  4386. + }
  4387. + }
  4388. + }
  4389. + return installed_replacees->len;
  4390. +}
  4391. +
  4392. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4393. +{
  4394. + int i;
  4395. + int replaces_count = replacees->len;
  4396. + for (i = 0; i < replaces_count; i++) {
  4397. + pkg_t *replacee = replacees->pkgs[i];
  4398. + int err;
  4399. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4400. + err = ipkg_remove_pkg(conf, replacee,0);
  4401. + if (err)
  4402. + return err;
  4403. + }
  4404. + return 0;
  4405. +}
  4406. +
  4407. +/* to unwind the removal: make sure they are installed */
  4408. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4409. +{
  4410. + int i, err;
  4411. + int replaces_count = replacees->len;
  4412. + for (i = 0; i < replaces_count; i++) {
  4413. + pkg_t *replacee = replacees->pkgs[i];
  4414. + if (replacee->state_status != SS_INSTALLED) {
  4415. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4416. + err = ipkg_install_pkg(conf, replacee,0);
  4417. + if (err)
  4418. + return err;
  4419. + }
  4420. + }
  4421. + return 0;
  4422. +}
  4423. +
  4424. +int caught_sigint = 0;
  4425. +static void ipkg_install_pkg_sigint_handler(int sig)
  4426. +{
  4427. + caught_sigint = sig;
  4428. +}
  4429. +
  4430. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4431. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4432. +{
  4433. + if (old_pkg) {
  4434. + char message_out[15];
  4435. + char *old_version = pkg_version_str_alloc(old_pkg);
  4436. + char *new_version = pkg_version_str_alloc(pkg);
  4437. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4438. + int rc = 0;
  4439. +
  4440. + memset(message_out,'\x0',15);
  4441. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4442. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4443. + cmp = -1 ; /* then we force ipkg to downgrade */
  4444. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4445. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4446. + }
  4447. +
  4448. + if (cmp > 0) {
  4449. + ipkg_message(conf, IPKG_NOTICE,
  4450. + "Not downgrading package %s on %s from %s to %s.\n",
  4451. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4452. + rc = 1;
  4453. + } else if (cmp < 0) {
  4454. + ipkg_message(conf, IPKG_NOTICE,
  4455. + "%s%s on %s from %s to %s...\n",
  4456. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4457. + pkg->dest = old_pkg->dest;
  4458. + rc = 0;
  4459. + } else /* cmp == 0 */ {
  4460. + if (conf->force_reinstall) {
  4461. + ipkg_message(conf, IPKG_NOTICE,
  4462. + "Reinstalling %s (%s) on %s...\n",
  4463. + pkg->name, new_version, old_pkg->dest->name);
  4464. + pkg->dest = old_pkg->dest;
  4465. + rc = 0;
  4466. + } else {
  4467. + ipkg_message(conf, IPKG_NOTICE,
  4468. + "Not installing %s (%s) on %s -- already installed.\n",
  4469. + pkg->name, new_version, old_pkg->dest->name);
  4470. + rc = 1;
  4471. + }
  4472. + }
  4473. + free(old_version);
  4474. + free(new_version);
  4475. + return rc;
  4476. + } else {
  4477. + char message_out[15], *version ;
  4478. + memset(message_out,'\x0',15);
  4479. + if ( message )
  4480. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4481. + else
  4482. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4483. + version = pkg_version_str_alloc(pkg);
  4484. +
  4485. + ipkg_message(conf, IPKG_NOTICE,
  4486. + "%s%s (%s) to %s...\n", message_out,
  4487. + pkg->name, version, pkg->dest->name);
  4488. + free(version);
  4489. + return 0;
  4490. + }
  4491. +}
  4492. +
  4493. +/* and now the meat... */
  4494. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4495. +{
  4496. + int err = 0;
  4497. + int message = 0;
  4498. + pkg_t *old_pkg = NULL;
  4499. + pkg_vec_t *replacees;
  4500. + abstract_pkg_t *ab_pkg = NULL;
  4501. + int old_state_flag;
  4502. + uint8_t *file_md5;
  4503. +
  4504. +
  4505. + if ( from_upgrade )
  4506. + message = 1; /* Coming from an upgrade, and should change the output message */
  4507. +
  4508. + if (!pkg) {
  4509. + ipkg_message(conf, IPKG_ERROR,
  4510. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4511. + return -EINVAL;
  4512. + }
  4513. +
  4514. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4515. +
  4516. + if (!pkg_arch_supported(conf, pkg)) {
  4517. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4518. + pkg->architecture, pkg->name);
  4519. + return -EINVAL;
  4520. + }
  4521. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4522. + err = satisfy_dependencies_for(conf, pkg);
  4523. + if (err) { return err; }
  4524. +
  4525. + ipkg_message(conf, IPKG_NOTICE,
  4526. + "Package %s is already installed in %s.\n",
  4527. + pkg->name, pkg->dest->name);
  4528. + return 0;
  4529. + }
  4530. +
  4531. + if (pkg->dest == NULL) {
  4532. + pkg->dest = conf->default_dest;
  4533. + }
  4534. +
  4535. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4536. +
  4537. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4538. + if (err) { return err; }
  4539. +
  4540. + pkg->state_want = SW_INSTALL;
  4541. + if (old_pkg){
  4542. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4543. + }
  4544. +
  4545. +
  4546. + /* Abhaya: conflicts check */
  4547. + err = check_conflicts_for(conf, pkg);
  4548. + if (err) { return err; }
  4549. +
  4550. + /* this setup is to remove the upgrade scenario in the end when
  4551. + installing pkg A, A deps B & B deps on A. So both B and A are
  4552. + installed. Then A's installation is started resulting in an
  4553. + uncecessary upgrade */
  4554. + if (pkg->state_status == SS_INSTALLED
  4555. + && conf->force_reinstall == 0) return 0;
  4556. +
  4557. + err = verify_pkg_installable(conf, pkg);
  4558. + if (err) { return err; }
  4559. +
  4560. + if (pkg->local_filename == NULL) {
  4561. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4562. + if (err) {
  4563. + ipkg_message(conf, IPKG_ERROR,
  4564. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4565. + pkg->name);
  4566. + return err;
  4567. + }
  4568. + }
  4569. +
  4570. +/* Check for md5 values */
  4571. + if (pkg->md5sum)
  4572. + {
  4573. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4574. + if (strcmp((char *)file_md5, pkg->md5sum))
  4575. + {
  4576. + ipkg_message(conf, IPKG_ERROR,
  4577. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4578. + pkg->name);
  4579. + free(file_md5);
  4580. + return err;
  4581. + }
  4582. + free(file_md5);
  4583. + }
  4584. +
  4585. + if (pkg->tmp_unpack_dir == NULL) {
  4586. + unpack_pkg_control_files(conf, pkg);
  4587. + }
  4588. +
  4589. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4590. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4591. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4592. + err = update_file_ownership(conf, pkg, old_pkg);
  4593. + if (err) { return err; }
  4594. +
  4595. + if (conf->nodeps == 0) {
  4596. + err = satisfy_dependencies_for(conf, pkg);
  4597. + if (err) { return err; }
  4598. + }
  4599. +
  4600. + replacees = pkg_vec_alloc();
  4601. + pkg_get_installed_replacees(pkg, replacees);
  4602. +
  4603. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4604. + {
  4605. + sigset_t newset, oldset;
  4606. + sighandler_t old_handler = NULL;
  4607. + int use_signal = 0;
  4608. + caught_sigint = 0;
  4609. + if (use_signal) {
  4610. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4611. + } else {
  4612. + sigemptyset(&newset);
  4613. + sigaddset(&newset, SIGINT);
  4614. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4615. + }
  4616. +
  4617. + ipkg_state_changed++;
  4618. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4619. +
  4620. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4621. + * Instead, we're going to remove the replacees
  4622. + */
  4623. + err = pkg_remove_installed_replacees(conf, replacees);
  4624. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4625. +
  4626. + /*
  4627. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4628. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4629. +
  4630. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4631. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4632. + */
  4633. +
  4634. + err = preinst_configure(conf, pkg, old_pkg);
  4635. + /*
  4636. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4637. + */
  4638. +
  4639. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4640. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4641. +
  4642. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4643. + /*
  4644. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4645. +
  4646. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4647. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4648. + */
  4649. +
  4650. + if (conf->noaction) return 0;
  4651. +
  4652. + /* point of no return: no unwinding after this */
  4653. + if (old_pkg && !conf->force_reinstall) {
  4654. + old_pkg->state_want = SW_DEINSTALL;
  4655. +
  4656. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4657. + ipkg_message(conf, IPKG_INFO,
  4658. + " not removing obsolesced files because package marked noprune\n");
  4659. + } else {
  4660. + ipkg_message(conf, IPKG_INFO,
  4661. + " removing obsolesced files\n");
  4662. + remove_obsolesced_files(conf, pkg, old_pkg);
  4663. + }
  4664. + /* removing files from old package, to avoid ghost files */
  4665. + remove_data_files_and_list(conf, old_pkg);
  4666. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4667. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4668. + remove_postrm(conf, old_pkg);
  4669. +/* Pigi */
  4670. +
  4671. + }
  4672. +
  4673. +
  4674. + ipkg_message(conf, IPKG_INFO,
  4675. + " installing maintainer scripts\n");
  4676. + install_maintainer_scripts(conf, pkg, old_pkg);
  4677. +
  4678. + /* the following just returns 0
  4679. + remove_disappeared(conf, pkg);
  4680. + */
  4681. +
  4682. + ipkg_message(conf, IPKG_INFO,
  4683. + " installing data files\n");
  4684. + install_data_files(conf, pkg);
  4685. +
  4686. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4687. + err = check_data_file_clashes_change(conf, pkg);
  4688. +
  4689. + ipkg_message(conf, IPKG_INFO,
  4690. + " resolving conf files\n");
  4691. + resolve_conffiles(conf, pkg);
  4692. +
  4693. + pkg->state_status = SS_UNPACKED;
  4694. + old_state_flag = pkg->state_flag;
  4695. + pkg->state_flag &= ~SF_PREFER;
  4696. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4697. +
  4698. + if (old_pkg && !conf->force_reinstall) {
  4699. + old_pkg->state_status = SS_NOT_INSTALLED;
  4700. + }
  4701. +
  4702. + time(&pkg->installed_time);
  4703. +
  4704. + ipkg_message(conf, IPKG_INFO,
  4705. + " cleanup temp files\n");
  4706. + cleanup_temporary_files(conf, pkg);
  4707. +
  4708. + ab_pkg = pkg->parent;
  4709. + if (ab_pkg)
  4710. + ab_pkg->state_status = pkg->state_status;
  4711. +
  4712. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4713. +
  4714. + if (use_signal)
  4715. + signal(SIGINT, old_handler);
  4716. + else
  4717. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4718. +
  4719. + return 0;
  4720. +
  4721. +
  4722. + /*
  4723. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4724. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4725. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4726. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4727. + */
  4728. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4729. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4730. + /*
  4731. + UNWIND_PREINST_CONFIGURE:
  4732. + preinst_configure_unwind(conf, pkg, old_pkg);
  4733. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4734. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4735. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4736. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4737. + */
  4738. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4739. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4740. +
  4741. + ipkg_message(conf, IPKG_INFO,
  4742. + " cleanup temp files\n");
  4743. + cleanup_temporary_files(conf, pkg);
  4744. +
  4745. + ipkg_message(conf, IPKG_INFO,
  4746. + "Failed.\n");
  4747. + if (use_signal)
  4748. + signal(SIGINT, old_handler);
  4749. + else
  4750. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4751. +
  4752. + return err;
  4753. + }
  4754. +}
  4755. +
  4756. +/*
  4757. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4758. +{
  4759. + DPKG_INCOMPATIBILITY:
  4760. + dpkg does some things here that we don't do yet. Do we care?
  4761. +
  4762. + 1. If a version of the package is already installed, call
  4763. + old-prerm upgrade new-version
  4764. + 2. If the script runs but exits with a non-zero exit status
  4765. + new-prerm failed-upgrade old-version
  4766. + Error unwind, for both the above cases:
  4767. + old-postinst abort-upgrade new-version
  4768. + return 0;
  4769. +}
  4770. +*/
  4771. +
  4772. +/*
  4773. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4774. +{
  4775. + DPKG_INCOMPATIBILITY:
  4776. + dpkg does some things here that we don't do yet. Do we care?
  4777. + (See prerm_upgrade_old_package for details)
  4778. +
  4779. + return 0;
  4780. +}
  4781. +*/
  4782. +
  4783. +/*
  4784. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4785. +{
  4786. + DPKG_INCOMPATIBILITY:
  4787. + dpkg does some things here that we don't do yet. Do we care?
  4788. + 2. If a 'conflicting' package is being removed at the same time:
  4789. + 1. If any packages depended on that conflicting package and
  4790. + --auto-deconfigure is specified, call, for each such package:
  4791. + deconfigured's-prerm deconfigure \
  4792. + in-favour package-being-installed version \
  4793. + removing conflicting-package version
  4794. + Error unwind:
  4795. + deconfigured's-postinst abort-deconfigure \
  4796. + in-favour package-being-installed-but-failed version \
  4797. + removing conflicting-package version
  4798. +
  4799. + The deconfigured packages are marked as requiring
  4800. + configuration, so that if --install is used they will be
  4801. + configured again if possible.
  4802. + 2. To prepare for removal of the conflicting package, call:
  4803. + conflictor's-prerm remove in-favour package new-version
  4804. + Error unwind:
  4805. + conflictor's-postinst abort-remove in-favour package new-version
  4806. + return 0;
  4807. +}
  4808. +*/
  4809. +
  4810. +/*
  4811. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4812. +{
  4813. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4814. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4815. + details)
  4816. + return 0;
  4817. +}
  4818. +*/
  4819. +
  4820. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4821. +{
  4822. + int err;
  4823. + char *preinst_args;
  4824. +
  4825. + if (old_pkg) {
  4826. + char *old_version = pkg_version_str_alloc(old_pkg);
  4827. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4828. + free(old_version);
  4829. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4830. + char *pkg_version = pkg_version_str_alloc(pkg);
  4831. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4832. + free(pkg_version);
  4833. + } else {
  4834. + preinst_args = strdup("install");
  4835. + }
  4836. +
  4837. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4838. + if (err) {
  4839. + ipkg_message(conf, IPKG_ERROR,
  4840. + "Aborting installation of %s\n", pkg->name);
  4841. + return 1;
  4842. + }
  4843. +
  4844. + free(preinst_args);
  4845. +
  4846. + return 0;
  4847. +}
  4848. +
  4849. +/*
  4850. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4851. +{
  4852. + DPKG_INCOMPATIBILITY:
  4853. + dpkg does the following error unwind, should we?
  4854. + pkg->postrm abort-upgrade old-version
  4855. + OR pkg->postrm abort-install old-version
  4856. + OR pkg->postrm abort-install
  4857. + return 0;
  4858. +}
  4859. +*/
  4860. +
  4861. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4862. +{
  4863. + int err;
  4864. + conffile_list_elt_t *iter;
  4865. + conffile_t *cf;
  4866. +
  4867. + if (conf->noaction) return 0;
  4868. +
  4869. + /* Backup all modified conffiles */
  4870. + if (old_pkg) {
  4871. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4872. + char *cf_name;
  4873. +
  4874. + cf = iter->data;
  4875. + cf_name = root_filename_alloc(conf, cf->name);
  4876. +
  4877. + /* Don't worry if the conffile is just plain gone */
  4878. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4879. + err = backup_make_backup(conf, cf_name);
  4880. + if (err) {
  4881. + return err;
  4882. + }
  4883. + }
  4884. + free(cf_name);
  4885. + }
  4886. + }
  4887. +
  4888. + /* Backup all conffiles that were not conffiles in old_pkg */
  4889. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4890. + char *cf_name;
  4891. + cf = iter->data;
  4892. + cf_name = root_filename_alloc(conf, cf->name);
  4893. + /* Ignore if this was a conffile in old_pkg as well */
  4894. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4895. + continue;
  4896. + }
  4897. +
  4898. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4899. + err = backup_make_backup(conf, cf_name);
  4900. + if (err) {
  4901. + return err;
  4902. + }
  4903. + }
  4904. + free(cf_name);
  4905. + }
  4906. +
  4907. + return 0;
  4908. +}
  4909. +
  4910. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4911. +{
  4912. + conffile_list_elt_t *iter;
  4913. +
  4914. + if (old_pkg) {
  4915. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4916. + backup_remove(iter->data->name);
  4917. + }
  4918. + }
  4919. +
  4920. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4921. + backup_remove(iter->data->name);
  4922. + }
  4923. +
  4924. + return 0;
  4925. +}
  4926. +
  4927. +
  4928. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4929. +{
  4930. + /* DPKG_INCOMPATIBILITY:
  4931. + ipkg takes a slightly different approach than dpkg at this
  4932. + point. dpkg installs each file in the new package while
  4933. + creating a backup for any file that is replaced, (so that it
  4934. + can unwind if necessary). To avoid complexity and redundant
  4935. + storage, ipkg doesn't do any installation until later, (at the
  4936. + point at which dpkg removes the backups.
  4937. +
  4938. + But, we do have to check for data file clashes, since after
  4939. + installing a package with a file clash, removing either of the
  4940. + packages involved in the clash has the potential to break the
  4941. + other package.
  4942. + */
  4943. + str_list_t *files_list;
  4944. + str_list_elt_t *iter;
  4945. +
  4946. + int clashes = 0;
  4947. +
  4948. + files_list = pkg_get_installed_files(pkg);
  4949. + for (iter = files_list->head; iter; iter = iter->next) {
  4950. + char *root_filename;
  4951. + char *filename = iter->data;
  4952. + root_filename = root_filename_alloc(conf, filename);
  4953. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4954. + pkg_t *owner;
  4955. + pkg_t *obs;
  4956. + /* Pre-existing conffiles are OK */
  4957. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4958. + if (backup_exists_for(root_filename)) {
  4959. + continue;
  4960. + }
  4961. +
  4962. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4963. + if (conf->force_overwrite) {
  4964. + /* but we need to change who owns this file */
  4965. + file_hash_set_file_owner(conf, filename, pkg);
  4966. + continue;
  4967. + }
  4968. +
  4969. + owner = file_hash_get_file_owner(conf, filename);
  4970. +
  4971. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4972. + if (owner && old_pkg) {
  4973. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4974. + continue;
  4975. + }
  4976. + }
  4977. +
  4978. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4979. + if (owner) {
  4980. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4981. + if (pkg_replaces(pkg, owner)) {
  4982. + continue;
  4983. + }
  4984. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4985. + then it's ok to overwrite. */
  4986. + if (strcmp(owner->name,pkg->name)==0){
  4987. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4988. + continue;
  4989. + }
  4990. + }
  4991. +
  4992. + /* Pre-existing files are OK if they are obsolete */
  4993. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4994. + if (obs) {
  4995. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4996. + continue;
  4997. + }
  4998. +
  4999. + /* We have found a clash. */
  5000. + ipkg_message(conf, IPKG_ERROR,
  5001. + "Package %s wants to install file %s\n"
  5002. + "\tBut that file is already provided by package ",
  5003. + pkg->name, filename);
  5004. + if (owner) {
  5005. + ipkg_message(conf, IPKG_ERROR,
  5006. + "%s\n", owner->name);
  5007. + } else {
  5008. + ipkg_message(conf, IPKG_ERROR,
  5009. + "<no package>\nPlease move this file out of the way and try again.\n");
  5010. + }
  5011. + clashes++;
  5012. + }
  5013. + free(root_filename);
  5014. + }
  5015. + pkg_free_installed_files(pkg);
  5016. +
  5017. + return clashes;
  5018. +}
  5019. +
  5020. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5021. +{
  5022. + /* Basically that's the worst hack I could do to be able to change ownership of
  5023. + file list, but, being that we have no way to unwind the mods, due to structure
  5024. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5025. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5026. + happens )
  5027. + Only the action that are needed to change name should be considered.
  5028. + @@@ To change after 1.0 release.
  5029. + */
  5030. + str_list_t *files_list;
  5031. + str_list_elt_t *iter;
  5032. +
  5033. + int clashes = 0;
  5034. +
  5035. + files_list = pkg_get_installed_files(pkg);
  5036. + for (iter = files_list->head; iter; iter = iter->next) {
  5037. + char *root_filename;
  5038. + char *filename = iter->data;
  5039. + root_filename = root_filename_alloc(conf, filename);
  5040. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5041. + pkg_t *owner;
  5042. +
  5043. + if (conf->force_overwrite) {
  5044. + /* but we need to change who owns this file */
  5045. + file_hash_set_file_owner(conf, filename, pkg);
  5046. + continue;
  5047. + }
  5048. +
  5049. + owner = file_hash_get_file_owner(conf, filename);
  5050. +
  5051. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5052. + if (owner) {
  5053. + if (pkg_replaces(pkg, owner)) {
  5054. +/* It's now time to change the owner of that file.
  5055. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5056. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5057. + file_hash_set_file_owner(conf, filename, pkg);
  5058. + continue;
  5059. + }
  5060. + }
  5061. +
  5062. + }
  5063. + free(root_filename);
  5064. + }
  5065. + pkg_free_installed_files(pkg);
  5066. +
  5067. + return clashes;
  5068. +}
  5069. +
  5070. +/*
  5071. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5072. +{
  5073. + Nothing to do since check_data_file_clashes doesn't change state
  5074. + return 0;
  5075. +}
  5076. +*/
  5077. +
  5078. +/*
  5079. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5080. +{
  5081. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5082. + 1. If the package is being upgraded, call
  5083. + old-postrm upgrade new-version
  5084. + 2. If this fails, attempt:
  5085. + new-postrm failed-upgrade old-version
  5086. + Error unwind, for both cases:
  5087. + old-preinst abort-upgrade new-version
  5088. + return 0;
  5089. +}
  5090. +*/
  5091. +
  5092. +/*
  5093. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5094. +{
  5095. + DPKG_INCOMPATIBILITY:
  5096. + dpkg does some things here that we don't do yet. Do we care?
  5097. + (See postrm_upgrade_old_pkg for details)
  5098. + return 0;
  5099. +}
  5100. +*/
  5101. +
  5102. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5103. +{
  5104. + int err;
  5105. + str_list_t *old_files;
  5106. + str_list_elt_t *of;
  5107. + str_list_t *new_files;
  5108. + str_list_elt_t *nf;
  5109. +
  5110. + if (old_pkg == NULL) {
  5111. + return 0;
  5112. + }
  5113. +
  5114. + old_files = pkg_get_installed_files(old_pkg);
  5115. + new_files = pkg_get_installed_files(pkg);
  5116. +
  5117. + for (of = old_files->head; of; of = of->next) {
  5118. + pkg_t *owner;
  5119. + char *old, *new;
  5120. + old = of->data;
  5121. + for (nf = new_files->head; nf; nf = nf->next) {
  5122. + new = nf->data;
  5123. + if (strcmp(old, new) == 0) {
  5124. + goto NOT_OBSOLETE;
  5125. + }
  5126. + }
  5127. + if (file_is_dir(old)) {
  5128. + continue;
  5129. + }
  5130. + owner = file_hash_get_file_owner(conf, old);
  5131. + if (owner != old_pkg) {
  5132. + /* in case obsolete file no longer belongs to old_pkg */
  5133. + continue;
  5134. + }
  5135. +
  5136. + /* old file is obsolete */
  5137. + ipkg_message(conf, IPKG_INFO,
  5138. + " removing obsolete file %s\n", old);
  5139. + if (!conf->noaction) {
  5140. + err = unlink(old);
  5141. + if (err) {
  5142. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5143. + strerror(errno));
  5144. + }
  5145. + }
  5146. +
  5147. + NOT_OBSOLETE:
  5148. + ;
  5149. + }
  5150. +
  5151. + pkg_free_installed_files(old_pkg);
  5152. + pkg_free_installed_files(pkg);
  5153. +
  5154. + return 0;
  5155. +}
  5156. +
  5157. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5158. +{
  5159. + int i;
  5160. + int err = 0;
  5161. + char *globpattern;
  5162. + glob_t globbuf;
  5163. + if (0) {
  5164. + if (!pkg->dest) {
  5165. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5166. + return -1;
  5167. + }
  5168. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5169. + err = glob(globpattern, 0, NULL, &globbuf);
  5170. + free(globpattern);
  5171. + if (err) {
  5172. + return err;
  5173. + }
  5174. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5175. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5176. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5177. + globbuf.gl_pathv[i], old_pkg->name);
  5178. + if (!conf->noaction)
  5179. + unlink(globbuf.gl_pathv[i]);
  5180. + }
  5181. + globfree(&globbuf);
  5182. + }
  5183. + return err;
  5184. +}
  5185. +
  5186. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5187. +{
  5188. + int ret;
  5189. + char *prefix;
  5190. +
  5191. + if (old_pkg)
  5192. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5193. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5194. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5195. + pkg->dest->info_dir,
  5196. + prefix);
  5197. + free(prefix);
  5198. + return ret;
  5199. +}
  5200. +
  5201. +/*
  5202. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5203. +{
  5204. + DPKG_INCOMPATIBILITY:
  5205. + This is a fairly sophisticated dpkg operation. Shall we
  5206. + skip it?
  5207. +
  5208. + Any packages all of whose files have been overwritten during the
  5209. + installation, and which aren't required for dependencies, are
  5210. + considered to have been removed. For each such package
  5211. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5212. + 2. The package's maintainer scripts are removed
  5213. + 3. It is noted in the status database as being in a sane state,
  5214. + namely not installed (any conffiles it may have are ignored,
  5215. + rather than being removed by dpkg). Note that disappearing
  5216. + packages do not have their prerm called, because dpkg doesn't
  5217. + know in advance that the package is going to vanish.
  5218. +
  5219. +
  5220. + return 0;
  5221. +}
  5222. +*/
  5223. +
  5224. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5225. +{
  5226. + int err;
  5227. +
  5228. + /* ipkg takes a slightly different approach to data file backups
  5229. + than dpkg. Rather than removing backups at this point, we
  5230. + actually do the data file installation now. See comments in
  5231. + check_data_file_clashes() for more details. */
  5232. +
  5233. + ipkg_message(conf, IPKG_INFO,
  5234. + " extracting data files to %s\n", pkg->dest->root_dir);
  5235. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5236. + if (err) {
  5237. + return err;
  5238. + }
  5239. +
  5240. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5241. + so we can't save ourself from removing important packages
  5242. + At this point we (should) have extracted the .control file, so it
  5243. + would be a good idea to reload the data in it, and set the Essential
  5244. + state in *pkg. From now on the Essential is back in status file and
  5245. + we can protect again.
  5246. + We should operate this way:
  5247. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5248. + check for "Essential" in it
  5249. + set the value in pkg->essential.
  5250. + This new routine could be useful also for every other flag
  5251. + Pigi: 16/03/2004 */
  5252. + set_flags_from_control(conf, pkg) ;
  5253. +
  5254. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5255. + err = pkg_write_filelist(conf, pkg);
  5256. + if (err)
  5257. + return err;
  5258. +
  5259. + /* XXX: FEATURE: ipkg should identify any files which existed
  5260. + before installation and which were overwritten, (see
  5261. + check_data_file_clashes()). What it must do is remove any such
  5262. + files from the filelist of the old package which provided the
  5263. + file. Otherwise, if the old package were removed at some point
  5264. + it would break the new package. Removing the new package will
  5265. + also break the old one, but this cannot be helped since the old
  5266. + package's file has already been deleted. This is the importance
  5267. + of check_data_file_clashes(), and only allowing ipkg to install
  5268. + a clashing package with a user force. */
  5269. +
  5270. + return 0;
  5271. +}
  5272. +
  5273. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5274. +{
  5275. + conffile_list_elt_t *iter;
  5276. + conffile_t *cf;
  5277. + char *cf_backup;
  5278. + uint8_t *md5sum;
  5279. +
  5280. +
  5281. + if (conf->noaction) return 0;
  5282. +
  5283. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5284. + char *root_filename;
  5285. + cf = iter->data;
  5286. + root_filename = root_filename_alloc(conf, cf->name);
  5287. +
  5288. + /* Might need to initialize the md5sum for each conffile */
  5289. + if (cf->value == NULL) {
  5290. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5291. + }
  5292. +
  5293. + if (!file_exists(root_filename)) {
  5294. + free(root_filename);
  5295. + continue;
  5296. + }
  5297. +
  5298. + cf_backup = backup_filename_alloc(root_filename);
  5299. +
  5300. +
  5301. + if (file_exists(cf_backup)) {
  5302. + /* Let's compute md5 to test if files are changed */
  5303. + md5sum = file_md5sum_alloc(cf_backup);
  5304. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5305. + if (conf->force_defaults
  5306. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5307. + rename(cf_backup, root_filename);
  5308. + }
  5309. + }
  5310. + unlink(cf_backup);
  5311. + free(md5sum);
  5312. + }
  5313. +
  5314. + free(cf_backup);
  5315. + free(root_filename);
  5316. + }
  5317. +
  5318. + return 0;
  5319. +}
  5320. +
  5321. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5322. +{
  5323. + char *response;
  5324. + const char *short_file_name;
  5325. +
  5326. + short_file_name = strrchr(file_name, '/');
  5327. + if (short_file_name) {
  5328. + short_file_name++;
  5329. + } else {
  5330. + short_file_name = file_name;
  5331. + }
  5332. +
  5333. + while (1) {
  5334. + response = get_user_response(" Configuration file '%s'\n"
  5335. + " ==> File on system created by you or by a script.\n"
  5336. + " ==> File also in package provided by package maintainer.\n"
  5337. + " What would you like to do about it ? Your options are:\n"
  5338. + " Y or I : install the package maintainer's version\n"
  5339. + " N or O : keep your currently-installed version\n"
  5340. +#ifdef CONFIG_DIFF
  5341. + " D : show the differences between the versions\n"
  5342. +#endif
  5343. + " The default action is to keep your current version.\n"
  5344. + " *** %s (Y/I/N/O"
  5345. +#ifdef CONFIG_DIFF
  5346. + "/D"
  5347. +#endif
  5348. + ") [default=N] ? ", file_name, short_file_name);
  5349. + if (strcmp(response, "y") == 0
  5350. + || strcmp(response, "i") == 0
  5351. + || strcmp(response, "yes") == 0) {
  5352. + free(response);
  5353. + return 0;
  5354. + }
  5355. +
  5356. +#ifdef CONFIG_DIFF
  5357. + if (strcmp(response, "d") == 0) {
  5358. + char *cmd;
  5359. +
  5360. + free(response);
  5361. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5362. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5363. + xsystem(cmd);
  5364. + free(cmd);
  5365. + printf(" [Press ENTER to continue]\n");
  5366. + response = file_read_line_alloc(stdin);
  5367. + free(response);
  5368. + continue;
  5369. + }
  5370. +#endif
  5371. +
  5372. + free(response);
  5373. + return 1;
  5374. + }
  5375. +}
  5376. +
  5377. +/* XXX: CLEANUP: I'd like to move all of the code for
  5378. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5379. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5380. + pkg_deinit for example). */
  5381. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5382. +{
  5383. + DIR *tmp_dir;
  5384. + struct dirent *dirent;
  5385. + char *tmp_file;
  5386. +
  5387. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5388. +#error
  5389. + ipkg_message(conf, IPKG_DEBUG,
  5390. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5391. + __FUNCTION__, pkg->tmp_unpack_dir);
  5392. + return 0;
  5393. +#endif
  5394. +
  5395. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5396. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5397. + if (tmp_dir) {
  5398. + while (1) {
  5399. + dirent = readdir(tmp_dir);
  5400. + if (dirent == NULL) {
  5401. + break;
  5402. + }
  5403. + sprintf_alloc(&tmp_file, "%s/%s",
  5404. + pkg->tmp_unpack_dir, dirent->d_name);
  5405. + if (! file_is_dir(tmp_file)) {
  5406. + unlink(tmp_file);
  5407. + }
  5408. + free(tmp_file);
  5409. + }
  5410. + closedir(tmp_dir);
  5411. + rmdir(pkg->tmp_unpack_dir);
  5412. + free(pkg->tmp_unpack_dir);
  5413. + pkg->tmp_unpack_dir = NULL;
  5414. + }
  5415. + }
  5416. +
  5417. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5418. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5419. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5420. + unlink(pkg->local_filename);
  5421. + free(pkg->local_filename);
  5422. + pkg->local_filename = NULL;
  5423. + }
  5424. +
  5425. + return 0;
  5426. +}
  5427. +
  5428. +static char *backup_filename_alloc(const char *file_name)
  5429. +{
  5430. + char *backup;
  5431. +
  5432. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5433. +
  5434. + return backup;
  5435. +}
  5436. +
  5437. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5438. +{
  5439. + int err;
  5440. + char *backup;
  5441. +
  5442. + backup = backup_filename_alloc(file_name);
  5443. + err = file_copy(file_name, backup);
  5444. + if (err) {
  5445. + ipkg_message(conf, IPKG_ERROR,
  5446. + "%s: Failed to copy %s to %s\n",
  5447. + __FUNCTION__, file_name, backup);
  5448. + }
  5449. +
  5450. + free(backup);
  5451. +
  5452. + return err;
  5453. +}
  5454. +
  5455. +static int backup_exists_for(const char *file_name)
  5456. +{
  5457. + int ret;
  5458. + char *backup;
  5459. +
  5460. + backup = backup_filename_alloc(file_name);
  5461. +
  5462. + ret = file_exists(backup);
  5463. +
  5464. + free(backup);
  5465. +
  5466. + return ret;
  5467. +}
  5468. +
  5469. +static int backup_remove(const char *file_name)
  5470. +{
  5471. + char *backup;
  5472. +
  5473. + backup = backup_filename_alloc(file_name);
  5474. + unlink(backup);
  5475. + free(backup);
  5476. +
  5477. + return 0;
  5478. +}
  5479. +
  5480. +
  5481. +
  5482. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5483. +
  5484. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5485. +{
  5486. + /* first, remove the packages that need removing */
  5487. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5488. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5489. + err = ipkg_remove_pkg(conf, pkg,0);
  5490. + if (err) return err;
  5491. + }
  5492. + return 0;
  5493. +}
  5494. +
  5495. +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5496. +{
  5497. + int i;
  5498. + /* now one more pass checking on the ones that need to be installed */
  5499. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5500. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5501. + if (pkg->dest == NULL)
  5502. + pkg->dest = conf->default_dest;
  5503. +
  5504. + pkg->state_want = SW_INSTALL;
  5505. +
  5506. + /* Abhaya: conflicts check */
  5507. + err = check_conflicts_for(conf, pkg);
  5508. + if (err) { return err; }
  5509. + }
  5510. + return 0;
  5511. +}
  5512. +
  5513. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5514. +{
  5515. + int i;
  5516. + /* now one more pass checking on the ones that need to be installed */
  5517. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5518. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5519. +
  5520. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5521. + pkg_vec_t *replacees = pkg_vec_alloc();
  5522. + pkg_get_installed_replacees(pkg, replacees);
  5523. +
  5524. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5525. + * Instead, we're going to remove the replacees
  5526. + */
  5527. + err = pkg_remove_installed_replacees(conf, replacees);
  5528. + if (err) return err;
  5529. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5530. + }
  5531. + return 0;
  5532. +}
  5533. +
  5534. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5535. +{
  5536. + int i;
  5537. + /* now one more pass checking on the ones that need to be installed */
  5538. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5539. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5540. + if (pkg->local_filename == NULL) {
  5541. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5542. + if (err) {
  5543. + ipkg_message(conf, IPKG_ERROR,
  5544. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5545. + pkg->name);
  5546. + return err;
  5547. + }
  5548. + }
  5549. + if (pkg->tmp_unpack_dir == NULL) {
  5550. + err = unpack_pkg_control_files(conf, pkg);
  5551. + if (err) return err;
  5552. + }
  5553. + }
  5554. + return 0;
  5555. +}
  5556. +
  5557. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5558. +{
  5559. + int i;
  5560. + /* now one more pass checking on the ones that need to be installed */
  5561. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5562. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5563. + pkg_t *old_pkg = pkg->old_pkg;
  5564. +
  5565. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5566. + if (err) return err;
  5567. +
  5568. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5569. + if (err) return err;
  5570. +
  5571. + err = preinst_configure(conf, pkg, old_pkg);
  5572. + if (err) return err;
  5573. +
  5574. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5575. + if (err) return err;
  5576. +
  5577. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5578. + if (err) return err;
  5579. + }
  5580. + return 0;
  5581. +}
  5582. +
  5583. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5584. +{
  5585. + int i;
  5586. + /* now one more pass checking on the ones that need to be installed */
  5587. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5588. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5589. + pkg_t *old_pkg = pkg->old_pkg;
  5590. +
  5591. + if (old_pkg) {
  5592. + old_pkg->state_want = SW_DEINSTALL;
  5593. +
  5594. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5595. + ipkg_message(conf, IPKG_INFO,
  5596. + " not removing obsolesced files because package marked noprune\n");
  5597. + } else {
  5598. + ipkg_message(conf, IPKG_INFO,
  5599. + " removing obsolesced files\n");
  5600. + remove_obsolesced_files(conf, pkg, old_pkg);
  5601. + }
  5602. + }
  5603. +
  5604. + ipkg_message(conf, IPKG_INFO,
  5605. + " installing maintainer scripts\n");
  5606. + install_maintainer_scripts(conf, pkg, old_pkg);
  5607. +
  5608. + /* the following just returns 0 */
  5609. + remove_disappeared(conf, pkg);
  5610. +
  5611. + ipkg_message(conf, IPKG_INFO,
  5612. + " installing data files\n");
  5613. + install_data_files(conf, pkg);
  5614. +
  5615. + ipkg_message(conf, IPKG_INFO,
  5616. + " resolving conf files\n");
  5617. + resolve_conffiles(conf, pkg);
  5618. +
  5619. + pkg->state_status = SS_UNPACKED;
  5620. +
  5621. + if (old_pkg) {
  5622. + old_pkg->state_status = SS_NOT_INSTALLED;
  5623. + }
  5624. +
  5625. + time(&pkg->installed_time);
  5626. +
  5627. + ipkg_message(conf, IPKG_INFO,
  5628. + " cleanup temp files\n");
  5629. + cleanup_temporary_files(conf, pkg);
  5630. +
  5631. + if (pkg->parent)
  5632. + pkg->parent->state_status = pkg->state_status;
  5633. + }
  5634. + return 0;
  5635. +}
  5636. +
  5637. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5638. +{
  5639. + int i;
  5640. + /* now one more pass checking on the ones that need to be installed */
  5641. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5642. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5643. + pkg_t *old_pkg = pkg->old_pkg;
  5644. +
  5645. + if (old_pkg) {
  5646. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5647. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5648. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5649. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5650. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5651. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5652. + */
  5653. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5654. + preinst_configure_unwind(conf, pkg, old_pkg);
  5655. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5656. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5657. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5658. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5659. + */
  5660. +
  5661. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5662. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5663. +
  5664. + }
  5665. + }
  5666. + return 0;
  5667. +}
  5668. +
  5669. +/*
  5670. + * Perform all the actions.
  5671. + *
  5672. + * pkgs_to_remove are packages marked for removal.
  5673. + * pkgs_superseded are the old packages being replaced by upgrades.
  5674. + *
  5675. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5676. + */
  5677. +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5678. +{
  5679. + int err;
  5680. + int i;
  5681. +
  5682. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5683. + if (err) return err;
  5684. +
  5685. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5686. + if (err) return err;
  5687. +
  5688. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5689. + if (err) goto UNWIND;
  5690. +
  5691. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5692. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5693. + if (err) goto UNWIND;
  5694. +
  5695. + /*
  5696. + * Now that we have the packages unpacked, we can look for data
  5697. + * file clashes. First, we mark the files from the superseded
  5698. + * packages as obsolete. Then we scan the files in
  5699. + * pkgs_to_install, and only complain about clashes with
  5700. + * non-obsolete files.
  5701. + */
  5702. +
  5703. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5704. + if (err) goto UNWIND;
  5705. +
  5706. + /* this was before checking data file clashes */
  5707. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5708. + if (err) goto UNWIND;
  5709. +
  5710. + /* point of no return: no unwinding after this */
  5711. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5712. + if (err) return err;
  5713. +
  5714. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5715. + return 0;
  5716. +
  5717. + UNWIND:
  5718. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5719. +
  5720. + ipkg_message(conf, IPKG_INFO,
  5721. + " cleanup temp files\n");
  5722. + cleanup_temporary_files(conf, pkg);
  5723. +
  5724. + ipkg_message(conf, IPKG_INFO,
  5725. + "Failed.\n");
  5726. + return err;
  5727. +}
  5728. +
  5729. +#endif
  5730. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_install.h busybox-1.26.0/archival/libipkg/ipkg_install.h
  5731. --- busybox-1.26.0.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5732. +++ busybox-1.26.0/archival/libipkg/ipkg_install.h 2016-12-22 17:08:31.004855223 +0100
  5733. @@ -0,0 +1,35 @@
  5734. +/* ipkg_install.h - the itsy package management system
  5735. +
  5736. + Carl D. Worth
  5737. +
  5738. + Copyright (C) 2001 University of Southern California
  5739. +
  5740. + This program is free software; you can redistribute it and/or
  5741. + modify it under the terms of the GNU General Public License as
  5742. + published by the Free Software Foundation; either version 2, or (at
  5743. + your option) any later version.
  5744. +
  5745. + This program is distributed in the hope that it will be useful, but
  5746. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5747. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5748. + General Public License for more details.
  5749. +*/
  5750. +
  5751. +#ifndef IPKG_INSTALL_H
  5752. +#define IPKG_INSTALL_H
  5753. +
  5754. +#include "pkg.h"
  5755. +#include "ipkg_conf.h"
  5756. +
  5757. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5758. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5759. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5760. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5761. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5762. +
  5763. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5764. +
  5765. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5766. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5767. +
  5768. +#endif
  5769. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_message.c busybox-1.26.0/archival/libipkg/ipkg_message.c
  5770. --- busybox-1.26.0.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5771. +++ busybox-1.26.0/archival/libipkg/ipkg_message.c 2016-12-22 17:08:31.004855223 +0100
  5772. @@ -0,0 +1,35 @@
  5773. +/* ipkg_message.c - the itsy package management system
  5774. +
  5775. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5776. +
  5777. + This program is free software; you can redistribute it and/or
  5778. + modify it under the terms of the GNU General Public License as
  5779. + published by the Free Software Foundation; either version 2, or (at
  5780. + your option) any later version.
  5781. +
  5782. + This program is distributed in the hope that it will be useful, but
  5783. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5784. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5785. + General Public License for more details.
  5786. +*/
  5787. +
  5788. +
  5789. +#include "ipkg.h"
  5790. +#include "ipkg_conf.h"
  5791. +#include "ipkg_message.h"
  5792. +#include "libipkg.h"
  5793. +
  5794. +void
  5795. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5796. +{
  5797. + va_list ap;
  5798. + char ts[256];
  5799. +
  5800. + if (ipkg_cb_message)
  5801. + {
  5802. + va_start (ap, fmt);
  5803. + vsnprintf (ts,256,fmt, ap);
  5804. + va_end (ap);
  5805. + ipkg_cb_message(conf,level,ts);
  5806. + }
  5807. +}
  5808. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_message.h busybox-1.26.0/archival/libipkg/ipkg_message.h
  5809. --- busybox-1.26.0.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5810. +++ busybox-1.26.0/archival/libipkg/ipkg_message.h 2016-12-22 17:08:31.004855223 +0100
  5811. @@ -0,0 +1,32 @@
  5812. +/* ipkg_message.h - the itsy package management system
  5813. +
  5814. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5815. +
  5816. + This program is free software; you can redistribute it and/or
  5817. + modify it under the terms of the GNU General Public License as
  5818. + published by the Free Software Foundation; either version 2, or (at
  5819. + your option) any later version.
  5820. +
  5821. + This program is distributed in the hope that it will be useful, but
  5822. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5823. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5824. + General Public License for more details.
  5825. +*/
  5826. +
  5827. +#ifndef _IPKG_MESSAGE_H_
  5828. +#define _IPKG_MESSAGE_H_
  5829. +
  5830. +#include "ipkg.h"
  5831. +#include "ipkg_conf.h"
  5832. +
  5833. +typedef enum {
  5834. + IPKG_ERROR, /* error conditions */
  5835. + IPKG_NOTICE, /* normal but significant condition */
  5836. + IPKG_INFO, /* informational message */
  5837. + IPKG_DEBUG, /* debug level message */
  5838. + IPKG_DEBUG2, /* more debug level message */
  5839. +} message_level_t;
  5840. +
  5841. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5842. +
  5843. +#endif /* _IPKG_MESSAGE_H_ */
  5844. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_remove.c busybox-1.26.0/archival/libipkg/ipkg_remove.c
  5845. --- busybox-1.26.0.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5846. +++ busybox-1.26.0/archival/libipkg/ipkg_remove.c 2016-12-22 17:08:31.004855223 +0100
  5847. @@ -0,0 +1,385 @@
  5848. +/* ipkg_remove.c - the itsy package management system
  5849. +
  5850. + Carl D. Worth
  5851. +
  5852. + Copyright (C) 2001 University of Southern California
  5853. +
  5854. + This program is free software; you can redistribute it and/or
  5855. + modify it under the terms of the GNU General Public License as
  5856. + published by the Free Software Foundation; either version 2, or (at
  5857. + your option) any later version.
  5858. +
  5859. + This program is distributed in the hope that it will be useful, but
  5860. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5861. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5862. + General Public License for more details.
  5863. +*/
  5864. +
  5865. +#include "ipkg.h"
  5866. +#include "ipkg_message.h"
  5867. +
  5868. +#include <glob.h>
  5869. +
  5870. +#include "ipkg_remove.h"
  5871. +
  5872. +#include "file_util.h"
  5873. +#include "sprintf_alloc.h"
  5874. +#include "str_util.h"
  5875. +
  5876. +#include "ipkg_cmd.h"
  5877. +
  5878. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5879. +
  5880. +/*
  5881. + * Returns number of the number of packages depending on the packages provided by this package.
  5882. + * Every package implicitly provides itself.
  5883. + */
  5884. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5885. +{
  5886. + int nprovides = pkg->provides_count;
  5887. + abstract_pkg_t **provides = pkg->provides;
  5888. + int n_installed_dependents = 0;
  5889. + int i;
  5890. + for (i = 0; i <= nprovides; i++) {
  5891. + abstract_pkg_t *providee = provides[i];
  5892. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5893. + abstract_pkg_t *dep_ab_pkg;
  5894. + if (dependers == NULL)
  5895. + continue;
  5896. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5897. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5898. + n_installed_dependents++;
  5899. + }
  5900. + }
  5901. +
  5902. + }
  5903. + /* if caller requested the set of installed dependents */
  5904. + if (pdependents) {
  5905. + int p = 0;
  5906. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5907. +
  5908. + if ( dependents == NULL ){
  5909. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5910. + return -1;
  5911. + }
  5912. +
  5913. + *pdependents = dependents;
  5914. + for (i = 0; i <= nprovides; i++) {
  5915. + abstract_pkg_t *providee = provides[i];
  5916. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5917. + abstract_pkg_t *dep_ab_pkg;
  5918. + if (dependers == NULL)
  5919. + continue;
  5920. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5921. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5922. + dependents[p++] = dep_ab_pkg;
  5923. + dep_ab_pkg->state_flag |= SF_MARKED;
  5924. + }
  5925. + }
  5926. + }
  5927. + dependents[p] = NULL;
  5928. + /* now clear the marks */
  5929. + for (i = 0; i < p; i++) {
  5930. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5931. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5932. + }
  5933. + }
  5934. + return n_installed_dependents;
  5935. +}
  5936. +
  5937. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5938. +{
  5939. + int i;
  5940. + int a;
  5941. + int count;
  5942. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5943. + abstract_pkg_t * ab_pkg;
  5944. +
  5945. + if((ab_pkg = pkg->parent) == NULL){
  5946. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5947. + __FUNCTION__, pkg->name);
  5948. + return 0;
  5949. + }
  5950. +
  5951. + if (dependents == NULL)
  5952. + return 0;
  5953. +
  5954. + // here i am using the dependencies_checked
  5955. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5956. + return 0; // has already been encountered in the process
  5957. + // of marking packages for removal - Karthik
  5958. + ab_pkg->dependencies_checked = 2;
  5959. +
  5960. + i = 0;
  5961. + count = 1;
  5962. + while (dependents [i] != NULL) {
  5963. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5964. +
  5965. + if (dep_ab_pkg->dependencies_checked == 2){
  5966. + i++;
  5967. + continue;
  5968. + }
  5969. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5970. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5971. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5972. + if (dep_pkg->state_status == SS_INSTALLED) {
  5973. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5974. + count++;
  5975. + }
  5976. + }
  5977. + }
  5978. + i++;
  5979. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5980. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5981. + }
  5982. +
  5983. + if (count == 1)
  5984. + return 0;
  5985. +
  5986. +
  5987. + for (i = 0; i < dependent_pkgs->len; i++) {
  5988. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5989. + if (err)
  5990. + return err;
  5991. + }
  5992. + return 0;
  5993. +}
  5994. +
  5995. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5996. +{
  5997. + abstract_pkg_t *dep_ab_pkg;
  5998. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5999. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6000. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6001. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6002. + }
  6003. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6004. + ipkg_message(conf, IPKG_ERROR, "");
  6005. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6006. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6007. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6008. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6009. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6010. + return 0;
  6011. +}
  6012. +
  6013. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6014. +{
  6015. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6016. + thus I wan't check for essential, as I'm upgrading.
  6017. + I hope it won't break anything :)
  6018. +*/
  6019. + int err;
  6020. + abstract_pkg_t *parent_pkg = NULL;
  6021. +
  6022. + if (pkg->essential && !message) {
  6023. + if (conf->force_removal_of_essential_packages) {
  6024. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6025. + "\tIf your system breaks, you get to keep both pieces\n",
  6026. + pkg->name);
  6027. + } else {
  6028. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6029. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6030. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6031. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6032. + pkg->name);
  6033. + return IPKG_PKG_IS_ESSENTIAL;
  6034. + }
  6035. + }
  6036. +
  6037. + if ((parent_pkg = pkg->parent) == NULL)
  6038. + return 0;
  6039. +
  6040. + /* only attempt to remove dependent installed packages if
  6041. + * force_depends is not specified or the package is being
  6042. + * replaced.
  6043. + */
  6044. + if (!conf->force_depends
  6045. + && !(pkg->state_flag & SF_REPLACE)) {
  6046. + abstract_pkg_t **dependents;
  6047. + int has_installed_dependents =
  6048. + pkg_has_installed_dependents(pkg, &dependents);
  6049. +
  6050. + if (has_installed_dependents) {
  6051. + /*
  6052. + * if this package is depended up by others, then either we should
  6053. + * not remove it or we should remove it and all of its dependents
  6054. + */
  6055. +
  6056. + if (!conf->force_removal_of_dependent_packages
  6057. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6058. + return IPKG_PKG_HAS_DEPENDENTS;
  6059. + }
  6060. +
  6061. + /* remove packages depending on this package - Karthik */
  6062. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6063. + free(dependents);
  6064. + if (err) return err;
  6065. + }
  6066. + }
  6067. +
  6068. + if ( message==0 ){
  6069. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6070. + fflush(stdout);
  6071. + }
  6072. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6073. +
  6074. + pkg->state_want = SW_DEINSTALL;
  6075. + ipkg_state_changed++;
  6076. +
  6077. + pkg_run_script(conf, pkg, "prerm", "remove");
  6078. +
  6079. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6080. + maintains an empty filelist rather than deleting it. That seems
  6081. + like a big pain, and I don't see that that should make a big
  6082. + difference, but for anyone who wants tighter compatibility,
  6083. + feel free to fix this. */
  6084. + remove_data_files_and_list(conf, pkg);
  6085. +
  6086. + pkg_run_script(conf, pkg, "postrm", "remove");
  6087. +
  6088. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6089. +
  6090. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6091. + * space, it doesn't make sense to leave extra configurations, files,
  6092. + * and maintainer scripts left around. So, we make remove like purge,
  6093. + * and take out all the crap :) */
  6094. +
  6095. + remove_postrm(conf, pkg);
  6096. + pkg->state_status = SS_NOT_INSTALLED;
  6097. +
  6098. + if (parent_pkg)
  6099. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6100. +
  6101. + return 0;
  6102. +}
  6103. +
  6104. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6105. +{
  6106. + ipkg_remove_pkg(conf, pkg,0);
  6107. + return 0;
  6108. +}
  6109. +
  6110. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6111. +{
  6112. + str_list_t installed_dirs;
  6113. + str_list_t *installed_files;
  6114. + str_list_elt_t *iter;
  6115. + char *file_name;
  6116. + conffile_t *conffile;
  6117. + int removed_a_dir;
  6118. + pkg_t *owner;
  6119. +
  6120. + str_list_init(&installed_dirs);
  6121. + installed_files = pkg_get_installed_files(pkg);
  6122. +
  6123. + for (iter = installed_files->head; iter; iter = iter->next) {
  6124. + file_name = iter->data;
  6125. +
  6126. + if (file_is_dir(file_name)) {
  6127. + str_list_append(&installed_dirs, strdup(file_name));
  6128. + continue;
  6129. + }
  6130. +
  6131. + conffile = pkg_get_conffile(pkg, file_name);
  6132. + if (conffile) {
  6133. + /* XXX: QUESTION: Is this right? I figure we only need to
  6134. + save the conffile if it has been modified. Is that what
  6135. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6136. + this seems like a better thing to do to conserve
  6137. + space. */
  6138. + if (conffile_has_been_modified(conf, conffile)) {
  6139. + printf(" not deleting modified conffile %s\n", file_name);
  6140. + fflush(stdout);
  6141. + continue;
  6142. + }
  6143. + }
  6144. +
  6145. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6146. + if (!conf->noaction)
  6147. + unlink(file_name);
  6148. + }
  6149. +
  6150. + if (!conf->noaction) {
  6151. + do {
  6152. + removed_a_dir = 0;
  6153. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6154. + file_name = iter->data;
  6155. +
  6156. + if (rmdir(file_name) == 0) {
  6157. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6158. + removed_a_dir = 1;
  6159. + str_list_remove(&installed_dirs, &iter);
  6160. + }
  6161. + }
  6162. + } while (removed_a_dir);
  6163. + }
  6164. +
  6165. + pkg_free_installed_files(pkg);
  6166. + /* We have to remove the file list now, so that
  6167. + find_pkg_owning_file does not always just report this package */
  6168. + pkg_remove_installed_files_list(conf, pkg);
  6169. +
  6170. + /* Don't print warning for dirs that are provided by other packages */
  6171. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6172. + file_name = iter->data;
  6173. +
  6174. + owner = file_hash_get_file_owner(conf, file_name);
  6175. + if (owner) {
  6176. + free(iter->data);
  6177. + iter->data = NULL;
  6178. + str_list_remove(&installed_dirs, &iter);
  6179. + }
  6180. + }
  6181. +
  6182. + /* cleanup */
  6183. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6184. + free(iter->data);
  6185. + iter->data = NULL;
  6186. + }
  6187. + str_list_deinit(&installed_dirs);
  6188. +
  6189. + return 0;
  6190. +}
  6191. +
  6192. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6193. +{
  6194. + int i, err;
  6195. + char *globpattern;
  6196. + glob_t globbuf;
  6197. +
  6198. + if (conf->noaction) return 0;
  6199. +
  6200. + sprintf_alloc(&globpattern, "%s/%s.*",
  6201. + pkg->dest->info_dir, pkg->name);
  6202. + err = glob(globpattern, 0, NULL, &globbuf);
  6203. + free(globpattern);
  6204. + if (err) {
  6205. + return 0;
  6206. + }
  6207. +
  6208. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6209. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6210. + continue;
  6211. + }
  6212. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6213. + unlink(globbuf.gl_pathv[i]);
  6214. + }
  6215. + globfree(&globbuf);
  6216. +
  6217. + return 0;
  6218. +}
  6219. +
  6220. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6221. +{
  6222. + char *postrm_file_name;
  6223. +
  6224. + if (conf->noaction) return 0;
  6225. +
  6226. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6227. + pkg->dest->info_dir, pkg->name);
  6228. + unlink(postrm_file_name);
  6229. + free(postrm_file_name);
  6230. +
  6231. + return 0;
  6232. +}
  6233. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_remove.h busybox-1.26.0/archival/libipkg/ipkg_remove.h
  6234. --- busybox-1.26.0.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6235. +++ busybox-1.26.0/archival/libipkg/ipkg_remove.h 2016-12-22 17:08:31.004855223 +0100
  6236. @@ -0,0 +1,33 @@
  6237. +/* ipkg_remove.h - the itsy package management system
  6238. +
  6239. + Carl D. Worth
  6240. +
  6241. + Copyright (C) 2001 University of Southern California
  6242. +
  6243. + This program is free software; you can redistribute it and/or
  6244. + modify it under the terms of the GNU General Public License as
  6245. + published by the Free Software Foundation; either version 2, or (at
  6246. + your option) any later version.
  6247. +
  6248. + This program is distributed in the hope that it will be useful, but
  6249. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6250. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6251. + General Public License for more details.
  6252. +*/
  6253. +
  6254. +#ifndef IPKG_REMOVE_H
  6255. +#define IPKG_REMOVE_H
  6256. +
  6257. +#include "pkg.h"
  6258. +#include "ipkg_conf.h"
  6259. +
  6260. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6261. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6262. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6263. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6264. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6265. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6266. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6267. +
  6268. +
  6269. +#endif
  6270. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_upgrade.c busybox-1.26.0/archival/libipkg/ipkg_upgrade.c
  6271. --- busybox-1.26.0.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6272. +++ busybox-1.26.0/archival/libipkg/ipkg_upgrade.c 2016-12-22 17:08:31.004855223 +0100
  6273. @@ -0,0 +1,79 @@
  6274. +/* ipkg_upgrade.c - the itsy package management system
  6275. +
  6276. + Carl D. Worth
  6277. + Copyright (C) 2001 University of Southern California
  6278. +
  6279. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6280. +
  6281. + This program is free software; you can redistribute it and/or
  6282. + modify it under the terms of the GNU General Public License as
  6283. + published by the Free Software Foundation; either version 2, or (at
  6284. + your option) any later version.
  6285. +
  6286. + This program is distributed in the hope that it will be useful, but
  6287. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6288. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6289. + General Public License for more details.
  6290. +*/
  6291. +
  6292. +#include "ipkg.h"
  6293. +#include "ipkg_install.h"
  6294. +#include "ipkg_message.h"
  6295. +
  6296. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6297. +
  6298. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6299. +{
  6300. + pkg_t *new;
  6301. + int cmp;
  6302. + char *old_version, *new_version;
  6303. +
  6304. + if (old->state_flag & SF_HOLD) {
  6305. + ipkg_message(conf, IPKG_NOTICE,
  6306. + "Not upgrading package %s which is marked "
  6307. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6308. + return 0;
  6309. + }
  6310. +
  6311. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6312. + if (new == NULL) {
  6313. + old_version = pkg_version_str_alloc(old);
  6314. + ipkg_message(conf, IPKG_NOTICE,
  6315. + "Assuming locally installed package %s (%s) "
  6316. + "is up to date.\n", old->name, old_version);
  6317. + free(old_version);
  6318. + return 0;
  6319. + }
  6320. +
  6321. + old_version = pkg_version_str_alloc(old);
  6322. + new_version = pkg_version_str_alloc(new);
  6323. +
  6324. + cmp = pkg_compare_versions(old, new);
  6325. + ipkg_message(conf, IPKG_DEBUG,
  6326. + "comparing visible versions of pkg %s:"
  6327. + "\n\t%s is installed "
  6328. + "\n\t%s is available "
  6329. + "\n\t%d was comparison result\n",
  6330. + old->name, old_version, new_version, cmp);
  6331. + if (cmp == 0) {
  6332. + ipkg_message(conf, IPKG_INFO,
  6333. + "Package %s (%s) installed in %s is up to date.\n",
  6334. + old->name, old_version, old->dest->name);
  6335. + free(old_version);
  6336. + free(new_version);
  6337. + return 0;
  6338. + } else if (cmp > 0) {
  6339. + ipkg_message(conf, IPKG_NOTICE,
  6340. + "Not downgrading package %s on %s from %s to %s.\n",
  6341. + old->name, old->dest->name, old_version, new_version);
  6342. + free(old_version);
  6343. + free(new_version);
  6344. + return 0;
  6345. + } else if (cmp < 0) {
  6346. + new->dest = old->dest;
  6347. + old->state_want = SW_DEINSTALL;
  6348. + }
  6349. +
  6350. + new->state_flag |= SF_USER;
  6351. + return ipkg_install_pkg(conf, new,1);
  6352. +}
  6353. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_upgrade.h busybox-1.26.0/archival/libipkg/ipkg_upgrade.h
  6354. --- busybox-1.26.0.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6355. +++ busybox-1.26.0/archival/libipkg/ipkg_upgrade.h 2016-12-22 17:08:31.004855223 +0100
  6356. @@ -0,0 +1,18 @@
  6357. +/* ipkg_upgrade.c - the itsy package management system
  6358. +
  6359. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6360. +
  6361. + This program is free software; you can redistribute it and/or
  6362. + modify it under the terms of the GNU General Public License as
  6363. + published by the Free Software Foundation; either version 2, or (at
  6364. + your option) any later version.
  6365. +
  6366. + This program is distributed in the hope that it will be useful, but
  6367. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6368. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6369. + General Public License for more details.
  6370. +*/
  6371. +
  6372. +#include "ipkg.h"
  6373. +
  6374. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6375. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_utils.c busybox-1.26.0/archival/libipkg/ipkg_utils.c
  6376. --- busybox-1.26.0.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6377. +++ busybox-1.26.0/archival/libipkg/ipkg_utils.c 2016-12-22 17:08:31.004855223 +0100
  6378. @@ -0,0 +1,185 @@
  6379. +/* ipkg_utils.c - the itsy package management system
  6380. +
  6381. + Steven M. Ayer
  6382. +
  6383. + Copyright (C) 2002 Compaq Computer Corporation
  6384. +
  6385. + This program is free software; you can redistribute it and/or
  6386. + modify it under the terms of the GNU General Public License as
  6387. + published by the Free Software Foundation; either version 2, or (at
  6388. + your option) any later version.
  6389. +
  6390. + This program is distributed in the hope that it will be useful, but
  6391. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6392. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6393. + General Public License for more details.
  6394. +*/
  6395. +
  6396. +#include "ipkg.h"
  6397. +#include <errno.h>
  6398. +#include <ctype.h>
  6399. +#include <sys/vfs.h>
  6400. +
  6401. +#include "ipkg_utils.h"
  6402. +#include "pkg.h"
  6403. +#include "pkg_hash.h"
  6404. +
  6405. +void push_error_list(struct errlist ** errors, char * msg);
  6406. +void reverse_error_list(struct errlist **errors);
  6407. +void free_error_list(struct errlist **errors);
  6408. +
  6409. +struct errlist* error_list;
  6410. +
  6411. +int get_available_blocks(char * filesystem)
  6412. +{
  6413. + struct statfs sfs;
  6414. +
  6415. + if(statfs(filesystem, &sfs)){
  6416. + fprintf(stderr, "bad statfs\n");
  6417. + return 0;
  6418. + }
  6419. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6420. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6421. +}
  6422. +
  6423. +char **read_raw_pkgs_from_file(const char *file_name)
  6424. +{
  6425. + FILE *fp;
  6426. + char **ret;
  6427. +
  6428. + if(!(fp = fopen(file_name, "r"))){
  6429. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6430. + return NULL;
  6431. + }
  6432. +
  6433. + ret = read_raw_pkgs_from_stream(fp);
  6434. +
  6435. + fclose(fp);
  6436. +
  6437. + return ret;
  6438. +}
  6439. +
  6440. +char **read_raw_pkgs_from_stream(FILE *fp)
  6441. +{
  6442. + char **raw = NULL, *buf, *scout;
  6443. + int count = 0;
  6444. + size_t size = 512;
  6445. +
  6446. + buf = malloc (size);
  6447. +
  6448. + while (fgets(buf, size, fp)) {
  6449. + while (strlen (buf) == (size - 1)
  6450. + && buf[size-2] != '\n') {
  6451. + size_t o = size - 1;
  6452. + size *= 2;
  6453. + buf = realloc (buf, size);
  6454. + if (fgets (buf + o, size - o, fp) == NULL)
  6455. + break;
  6456. + }
  6457. +
  6458. + if(!(count % 50))
  6459. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6460. +
  6461. + if((scout = strchr(buf, '\n')))
  6462. + *scout = '\0';
  6463. +
  6464. + raw[count++] = strdup(buf);
  6465. + }
  6466. +
  6467. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6468. + raw[count] = NULL;
  6469. +
  6470. + free (buf);
  6471. +
  6472. + return raw;
  6473. +}
  6474. +
  6475. +/* something to remove whitespace, a hash pooper */
  6476. +char *trim_alloc(char *line)
  6477. +{
  6478. + char *new;
  6479. + char *dest, *src, *end;
  6480. +
  6481. + new = malloc(strlen(line) + 1);
  6482. + if ( new == NULL ){
  6483. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6484. + return NULL;
  6485. + }
  6486. + dest = new, src = line, end = line + (strlen(line) - 1);
  6487. +
  6488. + /* remove it from the front */
  6489. + while(src &&
  6490. + isspace(*src) &&
  6491. + *src)
  6492. + src++;
  6493. + /* and now from the back */
  6494. + while((end > src) &&
  6495. + isspace(*end))
  6496. + end--;
  6497. + end++;
  6498. + *end = '\0';
  6499. + strcpy(new, src);
  6500. + /* this does from the first space
  6501. + * blasting away any versions stuff in depends
  6502. + while(src &&
  6503. + !isspace(*src) &&
  6504. + *src)
  6505. + *dest++ = *src++;
  6506. + *dest = '\0';
  6507. + */
  6508. +
  6509. + return new;
  6510. +}
  6511. +
  6512. +int line_is_blank(const char *line)
  6513. +{
  6514. + const char *s;
  6515. +
  6516. + for (s = line; *s; s++) {
  6517. + if (!isspace(*s))
  6518. + return 0;
  6519. + }
  6520. + return 1;
  6521. +}
  6522. +
  6523. +void push_error_list(struct errlist ** errors, char * msg){
  6524. + struct errlist *err_lst_tmp;
  6525. +
  6526. +
  6527. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6528. + err_lst_tmp->errmsg=strdup(msg) ;
  6529. + err_lst_tmp->next = *errors;
  6530. + *errors = err_lst_tmp;
  6531. +}
  6532. +
  6533. +
  6534. +void reverse_error_list(struct errlist **errors){
  6535. + struct errlist *result=NULL;
  6536. + struct errlist *current= *errors;
  6537. + struct errlist *next;
  6538. +
  6539. + while ( current != NULL ) {
  6540. + next = current->next;
  6541. + current->next=result;
  6542. + result=current;
  6543. + current=next;
  6544. + }
  6545. + *errors=result;
  6546. +
  6547. +}
  6548. +
  6549. +
  6550. +void free_error_list(struct errlist **errors){
  6551. + struct errlist *current = *errors;
  6552. +
  6553. + while (current != NULL) {
  6554. + free(current->errmsg);
  6555. + current = (*errors)->next;
  6556. + free(*errors);
  6557. + *errors = current;
  6558. + }
  6559. +
  6560. +
  6561. +}
  6562. +
  6563. +
  6564. diff -Nur busybox-1.26.0.orig/archival/libipkg/ipkg_utils.h busybox-1.26.0/archival/libipkg/ipkg_utils.h
  6565. --- busybox-1.26.0.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6566. +++ busybox-1.26.0/archival/libipkg/ipkg_utils.h 2016-12-22 17:08:31.008857485 +0100
  6567. @@ -0,0 +1,29 @@
  6568. +/* ipkg_utils.h - the itsy package management system
  6569. +
  6570. + Steven M. Ayer
  6571. +
  6572. + Copyright (C) 2002 Compaq Computer Corporation
  6573. +
  6574. + This program is free software; you can redistribute it and/or
  6575. + modify it under the terms of the GNU General Public License as
  6576. + published by the Free Software Foundation; either version 2, or (at
  6577. + your option) any later version.
  6578. +
  6579. + This program is distributed in the hope that it will be useful, but
  6580. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6581. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6582. + General Public License for more details.
  6583. +*/
  6584. +
  6585. +#ifndef IPKG_UTILS_H
  6586. +#define IPKG_UTILS_H
  6587. +
  6588. +#include "pkg.h"
  6589. +
  6590. +int get_available_blocks(char * filesystem);
  6591. +char **read_raw_pkgs_from_file(const char *file_name);
  6592. +char **read_raw_pkgs_from_stream(FILE *fp);
  6593. +char *trim_alloc(char * line);
  6594. +int line_is_blank(const char *line);
  6595. +
  6596. +#endif
  6597. diff -Nur busybox-1.26.0.orig/archival/libipkg/Kbuild busybox-1.26.0/archival/libipkg/Kbuild
  6598. --- busybox-1.26.0.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6599. +++ busybox-1.26.0/archival/libipkg/Kbuild 2016-12-22 17:08:31.008857485 +0100
  6600. @@ -0,0 +1,60 @@
  6601. +# Makefile for busybox
  6602. +#
  6603. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6604. +# Copyright (C) 2006 OpenWrt.org
  6605. +#
  6606. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6607. +
  6608. +LIBIPKG_CORE_OBJS:= \
  6609. + args.o \
  6610. + libipkg.o \
  6611. + user.o \
  6612. +
  6613. +LIBIPKG_CMD_OBJS:= \
  6614. + ipkg_cmd.o \
  6615. + ipkg_configure.o \
  6616. + ipkg_download.o \
  6617. + ipkg_install.o \
  6618. + ipkg_remove.o \
  6619. + ipkg_upgrade.o \
  6620. +
  6621. +LIBIPKG_DB_OBJS:= \
  6622. + hash_table.o \
  6623. + ipkg_conf.o \
  6624. + ipkg_utils.o \
  6625. + pkg.o \
  6626. + pkg_depends.o \
  6627. + pkg_extract.o \
  6628. + pkg_hash.o \
  6629. + pkg_parse.o \
  6630. + pkg_vec.o \
  6631. +
  6632. +LIBIPKG_LIST_OBJS:= \
  6633. + conffile.o \
  6634. + conffile_list.o \
  6635. + nv_pair.o \
  6636. + nv_pair_list.o \
  6637. + pkg_dest.o \
  6638. + pkg_dest_list.o \
  6639. + pkg_src.o \
  6640. + pkg_src_list.o \
  6641. + str_list.o \
  6642. + void_list.o \
  6643. +
  6644. +LIBIPKG_UTIL_OBJS:= \
  6645. + file_util.o \
  6646. + ipkg_message.o \
  6647. + str_util.o \
  6648. + xsystem.o \
  6649. +
  6650. +lib-y :=
  6651. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6652. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6653. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6654. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6655. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6656. +
  6657. +ifeq ($(strip $(IPKG_ARCH)),)
  6658. +IPKG_ARCH:=$(TARGET_ARCH)
  6659. +endif
  6660. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6661. diff -Nur busybox-1.26.0.orig/archival/libipkg/libipkg.c busybox-1.26.0/archival/libipkg/libipkg.c
  6662. --- busybox-1.26.0.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6663. +++ busybox-1.26.0/archival/libipkg/libipkg.c 2016-12-22 17:08:31.008857485 +0100
  6664. @@ -0,0 +1,583 @@
  6665. +/* ipkglib.c - the itsy package management system
  6666. +
  6667. + Florina Boor
  6668. +
  6669. + Copyright (C) 2003 kernel concepts
  6670. +
  6671. + This program is free software; you can redistribute it and/or
  6672. + modify it under the terms of the GNU General Public License as
  6673. + published by the Free Software Foundation; either version 2, or (at
  6674. + your option) any later version.
  6675. +
  6676. + This program is distributed in the hope that it will be useful, but
  6677. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6678. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6679. + General Public License for more details.
  6680. +*/
  6681. +
  6682. +#include "ipkg.h"
  6683. +#include "ipkg_includes.h"
  6684. +#include "libipkg.h"
  6685. +
  6686. +#include "args.h"
  6687. +#include "ipkg_conf.h"
  6688. +#include "ipkg_cmd.h"
  6689. +#include "file_util.h"
  6690. +
  6691. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6692. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6693. + char *msg);
  6694. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6695. +int default_ipkg_files_callback(char *desc);
  6696. +int default_ipkg_status_callback(char *desc);
  6697. +char* default_ipkg_response_callback(char *question);
  6698. +
  6699. +
  6700. +ipkg_message_callback ipkg_cb_message = NULL;
  6701. +ipkg_response_callback ipkg_cb_response = NULL;
  6702. +ipkg_status_callback ipkg_cb_status = NULL;
  6703. +ipkg_list_callback ipkg_cb_list = NULL;
  6704. +
  6705. +
  6706. +int
  6707. +ipkg_init (ipkg_message_callback mcall,
  6708. + ipkg_response_callback rcall,
  6709. + args_t * args)
  6710. +{
  6711. + ipkg_cb_message = mcall;
  6712. + ipkg_cb_response = rcall;
  6713. +
  6714. + args_init (args);
  6715. +
  6716. + return 0;
  6717. +}
  6718. +
  6719. +
  6720. +int
  6721. +ipkg_deinit (args_t * args)
  6722. +{
  6723. + args_deinit (args);
  6724. + ipkg_cb_message = NULL;
  6725. + ipkg_cb_response = NULL;
  6726. +
  6727. + /* place other cleanup stuff here */
  6728. +
  6729. + return 0;
  6730. +}
  6731. +
  6732. +
  6733. +int
  6734. +ipkg_packages_list(args_t *args,
  6735. + const char *packages,
  6736. + ipkg_list_callback cblist,
  6737. + void *userdata)
  6738. +{
  6739. + ipkg_cmd_t *cmd;
  6740. + ipkg_conf_t ipkg_conf;
  6741. + int err;
  6742. +
  6743. + err = ipkg_conf_init (&ipkg_conf, args);
  6744. + if (err)
  6745. + {
  6746. + return err;
  6747. + }
  6748. +
  6749. + ipkg_cb_list = cblist;
  6750. + /* we need to do this because of static declarations,
  6751. + * maybe a good idea to change */
  6752. + cmd = ipkg_cmd_find ("list");
  6753. + if (packages)
  6754. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6755. + else
  6756. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6757. + ipkg_cb_list = NULL;
  6758. + ipkg_conf_deinit (&ipkg_conf);
  6759. + return (err);
  6760. +}
  6761. +
  6762. +
  6763. +int
  6764. +ipkg_packages_status(args_t *args,
  6765. + const char *packages,
  6766. + ipkg_status_callback cbstatus,
  6767. + void *userdata)
  6768. +{
  6769. + ipkg_cmd_t *cmd;
  6770. + ipkg_conf_t ipkg_conf;
  6771. + int err;
  6772. +
  6773. + err = ipkg_conf_init (&ipkg_conf, args);
  6774. + if (err)
  6775. + {
  6776. + return err;
  6777. + }
  6778. +
  6779. + ipkg_cb_status = cbstatus;
  6780. +
  6781. + /* we need to do this because of static declarations,
  6782. + * maybe a good idea to change */
  6783. + cmd = ipkg_cmd_find ("status");
  6784. + if (packages)
  6785. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6786. + else
  6787. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6788. +
  6789. + ipkg_cb_status = NULL;
  6790. + ipkg_conf_deinit (&ipkg_conf);
  6791. + return (err);
  6792. +}
  6793. +
  6794. +
  6795. +int
  6796. +ipkg_packages_info(args_t *args,
  6797. + const char *packages,
  6798. + ipkg_status_callback cbstatus,
  6799. + void *userdata)
  6800. +{
  6801. + ipkg_cmd_t *cmd;
  6802. + ipkg_conf_t ipkg_conf;
  6803. + int err;
  6804. +
  6805. + err = ipkg_conf_init (&ipkg_conf, args);
  6806. + if (err)
  6807. + {
  6808. + return err;
  6809. + }
  6810. +
  6811. + ipkg_cb_status = cbstatus;
  6812. +
  6813. + /* we need to do this because of static declarations,
  6814. + * maybe a good idea to change */
  6815. + cmd = ipkg_cmd_find ("info");
  6816. + if (packages)
  6817. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6818. + else
  6819. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6820. +
  6821. + ipkg_cb_status = NULL;
  6822. + ipkg_conf_deinit (&ipkg_conf);
  6823. + return (err);
  6824. +}
  6825. +
  6826. +
  6827. +int
  6828. +ipkg_packages_install (args_t * args, const char *name)
  6829. +{
  6830. + ipkg_cmd_t *cmd;
  6831. + ipkg_conf_t ipkg_conf;
  6832. + int err;
  6833. +
  6834. + /* this error should be handled in application */
  6835. + if (!name || !strlen (name))
  6836. + return (-1);
  6837. +
  6838. + err = ipkg_conf_init (&ipkg_conf, args);
  6839. + if (err)
  6840. + {
  6841. + return err;
  6842. + }
  6843. +
  6844. + /* we need to do this because of static declarations,
  6845. + * maybe a good idea to change */
  6846. + cmd = ipkg_cmd_find ("install");
  6847. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6848. +
  6849. + ipkg_conf_deinit(&ipkg_conf);
  6850. + return (err);
  6851. +}
  6852. +
  6853. +
  6854. +int
  6855. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6856. +{
  6857. + ipkg_cmd_t *cmd;
  6858. + ipkg_conf_t ipkg_conf;
  6859. + int err;
  6860. +
  6861. + /* this error should be handled in application */
  6862. + if (!name || !strlen (name))
  6863. + return (-1);
  6864. +
  6865. + err = ipkg_conf_init (&ipkg_conf, args);
  6866. + if (err)
  6867. + {
  6868. + return err;
  6869. + }
  6870. +
  6871. + /* we need to do this because of static declarations,
  6872. + * maybe a good idea to change */
  6873. + if (purge)
  6874. + cmd = ipkg_cmd_find ("purge");
  6875. + else
  6876. + cmd = ipkg_cmd_find ("remove");
  6877. +
  6878. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6879. +
  6880. + ipkg_conf_deinit(&ipkg_conf);
  6881. + return (err);
  6882. +}
  6883. +
  6884. +
  6885. +int
  6886. +ipkg_lists_update(args_t *args)
  6887. +{
  6888. + ipkg_cmd_t *cmd;
  6889. + ipkg_conf_t ipkg_conf;
  6890. + int err;
  6891. +
  6892. + err = ipkg_conf_init (&ipkg_conf, args);
  6893. + if (err)
  6894. + {
  6895. + return err;
  6896. + }
  6897. +
  6898. + /* we need to do this because of static declarations,
  6899. + * maybe a good idea to change */
  6900. + cmd = ipkg_cmd_find ("update");
  6901. +
  6902. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6903. +
  6904. + ipkg_conf_deinit(&ipkg_conf);
  6905. + return (err);
  6906. +}
  6907. +
  6908. +
  6909. +int
  6910. +ipkg_packages_upgrade(args_t *args)
  6911. +{
  6912. + ipkg_cmd_t *cmd;
  6913. + ipkg_conf_t ipkg_conf;
  6914. + int err;
  6915. +
  6916. + err = ipkg_conf_init (&ipkg_conf, args);
  6917. + if (err)
  6918. + {
  6919. + return err;
  6920. + }
  6921. +
  6922. + /* we need to do this because of static declarations,
  6923. + * maybe a good idea to change */
  6924. + cmd = ipkg_cmd_find ("upgrade");
  6925. +
  6926. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6927. +
  6928. + ipkg_conf_deinit(&ipkg_conf);
  6929. + return (err);
  6930. +}
  6931. +
  6932. +
  6933. +int
  6934. +ipkg_packages_download (args_t * args, const char *name)
  6935. +{
  6936. + ipkg_cmd_t *cmd;
  6937. + ipkg_conf_t ipkg_conf;
  6938. + int err;
  6939. +
  6940. + /* this error should be handled in application */
  6941. + if (!name || !strlen (name))
  6942. + return (-1);
  6943. +
  6944. + err = ipkg_conf_init (&ipkg_conf, args);
  6945. + if (err)
  6946. + {
  6947. + return err;
  6948. + }
  6949. +
  6950. + /* we need to do this because of static declarations,
  6951. + * maybe a good idea to change */
  6952. + cmd = ipkg_cmd_find ("download");
  6953. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6954. +
  6955. + ipkg_conf_deinit(&ipkg_conf);
  6956. + return (err);
  6957. +}
  6958. +
  6959. +
  6960. +int
  6961. +ipkg_package_files(args_t *args,
  6962. + const char *name,
  6963. + ipkg_list_callback cblist,
  6964. + void *userdata)
  6965. +{
  6966. + ipkg_cmd_t *cmd;
  6967. + ipkg_conf_t ipkg_conf;
  6968. + int err;
  6969. +
  6970. + /* this error should be handled in application */
  6971. + if (!name || !strlen (name))
  6972. + return (-1);
  6973. +
  6974. + err = ipkg_conf_init (&ipkg_conf, args);
  6975. + if (err)
  6976. + {
  6977. + return err;
  6978. + }
  6979. +
  6980. + ipkg_cb_list = cblist;
  6981. +
  6982. + /* we need to do this because of static declarations,
  6983. + * maybe a good idea to change */
  6984. + cmd = ipkg_cmd_find ("files");
  6985. +
  6986. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6987. +
  6988. + ipkg_cb_list = NULL;
  6989. + ipkg_conf_deinit(&ipkg_conf);
  6990. + return (err);
  6991. +}
  6992. +
  6993. +
  6994. +int
  6995. +ipkg_file_search(args_t *args,
  6996. + const char *file,
  6997. + ipkg_list_callback cblist,
  6998. + void *userdata)
  6999. +{
  7000. + ipkg_cmd_t *cmd;
  7001. + ipkg_conf_t ipkg_conf;
  7002. + int err;
  7003. +
  7004. + /* this error should be handled in application */
  7005. + if (!file || !strlen (file))
  7006. + return (-1);
  7007. +
  7008. + err = ipkg_conf_init (&ipkg_conf, args);
  7009. + if (err)
  7010. + {
  7011. + return err;
  7012. + }
  7013. +
  7014. + ipkg_cb_list = cblist;
  7015. +
  7016. + /* we need to do this because of static declarations,
  7017. + * maybe a good idea to change */
  7018. + cmd = ipkg_cmd_find ("search");
  7019. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7020. +
  7021. + ipkg_cb_list = NULL;
  7022. + ipkg_conf_deinit(&ipkg_conf);
  7023. + return(err);
  7024. +}
  7025. +
  7026. +
  7027. +int
  7028. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7029. +{
  7030. + ipkg_cmd_t *cmd;
  7031. + ipkg_conf_t ipkg_conf;
  7032. + int err;
  7033. +
  7034. + /* this error should be handled in application */
  7035. + if (!file || !strlen (file))
  7036. + return (-1);
  7037. +
  7038. + err = ipkg_conf_init (&ipkg_conf, args);
  7039. + if (err)
  7040. + {
  7041. + return err;
  7042. + }
  7043. +
  7044. + /* we need to do this because of static declarations,
  7045. + * maybe a good idea to change */
  7046. + cmd = ipkg_cmd_find (command);
  7047. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7048. +
  7049. + ipkg_conf_deinit(&ipkg_conf);
  7050. + return(err);
  7051. +}
  7052. +
  7053. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7054. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7055. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7056. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7057. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7058. +
  7059. +
  7060. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7061. + char *msg)
  7062. +{
  7063. + if (conf && (conf->verbosity < level)) {
  7064. + return 0;
  7065. + } else {
  7066. + if ( level == IPKG_ERROR )
  7067. + push_error_list(&error_list, msg);
  7068. + else
  7069. + printf(msg);
  7070. + }
  7071. + return 0;
  7072. +}
  7073. +
  7074. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7075. +{
  7076. + if (desc)
  7077. + printf("%s - %s - %s\n", name, version, desc);
  7078. + else
  7079. + printf("%s - %s\n", name, version);
  7080. + return 0;
  7081. +}
  7082. +
  7083. +int default_ipkg_files_callback(char *desc)
  7084. +{
  7085. + if (desc)
  7086. + printf("%s\n", desc);
  7087. + return 0;
  7088. +}
  7089. +
  7090. +int default_ipkg_status_callback(char *desc)
  7091. +{
  7092. + printf("%s\n", desc);
  7093. + return 0;
  7094. +}
  7095. +
  7096. +char* default_ipkg_response_callback(char *question)
  7097. +{
  7098. + char *response = NULL;
  7099. + printf(question);
  7100. + fflush(stdout);
  7101. + do {
  7102. + response = (char *)file_read_line_alloc(stdin);
  7103. + } while (response == NULL);
  7104. + return response;
  7105. +}
  7106. +
  7107. +/* This is used for backward compatibility */
  7108. +int
  7109. +ipkg_op (int argc, char *argv[])
  7110. +{
  7111. + int err, optind_;
  7112. + args_t args;
  7113. + char *cmd_name;
  7114. + ipkg_cmd_t *cmd;
  7115. + ipkg_conf_t ipkg_conf;
  7116. + const char *message = "ipkg must have one sub-command argument";
  7117. + FILE *f;
  7118. + struct mntent *mnt;
  7119. + int remountroot;
  7120. +
  7121. + args_init (&args);
  7122. +
  7123. + optind_ = args_parse (&args, argc, argv);
  7124. + if (optind_ == argc || optind_ < 0)
  7125. + {
  7126. + args_usage(message);
  7127. + }
  7128. +
  7129. + cmd_name = argv[optind_++];
  7130. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7131. + read anything from there.
  7132. +*/
  7133. + if ( !strcmp(cmd_name,"print-architecture") ||
  7134. + !strcmp(cmd_name,"print_architecture") ||
  7135. + !strcmp(cmd_name,"print-installation-architecture") ||
  7136. + !strcmp(cmd_name,"print_installation_architecture") )
  7137. + args.nocheckfordirorfile = 1;
  7138. +
  7139. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7140. + read anything from there.
  7141. +*/
  7142. + if ( !strcmp(cmd_name,"flag") ||
  7143. + !strcmp(cmd_name,"configure") ||
  7144. + !strcmp(cmd_name,"remove") ||
  7145. + !strcmp(cmd_name,"files") ||
  7146. + !strcmp(cmd_name,"search") ||
  7147. + !strcmp(cmd_name,"compare_versions") ||
  7148. + !strcmp(cmd_name,"compare-versions") ||
  7149. + !strcmp(cmd_name,"list_installed") ||
  7150. + !strcmp(cmd_name,"list-installed") ||
  7151. + !strcmp(cmd_name,"status") )
  7152. + args.noreadfeedsfile = 1;
  7153. +
  7154. +
  7155. +
  7156. +
  7157. + err = ipkg_conf_init (&ipkg_conf, &args);
  7158. + if (err)
  7159. + {
  7160. + return err;
  7161. + }
  7162. +
  7163. + args_deinit (&args);
  7164. +
  7165. + ipkg_cb_message = default_ipkg_message_callback;
  7166. + ipkg_cb_response = default_ipkg_response_callback;
  7167. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7168. + if ( strcmp(cmd_name, "files")==0)
  7169. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7170. + else
  7171. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7172. +
  7173. + cmd = ipkg_cmd_find (cmd_name);
  7174. + if (cmd == NULL)
  7175. + {
  7176. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7177. + cmd_name);
  7178. + args_usage (NULL);
  7179. + }
  7180. +
  7181. + if (cmd->requires_args && optind_ == argc)
  7182. + {
  7183. + fprintf (stderr,
  7184. + "%s: the ``%s'' command requires at least one argument\n",
  7185. + __FUNCTION__, cmd_name);
  7186. + args_usage (NULL);
  7187. + }
  7188. +
  7189. + remountroot = 0;
  7190. + /* check if /dev/root is mounted read-only */
  7191. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7192. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7193. +
  7194. + while ((mnt = getmntent(f)) != NULL) {
  7195. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7196. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7197. + remountroot = 1;
  7198. + }
  7199. + }
  7200. +
  7201. + endmntent(f);
  7202. +
  7203. + if (remountroot) {
  7204. + if ( !strcmp(cmd_name,"install") ||
  7205. + !strcmp(cmd_name,"update") ||
  7206. + !strcmp(cmd_name,"upgrade") ||
  7207. + !strcmp(cmd_name,"flag") ||
  7208. + !strcmp(cmd_name,"configure") ||
  7209. + !strcmp(cmd_name,"remove") ) {
  7210. + /* mount rootfs read-write */
  7211. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7212. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7213. + }
  7214. + }
  7215. +
  7216. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7217. +
  7218. + ipkg_conf_deinit (&ipkg_conf);
  7219. +
  7220. + if (remountroot) {
  7221. + if ( !strcmp(cmd_name,"install") ||
  7222. + !strcmp(cmd_name,"update") ||
  7223. + !strcmp(cmd_name,"upgrade") ||
  7224. + !strcmp(cmd_name,"flag") ||
  7225. + !strcmp(cmd_name,"configure") ||
  7226. + !strcmp(cmd_name,"remove") ) {
  7227. + sync();
  7228. + /* mount rootfs read-only */
  7229. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7230. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7231. + }
  7232. + }
  7233. +
  7234. + /* check if cfgfs exists */
  7235. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7236. + if ( !strcmp(cmd_name,"install") ||
  7237. + !strcmp(cmd_name,"update") ||
  7238. + !strcmp(cmd_name,"upgrade")) {
  7239. + if (system("cfgfs status -q") != 0) {
  7240. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7241. + fprintf (stdout, "You can check via cfgfs status\n");
  7242. + }
  7243. + }
  7244. + }
  7245. +
  7246. + return err;
  7247. +}
  7248. diff -Nur busybox-1.26.0.orig/archival/libipkg/libipkg.h busybox-1.26.0/archival/libipkg/libipkg.h
  7249. --- busybox-1.26.0.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7250. +++ busybox-1.26.0/archival/libipkg/libipkg.h 2016-12-22 17:08:31.008857485 +0100
  7251. @@ -0,0 +1,78 @@
  7252. +/* ipkglib.h - the itsy package management system
  7253. +
  7254. + Florian Boor <florian.boor@kernelconcepts.de>
  7255. +
  7256. + This program is free software; you can redistribute it and/or
  7257. + modify it under the terms of the GNU General Public License as
  7258. + published by the Free Software Foundation; either version 2, or (at
  7259. + your option) any later version.
  7260. +
  7261. + This program is distributed in the hope that it will be useful, but
  7262. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7263. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7264. + General Public License for more details.
  7265. +*/
  7266. +
  7267. +#ifndef IPKGLIB_H
  7268. +#define IPKGLIB_H
  7269. +
  7270. +#include "ipkg_conf.h"
  7271. +#include "ipkg_message.h"
  7272. +
  7273. +#include "args.h"
  7274. +#include "pkg.h"
  7275. +
  7276. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7277. + char *msg);
  7278. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7279. + pkg_state_status_t status, void *userdata);
  7280. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7281. + void *userdata);
  7282. +typedef char* (*ipkg_response_callback)(char *question);
  7283. +
  7284. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7285. +extern int ipkg_init (ipkg_message_callback mcall,
  7286. + ipkg_response_callback rcall,
  7287. + args_t * args);
  7288. +
  7289. +extern int ipkg_deinit (args_t *args);
  7290. +extern int ipkg_packages_list(args_t *args,
  7291. + const char *packages,
  7292. + ipkg_list_callback cblist,
  7293. + void *userdata);
  7294. +extern int ipkg_packages_status(args_t *args,
  7295. + const char *packages,
  7296. + ipkg_status_callback cbstatus,
  7297. + void *userdata);
  7298. +extern int ipkg_packages_info(args_t *args,
  7299. + const char *packages,
  7300. + ipkg_status_callback cbstatus,
  7301. + void *userdata);
  7302. +extern int ipkg_packages_install(args_t *args, const char *name);
  7303. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7304. +extern int ipkg_lists_update(args_t *args);
  7305. +extern int ipkg_packages_upgrade(args_t *args);
  7306. +extern int ipkg_packages_download(args_t *args, const char *name);
  7307. +extern int ipkg_package_files(args_t *args,
  7308. + const char *name,
  7309. + ipkg_list_callback cblist,
  7310. + void *userdata);
  7311. +extern int ipkg_file_search(args_t *args,
  7312. + const char *file,
  7313. + ipkg_list_callback cblist,
  7314. + void *userdata);
  7315. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7316. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7317. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7318. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7319. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7320. +
  7321. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7322. +extern ipkg_response_callback ipkg_cb_response;
  7323. +extern ipkg_status_callback ipkg_cb_status;
  7324. +extern ipkg_list_callback ipkg_cb_list;
  7325. +extern void push_error_list(struct errlist **errors,char * msg);
  7326. +extern void reverse_error_list(struct errlist **errors);
  7327. +extern void free_error_list(struct errlist **errors);
  7328. +
  7329. +#endif
  7330. diff -Nur busybox-1.26.0.orig/archival/libipkg/nv_pair.c busybox-1.26.0/archival/libipkg/nv_pair.c
  7331. --- busybox-1.26.0.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7332. +++ busybox-1.26.0/archival/libipkg/nv_pair.c 2016-12-22 17:08:31.008857485 +0100
  7333. @@ -0,0 +1,40 @@
  7334. +/* nv_pair.c - the itsy package management system
  7335. +
  7336. + Carl D. Worth
  7337. +
  7338. + Copyright (C) 2001 University of Southern California
  7339. +
  7340. + This program is free software; you can redistribute it and/or
  7341. + modify it under the terms of the GNU General Public License as
  7342. + published by the Free Software Foundation; either version 2, or (at
  7343. + your option) any later version.
  7344. +
  7345. + This program is distributed in the hope that it will be useful, but
  7346. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7347. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7348. + General Public License for more details.
  7349. +*/
  7350. +
  7351. +#include "ipkg.h"
  7352. +
  7353. +#include "nv_pair.h"
  7354. +#include "str_util.h"
  7355. +
  7356. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7357. +{
  7358. + nv_pair->name = str_dup_safe(name);
  7359. + nv_pair->value = str_dup_safe(value);
  7360. +
  7361. + return 0;
  7362. +}
  7363. +
  7364. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7365. +{
  7366. + free(nv_pair->name);
  7367. + nv_pair->name = NULL;
  7368. +
  7369. + free(nv_pair->value);
  7370. + nv_pair->value = NULL;
  7371. +}
  7372. +
  7373. +
  7374. diff -Nur busybox-1.26.0.orig/archival/libipkg/nv_pair.h busybox-1.26.0/archival/libipkg/nv_pair.h
  7375. --- busybox-1.26.0.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7376. +++ busybox-1.26.0/archival/libipkg/nv_pair.h 2016-12-22 17:08:31.008857485 +0100
  7377. @@ -0,0 +1,32 @@
  7378. +/* nv_pair.h - the itsy package management system
  7379. +
  7380. + Carl D. Worth
  7381. +
  7382. + Copyright (C) 2001 University of Southern California
  7383. +
  7384. + This program is free software; you can redistribute it and/or
  7385. + modify it under the terms of the GNU General Public License as
  7386. + published by the Free Software Foundation; either version 2, or (at
  7387. + your option) any later version.
  7388. +
  7389. + This program is distributed in the hope that it will be useful, but
  7390. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7391. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7392. + General Public License for more details.
  7393. +*/
  7394. +
  7395. +#ifndef NV_PAIR_H
  7396. +#define NV_PAIR_H
  7397. +
  7398. +typedef struct nv_pair nv_pair_t;
  7399. +struct nv_pair
  7400. +{
  7401. + char *name;
  7402. + char *value;
  7403. +};
  7404. +
  7405. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7406. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7407. +
  7408. +#endif
  7409. +
  7410. diff -Nur busybox-1.26.0.orig/archival/libipkg/nv_pair_list.c busybox-1.26.0/archival/libipkg/nv_pair_list.c
  7411. --- busybox-1.26.0.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7412. +++ busybox-1.26.0/archival/libipkg/nv_pair_list.c 2016-12-22 17:08:31.008857485 +0100
  7413. @@ -0,0 +1,98 @@
  7414. +/* nv_pair_list.c - the itsy package management system
  7415. +
  7416. + Carl D. Worth
  7417. +
  7418. + Copyright (C) 2001 University of Southern California
  7419. +
  7420. + This program is free software; you can redistribute it and/or
  7421. + modify it under the terms of the GNU General Public License as
  7422. + published by the Free Software Foundation; either version 2, or (at
  7423. + your option) any later version.
  7424. +
  7425. + This program is distributed in the hope that it will be useful, but
  7426. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7427. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7428. + General Public License for more details.
  7429. +*/
  7430. +
  7431. +#include "ipkg.h"
  7432. +
  7433. +#include "nv_pair.h"
  7434. +#include "void_list.h"
  7435. +#include "nv_pair_list.h"
  7436. +
  7437. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7438. +{
  7439. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7440. +}
  7441. +
  7442. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7443. +{
  7444. + void_list_elt_deinit((void_list_elt_t *) elt);
  7445. +}
  7446. +
  7447. +int nv_pair_list_init(nv_pair_list_t *list)
  7448. +{
  7449. + return void_list_init((void_list_t *) list);
  7450. +}
  7451. +
  7452. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7453. +{
  7454. + nv_pair_list_elt_t *iter;
  7455. + nv_pair_t *nv_pair;
  7456. +
  7457. + for (iter = list->head; iter; iter = iter->next) {
  7458. + nv_pair = iter->data;
  7459. + nv_pair_deinit(nv_pair);
  7460. +
  7461. + /* malloced in nv_pair_list_append */
  7462. + free(nv_pair);
  7463. + iter->data = NULL;
  7464. + }
  7465. + void_list_deinit((void_list_t *) list);
  7466. +}
  7467. +
  7468. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7469. +{
  7470. + int err;
  7471. +
  7472. + /* freed in nv_pair_list_deinit */
  7473. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7474. +
  7475. + if (nv_pair == NULL) {
  7476. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7477. + return NULL;
  7478. + }
  7479. + nv_pair_init(nv_pair, name, value);
  7480. +
  7481. + err = void_list_append((void_list_t *) list, nv_pair);
  7482. + if (err) {
  7483. + return NULL;
  7484. + }
  7485. +
  7486. + return nv_pair;
  7487. +}
  7488. +
  7489. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7490. +{
  7491. + return void_list_push((void_list_t *) list, data);
  7492. +}
  7493. +
  7494. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7495. +{
  7496. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7497. +}
  7498. +
  7499. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7500. +{
  7501. + nv_pair_list_elt_t *iter;
  7502. + nv_pair_t *nv_pair;
  7503. +
  7504. + for (iter = list->head; iter; iter = iter->next) {
  7505. + nv_pair = iter->data;
  7506. + if (strcmp(nv_pair->name, name) == 0) {
  7507. + return nv_pair->value;
  7508. + }
  7509. + }
  7510. + return NULL;
  7511. +}
  7512. diff -Nur busybox-1.26.0.orig/archival/libipkg/nv_pair_list.h busybox-1.26.0/archival/libipkg/nv_pair_list.h
  7513. --- busybox-1.26.0.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7514. +++ busybox-1.26.0/archival/libipkg/nv_pair_list.h 2016-12-22 17:08:31.008857485 +0100
  7515. @@ -0,0 +1,60 @@
  7516. +/* nv_pair_list.h - the itsy package management system
  7517. +
  7518. + Carl D. Worth
  7519. +
  7520. + Copyright (C) 2001 University of Southern California
  7521. +
  7522. + This program is free software; you can redistribute it and/or
  7523. + modify it under the terms of the GNU General Public License as
  7524. + published by the Free Software Foundation; either version 2, or (at
  7525. + your option) any later version.
  7526. +
  7527. + This program is distributed in the hope that it will be useful, but
  7528. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7529. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7530. + General Public License for more details.
  7531. +*/
  7532. +
  7533. +#ifndef NV_PAIR_LIST_H
  7534. +#define NV_PAIR_LIST_H
  7535. +
  7536. +#include "nv_pair.h"
  7537. +#include "void_list.h"
  7538. +
  7539. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7540. +struct nv_pair_list_elt
  7541. +{
  7542. + nv_pair_list_elt_t *next;
  7543. + nv_pair_t *data;
  7544. +};
  7545. +
  7546. +typedef struct nv_pair_list nv_pair_list_t;
  7547. +struct nv_pair_list
  7548. +{
  7549. + nv_pair_list_elt_t pre_head;
  7550. + nv_pair_list_elt_t *head;
  7551. + nv_pair_list_elt_t *tail;
  7552. +};
  7553. +
  7554. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7555. +{
  7556. + if (list->head == NULL)
  7557. + return 1;
  7558. + else
  7559. + return 0;
  7560. +}
  7561. +
  7562. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7563. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7564. +
  7565. +int nv_pair_list_init(nv_pair_list_t *list);
  7566. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7567. +
  7568. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7569. + const char *name, const char *value);
  7570. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7571. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7572. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7573. +
  7574. +#endif
  7575. +
  7576. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg.c busybox-1.26.0/archival/libipkg/pkg.c
  7577. --- busybox-1.26.0.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7578. +++ busybox-1.26.0/archival/libipkg/pkg.c 2016-12-22 17:08:31.012859737 +0100
  7579. @@ -0,0 +1,1757 @@
  7580. +/* pkg.c - the itsy package management system
  7581. +
  7582. + Carl D. Worth
  7583. +
  7584. + Copyright (C) 2001 University of Southern California
  7585. +
  7586. + This program is free software; you can redistribute it and/or
  7587. + modify it under the terms of the GNU General Public License as
  7588. + published by the Free Software Foundation; either version 2, or (at
  7589. + your option) any later version.
  7590. +
  7591. + This program is distributed in the hope that it will be useful, but
  7592. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7593. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7594. + General Public License for more details.
  7595. +*/
  7596. +
  7597. +#include "ipkg.h"
  7598. +#include <ctype.h>
  7599. +#include <string.h>
  7600. +#include <errno.h>
  7601. +
  7602. +#include "pkg.h"
  7603. +
  7604. +#include "pkg_parse.h"
  7605. +#include "pkg_extract.h"
  7606. +#include "ipkg_message.h"
  7607. +#include "ipkg_utils.h"
  7608. +
  7609. +#include "sprintf_alloc.h"
  7610. +#include "file_util.h"
  7611. +#include "str_util.h"
  7612. +#include "xsystem.h"
  7613. +#include "ipkg_conf.h"
  7614. +
  7615. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7616. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7617. +
  7618. +typedef struct enum_map enum_map_t;
  7619. +struct enum_map
  7620. +{
  7621. + int value;
  7622. + const char *str;
  7623. +};
  7624. +
  7625. +static const enum_map_t pkg_state_want_map[] = {
  7626. + { SW_UNKNOWN, "unknown"},
  7627. + { SW_INSTALL, "install"},
  7628. + { SW_DEINSTALL, "deinstall"},
  7629. + { SW_PURGE, "purge"}
  7630. +};
  7631. +
  7632. +static const enum_map_t pkg_state_flag_map[] = {
  7633. + { SF_OK, "ok"},
  7634. + { SF_REINSTREQ, "reinstreq"},
  7635. + { SF_HOLD, "hold"},
  7636. + { SF_REPLACE, "replace"},
  7637. + { SF_NOPRUNE, "noprune"},
  7638. + { SF_PREFER, "prefer"},
  7639. + { SF_OBSOLETE, "obsolete"},
  7640. + { SF_USER, "user"},
  7641. +};
  7642. +
  7643. +static const enum_map_t pkg_state_status_map[] = {
  7644. + { SS_NOT_INSTALLED, "not-installed" },
  7645. + { SS_UNPACKED, "unpacked" },
  7646. + { SS_HALF_CONFIGURED, "half-configured" },
  7647. + { SS_INSTALLED, "installed" },
  7648. + { SS_HALF_INSTALLED, "half-installed" },
  7649. + { SS_CONFIG_FILES, "config-files" },
  7650. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7651. + { SS_REMOVAL_FAILED, "removal-failed" }
  7652. +};
  7653. +
  7654. +static int verrevcmp(const char *val, const char *ref);
  7655. +
  7656. +
  7657. +pkg_t *pkg_new(void)
  7658. +{
  7659. + pkg_t *pkg;
  7660. +
  7661. + pkg = malloc(sizeof(pkg_t));
  7662. + if (pkg == NULL) {
  7663. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7664. + return NULL;
  7665. + }
  7666. +
  7667. + pkg_init(pkg);
  7668. +
  7669. + return pkg;
  7670. +}
  7671. +
  7672. +int pkg_init(pkg_t *pkg)
  7673. +{
  7674. + memset(pkg, 0, sizeof(pkg_t));
  7675. + pkg->name = NULL;
  7676. + pkg->epoch = 0;
  7677. + pkg->version = NULL;
  7678. + pkg->revision = NULL;
  7679. + pkg->familiar_revision = NULL;
  7680. + pkg->dest = NULL;
  7681. + pkg->src = NULL;
  7682. + pkg->architecture = NULL;
  7683. + pkg->maintainer = NULL;
  7684. + pkg->section = NULL;
  7685. + pkg->description = NULL;
  7686. + pkg->state_want = SW_UNKNOWN;
  7687. + pkg->state_flag = SF_OK;
  7688. + pkg->state_status = SS_NOT_INSTALLED;
  7689. + pkg->depends_str = NULL;
  7690. + pkg->provides_str = NULL;
  7691. + pkg->depends_count = 0;
  7692. + pkg->depends = NULL;
  7693. + pkg->suggests_str = NULL;
  7694. + pkg->recommends_str = NULL;
  7695. + pkg->suggests_count = 0;
  7696. + pkg->recommends_count = 0;
  7697. +
  7698. + /* Abhaya: added init for conflicts fields */
  7699. + pkg->conflicts = NULL;
  7700. + pkg->conflicts_count = 0;
  7701. +
  7702. + /* added for replaces. Jamey 7/23/2002 */
  7703. + pkg->replaces = NULL;
  7704. + pkg->replaces_count = 0;
  7705. +
  7706. + pkg->pre_depends_count = 0;
  7707. + pkg->pre_depends_str = NULL;
  7708. + pkg->provides_count = 0;
  7709. + pkg->provides = NULL;
  7710. + pkg->filename = NULL;
  7711. + pkg->local_filename = NULL;
  7712. + pkg->tmp_unpack_dir = NULL;
  7713. + pkg->md5sum = NULL;
  7714. + pkg->size = NULL;
  7715. + pkg->installed_size = NULL;
  7716. + pkg->priority = NULL;
  7717. + pkg->source = NULL;
  7718. + conffile_list_init(&pkg->conffiles);
  7719. + pkg->installed_files = NULL;
  7720. + pkg->installed_files_ref_cnt = 0;
  7721. + pkg->essential = 0;
  7722. + pkg->provided_by_hand = 0;
  7723. +
  7724. + return 0;
  7725. +}
  7726. +
  7727. +void pkg_deinit(pkg_t *pkg)
  7728. +{
  7729. + free(pkg->name);
  7730. + pkg->name = NULL;
  7731. + pkg->epoch = 0;
  7732. + free(pkg->version);
  7733. + pkg->version = NULL;
  7734. + /* revision and familiar_revision share storage with version, so
  7735. + don't free */
  7736. + pkg->revision = NULL;
  7737. + pkg->familiar_revision = NULL;
  7738. + /* owned by ipkg_conf_t */
  7739. + pkg->dest = NULL;
  7740. + /* owned by ipkg_conf_t */
  7741. + pkg->src = NULL;
  7742. + free(pkg->architecture);
  7743. + pkg->architecture = NULL;
  7744. + free(pkg->maintainer);
  7745. + pkg->maintainer = NULL;
  7746. + free(pkg->section);
  7747. + pkg->section = NULL;
  7748. + free(pkg->description);
  7749. + pkg->description = NULL;
  7750. + pkg->state_want = SW_UNKNOWN;
  7751. + pkg->state_flag = SF_OK;
  7752. + pkg->state_status = SS_NOT_INSTALLED;
  7753. + free(pkg->depends_str);
  7754. + pkg->depends_str = NULL;
  7755. + free(pkg->provides_str);
  7756. + pkg->provides_str = NULL;
  7757. + pkg->depends_count = 0;
  7758. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7759. + pkg->pre_depends_count = 0;
  7760. + free(pkg->pre_depends_str);
  7761. + pkg->pre_depends_str = NULL;
  7762. + pkg->provides_count = 0;
  7763. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7764. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7765. + free(pkg->filename);
  7766. + pkg->filename = NULL;
  7767. + free(pkg->local_filename);
  7768. + pkg->local_filename = NULL;
  7769. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7770. + ipkg_install.c here. See comment in
  7771. + ipkg_install.c:cleanup_temporary_files */
  7772. + free(pkg->tmp_unpack_dir);
  7773. + pkg->tmp_unpack_dir = NULL;
  7774. + free(pkg->md5sum);
  7775. + pkg->md5sum = NULL;
  7776. + free(pkg->size);
  7777. + pkg->size = NULL;
  7778. + free(pkg->installed_size);
  7779. + pkg->installed_size = NULL;
  7780. + free(pkg->priority);
  7781. + pkg->priority = NULL;
  7782. + free(pkg->source);
  7783. + pkg->source = NULL;
  7784. + conffile_list_deinit(&pkg->conffiles);
  7785. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7786. + since if they are calling deinit, they should know. Maybe do an
  7787. + assertion here instead? */
  7788. + pkg->installed_files_ref_cnt = 1;
  7789. + pkg_free_installed_files(pkg);
  7790. + pkg->essential = 0;
  7791. +}
  7792. +
  7793. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7794. +{
  7795. + int err;
  7796. + char **raw;
  7797. + FILE *control_file;
  7798. +
  7799. + err = pkg_init(pkg);
  7800. + if (err) { return err; }
  7801. +
  7802. + pkg->local_filename = strdup(filename);
  7803. +
  7804. + control_file = tmpfile();
  7805. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7806. + if (err) { return err; }
  7807. +
  7808. + rewind(control_file);
  7809. + raw = read_raw_pkgs_from_stream(control_file);
  7810. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7811. +
  7812. + fclose(control_file);
  7813. +
  7814. + return 0;
  7815. +}
  7816. +
  7817. +/* Merge any new information in newpkg into oldpkg */
  7818. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7819. + newpkg, but should leave it usable. This rework is so that
  7820. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7821. +/*
  7822. + * uh, i thought that i had originally written this so that it took
  7823. + * two pkgs and returned a new one? we can do that again... -sma
  7824. + */
  7825. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7826. +{
  7827. + if (oldpkg == newpkg) {
  7828. + return 0;
  7829. + }
  7830. +
  7831. + if (!oldpkg->src)
  7832. + oldpkg->src = newpkg->src;
  7833. + if (!oldpkg->dest)
  7834. + oldpkg->dest = newpkg->dest;
  7835. + if (!oldpkg->architecture)
  7836. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7837. + if (!oldpkg->arch_priority)
  7838. + oldpkg->arch_priority = newpkg->arch_priority;
  7839. + if (!oldpkg->section)
  7840. + oldpkg->section = str_dup_safe(newpkg->section);
  7841. + if(!oldpkg->maintainer)
  7842. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7843. + if(!oldpkg->description)
  7844. + oldpkg->description = str_dup_safe(newpkg->description);
  7845. + if (set_status) {
  7846. + /* merge the state_flags from the new package */
  7847. + oldpkg->state_want = newpkg->state_want;
  7848. + oldpkg->state_status = newpkg->state_status;
  7849. + oldpkg->state_flag = newpkg->state_flag;
  7850. + } else {
  7851. + if (oldpkg->state_want == SW_UNKNOWN)
  7852. + oldpkg->state_want = newpkg->state_want;
  7853. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7854. + oldpkg->state_status = newpkg->state_status;
  7855. + oldpkg->state_flag |= newpkg->state_flag;
  7856. + }
  7857. +
  7858. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7859. + oldpkg->depends_str = newpkg->depends_str;
  7860. + newpkg->depends_str = NULL;
  7861. + oldpkg->depends_count = newpkg->depends_count;
  7862. + newpkg->depends_count = 0;
  7863. +
  7864. + oldpkg->depends = newpkg->depends;
  7865. + newpkg->depends = NULL;
  7866. +
  7867. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7868. + newpkg->pre_depends_str = NULL;
  7869. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7870. + newpkg->pre_depends_count = 0;
  7871. +
  7872. + oldpkg->recommends_str = newpkg->recommends_str;
  7873. + newpkg->recommends_str = NULL;
  7874. + oldpkg->recommends_count = newpkg->recommends_count;
  7875. + newpkg->recommends_count = 0;
  7876. +
  7877. + oldpkg->suggests_str = newpkg->suggests_str;
  7878. + newpkg->suggests_str = NULL;
  7879. + oldpkg->suggests_count = newpkg->suggests_count;
  7880. + newpkg->suggests_count = 0;
  7881. + }
  7882. +
  7883. + if (!oldpkg->provides_str) {
  7884. + oldpkg->provides_str = newpkg->provides_str;
  7885. + newpkg->provides_str = NULL;
  7886. + oldpkg->provides_count = newpkg->provides_count;
  7887. + newpkg->provides_count = 0;
  7888. +
  7889. + oldpkg->provides = newpkg->provides;
  7890. + newpkg->provides = NULL;
  7891. + }
  7892. +
  7893. + if (!oldpkg->conflicts_str) {
  7894. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7895. + newpkg->conflicts_str = NULL;
  7896. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7897. + newpkg->conflicts_count = 0;
  7898. +
  7899. + oldpkg->conflicts = newpkg->conflicts;
  7900. + newpkg->conflicts = NULL;
  7901. + }
  7902. +
  7903. + if (!oldpkg->replaces_str) {
  7904. + oldpkg->replaces_str = newpkg->replaces_str;
  7905. + newpkg->replaces_str = NULL;
  7906. + oldpkg->replaces_count = newpkg->replaces_count;
  7907. + newpkg->replaces_count = 0;
  7908. +
  7909. + oldpkg->replaces = newpkg->replaces;
  7910. + newpkg->replaces = NULL;
  7911. + }
  7912. +
  7913. + if (!oldpkg->filename)
  7914. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7915. + if (0)
  7916. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7917. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7918. + if (!oldpkg->local_filename)
  7919. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7920. + if (!oldpkg->tmp_unpack_dir)
  7921. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7922. + if (!oldpkg->md5sum)
  7923. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7924. + if (!oldpkg->size)
  7925. + oldpkg->size = str_dup_safe(newpkg->size);
  7926. + if (!oldpkg->installed_size)
  7927. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7928. + if (!oldpkg->priority)
  7929. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7930. + if (!oldpkg->source)
  7931. + oldpkg->source = str_dup_safe(newpkg->source);
  7932. + if (oldpkg->conffiles.head == NULL){
  7933. + oldpkg->conffiles = newpkg->conffiles;
  7934. + conffile_list_init(&newpkg->conffiles);
  7935. + }
  7936. + if (!oldpkg->installed_files){
  7937. + oldpkg->installed_files = newpkg->installed_files;
  7938. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7939. + newpkg->installed_files = NULL;
  7940. + }
  7941. + if (!oldpkg->essential)
  7942. + oldpkg->essential = newpkg->essential;
  7943. +
  7944. + return 0;
  7945. +}
  7946. +
  7947. +abstract_pkg_t *abstract_pkg_new(void)
  7948. +{
  7949. + abstract_pkg_t * ab_pkg;
  7950. +
  7951. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7952. +
  7953. + if (ab_pkg == NULL) {
  7954. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7955. + return NULL;
  7956. + }
  7957. +
  7958. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7959. + return NULL;
  7960. +
  7961. + return ab_pkg;
  7962. +}
  7963. +
  7964. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7965. +{
  7966. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7967. +
  7968. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7969. + if (ab_pkg->provided_by==NULL){
  7970. + return -1;
  7971. + }
  7972. + ab_pkg->dependencies_checked = 0;
  7973. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7974. +
  7975. + return 0;
  7976. +}
  7977. +
  7978. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7979. + char * temp_str;
  7980. + char **raw =NULL;
  7981. + char **raw_start=NULL;
  7982. +
  7983. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7984. + if (temp_str == NULL ){
  7985. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7986. + return;
  7987. + }
  7988. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7989. +
  7990. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7991. + if (raw == NULL ){
  7992. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7993. + return;
  7994. + }
  7995. +
  7996. + while(*raw){
  7997. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7998. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7999. + }
  8000. + }
  8001. + raw = raw_start;
  8002. + while (*raw) {
  8003. + if (raw!=NULL)
  8004. + free(*raw++);
  8005. + }
  8006. +
  8007. + free(raw_start);
  8008. + free(temp_str);
  8009. +
  8010. + return ;
  8011. +
  8012. +}
  8013. +
  8014. +char * pkg_formatted_info(pkg_t *pkg )
  8015. +{
  8016. + char *line;
  8017. + char * buff;
  8018. +
  8019. + buff = malloc(8192);
  8020. + if (buff == NULL) {
  8021. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8022. + return NULL;
  8023. + }
  8024. +
  8025. + buff[0] = '\0';
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Package");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Version");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Depends");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Recommends");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Suggests");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Provides");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Replaces");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Conflicts");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Status");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "Section");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Architecture");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Maintainer");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "MD5sum");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Size");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Filename");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + line = pkg_formatted_field(pkg, "Conffiles");
  8092. + strncat(buff ,line, strlen(line));
  8093. + free(line);
  8094. +
  8095. + line = pkg_formatted_field(pkg, "Source");
  8096. + strncat(buff ,line, strlen(line));
  8097. + free(line);
  8098. +
  8099. + line = pkg_formatted_field(pkg, "Description");
  8100. + strncat(buff ,line, strlen(line));
  8101. + free(line);
  8102. +
  8103. + line = pkg_formatted_field(pkg, "Installed-Time");
  8104. + strncat(buff ,line, strlen(line));
  8105. + free(line);
  8106. +
  8107. + return buff;
  8108. +}
  8109. +
  8110. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8111. +{
  8112. + static size_t LINE_LEN = 128;
  8113. + char * temp = (char *)malloc(1);
  8114. + int len = 0;
  8115. + int flag_provide_false = 0;
  8116. +
  8117. +/*
  8118. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8119. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8120. +*/
  8121. +
  8122. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8123. + goto UNKNOWN_FMT_FIELD;
  8124. + }
  8125. +
  8126. + temp[0]='\0';
  8127. +
  8128. + switch (field[0])
  8129. + {
  8130. + case 'a':
  8131. + case 'A':
  8132. + if (strcasecmp(field, "Architecture") == 0) {
  8133. + /* Architecture */
  8134. + if (pkg->architecture) {
  8135. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8136. + if ( temp == NULL ){
  8137. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8138. + return NULL;
  8139. + }
  8140. + temp[0]='\0';
  8141. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8142. + }
  8143. + } else {
  8144. + goto UNKNOWN_FMT_FIELD;
  8145. + }
  8146. + break;
  8147. + case 'c':
  8148. + case 'C':
  8149. + if (strcasecmp(field, "Conffiles") == 0) {
  8150. + /* Conffiles */
  8151. + conffile_list_elt_t *iter;
  8152. + char confstr_[LINE_LEN];
  8153. +
  8154. + if (pkg->conffiles.head == NULL) {
  8155. + return temp;
  8156. + }
  8157. +
  8158. + len = 14 ;
  8159. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8160. + if (iter->data->name && iter->data->value) {
  8161. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8162. + }
  8163. + }
  8164. + temp = (char *)realloc(temp,len);
  8165. + if ( temp == NULL ){
  8166. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8167. + return NULL;
  8168. + }
  8169. + temp[0]='\0';
  8170. + strncpy(temp, "Conffiles:\n", 12);
  8171. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8172. + if (iter->data->name && iter->data->value) {
  8173. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8174. + strncat(temp, confstr_, strlen(confstr_));
  8175. + }
  8176. + }
  8177. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8178. + int i;
  8179. +
  8180. + if (pkg->conflicts_count) {
  8181. + char conflictstr[LINE_LEN];
  8182. + len = 14 ;
  8183. + for(i = 0; i < pkg->conflicts_count; i++) {
  8184. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8185. + }
  8186. + temp = (char *)realloc(temp,len);
  8187. + if ( temp == NULL ){
  8188. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8189. + return NULL;
  8190. + }
  8191. + temp[0]='\0';
  8192. + strncpy(temp, "Conflicts:", 11);
  8193. + for(i = 0; i < pkg->conflicts_count; i++) {
  8194. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8195. + strncat(temp, conflictstr, strlen(conflictstr));
  8196. + }
  8197. + strncat(temp, "\n", strlen("\n"));
  8198. + }
  8199. + } else {
  8200. + goto UNKNOWN_FMT_FIELD;
  8201. + }
  8202. + break;
  8203. + case 'd':
  8204. + case 'D':
  8205. + if (strcasecmp(field, "Depends") == 0) {
  8206. + /* Depends */
  8207. + int i;
  8208. +
  8209. + if (pkg->depends_count) {
  8210. + char depstr[LINE_LEN];
  8211. + len = 14 ;
  8212. + for(i = 0; i < pkg->depends_count; i++) {
  8213. + len = len + (strlen(pkg->depends_str[i])+4);
  8214. + }
  8215. + temp = (char *)realloc(temp,len);
  8216. + if ( temp == NULL ){
  8217. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8218. + return NULL;
  8219. + }
  8220. + temp[0]='\0';
  8221. + strncpy(temp, "Depends:", 10);
  8222. + for(i = 0; i < pkg->depends_count; i++) {
  8223. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8224. + strncat(temp, depstr, strlen(depstr));
  8225. + }
  8226. + strncat(temp, "\n", strlen("\n"));
  8227. + }
  8228. + } else if (strcasecmp(field, "Description") == 0) {
  8229. + /* Description */
  8230. + if (pkg->description) {
  8231. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8232. + if ( temp == NULL ){
  8233. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8234. + return NULL;
  8235. + }
  8236. + temp[0]='\0';
  8237. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8238. + }
  8239. + } else {
  8240. + goto UNKNOWN_FMT_FIELD;
  8241. + }
  8242. + break;
  8243. + case 'e':
  8244. + case 'E': {
  8245. + /* Essential */
  8246. + if (pkg->essential) {
  8247. + temp = (char *)realloc(temp,16);
  8248. + if ( temp == NULL ){
  8249. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8250. + return NULL;
  8251. + }
  8252. + temp[0]='\0';
  8253. + snprintf(temp, (16), "Essential: yes\n");
  8254. + }
  8255. + }
  8256. + break;
  8257. + case 'f':
  8258. + case 'F': {
  8259. + /* Filename */
  8260. + if (pkg->filename) {
  8261. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8262. + if ( temp == NULL ){
  8263. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8264. + return NULL;
  8265. + }
  8266. + temp[0]='\0';
  8267. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8268. + }
  8269. + }
  8270. + break;
  8271. + case 'i':
  8272. + case 'I': {
  8273. + if (strcasecmp(field, "Installed-Size") == 0) {
  8274. + /* Installed-Size */
  8275. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8276. + if ( temp == NULL ){
  8277. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8278. + return NULL;
  8279. + }
  8280. + temp[0]='\0';
  8281. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8282. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8283. + temp = (char *)realloc(temp,29);
  8284. + if ( temp == NULL ){
  8285. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8286. + return NULL;
  8287. + }
  8288. + temp[0]='\0';
  8289. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8290. + }
  8291. + }
  8292. + break;
  8293. + case 'm':
  8294. + case 'M': {
  8295. + /* Maintainer | MD5sum */
  8296. + if (strcasecmp(field, "Maintainer") == 0) {
  8297. + /* Maintainer */
  8298. + if (pkg->maintainer) {
  8299. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8300. + if ( temp == NULL ){
  8301. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8302. + return NULL;
  8303. + }
  8304. + temp[0]='\0';
  8305. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8306. + }
  8307. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8308. + /* MD5sum */
  8309. + if (pkg->md5sum) {
  8310. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8311. + if ( temp == NULL ){
  8312. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8313. + return NULL;
  8314. + }
  8315. + temp[0]='\0';
  8316. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8317. + }
  8318. + } else {
  8319. + goto UNKNOWN_FMT_FIELD;
  8320. + }
  8321. + }
  8322. + break;
  8323. + case 'p':
  8324. + case 'P': {
  8325. + if (strcasecmp(field, "Package") == 0) {
  8326. + /* Package */
  8327. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8328. + if ( temp == NULL ){
  8329. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8330. + return NULL;
  8331. + }
  8332. + temp[0]='\0';
  8333. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8334. + } else if (strcasecmp(field, "Priority") == 0) {
  8335. + /* Priority */
  8336. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8337. + if ( temp == NULL ){
  8338. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8339. + return NULL;
  8340. + }
  8341. + temp[0]='\0';
  8342. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8343. + } else if (strcasecmp(field, "Provides") == 0) {
  8344. + /* Provides */
  8345. + int i;
  8346. +
  8347. + if (pkg->provides_count) {
  8348. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8349. + for ( i=0; i < pkg->provides_count; i++ ){
  8350. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8351. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8352. + flag_provide_false = 1;
  8353. + }
  8354. + }
  8355. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8356. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8357. + char provstr[LINE_LEN];
  8358. + len = 15;
  8359. + for(i = 0; i < pkg->provides_count; i++) {
  8360. + len = len + (strlen(pkg->provides_str[i])+5);
  8361. + }
  8362. + temp = (char *)realloc(temp,len);
  8363. + if ( temp == NULL ){
  8364. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8365. + return NULL;
  8366. + }
  8367. + temp[0]='\0';
  8368. + strncpy(temp, "Provides:", 12);
  8369. + for(i = 0; i < pkg->provides_count; i++) {
  8370. + if (strlen(pkg->provides_str[i])>0){;
  8371. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8372. + strncat(temp, provstr, strlen(provstr));
  8373. + }
  8374. + }
  8375. + strncat(temp, "\n", strlen("\n"));
  8376. + }
  8377. + }
  8378. + } else {
  8379. + goto UNKNOWN_FMT_FIELD;
  8380. + }
  8381. + }
  8382. + break;
  8383. + case 'r':
  8384. + case 'R': {
  8385. + int i;
  8386. + /* Replaces | Recommends*/
  8387. + if (strcasecmp (field, "Replaces") == 0) {
  8388. + if (pkg->replaces_count) {
  8389. + char replstr[LINE_LEN];
  8390. + len = 14;
  8391. + for (i = 0; i < pkg->replaces_count; i++) {
  8392. + len = len + (strlen(pkg->replaces_str[i])+5);
  8393. + }
  8394. + temp = (char *)realloc(temp,len);
  8395. + if ( temp == NULL ){
  8396. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8397. + return NULL;
  8398. + }
  8399. + temp[0]='\0';
  8400. + strncpy(temp, "Replaces:", 12);
  8401. + for (i = 0; i < pkg->replaces_count; i++) {
  8402. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8403. + strncat(temp, replstr, strlen(replstr));
  8404. + }
  8405. + strncat(temp, "\n", strlen("\n"));
  8406. + }
  8407. + } else if (strcasecmp (field, "Recommends") == 0) {
  8408. + if (pkg->recommends_count) {
  8409. + char recstr[LINE_LEN];
  8410. + len = 15;
  8411. + for(i = 0; i < pkg->recommends_count; i++) {
  8412. + len = len + (strlen( pkg->recommends_str[i])+5);
  8413. + }
  8414. + temp = (char *)realloc(temp,len);
  8415. + if ( temp == NULL ){
  8416. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8417. + return NULL;
  8418. + }
  8419. + temp[0]='\0';
  8420. + strncpy(temp, "Recommends:", 13);
  8421. + for(i = 0; i < pkg->recommends_count; i++) {
  8422. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8423. + strncat(temp, recstr, strlen(recstr));
  8424. + }
  8425. + strncat(temp, "\n", strlen("\n"));
  8426. + }
  8427. + } else {
  8428. + goto UNKNOWN_FMT_FIELD;
  8429. + }
  8430. + }
  8431. + break;
  8432. + case 's':
  8433. + case 'S': {
  8434. + /* Section | Size | Source | Status | Suggests */
  8435. + if (strcasecmp(field, "Section") == 0) {
  8436. + /* Section */
  8437. + if (pkg->section) {
  8438. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8439. + if ( temp == NULL ){
  8440. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8441. + return NULL;
  8442. + }
  8443. + temp[0]='\0';
  8444. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8445. + }
  8446. + } else if (strcasecmp(field, "Size") == 0) {
  8447. + /* Size */
  8448. + if (pkg->size) {
  8449. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8450. + if ( temp == NULL ){
  8451. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8452. + return NULL;
  8453. + }
  8454. + temp[0]='\0';
  8455. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8456. + }
  8457. + } else if (strcasecmp(field, "Source") == 0) {
  8458. + /* Source */
  8459. + if (pkg->source) {
  8460. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8461. + if ( temp == NULL ){
  8462. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8463. + return NULL;
  8464. + }
  8465. + temp[0]='\0';
  8466. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8467. + }
  8468. + } else if (strcasecmp(field, "Status") == 0) {
  8469. + /* Status */
  8470. + /* Benjamin Pineau note: we should avoid direct usage of
  8471. + * strlen(arg) without keeping "arg" for later free()
  8472. + */
  8473. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8474. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8475. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8476. +
  8477. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8478. + temp = (char *)realloc(temp,sum_of_sizes);
  8479. + if ( temp == NULL ){
  8480. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8481. + return NULL;
  8482. + }
  8483. + temp[0]='\0';
  8484. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8485. + free(pflag);
  8486. + free(pwant);
  8487. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8488. + free(pstat);
  8489. + } else if (strcasecmp(field, "Suggests") == 0) {
  8490. + if (pkg->suggests_count) {
  8491. + int i;
  8492. + char sugstr[LINE_LEN];
  8493. + len = 13;
  8494. + for(i = 0; i < pkg->suggests_count; i++) {
  8495. + len = len + (strlen(pkg->suggests_str[i])+5);
  8496. + }
  8497. + temp = (char *)realloc(temp,len);
  8498. + if ( temp == NULL ){
  8499. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8500. + return NULL;
  8501. + }
  8502. + temp[0]='\0';
  8503. + strncpy(temp, "Suggests:", 10);
  8504. + for(i = 0; i < pkg->suggests_count; i++) {
  8505. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8506. + strncat(temp, sugstr, strlen(sugstr));
  8507. + }
  8508. + strncat(temp, "\n", strlen("\n"));
  8509. + }
  8510. + } else {
  8511. + goto UNKNOWN_FMT_FIELD;
  8512. + }
  8513. + }
  8514. + break;
  8515. + case 'v':
  8516. + case 'V': {
  8517. + /* Version */
  8518. + char *version = pkg_version_str_alloc(pkg);
  8519. + temp = (char *)realloc(temp,strlen(version)+14);
  8520. + if ( temp == NULL ){
  8521. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8522. + return NULL;
  8523. + }
  8524. + temp[0]='\0';
  8525. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8526. + free(version);
  8527. + }
  8528. + break;
  8529. + default:
  8530. + goto UNKNOWN_FMT_FIELD;
  8531. + }
  8532. +
  8533. + if ( strlen(temp)<2 ) {
  8534. + temp[0]='\0';
  8535. + }
  8536. + return temp;
  8537. +
  8538. + UNKNOWN_FMT_FIELD:
  8539. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8540. + if ( strlen(temp)<2 ) {
  8541. + temp[0]='\0';
  8542. + }
  8543. +
  8544. + return temp;
  8545. +}
  8546. +
  8547. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8548. +{
  8549. + char * buff;
  8550. + if (pkg == NULL) {
  8551. + return;
  8552. + }
  8553. +
  8554. + buff = pkg_formatted_info(pkg);
  8555. + if ( buff == NULL )
  8556. + return;
  8557. + if (strlen(buff)>2){
  8558. + fwrite(buff, 1, strlen(buff), file);
  8559. + }
  8560. + free(buff);
  8561. +}
  8562. +
  8563. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8564. +{
  8565. + if (pkg == NULL) {
  8566. + return;
  8567. + }
  8568. +
  8569. + /* XXX: QUESTION: Do we actually want more fields here? The
  8570. + original idea was to save space by installing only what was
  8571. + needed for actual computation, (package, version, status,
  8572. + essential, conffiles). The assumption is that all other fields
  8573. + can be found in th available file.
  8574. +
  8575. + But, someone proposed the idea to make it possible to
  8576. + reconstruct a .ipk from an installed package, (ie. for beaming
  8577. + from one handheld to another). So, maybe we actually want a few
  8578. + more fields here, (depends, suggests, etc.), so that that would
  8579. + be guaranteed to work even in the absence of more information
  8580. + from the available file.
  8581. +
  8582. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8583. + the essential info needs to be here for all installed packages
  8584. + because they may not appear in the Packages files on various
  8585. + feeds. Furthermore, one should be able to install from URL or
  8586. + local storage without requiring a Packages file from any feed.
  8587. + -Jamey
  8588. + */
  8589. + pkg_print_field(pkg, file, "Package");
  8590. + pkg_print_field(pkg, file, "Version");
  8591. + pkg_print_field(pkg, file, "Depends");
  8592. + pkg_print_field(pkg, file, "Recommends");
  8593. + pkg_print_field(pkg, file, "Suggests");
  8594. + pkg_print_field(pkg, file, "Provides");
  8595. + pkg_print_field(pkg, file, "Replaces");
  8596. + pkg_print_field(pkg, file, "Conflicts");
  8597. + pkg_print_field(pkg, file, "Status");
  8598. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8599. + pkg_print_field(pkg, file, "Architecture");
  8600. + pkg_print_field(pkg, file, "Conffiles");
  8601. + pkg_print_field(pkg, file, "Installed-Time");
  8602. + fputs("\n", file);
  8603. +}
  8604. +
  8605. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8606. +{
  8607. + char *buff;
  8608. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8609. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8610. + __FUNCTION__, field);
  8611. + }
  8612. + buff = pkg_formatted_field(pkg, field);
  8613. + if (strlen(buff)>2) {
  8614. + fprintf(file, "%s", buff);
  8615. + fflush(file);
  8616. + }
  8617. + free(buff);
  8618. + return;
  8619. +}
  8620. +
  8621. +/*
  8622. + * libdpkg - Debian packaging suite library routines
  8623. + * vercmp.c - comparison of version numbers
  8624. + *
  8625. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8626. + */
  8627. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8628. +{
  8629. + int r;
  8630. +
  8631. + if (pkg->epoch > ref_pkg->epoch) {
  8632. + return 1;
  8633. + }
  8634. +
  8635. + if (pkg->epoch < ref_pkg->epoch) {
  8636. + return -1;
  8637. + }
  8638. +
  8639. + r = verrevcmp(pkg->version, ref_pkg->version);
  8640. + if (r) {
  8641. + return r;
  8642. + }
  8643. +
  8644. +#ifdef USE_DEBVERSION
  8645. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8646. + if (r) {
  8647. + return r;
  8648. + }
  8649. +
  8650. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8651. +#endif
  8652. +
  8653. + return r;
  8654. +}
  8655. +
  8656. +int verrevcmp(const char *val, const char *ref)
  8657. +{
  8658. + int vc, rc;
  8659. + long vl, rl;
  8660. + const char *vp, *rp;
  8661. + const char *vsep, *rsep;
  8662. +
  8663. + if (!val) val= "";
  8664. + if (!ref) ref= "";
  8665. + for (;;) {
  8666. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8667. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8668. + for (;;) {
  8669. + vc= (val == vp) ? 0 : *val++;
  8670. + rc= (ref == rp) ? 0 : *ref++;
  8671. + if (!rc && !vc) break;
  8672. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8673. + if (rc && !isalpha(rc)) rc += 256;
  8674. + if (vc != rc) return vc - rc;
  8675. + }
  8676. + val= vp;
  8677. + ref= rp;
  8678. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8679. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8680. + if (vl != rl) return vl - rl;
  8681. +
  8682. + vc = *val;
  8683. + rc = *ref;
  8684. + vsep = strchr(".-", vc);
  8685. + rsep = strchr(".-", rc);
  8686. + if (vsep && !rsep) return -1;
  8687. + if (!vsep && rsep) return +1;
  8688. +
  8689. + if (!*val && !*ref) return 0;
  8690. + if (!*val) return -1;
  8691. + if (!*ref) return +1;
  8692. + }
  8693. +}
  8694. +
  8695. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8696. +{
  8697. + int r;
  8698. +
  8699. + r = pkg_compare_versions(it, ref);
  8700. +
  8701. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8702. + return r <= 0;
  8703. + }
  8704. +
  8705. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8706. + return r >= 0;
  8707. + }
  8708. +
  8709. + if (strcmp(op, "<<") == 0) {
  8710. + return r < 0;
  8711. + }
  8712. +
  8713. + if (strcmp(op, ">>") == 0) {
  8714. + return r > 0;
  8715. + }
  8716. +
  8717. + if (strcmp(op, "=") == 0) {
  8718. + return r == 0;
  8719. + }
  8720. +
  8721. + fprintf(stderr, "unknown operator: %s", op);
  8722. + return 0;
  8723. +}
  8724. +
  8725. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8726. +{
  8727. + const pkg_t *a = *(const pkg_t **)p1;
  8728. + const pkg_t *b = *(const pkg_t **)p2;
  8729. + int namecmp;
  8730. + int vercmp;
  8731. + if (!a->name || !b->name) {
  8732. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8733. + a, a->name, b, b->name);
  8734. + return 0;
  8735. + }
  8736. +
  8737. + namecmp = strcmp(a->name, b->name);
  8738. + if (namecmp)
  8739. + return namecmp;
  8740. + vercmp = pkg_compare_versions(a, b);
  8741. + if (vercmp)
  8742. + return vercmp;
  8743. + if (!a->arch_priority || !b->arch_priority) {
  8744. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8745. + a, a->arch_priority, b, b->arch_priority);
  8746. + return 0;
  8747. + }
  8748. + if (a->arch_priority > b->arch_priority)
  8749. + return 1;
  8750. + if (a->arch_priority < b->arch_priority)
  8751. + return -1;
  8752. + return 0;
  8753. +}
  8754. +
  8755. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8756. +{
  8757. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8758. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8759. + if (!a->name || !b->name) {
  8760. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8761. + a, a->name, b, b->name);
  8762. + return 0;
  8763. + }
  8764. + return strcmp(a->name, b->name);
  8765. +}
  8766. +
  8767. +
  8768. +char *pkg_version_str_alloc(pkg_t *pkg)
  8769. +{
  8770. + char *complete_version;
  8771. + char *epoch_str;
  8772. +#ifdef USE_DEBVERSION
  8773. + char *revision_str;
  8774. + char *familiar_revision_str;
  8775. +#endif
  8776. +
  8777. + if (pkg->epoch) {
  8778. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8779. + } else {
  8780. + epoch_str = strdup("");
  8781. + }
  8782. +
  8783. +#ifdef USE_DEBVERSION
  8784. + if (pkg->revision && strlen(pkg->revision)) {
  8785. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8786. + } else {
  8787. + revision_str = strdup("");
  8788. + }
  8789. +
  8790. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8791. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8792. + } else {
  8793. + familiar_revision_str = strdup("");
  8794. + }
  8795. +#endif
  8796. +
  8797. +#ifdef USE_DEBVERSION
  8798. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8799. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8800. +#else
  8801. + sprintf_alloc(&complete_version, "%s%s",
  8802. + epoch_str, pkg->version);
  8803. +#endif
  8804. +
  8805. + free(epoch_str);
  8806. +#ifdef USE_DEBVERSION
  8807. + free(revision_str);
  8808. + free(familiar_revision_str);
  8809. +#endif
  8810. +
  8811. + return complete_version;
  8812. +}
  8813. +
  8814. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8815. +{
  8816. + int err;
  8817. + char *list_file_name = NULL;
  8818. + FILE *list_file = NULL;
  8819. + char *line;
  8820. + char *installed_file_name;
  8821. + int rootdirlen;
  8822. +
  8823. + pkg->installed_files_ref_cnt++;
  8824. +
  8825. + if (pkg->installed_files) {
  8826. + return pkg->installed_files;
  8827. + }
  8828. +
  8829. + pkg->installed_files = str_list_alloc();
  8830. + if (pkg->installed_files == NULL) {
  8831. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8832. + return NULL;
  8833. + }
  8834. +
  8835. + /* For uninstalled packages, get the file list firectly from the package.
  8836. + For installed packages, look at the package.list file in the database.
  8837. + */
  8838. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8839. + if (pkg->local_filename == NULL) {
  8840. + return pkg->installed_files;
  8841. + }
  8842. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8843. + file. In other words, change deb_extract so that it can
  8844. + simply return the file list as a char *[] rather than
  8845. + insisting on writing in to a FILE * as it does now. */
  8846. + list_file = tmpfile();
  8847. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8848. + if (err) {
  8849. + fclose(list_file);
  8850. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8851. + __FUNCTION__, pkg->local_filename, strerror(err));
  8852. + return pkg->installed_files;
  8853. + }
  8854. + rewind(list_file);
  8855. + } else {
  8856. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8857. + pkg->dest->info_dir, pkg->name);
  8858. + if (! file_exists(list_file_name)) {
  8859. + free(list_file_name);
  8860. + return pkg->installed_files;
  8861. + }
  8862. +
  8863. + list_file = fopen(list_file_name, "r");
  8864. + if (list_file == NULL) {
  8865. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8866. + list_file_name, strerror(errno));
  8867. + free(list_file_name);
  8868. + return pkg->installed_files;
  8869. + }
  8870. + free(list_file_name);
  8871. + }
  8872. +
  8873. + rootdirlen = strlen( pkg->dest->root_dir );
  8874. + while (1) {
  8875. + char *file_name;
  8876. +
  8877. + line = file_read_line_alloc(list_file);
  8878. + if (line == NULL) {
  8879. + break;
  8880. + }
  8881. + str_chomp(line);
  8882. + file_name = line;
  8883. +
  8884. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8885. + if( strncmp( pkg->dest->root_dir,
  8886. + file_name,
  8887. + rootdirlen ) ) {
  8888. + if (*file_name == '.') {
  8889. + file_name++;
  8890. + }
  8891. + if (*file_name == '/') {
  8892. + file_name++;
  8893. + }
  8894. +
  8895. + /* Freed in pkg_free_installed_files */
  8896. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8897. + } else {
  8898. + // already contains root_dir as header -> ABSOLUTE
  8899. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8900. + }
  8901. + str_list_append(pkg->installed_files, installed_file_name);
  8902. + free(line);
  8903. + }
  8904. +
  8905. + fclose(list_file);
  8906. +
  8907. + return pkg->installed_files;
  8908. +}
  8909. +
  8910. +/* XXX: CLEANUP: This function and it's counterpart,
  8911. + (pkg_get_installed_files), do not match our init/deinit naming
  8912. + convention. Nor the alloc/free convention. But, then again, neither
  8913. + of these conventions currrently fit the way these two functions
  8914. + work. */
  8915. +int pkg_free_installed_files(pkg_t *pkg)
  8916. +{
  8917. + str_list_elt_t *iter;
  8918. +
  8919. + pkg->installed_files_ref_cnt--;
  8920. + if (pkg->installed_files_ref_cnt > 0) {
  8921. + return 0;
  8922. + }
  8923. +
  8924. + if (pkg->installed_files) {
  8925. +
  8926. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8927. + /* malloced in pkg_get_installed_files */
  8928. + free (iter->data);
  8929. + iter->data = NULL;
  8930. + }
  8931. +
  8932. + str_list_deinit(pkg->installed_files);
  8933. + }
  8934. +
  8935. + pkg->installed_files = NULL;
  8936. +
  8937. + return 0;
  8938. +}
  8939. +
  8940. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8941. +{
  8942. + int err;
  8943. + char *list_file_name;
  8944. +
  8945. + //I don't think pkg_free_installed_files should be called here. Jamey
  8946. + //pkg_free_installed_files(pkg);
  8947. +
  8948. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8949. + pkg->dest->info_dir, pkg->name);
  8950. + if (!conf->noaction) {
  8951. + err = unlink(list_file_name);
  8952. + free(list_file_name);
  8953. +
  8954. + if (err) {
  8955. + return errno;
  8956. + }
  8957. + }
  8958. + return 0;
  8959. +}
  8960. +
  8961. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8962. +{
  8963. + conffile_list_elt_t *iter;
  8964. + conffile_t *conffile;
  8965. +
  8966. + if (pkg == NULL) {
  8967. + return NULL;
  8968. + }
  8969. +
  8970. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8971. + conffile = iter->data;
  8972. +
  8973. + if (strcmp(conffile->name, file_name) == 0) {
  8974. + return conffile;
  8975. + }
  8976. + }
  8977. +
  8978. + return NULL;
  8979. +}
  8980. +
  8981. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8982. + const char *script, const char *args)
  8983. +{
  8984. + int err;
  8985. + char *path;
  8986. + char *cmd;
  8987. +
  8988. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8989. + maintainer script within a chroot environment. */
  8990. +
  8991. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8992. + have scripts in pkg->tmp_unpack_dir. */
  8993. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8994. + if (pkg->dest == NULL) {
  8995. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8996. + __FUNCTION__, pkg->name);
  8997. + return EINVAL;
  8998. + }
  8999. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  9000. + } else {
  9001. + if (pkg->tmp_unpack_dir == NULL) {
  9002. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9003. + __FUNCTION__, pkg->name);
  9004. + return EINVAL;
  9005. + }
  9006. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9007. + }
  9008. +
  9009. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9010. + if (conf->noaction) return 0;
  9011. +
  9012. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9013. + scripts when running with offline_root mode and/or a dest other
  9014. + than '/'. I've been playing around with some clever chroot
  9015. + tricks and I might come up with something workable. */
  9016. + if (conf->offline_root) {
  9017. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9018. + }
  9019. +
  9020. + setenv("PKG_ROOT",
  9021. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9022. +
  9023. + if (! file_exists(path)) {
  9024. + free(path);
  9025. + return 0;
  9026. + }
  9027. +
  9028. + if (conf->offline_root) {
  9029. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9030. + free(path);
  9031. + return 0;
  9032. + }
  9033. +
  9034. + sprintf_alloc(&cmd, "%s %s", path, args);
  9035. + free(path);
  9036. +
  9037. + err = xsystem(cmd);
  9038. + free(cmd);
  9039. +
  9040. + if (err) {
  9041. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9042. + return err;
  9043. + }
  9044. +
  9045. + return 0;
  9046. +}
  9047. +
  9048. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9049. +{
  9050. + int i;
  9051. +
  9052. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9053. + if (pkg_state_want_map[i].value == sw) {
  9054. + return strdup(pkg_state_want_map[i].str);
  9055. + }
  9056. + }
  9057. +
  9058. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9059. + __FUNCTION__, sw);
  9060. + return strdup("<STATE_WANT_UNKNOWN>");
  9061. +}
  9062. +
  9063. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9064. +{
  9065. + int i;
  9066. +
  9067. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9068. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9069. + return pkg_state_want_map[i].value;
  9070. + }
  9071. + }
  9072. +
  9073. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9074. + __FUNCTION__, str);
  9075. + return SW_UNKNOWN;
  9076. +}
  9077. +
  9078. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9079. +{
  9080. + int i;
  9081. + int len = 3; /* ok\000 is minimum */
  9082. + char *str = NULL;
  9083. +
  9084. + /* clear the temporary flags before converting to string */
  9085. + sf &= SF_NONVOLATILE_FLAGS;
  9086. +
  9087. + if (sf == 0) {
  9088. + return strdup("ok");
  9089. + } else {
  9090. +
  9091. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9092. + if (sf & pkg_state_flag_map[i].value) {
  9093. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9094. + }
  9095. + }
  9096. + str = malloc(len);
  9097. + if ( str == NULL ) {
  9098. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9099. + return NULL;
  9100. + }
  9101. + str[0] = 0;
  9102. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9103. + if (sf & pkg_state_flag_map[i].value) {
  9104. + strcat(str, pkg_state_flag_map[i].str);
  9105. + strcat(str, ",");
  9106. + }
  9107. + }
  9108. + len = strlen(str);
  9109. + str[len-1] = 0; /* squash last comma */
  9110. + return str;
  9111. + }
  9112. +}
  9113. +
  9114. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9115. +{
  9116. + int i;
  9117. + int sf = SF_OK;
  9118. +
  9119. + if (strcmp(str, "ok") == 0) {
  9120. + return SF_OK;
  9121. + }
  9122. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9123. + const char *sfname = pkg_state_flag_map[i].str;
  9124. + int sfname_len = strlen(sfname);
  9125. + if (strncmp(str, sfname, sfname_len) == 0) {
  9126. + sf |= pkg_state_flag_map[i].value;
  9127. + str += sfname_len;
  9128. + if (str[0] == ',') {
  9129. + str++;
  9130. + } else {
  9131. + break;
  9132. + }
  9133. + }
  9134. + }
  9135. +
  9136. + return sf;
  9137. +}
  9138. +
  9139. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9140. +{
  9141. + int i;
  9142. +
  9143. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9144. + if (pkg_state_status_map[i].value == ss) {
  9145. + return strdup(pkg_state_status_map[i].str);
  9146. + }
  9147. + }
  9148. +
  9149. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9150. + __FUNCTION__, ss);
  9151. + return strdup("<STATE_STATUS_UNKNOWN>");
  9152. +}
  9153. +
  9154. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9155. +{
  9156. + int i;
  9157. +
  9158. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9159. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9160. + return pkg_state_status_map[i].value;
  9161. + }
  9162. + }
  9163. +
  9164. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9165. + __FUNCTION__, str);
  9166. + return SS_NOT_INSTALLED;
  9167. +}
  9168. +
  9169. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9170. +{
  9171. + nv_pair_list_elt_t *l;
  9172. +
  9173. + if (!pkg->architecture)
  9174. + return 1;
  9175. +
  9176. + l = conf->arch_list.head;
  9177. +
  9178. + while (l) {
  9179. + nv_pair_t *nv = l->data;
  9180. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9181. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9182. + return 1;
  9183. + }
  9184. + l = l->next;
  9185. + }
  9186. +
  9187. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9188. + return 0;
  9189. +}
  9190. +
  9191. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9192. +{
  9193. + nv_pair_list_elt_t *l;
  9194. +
  9195. + l = conf->arch_list.head;
  9196. +
  9197. + while (l) {
  9198. + nv_pair_t *nv = l->data;
  9199. + if (strcmp(nv->name, archname) == 0) {
  9200. + int priority = strtol(nv->value, NULL, 0);
  9201. + return priority;
  9202. + }
  9203. + l = l->next;
  9204. + }
  9205. + return 0;
  9206. +}
  9207. +
  9208. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9209. +{
  9210. + int i;
  9211. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9212. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9213. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9214. +
  9215. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9216. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9217. + /* update arch_priority for each package */
  9218. + for (i = 0; i < available_pkgs->len; i++) {
  9219. + pkg_t *pkg = available_pkgs->pkgs[i];
  9220. + int arch_priority = 1;
  9221. + if (!pkg)
  9222. + continue;
  9223. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9224. + if (pkg->architecture)
  9225. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9226. + else
  9227. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9228. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9229. + pkg->arch_priority = arch_priority;
  9230. + }
  9231. +
  9232. + for (i = 0; i < available_pkgs->len; i++) {
  9233. + pkg_t *pkg = available_pkgs->pkgs[i];
  9234. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9235. + /* clear flags and want for any uninstallable package */
  9236. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9237. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9238. + pkg->state_want = SW_UNKNOWN;
  9239. + pkg->state_flag = 0;
  9240. + }
  9241. + }
  9242. + pkg_vec_free(available_pkgs);
  9243. +
  9244. + /* update the file owner data structure */
  9245. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9246. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9247. + for (i = 0; i < installed_pkgs->len; i++) {
  9248. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9249. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9250. + str_list_elt_t *iter;
  9251. + if (installed_files == NULL) {
  9252. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9253. + break;
  9254. + }
  9255. + for (iter = installed_files->head; iter; iter = iter->next) {
  9256. + char *installed_file = iter->data;
  9257. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9258. + file_hash_set_file_owner(conf, installed_file, pkg);
  9259. + }
  9260. + }
  9261. + pkg_vec_free(installed_pkgs);
  9262. +
  9263. + return 0;
  9264. +}
  9265. +
  9266. +struct pkg_write_filelist_data {
  9267. + ipkg_conf_t *conf;
  9268. + pkg_t *pkg;
  9269. + FILE *stream;
  9270. +};
  9271. +
  9272. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9273. +{
  9274. + struct pkg_write_filelist_data *data = data_;
  9275. + pkg_t *entry = entry_;
  9276. + if (entry == data->pkg) {
  9277. + fprintf(data->stream, "%s\n", key);
  9278. + }
  9279. +}
  9280. +
  9281. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9282. +{
  9283. + struct pkg_write_filelist_data data;
  9284. + char *list_file_name = NULL;
  9285. + int err = 0;
  9286. +
  9287. + if (!pkg) {
  9288. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9289. + return -EINVAL;
  9290. + }
  9291. + ipkg_message(conf, IPKG_INFO,
  9292. + " creating %s.list file\n", pkg->name);
  9293. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9294. + if (!list_file_name) {
  9295. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9296. + return -ENOMEM;
  9297. + }
  9298. + ipkg_message(conf, IPKG_INFO,
  9299. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9300. + data.stream = fopen(list_file_name, "w");
  9301. + if (!data.stream) {
  9302. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9303. + list_file_name, strerror(errno));
  9304. + return errno;
  9305. + }
  9306. + data.pkg = pkg;
  9307. + data.conf = conf;
  9308. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9309. + fclose(data.stream);
  9310. + free(list_file_name);
  9311. +
  9312. + return err;
  9313. +}
  9314. +
  9315. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9316. +{
  9317. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9318. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9319. + int i;
  9320. + int err;
  9321. + if (conf->noaction)
  9322. + return 0;
  9323. +
  9324. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9325. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9326. + for (i = 0; i < installed_pkgs->len; i++) {
  9327. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9328. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9329. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9330. + err = pkg_write_filelist(conf, pkg);
  9331. + if (err)
  9332. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9333. + }
  9334. + }
  9335. + return 0;
  9336. +}
  9337. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_depends.c busybox-1.26.0/archival/libipkg/pkg_depends.c
  9338. --- busybox-1.26.0.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9339. +++ busybox-1.26.0/archival/libipkg/pkg_depends.c 2016-12-22 17:08:31.016862000 +0100
  9340. @@ -0,0 +1,1032 @@
  9341. +/* pkg_depends.c - the itsy package management system
  9342. +
  9343. + Steven M. Ayer
  9344. +
  9345. + Copyright (C) 2002 Compaq Computer Corporation
  9346. +
  9347. + This program is free software; you can redistribute it and/or
  9348. + modify it under the terms of the GNU General Public License as
  9349. + published by the Free Software Foundation; either version 2, or (at
  9350. + your option) any later version.
  9351. +
  9352. + This program is distributed in the hope that it will be useful, but
  9353. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9354. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9355. + General Public License for more details.
  9356. +*/
  9357. +
  9358. +#include "ipkg.h"
  9359. +#include <errno.h>
  9360. +#include <ctype.h>
  9361. +
  9362. +#include "pkg.h"
  9363. +#include "ipkg_utils.h"
  9364. +#include "pkg_hash.h"
  9365. +#include "ipkg_message.h"
  9366. +#include "pkg_parse.h"
  9367. +#include "hash_table.h"
  9368. +
  9369. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9370. +static depend_t * depend_init(void);
  9371. +static void depend_deinit(depend_t *d);
  9372. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9373. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9374. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9375. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9376. +
  9377. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9378. +{
  9379. + depend_t *depend = (depend_t *)cdata;
  9380. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9381. + return 1;
  9382. + else
  9383. + return 0;
  9384. +}
  9385. +
  9386. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9387. +{
  9388. + depend_t *depend = (depend_t *)cdata;
  9389. +#if 0
  9390. + pkg_t * temp = pkg_new();
  9391. + int comparison;
  9392. + parseVersion(temp, depend->version);
  9393. + comparison = pkg_compare_versions(pkg, temp);
  9394. + free(temp);
  9395. +
  9396. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9397. + __FUNCTION__, pkg->name, pkg->version,
  9398. + depend, depend->constraint, depend->version,
  9399. + comparison, version_constraints_satisfied(depend, pkg));
  9400. +#endif
  9401. + if (version_constraints_satisfied(depend, pkg))
  9402. + return 1;
  9403. + else
  9404. + return 0;
  9405. +}
  9406. +
  9407. +/* returns ndependences or negative error value */
  9408. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9409. + pkg_vec_t *unsatisfied, char *** unresolved)
  9410. +{
  9411. + pkg_t * satisfier_entry_pkg;
  9412. + register int i, j, k, l;
  9413. + int count, found;
  9414. + char ** the_lost;
  9415. + abstract_pkg_t * ab_pkg;
  9416. +
  9417. + /*
  9418. + * this is a setup to check for redundant/cyclic dependency checks,
  9419. + * which are marked at the abstract_pkg level
  9420. + */
  9421. + if (!(ab_pkg = pkg->parent)) {
  9422. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9423. + *unresolved = NULL;
  9424. + return 0;
  9425. + }
  9426. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9427. + *unresolved = NULL;
  9428. + return 0;
  9429. + } else {
  9430. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9431. + }
  9432. + /**/
  9433. +
  9434. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9435. + if (!count){
  9436. + *unresolved = NULL;
  9437. + return 0;
  9438. + }
  9439. +
  9440. + the_lost = NULL;
  9441. +
  9442. + /* foreach dependency */
  9443. + for (i = 0; i < count; i++) {
  9444. + compound_depend_t * compound_depend = &pkg->depends[i];
  9445. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9446. + found = 0;
  9447. + satisfier_entry_pkg = NULL;
  9448. +
  9449. + if (compound_depend->type == GREEDY_DEPEND) {
  9450. + /* foreach possible satisfier */
  9451. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9452. + /* foreach provided_by, which includes the abstract_pkg itself */
  9453. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9454. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9455. + int nposs = ab_provider_vec->len;
  9456. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9457. + for (l = 0; l < nposs; l++) {
  9458. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9459. + /* if no depends on this one, try the first package that Provides this one */
  9460. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9461. + continue;
  9462. + }
  9463. +
  9464. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9465. + for (k = 0; k < test_vec->len; k++) {
  9466. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9467. + /* not installed, and not already known about? */
  9468. + if ((pkg_scout->state_want != SW_INSTALL)
  9469. + && !pkg_scout->parent->dependencies_checked
  9470. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9471. + char ** newstuff = NULL;
  9472. + int rc;
  9473. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9474. + /* check for not-already-installed dependencies */
  9475. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9476. + pkg_scout,
  9477. + tmp_vec,
  9478. + &newstuff);
  9479. + if (newstuff == NULL) {
  9480. + int ok = 1;
  9481. + for (i = 0; i < rc; i++) {
  9482. + pkg_t *p = tmp_vec->pkgs[i];
  9483. + if (p->state_want == SW_INSTALL)
  9484. + continue;
  9485. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9486. + ok = 0;
  9487. + break;
  9488. + }
  9489. + pkg_vec_free (tmp_vec);
  9490. + if (ok) {
  9491. + /* mark this one for installation */
  9492. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9493. + pkg_vec_insert(unsatisfied, pkg_scout);
  9494. + }
  9495. + } else {
  9496. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9497. + free (newstuff);
  9498. + }
  9499. + }
  9500. + }
  9501. + }
  9502. + }
  9503. +
  9504. + continue;
  9505. + }
  9506. +
  9507. + /* foreach possible satisfier, look for installed package */
  9508. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9509. + /* foreach provided_by, which includes the abstract_pkg itself */
  9510. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9511. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9512. + pkg_t *satisfying_pkg =
  9513. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9514. + pkg_installed_and_constraint_satisfied,
  9515. + dependence_to_satisfy, 1);
  9516. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9517. + if (satisfying_pkg != NULL) {
  9518. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9519. + satisfying_pkg = NULL;
  9520. + }
  9521. + }
  9522. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9523. + if (satisfying_pkg != NULL) {
  9524. + found = 1;
  9525. + break;
  9526. + }
  9527. +
  9528. + }
  9529. + /* if nothing installed matches, then look for uninstalled satisfier */
  9530. + if (!found) {
  9531. + /* foreach possible satisfier, look for installed package */
  9532. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9533. + /* foreach provided_by, which includes the abstract_pkg itself */
  9534. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9535. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9536. + pkg_t *satisfying_pkg =
  9537. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9538. + pkg_constraint_satisfied,
  9539. + dependence_to_satisfy, 1);
  9540. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9541. + if (satisfying_pkg != NULL) {
  9542. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9543. + satisfying_pkg = NULL;
  9544. + }
  9545. + }
  9546. +
  9547. + /* user request overrides package recommendation */
  9548. + if (satisfying_pkg != NULL
  9549. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9550. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9551. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9552. + pkg->name, satisfying_pkg->name);
  9553. + continue;
  9554. + }
  9555. +
  9556. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9557. + if (satisfying_pkg != NULL) {
  9558. + satisfier_entry_pkg = satisfying_pkg;
  9559. + break;
  9560. + }
  9561. + }
  9562. + }
  9563. +
  9564. + /* we didn't find one, add something to the unsatisfied vector */
  9565. + if (!found) {
  9566. + if (!satisfier_entry_pkg) {
  9567. + /* failure to meet recommendations is not an error */
  9568. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9569. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9570. + else
  9571. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9572. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9573. + }
  9574. + else {
  9575. + if (compound_depend->type == SUGGEST) {
  9576. + /* just mention it politely */
  9577. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9578. + pkg->name, satisfier_entry_pkg->name);
  9579. + } else {
  9580. + char ** newstuff = NULL;
  9581. +
  9582. + if (satisfier_entry_pkg != pkg &&
  9583. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9584. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9585. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9586. + satisfier_entry_pkg,
  9587. + unsatisfied,
  9588. + &newstuff);
  9589. + the_lost = merge_unresolved(the_lost, newstuff);
  9590. + }
  9591. + }
  9592. + }
  9593. + }
  9594. + }
  9595. + *unresolved = the_lost;
  9596. +
  9597. + return unsatisfied->len;
  9598. +}
  9599. +
  9600. +/*checking for conflicts !in replaces
  9601. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9602. + really conflicts
  9603. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9604. +*/
  9605. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9606. +{
  9607. + int i ;
  9608. + int replaces_count = pkg->replaces_count;
  9609. + abstract_pkg_t **replaces;
  9610. +
  9611. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9612. + return 0;
  9613. +
  9614. + replaces = pkg->replaces;
  9615. +
  9616. + for (i = 0; i < replaces_count; i++) {
  9617. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9618. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9619. + return 1;
  9620. + }
  9621. + }
  9622. + return 0;
  9623. +
  9624. +}
  9625. +
  9626. +
  9627. +/* Abhaya: added support for conflicts */
  9628. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9629. +{
  9630. + pkg_vec_t * installed_conflicts, * test_vec;
  9631. + compound_depend_t * conflicts;
  9632. + depend_t ** possible_satisfiers;
  9633. + depend_t * possible_satisfier;
  9634. + register int i, j, k;
  9635. + int count;
  9636. + abstract_pkg_t * ab_pkg;
  9637. + pkg_t **pkg_scouts;
  9638. + pkg_t *pkg_scout;
  9639. +
  9640. + /*
  9641. + * this is a setup to check for redundant/cyclic dependency checks,
  9642. + * which are marked at the abstract_pkg level
  9643. + */
  9644. + if(!(ab_pkg = pkg->parent)){
  9645. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9646. + return (pkg_vec_t *)NULL;
  9647. + }
  9648. +
  9649. + conflicts = pkg->conflicts;
  9650. + if(!conflicts){
  9651. + return (pkg_vec_t *)NULL;
  9652. + }
  9653. + installed_conflicts = pkg_vec_alloc();
  9654. +
  9655. + count = pkg->conflicts_count;
  9656. +
  9657. +
  9658. +
  9659. + /* foreach conflict */
  9660. + for(i = 0; i < pkg->conflicts_count; i++){
  9661. +
  9662. + possible_satisfiers = conflicts->possibilities;
  9663. +
  9664. + /* foreach possible satisfier */
  9665. + for(j = 0; j < conflicts->possibility_count; j++){
  9666. + possible_satisfier = possible_satisfiers[j];
  9667. + if (!possible_satisfier)
  9668. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9669. + if (!possible_satisfier->pkg)
  9670. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9671. + test_vec = possible_satisfier->pkg->pkgs;
  9672. + if (test_vec) {
  9673. + /* pkg_vec found, it is an actual package conflict
  9674. + * cruise this possiblity's pkg_vec looking for an installed version */
  9675. + pkg_scouts = test_vec->pkgs;
  9676. + for(k = 0; k < test_vec->len; k++){
  9677. + pkg_scout = pkg_scouts[k];
  9678. + if (!pkg_scout) {
  9679. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9680. + continue;
  9681. + }
  9682. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9683. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9684. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9685. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9686. + }
  9687. + }
  9688. + }
  9689. + }
  9690. + }
  9691. + conflicts++;
  9692. + }
  9693. +
  9694. + if (installed_conflicts->len)
  9695. + return installed_conflicts;
  9696. + pkg_vec_free(installed_conflicts);
  9697. + return (pkg_vec_t *)NULL;
  9698. +}
  9699. +
  9700. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9701. +{
  9702. + pkg_t * temp;
  9703. + int comparison;
  9704. +
  9705. + if(depends->constraint == NONE)
  9706. + return 1;
  9707. +
  9708. + temp = pkg_new();
  9709. +
  9710. + parseVersion(temp, depends->version);
  9711. +
  9712. + comparison = pkg_compare_versions(pkg, temp);
  9713. +
  9714. + free(temp);
  9715. +
  9716. + if((depends->constraint == EARLIER) &&
  9717. + (comparison < 0))
  9718. + return 1;
  9719. + else if((depends->constraint == LATER) &&
  9720. + (comparison > 0))
  9721. + return 1;
  9722. + else if(comparison == 0)
  9723. + return 1;
  9724. + else if((depends->constraint == LATER_EQUAL) &&
  9725. + (comparison >= 0))
  9726. + return 1;
  9727. + else if((depends->constraint == EARLIER_EQUAL) &&
  9728. + (comparison <= 0))
  9729. + return 1;
  9730. +
  9731. + return 0;
  9732. +}
  9733. +
  9734. +int pkg_dependence_satisfiable(depend_t *depend)
  9735. +{
  9736. + abstract_pkg_t *apkg = depend->pkg;
  9737. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9738. + int n_providers = provider_apkgs->len;
  9739. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9740. + pkg_vec_t *pkg_vec;
  9741. + int n_pkgs ;
  9742. + int i;
  9743. + int j;
  9744. +
  9745. + for (i = 0; i < n_providers; i++) {
  9746. + abstract_pkg_t *papkg = apkgs[i];
  9747. + pkg_vec = papkg->pkgs;
  9748. + if (pkg_vec) {
  9749. + n_pkgs = pkg_vec->len;
  9750. + for (j = 0; j < n_pkgs; j++) {
  9751. + pkg_t *pkg = pkg_vec->pkgs[j];
  9752. + if (version_constraints_satisfied(depend, pkg)) {
  9753. + return 1;
  9754. + }
  9755. + }
  9756. + }
  9757. + }
  9758. + return 0;
  9759. +}
  9760. +
  9761. +int pkg_dependence_satisfied(depend_t *depend)
  9762. +{
  9763. + abstract_pkg_t *apkg = depend->pkg;
  9764. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9765. + int n_providers = provider_apkgs->len;
  9766. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9767. + int i;
  9768. + int n_pkgs;
  9769. + int j;
  9770. +
  9771. + for (i = 0; i < n_providers; i++) {
  9772. + abstract_pkg_t *papkg = apkgs[i];
  9773. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9774. + if (pkg_vec) {
  9775. + n_pkgs = pkg_vec->len;
  9776. + for (j = 0; j < n_pkgs; j++) {
  9777. + pkg_t *pkg = pkg_vec->pkgs[j];
  9778. + if (version_constraints_satisfied(depend, pkg)) {
  9779. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9780. + return 1;
  9781. + }
  9782. + }
  9783. + }
  9784. + }
  9785. + return 0;
  9786. +}
  9787. +
  9788. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9789. +{
  9790. + register int i;
  9791. + pkg_t ** pkgs = vec->pkgs;
  9792. +
  9793. + for(i = 0; i < vec->len; i++)
  9794. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9795. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9796. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9797. + return 1;
  9798. + return 0;
  9799. +}
  9800. +
  9801. +
  9802. +#ifdef DeadCode
  9803. +/**
  9804. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9805. + * the same abstract package and 0 otherwise.
  9806. + */
  9807. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9808. +{
  9809. + abstract_pkg_t **provides = pkg->provides;
  9810. + int provides_count = pkg->provides_count;
  9811. + abstract_pkg_t **replacee_provides = replacee->provides;
  9812. + int replacee_provides_count = replacee->provides_count;
  9813. + int i, j;
  9814. + for (i = 0; i < provides_count; i++) {
  9815. + abstract_pkg_t *apkg = provides[i];
  9816. + for (j = 0; j < replacee_provides_count; j++) {
  9817. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9818. + if (apkg == replacee_apkg)
  9819. + return 1;
  9820. + }
  9821. + }
  9822. + return 0;
  9823. +}
  9824. +#endif
  9825. +
  9826. +/**
  9827. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9828. + * and 0 otherwise.
  9829. + */
  9830. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9831. +{
  9832. + abstract_pkg_t **provides = pkg->provides;
  9833. + int provides_count = pkg->provides_count;
  9834. + int i;
  9835. + for (i = 0; i < provides_count; i++) {
  9836. + if (provides[i] == providee)
  9837. + return 1;
  9838. + }
  9839. + return 0;
  9840. +}
  9841. +
  9842. +/**
  9843. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9844. + * otherwise.
  9845. + */
  9846. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9847. +{
  9848. + abstract_pkg_t **replaces = pkg->replaces;
  9849. + int replaces_count = pkg->replaces_count;
  9850. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9851. + int replacee_provides_count = pkg->provides_count; */
  9852. + int i, j;
  9853. + for (i = 0; i < replaces_count; i++) {
  9854. + abstract_pkg_t *abstract_replacee = replaces[i];
  9855. + for (j = 0; j < replaces_count; j++) {
  9856. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9857. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9858. + if (replacee->provides[j] == abstract_replacee)
  9859. + return 1;
  9860. + }
  9861. + }
  9862. + return 0;
  9863. +}
  9864. +
  9865. +
  9866. +/**
  9867. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9868. + * otherwise.
  9869. + */
  9870. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9871. +{
  9872. + compound_depend_t *conflicts = pkg->conflicts;
  9873. + int conflicts_count = pkg->conflicts_count;
  9874. + int i, j;
  9875. + for (i = 0; i < conflicts_count; i++) {
  9876. + int possibility_count = conflicts[i].possibility_count;
  9877. + struct depend **possibilities = conflicts[i].possibilities;
  9878. + for (j = 0; j < possibility_count; j++) {
  9879. + if (possibilities[j]->pkg == conflictee) {
  9880. + return 1;
  9881. + }
  9882. + }
  9883. + }
  9884. + return 0;
  9885. +}
  9886. +
  9887. +/**
  9888. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9889. + * conflictee's provides and 0 otherwise.
  9890. + */
  9891. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9892. +{
  9893. + compound_depend_t *conflicts = pkg->conflicts;
  9894. + int conflicts_count = pkg->conflicts_count;
  9895. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9896. + int conflictee_provides_count = conflictee->provides_count;
  9897. + int i, j, k;
  9898. + int possibility_count;
  9899. + struct depend **possibilities;
  9900. + abstract_pkg_t *possibility ;
  9901. +
  9902. + for (i = 0; i < conflicts_count; i++) {
  9903. + possibility_count = conflicts[i].possibility_count;
  9904. + possibilities = conflicts[i].possibilities;
  9905. + for (j = 0; j < possibility_count; j++) {
  9906. + possibility = possibilities[j]->pkg;
  9907. + for (k = 0; k < conflictee_provides_count; k++) {
  9908. + if (possibility == conflictee_provides[k]) {
  9909. + return 1;
  9910. + }
  9911. + }
  9912. + }
  9913. + }
  9914. + return 0;
  9915. +}
  9916. +
  9917. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9918. +{
  9919. + int oldlen = 0, newlen = 0;
  9920. + char ** result;
  9921. + register int i, j;
  9922. +
  9923. + if(!newstuff)
  9924. + return oldstuff;
  9925. +
  9926. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9927. + while(newstuff && newstuff[newlen]) newlen++;
  9928. +
  9929. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9930. + if (result == NULL) {
  9931. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9932. + return NULL;
  9933. + }
  9934. +
  9935. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9936. + *(result + i) = *(newstuff + j);
  9937. +
  9938. + *(result + i) = NULL;
  9939. +
  9940. + return result;
  9941. +}
  9942. +
  9943. +/*
  9944. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9945. + * this is null terminated, no count is carried around
  9946. + */
  9947. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9948. +{
  9949. + int count;
  9950. + char ** resized;
  9951. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9952. +
  9953. + count = 0;
  9954. + while(the_lost && the_lost[count]) count++;
  9955. +
  9956. + count++; /* need one to hold the null */
  9957. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9958. + if (resized == NULL) {
  9959. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9960. + return NULL;
  9961. + }
  9962. + resized[count - 1] = strdup(depend_str);
  9963. + resized[count] = NULL;
  9964. +
  9965. + return resized;
  9966. +}
  9967. +
  9968. +void printDepends(pkg_t * pkg)
  9969. +{
  9970. + register int i, j;
  9971. + compound_depend_t * depend;
  9972. + int count;
  9973. +
  9974. + count = pkg->pre_depends_count + pkg->depends_count;
  9975. +
  9976. + depend = pkg->depends;
  9977. + if(!depend){
  9978. + fprintf(stderr, "Depends pointer is NULL\n");
  9979. + return;
  9980. + }
  9981. + for(i = 0; i < count; i++){
  9982. + fprintf(stderr, "%s has %d possibilities:\n",
  9983. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9984. + depend->possibility_count);
  9985. + for(j = 0; j < depend->possibility_count; j++)
  9986. + fprintf(stderr, "\t%s version %s (%d)\n",
  9987. + depend->possibilities[j]->pkg->name,
  9988. + depend->possibilities[j]->version,
  9989. + depend->possibilities[j]->constraint);
  9990. + depend++;
  9991. + }
  9992. +}
  9993. +
  9994. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9995. +{
  9996. + register int i, j;
  9997. +
  9998. + /* every pkg provides itself */
  9999. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10000. +
  10001. + if (!pkg->provides_count)
  10002. + return 0;
  10003. +
  10004. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10005. + if (pkg->provides == NULL) {
  10006. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10007. + return -1 ;
  10008. + }
  10009. + pkg->provides[0] = ab_pkg;
  10010. +
  10011. + // if (strcmp(ab_pkg->name, pkg->name))
  10012. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10013. +
  10014. + for(i = 0; i < pkg->provides_count; i++){
  10015. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10016. +
  10017. + pkg->provides[i+1] = provided_abpkg;
  10018. +
  10019. + j = 0;
  10020. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10021. + }
  10022. + return 0;
  10023. +}
  10024. +
  10025. +/* Abhaya: added conflicts support */
  10026. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10027. +{
  10028. + register int i;
  10029. + compound_depend_t * conflicts;
  10030. +
  10031. + if (!pkg->conflicts_count)
  10032. + return 0;
  10033. +
  10034. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10035. + pkg->conflicts_count);
  10036. + if (conflicts == NULL) {
  10037. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10038. + return -1;
  10039. + }
  10040. + for (i = 0; i < pkg->conflicts_count; i++) {
  10041. + conflicts->type = CONFLICTS;
  10042. + parseDepends(conflicts, hash,
  10043. + pkg->conflicts_str[i]);
  10044. +#if 0
  10045. + for (j = 0; j < conflicts->possibility_count; j++) {
  10046. + depend_t *possibility = conflicts->possibilities[j];
  10047. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10048. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10049. + }
  10050. +#endif
  10051. + conflicts++;
  10052. + }
  10053. + return 0;
  10054. +}
  10055. +
  10056. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10057. +{
  10058. + register int i, j;
  10059. +
  10060. + if (!pkg->replaces_count)
  10061. + return 0;
  10062. +
  10063. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10064. + if (pkg->replaces == NULL) {
  10065. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10066. + return -1;
  10067. + }
  10068. +
  10069. + // if (strcmp(ab_pkg->name, pkg->name))
  10070. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10071. +
  10072. + for(i = 0; i < pkg->replaces_count; i++){
  10073. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10074. +
  10075. + pkg->replaces[i] = old_abpkg;
  10076. +
  10077. + j = 0;
  10078. + if (!old_abpkg->replaced_by)
  10079. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10080. + if ( old_abpkg->replaced_by == NULL ){
  10081. + return -1;
  10082. + }
  10083. + /* if a package pkg both replaces and conflicts old_abpkg,
  10084. + * then add it to the replaced_by vector so that old_abpkg
  10085. + * will be upgraded to ab_pkg automatically */
  10086. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10087. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10088. + }
  10089. + return 0;
  10090. +}
  10091. +
  10092. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10093. +{
  10094. + int count;
  10095. + register int i;
  10096. + compound_depend_t * depends;
  10097. +
  10098. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10099. + return 0;
  10100. +
  10101. + if (0 && pkg->pre_depends_count)
  10102. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10103. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10104. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10105. + if (depends == NULL) {
  10106. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10107. + return -1;
  10108. + }
  10109. +
  10110. +
  10111. + for(i = 0; i < pkg->pre_depends_count; i++){
  10112. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10113. + if (0 && pkg->pre_depends_count)
  10114. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10115. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10116. + depends->type = PREDEPEND;
  10117. + depends++;
  10118. + }
  10119. +
  10120. + for(i = 0; i < pkg->recommends_count; i++){
  10121. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10122. + if (0 && pkg->recommends_count)
  10123. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10124. + pkg->recommends_str[i], depends, depends->possibility_count);
  10125. + depends->type = RECOMMEND;
  10126. + depends++;
  10127. + }
  10128. +
  10129. + for(i = 0; i < pkg->suggests_count; i++){
  10130. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10131. + if (0 && pkg->suggests_count)
  10132. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10133. + pkg->suggests_str[i], depends, depends->possibility_count);
  10134. + depends->type = SUGGEST;
  10135. + depends++;
  10136. + }
  10137. +
  10138. + for(i = 0; i < pkg->depends_count; i++){
  10139. + parseDepends(depends, hash, pkg->depends_str[i]);
  10140. + if (0 && pkg->depends_count)
  10141. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10142. + pkg->depends_str[i], depends, depends->possibility_count);
  10143. + depends++;
  10144. + }
  10145. + return 0;
  10146. +}
  10147. +
  10148. +/*
  10149. + * pkg_depend_string: returns the depends string specified by index_.
  10150. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10151. + * [0,npredepends) -> returns pre_depends_str[index_]
  10152. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10153. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10154. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10155. + */
  10156. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10157. +{
  10158. + if (index_ < pkg->pre_depends_count) {
  10159. + return pkg->pre_depends_str[index_];
  10160. + }
  10161. + index_ -= pkg->pre_depends_count;
  10162. +
  10163. + if (index_ < pkg->recommends_count) {
  10164. + return pkg->recommends_str[index_];
  10165. + }
  10166. + index_ -= pkg->recommends_count;
  10167. +
  10168. + if (index_ < pkg->suggests_count) {
  10169. + return pkg->suggests_str[index_];
  10170. + }
  10171. + index_ -= pkg->suggests_count;
  10172. +
  10173. + if (index_ < pkg->depends_count) {
  10174. + return pkg->depends_str[index_];
  10175. + }
  10176. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10177. + return NULL;
  10178. +}
  10179. +
  10180. +void freeDepends(pkg_t *pkg)
  10181. +{
  10182. + int i;
  10183. +
  10184. + if (pkg == NULL || pkg->depends == NULL) {
  10185. + return;
  10186. + }
  10187. +
  10188. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10189. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10190. + depend_deinit(pkg->depends->possibilities[i]);
  10191. + }
  10192. + free(pkg->depends->possibilities);
  10193. + free(pkg->depends);
  10194. + pkg->depends = NULL;
  10195. +}
  10196. +
  10197. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10198. +{
  10199. + compound_depend_t * depends;
  10200. + int count, othercount;
  10201. + register int i, j;
  10202. + abstract_pkg_t * ab_depend;
  10203. + abstract_pkg_t ** temp;
  10204. +
  10205. + count = pkg->pre_depends_count + pkg->depends_count;
  10206. + depends = pkg->depends;
  10207. +
  10208. + if (0 && pkg->pre_depends_count)
  10209. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10210. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10211. + for (i = 0; i < count; i++) {
  10212. + if (0 && pkg->pre_depends_count)
  10213. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10214. + for (j = 0; j < depends->possibility_count; j++){
  10215. + ab_depend = depends->possibilities[j]->pkg;
  10216. + if(!ab_depend->depended_upon_by)
  10217. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10218. +
  10219. + temp = ab_depend->depended_upon_by;
  10220. + othercount = 1;
  10221. + while(*temp){
  10222. + temp++;
  10223. + othercount++;
  10224. + }
  10225. + *temp = ab_pkg;
  10226. +
  10227. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10228. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10229. + /* the array may have moved */
  10230. + temp = ab_depend->depended_upon_by + othercount;
  10231. + *temp = NULL;
  10232. + }
  10233. + depends++;
  10234. + }
  10235. +}
  10236. +
  10237. +static depend_t * depend_init(void)
  10238. +{
  10239. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10240. + if ( d==NULL ){
  10241. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10242. + return NULL;
  10243. + }
  10244. + d->constraint = NONE;
  10245. + d->version = NULL;
  10246. + d->pkg = NULL;
  10247. +
  10248. + return d;
  10249. +}
  10250. +
  10251. +static void depend_deinit(depend_t *d)
  10252. +{
  10253. + free(d);
  10254. +}
  10255. +
  10256. +static int parseDepends(compound_depend_t *compound_depend,
  10257. + hash_table_t * hash, char * depend_str)
  10258. +{
  10259. + char * pkg_name, buffer[2048];
  10260. + int num_of_ors = 0;
  10261. + register int i;
  10262. + register char * src, * dest;
  10263. + depend_t ** possibilities;
  10264. +
  10265. + /* first count the number of ored possibilities for satisfying dependency */
  10266. + src = depend_str;
  10267. + while(*src)
  10268. + if(*src++ == '|')
  10269. + num_of_ors++;
  10270. +
  10271. + compound_depend->type = DEPEND;
  10272. +
  10273. + compound_depend->possibility_count = num_of_ors + 1;
  10274. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10275. + if (!possibilities)
  10276. + return -ENOMEM;
  10277. + compound_depend->possibilities = possibilities;
  10278. +
  10279. + src = depend_str;
  10280. + for(i = 0; i < num_of_ors + 1; i++){
  10281. + possibilities[i] = depend_init();
  10282. + if (!possibilities[i])
  10283. + return -ENOMEM;
  10284. + /* gobble up just the name first */
  10285. + dest = buffer;
  10286. + while(*src &&
  10287. + !isspace(*src) &&
  10288. + (*src != '(') &&
  10289. + (*src != '*') &&
  10290. + (*src != '|'))
  10291. + *dest++ = *src++;
  10292. + *dest = '\0';
  10293. + pkg_name = trim_alloc(buffer);
  10294. + if (pkg_name == NULL )
  10295. + return -ENOMEM;
  10296. +
  10297. + /* now look at possible version info */
  10298. +
  10299. + /* skip to next chars */
  10300. + if(isspace(*src))
  10301. + while(*src && isspace(*src)) src++;
  10302. +
  10303. + /* extract constraint and version */
  10304. + if(*src == '('){
  10305. + src++;
  10306. + if(!strncmp(src, "<<", 2)){
  10307. + possibilities[i]->constraint = EARLIER;
  10308. + src += 2;
  10309. + }
  10310. + else if(!strncmp(src, "<=", 2)){
  10311. + possibilities[i]->constraint = EARLIER_EQUAL;
  10312. + src += 2;
  10313. + }
  10314. + else if(!strncmp(src, ">=", 2)){
  10315. + possibilities[i]->constraint = LATER_EQUAL;
  10316. + src += 2;
  10317. + }
  10318. + else if(!strncmp(src, ">>", 2)){
  10319. + possibilities[i]->constraint = LATER;
  10320. + src += 2;
  10321. + }
  10322. + else if(!strncmp(src, "=", 1)){
  10323. + possibilities[i]->constraint = EQUAL;
  10324. + src++;
  10325. + }
  10326. + /* should these be here to support deprecated designations; dpkg does */
  10327. + else if(!strncmp(src, "<", 1)){
  10328. + possibilities[i]->constraint = EARLIER_EQUAL;
  10329. + src++;
  10330. + }
  10331. + else if(!strncmp(src, ">", 1)){
  10332. + possibilities[i]->constraint = LATER_EQUAL;
  10333. + src++;
  10334. + }
  10335. +
  10336. + /* now we have any constraint, pass space to version string */
  10337. + while(isspace(*src)) src++;
  10338. +
  10339. + /* this would be the version string */
  10340. + dest = buffer;
  10341. + while(*src && *src != ')')
  10342. + *dest++ = *src++;
  10343. + *dest = '\0';
  10344. +
  10345. + possibilities[i]->version = trim_alloc(buffer);
  10346. + /* fprintf(stderr, "let's print the depends version string:");
  10347. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10348. + if (possibilities[i]->version == NULL )
  10349. + return -ENOMEM;
  10350. +
  10351. +
  10352. + }
  10353. + /* hook up the dependency to its abstract pkg */
  10354. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10355. +
  10356. + free(pkg_name);
  10357. +
  10358. + /* now get past the ) and any possible | chars */
  10359. + while(*src &&
  10360. + (isspace(*src) ||
  10361. + (*src == ')') ||
  10362. + (*src == '|')))
  10363. + src++;
  10364. + if (*src == '*')
  10365. + {
  10366. + compound_depend->type = GREEDY_DEPEND;
  10367. + src++;
  10368. + }
  10369. + }
  10370. +
  10371. + return 0;
  10372. +}
  10373. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_depends.h busybox-1.26.0/archival/libipkg/pkg_depends.h
  10374. --- busybox-1.26.0.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10375. +++ busybox-1.26.0/archival/libipkg/pkg_depends.h 2016-12-22 17:08:31.016862000 +0100
  10376. @@ -0,0 +1,105 @@
  10377. +/* pkg_depends.h - the itsy package management system
  10378. +
  10379. + Steven M. Ayer
  10380. +
  10381. + Copyright (C) 2002 Compaq Computer Corporation
  10382. +
  10383. + This program is free software; you can redistribute it and/or
  10384. + modify it under the terms of the GNU General Public License as
  10385. + published by the Free Software Foundation; either version 2, or (at
  10386. + your option) any later version.
  10387. +
  10388. + This program is distributed in the hope that it will be useful, but
  10389. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10390. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10391. + General Public License for more details.
  10392. +*/
  10393. +
  10394. +#ifndef PKG_DEPENDS_H
  10395. +#define PKG_DEPENDS_H
  10396. +
  10397. +#include "pkg.h"
  10398. +#include "pkg_hash.h"
  10399. +
  10400. +enum depend_type {
  10401. + PREDEPEND,
  10402. + DEPEND,
  10403. + CONFLICTS,
  10404. + GREEDY_DEPEND,
  10405. + RECOMMEND,
  10406. + SUGGEST
  10407. +};
  10408. +typedef enum depend_type depend_type_t;
  10409. +
  10410. +enum version_constraint {
  10411. + NONE,
  10412. + EARLIER,
  10413. + EARLIER_EQUAL,
  10414. + EQUAL,
  10415. + LATER_EQUAL,
  10416. + LATER
  10417. +};
  10418. +typedef enum version_constraint version_constraint_t;
  10419. +
  10420. +struct depend{
  10421. + version_constraint_t constraint;
  10422. + char * version;
  10423. + abstract_pkg_t * pkg;
  10424. +};
  10425. +typedef struct depend depend_t;
  10426. +
  10427. +struct compound_depend{
  10428. + depend_type_t type;
  10429. + int possibility_count;
  10430. + struct depend ** possibilities;
  10431. +};
  10432. +typedef struct compound_depend compound_depend_t;
  10433. +
  10434. +#include "hash_table.h"
  10435. +
  10436. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10437. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10438. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10439. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10440. +
  10441. +/**
  10442. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10443. + * the same abstract package and 0 otherwise.
  10444. + */
  10445. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10446. +
  10447. +/**
  10448. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10449. + * otherwise.
  10450. + */
  10451. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10452. +
  10453. +/**
  10454. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10455. + * otherwise.
  10456. + */
  10457. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10458. +
  10459. +/**
  10460. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10461. + * otherwise.
  10462. + */
  10463. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10464. +
  10465. +/**
  10466. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10467. + * otherwise.
  10468. + */
  10469. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10470. +
  10471. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10472. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10473. +void freeDepends(pkg_t *pkg);
  10474. +void printDepends(pkg_t * pkg);
  10475. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10476. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10477. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10478. +int pkg_dependence_satisfiable(depend_t *depend);
  10479. +int pkg_dependence_satisfied(depend_t *depend);
  10480. +
  10481. +#endif
  10482. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_dest.c busybox-1.26.0/archival/libipkg/pkg_dest.c
  10483. --- busybox-1.26.0.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10484. +++ busybox-1.26.0/archival/libipkg/pkg_dest.c 2016-12-22 17:08:31.016862000 +0100
  10485. @@ -0,0 +1,92 @@
  10486. +/* pkg_dest.c - the itsy package management system
  10487. +
  10488. + Carl D. Worth
  10489. +
  10490. + Copyright (C) 2001 University of Southern California
  10491. +
  10492. + This program is free software; you can redistribute it and/or
  10493. + modify it under the terms of the GNU General Public License as
  10494. + published by the Free Software Foundation; either version 2, or (at
  10495. + your option) any later version.
  10496. +
  10497. + This program is distributed in the hope that it will be useful, but
  10498. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10499. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10500. + General Public License for more details.
  10501. +*/
  10502. +
  10503. +#include "ipkg.h"
  10504. +
  10505. +#include "pkg_dest.h"
  10506. +#include "file_util.h"
  10507. +#include "str_util.h"
  10508. +#include "sprintf_alloc.h"
  10509. +
  10510. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10511. +{
  10512. + dest->name = strdup(name);
  10513. +
  10514. + /* Guarantee that dest->root_dir ends with a '/' */
  10515. + if (str_ends_with(root_dir, "/")) {
  10516. + dest->root_dir = strdup(root_dir);
  10517. + } else {
  10518. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10519. + }
  10520. + file_mkdir_hier(dest->root_dir, 0755);
  10521. +
  10522. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10523. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10524. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10525. +
  10526. + if (str_starts_with (lists_dir, "/"))
  10527. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10528. + else
  10529. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10530. +
  10531. + file_mkdir_hier(dest->lists_dir, 0755);
  10532. +
  10533. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10534. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10535. + file_mkdir_hier(dest->info_dir, 0755);
  10536. +
  10537. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10538. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10539. +
  10540. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10541. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10542. +
  10543. + dest->status_file = NULL;
  10544. +
  10545. + return 0;
  10546. +}
  10547. +
  10548. +void pkg_dest_deinit(pkg_dest_t *dest)
  10549. +{
  10550. + free(dest->name);
  10551. + dest->name = NULL;
  10552. +
  10553. + free(dest->root_dir);
  10554. + dest->root_dir = NULL;
  10555. +
  10556. + free(dest->ipkg_dir);
  10557. + dest->ipkg_dir = NULL;
  10558. +
  10559. + free(dest->lists_dir);
  10560. + dest->lists_dir = NULL;
  10561. +
  10562. + free(dest->info_dir);
  10563. + dest->info_dir = NULL;
  10564. +
  10565. + free(dest->status_file_name);
  10566. + dest->status_file_name = NULL;
  10567. +
  10568. + free(dest->status_file_tmp_name);
  10569. + dest->status_file_tmp_name = NULL;
  10570. +
  10571. + if (dest->status_file) {
  10572. + fclose(dest->status_file);
  10573. + }
  10574. + dest->status_file = NULL;
  10575. +
  10576. + dest->root_dir = NULL;
  10577. +}
  10578. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_dest.h busybox-1.26.0/archival/libipkg/pkg_dest.h
  10579. --- busybox-1.26.0.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10580. +++ busybox-1.26.0/archival/libipkg/pkg_dest.h 2016-12-22 17:08:31.016862000 +0100
  10581. @@ -0,0 +1,38 @@
  10582. +/* pkg_dest.h - the itsy package management system
  10583. +
  10584. + Carl D. Worth
  10585. +
  10586. + Copyright (C) 2001 University of Southern California
  10587. +
  10588. + This program is free software; you can redistribute it and/or
  10589. + modify it under the terms of the GNU General Public License as
  10590. + published by the Free Software Foundation; either version 2, or (at
  10591. + your option) any later version.
  10592. +
  10593. + This program is distributed in the hope that it will be useful, but
  10594. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10595. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10596. + General Public License for more details.
  10597. +*/
  10598. +
  10599. +#ifndef PKG_DEST_H
  10600. +#define PKG_DEST_H
  10601. +
  10602. +typedef struct pkg_dest pkg_dest_t;
  10603. +struct pkg_dest
  10604. +{
  10605. + char *name;
  10606. + char *root_dir;
  10607. + char *ipkg_dir;
  10608. + char *lists_dir;
  10609. + char *info_dir;
  10610. + char *status_file_name;
  10611. + char *status_file_tmp_name;
  10612. + FILE *status_file;
  10613. +};
  10614. +
  10615. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10616. +void pkg_dest_deinit(pkg_dest_t *dest);
  10617. +
  10618. +#endif
  10619. +
  10620. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_dest_list.c busybox-1.26.0/archival/libipkg/pkg_dest_list.c
  10621. --- busybox-1.26.0.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10622. +++ busybox-1.26.0/archival/libipkg/pkg_dest_list.c 2016-12-22 17:08:31.016862000 +0100
  10623. @@ -0,0 +1,85 @@
  10624. +/* pkg_dest_list.c - the itsy package management system
  10625. +
  10626. + Carl D. Worth
  10627. +
  10628. + Copyright (C) 2001 University of Southern California
  10629. +
  10630. + This program is free software; you can redistribute it and/or
  10631. + modify it under the terms of the GNU General Public License as
  10632. + published by the Free Software Foundation; either version 2, or (at
  10633. + your option) any later version.
  10634. +
  10635. + This program is distributed in the hope that it will be useful, but
  10636. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10637. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10638. + General Public License for more details.
  10639. +*/
  10640. +
  10641. +#include "ipkg.h"
  10642. +
  10643. +#include "pkg_dest.h"
  10644. +#include "void_list.h"
  10645. +#include "pkg_dest_list.h"
  10646. +
  10647. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10648. +{
  10649. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10650. +}
  10651. +
  10652. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10653. +{
  10654. + void_list_elt_deinit((void_list_elt_t *) elt);
  10655. +}
  10656. +
  10657. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10658. +{
  10659. + return void_list_init((void_list_t *) list);
  10660. +}
  10661. +
  10662. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10663. +{
  10664. + pkg_dest_list_elt_t *iter;
  10665. + pkg_dest_t *pkg_dest;
  10666. +
  10667. + for (iter = list->head; iter; iter = iter->next) {
  10668. + pkg_dest = iter->data;
  10669. + pkg_dest_deinit(pkg_dest);
  10670. +
  10671. + /* malloced in pkg_dest_list_append */
  10672. + free(pkg_dest);
  10673. + iter->data = NULL;
  10674. + }
  10675. + void_list_deinit((void_list_t *) list);
  10676. +}
  10677. +
  10678. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10679. + const char *root_dir,const char *lists_dir)
  10680. +{
  10681. + int err;
  10682. + pkg_dest_t *pkg_dest;
  10683. +
  10684. + /* freed in plg_dest_list_deinit */
  10685. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10686. + if (pkg_dest == NULL) {
  10687. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10688. + return NULL;
  10689. + }
  10690. +
  10691. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10692. + err = void_list_append((void_list_t *) list, pkg_dest);
  10693. + if (err) {
  10694. + return NULL;
  10695. + }
  10696. +
  10697. + return pkg_dest;
  10698. +}
  10699. +
  10700. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10701. +{
  10702. + return void_list_push((void_list_t *) list, data);
  10703. +}
  10704. +
  10705. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10706. +{
  10707. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10708. +}
  10709. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_dest_list.h busybox-1.26.0/archival/libipkg/pkg_dest_list.h
  10710. --- busybox-1.26.0.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10711. +++ busybox-1.26.0/archival/libipkg/pkg_dest_list.h 2016-12-22 17:08:31.016862000 +0100
  10712. @@ -0,0 +1,50 @@
  10713. +/* pkg_dest_list.h - the itsy package management system
  10714. +
  10715. + Carl D. Worth
  10716. +
  10717. + Copyright (C) 2001 University of Southern California
  10718. +
  10719. + This program is free software; you can redistribute it and/or
  10720. + modify it under the terms of the GNU General Public License as
  10721. + published by the Free Software Foundation; either version 2, or (at
  10722. + your option) any later version.
  10723. +
  10724. + This program is distributed in the hope that it will be useful, but
  10725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10727. + General Public License for more details.
  10728. +*/
  10729. +
  10730. +#ifndef PKG_DEST_LIST_H
  10731. +#define PKG_DEST_LIST_H
  10732. +
  10733. +#include "pkg_dest.h"
  10734. +
  10735. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10736. +struct pkg_dest_list_elt
  10737. +{
  10738. + pkg_dest_list_elt_t *next;
  10739. + pkg_dest_t *data;
  10740. +};
  10741. +
  10742. +typedef struct pkg_dest_list pkg_dest_list_t;
  10743. +struct pkg_dest_list
  10744. +{
  10745. + pkg_dest_list_elt_t pre_head;
  10746. + pkg_dest_list_elt_t *head;
  10747. + pkg_dest_list_elt_t *tail;
  10748. +};
  10749. +
  10750. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10751. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10752. +
  10753. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10754. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10755. +
  10756. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10757. + const char *root_dir,const char* lists_dir);
  10758. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10759. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10760. +
  10761. +#endif
  10762. +
  10763. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_extract.c busybox-1.26.0/archival/libipkg/pkg_extract.c
  10764. --- busybox-1.26.0.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10765. +++ busybox-1.26.0/archival/libipkg/pkg_extract.c 2016-12-22 17:08:31.016862000 +0100
  10766. @@ -0,0 +1,255 @@
  10767. +/* pkg_extract.c - the itsy package management system
  10768. +
  10769. + Carl D. Worth
  10770. +
  10771. + Copyright (C) 2001 University of Southern California
  10772. +
  10773. + This program is free software; you can redistribute it and/or
  10774. + modify it under the terms of the GNU General Public License as
  10775. + published by the Free Software Foundation; either version 2, or (at
  10776. + your option) any later version.
  10777. +
  10778. + This program is distributed in the hope that it will be useful, but
  10779. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10780. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10781. + General Public License for more details.
  10782. +*/
  10783. +
  10784. +#include "ipkg.h"
  10785. +#include <errno.h>
  10786. +#include <fcntl.h>
  10787. +#include <stdio.h>
  10788. +
  10789. +#include "pkg_extract.h"
  10790. +
  10791. +#include "libbb.h"
  10792. +#include "file_util.h"
  10793. +#include "sprintf_alloc.h"
  10794. +#include "bb_archive.h"
  10795. +
  10796. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10797. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10798. +#define IPKG_CONTROL_FILE "control"
  10799. +
  10800. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10801. +{
  10802. + char *name_ptr = archive_handle->file_header->name;
  10803. +
  10804. + /* Skip all leading "/" */
  10805. + while (*name_ptr == '/')
  10806. + name_ptr++;
  10807. + /* Skip all leading "./" and "../" */
  10808. + while (name_ptr[0] == '.') {
  10809. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10810. + name_ptr++;
  10811. + if (name_ptr[1] != '/')
  10812. + break;
  10813. + name_ptr += 2;
  10814. + }
  10815. +
  10816. + if (name_ptr[0] != '\0') {
  10817. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10818. + data_extract_all(archive_handle);
  10819. + }
  10820. +}
  10821. +
  10822. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10823. +{
  10824. + unsigned size = archive_handle->file_header->size;
  10825. +
  10826. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10827. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10828. +}
  10829. +
  10830. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10831. +{
  10832. + archive_handle_t *archive;
  10833. + char *path;
  10834. +
  10835. + sprintf_alloc(&path, "%s/", dir);
  10836. + archive = init_handle();
  10837. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10838. + archive->filter = filter_accept_list;
  10839. + llist_add_to(&(archive->accept), (char *)filename);
  10840. + archive->dpkg__buffer = path;
  10841. + archive->action_data = ipkg_data_extract_all_prefix;
  10842. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10843. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10844. + close(archive->src_fd);
  10845. + free(archive->accept);
  10846. + free(archive);
  10847. + free(path);
  10848. +}
  10849. +
  10850. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10851. +{
  10852. + unsigned int size = strlen(archive->file_header->name) + 2;
  10853. +
  10854. + if (archive->dpkg__buffer == NULL) {
  10855. + archive->dpkg__buffer = xmalloc(size);
  10856. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10857. + } else {
  10858. + size += strlen(archive->dpkg__buffer);
  10859. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10860. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10861. + }
  10862. + strcat(archive->dpkg__buffer, "\n");
  10863. + data_skip(archive);
  10864. +}
  10865. +
  10866. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10867. +{
  10868. + archive_handle_t *archive;
  10869. + char *name;
  10870. + const char *filename = IPKG_CONTROL_FILE;
  10871. +
  10872. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10873. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10874. + archive = init_handle();
  10875. + archive->src_fd = xopen(name, O_RDONLY);
  10876. + archive->filter = filter_accept_list;
  10877. + llist_add_to(&(archive->accept), (char *)filename);
  10878. + archive->action_data = ipkg_data_extract_to_buffer;
  10879. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10880. + close(archive->src_fd);
  10881. + fputs(archive->dpkg__buffer, stream);
  10882. + free(archive->dpkg__buffer);
  10883. + free(archive->accept);
  10884. + free(archive);
  10885. + free(name);
  10886. +
  10887. + return 0;
  10888. +}
  10889. +
  10890. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10891. +{
  10892. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10893. +}
  10894. +
  10895. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10896. +{
  10897. + archive_handle_t *archive;
  10898. + char *name;
  10899. + char *path;
  10900. +
  10901. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10902. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10903. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10904. + archive = init_handle();
  10905. + archive->src_fd = xopen(name, O_RDONLY);
  10906. + archive->filter = filter_accept_all;
  10907. + archive->dpkg__buffer = path;
  10908. + archive->action_data = ipkg_data_extract_all_prefix;
  10909. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10910. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10911. + close(archive->src_fd);
  10912. + free(archive);
  10913. + free(path);
  10914. + free(name);
  10915. +
  10916. + return 0;
  10917. +}
  10918. +
  10919. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10920. +{
  10921. + archive_handle_t *archive;
  10922. + char *name;
  10923. + char *path;
  10924. +
  10925. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10926. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10927. + sprintf_alloc(&path, "%s/", dir);
  10928. + archive = init_handle();
  10929. + archive->src_fd = xopen(name, O_RDONLY);
  10930. + archive->filter = filter_accept_all;
  10931. + archive->dpkg__buffer = path;
  10932. + archive->action_data = ipkg_data_extract_all_prefix;
  10933. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10934. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10935. + close(archive->src_fd);
  10936. + free(archive);
  10937. + free(path);
  10938. + free(name);
  10939. +
  10940. + return 0;
  10941. +}
  10942. +
  10943. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10944. +{
  10945. + int err=0;
  10946. + char *line, *data_file;
  10947. + FILE *file;
  10948. + FILE *tmp;
  10949. +
  10950. + file = fopen(file_name, "w");
  10951. + if (file == NULL) {
  10952. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10953. + __FUNCTION__, file_name);
  10954. + return EINVAL;
  10955. + }
  10956. +
  10957. + tmp = tmpfile();
  10958. + if (pkg->installed_files) {
  10959. + str_list_elt_t *elt;
  10960. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10961. + fprintf(file, "%s\n", elt->data);
  10962. + }
  10963. + } else {
  10964. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10965. + if (err) {
  10966. + fclose(file);
  10967. + fclose(tmp);
  10968. + return err;
  10969. + }
  10970. +
  10971. + /* Fixup data file names by removing the initial '.' */
  10972. + rewind(tmp);
  10973. + while (1) {
  10974. + line = file_read_line_alloc(tmp);
  10975. + if (line == NULL) {
  10976. + break;
  10977. + }
  10978. +
  10979. + data_file = line;
  10980. + if (*data_file == '.') {
  10981. + data_file++;
  10982. + }
  10983. +
  10984. + if (*data_file != '/') {
  10985. + fputs("/", file);
  10986. + }
  10987. +
  10988. + /* I have no idea why, but this is what dpkg does */
  10989. + if (strcmp(data_file, "/\n") == 0) {
  10990. + fputs("/.\n", file);
  10991. + } else {
  10992. + fputs(data_file, file);
  10993. + }
  10994. + }
  10995. + }
  10996. + fclose(tmp);
  10997. + fclose(file);
  10998. +
  10999. + return err;
  11000. +}
  11001. +
  11002. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11003. +{
  11004. + archive_handle_t *archive;
  11005. + char *name;
  11006. +
  11007. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11008. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11009. + archive = init_handle();
  11010. + archive->src_fd = xopen(name, O_RDONLY);
  11011. + archive->filter = filter_accept_all;
  11012. + archive->action_data = data_extract_file_name_to_buffer;
  11013. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11014. + close(archive->src_fd);
  11015. + fputs(archive->dpkg__buffer, file);
  11016. + free(archive->dpkg__buffer);
  11017. + free(archive);
  11018. + free(name);
  11019. +
  11020. + return 0;
  11021. +}
  11022. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_extract.h busybox-1.26.0/archival/libipkg/pkg_extract.h
  11023. --- busybox-1.26.0.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11024. +++ busybox-1.26.0/archival/libipkg/pkg_extract.h 2016-12-22 17:08:31.016862000 +0100
  11025. @@ -0,0 +1,32 @@
  11026. +/* pkg_extract.c - the itsy package management system
  11027. +
  11028. + Carl D. Worth
  11029. +
  11030. + Copyright (C) 2001 University of Southern California
  11031. +
  11032. + This program is free software; you can redistribute it and/or
  11033. + modify it under the terms of the GNU General Public License as
  11034. + published by the Free Software Foundation; either version 2, or (at
  11035. + your option) any later version.
  11036. +
  11037. + This program is distributed in the hope that it will be useful, but
  11038. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11039. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11040. + General Public License for more details.
  11041. +*/
  11042. +
  11043. +#ifndef PKG_EXTRACT_H
  11044. +#define PKG_EXTRACT_H
  11045. +
  11046. +#include "pkg.h"
  11047. +
  11048. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11049. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11050. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11051. + const char *dir,
  11052. + const char *prefix);
  11053. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11054. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11055. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11056. +
  11057. +#endif
  11058. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg.h busybox-1.26.0/archival/libipkg/pkg.h
  11059. --- busybox-1.26.0.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11060. +++ busybox-1.26.0/archival/libipkg/pkg.h 2016-12-22 17:08:31.016862000 +0100
  11061. @@ -0,0 +1,229 @@
  11062. +/* pkg.h - the itsy package management system
  11063. +
  11064. + Carl D. Worth
  11065. +
  11066. + Copyright (C) 2001 University of Southern California
  11067. +
  11068. + This program is free software; you can redistribute it and/or
  11069. + modify it under the terms of the GNU General Public License as
  11070. + published by the Free Software Foundation; either version 2, or (at
  11071. + your option) any later version.
  11072. +
  11073. + This program is distributed in the hope that it will be useful, but
  11074. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11075. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11076. + General Public License for more details.
  11077. +*/
  11078. +
  11079. +#ifndef PKG_H
  11080. +#define PKG_H
  11081. +
  11082. +#include <sys/types.h>
  11083. +#include <sys/stat.h>
  11084. +#include <unistd.h>
  11085. +
  11086. +#include "pkg_vec.h"
  11087. +#include "str_list.h"
  11088. +#include "pkg_src.h"
  11089. +#include "pkg_dest.h"
  11090. +#include "ipkg_conf.h"
  11091. +#include "conffile_list.h"
  11092. +
  11093. +struct ipkg_conf;
  11094. +
  11095. +/* I think "Size" is currently the shortest field name */
  11096. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11097. +
  11098. +enum pkg_state_want
  11099. +{
  11100. + SW_UNKNOWN = 1,
  11101. + SW_INSTALL,
  11102. + SW_DEINSTALL,
  11103. + SW_PURGE,
  11104. + SW_LAST_STATE_WANT
  11105. +};
  11106. +typedef enum pkg_state_want pkg_state_want_t;
  11107. +
  11108. +enum pkg_state_flag
  11109. +{
  11110. + SF_OK = 0,
  11111. + SF_REINSTREQ = 1,
  11112. + SF_HOLD = 2, /* do not upgrade version */
  11113. + SF_REPLACE = 4, /* replace this package */
  11114. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11115. + SF_PREFER = 16, /* prefer this version */
  11116. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11117. + SF_MARKED = 64, /* temporary mark */
  11118. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11119. + SF_USER = 256,
  11120. + SF_LAST_STATE_FLAG
  11121. +};
  11122. +typedef enum pkg_state_flag pkg_state_flag_t;
  11123. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11124. +
  11125. +enum pkg_state_status
  11126. +{
  11127. + SS_NOT_INSTALLED = 1,
  11128. + SS_UNPACKED,
  11129. + SS_HALF_CONFIGURED,
  11130. + SS_INSTALLED,
  11131. + SS_HALF_INSTALLED,
  11132. + SS_CONFIG_FILES,
  11133. + SS_POST_INST_FAILED,
  11134. + SS_REMOVAL_FAILED,
  11135. + SS_LAST_STATE_STATUS
  11136. +};
  11137. +typedef enum pkg_state_status pkg_state_status_t;
  11138. +
  11139. +struct abstract_pkg{
  11140. + char * name;
  11141. + int dependencies_checked;
  11142. + pkg_vec_t * pkgs;
  11143. + pkg_state_status_t state_status;
  11144. + pkg_state_flag_t state_flag;
  11145. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11146. + abstract_pkg_vec_t * provided_by;
  11147. + abstract_pkg_vec_t * replaced_by;
  11148. +};
  11149. +
  11150. +#include "pkg_depends.h"
  11151. +
  11152. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11153. +
  11154. + The 3 version fields should go into a single version struct. (This
  11155. + is especially important since, currently, pkg->version can easily
  11156. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11157. + distinct. This has been the source of multiple bugs.
  11158. +
  11159. + The 3 state fields could possibly also go into their own struct.
  11160. +
  11161. + All fields which deal with lists of packages, (Depends,
  11162. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11163. + be handled by a single struct in pkg_t
  11164. +
  11165. + All string fields for which there is a small set of possible
  11166. + values, (section, maintainer, architecture, maybe version?), that
  11167. + are reused among different packages -- for all such packages we
  11168. + should move from "char *"s to some atom datatype to share data
  11169. + storage and use less memory. We might even do reference counting,
  11170. + but probably not since most often we only create new pkg_t structs,
  11171. + we don't often free them. */
  11172. +struct pkg
  11173. +{
  11174. + char *name;
  11175. + unsigned long epoch;
  11176. + char *version;
  11177. + char *revision;
  11178. + char *familiar_revision;
  11179. + pkg_src_t *src;
  11180. + pkg_dest_t *dest;
  11181. + char *architecture;
  11182. + char *section;
  11183. + char *maintainer;
  11184. + char *description;
  11185. + pkg_state_want_t state_want;
  11186. + pkg_state_flag_t state_flag;
  11187. + pkg_state_status_t state_status;
  11188. + char **depends_str;
  11189. + int depends_count;
  11190. + char **pre_depends_str;
  11191. + int pre_depends_count;
  11192. + char **recommends_str;
  11193. + int recommends_count;
  11194. + char **suggests_str;
  11195. + int suggests_count;
  11196. + compound_depend_t * depends;
  11197. +
  11198. + /* Abhaya: new conflicts */
  11199. + char **conflicts_str;
  11200. + compound_depend_t * conflicts;
  11201. + int conflicts_count;
  11202. +
  11203. + char **replaces_str;
  11204. + int replaces_count;
  11205. + abstract_pkg_t ** replaces;
  11206. +
  11207. + char **provides_str;
  11208. + int provides_count;
  11209. + abstract_pkg_t ** provides;
  11210. +
  11211. + abstract_pkg_t *parent;
  11212. +
  11213. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11214. +
  11215. + char *filename;
  11216. + char *local_filename;
  11217. + char *url;
  11218. + char *tmp_unpack_dir;
  11219. + char *md5sum;
  11220. + char *size;
  11221. + char *installed_size;
  11222. + char *priority;
  11223. + char *source;
  11224. + conffile_list_t conffiles;
  11225. + time_t installed_time;
  11226. + /* As pointer for lazy evaluation */
  11227. + str_list_t *installed_files;
  11228. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11229. + mechanism to avoid the problem here, (which is that the
  11230. + installed_files list was being freed from an inner loop while
  11231. + still being used within an outer loop. */
  11232. + int installed_files_ref_cnt;
  11233. + int essential;
  11234. + int arch_priority;
  11235. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11236. + int provided_by_hand;
  11237. +};
  11238. +
  11239. +pkg_t *pkg_new(void);
  11240. +int pkg_init(pkg_t *pkg);
  11241. +void pkg_deinit(pkg_t *pkg);
  11242. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11243. +abstract_pkg_t *abstract_pkg_new(void);
  11244. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11245. +
  11246. +/*
  11247. + * merges fields from newpkg into oldpkg.
  11248. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11249. + */
  11250. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11251. +
  11252. +char *pkg_version_str_alloc(pkg_t *pkg);
  11253. +
  11254. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11255. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11256. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11257. +
  11258. +char * pkg_formatted_info(pkg_t *pkg );
  11259. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11260. +
  11261. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11262. +
  11263. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11264. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11265. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11266. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11267. +int pkg_free_installed_files(pkg_t *pkg);
  11268. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11269. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11270. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11271. + const char *script, const char *args);
  11272. +
  11273. +/* enum mappings */
  11274. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11275. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11276. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11277. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11278. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11279. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11280. +
  11281. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11282. +
  11283. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11284. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11285. +int pkg_free_installed_files(pkg_t *pkg);
  11286. +
  11287. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11288. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11289. +
  11290. +#endif
  11291. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_hash.c busybox-1.26.0/archival/libipkg/pkg_hash.c
  11292. --- busybox-1.26.0.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11293. +++ busybox-1.26.0/archival/libipkg/pkg_hash.c 2016-12-22 17:08:31.020864252 +0100
  11294. @@ -0,0 +1,623 @@
  11295. +/* ipkg_hash.c - the itsy package management system
  11296. +
  11297. + Steven M. Ayer
  11298. +
  11299. + Copyright (C) 2002 Compaq Computer Corporation
  11300. +
  11301. + This program is free software; you can redistribute it and/or
  11302. + modify it under the terms of the GNU General Public License as
  11303. + published by the Free Software Foundation; either version 2, or (at
  11304. + your option) any later version.
  11305. +
  11306. + This program is distributed in the hope that it will be useful, but
  11307. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11308. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11309. + General Public License for more details.
  11310. +*/
  11311. +
  11312. +#include "ipkg.h"
  11313. +#include <errno.h>
  11314. +#include <ctype.h>
  11315. +#include <stdlib.h>
  11316. +#include <string.h>
  11317. +
  11318. +#include "hash_table.h"
  11319. +#include "pkg.h"
  11320. +#include "ipkg_message.h"
  11321. +#include "pkg_vec.h"
  11322. +#include "pkg_hash.h"
  11323. +#include "pkg_parse.h"
  11324. +#include "ipkg_utils.h"
  11325. +
  11326. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11327. +
  11328. +/*
  11329. + * this will talk to both feeds-lists files and installed status files
  11330. + * example api:
  11331. + *
  11332. + * hash_table_t hash;
  11333. + * pkg_hash_init(name, &hash, 1000);
  11334. + * pkg_hash_add_from_file(<feed filename>);
  11335. + *
  11336. + * the query function is just there as a shell to prove to me that this
  11337. + * sort of works, but isn't far from doing something useful
  11338. + *
  11339. + * -sma, 12/21/01
  11340. + * modified: CDW 3 Jan. 2002
  11341. + */
  11342. +
  11343. +
  11344. +
  11345. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11346. +{
  11347. + return hash_table_init(name, hash, len);
  11348. +}
  11349. +
  11350. +void pkg_hash_deinit(hash_table_t *hash)
  11351. +{
  11352. + hash_table_deinit(hash);
  11353. +}
  11354. +
  11355. +
  11356. +/* Find the default arch for a given package status file if none is given. */
  11357. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11358. +{
  11359. + nv_pair_list_elt_t *l;
  11360. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11361. + int def_prio = 0; /* Other archs override this */
  11362. +
  11363. + l = conf->arch_list.head;
  11364. +
  11365. + while (l) {
  11366. + nv_pair_t *nv = l->data;
  11367. + int priority = strtol(nv->value, NULL, 0);
  11368. +
  11369. + /* Check if this arch has higher priority, and is valid */
  11370. + if ((priority > def_prio) &&
  11371. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11372. + /* Our new default */
  11373. + def_prio = priority;
  11374. + def_arch = nv->name;
  11375. + }
  11376. + l = l->next;
  11377. + }
  11378. +
  11379. + return strdup(def_arch);
  11380. +}
  11381. +
  11382. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11383. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11384. +{
  11385. + hash_table_t *hash = &conf->pkg_hash;
  11386. + char **raw;
  11387. + char **raw_start;
  11388. + pkg_t *pkg;
  11389. +
  11390. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11391. + if (!raw)
  11392. + return -ENOMEM;
  11393. +
  11394. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11395. + pkg = pkg_new();
  11396. + if (!pkg)
  11397. + return -ENOMEM;
  11398. +
  11399. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11400. + if (!pkg->architecture) {
  11401. + char *version_str = pkg_version_str_alloc(pkg);
  11402. + pkg->architecture = pkg_get_default_arch(conf);
  11403. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11404. + pkg->name, version_str, pkg->architecture);
  11405. + free(version_str);
  11406. + }
  11407. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11408. + } else {
  11409. + free(pkg);
  11410. + }
  11411. + }
  11412. +
  11413. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11414. + memory after read_raw_pkgs_from_file */
  11415. + raw = raw_start;
  11416. + while (*raw) {
  11417. + free(*raw++);
  11418. + }
  11419. + free(raw_start);
  11420. + return 0;
  11421. +}
  11422. +
  11423. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11424. +{
  11425. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11426. +}
  11427. +
  11428. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11429. +{
  11430. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11431. + if (apkg)
  11432. + return NULL;
  11433. + return apkg->provided_by;
  11434. +}
  11435. +
  11436. +
  11437. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11438. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11439. +{
  11440. + int i;
  11441. + int nprovides = 0;
  11442. + int nmatching = 0;
  11443. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11444. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11445. + abstract_pkg_vec_t *provided_apkg_vec;
  11446. + abstract_pkg_t **provided_apkgs;
  11447. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11448. + pkg_t *latest_installed_parent = NULL;
  11449. + pkg_t *latest_matching = NULL;
  11450. + pkg_t *held_pkg = NULL;
  11451. + pkg_t *good_pkg_by_name = NULL;
  11452. +
  11453. + if (matching_apkgs == NULL || providers == NULL ||
  11454. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11455. + return NULL;
  11456. +
  11457. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11458. +
  11459. + provided_apkg_vec = apkg->provided_by;
  11460. + nprovides = provided_apkg_vec->len;
  11461. + provided_apkgs = provided_apkg_vec->pkgs;
  11462. + if (nprovides > 1)
  11463. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11464. +
  11465. + /* accumulate all the providers */
  11466. + for (i = 0; i < nprovides; i++) {
  11467. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11468. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11469. + abstract_pkg_vec_insert(providers, provider_apkg);
  11470. + }
  11471. + nprovides = providers->len;
  11472. +
  11473. + for (i = 0; i < nprovides; i++) {
  11474. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11475. + abstract_pkg_t *replacement_apkg = NULL;
  11476. + pkg_vec_t *vec;
  11477. +
  11478. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11479. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11480. + if (provider_apkg->replaced_by->len > 1) {
  11481. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11482. + provider_apkg->name, replacement_apkg->name);
  11483. + }
  11484. + }
  11485. +
  11486. + if (replacement_apkg)
  11487. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11488. + replacement_apkg->name, provider_apkg->name);
  11489. +
  11490. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11491. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11492. + continue;
  11493. + else
  11494. + provider_apkg = replacement_apkg;
  11495. + }
  11496. +
  11497. + if (!(vec = provider_apkg->pkgs)) {
  11498. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11499. + continue;
  11500. + }
  11501. +
  11502. +
  11503. + /* now check for supported architecture */
  11504. + {
  11505. + int max_count = 0;
  11506. + int j;
  11507. +
  11508. + /* count packages matching max arch priority and keep track of last one */
  11509. + for (j = 0; j < vec->len; j++) {
  11510. + pkg_t *maybe = vec->pkgs[j];
  11511. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11512. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11513. + if (maybe->arch_priority > 0) {
  11514. + max_count++;
  11515. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11516. + pkg_vec_insert(matching_pkgs, maybe);
  11517. + }
  11518. + }
  11519. + }
  11520. + }
  11521. +
  11522. + if (matching_pkgs->len > 1)
  11523. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11524. + if (matching_apkgs->len > 1)
  11525. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11526. +
  11527. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11528. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11529. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11530. + Until now I always got the latest, but that breaks the downgrade option.
  11531. + If I stop at the first one, I would probably miss the new ones
  11532. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11533. + or from a Packages feed.
  11534. + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
  11535. +/*Pigi*/
  11536. +
  11537. + for (i = 0; i < matching_pkgs->len; i++) {
  11538. + pkg_t *matching = matching_pkgs->pkgs[i];
  11539. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11540. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11541. + good_pkg_by_name = matching;
  11542. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11543. + break;
  11544. + }
  11545. + }
  11546. +
  11547. +
  11548. + for (i = 0; i < matching_pkgs->len; i++) {
  11549. + pkg_t *matching = matching_pkgs->pkgs[i];
  11550. + latest_matching = matching;
  11551. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11552. + latest_installed_parent = matching;
  11553. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11554. + if (held_pkg)
  11555. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11556. + held_pkg->name, matching->name);
  11557. + held_pkg = matching;
  11558. + }
  11559. + }
  11560. +
  11561. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11562. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11563. + apkg->name, matching_apkgs->len);
  11564. + for (i = 0; i < matching_apkgs->len; i++) {
  11565. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11566. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11567. + }
  11568. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11569. + }
  11570. +
  11571. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11572. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11573. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11574. + for (i = 0; i < matching_pkgs->len; i++) {
  11575. + pkg_t *matching = matching_pkgs->pkgs[i];
  11576. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11577. + matching->name, matching->version, matching->architecture);
  11578. + }
  11579. + }
  11580. +
  11581. + nmatching = matching_apkgs->len;
  11582. +
  11583. + pkg_vec_free(matching_pkgs);
  11584. + abstract_pkg_vec_free(matching_apkgs);
  11585. + abstract_pkg_vec_free(providers);
  11586. +
  11587. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11588. + return good_pkg_by_name;
  11589. + }
  11590. + if (held_pkg) {
  11591. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11592. + return held_pkg;
  11593. + }
  11594. + if (latest_installed_parent) {
  11595. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11596. + return latest_installed_parent;
  11597. + }
  11598. + if (nmatching > 1) {
  11599. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11600. + return NULL;
  11601. + }
  11602. + if (latest_matching) {
  11603. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11604. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11605. + return latest_matching;
  11606. + }
  11607. + return NULL;
  11608. +}
  11609. +
  11610. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11611. +{
  11612. + const char *name = (const char *)cdata;
  11613. + if (strcmp(pkg->name, name) == 0)
  11614. + return 1;
  11615. + else
  11616. + return 0;
  11617. +}
  11618. +
  11619. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11620. +{
  11621. + hash_table_t *hash = &conf->pkg_hash;
  11622. + abstract_pkg_t *apkg = NULL;
  11623. +
  11624. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11625. + return NULL;
  11626. +
  11627. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11628. +}
  11629. +
  11630. +
  11631. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11632. + const char *pkg_name,
  11633. + const char * version)
  11634. +{
  11635. + pkg_vec_t * vec;
  11636. + register int i;
  11637. + char *version_str = NULL;
  11638. +
  11639. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11640. + return NULL;
  11641. +
  11642. + for(i = 0; i < vec->len; i++) {
  11643. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11644. + if(!strcmp(version_str, version)) {
  11645. + free(version_str);
  11646. + break;
  11647. + }
  11648. + free(version_str);
  11649. + }
  11650. +
  11651. + if(i == vec->len)
  11652. + return NULL;
  11653. +
  11654. + return vec->pkgs[i];
  11655. +}
  11656. +
  11657. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11658. + const char *pkg_name,
  11659. + pkg_dest_t *dest)
  11660. +{
  11661. + pkg_vec_t * vec;
  11662. + register int i;
  11663. +
  11664. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11665. + return NULL;
  11666. + }
  11667. +
  11668. + for(i = 0; i < vec->len; i++)
  11669. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11670. + return vec->pkgs[i];
  11671. + }
  11672. + return NULL;
  11673. +}
  11674. +
  11675. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11676. + const char *pkg_name)
  11677. +{
  11678. + pkg_vec_t * vec;
  11679. + register int i;
  11680. +
  11681. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11682. + return NULL;
  11683. + }
  11684. +
  11685. + for(i = 0; i < vec->len; i++)
  11686. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11687. + return vec->pkgs[i];
  11688. + }
  11689. +
  11690. + return NULL;
  11691. +}
  11692. +
  11693. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11694. +{
  11695. + abstract_pkg_t * ab_pkg;
  11696. +
  11697. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11698. + return NULL;
  11699. + }
  11700. +
  11701. + if (ab_pkg->pkgs) {
  11702. + return ab_pkg->pkgs;
  11703. + } else if (ab_pkg->provided_by) {
  11704. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11705. + if (abpkg != NULL){
  11706. + return abpkg->pkgs;
  11707. + } else {
  11708. + return ab_pkg->pkgs;
  11709. + }
  11710. + } else {
  11711. + return NULL;
  11712. + }
  11713. +}
  11714. +
  11715. +static int pkg_compare_names(const void *p1, const void *p2)
  11716. +{
  11717. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11718. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11719. + if (pkg1->name == NULL)
  11720. + return 1;
  11721. + if (pkg2->name == NULL)
  11722. + return -1;
  11723. + return(strcmp(pkg1->name, pkg2->name));
  11724. +}
  11725. +
  11726. +
  11727. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11728. +{
  11729. + int j;
  11730. + const char *name;
  11731. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11732. + pkg_vec_t *all = (pkg_vec_t *)data;
  11733. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11734. + name = pkg_name;
  11735. + if (pkg_vec) {
  11736. + for (j = 0; j < pkg_vec->len; j++) {
  11737. + pkg_t *pkg = pkg_vec->pkgs[j];
  11738. + pkg_vec_insert(all, pkg);
  11739. + }
  11740. + }
  11741. +}
  11742. +
  11743. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11744. +{
  11745. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11746. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11747. +}
  11748. +
  11749. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11750. +{
  11751. + const char *name;
  11752. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11753. + pkg_vec_t *all = (pkg_vec_t *)data;
  11754. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11755. + int j;
  11756. + name = pkg_name;
  11757. + if (pkg_vec) {
  11758. + for (j = 0; j < pkg_vec->len; j++) {
  11759. + pkg_t *pkg = pkg_vec->pkgs[j];
  11760. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11761. + pkg_vec_insert(all, pkg);
  11762. + }
  11763. + }
  11764. + }
  11765. +}
  11766. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11767. +{
  11768. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11769. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11770. +}
  11771. +
  11772. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11773. +{
  11774. + int i;
  11775. + pkg_t *pkg;
  11776. + const char *name;
  11777. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11778. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11779. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11780. + name = pkg_name;
  11781. + fprintf(stdout, "%s\n", ab_pkg->name);
  11782. + i = 0;
  11783. + if (dependents != NULL)
  11784. + while (dependents [i] != NULL)
  11785. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11786. + dependents = ab_pkg->provided_by->pkgs;
  11787. + i = 0;
  11788. + if (dependents != NULL)
  11789. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11790. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11791. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11792. + if (pkg) {
  11793. + i = 0;
  11794. + while (i < pkg->depends_count)
  11795. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11796. + }
  11797. +}
  11798. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11799. +{
  11800. +
  11801. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11802. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11803. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11804. +}
  11805. +
  11806. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11807. +{
  11808. + abstract_pkg_t * ab_pkg;
  11809. +
  11810. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11811. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11812. +
  11813. + return ab_pkg;
  11814. +}
  11815. +
  11816. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11817. +{
  11818. + abstract_pkg_t * ab_pkg;
  11819. + int arch_priority;
  11820. +
  11821. + if(!pkg)
  11822. + return pkg;
  11823. +
  11824. + arch_priority = pkg->arch_priority;
  11825. +
  11826. + if (buildDepends(hash, pkg)<0){
  11827. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11828. + return NULL;
  11829. + }
  11830. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11831. +
  11832. + if (set_status) {
  11833. + if (pkg->state_status == SS_INSTALLED) {
  11834. + ab_pkg->state_status = SS_INSTALLED;
  11835. + } else if (pkg->state_status == SS_UNPACKED) {
  11836. + ab_pkg->state_status = SS_UNPACKED;
  11837. + }
  11838. + }
  11839. +
  11840. + if(!ab_pkg->pkgs)
  11841. + ab_pkg->pkgs = pkg_vec_alloc();
  11842. +
  11843. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11844. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11845. + pkg->parent = ab_pkg;
  11846. +
  11847. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11848. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11849. + return NULL;
  11850. + }
  11851. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11852. + if (buildConflicts(hash, pkg)<0){
  11853. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11854. + return NULL;
  11855. + }
  11856. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11857. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11858. + return NULL;
  11859. + }
  11860. +
  11861. + buildDependedUponBy(pkg, ab_pkg);
  11862. + return pkg;
  11863. +}
  11864. +
  11865. +/*
  11866. + * this will assume that we've already determined that
  11867. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11868. + */
  11869. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11870. +{
  11871. + abstract_pkg_t * ab_pkg;
  11872. +
  11873. + ab_pkg = abstract_pkg_new();
  11874. + if (ab_pkg == NULL) { return NULL; }
  11875. +
  11876. + ab_pkg->name = strdup(pkg_name);
  11877. + hash_table_insert(hash, pkg_name, ab_pkg);
  11878. +
  11879. + return ab_pkg;
  11880. +}
  11881. +
  11882. +
  11883. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11884. +{
  11885. + hash_table_t *file_hash = &conf->file_hash;
  11886. +
  11887. + return hash_table_get(file_hash, file_name);
  11888. +}
  11889. +
  11890. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11891. +{
  11892. + hash_table_t *file_hash = &conf->file_hash;
  11893. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11894. + int file_name_len = strlen(file_name);
  11895. +
  11896. + if (file_name[file_name_len -1] == '/')
  11897. + return 0;
  11898. +
  11899. + if (conf->offline_root) {
  11900. + int len = strlen(conf->offline_root);
  11901. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11902. + file_name += len;
  11903. + }
  11904. + }
  11905. +
  11906. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11907. + hash_table_insert(file_hash, file_name, owning_pkg);
  11908. + if (old_owning_pkg) {
  11909. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11910. + /* mark this package to have its filelist written */
  11911. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11912. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11913. + }
  11914. + return 0;
  11915. +}
  11916. +
  11917. +
  11918. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_hash.h busybox-1.26.0/archival/libipkg/pkg_hash.h
  11919. --- busybox-1.26.0.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11920. +++ busybox-1.26.0/archival/libipkg/pkg_hash.h 2016-12-22 17:08:31.020864252 +0100
  11921. @@ -0,0 +1,61 @@
  11922. +/* pkg_hash.h - the itsy package management system
  11923. +
  11924. + Steven M. Ayer
  11925. +
  11926. + Copyright (C) 2002 Compaq Computer Corporation
  11927. +
  11928. + This program is free software; you can redistribute it and/or
  11929. + modify it under the terms of the GNU General Public License as
  11930. + published by the Free Software Foundation; either version 2, or (at
  11931. + your option) any later version.
  11932. +
  11933. + This program is distributed in the hope that it will be useful, but
  11934. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11935. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11936. + General Public License for more details.
  11937. +*/
  11938. +
  11939. +#ifndef PKG_HASH_H
  11940. +#define PKG_HASH_H
  11941. +
  11942. +#include "pkg.h"
  11943. +#include "pkg_vec.h"
  11944. +#include "hash_table.h"
  11945. +
  11946. +
  11947. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11948. +void pkg_hash_deinit(hash_table_t *hash);
  11949. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11950. +
  11951. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11952. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11953. +
  11954. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11955. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11956. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11957. +
  11958. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11959. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11960. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11961. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11962. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11963. + const char *pkg_name,
  11964. + const char * version);
  11965. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11966. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11967. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11968. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11969. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11970. + const char *pkg_name);
  11971. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11972. + const char *pkg_name,
  11973. + pkg_dest_t *dest);
  11974. +
  11975. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11976. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11977. +
  11978. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11979. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11980. +
  11981. +#endif
  11982. +
  11983. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_parse.c busybox-1.26.0/archival/libipkg/pkg_parse.c
  11984. --- busybox-1.26.0.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11985. +++ busybox-1.26.0/archival/libipkg/pkg_parse.c 2016-12-22 17:08:31.020864252 +0100
  11986. @@ -0,0 +1,368 @@
  11987. +/* pkg_parse.c - the itsy package management system
  11988. +
  11989. + Steven M. Ayer
  11990. +
  11991. + Copyright (C) 2002 Compaq Computer Corporation
  11992. +
  11993. + This program is free software; you can redistribute it and/or
  11994. + modify it under the terms of the GNU General Public License as
  11995. + published by the Free Software Foundation; either version 2, or (at
  11996. + your option) any later version.
  11997. +
  11998. + This program is distributed in the hope that it will be useful, but
  11999. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12000. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12001. + General Public License for more details.
  12002. +*/
  12003. +
  12004. +#include "ipkg.h"
  12005. +#include <errno.h>
  12006. +#include <ctype.h>
  12007. +
  12008. +#include "pkg.h"
  12009. +#include "ipkg_utils.h"
  12010. +#include "pkg_parse.h"
  12011. +
  12012. +int alterProvidesLine(char *raw, char *temp);
  12013. +
  12014. +int isGenericFieldType(char * type, char * line)
  12015. +{
  12016. + if(!strncmp(line, type, strlen(type)))
  12017. + return 1;
  12018. + return 0;
  12019. +}
  12020. +
  12021. +char * parseGenericFieldType(char * type, char * raw)
  12022. +{
  12023. + char * field_value = raw + (strlen(type) + 1);
  12024. + return trim_alloc(field_value);
  12025. +}
  12026. +
  12027. +void parseStatus(pkg_t *pkg, char * raw)
  12028. +{
  12029. + char sw_str[64], sf_str[64], ss_str[64];
  12030. +
  12031. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12032. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12033. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12034. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12035. +}
  12036. +
  12037. +char ** parseDependsString(char * raw, int * depends_count)
  12038. +{
  12039. + char ** depends = NULL;
  12040. + int line_count = 0;
  12041. + char buff[2048], * dest;
  12042. +
  12043. + while(raw && *raw && !isspace(*raw)) {
  12044. + raw++;
  12045. + }
  12046. +
  12047. + if(line_is_blank(raw)){
  12048. + *depends_count = line_count;
  12049. + return NULL;
  12050. + }
  12051. + while(raw && *raw){
  12052. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12053. +
  12054. + while(isspace(*raw)) raw++;
  12055. +
  12056. + dest = buff;
  12057. + while((*raw != ',') && *raw)
  12058. + *dest++ = *raw++;
  12059. +
  12060. + *dest = '\0';
  12061. + depends[line_count] = trim_alloc(buff);
  12062. + if(depends[line_count] ==NULL)
  12063. + return NULL;
  12064. + line_count++;
  12065. + if(*raw == ',')
  12066. + raw++;
  12067. + }
  12068. + *depends_count = line_count;
  12069. + return depends;
  12070. +}
  12071. +
  12072. +void parseConffiles(pkg_t * pkg, char * raw)
  12073. +{
  12074. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12075. +
  12076. + if(!strncmp(raw, "Conffiles:", 10))
  12077. + raw += strlen("Conffiles:");
  12078. +
  12079. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12080. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12081. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12082. + while (*raw && isspace(*raw)) {
  12083. + raw++;
  12084. + }
  12085. + raw += strlen(file_name);
  12086. + while (*raw && isspace(*raw)) {
  12087. + raw++;
  12088. + }
  12089. + raw += strlen(md5sum);
  12090. + }
  12091. +}
  12092. +
  12093. +int parseVersion(pkg_t *pkg, char *raw)
  12094. +{
  12095. + char *colon, *eepochcolon;
  12096. +#ifdef USE_DEBVERSION
  12097. + char *hyphen;
  12098. +#endif
  12099. + unsigned long epoch;
  12100. +
  12101. + if (!*raw) {
  12102. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12103. + return EINVAL;
  12104. + }
  12105. +
  12106. + if (strncmp(raw, "Version:", 8) == 0) {
  12107. + raw += 8;
  12108. + }
  12109. + while (*raw && isspace(*raw)) {
  12110. + raw++;
  12111. + }
  12112. +
  12113. + colon= strchr(raw,':');
  12114. + if (colon) {
  12115. + epoch= strtoul(raw,&eepochcolon,10);
  12116. + if (colon != eepochcolon) {
  12117. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12118. + return EINVAL;
  12119. + }
  12120. + if (!*++colon) {
  12121. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12122. + return EINVAL;
  12123. + }
  12124. + raw= colon;
  12125. + pkg->epoch= epoch;
  12126. + } else {
  12127. + pkg->epoch= 0;
  12128. + }
  12129. +
  12130. + pkg->revision = (char *)"";
  12131. + pkg->familiar_revision = (char *)"";
  12132. +
  12133. + pkg->version= malloc(strlen(raw)+1);
  12134. + if ( pkg->version == NULL ) {
  12135. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12136. + return ENOMEM;
  12137. + }
  12138. + strcpy(pkg->version, raw);
  12139. +
  12140. +#ifdef USE_DEBVERSION
  12141. + hyphen= strrchr(pkg->version,'-');
  12142. +
  12143. + if (hyphen) {
  12144. + *hyphen++= 0;
  12145. + if (strncmp("fam", hyphen, 3) == 0) {
  12146. + pkg->familiar_revision=hyphen+3;
  12147. + hyphen= strrchr(pkg->version,'-');
  12148. + if (hyphen) {
  12149. + *hyphen++= 0;
  12150. + pkg->revision = hyphen;
  12151. + }
  12152. + } else {
  12153. + pkg->revision = hyphen;
  12154. + }
  12155. + }
  12156. +#endif
  12157. +
  12158. +/*
  12159. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12160. + pkg->epoch,
  12161. + pkg->version,
  12162. + pkg->revision,
  12163. + pkg->familiar_revision);
  12164. +*/
  12165. +
  12166. + return 0;
  12167. +}
  12168. +
  12169. +
  12170. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12171. +
  12172. +int alterProvidesLine(char *raw, char *temp)
  12173. +{
  12174. +
  12175. +
  12176. + if (!*raw) {
  12177. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12178. + return -EINVAL;
  12179. + }
  12180. +
  12181. + if ( temp == NULL ) {
  12182. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12183. + return -ENOMEM;
  12184. + }
  12185. +
  12186. + if (strncmp(raw, "Provides:", 9) == 0) {
  12187. + raw += 9;
  12188. + }
  12189. + while (*raw && isspace(*raw)) {
  12190. + raw++;
  12191. + }
  12192. +
  12193. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12194. + while (*raw) {
  12195. + strncat( temp, raw++, 1);
  12196. + }
  12197. + return 0;
  12198. +
  12199. +}
  12200. +
  12201. +/* Some random thoughts from Carl:
  12202. +
  12203. + This function could be considerably simplified if we just kept
  12204. + an array of all the generic string-valued field names, and looped
  12205. + through those looking for a match. Also, these fields could perhaps
  12206. + be stored in the package as an array as well, (or, probably better,
  12207. + as an nv_pair_list_t).
  12208. +
  12209. + Fields which require special parsing or storage, (such as Depends:
  12210. + and Status:) could be handled as they are now.
  12211. +*/
  12212. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12213. + to a dependency list. And, since we already have
  12214. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12215. + Enhances, perhaps we could generalize all of these and save some
  12216. + code duplication.
  12217. +*/
  12218. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12219. +{
  12220. + int reading_conffiles, reading_description;
  12221. + int pkg_false_provides=1;
  12222. + char ** lines;
  12223. + char * provide=NULL;
  12224. +
  12225. + pkg->src = src;
  12226. + pkg->dest = dest;
  12227. +
  12228. + reading_conffiles = reading_description = 0;
  12229. +
  12230. + for (lines = *raw; *lines; lines++) {
  12231. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12232. + if(isGenericFieldType((char *)"Package:", *lines))
  12233. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12234. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12235. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12236. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12237. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12238. + else if(isGenericFieldType((char *)"Section:", *lines))
  12239. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12240. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12241. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12242. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12243. + let's parse it either way */
  12244. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12245. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12246. + else if(isGenericFieldType((char *)"Size:", *lines))
  12247. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12248. + else if(isGenericFieldType((char *)"Source:", *lines))
  12249. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12250. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12251. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12252. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12253. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12254. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12255. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12256. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12257. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12258. + char *essential_value;
  12259. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12260. + if (strcmp(essential_value, "yes") == 0) {
  12261. + pkg->essential = 1;
  12262. + }
  12263. + free(essential_value);
  12264. + }
  12265. + else if(isGenericFieldType((char *)"Status", *lines))
  12266. + parseStatus(pkg, *lines);
  12267. + else if(isGenericFieldType((char *)"Version", *lines))
  12268. + parseVersion(pkg, *lines);
  12269. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12270. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12271. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12272. + parseConffiles(pkg, *lines);
  12273. + reading_conffiles = 1;
  12274. + }
  12275. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12276. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12277. + reading_conffiles = 0;
  12278. + reading_description = 1;
  12279. + }
  12280. +
  12281. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12282. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12283. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12284. + if ( alterProvidesLine(*lines,provide) ){
  12285. + return EINVAL;
  12286. + }
  12287. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12288. +/* Let's try to hack a bit here.
  12289. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12290. + in alot of other places. We will remove it before writing down the status database */
  12291. + pkg_false_provides=0;
  12292. + free(provide);
  12293. + }
  12294. +
  12295. + else if(isGenericFieldType((char *)"Depends", *lines))
  12296. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12297. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12298. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12299. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12300. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12301. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12302. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12303. + /* Abhaya: support for conflicts */
  12304. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12305. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12306. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12307. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12308. + else if(line_is_blank(*lines)) {
  12309. + lines++;
  12310. + break;
  12311. + }
  12312. + else if(**lines == ' '){
  12313. + if(reading_description) {
  12314. + /* we already know it's not blank, so the rest of description */
  12315. + pkg->description = realloc(pkg->description,
  12316. + strlen(pkg->description)
  12317. + + 1 + strlen(*lines) + 1);
  12318. + strcat(pkg->description, "\n");
  12319. + strcat(pkg->description, (*lines));
  12320. + }
  12321. + else if(reading_conffiles)
  12322. + parseConffiles(pkg, *lines);
  12323. + }
  12324. + }
  12325. + *raw = lines;
  12326. +/* If the ipk has not a Provides line, we insert our false line */
  12327. + if ( pkg_false_provides==1)
  12328. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12329. +
  12330. + if (pkg->name) {
  12331. + return 0;
  12332. + } else {
  12333. + return EINVAL;
  12334. + }
  12335. +}
  12336. +
  12337. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12338. +{
  12339. + char ** lines;
  12340. +
  12341. + for (lines = *raw; *lines; lines++) {
  12342. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12343. + char *essential_value;
  12344. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12345. + if (strcmp(essential_value, "yes") == 0) {
  12346. + pkg->essential = 1;
  12347. + }
  12348. + free(essential_value);
  12349. + }
  12350. + }
  12351. + *raw = lines;
  12352. +
  12353. + return 0;
  12354. +}
  12355. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_parse.h busybox-1.26.0/archival/libipkg/pkg_parse.h
  12356. --- busybox-1.26.0.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12357. +++ busybox-1.26.0/archival/libipkg/pkg_parse.h 2016-12-22 17:08:31.020864252 +0100
  12358. @@ -0,0 +1,31 @@
  12359. +/* pkg_parse.h - the itsy package management system
  12360. +
  12361. + Steven M. Ayer
  12362. +
  12363. + Copyright (C) 2002 Compaq Computer Corporation
  12364. +
  12365. + This program is free software; you can redistribute it and/or
  12366. + modify it under the terms of the GNU General Public License as
  12367. + published by the Free Software Foundation; either version 2, or (at
  12368. + your option) any later version.
  12369. +
  12370. + This program is distributed in the hope that it will be useful, but
  12371. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12372. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12373. + General Public License for more details.
  12374. +*/
  12375. +
  12376. +#ifndef PKG_PARSE_H
  12377. +#define PKG_PARSE_H
  12378. +
  12379. +int isGenericFieldType(char * type, char * line);
  12380. +char * parseGenericFieldType(char * type, char * raw);
  12381. +void parseStatus(pkg_t *pkg, char * raw);
  12382. +int parseVersion(pkg_t *pkg, char *raw);
  12383. +char ** parseDependsString(char * raw, int * depends_count);
  12384. +int parseVersion(pkg_t *pkg, char *raw);
  12385. +void parseConffiles(pkg_t * pkg, char * raw);
  12386. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12387. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12388. +
  12389. +#endif
  12390. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_src.c busybox-1.26.0/archival/libipkg/pkg_src.c
  12391. --- busybox-1.26.0.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12392. +++ busybox-1.26.0/archival/libipkg/pkg_src.c 2016-12-22 17:08:31.020864252 +0100
  12393. @@ -0,0 +1,43 @@
  12394. +/* pkg_src.c - the itsy package management system
  12395. +
  12396. + Carl D. Worth
  12397. +
  12398. + Copyright (C) 2001 University of Southern California
  12399. +
  12400. + This program is free software; you can redistribute it and/or
  12401. + modify it under the terms of the GNU General Public License as
  12402. + published by the Free Software Foundation; either version 2, or (at
  12403. + your option) any later version.
  12404. +
  12405. + This program is distributed in the hope that it will be useful, but
  12406. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12407. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12408. + General Public License for more details.
  12409. +*/
  12410. +
  12411. +#include "ipkg.h"
  12412. +
  12413. +#include "pkg_src.h"
  12414. +#include "str_util.h"
  12415. +
  12416. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12417. +{
  12418. + src->gzip = gzip;
  12419. + src->name = str_dup_safe (name);
  12420. + src->value = str_dup_safe (base_url);
  12421. + if (extra_data)
  12422. + src->extra_data = str_dup_safe (extra_data);
  12423. + else
  12424. + src->extra_data = NULL;
  12425. + return 0;
  12426. +}
  12427. +
  12428. +void pkg_src_deinit(pkg_src_t *src)
  12429. +{
  12430. + free (src->name);
  12431. + free (src->value);
  12432. + if (src->extra_data)
  12433. + free (src->extra_data);
  12434. +}
  12435. +
  12436. +
  12437. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_src.h busybox-1.26.0/archival/libipkg/pkg_src.h
  12438. --- busybox-1.26.0.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12439. +++ busybox-1.26.0/archival/libipkg/pkg_src.h 2016-12-22 17:08:31.020864252 +0100
  12440. @@ -0,0 +1,34 @@
  12441. +/* pkg_src.h - the itsy package management system
  12442. +
  12443. + Carl D. Worth
  12444. +
  12445. + Copyright (C) 2001 University of Southern California
  12446. +
  12447. + This program is free software; you can redistribute it and/or
  12448. + modify it under the terms of the GNU General Public License as
  12449. + published by the Free Software Foundation; either version 2, or (at
  12450. + your option) any later version.
  12451. +
  12452. + This program is distributed in the hope that it will be useful, but
  12453. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12454. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12455. + General Public License for more details.
  12456. +*/
  12457. +
  12458. +#ifndef PKG_SRC_H
  12459. +#define PKG_SRC_H
  12460. +
  12461. +#include "nv_pair.h"
  12462. +
  12463. +typedef struct
  12464. +{
  12465. + char *name;
  12466. + char *value;
  12467. + char *extra_data;
  12468. + int gzip;
  12469. +} pkg_src_t;
  12470. +
  12471. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12472. +void pkg_src_deinit(pkg_src_t *src);
  12473. +
  12474. +#endif
  12475. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_src_list.c busybox-1.26.0/archival/libipkg/pkg_src_list.c
  12476. --- busybox-1.26.0.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12477. +++ busybox-1.26.0/archival/libipkg/pkg_src_list.c 2016-12-22 17:08:31.020864252 +0100
  12478. @@ -0,0 +1,75 @@
  12479. +/* pkg_src_list.c - the itsy package management system
  12480. +
  12481. + Carl D. Worth
  12482. +
  12483. + Copyright (C) 2001 University of Southern California
  12484. +
  12485. + This program is free software; you can redistribute it and/or
  12486. + modify it under the terms of the GNU General Public License as
  12487. + published by the Free Software Foundation; either version 2, or (at
  12488. + your option) any later version.
  12489. +
  12490. + This program is distributed in the hope that it will be useful, but
  12491. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12492. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12493. + General Public License for more details.
  12494. +*/
  12495. +
  12496. +#include "ipkg.h"
  12497. +
  12498. +#include "pkg_src_list.h"
  12499. +#include "void_list.h"
  12500. +
  12501. +int pkg_src_list_init(pkg_src_list_t *list)
  12502. +{
  12503. + return void_list_init((void_list_t *) list);
  12504. +}
  12505. +
  12506. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12507. +{
  12508. + pkg_src_list_elt_t *iter;
  12509. + pkg_src_t *pkg_src;
  12510. +
  12511. + for (iter = list->head; iter; iter = iter->next) {
  12512. + pkg_src = iter->data;
  12513. + pkg_src_deinit(pkg_src);
  12514. +
  12515. + /* malloced in pkg_src_list_append */
  12516. + free(pkg_src);
  12517. + iter->data = NULL;
  12518. + }
  12519. + void_list_deinit((void_list_t *) list);
  12520. +}
  12521. +
  12522. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12523. + const char *name, const char *base_url, const char *extra_data,
  12524. + int gzip)
  12525. +{
  12526. + int err;
  12527. +
  12528. + /* freed in pkg_src_list_deinit */
  12529. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12530. +
  12531. + if (pkg_src == NULL) {
  12532. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12533. + return NULL;
  12534. + }
  12535. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12536. +
  12537. + err = void_list_append((void_list_t *) list, pkg_src);
  12538. + if (err) {
  12539. + return NULL;
  12540. + }
  12541. +
  12542. + return pkg_src;
  12543. +}
  12544. +
  12545. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12546. +{
  12547. + return void_list_push((void_list_t *) list, data);
  12548. +}
  12549. +
  12550. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12551. +{
  12552. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12553. +}
  12554. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_src_list.h busybox-1.26.0/archival/libipkg/pkg_src_list.h
  12555. --- busybox-1.26.0.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12556. +++ busybox-1.26.0/archival/libipkg/pkg_src_list.h 2016-12-22 17:08:31.020864252 +0100
  12557. @@ -0,0 +1,57 @@
  12558. +/* pkg_src_list.h - the itsy package management system
  12559. +
  12560. + Carl D. Worth
  12561. +
  12562. + Copyright (C) 2001 University of Southern California
  12563. +
  12564. + This program is free software; you can redistribute it and/or
  12565. + modify it under the terms of the GNU General Public License as
  12566. + published by the Free Software Foundation; either version 2, or (at
  12567. + your option) any later version.
  12568. +
  12569. + This program is distributed in the hope that it will be useful, but
  12570. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12571. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12572. + General Public License for more details.
  12573. +*/
  12574. +
  12575. +#ifndef PKG_SRC_LIST_H
  12576. +#define PKG_SRC_LIST_H
  12577. +
  12578. +#include "pkg_src.h"
  12579. +
  12580. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12581. +struct pkg_src_list_elt
  12582. +{
  12583. + pkg_src_list_elt_t *next;
  12584. + pkg_src_t *data;
  12585. +};
  12586. +
  12587. +typedef struct pkg_src_list pkg_src_list_t;
  12588. +struct pkg_src_list
  12589. +{
  12590. + pkg_src_list_elt_t pre_head;
  12591. + pkg_src_list_elt_t *head;
  12592. + pkg_src_list_elt_t *tail;
  12593. +};
  12594. +
  12595. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12596. +{
  12597. + if (list->head == NULL)
  12598. + return 1;
  12599. + else
  12600. + return 0;
  12601. +}
  12602. +
  12603. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12604. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12605. +
  12606. +int pkg_src_list_init(pkg_src_list_t *list);
  12607. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12608. +
  12609. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
  12610. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12611. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12612. +
  12613. +#endif
  12614. +
  12615. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_vec.c busybox-1.26.0/archival/libipkg/pkg_vec.c
  12616. --- busybox-1.26.0.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12617. +++ busybox-1.26.0/archival/libipkg/pkg_vec.c 2016-12-22 17:08:31.024866515 +0100
  12618. @@ -0,0 +1,231 @@
  12619. +/* pkg_vec.c - the itsy package management system
  12620. +
  12621. + Steven M. Ayer
  12622. +
  12623. + Copyright (C) 2002 Compaq Computer Corporation
  12624. +
  12625. + This program is free software; you can redistribute it and/or
  12626. + modify it under the terms of the GNU General Public License as
  12627. + published by the Free Software Foundation; either version 2, or (at
  12628. + your option) any later version.
  12629. +
  12630. + This program is distributed in the hope that it will be useful, but
  12631. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12632. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12633. + General Public License for more details.
  12634. +*/
  12635. +
  12636. +#include <stdlib.h>
  12637. +#include <fnmatch.h>
  12638. +#include "libbb.h"
  12639. +#include "xregex.h"
  12640. +#include "ipkg.h"
  12641. +#include "pkg.h"
  12642. +
  12643. +pkg_vec_t * pkg_vec_alloc(void)
  12644. +{
  12645. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12646. + if (!vec) {
  12647. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12648. + return NULL;
  12649. + }
  12650. + vec->pkgs = NULL;
  12651. + vec->len = 0;
  12652. +
  12653. + return vec;
  12654. +}
  12655. +
  12656. +void pkg_vec_free(pkg_vec_t *vec)
  12657. +{
  12658. + free(vec->pkgs);
  12659. + free(vec);
  12660. +}
  12661. +
  12662. +/*
  12663. + * assumption: all names in a vector are identical
  12664. + * assumption: all version strings are trimmed,
  12665. + * so identical versions have identical version strings,
  12666. + * implying identical packages; let's marry these
  12667. + */
  12668. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12669. +{
  12670. + int i;
  12671. + int found = 0;
  12672. +
  12673. + /* look for a duplicate pkg by name, version, and architecture */
  12674. + for (i = 0; i < vec->len; i++){
  12675. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12676. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12677. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12678. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12679. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12680. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12681. + found = 1;
  12682. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12683. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12684. + break;
  12685. + }
  12686. + }
  12687. +
  12688. + /* we didn't find one, add it */
  12689. + if (!found){
  12690. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12691. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12692. +
  12693. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12694. + vec->pkgs[vec->len] = pkg;
  12695. + vec->len++;
  12696. + return pkg;
  12697. + }
  12698. + /* update the one that we have */
  12699. + else {
  12700. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12701. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12702. + if (set_status) {
  12703. + /* this is from the status file, so need to merge with existing database */
  12704. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12705. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12706. + /* XXX: CLEANUP: It's not so polite to free something here
  12707. + that was passed in from above. */
  12708. + pkg_deinit(pkg);
  12709. + free(pkg);
  12710. + } else {
  12711. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12712. + /* just overwrite the old one */
  12713. + pkg_deinit(vec->pkgs[i]);
  12714. + free(vec->pkgs[i]);
  12715. + vec->pkgs[i] = pkg;
  12716. + }
  12717. + return vec->pkgs[i];
  12718. + }
  12719. +}
  12720. +
  12721. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12722. +{
  12723. + int i;
  12724. + int found = 0;
  12725. +
  12726. + /* look for a duplicate pkg by name, version, and architecture */
  12727. + for (i = 0; i < vec->len; i++)
  12728. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12729. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12730. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12731. + found = 1;
  12732. + break;
  12733. + }
  12734. +
  12735. + /* we didn't find one, add it */
  12736. + if(!found){
  12737. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12738. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12739. + vec->len++;
  12740. + }
  12741. +}
  12742. +
  12743. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12744. +{
  12745. + int i;
  12746. + for (i = 0; i < vec->len; i++)
  12747. + if (vec->pkgs[i] == apkg)
  12748. + return 1;
  12749. + return 0;
  12750. +}
  12751. +
  12752. +typedef int (*compare_fcn_t)(const void *, const void *);
  12753. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12754. +{
  12755. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12756. +}
  12757. +
  12758. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12759. +{
  12760. + int npkgs = vec->len;
  12761. + int i;
  12762. + for (i = 0; i < npkgs; i++) {
  12763. + pkg_t *pkg = vec->pkgs[i];
  12764. + pkg->state_flag &= ~SF_MARKED;
  12765. + }
  12766. + return 0;
  12767. +}
  12768. +
  12769. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12770. +{
  12771. + int matching_count = 0;
  12772. + pkg_t **pkgs = vec->pkgs;
  12773. + int npkgs = vec->len;
  12774. + int i;
  12775. + for (i = 0; i < npkgs; i++) {
  12776. + pkg_t *pkg = pkgs[i];
  12777. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12778. + pkg->state_flag |= SF_MARKED;
  12779. + matching_count++;
  12780. + }
  12781. + }
  12782. + return matching_count;
  12783. +}
  12784. +
  12785. +
  12786. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12787. +{
  12788. + abstract_pkg_vec_t * vec ;
  12789. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12790. + if (!vec) {
  12791. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12792. + return NULL;
  12793. + }
  12794. + vec->pkgs = NULL;
  12795. + vec->len = 0;
  12796. +
  12797. + return vec;
  12798. +}
  12799. +
  12800. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12801. +{
  12802. + free(vec->pkgs);
  12803. + free(vec);
  12804. +}
  12805. +
  12806. +/*
  12807. + * assumption: all names in a vector are unique
  12808. + */
  12809. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12810. +{
  12811. + int i;
  12812. +
  12813. + /* look for a duplicate pkg by name */
  12814. + for(i = 0; i < vec->len; i++)
  12815. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12816. + break;
  12817. +
  12818. + /* we didn't find one, add it */
  12819. + if(i == vec->len){
  12820. + vec->pkgs =
  12821. + (abstract_pkg_t **)
  12822. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12823. + vec->pkgs[vec->len] = pkg;
  12824. + vec->len++;
  12825. + }
  12826. +}
  12827. +
  12828. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12829. +{
  12830. + if (vec->len > i)
  12831. + return vec->pkgs[i];
  12832. + else
  12833. + return NULL;
  12834. +}
  12835. +
  12836. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12837. +{
  12838. + int i;
  12839. + for (i = 0; i < vec->len; i++)
  12840. + if (vec->pkgs[i] == apkg)
  12841. + return 1;
  12842. + return 0;
  12843. +}
  12844. +
  12845. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12846. +{
  12847. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12848. +}
  12849. +
  12850. diff -Nur busybox-1.26.0.orig/archival/libipkg/pkg_vec.h busybox-1.26.0/archival/libipkg/pkg_vec.h
  12851. --- busybox-1.26.0.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12852. +++ busybox-1.26.0/archival/libipkg/pkg_vec.h 2016-12-22 17:08:31.024866515 +0100
  12853. @@ -0,0 +1,62 @@
  12854. +/* pkg_vec.h - the itsy package management system
  12855. +
  12856. + Steven M. Ayer
  12857. +
  12858. + Copyright (C) 2002 Compaq Computer Corporation
  12859. +
  12860. + This program is free software; you can redistribute it and/or
  12861. + modify it under the terms of the GNU General Public License as
  12862. + published by the Free Software Foundation; either version 2, or (at
  12863. + your option) any later version.
  12864. +
  12865. + This program is distributed in the hope that it will be useful, but
  12866. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12867. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12868. + General Public License for more details.
  12869. +*/
  12870. +
  12871. +#ifndef PKG_VEC_H
  12872. +#define PKG_VEC_H
  12873. +
  12874. +typedef struct pkg pkg_t;
  12875. +typedef struct abstract_pkg abstract_pkg_t;
  12876. +
  12877. +struct pkg_vec
  12878. +{
  12879. + pkg_t **pkgs;
  12880. + int len;
  12881. +};
  12882. +typedef struct pkg_vec pkg_vec_t;
  12883. +
  12884. +struct abstract_pkg_vec
  12885. +{
  12886. + abstract_pkg_t **pkgs;
  12887. + int len;
  12888. +};
  12889. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12890. +
  12891. +
  12892. +pkg_vec_t * pkg_vec_alloc(void);
  12893. +void pkg_vec_free(pkg_vec_t *vec);
  12894. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12895. +
  12896. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12897. +/* pkg_vec_insert_merge: might munge pkg.
  12898. +* returns the pkg that is in the pkg graph */
  12899. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12900. +/* this one never munges pkg */
  12901. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12902. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12903. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12904. +
  12905. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12906. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12907. +
  12908. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12909. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12910. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12911. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12912. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12913. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12914. +#endif
  12915. +
  12916. diff -Nur busybox-1.26.0.orig/archival/libipkg/sprintf_alloc.h busybox-1.26.0/archival/libipkg/sprintf_alloc.h
  12917. --- busybox-1.26.0.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12918. +++ busybox-1.26.0/archival/libipkg/sprintf_alloc.h 2016-12-22 17:08:31.024866515 +0100
  12919. @@ -0,0 +1,25 @@
  12920. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12921. +
  12922. + Carl D. Worth
  12923. +
  12924. + Copyright (C) 2001 University of Southern California
  12925. +
  12926. + This program is free software; you can redistribute it and/or modify
  12927. + it under the terms of the GNU General Public License as published by
  12928. + the Free Software Foundation; either version 2, or (at your option)
  12929. + any later version.
  12930. +
  12931. + This program is distributed in the hope that it will be useful,
  12932. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12933. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12934. + GNU General Public License for more details.
  12935. +*/
  12936. +
  12937. +#ifndef SPRINTF_ALLOC_H
  12938. +#define SPRINTF_ALLOC_H
  12939. +
  12940. +#include "libbb.h"
  12941. +
  12942. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12943. +
  12944. +#endif
  12945. diff -Nur busybox-1.26.0.orig/archival/libipkg/str_list.c busybox-1.26.0/archival/libipkg/str_list.c
  12946. --- busybox-1.26.0.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12947. +++ busybox-1.26.0/archival/libipkg/str_list.c 2016-12-22 17:08:31.024866515 +0100
  12948. @@ -0,0 +1,76 @@
  12949. +/* str_list.c - the itsy package management system
  12950. +
  12951. + Carl D. Worth
  12952. +
  12953. + Copyright (C) 2001 University of Southern California
  12954. +
  12955. + This program is free software; you can redistribute it and/or
  12956. + modify it under the terms of the GNU General Public License as
  12957. + published by the Free Software Foundation; either version 2, or (at
  12958. + your option) any later version.
  12959. +
  12960. + This program is distributed in the hope that it will be useful, but
  12961. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12962. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12963. + General Public License for more details.
  12964. +*/
  12965. +
  12966. +#include "ipkg.h"
  12967. +
  12968. +#include "str_list.h"
  12969. +
  12970. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12971. +{
  12972. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12973. +}
  12974. +
  12975. +void str_list_elt_deinit(str_list_elt_t *elt)
  12976. +{
  12977. + void_list_elt_deinit((void_list_elt_t *) elt);
  12978. +}
  12979. +
  12980. +str_list_t *str_list_alloc(void)
  12981. +{
  12982. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12983. + if (list)
  12984. + str_list_init(list);
  12985. + return list;
  12986. +}
  12987. +
  12988. +int str_list_init(str_list_t *list)
  12989. +{
  12990. + return void_list_init((void_list_t *) list);
  12991. +}
  12992. +
  12993. +void str_list_deinit(str_list_t *list)
  12994. +{
  12995. + void_list_deinit((void_list_t *) list);
  12996. +}
  12997. +
  12998. +int str_list_append(str_list_t *list, char *data)
  12999. +{
  13000. + return void_list_append((void_list_t *) list, data);
  13001. +}
  13002. +
  13003. +int str_list_push(str_list_t *list, char *data)
  13004. +{
  13005. + return void_list_push((void_list_t *) list, data);
  13006. +}
  13007. +
  13008. +str_list_elt_t *str_list_pop(str_list_t *list)
  13009. +{
  13010. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13011. +}
  13012. +
  13013. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13014. +{
  13015. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13016. + (void_list_elt_t **) iter);
  13017. +}
  13018. +
  13019. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13020. +{
  13021. + return (char *)void_list_remove_elt((void_list_t *) list,
  13022. + (void *)target_str,
  13023. + (void_list_cmp_t)strcmp);
  13024. +}
  13025. diff -Nur busybox-1.26.0.orig/archival/libipkg/str_list.h busybox-1.26.0/archival/libipkg/str_list.h
  13026. --- busybox-1.26.0.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13027. +++ busybox-1.26.0/archival/libipkg/str_list.h 2016-12-22 17:08:31.024866515 +0100
  13028. @@ -0,0 +1,51 @@
  13029. +/* str_list.h - the itsy package management system
  13030. +
  13031. + Carl D. Worth
  13032. +
  13033. + Copyright (C) 2001 University of Southern California
  13034. +
  13035. + This program is free software; you can redistribute it and/or
  13036. + modify it under the terms of the GNU General Public License as
  13037. + published by the Free Software Foundation; either version 2, or (at
  13038. + your option) any later version.
  13039. +
  13040. + This program is distributed in the hope that it will be useful, but
  13041. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13042. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13043. + General Public License for more details.
  13044. +*/
  13045. +
  13046. +#ifndef STR_LIST_H
  13047. +#define STR_LIST_H
  13048. +
  13049. +#include "void_list.h"
  13050. +
  13051. +typedef struct str_list_elt str_list_elt_t;
  13052. +struct str_list_elt
  13053. +{
  13054. + str_list_elt_t *next;
  13055. + char *data;
  13056. +};
  13057. +
  13058. +typedef struct xstr_list str_list_t;
  13059. +struct xstr_list
  13060. +{
  13061. + str_list_elt_t pre_head;
  13062. + str_list_elt_t *head;
  13063. + str_list_elt_t *tail;
  13064. +};
  13065. +
  13066. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13067. +void str_list_elt_deinit(str_list_elt_t *elt);
  13068. +
  13069. +str_list_t *str_list_alloc(void);
  13070. +int str_list_init(str_list_t *list);
  13071. +void str_list_deinit(str_list_t *list);
  13072. +
  13073. +int str_list_append(str_list_t *list, char *data);
  13074. +int str_list_push(str_list_t *list, char *data);
  13075. +str_list_elt_t *str_list_pop(str_list_t *list);
  13076. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13077. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13078. +
  13079. +#endif
  13080. diff -Nur busybox-1.26.0.orig/archival/libipkg/str_util.c busybox-1.26.0/archival/libipkg/str_util.c
  13081. --- busybox-1.26.0.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13082. +++ busybox-1.26.0/archival/libipkg/str_util.c 2016-12-22 17:08:31.024866515 +0100
  13083. @@ -0,0 +1,69 @@
  13084. +/* str_utils.c - the itsy package management system
  13085. +
  13086. + Carl D. Worth
  13087. +
  13088. + Copyright (C) 2001 University of Southern California
  13089. +
  13090. + This program is free software; you can redistribute it and/or
  13091. + modify it under the terms of the GNU General Public License as
  13092. + published by the Free Software Foundation; either version 2, or (at
  13093. + your option) any later version.
  13094. +
  13095. + This program is distributed in the hope that it will be useful, but
  13096. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13097. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13098. + General Public License for more details.
  13099. +*/
  13100. +
  13101. +#include "ipkg.h"
  13102. +
  13103. +int str_starts_with(const char *str, const char *prefix);
  13104. +int str_ends_with(const char *str, const char *suffix);
  13105. +int str_chomp(char *str);
  13106. +int str_toupper(char *str);
  13107. +char *str_dup_safe(const char *str);
  13108. +
  13109. +int str_starts_with(const char *str, const char *prefix)
  13110. +{
  13111. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13112. +}
  13113. +
  13114. +int str_ends_with(const char *str, const char *suffix)
  13115. +{
  13116. + int suffix_len;
  13117. + int str_len;
  13118. +
  13119. + str_len = strlen(str);
  13120. + suffix_len = strlen(suffix);
  13121. +
  13122. + if (str_len < suffix_len) {
  13123. + return 0;
  13124. + }
  13125. +
  13126. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13127. +}
  13128. +
  13129. +int str_chomp(char *str)
  13130. +{
  13131. + if (str[strlen(str) - 1] == '\n') {
  13132. + str[strlen(str) - 1] = '\0';
  13133. + return 1;
  13134. + }
  13135. + return 0;
  13136. +}
  13137. +
  13138. +int str_toupper(char *str)
  13139. +{
  13140. + while (*str) {
  13141. + *str = toupper(*str);
  13142. + str++;
  13143. + }
  13144. +
  13145. + return 0;
  13146. +}
  13147. +
  13148. +char *str_dup_safe(const char *str)
  13149. +{
  13150. + return str ? strdup(str) : NULL;
  13151. +}
  13152. +
  13153. diff -Nur busybox-1.26.0.orig/archival/libipkg/str_util.h busybox-1.26.0/archival/libipkg/str_util.h
  13154. --- busybox-1.26.0.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13155. +++ busybox-1.26.0/archival/libipkg/str_util.h 2016-12-22 17:08:31.024866515 +0100
  13156. @@ -0,0 +1,27 @@
  13157. +/* str_utils.h - the itsy package management system
  13158. +
  13159. + Carl D. Worth
  13160. +
  13161. + Copyright (C) 2001 University of Southern California
  13162. +
  13163. + This program is free software; you can redistribute it and/or
  13164. + modify it under the terms of the GNU General Public License as
  13165. + published by the Free Software Foundation; either version 2, or (at
  13166. + your option) any later version.
  13167. +
  13168. + This program is distributed in the hope that it will be useful, but
  13169. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13170. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13171. + General Public License for more details.
  13172. +*/
  13173. +
  13174. +#ifndef STR_UTILS_H
  13175. +#define STR_UTILS_H
  13176. +
  13177. +int str_starts_with(const char *str, const char *prefix);
  13178. +int str_ends_with(const char *str, const char *suffix);
  13179. +int str_chomp(char *str);
  13180. +int str_toupper(char *str);
  13181. +char *str_dup_safe(const char *str);
  13182. +
  13183. +#endif
  13184. diff -Nur busybox-1.26.0.orig/archival/libipkg/user.c busybox-1.26.0/archival/libipkg/user.c
  13185. --- busybox-1.26.0.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13186. +++ busybox-1.26.0/archival/libipkg/user.c 2016-12-22 17:08:31.024866515 +0100
  13187. @@ -0,0 +1,49 @@
  13188. +/* user.c - the itsy package management system
  13189. +
  13190. + Jamey Hicks
  13191. +
  13192. + Copyright (C) 2002 Hewlett Packard Company
  13193. + Copyright (C) 2001 University of Southern California
  13194. +
  13195. + This program is free software; you can redistribute it and/or
  13196. + modify it under the terms of the GNU General Public License as
  13197. + published by the Free Software Foundation; either version 2, or (at
  13198. + your option) any later version.
  13199. +
  13200. + This program is distributed in the hope that it will be useful, but
  13201. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13202. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13203. + General Public License for more details.
  13204. +*/
  13205. +
  13206. +#include <stdio.h>
  13207. +#include <stdarg.h>
  13208. +#include "libbb.h"
  13209. +#include "file_util.h"
  13210. +#include "str_util.h"
  13211. +#include "libipkg.h"
  13212. +
  13213. +char *get_user_response(const char *format, ...);
  13214. +static char *question = NULL;
  13215. +static int question_len = 255;
  13216. +
  13217. +char *get_user_response(const char *format, ...)
  13218. +{
  13219. + int len = question_len;
  13220. + va_list ap;
  13221. + char *response;
  13222. + va_start(ap, format);
  13223. +
  13224. + do {
  13225. + if (question == NULL || len > question_len) {
  13226. + question = realloc(question, len + 1);
  13227. + question_len = len;
  13228. + }
  13229. + len = vsnprintf(question,question_len,format,ap);
  13230. + } while (len > question_len);
  13231. + response = strdup(ipkg_cb_response(question));
  13232. + str_chomp(response);
  13233. + str_tolower(response);
  13234. +
  13235. + return response;
  13236. +}
  13237. diff -Nur busybox-1.26.0.orig/archival/libipkg/user.h busybox-1.26.0/archival/libipkg/user.h
  13238. --- busybox-1.26.0.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13239. +++ busybox-1.26.0/archival/libipkg/user.h 2016-12-22 17:08:31.024866515 +0100
  13240. @@ -0,0 +1,23 @@
  13241. +/* user.c - the itsy package management system
  13242. +
  13243. + Jamey Hicks
  13244. +
  13245. + Copyright (C) 2002 Hewlett Packard Company
  13246. + Copyright (C) 2001 University of Southern California
  13247. +
  13248. + This program is free software; you can redistribute it and/or
  13249. + modify it under the terms of the GNU General Public License as
  13250. + published by the Free Software Foundation; either version 2, or (at
  13251. + your option) any later version.
  13252. +
  13253. + This program is distributed in the hope that it will be useful, but
  13254. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13255. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13256. + General Public License for more details.
  13257. +*/
  13258. +
  13259. +#include <stdio.h>
  13260. +#include <stdarg.h>
  13261. +
  13262. +char *get_user_response(const char *format, ...);
  13263. +
  13264. diff -Nur busybox-1.26.0.orig/archival/libipkg/void_list.c busybox-1.26.0/archival/libipkg/void_list.c
  13265. --- busybox-1.26.0.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13266. +++ busybox-1.26.0/archival/libipkg/void_list.c 2016-12-22 17:08:31.024866515 +0100
  13267. @@ -0,0 +1,194 @@
  13268. +/* void_list.c - the itsy package management system
  13269. +
  13270. + Carl D. Worth
  13271. +
  13272. + Copyright (C) 2001 University of Southern California
  13273. +
  13274. + This program is free software; you can redistribute it and/or
  13275. + modify it under the terms of the GNU General Public License as
  13276. + published by the Free Software Foundation; either version 2, or (at
  13277. + your option) any later version.
  13278. +
  13279. + This program is distributed in the hope that it will be useful, but
  13280. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13282. + General Public License for more details.
  13283. +*/
  13284. +
  13285. +#include "ipkg.h"
  13286. +#include <errno.h>
  13287. +
  13288. +#include "void_list.h"
  13289. +
  13290. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13291. +{
  13292. + elt->next = NULL;
  13293. + elt->data = data;
  13294. +
  13295. + return 0;
  13296. +}
  13297. +
  13298. +void void_list_elt_deinit(void_list_elt_t *elt)
  13299. +{
  13300. + void_list_elt_init(elt, NULL);
  13301. +}
  13302. +
  13303. +int void_list_init(void_list_t *list)
  13304. +{
  13305. + void_list_elt_init(&list->pre_head, NULL);
  13306. + list->head = NULL;
  13307. + list->pre_head.next = list->head;
  13308. + list->tail = NULL;
  13309. +
  13310. + return 0;
  13311. +}
  13312. +
  13313. +void void_list_deinit(void_list_t *list)
  13314. +{
  13315. + void_list_elt_t *elt;
  13316. +
  13317. + while (list->head) {
  13318. + elt = void_list_pop(list);
  13319. + void_list_elt_deinit(elt);
  13320. + /* malloced in void_list_append */
  13321. + free(elt);
  13322. + }
  13323. +}
  13324. +
  13325. +int void_list_append(void_list_t *list, void *data)
  13326. +{
  13327. + void_list_elt_t *elt;
  13328. +
  13329. + /* freed in void_list_deinit */
  13330. + elt = malloc(sizeof(void_list_elt_t));
  13331. + if (elt == NULL) {
  13332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13333. + return ENOMEM;
  13334. + }
  13335. +
  13336. + void_list_elt_init(elt, data);
  13337. +
  13338. + if (list->tail) {
  13339. + list->tail->next = elt;
  13340. + list->tail = elt;
  13341. + } else {
  13342. + list->head = elt;
  13343. + list->pre_head.next = list->head;
  13344. + list->tail = elt;
  13345. + }
  13346. +
  13347. + return 0;
  13348. +}
  13349. +
  13350. +int void_list_push(void_list_t *list, void *data)
  13351. +{
  13352. + void_list_elt_t *elt;
  13353. +
  13354. + elt = malloc(sizeof(void_list_elt_t));
  13355. + if (elt == NULL) {
  13356. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13357. + return ENOMEM;
  13358. + }
  13359. +
  13360. + void_list_elt_init(elt, data);
  13361. +
  13362. + elt->next = list->head;
  13363. + list->head->next = elt;
  13364. + if (list->tail == NULL) {
  13365. + list->tail = list->head;
  13366. + }
  13367. +
  13368. + return 0;
  13369. +}
  13370. +
  13371. +void_list_elt_t *void_list_pop(void_list_t *list)
  13372. +{
  13373. + void_list_elt_t *elt;
  13374. +
  13375. + elt = list->head;
  13376. +
  13377. + if (list->head) {
  13378. + list->head = list->head->next;
  13379. + list->pre_head.next = list->head;
  13380. + if (list->head == NULL) {
  13381. + list->tail = NULL;
  13382. + }
  13383. + }
  13384. +
  13385. + return elt;
  13386. +}
  13387. +
  13388. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13389. +{
  13390. + void_list_elt_t *prior;
  13391. + void_list_elt_t *old_elt;
  13392. + void *old_data;
  13393. +
  13394. + old_elt = *iter;
  13395. + old_data = old_elt->data;
  13396. +
  13397. + if (old_elt == list->head) {
  13398. + prior = &list->pre_head;
  13399. + void_list_pop(list);
  13400. + } else {
  13401. + for (prior = list->head; prior; prior = prior->next) {
  13402. + if (prior->next == old_elt) {
  13403. + break;
  13404. + }
  13405. + }
  13406. + if (prior == NULL || prior->next != old_elt) {
  13407. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13408. + return NULL;
  13409. + }
  13410. + prior->next = old_elt->next;
  13411. +
  13412. + if (old_elt == list->tail) {
  13413. + list->tail = prior;
  13414. + }
  13415. + }
  13416. +
  13417. + void_list_elt_deinit(old_elt);
  13418. + *iter = prior;
  13419. +
  13420. + return old_data;
  13421. +}
  13422. +
  13423. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13424. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13425. +{
  13426. + void_list_elt_t *prior;
  13427. + void_list_elt_t *old_elt = NULL;
  13428. + void *old_data = NULL;
  13429. +
  13430. + /* first element */
  13431. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13432. + old_elt = list->head;
  13433. + old_data = list->head->data;
  13434. + void_list_pop(list);
  13435. + } else {
  13436. + int found = 0;
  13437. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13438. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13439. + old_elt = prior->next;
  13440. + old_data = old_elt->data;
  13441. + found = 1;
  13442. + break;
  13443. + }
  13444. + }
  13445. + if (!found) {
  13446. + return NULL;
  13447. + }
  13448. + prior->next = old_elt->next;
  13449. +
  13450. + if (old_elt == list->tail) {
  13451. + list->tail = prior;
  13452. + }
  13453. + }
  13454. + if (old_elt)
  13455. + void_list_elt_deinit(old_elt);
  13456. +
  13457. + if (old_data)
  13458. + return old_data;
  13459. + else
  13460. + return NULL;
  13461. +}
  13462. diff -Nur busybox-1.26.0.orig/archival/libipkg/void_list.h busybox-1.26.0/archival/libipkg/void_list.h
  13463. --- busybox-1.26.0.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13464. +++ busybox-1.26.0/archival/libipkg/void_list.h 2016-12-22 17:08:31.028868767 +0100
  13465. @@ -0,0 +1,59 @@
  13466. +/* void_list.h - the itsy package management system
  13467. +
  13468. + Carl D. Worth
  13469. +
  13470. + Copyright (C) 2001 University of Southern California
  13471. +
  13472. + This program is free software; you can redistribute it and/or
  13473. + modify it under the terms of the GNU General Public License as
  13474. + published by the Free Software Foundation; either version 2, or (at
  13475. + your option) any later version.
  13476. +
  13477. + This program is distributed in the hope that it will be useful, but
  13478. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13479. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13480. + General Public License for more details.
  13481. +*/
  13482. +
  13483. +#ifndef VOID_LIST_H
  13484. +#define VOID_LIST_H
  13485. +
  13486. +typedef struct void_list_elt void_list_elt_t;
  13487. +struct void_list_elt
  13488. +{
  13489. + void_list_elt_t *next;
  13490. + void *data;
  13491. +};
  13492. +
  13493. +typedef struct void_list void_list_t;
  13494. +struct void_list
  13495. +{
  13496. + void_list_elt_t pre_head;
  13497. + void_list_elt_t *head;
  13498. + void_list_elt_t *tail;
  13499. +};
  13500. +
  13501. +static inline int void_list_empty(void_list_t *list)
  13502. +{
  13503. + if (list->head == NULL)
  13504. + return 1;
  13505. + else
  13506. + return 0;
  13507. +}
  13508. +
  13509. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13510. +void void_list_elt_deinit(void_list_elt_t *elt);
  13511. +
  13512. +int void_list_init(void_list_t *list);
  13513. +void void_list_deinit(void_list_t *list);
  13514. +
  13515. +int void_list_append(void_list_t *list, void *data);
  13516. +int void_list_push(void_list_t *list, void *data);
  13517. +void_list_elt_t *void_list_pop(void_list_t *list);
  13518. +
  13519. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13520. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13521. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13522. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13523. +
  13524. +#endif
  13525. diff -Nur busybox-1.26.0.orig/archival/libipkg/xsystem.c busybox-1.26.0/archival/libipkg/xsystem.c
  13526. --- busybox-1.26.0.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13527. +++ busybox-1.26.0/archival/libipkg/xsystem.c 2016-12-22 17:08:31.028868767 +0100
  13528. @@ -0,0 +1,64 @@
  13529. +/* xsystem.c - system(3) with error messages
  13530. +
  13531. + Carl D. Worth
  13532. +
  13533. + Copyright (C) 2001 University of Southern California
  13534. +
  13535. + This program is free software; you can redistribute it and/or
  13536. + modify it under the terms of the GNU General Public License as
  13537. + published by the Free Software Foundation; either version 2, or (at
  13538. + your option) any later version.
  13539. +
  13540. + This program is distributed in the hope that it will be useful, but
  13541. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13542. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13543. + General Public License for more details.
  13544. +*/
  13545. +
  13546. +#include "ipkg.h"
  13547. +#include <sys/wait.h>
  13548. +
  13549. +#include "xsystem.h"
  13550. +
  13551. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13552. + really need the /bin/sh invocation which takes resources and
  13553. + introduces security problems. I should switch all of this to a sort
  13554. + of execl() or execv() interface/implementation.
  13555. +*/
  13556. +
  13557. +/* Like system(3), but with error messages printed if the fork fails
  13558. + or if the child process dies due to an uncaught signal. Also, the
  13559. + return value is a bit simpler:
  13560. +
  13561. + -1 if there was any problem
  13562. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13563. + as defined in <sys/wait.h>.
  13564. +*/
  13565. +int xsystem(const char *cmd)
  13566. +{
  13567. + int err;
  13568. +
  13569. + err = system(cmd);
  13570. +
  13571. + if (err == -1) {
  13572. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13573. + __FUNCTION__, cmd);
  13574. + return -1;
  13575. + }
  13576. +
  13577. + if (WIFSIGNALED(err)) {
  13578. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13579. + __FUNCTION__, WTERMSIG(err), cmd);
  13580. + return -1;
  13581. + }
  13582. +
  13583. + if (WIFEXITED(err)) {
  13584. + /* Normal child exit */
  13585. + return WEXITSTATUS(err);
  13586. + }
  13587. +
  13588. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13589. + __FUNCTION__, err);
  13590. + return -1;
  13591. +}
  13592. +
  13593. diff -Nur busybox-1.26.0.orig/archival/libipkg/xsystem.h busybox-1.26.0/archival/libipkg/xsystem.h
  13594. --- busybox-1.26.0.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13595. +++ busybox-1.26.0/archival/libipkg/xsystem.h 2016-12-22 17:08:31.028868767 +0100
  13596. @@ -0,0 +1,34 @@
  13597. +/* xsystem.h - system(3) with error messages
  13598. +
  13599. + Carl D. Worth
  13600. +
  13601. + Copyright (C) 2001 University of Southern California
  13602. +
  13603. + This program is free software; you can redistribute it and/or
  13604. + modify it under the terms of the GNU General Public License as
  13605. + published by the Free Software Foundation; either version 2, or (at
  13606. + your option) any later version.
  13607. +
  13608. + This program is distributed in the hope that it will be useful, but
  13609. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13610. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13611. + General Public License for more details.
  13612. +*/
  13613. +
  13614. +#ifndef XSYSTEM_H
  13615. +#define XSYSTEM_H
  13616. +
  13617. +#include <stdlib.h>
  13618. +
  13619. +/* Like system(3), but with error messages printed if the fork fails
  13620. + or if the child process dies due to an uncaught signal. Also, the
  13621. + return value is a bit simpler:
  13622. +
  13623. + -1 if there was any problem
  13624. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13625. + as defined in <sys/wait.h>.
  13626. +*/
  13627. +int xsystem(const char *cmd);
  13628. +
  13629. +#endif
  13630. +
  13631. diff -Nur busybox-1.26.0.orig/include/bb_archive.h busybox-1.26.0/include/bb_archive.h
  13632. --- busybox-1.26.0.orig/include/bb_archive.h 2016-06-20 21:46:04.000000000 +0200
  13633. +++ busybox-1.26.0/include/bb_archive.h 2016-12-22 17:08:31.028868767 +0100
  13634. @@ -102,7 +102,7 @@
  13635. struct hardlinks_t *cpio__hardlinks_to_create;
  13636. struct hardlinks_t *cpio__created_hardlinks;
  13637. #endif
  13638. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13639. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13640. /* Temporary storage */
  13641. char *dpkg__buffer;
  13642. /* How to process any sub archive, e.g. get_header_tar_gz */
  13643. diff -Nur busybox-1.26.0.orig/include/usage.src.h busybox-1.26.0/include/usage.src.h
  13644. --- busybox-1.26.0.orig/include/usage.src.h 2015-07-13 04:18:47.000000000 +0200
  13645. +++ busybox-1.26.0/include/usage.src.h 2016-12-22 17:08:31.028868767 +0100
  13646. @@ -19,4 +19,80 @@
  13647. #define busybox_notes_usage \
  13648. "Hello world!\n"
  13649. +#define ipkg_trivial_usage \
  13650. + "[options]... sub-command [arguments]..."
  13651. +#define ipkg_full_usage \
  13652. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13653. + "\n" \
  13654. + "Sub-commands:\n" \
  13655. + "\nPackage Manipulation:\n" \
  13656. + "\tupdate Update list of available packages\n" \
  13657. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13658. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13659. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13660. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13661. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13662. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13663. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13664. + "\n" \
  13665. + "Informational Commands:\n" \
  13666. + "\tlist List available packages and descriptions\n" \
  13667. + "\tlist_installed List all and only the installed packages and description \n" \
  13668. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13669. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13670. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13671. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13672. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13673. + "\tcompare_versions <v1> <op> <v2>\n" \
  13674. + "\t compare versions using <= < > >= = << >>\n" \
  13675. + "\tprint_architecture prints the architecture.\n" \
  13676. + "\tprint_installation_architecture\n" \
  13677. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13678. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13679. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13680. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13681. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13682. + "\t prints the installation architecture.\n" \
  13683. + "\n" \
  13684. + "\nOptions:\n" \
  13685. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13686. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13687. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13688. + "\t 0 errors only\n" \
  13689. + "\t 1 normal messages (default)\n" \
  13690. + "\t 2 informative messages\n" \
  13691. + "\t 3 debug output\n" \
  13692. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13693. + "\t-conf <conf_file> Default configuration file location\n" \
  13694. + " is /etc/ipkg.conf\n" \
  13695. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13696. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13697. + " <dest_name> should be a defined dest name from\n" \
  13698. + " the configuration file, (but can also be a\n" \
  13699. + " directory name in a pinch).\n" \
  13700. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13701. + "\t-offline <offline_root> offline installation of packages.\n" \
  13702. + "\t-verbose_wget more wget messages\n" \
  13703. + "\n" \
  13704. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13705. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13706. + "\t Install/remove package in spite of failed dependences\n" \
  13707. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13708. + " (no prompts). Note that this will not prevent\n" \
  13709. + " package installation scripts from prompting.\n" \
  13710. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13711. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13712. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13713. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13714. + "\t-noaction No action -- test only\n" \
  13715. + "\t-nodeps Do not follow dependences\n" \
  13716. + "\t-force-removal-of-dependent-packages\n" \
  13717. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13718. + "\t-test No action -- test only\n" \
  13719. + "\t-t Specify tmp-dir.\n" \
  13720. + "\t--tmp-dir Specify tmp-dir.\n" \
  13721. + "\n" \
  13722. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13723. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13724. +
  13725. #endif
  13726. diff -Nur busybox-1.26.0.orig/Makefile busybox-1.26.0/Makefile
  13727. --- busybox-1.26.0.orig/Makefile 2016-12-20 02:21:42.000000000 +0100
  13728. +++ busybox-1.26.0/Makefile 2016-12-22 17:08:31.028868767 +0100
  13729. @@ -466,6 +466,7 @@
  13730. libs-y := \
  13731. archival/ \
  13732. archival/libarchive/ \
  13733. + archival/libipkg/ \
  13734. console-tools/ \
  13735. coreutils/ \
  13736. coreutils/libcoreutils/ \