001-ipkg.patch 448 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166
  1. diff -Nur busybox-1.23.0.orig/archival/ipkg.c busybox-1.23.0/archival/ipkg.c
  2. --- busybox-1.23.0.orig/archival/ipkg.c 1969-12-31 18:00:00.000000000 -0600
  3. +++ busybox-1.23.0/archival/ipkg.c 2015-01-09 11:18:22.424197243 -0600
  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.23.0.orig/archival/libarchive/Kbuild.src busybox-1.23.0/archival/libarchive/Kbuild.src
  45. --- busybox-1.23.0.orig/archival/libarchive/Kbuild.src 2014-10-04 15:35:57.000000000 -0500
  46. +++ busybox-1.23.0/archival/libarchive/Kbuild.src 2015-01-09 11:18:22.424197243 -0600
  47. @@ -25,14 +25,14 @@
  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. unpack_ar_archive.o \
  56. filter_accept_list_reassign.o \
  57. get_header_ar.o \
  58. - get_header_tar.o \
  59. - get_header_tar_gz.o \
  60. get_header_tar_bz2.o \
  61. get_header_tar_lzma.o \
  62. diff -Nur busybox-1.23.0.orig/archival/libipkg/args.c busybox-1.23.0/archival/libipkg/args.c
  63. --- busybox-1.23.0.orig/archival/libipkg/args.c 1969-12-31 18:00:00.000000000 -0600
  64. +++ busybox-1.23.0/archival/libipkg/args.c 2015-01-09 11:18:22.424197243 -0600
  65. @@ -0,0 +1,242 @@
  66. +/* args.c - parse command-line args
  67. +
  68. + Carl D. Worth
  69. +
  70. + Copyright 2001 University of Southern California
  71. +
  72. + This program is free software; you can redistribute it and/or modify
  73. + it under the terms of the GNU General Public License as published by
  74. + the Free Software Foundation; either version 2, or (at your option)
  75. + any later version.
  76. +
  77. + This program is distributed in the hope that it will be useful,
  78. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  79. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  80. + GNU General Public License for more details.
  81. + */
  82. +
  83. +#include <getopt.h>
  84. +#include <stdlib.h>
  85. +#include <string.h>
  86. +#include <unistd.h>
  87. +
  88. +#include "ipkg.h"
  89. +#include "ipkg_message.h"
  90. +
  91. +#include "args.h"
  92. +#include "sprintf_alloc.h"
  93. +
  94. +#include "libbb.h"
  95. +
  96. +
  97. +static void print_version(void);
  98. +
  99. +enum long_args_opt
  100. +{
  101. + ARGS_OPT_FORCE_DEFAULTS = 129,
  102. + ARGS_OPT_FORCE_DEPENDS,
  103. + ARGS_OPT_FORCE_OVERWRITE,
  104. + ARGS_OPT_FORCE_DOWNGRADE,
  105. + ARGS_OPT_FORCE_REINSTALL,
  106. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  107. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  108. + ARGS_OPT_FORCE_SPACE,
  109. + ARGS_OPT_NOACTION,
  110. + ARGS_OPT_NODEPS,
  111. + ARGS_OPT_VERBOSE_WGET,
  112. + ARGS_OPT_VERBOSITY,
  113. + ARGS_OPT_MULTIPLE_PROVIDERS
  114. +};
  115. +
  116. +int args_init(args_t *args)
  117. +{
  118. + const char *conf_file_dir;
  119. +
  120. + memset(args, 0, sizeof(args_t));
  121. +
  122. + args->dest = ARGS_DEFAULT_DEST;
  123. +
  124. + conf_file_dir = getenv("IPKG_CONF_DIR");
  125. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  126. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  127. + }
  128. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  129. + ARGS_DEFAULT_CONF_FILE_NAME);
  130. +
  131. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  132. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  133. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  134. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  135. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  136. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  137. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  138. + args->noaction = ARGS_DEFAULT_NOACTION;
  139. + args->nodeps = ARGS_DEFAULT_NODEPS;
  140. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  141. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  142. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  143. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  144. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  145. + args->multiple_providers = 0;
  146. + args->nocheckfordirorfile = 0;
  147. + args->noreadfeedsfile = 0;
  148. +
  149. + return 1;
  150. +}
  151. +
  152. +void args_deinit(args_t *args)
  153. +{
  154. + free(args->conf_file);
  155. + args->conf_file = NULL;
  156. +}
  157. +
  158. +int args_parse(args_t *args, int argc, char *argv[])
  159. +{
  160. + int c;
  161. + int option_index = 0;
  162. + int parse_err = 0;
  163. + static struct option long_options[] = {
  164. + {"query-all", 0, 0, 'A'},
  165. + {"conf-file", 1, 0, 'f'},
  166. + {"conf", 1, 0, 'f'},
  167. + {"dest", 1, 0, 'd'},
  168. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  169. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  170. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  171. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  172. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  173. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  174. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  175. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  176. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  177. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  178. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  179. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  180. + {"recursive", 0, 0,
  181. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  182. + {"force-removal-of-dependent-packages", 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-essential-packages", 0, 0,
  187. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  188. + {"force_removal_of_essential_packages", 0, 0,
  189. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  190. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  191. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  192. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  193. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  194. + {"offline", 1, 0, 'o'},
  195. + {"offline-root", 1, 0, 'o'},
  196. + {"test", 0, 0, ARGS_OPT_NOACTION},
  197. + {"tmp-dir", 1, 0, 't'},
  198. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  199. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  200. + {"verbosity", 2, 0, 'V'},
  201. + {"version", 0, 0, 'v'},
  202. + {0, 0, 0, 0}
  203. + };
  204. +
  205. + while (1) {
  206. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  207. + if (c == -1)
  208. + break;
  209. +
  210. + switch (c) {
  211. + case 'A':
  212. + args->query_all = 1;
  213. + break;
  214. + case 'd':
  215. + args->dest = optarg;
  216. + break;
  217. + case 'f':
  218. + free(args->conf_file);
  219. + args->conf_file = strdup(optarg);
  220. + break;
  221. + case 'o':
  222. + args->offline_root = optarg;
  223. + break;
  224. + case 'n':
  225. + args->noaction = 1;
  226. + break;
  227. + case 't':
  228. + args->tmp_dir = strdup(optarg);
  229. + break;
  230. + case 'v':
  231. + print_version();
  232. + exit(0);
  233. + case 'V':
  234. + case ARGS_OPT_VERBOSITY:
  235. + if (optarg)
  236. + args->verbosity = atoi(optarg);
  237. + else
  238. + args->verbosity += 1;
  239. + break;
  240. + case ARGS_OPT_FORCE_DEFAULTS:
  241. + args->force_defaults = 1;
  242. + break;
  243. + case ARGS_OPT_FORCE_DEPENDS:
  244. + args->force_depends = 1;
  245. + break;
  246. + case ARGS_OPT_FORCE_OVERWRITE:
  247. + args->force_overwrite = 1;
  248. + break;
  249. + case ARGS_OPT_FORCE_DOWNGRADE:
  250. + args->force_downgrade = 1;
  251. + break;
  252. + case ARGS_OPT_FORCE_REINSTALL:
  253. + args->force_reinstall = 1;
  254. + break;
  255. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  256. + args->force_removal_of_essential_packages = 1;
  257. + break;
  258. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  259. + args->force_removal_of_dependent_packages = 1;
  260. + break;
  261. + case ARGS_OPT_FORCE_SPACE:
  262. + args->force_space = 1;
  263. + break;
  264. + case ARGS_OPT_VERBOSE_WGET:
  265. + args->verbose_wget = 1;
  266. + break;
  267. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  268. + args->multiple_providers = 1;
  269. + break;
  270. + case ARGS_OPT_NODEPS:
  271. + args->nodeps = 1;
  272. + break;
  273. + case ARGS_OPT_NOACTION:
  274. + args->noaction = 1;
  275. + break;
  276. + case ':':
  277. + parse_err++;
  278. + break;
  279. + case '?':
  280. + parse_err++;
  281. + break;
  282. + default:
  283. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  284. + }
  285. + }
  286. +
  287. + if (parse_err) {
  288. + return -parse_err;
  289. + } else {
  290. + return optind;
  291. + }
  292. +}
  293. +
  294. +void args_usage(const char *complaint)
  295. +{
  296. + if (complaint) {
  297. + bb_error_msg("%s\n", complaint);
  298. + }
  299. + print_version();
  300. + bb_show_usage();
  301. + exit(1);
  302. +}
  303. +
  304. +static void print_version(void)
  305. +{
  306. + bb_error_msg("version %s\n", IPKG_VERSION);
  307. +}
  308. diff -Nur busybox-1.23.0.orig/archival/libipkg/args.h busybox-1.23.0/archival/libipkg/args.h
  309. --- busybox-1.23.0.orig/archival/libipkg/args.h 1969-12-31 18:00:00.000000000 -0600
  310. +++ busybox-1.23.0/archival/libipkg/args.h 2015-01-09 11:18:22.424197243 -0600
  311. @@ -0,0 +1,72 @@
  312. +/* args.h - parse command-line args
  313. +
  314. + Carl D. Worth
  315. +
  316. + Copyright 2001 University of Southern California
  317. +
  318. + This program is free software; you can redistribute it and/or modify
  319. + it under the terms of the GNU General Public License as published by
  320. + the Free Software Foundation; either version 2, or (at your option)
  321. + any later version.
  322. +
  323. + This program is distributed in the hope that it will be useful,
  324. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  325. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  326. + GNU General Public License for more details.
  327. +*/
  328. +
  329. +#ifndef ARGS_H
  330. +#define ARGS_H
  331. +
  332. +struct args
  333. +{
  334. + char *conf_file;
  335. + char *dest;
  336. + char *tmp_dir;
  337. + int force_defaults;
  338. + int force_depends;
  339. + int force_overwrite;
  340. + int force_downgrade;
  341. + int force_reinstall;
  342. + int force_removal_of_essential_packages;
  343. + int force_removal_of_dependent_packages;
  344. + int force_space;
  345. + int noaction;
  346. + int nodeps;
  347. + int multiple_providers;
  348. + int query_all;
  349. + int verbose_wget;
  350. + int verbosity;
  351. + int nocheckfordirorfile;
  352. + int noreadfeedsfile;
  353. + char *offline_root;
  354. + char *offline_root_pre_script_cmd;
  355. + char *offline_root_post_script_cmd;
  356. +};
  357. +typedef struct args args_t;
  358. +
  359. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  360. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  361. +#define ARGS_DEFAULT_DEST NULL
  362. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  363. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  364. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  365. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  366. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  367. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  368. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  369. +#define ARGS_DEFAULT_FORCE_SPACE 0
  370. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  371. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  372. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  373. +#define ARGS_DEFAULT_NOACTION 0
  374. +#define ARGS_DEFAULT_NODEPS 0
  375. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  376. +#define ARGS_DEFAULT_VERBOSITY 1
  377. +
  378. +int args_init(args_t *args);
  379. +void args_deinit(args_t *args);
  380. +int args_parse(args_t *args, int argc, char *argv[]);
  381. +void args_usage(const char *complaint);
  382. +
  383. +#endif
  384. diff -Nur busybox-1.23.0.orig/archival/libipkg/conffile.c busybox-1.23.0/archival/libipkg/conffile.c
  385. --- busybox-1.23.0.orig/archival/libipkg/conffile.c 1969-12-31 18:00:00.000000000 -0600
  386. +++ busybox-1.23.0/archival/libipkg/conffile.c 2015-01-09 11:18:22.424197243 -0600
  387. @@ -0,0 +1,65 @@
  388. +/* conffile.c - the itsy package management system
  389. +
  390. + Carl D. Worth
  391. +
  392. + Copyright (C) 2001 University of Southern California
  393. +
  394. + This program is free software; you can redistribute it and/or
  395. + modify it under the terms of the GNU General Public License as
  396. + published by the Free Software Foundation; either version 2, or (at
  397. + your option) any later version.
  398. +
  399. + This program is distributed in the hope that it will be useful, but
  400. + WITHOUT ANY WARRANTY; without even the implied warranty of
  401. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  402. + General Public License for more details.
  403. +*/
  404. +
  405. +#include <string.h>
  406. +#include <stdlib.h>
  407. +
  408. +#include "libbb.h"
  409. +#include "ipkg.h"
  410. +#include "ipkg_message.h"
  411. +
  412. +#include "conffile.h"
  413. +#include "file_util.h"
  414. +#include "sprintf_alloc.h"
  415. +
  416. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  417. +{
  418. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  419. +}
  420. +
  421. +void conffile_deinit(conffile_t *conffile)
  422. +{
  423. + nv_pair_deinit(conffile);
  424. +}
  425. +
  426. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  427. +{
  428. + uint8_t *md5sum;
  429. + char *filename = conffile->name;
  430. + char *root_filename;
  431. + int ret;
  432. +
  433. + if (conffile->value == NULL) {
  434. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  435. + return 1;
  436. + }
  437. +
  438. + root_filename = root_filename_alloc(conf, filename);
  439. +
  440. + md5sum = file_md5sum_alloc(root_filename);
  441. +
  442. + ret = strcmp((char *)md5sum, conffile->value);
  443. + if (ret) {
  444. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  445. + conffile->name, md5sum, conffile->value);
  446. + }
  447. +
  448. + free(root_filename);
  449. + free(md5sum);
  450. +
  451. + return ret;
  452. +}
  453. diff -Nur busybox-1.23.0.orig/archival/libipkg/conffile.h busybox-1.23.0/archival/libipkg/conffile.h
  454. --- busybox-1.23.0.orig/archival/libipkg/conffile.h 1969-12-31 18:00:00.000000000 -0600
  455. +++ busybox-1.23.0/archival/libipkg/conffile.h 2015-01-09 11:18:22.424197243 -0600
  456. @@ -0,0 +1,30 @@
  457. +/* conffile.h - the itsy package management system
  458. +
  459. + Carl D. Worth
  460. +
  461. + Copyright (C) 2001 University of Southern California
  462. +
  463. + This program is free software; you can redistribute it and/or
  464. + modify it under the terms of the GNU General Public License as
  465. + published by the Free Software Foundation; either version 2, or (at
  466. + your option) any later version.
  467. +
  468. + This program is distributed in the hope that it will be useful, but
  469. + WITHOUT ANY WARRANTY; without even the implied warranty of
  470. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  471. + General Public License for more details.
  472. +*/
  473. +
  474. +#ifndef CONFFILE_H
  475. +#define CONFFILE_H
  476. +
  477. +#include "nv_pair.h"
  478. +
  479. +typedef struct nv_pair conffile_t;
  480. +
  481. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  482. +void conffile_deinit(conffile_t *conffile);
  483. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  484. +
  485. +#endif
  486. +
  487. diff -Nur busybox-1.23.0.orig/archival/libipkg/conffile_list.c busybox-1.23.0/archival/libipkg/conffile_list.c
  488. --- busybox-1.23.0.orig/archival/libipkg/conffile_list.c 1969-12-31 18:00:00.000000000 -0600
  489. +++ busybox-1.23.0/archival/libipkg/conffile_list.c 2015-01-09 11:18:22.424197243 -0600
  490. @@ -0,0 +1,47 @@
  491. +/* conffile_list.c - the itsy package management system
  492. +
  493. + Carl D. Worth
  494. +
  495. + Copyright (C) 2001 University of Southern California
  496. +
  497. + This program is free software; you can redistribute it and/or
  498. + modify it under the terms of the GNU General Public License as
  499. + published by the Free Software Foundation; either version 2, or (at
  500. + your option) any later version.
  501. +
  502. + This program is distributed in the hope that it will be useful, but
  503. + WITHOUT ANY WARRANTY; without even the implied warranty of
  504. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  505. + General Public License for more details.
  506. +*/
  507. +
  508. +#include "ipkg.h"
  509. +
  510. +#include "conffile_list.h"
  511. +
  512. +int conffile_list_init(conffile_list_t *list)
  513. +{
  514. + return nv_pair_list_init(list);
  515. +}
  516. +
  517. +void conffile_list_deinit(conffile_list_t *list)
  518. +{
  519. + nv_pair_list_deinit(list);
  520. +}
  521. +
  522. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  523. + const char *md5sum)
  524. +{
  525. + return nv_pair_list_append(list, file_name, md5sum);
  526. +}
  527. +
  528. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  529. +{
  530. + return nv_pair_list_push(list, data);
  531. +}
  532. +
  533. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  534. +{
  535. + return nv_pair_list_pop(list);
  536. +}
  537. +
  538. diff -Nur busybox-1.23.0.orig/archival/libipkg/conffile_list.h busybox-1.23.0/archival/libipkg/conffile_list.h
  539. --- busybox-1.23.0.orig/archival/libipkg/conffile_list.h 1969-12-31 18:00:00.000000000 -0600
  540. +++ busybox-1.23.0/archival/libipkg/conffile_list.h 2015-01-09 11:18:22.424197243 -0600
  541. @@ -0,0 +1,36 @@
  542. +/* conffile_list.h - the itsy package management system
  543. +
  544. + Carl D. Worth
  545. +
  546. + Copyright (C) 2001 University of Southern California
  547. +
  548. + This program is free software; you can redistribute it and/or
  549. + modify it under the terms of the GNU General Public License as
  550. + published by the Free Software Foundation; either version 2, or (at
  551. + your option) any later version.
  552. +
  553. + This program is distributed in the hope that it will be useful, but
  554. + WITHOUT ANY WARRANTY; without even the implied warranty of
  555. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  556. + General Public License for more details.
  557. +*/
  558. +
  559. +#ifndef CONFFILE_LIST_H
  560. +#define CONFFILE_LIST_H
  561. +
  562. +#include "conffile.h"
  563. +#include "nv_pair_list.h"
  564. +
  565. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  566. +typedef struct nv_pair_list conffile_list_t;
  567. +
  568. +int conffile_list_init(conffile_list_t *list);
  569. +void conffile_list_deinit(conffile_list_t *list);
  570. +
  571. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  572. + const char *root_dir);
  573. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  574. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  575. +
  576. +#endif
  577. +
  578. diff -Nur busybox-1.23.0.orig/archival/libipkg/file_util.c busybox-1.23.0/archival/libipkg/file_util.c
  579. --- busybox-1.23.0.orig/archival/libipkg/file_util.c 1969-12-31 18:00:00.000000000 -0600
  580. +++ busybox-1.23.0/archival/libipkg/file_util.c 2015-01-09 11:18:22.424197243 -0600
  581. @@ -0,0 +1,186 @@
  582. +/* file_util.c - convenience routines for common stat operations
  583. +
  584. + Carl D. Worth
  585. +
  586. + Copyright (C) 2001 University of Southern California
  587. +
  588. + This program is free software; you can redistribute it and/or
  589. + modify it under the terms of the GNU General Public License as
  590. + published by the Free Software Foundation; either version 2, or (at
  591. + your option) any later version.
  592. +
  593. + This program is distributed in the hope that it will be useful, but
  594. + WITHOUT ANY WARRANTY; without even the implied warranty of
  595. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  596. + General Public License for more details.
  597. +*/
  598. +
  599. +#include "ipkg.h"
  600. +#include <sys/types.h>
  601. +#include <sys/stat.h>
  602. +
  603. +#include "sprintf_alloc.h"
  604. +#include "file_util.h"
  605. +#include "libbb.h"
  606. +#undef strlen
  607. +
  608. +int file_exists(const char *file_name)
  609. +{
  610. + int err;
  611. + struct stat stat_buf;
  612. +
  613. + err = stat(file_name, &stat_buf);
  614. + if (err == 0) {
  615. + return 1;
  616. + } else {
  617. + return 0;
  618. + }
  619. +}
  620. +
  621. +int file_is_dir(const char *file_name)
  622. +{
  623. + int err;
  624. + struct stat stat_buf;
  625. +
  626. + err = stat(file_name, &stat_buf);
  627. + if (err) {
  628. + return 0;
  629. + }
  630. +
  631. + return S_ISDIR(stat_buf.st_mode);
  632. +}
  633. +
  634. +/* read a single line from a file, stopping at a newline or EOF.
  635. + If a newline is read, it will appear in the resulting string.
  636. + Return value is a malloc'ed char * which should be freed at
  637. + some point by the caller.
  638. +
  639. + Return value is NULL if the file is at EOF when called.
  640. +*/
  641. +#define FILE_READ_LINE_BUF_SIZE 1024
  642. +char *file_read_line_alloc(FILE *file)
  643. +{
  644. + char buf[FILE_READ_LINE_BUF_SIZE];
  645. + int buf_len;
  646. + char *line = NULL;
  647. + int line_size = 0;
  648. +
  649. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  650. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  651. + buf_len = strlen(buf);
  652. + if (line) {
  653. + line_size += buf_len;
  654. + line = realloc(line, line_size);
  655. + if (line == NULL) {
  656. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  657. + break;
  658. + }
  659. + strcat(line, buf);
  660. + } else {
  661. + line_size = buf_len + 1;
  662. + line = strdup(buf);
  663. + }
  664. + if (buf[buf_len - 1] == '\n') {
  665. + break;
  666. + }
  667. + }
  668. +
  669. + return line;
  670. +}
  671. +
  672. +int file_move(const char *src, const char *dest)
  673. +{
  674. + int err;
  675. +
  676. + err = rename(src, dest);
  677. +
  678. + if (err && errno == EXDEV) {
  679. + err = file_copy(src, dest);
  680. + unlink(src);
  681. + } else if (err) {
  682. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  683. + __FUNCTION__, src, dest, strerror(errno));
  684. + }
  685. +
  686. + return err;
  687. +}
  688. +
  689. +/* I put these here to keep libbb dependencies from creeping all over
  690. + the ipkg code */
  691. +int file_copy(const char *src, const char *dest)
  692. +{
  693. + int err;
  694. +
  695. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  696. + if (err) {
  697. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  698. + __FUNCTION__, src, dest);
  699. + }
  700. +
  701. + return err;
  702. +}
  703. +
  704. +int file_mkdir_hier(char *path, long mode)
  705. +{
  706. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  707. +}
  708. +
  709. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  710. + unsigned hash_length)
  711. +{
  712. + /* xzalloc zero-terminates */
  713. + char *hex_value = xzalloc((hash_length * 2) + 1);
  714. + bin2hex(hex_value, (char*)hash_value, hash_length);
  715. + return (unsigned char *)hex_value;
  716. +}
  717. +
  718. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  719. +{
  720. + int src_fd, hash_len, count;
  721. + union _ctx_ {
  722. + sha1_ctx_t sha1;
  723. + md5_ctx_t md5;
  724. + } context;
  725. + uint8_t *hash_value = NULL;
  726. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  727. + void FAST_FUNC (*update)(void*, const void*, size_t);
  728. + void FAST_FUNC (*final)(void*, void*);
  729. +
  730. + src_fd = open_or_warn_stdin(filename);
  731. + if (src_fd < 0) {
  732. + return NULL;
  733. + }
  734. +
  735. + /* figure specific hash algorithims */
  736. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  737. + md5_begin(&context.md5);
  738. + update = (void*)md5_hash;
  739. + final = (void*)md5_end;
  740. + hash_len = 16;
  741. + } else {
  742. + bb_error_msg_and_die("algorithm not supported");
  743. + }
  744. +
  745. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  746. + update(&context, in_buf, count);
  747. + }
  748. +
  749. + if (count == 0) {
  750. + final(&context, in_buf);
  751. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  752. + }
  753. +
  754. + RELEASE_CONFIG_BUFFER(in_buf);
  755. +
  756. + if (src_fd != STDIN_FILENO) {
  757. + close(src_fd);
  758. + }
  759. +
  760. + return hash_value;
  761. +}
  762. +
  763. +uint8_t *file_md5sum_alloc(const char *file_name)
  764. +{
  765. + return hash_file(file_name, HASH_MD5);
  766. +}
  767. +
  768. diff -Nur busybox-1.23.0.orig/archival/libipkg/file_util.h busybox-1.23.0/archival/libipkg/file_util.h
  769. --- busybox-1.23.0.orig/archival/libipkg/file_util.h 1969-12-31 18:00:00.000000000 -0600
  770. +++ busybox-1.23.0/archival/libipkg/file_util.h 2015-01-09 11:18:22.424197243 -0600
  771. @@ -0,0 +1,29 @@
  772. +/* file_util.h - convenience routines for common file operations
  773. +
  774. + Carl D. Worth
  775. +
  776. + Copyright (C) 2001 University of Southern California
  777. +
  778. + This program is free software; you can redistribute it and/or
  779. + modify it under the terms of the GNU General Public License as
  780. + published by the Free Software Foundation; either version 2, or (at
  781. + your option) any later version.
  782. +
  783. + This program is distributed in the hope that it will be useful, but
  784. + WITHOUT ANY WARRANTY; without even the implied warranty of
  785. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  786. + General Public License for more details.
  787. +*/
  788. +
  789. +#ifndef FILE_UTIL_H
  790. +#define FILE_UTIL_H
  791. +
  792. +int file_exists(const char *file_name);
  793. +int file_is_dir(const char *file_name);
  794. +char *file_read_line_alloc(FILE *file);
  795. +int file_move(const char *src, const char *dest);
  796. +int file_copy(const char *src, const char *dest);
  797. +int file_mkdir_hier(char *path, long mode);
  798. +uint8_t *file_md5sum_alloc(const char *file_name);
  799. +
  800. +#endif
  801. diff -Nur busybox-1.23.0.orig/archival/libipkg/hash_table.c busybox-1.23.0/archival/libipkg/hash_table.c
  802. --- busybox-1.23.0.orig/archival/libipkg/hash_table.c 1969-12-31 18:00:00.000000000 -0600
  803. +++ busybox-1.23.0/archival/libipkg/hash_table.c 2015-01-09 11:18:22.424197243 -0600
  804. @@ -0,0 +1,155 @@
  805. +/* hash.c - hash tables for ipkg
  806. +
  807. + Steven M. Ayer, Jamey Hicks
  808. +
  809. + Copyright (C) 2002 Compaq Computer Corporation
  810. +
  811. + This program is free software; you can redistribute it and/or
  812. + modify it under the terms of the GNU General Public License as
  813. + published by the Free Software Foundation; either version 2, or (at
  814. + your option) any later version.
  815. +
  816. + This program is distributed in the hope that it will be useful, but
  817. + WITHOUT ANY WARRANTY; without even the implied warranty of
  818. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  819. + General Public License for more details.
  820. +*/
  821. +
  822. +#include <errno.h>
  823. +#include <stdio.h>
  824. +#include <stdlib.h>
  825. +#include <string.h>
  826. +#include "hash_table.h"
  827. +#include "ipkg_message.h"
  828. +
  829. +
  830. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  831. +static int rotating(const char *key, int len, int prime);
  832. +
  833. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  834. +{
  835. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  836. +}
  837. +
  838. +static int rotating(const char *key, int len, int prime)
  839. +{
  840. + unsigned int hash, i;
  841. + for (hash=len, i=0; i<len; ++i)
  842. + hash = (hash<<4)^(hash>>28)^key[i];
  843. + return (hash % prime);
  844. +}
  845. +
  846. +
  847. +/*
  848. + * this is an open table keyed by strings
  849. + */
  850. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  851. +{
  852. + static int primes_table[] = {
  853. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  854. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  855. + };
  856. + int *picker;
  857. +
  858. + if (hash->entries != NULL) {
  859. + /* we have been here already */
  860. + return 0;
  861. + }
  862. +
  863. + hash->name = name;
  864. + hash->entries = NULL;
  865. + hash->n_entries = 0;
  866. + hash->hash_entry_key = NULL;
  867. +
  868. + picker = primes_table;
  869. + while(*picker && (*picker++ < len));
  870. + if(!*picker)
  871. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  872. + --picker;
  873. +
  874. + hash->n_entries = *picker;
  875. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  876. + if (hash->entries == NULL) {
  877. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  878. + return ENOMEM;
  879. + }
  880. + return 0;
  881. +}
  882. +
  883. +void hash_table_deinit(hash_table_t *hash)
  884. +{
  885. + free(hash->entries);
  886. + hash->entries = NULL;
  887. + hash->n_entries = 0;
  888. +}
  889. +
  890. +void *hash_table_get(hash_table_t *hash, const char *key)
  891. +{
  892. + int ndx= hash_index(hash, key);
  893. + hash_entry_t *hash_entry = hash->entries + ndx;
  894. + while (hash_entry)
  895. + {
  896. + if (hash_entry->key)
  897. + {
  898. + if (strcmp(key, hash_entry->key) == 0) {
  899. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  900. + return hash_entry->data;
  901. + }
  902. + }
  903. + hash_entry = hash_entry->next;
  904. + }
  905. + return NULL;
  906. +}
  907. +
  908. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  909. +{
  910. + int ndx= hash_index(hash, key);
  911. + hash_entry_t *hash_entry = hash->entries + ndx;
  912. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  913. + if (hash_entry->key) {
  914. + if (strcmp(hash_entry->key, key) == 0) {
  915. + /* alread in table, update the value */
  916. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  917. + hash_entry->data = value;
  918. + return 0;
  919. + } else {
  920. + /*
  921. + * if this is a collision, we have to go to the end of the ll,
  922. + * then add a new entry
  923. + * before we can hook up the value
  924. + */
  925. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  926. + while (hash_entry->next)
  927. + hash_entry = hash_entry->next;
  928. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  929. + if (!hash_entry->next) {
  930. + return -ENOMEM;
  931. + }
  932. + hash_entry = hash_entry->next;
  933. + hash_entry->next = NULL;
  934. + }
  935. + }
  936. + hash->n_elements++;
  937. + hash_entry->key = strdup(key);
  938. + hash_entry->data = value;
  939. +
  940. + return 0;
  941. +}
  942. +
  943. +
  944. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  945. +{
  946. + int i;
  947. + if (!hash || !f)
  948. + return;
  949. +
  950. + for (i = 0; i < hash->n_entries; i++) {
  951. + hash_entry_t *hash_entry = (hash->entries + i);
  952. + do {
  953. + if(hash_entry->key) {
  954. + f(hash_entry->key, hash_entry->data, data);
  955. + }
  956. + } while((hash_entry = hash_entry->next));
  957. + }
  958. +}
  959. +
  960. diff -Nur busybox-1.23.0.orig/archival/libipkg/hash_table.h busybox-1.23.0/archival/libipkg/hash_table.h
  961. --- busybox-1.23.0.orig/archival/libipkg/hash_table.h 1969-12-31 18:00:00.000000000 -0600
  962. +++ busybox-1.23.0/archival/libipkg/hash_table.h 2015-01-09 11:18:22.424197243 -0600
  963. @@ -0,0 +1,44 @@
  964. +/* hash.h - hash tables for ipkg
  965. +
  966. + Steven M. Ayer, Jamey Hicks
  967. +
  968. + Copyright (C) 2002 Compaq Computer Corporation
  969. +
  970. + This program is free software; you can redistribute it and/or
  971. + modify it under the terms of the GNU General Public License as
  972. + published by the Free Software Foundation; either version 2, or (at
  973. + your option) any later version.
  974. +
  975. + This program is distributed in the hope that it will be useful, but
  976. + WITHOUT ANY WARRANTY; without even the implied warranty of
  977. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  978. + General Public License for more details.
  979. +*/
  980. +
  981. +#ifndef _HASH_TABLE_H_
  982. +#define _HASH_TABLE_H_
  983. +
  984. +typedef struct hash_entry hash_entry_t;
  985. +typedef struct hash_table hash_table_t;
  986. +
  987. +struct hash_entry {
  988. + const char * key;
  989. + void * data;
  990. + struct hash_entry * next;
  991. +};
  992. +
  993. +struct hash_table {
  994. + const char *name;
  995. + hash_entry_t * entries;
  996. + int n_entries; /* number of buckets */
  997. + int n_elements;
  998. + const char * (*hash_entry_key)(void * data);
  999. +};
  1000. +
  1001. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1002. +void hash_table_deinit(hash_table_t *hash);
  1003. +void *hash_table_get(hash_table_t *hash, const char *key);
  1004. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1005. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1006. +
  1007. +#endif /* _HASH_TABLE_H_ */
  1008. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_cmd.c busybox-1.23.0/archival/libipkg/ipkg_cmd.c
  1009. --- busybox-1.23.0.orig/archival/libipkg/ipkg_cmd.c 1969-12-31 18:00:00.000000000 -0600
  1010. +++ busybox-1.23.0/archival/libipkg/ipkg_cmd.c 2015-01-09 11:30:09.308190771 -0600
  1011. @@ -0,0 +1,1367 @@
  1012. +/* ipkg_cmd.c - the itsy package management system
  1013. +
  1014. + Carl D. Worth
  1015. +
  1016. + Copyright (C) 2001 University of Southern California
  1017. +
  1018. + This program is free software; you can redistribute it and/or
  1019. + modify it under the terms of the GNU General Public License as
  1020. + published by the Free Software Foundation; either version 2, or (at
  1021. + your option) any later version.
  1022. +
  1023. + This program is distributed in the hope that it will be useful, but
  1024. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1025. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1026. + General Public License for more details.
  1027. +*/
  1028. +
  1029. +#include <string.h>
  1030. +
  1031. +#include "ipkg.h"
  1032. +#include <libgen.h>
  1033. +#include <glob.h>
  1034. +#include <errno.h>
  1035. +#include <stdlib.h>
  1036. +#include <unistd.h>
  1037. +#include <signal.h>
  1038. +#include <stdio.h>
  1039. +#include <dirent.h>
  1040. +
  1041. +#include "ipkg_conf.h"
  1042. +#include "ipkg_cmd.h"
  1043. +#include "ipkg_message.h"
  1044. +#include "pkg.h"
  1045. +#include "pkg_dest.h"
  1046. +#include "pkg_parse.h"
  1047. +#include "sprintf_alloc.h"
  1048. +#include "pkg.h"
  1049. +#include "file_util.h"
  1050. +#include "str_util.h"
  1051. +#include "bb_archive.h"
  1052. +
  1053. +#include <fnmatch.h>
  1054. +
  1055. +
  1056. +#include "ipkg_download.h"
  1057. +#include "ipkg_install.h"
  1058. +#include "ipkg_upgrade.h"
  1059. +#include "ipkg_remove.h"
  1060. +#include "ipkg_configure.h"
  1061. +#include "ipkg_message.h"
  1062. +
  1063. +#include "libipkg.h"
  1064. +static void *p_userdata = NULL;
  1065. +
  1066. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1067. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1068. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1069. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1072. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1074. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1090. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +
  1092. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1093. + array for easier maintenance */
  1094. +static ipkg_cmd_t cmds[] = {
  1095. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1096. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1097. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1098. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1099. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1100. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1101. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1102. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1103. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1104. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1105. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1106. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1107. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1108. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1109. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1110. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1111. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1112. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1113. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1114. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1115. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1116. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1117. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1118. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1119. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1120. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1121. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1122. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1123. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1124. +};
  1125. +
  1126. +int ipkg_state_changed;
  1127. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1128. +{
  1129. + if (ipkg_state_changed && !conf->noaction) {
  1130. + ipkg_message(conf, IPKG_INFO,
  1131. + " writing status file\n");
  1132. + ipkg_conf_write_status_files(conf);
  1133. + pkg_write_changed_filelists(conf);
  1134. + } else {
  1135. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1136. + }
  1137. +}
  1138. +
  1139. +
  1140. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1141. +
  1142. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1143. +{
  1144. + int i;
  1145. + ipkg_cmd_t *cmd;
  1146. +
  1147. + for (i=0; i < num_cmds; i++) {
  1148. + cmd = &cmds[i];
  1149. + if (strcmp(name, cmd->name) == 0) {
  1150. + return cmd;
  1151. + }
  1152. + }
  1153. +
  1154. + return NULL;
  1155. +}
  1156. +
  1157. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1158. +{
  1159. + int result;
  1160. + p_userdata = userdata;
  1161. +
  1162. +
  1163. + result = (cmd->fun)(conf, argc, argv);
  1164. + if ( result == 0 ) {
  1165. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1166. + } else {
  1167. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1168. +
  1169. + }
  1170. + if ( error_list ) {
  1171. + reverse_error_list(&error_list);
  1172. +
  1173. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1174. + /* Here we print the errors collected and free the list */
  1175. + while (error_list != NULL) {
  1176. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1177. + error_list = error_list->next;
  1178. +
  1179. + }
  1180. + free_error_list(&error_list);
  1181. +
  1182. + }
  1183. +
  1184. + p_userdata = NULL;
  1185. + return result;
  1186. +}
  1187. +
  1188. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1189. +{
  1190. + int err;
  1191. + int failures;
  1192. + char *lists_dir;
  1193. + pkg_src_list_elt_t *iter;
  1194. + pkg_src_t *src;
  1195. +
  1196. +
  1197. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1198. +
  1199. + if (! file_is_dir(lists_dir)) {
  1200. + if (file_exists(lists_dir)) {
  1201. + ipkg_message(conf, IPKG_ERROR,
  1202. + "%s: ERROR: %s exists, but is not a directory\n",
  1203. + __FUNCTION__, lists_dir);
  1204. + free(lists_dir);
  1205. + return EINVAL;
  1206. + }
  1207. + err = file_mkdir_hier(lists_dir, 0755);
  1208. + if (err) {
  1209. + ipkg_message(conf, IPKG_ERROR,
  1210. + "%s: ERROR: failed to make directory %s: %s\n",
  1211. + __FUNCTION__, lists_dir, strerror(errno));
  1212. + free(lists_dir);
  1213. + return EINVAL;
  1214. + }
  1215. + }
  1216. +
  1217. + failures = 0;
  1218. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1219. + char *url, *list_file_name;
  1220. +
  1221. + src = iter->data;
  1222. +
  1223. + if (src->extra_data) /* debian style? */
  1224. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1225. + src->gzip ? "Packages.gz" : "Packages");
  1226. + else
  1227. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1228. +
  1229. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1230. + if (src->gzip) {
  1231. + char *tmp;
  1232. + char *tmp_file_name;
  1233. + FILE *in, *out;
  1234. +
  1235. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1236. +
  1237. + if (mkdtemp (tmp) == NULL) {
  1238. + perror ("mkdtemp");
  1239. + failures++;
  1240. + continue;
  1241. + }
  1242. +
  1243. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1244. + err = ipkg_download(conf, url, tmp_file_name);
  1245. + if (err == 0) {
  1246. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1247. + in = fopen (tmp_file_name, "r");
  1248. + out = fopen (list_file_name, "w");
  1249. + if (in && out) {
  1250. + transformer_state_t xstate;
  1251. + init_transformer_state(&xstate);
  1252. + inflate_unzip (&xstate);
  1253. + } else
  1254. + err = 1;
  1255. + if (in)
  1256. + fclose (in);
  1257. + if (out)
  1258. + fclose (out);
  1259. + unlink (tmp_file_name);
  1260. + rmdir (tmp);
  1261. + free (tmp);
  1262. + }
  1263. + } else
  1264. + err = ipkg_download(conf, url, list_file_name);
  1265. + if (err) {
  1266. + failures++;
  1267. + } else {
  1268. + ipkg_message(conf, IPKG_NOTICE,
  1269. + "Updated list of available packages in %s\n",
  1270. + list_file_name);
  1271. + }
  1272. + free(url);
  1273. + free(list_file_name);
  1274. + }
  1275. + free(lists_dir);
  1276. +
  1277. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1278. +#warning here
  1279. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1280. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1281. + * -Jamey 3/1/03
  1282. + */
  1283. + {
  1284. + int i;
  1285. + int changed = 0;
  1286. + pkg_vec_t *available = pkg_vec_alloc();
  1287. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1288. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1289. + for (i = 0; i < available->len; i++) {
  1290. + pkg_t *pkg = available->pkgs[i];
  1291. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1292. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1293. + pkg->state_want = SW_UNKNOWN;
  1294. + changed = 1;
  1295. + }
  1296. + }
  1297. + pkg_vec_free(available);
  1298. + if (changed) {
  1299. + write_status_files_if_changed(conf);
  1300. + }
  1301. + }
  1302. +#endif
  1303. +
  1304. + return failures;
  1305. +}
  1306. +
  1307. +
  1308. +/* scan the args passed and cache the local filenames of the packages */
  1309. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1310. +{
  1311. + int i;
  1312. + int err;
  1313. +
  1314. + /*
  1315. + * First scan through package names/urls
  1316. + * For any urls, download the packages and install in database.
  1317. + * For any files, install package info in database.
  1318. + */
  1319. + for (i = 0; i < argc; i ++) {
  1320. + char *filename = argv [i];
  1321. + //char *tmp = basename (tmp);
  1322. + //int tmplen = strlen (tmp);
  1323. +
  1324. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1325. + // continue;
  1326. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1327. + // continue;
  1328. +
  1329. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1330. +
  1331. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1332. + if (err)
  1333. + return err;
  1334. + }
  1335. + return 0;
  1336. +}
  1337. +
  1338. +struct ipkg_intercept
  1339. +{
  1340. + char *oldpath;
  1341. + char *statedir;
  1342. +};
  1343. +
  1344. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1345. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1346. +
  1347. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1348. +{
  1349. + ipkg_intercept_t ctx;
  1350. + char *newpath;
  1351. + int gen;
  1352. +
  1353. + ctx = malloc (sizeof (*ctx));
  1354. + ctx->oldpath = strdup (getenv ("PATH"));
  1355. +
  1356. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1357. + setenv ("PATH", newpath, 1);
  1358. + free (newpath);
  1359. +
  1360. + gen = 0;
  1361. + retry:
  1362. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1363. + if (mkdir (ctx->statedir, 0770) < 0) {
  1364. + if (errno == EEXIST) {
  1365. + free (ctx->statedir);
  1366. + gen++;
  1367. + goto retry;
  1368. + }
  1369. + perror (ctx->statedir);
  1370. + return NULL;
  1371. + }
  1372. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1373. + return ctx;
  1374. +}
  1375. +
  1376. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1377. +
  1378. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1379. +{
  1380. + char *cmd;
  1381. + DIR *dir;
  1382. + int err = 0;
  1383. +
  1384. + setenv ("PATH", ctx->oldpath, 1);
  1385. + free (ctx->oldpath);
  1386. +
  1387. + dir = opendir (ctx->statedir);
  1388. + if (dir) {
  1389. + struct dirent *de;
  1390. + while (de = readdir (dir), de != NULL) {
  1391. + char *path;
  1392. +
  1393. + if (de->d_name[0] == '.')
  1394. + continue;
  1395. +
  1396. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1397. + if (access (path, X_OK) == 0) {
  1398. + if (system (path)) {
  1399. + err = errno;
  1400. + perror (de->d_name);
  1401. + }
  1402. + }
  1403. + free (path);
  1404. + }
  1405. + } else
  1406. + perror (ctx->statedir);
  1407. +
  1408. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1409. + system (cmd);
  1410. + free (cmd);
  1411. +
  1412. + free (ctx->statedir);
  1413. + free (ctx);
  1414. +
  1415. + return err;
  1416. +}
  1417. +
  1418. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1419. +{
  1420. + pkg_vec_t *all;
  1421. + int i;
  1422. + pkg_t *pkg;
  1423. + ipkg_intercept_t ic;
  1424. + int r, err = 0;
  1425. +
  1426. + ipkg_message(conf, IPKG_INFO,
  1427. + "Configuring unpacked packages\n");
  1428. + fflush( stdout );
  1429. +
  1430. + all = pkg_vec_alloc();
  1431. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1432. +
  1433. + ic = ipkg_prep_intercepts();
  1434. +
  1435. + for(i = 0; i < all->len; i++) {
  1436. + pkg = all->pkgs[i];
  1437. +
  1438. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1439. + continue;
  1440. +
  1441. + if (pkg->state_status == SS_UNPACKED) {
  1442. + ipkg_message(conf, IPKG_NOTICE,
  1443. + "Configuring %s\n", pkg->name);
  1444. + fflush( stdout );
  1445. + r = ipkg_configure(conf, pkg);
  1446. + if (r == 0) {
  1447. + pkg->state_status = SS_INSTALLED;
  1448. + pkg->parent->state_status = SS_INSTALLED;
  1449. + pkg->state_flag &= ~SF_PREFER;
  1450. + } else {
  1451. + if (!err)
  1452. + err = r;
  1453. + }
  1454. + }
  1455. + }
  1456. +
  1457. + r = ipkg_finalize_intercepts (ic);
  1458. + if (r && !err)
  1459. + err = r;
  1460. +
  1461. + pkg_vec_free(all);
  1462. + return err;
  1463. +}
  1464. +
  1465. +static void sigint_handler(int sig)
  1466. +{
  1467. + signal(sig, SIG_DFL);
  1468. + ipkg_message(NULL, IPKG_NOTICE,
  1469. + "ipkg: interrupted. writing out status database\n");
  1470. + write_status_files_if_changed(global_conf);
  1471. + exit(128 + sig);
  1472. +}
  1473. +
  1474. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1475. +{
  1476. + int i;
  1477. + char *arg;
  1478. + int err=0;
  1479. +
  1480. + global_conf = conf;
  1481. + signal(SIGINT, sigint_handler);
  1482. +
  1483. + /*
  1484. + * Now scan through package names and install
  1485. + */
  1486. + for (i=0; i < argc; i++) {
  1487. + arg = argv[i];
  1488. +
  1489. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1490. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1491. + if (err != EINVAL && err != 0)
  1492. + return err;
  1493. + }
  1494. + pkg_info_preinstall_check(conf);
  1495. +
  1496. + for (i=0; i < argc; i++) {
  1497. + arg = argv[i];
  1498. + if (conf->multiple_providers)
  1499. + err = ipkg_install_multi_by_name(conf, arg);
  1500. + else{
  1501. + err = ipkg_install_by_name(conf, arg);
  1502. + }
  1503. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1504. + ipkg_message(conf, IPKG_ERROR,
  1505. + "Cannot find package %s.\n"
  1506. + "Check the spelling or perhaps run 'ipkg update'\n",
  1507. + arg);
  1508. + }
  1509. + }
  1510. +
  1511. + /* recheck to verify that all dependences are satisfied */
  1512. + if (0) ipkg_satisfy_all_dependences(conf);
  1513. +
  1514. + ipkg_configure_packages(conf, NULL);
  1515. +
  1516. + write_status_files_if_changed(conf);
  1517. +
  1518. + return err;
  1519. +}
  1520. +
  1521. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1522. +{
  1523. + int i;
  1524. + pkg_t *pkg;
  1525. + int err;
  1526. +
  1527. + global_conf = conf;
  1528. + signal(SIGINT, sigint_handler);
  1529. +
  1530. + if (argc) {
  1531. + for (i=0; i < argc; i++) {
  1532. + char *arg = argv[i];
  1533. +
  1534. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1535. + if (err != EINVAL && err != 0)
  1536. + return err;
  1537. + }
  1538. + pkg_info_preinstall_check(conf);
  1539. +
  1540. + for (i=0; i < argc; i++) {
  1541. + char *arg = argv[i];
  1542. + if (conf->restrict_to_default_dest) {
  1543. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1544. + argv[i],
  1545. + conf->default_dest);
  1546. + if (pkg == NULL) {
  1547. + ipkg_message(conf, IPKG_NOTICE,
  1548. + "Package %s not installed in %s\n",
  1549. + argv[i], conf->default_dest->name);
  1550. + continue;
  1551. + }
  1552. + } else {
  1553. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1554. + argv[i]);
  1555. + }
  1556. + if (pkg)
  1557. + ipkg_upgrade_pkg(conf, pkg);
  1558. + else {
  1559. + ipkg_install_by_name(conf, arg);
  1560. + }
  1561. + }
  1562. + } else {
  1563. + pkg_vec_t *installed = pkg_vec_alloc();
  1564. +
  1565. + pkg_info_preinstall_check(conf);
  1566. +
  1567. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1568. + for (i = 0; i < installed->len; i++) {
  1569. + pkg = installed->pkgs[i];
  1570. + ipkg_upgrade_pkg(conf, pkg);
  1571. + }
  1572. + pkg_vec_free(installed);
  1573. + }
  1574. +
  1575. + /* recheck to verify that all dependences are satisfied */
  1576. + if (0) ipkg_satisfy_all_dependences(conf);
  1577. +
  1578. + ipkg_configure_packages(conf, NULL);
  1579. +
  1580. + write_status_files_if_changed(conf);
  1581. +
  1582. + return 0;
  1583. +}
  1584. +
  1585. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1586. +{
  1587. + int i, err;
  1588. + char *arg;
  1589. + pkg_t *pkg;
  1590. +
  1591. + pkg_info_preinstall_check(conf);
  1592. + for (i = 0; i < argc; i++) {
  1593. + arg = argv[i];
  1594. +
  1595. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1596. + if (pkg == NULL) {
  1597. + ipkg_message(conf, IPKG_ERROR,
  1598. + "Cannot find package %s.\n"
  1599. + "Check the spelling or perhaps run 'ipkg update'\n",
  1600. + arg);
  1601. + continue;
  1602. + }
  1603. +
  1604. + err = ipkg_download_pkg(conf, pkg, ".");
  1605. +
  1606. + if (err) {
  1607. + ipkg_message(conf, IPKG_ERROR,
  1608. + "Failed to download %s\n", pkg->name);
  1609. + } else {
  1610. + ipkg_message(conf, IPKG_NOTICE,
  1611. + "Downloaded %s as %s\n",
  1612. + pkg->name, pkg->local_filename);
  1613. + }
  1614. + }
  1615. +
  1616. + return 0;
  1617. +}
  1618. +
  1619. +
  1620. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1621. +{
  1622. + int i ;
  1623. + pkg_vec_t *available;
  1624. + pkg_t *pkg;
  1625. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1626. + char *newline;
  1627. + char *pkg_name = NULL;
  1628. + char *version_str;
  1629. +
  1630. + if (argc > 0) {
  1631. + pkg_name = argv[0];
  1632. + }
  1633. + available = pkg_vec_alloc();
  1634. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1635. + for (i=0; i < available->len; i++) {
  1636. + pkg = available->pkgs[i];
  1637. + /* if we have package name or pattern and pkg does not match, then skip it */
  1638. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1639. + continue;
  1640. + if (pkg->description) {
  1641. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1642. + } else {
  1643. + desc_short[0] = '\0';
  1644. + }
  1645. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1646. + newline = strchr(desc_short, '\n');
  1647. + if (newline) {
  1648. + *newline = '\0';
  1649. + }
  1650. + if (ipkg_cb_list) {
  1651. + version_str = pkg_version_str_alloc(pkg);
  1652. + ipkg_cb_list(pkg->name,desc_short,
  1653. + version_str,
  1654. + pkg->state_status,
  1655. + p_userdata);
  1656. + free(version_str);
  1657. + }
  1658. + }
  1659. + pkg_vec_free(available);
  1660. +
  1661. + return 0;
  1662. +}
  1663. +
  1664. +
  1665. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1666. +{
  1667. + int i ;
  1668. + pkg_vec_t *available;
  1669. + pkg_t *pkg;
  1670. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1671. + char *newline;
  1672. + char *pkg_name = NULL;
  1673. + char *version_str;
  1674. +
  1675. + if (argc > 0) {
  1676. + pkg_name = argv[0];
  1677. + }
  1678. + available = pkg_vec_alloc();
  1679. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1680. + for (i=0; i < available->len; i++) {
  1681. + pkg = available->pkgs[i];
  1682. + /* if we have package name or pattern and pkg does not match, then skip it */
  1683. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1684. + continue;
  1685. + if (pkg->description) {
  1686. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1687. + } else {
  1688. + desc_short[0] = '\0';
  1689. + }
  1690. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1691. + newline = strchr(desc_short, '\n');
  1692. + if (newline) {
  1693. + *newline = '\0';
  1694. + }
  1695. + if (ipkg_cb_list) {
  1696. + version_str = pkg_version_str_alloc(pkg);
  1697. + ipkg_cb_list(pkg->name,desc_short,
  1698. + version_str,
  1699. + pkg->state_status,
  1700. + p_userdata);
  1701. + free(version_str);
  1702. + }
  1703. + }
  1704. +
  1705. + return 0;
  1706. +}
  1707. +
  1708. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1709. +{
  1710. + int i;
  1711. + pkg_vec_t *available;
  1712. + pkg_t *pkg;
  1713. + char *pkg_name = NULL;
  1714. + char **pkg_fields = NULL;
  1715. + int n_fields = 0;
  1716. + char *buff ; // = (char *)malloc(1);
  1717. +
  1718. + if (argc > 0) {
  1719. + pkg_name = argv[0];
  1720. + }
  1721. + if (argc > 1) {
  1722. + pkg_fields = &argv[1];
  1723. + n_fields = argc - 1;
  1724. + }
  1725. +
  1726. + available = pkg_vec_alloc();
  1727. + if (installed_only)
  1728. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1729. + else
  1730. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1731. + for (i=0; i < available->len; i++) {
  1732. + pkg = available->pkgs[i];
  1733. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1734. + continue;
  1735. + }
  1736. + buff = pkg_formatted_info(pkg);
  1737. + if ( buff ) {
  1738. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1739. + pkg->state_status,
  1740. + buff,
  1741. + p_userdata);
  1742. + free(buff);
  1743. + }
  1744. + if (conf->verbosity > 1) {
  1745. + conffile_list_elt_t *iter;
  1746. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1747. + conffile_t *cf = iter->data;
  1748. + int modified = conffile_has_been_modified(conf, cf);
  1749. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1750. + cf->name, cf->value, modified);
  1751. + }
  1752. + }
  1753. + }
  1754. + pkg_vec_free(available);
  1755. +
  1756. + return 0;
  1757. +}
  1758. +
  1759. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1760. +{
  1761. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1762. +}
  1763. +
  1764. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1765. +{
  1766. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1767. +}
  1768. +
  1769. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1770. +{
  1771. +
  1772. + int err;
  1773. + if (argc > 0) {
  1774. + char *pkg_name = NULL;
  1775. +
  1776. + pkg_name = argv[0];
  1777. +
  1778. + err = ipkg_configure_packages (conf, pkg_name);
  1779. +
  1780. + } else {
  1781. + err = ipkg_configure_packages (conf, NULL);
  1782. + }
  1783. +
  1784. + write_status_files_if_changed(conf);
  1785. +
  1786. + return err;
  1787. +}
  1788. +
  1789. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1790. +{
  1791. + int i, err;
  1792. + char *globpattern;
  1793. + glob_t globbuf;
  1794. +
  1795. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1796. + err = glob(globpattern, 0, NULL, &globbuf);
  1797. + free(globpattern);
  1798. + if (err) {
  1799. + return 0;
  1800. + }
  1801. +
  1802. + ipkg_message(conf, IPKG_NOTICE,
  1803. + "The following packages in %s will now be installed.\n",
  1804. + conf->pending_dir);
  1805. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1806. + ipkg_message(conf, IPKG_NOTICE,
  1807. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1808. + }
  1809. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1810. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1811. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1812. + if (err == 0) {
  1813. + err = unlink(globbuf.gl_pathv[i]);
  1814. + if (err) {
  1815. + ipkg_message(conf, IPKG_ERROR,
  1816. + "%s: ERROR: failed to unlink %s: %s\n",
  1817. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1818. + return err;
  1819. + }
  1820. + }
  1821. + }
  1822. + globfree(&globbuf);
  1823. +
  1824. + return err;
  1825. +}
  1826. +
  1827. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1828. +{
  1829. + int i,a,done;
  1830. + pkg_t *pkg;
  1831. + pkg_t *pkg_to_remove;
  1832. + pkg_vec_t *available;
  1833. + char *pkg_name = NULL;
  1834. + global_conf = conf;
  1835. + signal(SIGINT, sigint_handler);
  1836. +
  1837. +// ENH: Add the "no pkg removed" just in case.
  1838. +
  1839. + done = 0;
  1840. +
  1841. + available = pkg_vec_alloc();
  1842. + pkg_info_preinstall_check(conf);
  1843. + if ( argc > 0 ) {
  1844. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1845. + for (i=0; i < argc; i++) {
  1846. + pkg_name = malloc(strlen(argv[i])+2);
  1847. + strcpy(pkg_name,argv[i]);
  1848. + for (a=0; a < available->len; a++) {
  1849. + pkg = available->pkgs[a];
  1850. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1851. + continue;
  1852. + }
  1853. + if (conf->restrict_to_default_dest) {
  1854. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1855. + pkg->name,
  1856. + conf->default_dest);
  1857. + } else {
  1858. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1859. + }
  1860. +
  1861. + if (pkg == NULL) {
  1862. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1863. + continue;
  1864. + }
  1865. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1866. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1867. + continue;
  1868. + }
  1869. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1870. + done = 1;
  1871. + }
  1872. + free (pkg_name);
  1873. + }
  1874. + pkg_vec_free(available);
  1875. + } else {
  1876. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1877. + int flagged_pkg_count = 0;
  1878. + int removed;
  1879. +
  1880. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1881. +
  1882. + for (i = 0; i < installed_pkgs->len; i++) {
  1883. + pkg = installed_pkgs->pkgs[i];
  1884. + if (pkg->state_flag & SF_USER) {
  1885. + flagged_pkg_count++;
  1886. + } else {
  1887. + if (!pkg_has_installed_dependents(pkg, NULL))
  1888. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1889. + }
  1890. + }
  1891. + if (!flagged_pkg_count) {
  1892. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1893. + "so refusing to uninstall unflagged non-leaf packages\n");
  1894. + return 0;
  1895. + }
  1896. +
  1897. + /* find packages not flagged SF_USER (i.e., installed to
  1898. + * satisfy a dependence) and not having any dependents, and
  1899. + * remove them */
  1900. + do {
  1901. + removed = 0;
  1902. + for (i = 0; i < installed_pkgs->len; i++) {
  1903. + pkg = installed_pkgs->pkgs[i];
  1904. + if (!(pkg->state_flag & SF_USER)
  1905. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1906. + removed++;
  1907. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1908. + ipkg_remove_pkg(conf, pkg,0);
  1909. + done = 1;
  1910. + }
  1911. + }
  1912. + } while (removed);
  1913. + pkg_vec_free(installed_pkgs);
  1914. + }
  1915. +
  1916. + if ( done == 0 )
  1917. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1918. +
  1919. + write_status_files_if_changed(conf);
  1920. + return 0;
  1921. +}
  1922. +
  1923. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1924. +{
  1925. + int i;
  1926. + pkg_t *pkg;
  1927. +
  1928. + global_conf = conf;
  1929. + signal(SIGINT, sigint_handler);
  1930. +
  1931. + pkg_info_preinstall_check(conf);
  1932. +
  1933. + for (i=0; i < argc; i++) {
  1934. + if (conf->restrict_to_default_dest) {
  1935. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1936. + argv[i],
  1937. + conf->default_dest);
  1938. + } else {
  1939. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1940. + }
  1941. +
  1942. + if (pkg == NULL) {
  1943. + ipkg_message(conf, IPKG_ERROR,
  1944. + "Package %s is not installed.\n", argv[i]);
  1945. + continue;
  1946. + }
  1947. + ipkg_purge_pkg(conf, pkg);
  1948. + }
  1949. +
  1950. + write_status_files_if_changed(conf);
  1951. + return 0;
  1952. +}
  1953. +
  1954. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1955. +{
  1956. + int i;
  1957. + pkg_t *pkg;
  1958. + char *flags = argv[0];
  1959. +
  1960. + global_conf = conf;
  1961. + signal(SIGINT, sigint_handler);
  1962. +
  1963. + for (i=1; i < argc; i++) {
  1964. + if (conf->restrict_to_default_dest) {
  1965. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1966. + argv[i],
  1967. + conf->default_dest);
  1968. + } else {
  1969. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1970. + }
  1971. +
  1972. + if (pkg == NULL) {
  1973. + ipkg_message(conf, IPKG_ERROR,
  1974. + "Package %s is not installed.\n", argv[i]);
  1975. + continue;
  1976. + }
  1977. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1978. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1979. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1980. + }
  1981. +/* pb_ asked this feature 03292004 */
  1982. +/* Actually I will use only this two, but this is an open for various status */
  1983. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1984. + pkg->state_status = pkg_state_status_from_str(flags);
  1985. + }
  1986. + ipkg_state_changed++;
  1987. + ipkg_message(conf, IPKG_NOTICE,
  1988. + "Setting flags for package %s to %s\n",
  1989. + pkg->name, flags);
  1990. + }
  1991. +
  1992. + write_status_files_if_changed(conf);
  1993. + return 0;
  1994. +}
  1995. +
  1996. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1997. +{
  1998. + pkg_t *pkg;
  1999. + str_list_t *installed_files;
  2000. + str_list_elt_t *iter;
  2001. + char *pkg_version;
  2002. + size_t buff_len = 8192;
  2003. + size_t used_len;
  2004. + char *buff ;
  2005. +
  2006. + buff = (char *)malloc(buff_len);
  2007. + if ( buff == NULL ) {
  2008. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2009. + return ENOMEM;
  2010. + }
  2011. +
  2012. + if (argc < 1) {
  2013. + return EINVAL;
  2014. + }
  2015. +
  2016. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2017. + argv[0]);
  2018. + if (pkg == NULL) {
  2019. + ipkg_message(conf, IPKG_ERROR,
  2020. + "Package %s not installed.\n", argv[0]);
  2021. + return 0;
  2022. + }
  2023. +
  2024. + installed_files = pkg_get_installed_files(pkg);
  2025. + pkg_version = pkg_version_str_alloc(pkg);
  2026. +
  2027. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2028. + pkg->name, pkg_version, pkg->dest->name);
  2029. + for (iter = installed_files->head; iter; iter = iter->next) {
  2030. + puts(iter->data);
  2031. + }
  2032. +
  2033. + free(pkg_version);
  2034. + pkg_free_installed_files(pkg);
  2035. +
  2036. + return 0;
  2037. +}
  2038. +
  2039. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2040. +{
  2041. +
  2042. + if (argc > 0) {
  2043. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2044. + const char *rel_str = "depends on";
  2045. + int i;
  2046. +
  2047. + pkg_info_preinstall_check(conf);
  2048. +
  2049. + if (conf->query_all)
  2050. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2051. + else
  2052. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2053. + for (i = 0; i < argc; i++) {
  2054. + const char *target = argv[i];
  2055. + int j;
  2056. +
  2057. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2058. +
  2059. + for (j = 0; j < available_pkgs->len; j++) {
  2060. + pkg_t *pkg = available_pkgs->pkgs[j];
  2061. + if (fnmatch(target, pkg->name, 0) == 0) {
  2062. + int k;
  2063. + int count = pkg->depends_count + pkg->pre_depends_count;
  2064. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2065. + target, pkg->architecture, rel_str);
  2066. + for (k = 0; k < count; k++) {
  2067. + compound_depend_t *cdepend = &pkg->depends[k];
  2068. + int l;
  2069. + for (l = 0; l < cdepend->possibility_count; l++) {
  2070. + depend_t *possibility = cdepend->possibilities[l];
  2071. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2072. + if (conf->verbosity > 0) {
  2073. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2074. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2075. + if (possibility->version) {
  2076. + const char *typestr = NULL;
  2077. + switch (possibility->constraint) {
  2078. + case NONE: typestr = "none"; break;
  2079. + case EARLIER: typestr = "<"; break;
  2080. + case EARLIER_EQUAL: typestr = "<="; break;
  2081. + case EQUAL: typestr = "="; break;
  2082. + case LATER_EQUAL: typestr = ">="; break;
  2083. + case LATER: typestr = ">"; break;
  2084. + }
  2085. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2086. + }
  2087. + // free(ver);
  2088. + }
  2089. + ipkg_message(conf, IPKG_ERROR, "\n");
  2090. + }
  2091. + }
  2092. + }
  2093. + }
  2094. + }
  2095. + pkg_vec_free(available_pkgs);
  2096. + }
  2097. + return 0;
  2098. +}
  2099. +
  2100. +enum what_field_type {
  2101. + WHATDEPENDS,
  2102. + WHATCONFLICTS,
  2103. + WHATPROVIDES,
  2104. + WHATREPLACES,
  2105. + WHATRECOMMENDS,
  2106. + WHATSUGGESTS
  2107. +};
  2108. +
  2109. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2110. +{
  2111. +
  2112. + if (argc > 0) {
  2113. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2114. + const char *rel_str = NULL;
  2115. + int i;
  2116. + int changed;
  2117. +
  2118. + switch (what_field_type) {
  2119. + case WHATDEPENDS: rel_str = "depends on"; break;
  2120. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2121. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2122. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2123. + case WHATPROVIDES: rel_str = "provides"; break;
  2124. + case WHATREPLACES: rel_str = "replaces"; break;
  2125. + }
  2126. +
  2127. + if (conf->query_all)
  2128. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2129. + else
  2130. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2131. +
  2132. + /* mark the root set */
  2133. + pkg_vec_clear_marks(available_pkgs);
  2134. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2135. + for (i = 0; i < argc; i++) {
  2136. + const char *dependee_pattern = argv[i];
  2137. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2138. + }
  2139. + for (i = 0; i < available_pkgs->len; i++) {
  2140. + pkg_t *pkg = available_pkgs->pkgs[i];
  2141. + if (pkg->state_flag & SF_MARKED) {
  2142. + /* mark the parent (abstract) package */
  2143. + pkg_mark_provides(pkg);
  2144. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2145. + }
  2146. + }
  2147. +
  2148. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2149. + do {
  2150. + int j;
  2151. + changed = 0;
  2152. +
  2153. + for (j = 0; j < available_pkgs->len; j++) {
  2154. + pkg_t *pkg = available_pkgs->pkgs[j];
  2155. + int k;
  2156. + int count = ((what_field_type == WHATCONFLICTS)
  2157. + ? pkg->conflicts_count
  2158. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2159. + /* skip this package if it is already marked */
  2160. + if (pkg->parent->state_flag & SF_MARKED) {
  2161. + continue;
  2162. + }
  2163. + for (k = 0; k < count; k++) {
  2164. + compound_depend_t *cdepend =
  2165. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2166. + int l;
  2167. + for (l = 0; l < cdepend->possibility_count; l++) {
  2168. + depend_t *possibility = cdepend->possibilities[l];
  2169. + if (possibility->pkg->state_flag & SF_MARKED) {
  2170. + /* mark the depending package so we won't visit it again */
  2171. + pkg->state_flag |= SF_MARKED;
  2172. + pkg_mark_provides(pkg);
  2173. + changed++;
  2174. +
  2175. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2176. + if (conf->verbosity > 0) {
  2177. + char *ver = pkg_version_str_alloc(pkg);
  2178. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2179. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2180. + if (possibility->version) {
  2181. + const char *typestr = NULL;
  2182. + switch (possibility->constraint) {
  2183. + case NONE: typestr = "none"; break;
  2184. + case EARLIER: typestr = "<"; break;
  2185. + case EARLIER_EQUAL: typestr = "<="; break;
  2186. + case EQUAL: typestr = "="; break;
  2187. + case LATER_EQUAL: typestr = ">="; break;
  2188. + case LATER: typestr = ">"; break;
  2189. + }
  2190. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2191. + }
  2192. + free(ver);
  2193. + if (!pkg_dependence_satisfiable(possibility))
  2194. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2195. + }
  2196. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2197. + goto next_package;
  2198. + }
  2199. + }
  2200. + }
  2201. + next_package:
  2202. + ;
  2203. + }
  2204. + } while (changed && recursive);
  2205. + pkg_vec_free(available_pkgs);
  2206. + }
  2207. +
  2208. + return 0;
  2209. +}
  2210. +
  2211. +int pkg_mark_provides(pkg_t *pkg)
  2212. +{
  2213. + int provides_count = pkg->provides_count;
  2214. + abstract_pkg_t **provides = pkg->provides;
  2215. + int i;
  2216. + pkg->parent->state_flag |= SF_MARKED;
  2217. + for (i = 0; i < provides_count; i++) {
  2218. + provides[i]->state_flag |= SF_MARKED;
  2219. + }
  2220. + return 0;
  2221. +}
  2222. +
  2223. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2224. +{
  2225. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2226. +}
  2227. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2228. +{
  2229. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2230. +}
  2231. +
  2232. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2233. +{
  2234. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2235. +}
  2236. +
  2237. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2238. +{
  2239. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2240. +}
  2241. +
  2242. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2243. +{
  2244. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2245. +}
  2246. +
  2247. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2248. +{
  2249. +
  2250. + if (argc > 0) {
  2251. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2252. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2253. + int i;
  2254. +
  2255. + pkg_info_preinstall_check(conf);
  2256. +
  2257. + if (conf->query_all)
  2258. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2259. + else
  2260. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2261. + for (i = 0; i < argc; i++) {
  2262. + const char *target = argv[i];
  2263. + int j;
  2264. +
  2265. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2266. + rel_str, target);
  2267. + for (j = 0; j < available_pkgs->len; j++) {
  2268. + pkg_t *pkg = available_pkgs->pkgs[j];
  2269. + int k;
  2270. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2271. + for (k = 0; k < count; k++) {
  2272. + abstract_pkg_t *apkg =
  2273. + ((what_field_type == WHATPROVIDES)
  2274. + ? pkg->provides[k]
  2275. + : pkg->replaces[k]);
  2276. + if (fnmatch(target, apkg->name, 0) == 0) {
  2277. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2278. + if (strcmp(target, apkg->name) != 0)
  2279. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2280. + ipkg_message(conf, IPKG_ERROR, "\n");
  2281. + }
  2282. + }
  2283. + }
  2284. + }
  2285. + pkg_vec_free(available_pkgs);
  2286. + }
  2287. + return 0;
  2288. +}
  2289. +
  2290. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2291. +{
  2292. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2293. +}
  2294. +
  2295. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2296. +{
  2297. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2298. +}
  2299. +
  2300. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2301. +{
  2302. + int i;
  2303. +
  2304. + pkg_vec_t *installed;
  2305. + pkg_t *pkg;
  2306. + str_list_t *installed_files;
  2307. + str_list_elt_t *iter;
  2308. + char *installed_file;
  2309. +
  2310. + if (argc < 1) {
  2311. + return EINVAL;
  2312. + }
  2313. +
  2314. + installed = pkg_vec_alloc();
  2315. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2316. +
  2317. + for (i=0; i < installed->len; i++) {
  2318. + pkg = installed->pkgs[i];
  2319. +
  2320. + installed_files = pkg_get_installed_files(pkg);
  2321. +
  2322. + for (iter = installed_files->head; iter; iter = iter->next) {
  2323. + installed_file = iter->data;
  2324. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2325. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2326. + installed_file,
  2327. + pkg_version_str_alloc(pkg),
  2328. + pkg->state_status, p_userdata);
  2329. + }
  2330. + }
  2331. +
  2332. + pkg_free_installed_files(pkg);
  2333. + }
  2334. +
  2335. + /* XXX: CLEANUP: It's not obvious from the name of
  2336. + pkg_hash_fetch_all_installed that we need to call
  2337. + pkg_vec_free to avoid a memory leak. */
  2338. + pkg_vec_free(installed);
  2339. +
  2340. + return 0;
  2341. +}
  2342. +
  2343. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2344. +{
  2345. + if (argc == 3) {
  2346. + /* this is a bit gross */
  2347. + struct pkg p1, p2;
  2348. + parseVersion(&p1, argv[0]);
  2349. + parseVersion(&p2, argv[2]);
  2350. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2351. + } else {
  2352. + ipkg_message(conf, IPKG_ERROR,
  2353. + "ipkg compare_versions <v1> <op> <v2>\n"
  2354. + "<op> is one of <= >= << >> =\n");
  2355. + return -1;
  2356. + }
  2357. +}
  2358. +
  2359. +#ifndef HOST_CPU_STR
  2360. +#define HOST_CPU_STR__(X) #X
  2361. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2362. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2363. +#endif
  2364. +
  2365. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2366. +{
  2367. + nv_pair_list_elt_t *l;
  2368. +
  2369. + l = conf->arch_list.head;
  2370. + while (l) {
  2371. + nv_pair_t *nv = l->data;
  2372. + printf("arch %s %s\n", nv->name, nv->value);
  2373. + l = l->next;
  2374. + }
  2375. + return 0;
  2376. +}
  2377. +
  2378. +
  2379. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_cmd.h busybox-1.23.0/archival/libipkg/ipkg_cmd.h
  2380. --- busybox-1.23.0.orig/archival/libipkg/ipkg_cmd.h 1969-12-31 18:00:00.000000000 -0600
  2381. +++ busybox-1.23.0/archival/libipkg/ipkg_cmd.h 2015-01-09 11:18:22.424197243 -0600
  2382. @@ -0,0 +1,41 @@
  2383. +/* ipkg_cmd.h - the itsy package management system
  2384. +
  2385. + Carl D. Worth
  2386. +
  2387. + Copyright (C) 2001 University of Southern California
  2388. +
  2389. + This program is free software; you can redistribute it and/or
  2390. + modify it under the terms of the GNU General Public License as
  2391. + published by the Free Software Foundation; either version 2, or (at
  2392. + your option) any later version.
  2393. +
  2394. + This program is distributed in the hope that it will be useful, but
  2395. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2396. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2397. + General Public License for more details.
  2398. +*/
  2399. +
  2400. +#ifndef IPKG_CMD_H
  2401. +#define IPKG_CMD_H
  2402. +
  2403. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2404. +
  2405. +struct ipkg_cmd
  2406. +{
  2407. + const char *name;
  2408. + int requires_args;
  2409. + ipkg_cmd_fun_t fun;
  2410. +};
  2411. +typedef struct ipkg_cmd ipkg_cmd_t;
  2412. +
  2413. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2414. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2415. + const char **argv, void *userdata);
  2416. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2417. +/* install any packges with state_want == SW_INSTALL */
  2418. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2419. +/* ensure that all dependences are satisfied */
  2420. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2421. +int pkg_mark_provides(pkg_t *pkg);
  2422. +
  2423. +#endif
  2424. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_conf.c busybox-1.23.0/archival/libipkg/ipkg_conf.c
  2425. --- busybox-1.23.0.orig/archival/libipkg/ipkg_conf.c 1969-12-31 18:00:00.000000000 -0600
  2426. +++ busybox-1.23.0/archival/libipkg/ipkg_conf.c 2015-01-09 11:18:22.424197243 -0600
  2427. @@ -0,0 +1,739 @@
  2428. +/* ipkg_conf.c - the itsy package management system
  2429. +
  2430. + Carl D. Worth
  2431. +
  2432. + Copyright (C) 2001 University of Southern California
  2433. +
  2434. + This program is free software; you can redistribute it and/or
  2435. + modify it under the terms of the GNU General Public License as
  2436. + published by the Free Software Foundation; either version 2, or (at
  2437. + your option) any later version.
  2438. +
  2439. + This program is distributed in the hope that it will be useful, but
  2440. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2441. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2442. + General Public License for more details.
  2443. +*/
  2444. +
  2445. +#include <glob.h>
  2446. +
  2447. +#include "ipkg.h"
  2448. +#include "ipkg_conf.h"
  2449. +
  2450. +#include "xregex.h"
  2451. +#include "sprintf_alloc.h"
  2452. +#include "ipkg_conf.h"
  2453. +#include "ipkg_message.h"
  2454. +#include "file_util.h"
  2455. +#include "str_util.h"
  2456. +#include "xsystem.h"
  2457. +
  2458. +
  2459. +ipkg_conf_t *global_conf;
  2460. +
  2461. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2462. + pkg_src_list_t *pkg_src_list,
  2463. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2464. + char **tmp_lists_dir);
  2465. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2466. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2467. + const char *name, const char *value);
  2468. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2469. + const char *default_dest_name);
  2470. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2471. + pkg_src_list_t *nv_pair_list);
  2472. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2473. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2474. +
  2475. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2476. +{
  2477. + ipkg_option_t tmp[] = {
  2478. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2479. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2480. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2481. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2482. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2483. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2484. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2485. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2486. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2487. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2488. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2489. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2490. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2491. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2492. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2493. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2494. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2495. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2496. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2497. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2498. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2499. + { NULL }
  2500. + };
  2501. +
  2502. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2503. + if ( options == NULL ){
  2504. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2505. + return -1;
  2506. + }
  2507. +
  2508. + memcpy(*options, tmp, sizeof(tmp));
  2509. + return 0;
  2510. +};
  2511. +
  2512. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2513. +{
  2514. + if (arg_str) {
  2515. + if (*conf_str) {
  2516. + free(*conf_str);
  2517. + }
  2518. + *conf_str = strdup(arg_str);
  2519. + }
  2520. +}
  2521. +
  2522. +static void ipkg_conf_free_string(char **conf_str)
  2523. +{
  2524. + if (*conf_str) {
  2525. + free(*conf_str);
  2526. + *conf_str = NULL;
  2527. + }
  2528. +}
  2529. +
  2530. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2531. +{
  2532. + int err;
  2533. + int remountroot;
  2534. + struct mntent *mnt;
  2535. + FILE *f;
  2536. + char *tmp_dir_base;
  2537. + nv_pair_list_t tmp_dest_nv_pair_list;
  2538. + char * lists_dir =NULL;
  2539. + glob_t globbuf;
  2540. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2541. + char *pending_dir =NULL;
  2542. +
  2543. + memset(conf, 0, sizeof(ipkg_conf_t));
  2544. +
  2545. + pkg_src_list_init(&conf->pkg_src_list);
  2546. +
  2547. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2548. + pkg_dest_list_init(&conf->pkg_dest_list);
  2549. +
  2550. + nv_pair_list_init(&conf->arch_list);
  2551. +
  2552. + conf->restrict_to_default_dest = 0;
  2553. + conf->default_dest = NULL;
  2554. +
  2555. +
  2556. + if (args->tmp_dir)
  2557. + tmp_dir_base = args->tmp_dir;
  2558. + else
  2559. + tmp_dir_base = getenv("IPKGTMPDIR");
  2560. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2561. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2562. + IPKG_CONF_TMP_DIR_SUFFIX);
  2563. +
  2564. + remountroot = 0;
  2565. + /* check if /dev/root is mounted read-only */
  2566. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  2567. + fprintf (stderr, "Checking /proc/mounts failed\n");
  2568. + while ((mnt = getmntent(f)) != NULL) {
  2569. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  2570. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  2571. + remountroot = 1;
  2572. + }
  2573. + }
  2574. + endmntent(f);
  2575. +
  2576. + if (remountroot) {
  2577. + /* mount rootfs read-write */
  2578. + if (mount("","/",0,MS_REMOUNT,0)<0)
  2579. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  2580. + }
  2581. + mkdir(tmp_dir_base, S_IRWXU);
  2582. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2583. + if (conf->tmp_dir == NULL) {
  2584. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2585. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2586. + return errno;
  2587. + }
  2588. + if (remountroot) {
  2589. + sync();
  2590. + /* mount rootfs read-only */
  2591. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  2592. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  2593. + }
  2594. +
  2595. + conf->force_depends = 0;
  2596. + conf->force_defaults = 0;
  2597. + conf->force_overwrite = 0;
  2598. + conf->force_downgrade = 0;
  2599. + conf->force_reinstall = 0;
  2600. + conf->force_space = 0;
  2601. + conf->force_removal_of_essential_packages = 0;
  2602. + conf->force_removal_of_dependent_packages = 0;
  2603. + conf->nodeps = 0;
  2604. + conf->verbose_wget = 0;
  2605. + conf->offline_root = NULL;
  2606. + conf->offline_root_pre_script_cmd = NULL;
  2607. + conf->offline_root_post_script_cmd = NULL;
  2608. + conf->multiple_providers = 0;
  2609. + conf->verbosity = 1;
  2610. + conf->noaction = 0;
  2611. +
  2612. + conf->http_proxy = NULL;
  2613. + conf->ftp_proxy = NULL;
  2614. + conf->no_proxy = NULL;
  2615. + conf->proxy_user = NULL;
  2616. + conf->proxy_passwd = NULL;
  2617. +
  2618. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2619. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2620. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2621. + lists_dir=(char *)malloc(1);
  2622. + lists_dir[0]='\0';
  2623. + if (args->conf_file) {
  2624. + struct stat stat_buf;
  2625. + err = stat(args->conf_file, &stat_buf);
  2626. + if (err == 0)
  2627. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2628. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2629. + /* Memory leakage from ipkg_conf_parse-file */
  2630. + return -1;
  2631. + }
  2632. +
  2633. + }
  2634. +
  2635. + /* if (!lists_dir ){*/
  2636. + if (strlen(lists_dir)<=1 ){
  2637. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2638. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2639. + }
  2640. +
  2641. + if (args->offline_root) {
  2642. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2643. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2644. + free(lists_dir);
  2645. + lists_dir = tmp;
  2646. + }
  2647. +
  2648. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2649. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2650. +
  2651. + conf->lists_dir = strdup(lists_dir);
  2652. + conf->pending_dir = strdup(pending_dir);
  2653. +
  2654. + if (args->offline_root)
  2655. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2656. + memset(&globbuf, 0, sizeof(globbuf));
  2657. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2658. + if (!err) {
  2659. + int i;
  2660. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2661. + if (globbuf.gl_pathv[i])
  2662. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2663. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2664. + /* Memory leakage from ipkg_conf_parse-file */
  2665. + return -1;
  2666. + }
  2667. + }
  2668. + }
  2669. + globfree(&globbuf);
  2670. +
  2671. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2672. + if (nv_pair_list_empty(&conf->arch_list)) {
  2673. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2674. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2675. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2676. + }
  2677. +
  2678. + /* Even if there is no conf file, we'll need at least one dest. */
  2679. + if (tmp_dest_nv_pair_list.head == NULL) {
  2680. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2681. + IPKG_CONF_DEFAULT_DEST_NAME,
  2682. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2683. + }
  2684. +
  2685. + /* After parsing the file, set options from command-line, (so that
  2686. + command-line arguments take precedence) */
  2687. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2688. + really needs to be cleaned up. There is so much duplication
  2689. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2690. + a pointer to args_t (which could then not be freed), rather
  2691. + than duplicating every field here? */
  2692. + if (args->force_depends) {
  2693. + conf->force_depends = 1;
  2694. + }
  2695. + if (args->force_defaults) {
  2696. + conf->force_defaults = 1;
  2697. + }
  2698. + if (args->force_overwrite) {
  2699. + conf->force_overwrite = 1;
  2700. + }
  2701. + if (args->force_downgrade) {
  2702. + conf->force_downgrade = 1;
  2703. + }
  2704. + if (args->force_reinstall) {
  2705. + conf->force_reinstall = 1;
  2706. + }
  2707. + if (args->force_removal_of_dependent_packages) {
  2708. + conf->force_removal_of_dependent_packages = 1;
  2709. + }
  2710. + if (args->force_removal_of_essential_packages) {
  2711. + conf->force_removal_of_essential_packages = 1;
  2712. + }
  2713. + if (args->nodeps) {
  2714. + conf->nodeps = 1;
  2715. + }
  2716. + if (args->noaction) {
  2717. + conf->noaction = 1;
  2718. + }
  2719. + if (args->query_all) {
  2720. + conf->query_all = 1;
  2721. + }
  2722. + if (args->verbose_wget) {
  2723. + conf->verbose_wget = 1;
  2724. + }
  2725. + if (args->multiple_providers) {
  2726. + conf->multiple_providers = 1;
  2727. + }
  2728. + if (args->verbosity != conf->verbosity) {
  2729. + conf->verbosity = args->verbosity;
  2730. + }
  2731. +
  2732. + ipkg_conf_override_string(&conf->offline_root,
  2733. + args->offline_root);
  2734. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2735. + args->offline_root_pre_script_cmd);
  2736. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2737. + args->offline_root_post_script_cmd);
  2738. +
  2739. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2740. + read anything from there.
  2741. +*/
  2742. + if ( !(args->nocheckfordirorfile)){
  2743. + /* need to run load the source list before dest list -Jamey */
  2744. + if ( !(args->noreadfeedsfile))
  2745. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2746. +
  2747. + /* Now that we have resolved conf->offline_root, we can commit to
  2748. + the directory names for the dests and load in all the package
  2749. + lists. */
  2750. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2751. +
  2752. + if (args->dest) {
  2753. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2754. + if (err) {
  2755. + return err;
  2756. + }
  2757. + }
  2758. + }
  2759. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2760. + free(lists_dir);
  2761. + free(pending_dir);
  2762. +
  2763. + return 0;
  2764. +}
  2765. +
  2766. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2767. +{
  2768. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2769. +#error
  2770. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2771. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2772. + __FUNCTION__, conf->tmp_dir);
  2773. +#else
  2774. + int err;
  2775. +
  2776. + err = rmdir(conf->tmp_dir);
  2777. + if (err) {
  2778. + if (errno == ENOTEMPTY) {
  2779. + char *cmd;
  2780. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2781. + err = xsystem(cmd);
  2782. + free(cmd);
  2783. + }
  2784. + if (err)
  2785. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2786. + }
  2787. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2788. +
  2789. + free(conf->tmp_dir); /*XXX*/
  2790. +
  2791. + pkg_src_list_deinit(&conf->pkg_src_list);
  2792. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2793. + nv_pair_list_deinit(&conf->arch_list);
  2794. + if (&conf->pkg_hash)
  2795. + pkg_hash_deinit(&conf->pkg_hash);
  2796. + if (&conf->file_hash)
  2797. + hash_table_deinit(&conf->file_hash);
  2798. + if (&conf->obs_file_hash)
  2799. + hash_table_deinit(&conf->obs_file_hash);
  2800. +
  2801. + ipkg_conf_free_string(&conf->offline_root);
  2802. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2803. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2804. +
  2805. + if (conf->verbosity > 1) {
  2806. + int i;
  2807. + hash_table_t *hashes[] = {
  2808. + &conf->pkg_hash,
  2809. + &conf->file_hash,
  2810. + &conf->obs_file_hash };
  2811. + for (i = 0; i < 3; i++) {
  2812. + hash_table_t *hash = hashes[i];
  2813. + int c = 0;
  2814. + int n_conflicts = 0;
  2815. + int j;
  2816. + for (j = 0; j < hash->n_entries; j++) {
  2817. + int len = 0;
  2818. + hash_entry_t *e = &hash->entries[j];
  2819. + if (e->next)
  2820. + n_conflicts++;
  2821. + while (e && e->key) {
  2822. + len++;
  2823. + e = e->next;
  2824. + }
  2825. + if (len > c)
  2826. + c = len;
  2827. + }
  2828. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2829. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2830. + hash_table_deinit(hash);
  2831. + }
  2832. + }
  2833. +}
  2834. +
  2835. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2836. + const char *default_dest_name)
  2837. +{
  2838. + pkg_dest_list_elt_t *iter;
  2839. + pkg_dest_t *dest;
  2840. +
  2841. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2842. + dest = iter->data;
  2843. + if (strcmp(dest->name, default_dest_name) == 0) {
  2844. + conf->default_dest = dest;
  2845. + conf->restrict_to_default_dest = 1;
  2846. + return 0;
  2847. + }
  2848. + }
  2849. +
  2850. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2851. +
  2852. + return 1;
  2853. +}
  2854. +
  2855. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2856. +{
  2857. + pkg_src_list_elt_t *iter;
  2858. + pkg_src_t *src;
  2859. + char *list_file;
  2860. +
  2861. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2862. + src = iter->data;
  2863. + if (src == NULL) {
  2864. + continue;
  2865. + }
  2866. +
  2867. + sprintf_alloc(&list_file, "%s/%s",
  2868. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2869. + src->name);
  2870. +
  2871. + if (file_exists(list_file)) {
  2872. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2873. + }
  2874. + free(list_file);
  2875. + }
  2876. +
  2877. + return 0;
  2878. +}
  2879. +
  2880. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2881. +{
  2882. + nv_pair_list_elt_t *iter;
  2883. + nv_pair_t *nv_pair;
  2884. + pkg_dest_t *dest;
  2885. + char *root_dir;
  2886. +
  2887. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2888. + nv_pair = iter->data;
  2889. +
  2890. + if (conf->offline_root) {
  2891. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2892. + } else {
  2893. + root_dir = strdup(nv_pair->value);
  2894. + }
  2895. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2896. + free(root_dir);
  2897. + if (dest == NULL) {
  2898. + continue;
  2899. + }
  2900. + if (conf->default_dest == NULL) {
  2901. + conf->default_dest = dest;
  2902. + }
  2903. + if (file_exists(dest->status_file_name)) {
  2904. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2905. + NULL, dest, 1);
  2906. + }
  2907. + }
  2908. +
  2909. + return 0;
  2910. +}
  2911. +
  2912. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2913. + pkg_src_list_t *pkg_src_list,
  2914. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2915. + char **lists_dir)
  2916. +{
  2917. + ipkg_option_t * options;
  2918. + FILE *file = fopen(filename, "r");
  2919. + regex_t valid_line_re, comment_re;
  2920. +#define regmatch_size 12
  2921. + regmatch_t regmatch[regmatch_size];
  2922. +
  2923. + if (ipkg_init_options_array(conf, &options)<0)
  2924. + return ENOMEM;
  2925. +
  2926. + if (file == NULL) {
  2927. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2928. + __FUNCTION__, filename, strerror(errno));
  2929. + free(options);
  2930. + return errno;
  2931. + }
  2932. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2933. +
  2934. + xregcomp(&comment_re,
  2935. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2936. + REG_EXTENDED);
  2937. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2938. +
  2939. + while(1) {
  2940. + int line_num = 0;
  2941. + char *line;
  2942. + char *type, *name, *value, *extra;
  2943. +
  2944. + line = file_read_line_alloc(file);
  2945. + line_num++;
  2946. + if (line == NULL) {
  2947. + break;
  2948. + }
  2949. +
  2950. + str_chomp(line);
  2951. +
  2952. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2953. + goto NEXT_LINE;
  2954. + }
  2955. +
  2956. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2957. + str_chomp(line);
  2958. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2959. + filename, line_num, line);
  2960. + goto NEXT_LINE;
  2961. + }
  2962. +
  2963. + /* This has to be so ugly to deal with optional quotation marks */
  2964. + if (regmatch[2].rm_so > 0) {
  2965. + type = strndup(line + regmatch[2].rm_so,
  2966. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2967. + } else {
  2968. + type = strndup(line + regmatch[3].rm_so,
  2969. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2970. + }
  2971. + if (regmatch[5].rm_so > 0) {
  2972. + name = strndup(line + regmatch[5].rm_so,
  2973. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2974. + } else {
  2975. + name = strndup(line + regmatch[6].rm_so,
  2976. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2977. + }
  2978. + if (regmatch[8].rm_so > 0) {
  2979. + value = strndup(line + regmatch[8].rm_so,
  2980. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2981. + } else {
  2982. + value = strndup(line + regmatch[9].rm_so,
  2983. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2984. + }
  2985. + extra = NULL;
  2986. + if (regmatch[11].rm_so > 0) {
  2987. + extra = strndup (line + regmatch[11].rm_so,
  2988. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2989. + }
  2990. +
  2991. + /* We use the tmp_dest_nv_pair_list below instead of
  2992. + conf->pkg_dest_list because we might encounter an
  2993. + offline_root option later and that would invalidate the
  2994. + directories we would have computed in
  2995. + pkg_dest_list_init. (We do a similar thing with
  2996. + tmp_src_nv_pair_list for sake of symmetry.) */
  2997. + if (strcmp(type, "option") == 0) {
  2998. + ipkg_conf_set_option(options, name, value);
  2999. + } else if (strcmp(type, "src") == 0) {
  3000. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3001. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3002. + } else {
  3003. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3004. + name, value);
  3005. + }
  3006. + } else if (strcmp(type, "src/gz") == 0) {
  3007. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3008. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3009. + } else {
  3010. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3011. + name, value);
  3012. + }
  3013. + } else if (strcmp(type, "dest") == 0) {
  3014. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3015. + } else if (strcmp(type, "lists_dir") == 0) {
  3016. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3017. + if (*lists_dir == NULL) {
  3018. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3019. + free(options);
  3020. + return EINVAL;
  3021. + }
  3022. + sprintf (*lists_dir,"%s",value);
  3023. + } else if (strcmp(type, "arch") == 0) {
  3024. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3025. + if (!value) {
  3026. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3027. + value = strdup("10");
  3028. + }
  3029. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3030. + } else {
  3031. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3032. + "parameter: %s %s %s\n", type, name, value);
  3033. + free(options);
  3034. + return EINVAL;
  3035. + }
  3036. +
  3037. + free(type);
  3038. + free(name);
  3039. + free(value);
  3040. + if (extra)
  3041. + free (extra);
  3042. +
  3043. + NEXT_LINE:
  3044. + free(line);
  3045. + }
  3046. +
  3047. + free(options);
  3048. + regfree(&comment_re);
  3049. + regfree(&valid_line_re);
  3050. + fclose(file);
  3051. +
  3052. + return 0;
  3053. +}
  3054. +
  3055. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3056. + const char *name, const char *value)
  3057. +{
  3058. + int i = 0;
  3059. + while (options[i].name) {
  3060. + if (strcmp(options[i].name, name) == 0) {
  3061. + switch (options[i].type) {
  3062. + case IPKG_OPT_TYPE_BOOL:
  3063. + *((int *)options[i].value) = 1;
  3064. + return 0;
  3065. + case IPKG_OPT_TYPE_INT:
  3066. + if (value) {
  3067. + *((int *)options[i].value) = atoi(value);
  3068. + return 0;
  3069. + } else {
  3070. + printf("%s: Option %s need an argument\n",
  3071. + __FUNCTION__, name);
  3072. + return EINVAL;
  3073. + }
  3074. + case IPKG_OPT_TYPE_STRING:
  3075. + if (value) {
  3076. + *((char **)options[i].value) = strdup(value);
  3077. + return 0;
  3078. + } else {
  3079. + printf("%s: Option %s need an argument\n",
  3080. + __FUNCTION__, name);
  3081. + return EINVAL;
  3082. + }
  3083. + }
  3084. + }
  3085. + i++;
  3086. + }
  3087. +
  3088. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3089. + __FUNCTION__, name, value);
  3090. + return EINVAL;
  3091. +}
  3092. +
  3093. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3094. +{
  3095. + pkg_dest_list_elt_t *iter;
  3096. + pkg_dest_t *dest;
  3097. + pkg_vec_t *all;
  3098. + pkg_t *pkg;
  3099. + register int i;
  3100. + int err;
  3101. +
  3102. + if (conf->noaction)
  3103. + return 0;
  3104. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3105. + dest = iter->data;
  3106. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3107. + if (dest->status_file == NULL) {
  3108. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3109. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3110. + }
  3111. + }
  3112. +
  3113. + all = pkg_vec_alloc();
  3114. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3115. +
  3116. + for(i = 0; i < all->len; i++) {
  3117. + pkg = all->pkgs[i];
  3118. + /* We don't need most uninstalled packages in the status file */
  3119. + if (pkg->state_status == SS_NOT_INSTALLED
  3120. + && (pkg->state_want == SW_UNKNOWN
  3121. + || pkg->state_want == SW_DEINSTALL
  3122. + || pkg->state_want == SW_PURGE)) {
  3123. + continue;
  3124. + }
  3125. + if (!pkg) {
  3126. + fprintf(stderr, "Null package\n");
  3127. + }
  3128. + if (pkg->dest == NULL) {
  3129. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3130. + "package %s since it has a NULL dest\n",
  3131. + __FUNCTION__, pkg->name);
  3132. + continue;
  3133. + }
  3134. + if (pkg->dest->status_file) {
  3135. + pkg_print_status(pkg, pkg->dest->status_file);
  3136. + }
  3137. + }
  3138. +
  3139. + pkg_vec_free(all);
  3140. +
  3141. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3142. + dest = iter->data;
  3143. + if (dest->status_file) {
  3144. + err = ferror(dest->status_file);
  3145. + fclose(dest->status_file);
  3146. + dest->status_file = NULL;
  3147. + if (!err) {
  3148. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3149. + } else {
  3150. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3151. + "retaining old %s\n", __FUNCTION__,
  3152. + dest->status_file_tmp_name, dest->status_file_name);
  3153. + }
  3154. + }
  3155. + }
  3156. +
  3157. + return 0;
  3158. +}
  3159. +
  3160. +
  3161. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3162. +{
  3163. + char *root_filename;
  3164. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3165. + return root_filename;
  3166. +}
  3167. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_conf.h busybox-1.23.0/archival/libipkg/ipkg_conf.h
  3168. --- busybox-1.23.0.orig/archival/libipkg/ipkg_conf.h 1969-12-31 18:00:00.000000000 -0600
  3169. +++ busybox-1.23.0/archival/libipkg/ipkg_conf.h 2015-01-09 11:18:22.424197243 -0600
  3170. @@ -0,0 +1,107 @@
  3171. +/* ipkg_conf.h - the itsy package management system
  3172. +
  3173. + Carl D. Worth
  3174. +
  3175. + Copyright (C) 2001 University of Southern California
  3176. +
  3177. + This program is free software; you can redistribute it and/or
  3178. + modify it under the terms of the GNU General Public License as
  3179. + published by the Free Software Foundation; either version 2, or (at
  3180. + your option) any later version.
  3181. +
  3182. + This program is distributed in the hope that it will be useful, but
  3183. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3184. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3185. + General Public License for more details.
  3186. +*/
  3187. +
  3188. +#ifndef IPKG_CONF_H
  3189. +#define IPKG_CONF_H
  3190. +
  3191. +typedef struct ipkg_conf ipkg_conf_t;
  3192. +
  3193. +#include "hash_table.h"
  3194. +#include "ipkg.h"
  3195. +#include "args.h"
  3196. +#include "pkg.h"
  3197. +#include "pkg_hash.h"
  3198. +#include "pkg_src_list.h"
  3199. +#include "pkg_dest_list.h"
  3200. +#include "nv_pair_list.h"
  3201. +
  3202. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3203. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3204. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3205. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3206. +
  3207. +/* In case the config file defines no dest */
  3208. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3209. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3210. +
  3211. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3212. +
  3213. +struct ipkg_conf
  3214. +{
  3215. + pkg_src_list_t pkg_src_list;
  3216. + pkg_dest_list_t pkg_dest_list;
  3217. + nv_pair_list_t arch_list;
  3218. +
  3219. + int restrict_to_default_dest;
  3220. + pkg_dest_t *default_dest;
  3221. +
  3222. + char *tmp_dir;
  3223. + char *lists_dir;
  3224. + char *pending_dir;
  3225. +
  3226. + /* options */
  3227. + int force_depends;
  3228. + int force_defaults;
  3229. + int force_overwrite;
  3230. + int force_downgrade;
  3231. + int force_reinstall;
  3232. + int force_space;
  3233. + int force_removal_of_dependent_packages;
  3234. + int force_removal_of_essential_packages;
  3235. + int nodeps; /* do not follow dependences */
  3236. + int verbose_wget;
  3237. + int multiple_providers;
  3238. + char *offline_root;
  3239. + char *offline_root_pre_script_cmd;
  3240. + char *offline_root_post_script_cmd;
  3241. + int query_all;
  3242. + int verbosity;
  3243. + int noaction;
  3244. +
  3245. + /* proxy options */
  3246. + char *http_proxy;
  3247. + char *ftp_proxy;
  3248. + char *no_proxy;
  3249. + char *proxy_user;
  3250. + char *proxy_passwd;
  3251. +
  3252. + hash_table_t pkg_hash;
  3253. + hash_table_t file_hash;
  3254. + hash_table_t obs_file_hash;
  3255. +};
  3256. +
  3257. +enum ipkg_option_type {
  3258. + IPKG_OPT_TYPE_BOOL,
  3259. + IPKG_OPT_TYPE_INT,
  3260. + IPKG_OPT_TYPE_STRING
  3261. +};
  3262. +typedef enum ipkg_option_type ipkg_option_type_t;
  3263. +
  3264. +typedef struct ipkg_option ipkg_option_t;
  3265. +struct ipkg_option {
  3266. + const char *name;
  3267. + const ipkg_option_type_t type;
  3268. + const void *value;
  3269. +};
  3270. +
  3271. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3272. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3273. +
  3274. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3275. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3276. +
  3277. +#endif
  3278. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_configure.c busybox-1.23.0/archival/libipkg/ipkg_configure.c
  3279. --- busybox-1.23.0.orig/archival/libipkg/ipkg_configure.c 1969-12-31 18:00:00.000000000 -0600
  3280. +++ busybox-1.23.0/archival/libipkg/ipkg_configure.c 2015-01-09 11:18:22.424197243 -0600
  3281. @@ -0,0 +1,40 @@
  3282. +/* ipkg_configure.c - the itsy package management system
  3283. +
  3284. + Carl D. Worth
  3285. +
  3286. + Copyright (C) 2001 University of Southern California
  3287. +
  3288. + This program is free software; you can redistribute it and/or
  3289. + modify it under the terms of the GNU General Public License as
  3290. + published by the Free Software Foundation; either version 2, or (at
  3291. + your option) any later version.
  3292. +
  3293. + This program is distributed in the hope that it will be useful, but
  3294. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3295. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3296. + General Public License for more details.
  3297. +*/
  3298. +
  3299. +#include "ipkg.h"
  3300. +
  3301. +#include "ipkg_configure.h"
  3302. +
  3303. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3304. +{
  3305. + int err;
  3306. +
  3307. + /* DPKG_INCOMPATIBILITY:
  3308. + dpkg actually does some conffile handling here, rather than at the
  3309. + end of ipkg_install(). Do we care? */
  3310. + /* DPKG_INCOMPATIBILITY:
  3311. + dpkg actually includes a version number to this script call */
  3312. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3313. + if (err) {
  3314. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3315. + return err;
  3316. + }
  3317. +
  3318. + ipkg_state_changed++;
  3319. + return 0;
  3320. +}
  3321. +
  3322. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_configure.h busybox-1.23.0/archival/libipkg/ipkg_configure.h
  3323. --- busybox-1.23.0.orig/archival/libipkg/ipkg_configure.h 1969-12-31 18:00:00.000000000 -0600
  3324. +++ busybox-1.23.0/archival/libipkg/ipkg_configure.h 2015-01-09 11:18:22.424197243 -0600
  3325. @@ -0,0 +1,25 @@
  3326. +/* ipkg_configure.h - the itsy package management system
  3327. +
  3328. + Carl D. Worth
  3329. +
  3330. + Copyright (C) 2001 University of Southern California
  3331. +
  3332. + This program is free software; you can redistribute it and/or
  3333. + modify it under the terms of the GNU General Public License as
  3334. + published by the Free Software Foundation; either version 2, or (at
  3335. + your option) any later version.
  3336. +
  3337. + This program is distributed in the hope that it will be useful, but
  3338. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3339. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3340. + General Public License for more details.
  3341. +*/
  3342. +
  3343. +#ifndef IPKG_CONFIGURE_H
  3344. +#define IPKG_CONFIGURE_H
  3345. +
  3346. +#include "ipkg_conf.h"
  3347. +
  3348. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3349. +
  3350. +#endif
  3351. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_download.c busybox-1.23.0/archival/libipkg/ipkg_download.c
  3352. --- busybox-1.23.0.orig/archival/libipkg/ipkg_download.c 1969-12-31 18:00:00.000000000 -0600
  3353. +++ busybox-1.23.0/archival/libipkg/ipkg_download.c 2015-01-09 11:18:22.424197243 -0600
  3354. @@ -0,0 +1,195 @@
  3355. +/* ipkg_download.c - the itsy package management system
  3356. +
  3357. + Carl D. Worth
  3358. +
  3359. + Copyright (C) 2001 University of Southern California
  3360. +
  3361. + This program is free software; you can redistribute it and/or
  3362. + modify it under the terms of the GNU General Public License as
  3363. + published by the Free Software Foundation; either version 2, or (at
  3364. + your option) any later version.
  3365. +
  3366. + This program is distributed in the hope that it will be useful, but
  3367. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3368. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3369. + General Public License for more details.
  3370. +*/
  3371. +
  3372. +#include "ipkg.h"
  3373. +#include "ipkg_download.h"
  3374. +#include "ipkg_message.h"
  3375. +
  3376. +#include "sprintf_alloc.h"
  3377. +#include "xsystem.h"
  3378. +#include "file_util.h"
  3379. +#include "str_util.h"
  3380. +
  3381. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3382. +{
  3383. + int err = 0;
  3384. +
  3385. + char *src_basec = strdup(src);
  3386. + char *src_base = bb_basename(src_basec);
  3387. + char *tmp_file_location;
  3388. + char *cmd;
  3389. +
  3390. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3391. +
  3392. + fflush(stdout);
  3393. +
  3394. + if (str_starts_with(src, "file:")) {
  3395. + int ret;
  3396. + const char *file_src = src + 5;
  3397. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3398. + ret = file_copy(src + 5, dest_file_name);
  3399. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3400. + return ret;
  3401. + }
  3402. +
  3403. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3404. + err = unlink(tmp_file_location);
  3405. + if (err && errno != ENOENT) {
  3406. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3407. + __FUNCTION__, tmp_file_location, strerror(errno));
  3408. + free(tmp_file_location);
  3409. + return errno;
  3410. + }
  3411. +
  3412. + if (conf->http_proxy) {
  3413. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3414. + setenv("http_proxy", conf->http_proxy, 1);
  3415. + }
  3416. + if (conf->ftp_proxy) {
  3417. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3418. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3419. + }
  3420. + if (conf->no_proxy) {
  3421. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3422. + setenv("no_proxy", conf->no_proxy, 1);
  3423. + }
  3424. +
  3425. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3426. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3427. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3428. + conf->proxy_user ? "--proxy-user=" : "",
  3429. + conf->proxy_user ? conf->proxy_user : "",
  3430. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3431. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3432. + conf->verbose_wget ? "" : "-q",
  3433. + conf->tmp_dir,
  3434. + src);
  3435. + err = xsystem(cmd);
  3436. + if (err) {
  3437. + if (err != -1) {
  3438. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3439. + __FUNCTION__, err, cmd);
  3440. + }
  3441. + unlink(tmp_file_location);
  3442. + free(tmp_file_location);
  3443. + free(src_basec);
  3444. + free(cmd);
  3445. + return EINVAL;
  3446. + }
  3447. + free(cmd);
  3448. +
  3449. + err = file_move(tmp_file_location, dest_file_name);
  3450. +
  3451. + free(tmp_file_location);
  3452. + free(src_basec);
  3453. +
  3454. + if (err) {
  3455. + return err;
  3456. + }
  3457. +
  3458. + return 0;
  3459. +}
  3460. +
  3461. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3462. +{
  3463. + int err;
  3464. + char *url;
  3465. +
  3466. + if (pkg->src == NULL) {
  3467. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3468. + pkg->name, pkg->parent->name);
  3469. + return -1;
  3470. + }
  3471. +
  3472. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3473. +
  3474. + /* XXX: BUG: The pkg->filename might be something like
  3475. + "../../foo.ipk". While this is correct, and exactly what we
  3476. + want to use to construct url above, here we actually need to
  3477. + use just the filename part, without any directory. */
  3478. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3479. +
  3480. + err = ipkg_download(conf, url, pkg->local_filename);
  3481. + free(url);
  3482. +
  3483. + return err;
  3484. +}
  3485. +
  3486. +/*
  3487. + * Downloads file from url, installs in package database, return package name.
  3488. + */
  3489. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3490. +{
  3491. + int err = 0;
  3492. + pkg_t *pkg;
  3493. + pkg = pkg_new();
  3494. + if (pkg == NULL)
  3495. + return ENOMEM;
  3496. +
  3497. + if (str_starts_with(url, "http://")
  3498. + || str_starts_with(url, "ftp://")) {
  3499. + char *tmp_file;
  3500. + char *file_basec = strdup(url);
  3501. + char *file_base = bb_basename(file_basec);
  3502. +
  3503. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3504. + err = ipkg_download(conf, url, tmp_file);
  3505. + if (err)
  3506. + return err;
  3507. +
  3508. + err = pkg_init_from_file(pkg, tmp_file);
  3509. + if (err)
  3510. + return err;
  3511. + pkg->local_filename = strdup(tmp_file);
  3512. +
  3513. + free(tmp_file);
  3514. + free(file_basec);
  3515. +
  3516. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3517. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3518. +
  3519. + err = pkg_init_from_file(pkg, url);
  3520. + if (err)
  3521. + return err;
  3522. + pkg->local_filename = strdup(url);
  3523. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3524. + pkg->provided_by_hand = 1;
  3525. +
  3526. + } else {
  3527. + pkg_deinit(pkg);
  3528. + free(pkg);
  3529. + return 0;
  3530. + }
  3531. +
  3532. + if (!pkg->architecture) {
  3533. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3534. + return -EINVAL;
  3535. + }
  3536. +
  3537. + pkg->dest = conf->default_dest;
  3538. + pkg->state_want = SW_INSTALL;
  3539. + pkg->state_flag |= SF_PREFER;
  3540. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3541. + if ( pkg == NULL ){
  3542. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3543. + return 0;
  3544. + }
  3545. + if (namep) {
  3546. + *namep = strdup(pkg->name);
  3547. + }
  3548. + return 0;
  3549. +}
  3550. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_download.h busybox-1.23.0/archival/libipkg/ipkg_download.h
  3551. --- busybox-1.23.0.orig/archival/libipkg/ipkg_download.h 1969-12-31 18:00:00.000000000 -0600
  3552. +++ busybox-1.23.0/archival/libipkg/ipkg_download.h 2015-01-09 11:18:22.424197243 -0600
  3553. @@ -0,0 +1,30 @@
  3554. +/* ipkg_download.h - the itsy package management system
  3555. +
  3556. + Carl D. Worth
  3557. +
  3558. + Copyright (C) 2001 University of Southern California
  3559. +
  3560. + This program is free software; you can redistribute it and/or
  3561. + modify it under the terms of the GNU General Public License as
  3562. + published by the Free Software Foundation; either version 2, or (at
  3563. + your option) any later version.
  3564. +
  3565. + This program is distributed in the hope that it will be useful, but
  3566. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3567. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3568. + General Public License for more details.
  3569. +*/
  3570. +
  3571. +#ifndef IPKG_DOWNLOAD_H
  3572. +#define IPKG_DOWNLOAD_H
  3573. +
  3574. +#include "ipkg_conf.h"
  3575. +
  3576. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3577. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3578. +/*
  3579. + * Downloads file from url, installs in package database, return package name.
  3580. + */
  3581. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3582. +
  3583. +#endif
  3584. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg.h busybox-1.23.0/archival/libipkg/ipkg.h
  3585. --- busybox-1.23.0.orig/archival/libipkg/ipkg.h 1969-12-31 18:00:00.000000000 -0600
  3586. +++ busybox-1.23.0/archival/libipkg/ipkg.h 2015-01-09 11:18:22.424197243 -0600
  3587. @@ -0,0 +1,68 @@
  3588. +/* ipkg.h - the itsy package management system
  3589. +
  3590. + Carl D. Worth
  3591. +
  3592. + Copyright (C) 2001 University of Southern California
  3593. +
  3594. + This program is free software; you can redistribute it and/or
  3595. + modify it under the terms of the GNU General Public License as
  3596. + published by the Free Software Foundation; either version 2, or (at
  3597. + your option) any later version.
  3598. +
  3599. + This program is distributed in the hope that it will be useful, but
  3600. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3601. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3602. + General Public License for more details.
  3603. +*/
  3604. +
  3605. +#ifndef IPKG_H
  3606. +#define IPKG_H
  3607. +
  3608. +#include "libbb.h"
  3609. +
  3610. +#include "ipkg_includes.h"
  3611. +#include "ipkg_conf.h"
  3612. +#include "ipkg_message.h"
  3613. +
  3614. +#define IPKG_PKG_EXTENSION ".ipk"
  3615. +#define DPKG_PKG_EXTENSION ".deb"
  3616. +
  3617. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3618. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3619. +
  3620. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3621. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3622. +#define IPKG_INFO_DIR_SUFFIX "info"
  3623. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3624. +
  3625. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3626. +
  3627. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3628. +
  3629. +#define IPKG_VERSION "1.00"
  3630. +
  3631. +
  3632. +enum ipkg_error {
  3633. + IPKG_SUCCESS = 0,
  3634. + IPKG_PKG_DEPS_UNSATISFIED,
  3635. + IPKG_PKG_IS_ESSENTIAL,
  3636. + IPKG_PKG_HAS_DEPENDENTS,
  3637. + IPKG_PKG_HAS_NO_CANDIDATE
  3638. +};
  3639. +typedef enum ipkg_error ipkg_error_t;
  3640. +
  3641. +extern int ipkg_state_changed;
  3642. +
  3643. +
  3644. +struct errlist {
  3645. + char * errmsg;
  3646. + struct errlist * next;
  3647. +} ;
  3648. +
  3649. +extern struct errlist* error_list;
  3650. +
  3651. +extern ipkg_conf_t *global_conf;
  3652. +
  3653. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3654. +
  3655. +#endif
  3656. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_includes.h busybox-1.23.0/archival/libipkg/ipkg_includes.h
  3657. --- busybox-1.23.0.orig/archival/libipkg/ipkg_includes.h 1969-12-31 18:00:00.000000000 -0600
  3658. +++ busybox-1.23.0/archival/libipkg/ipkg_includes.h 2015-01-09 11:18:22.424197243 -0600
  3659. @@ -0,0 +1,82 @@
  3660. +#ifndef IPKG_INCLUDES_H
  3661. +#define IPKG_INCLUDES_H
  3662. +
  3663. +/* Define to 1 if you have the <memory.h> header file. */
  3664. +#define HAVE_MEMORY_H 1
  3665. +
  3666. +/* Define to 1 if you have the <regex.h> header file. */
  3667. +#define HAVE_REGEX_H 1
  3668. +
  3669. +/* Define to 1 if you have the <stdlib.h> header file. */
  3670. +#define HAVE_STDLIB_H 1
  3671. +
  3672. +/* Define to 1 if you have the <strings.h> header file. */
  3673. +#define HAVE_STRINGS_H 1
  3674. +
  3675. +/* Define to 1 if you have the <string.h> header file. */
  3676. +#define HAVE_STRING_H 1
  3677. +
  3678. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3679. +#define HAVE_SYS_STAT_H 1
  3680. +
  3681. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3682. +#define HAVE_SYS_WAIT_H 1
  3683. +
  3684. +/* Define to 1 if you have the <unistd.h> header file. */
  3685. +#define HAVE_UNISTD_H 1
  3686. +
  3687. +/* Define to 1 if you have the ANSI C header files. */
  3688. +#define STDC_HEADERS 1
  3689. +
  3690. +
  3691. +#include <stdio.h>
  3692. +
  3693. +#if STDC_HEADERS
  3694. +# include <stdlib.h>
  3695. +# include <stdarg.h>
  3696. +# include <stddef.h>
  3697. +# include <ctype.h>
  3698. +# include <errno.h>
  3699. +#else
  3700. +# if HAVE_STDLIB_H
  3701. +# include <stdlib.h>
  3702. +# endif
  3703. +#endif
  3704. +
  3705. +#if HAVE_REGEX_H
  3706. +# include <regex.h>
  3707. +#endif
  3708. +
  3709. +#if HAVE_STRING_H
  3710. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3711. +# include <memory.h>
  3712. +# endif
  3713. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3714. +# if __GNUC__
  3715. +# define __USE_GNU 1
  3716. +# endif
  3717. +# include <string.h>
  3718. +# undef __USE_GNU
  3719. +#endif
  3720. +
  3721. +#if HAVE_STRINGS_H
  3722. +# include <strings.h>
  3723. +#endif
  3724. +
  3725. +#if HAVE_SYS_STAT_H
  3726. +# include <sys/stat.h>
  3727. +#endif
  3728. +
  3729. +#if HAVE_SYS_WAIT_H
  3730. +# include <sys/wait.h>
  3731. +#endif
  3732. +
  3733. +#if HAVE_UNISTD_H
  3734. +# include <sys/types.h>
  3735. +# include <unistd.h>
  3736. +#endif
  3737. +
  3738. +#include <sys/mount.h>
  3739. +#include <mntent.h>
  3740. +
  3741. +#endif /* IPKG_INCLUDES_H */
  3742. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_install.c busybox-1.23.0/archival/libipkg/ipkg_install.c
  3743. --- busybox-1.23.0.orig/archival/libipkg/ipkg_install.c 1969-12-31 18:00:00.000000000 -0600
  3744. +++ busybox-1.23.0/archival/libipkg/ipkg_install.c 2015-01-09 11:18:22.428197243 -0600
  3745. @@ -0,0 +1,1982 @@
  3746. +/* ipkg_install.c - the itsy package management system
  3747. +
  3748. + Carl D. Worth
  3749. +
  3750. + Copyright (C) 2001 University of Southern California
  3751. +
  3752. + This program is free software; you can redistribute it and/or
  3753. + modify it under the terms of the GNU General Public License as
  3754. + published by the Free Software Foundation; either version 2, or (at
  3755. + your option) any later version.
  3756. +
  3757. + This program is distributed in the hope that it will be useful, but
  3758. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3759. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3760. + General Public License for more details.
  3761. +*/
  3762. +
  3763. +#include "ipkg.h"
  3764. +#include <errno.h>
  3765. +#include <dirent.h>
  3766. +#include <glob.h>
  3767. +#include <time.h>
  3768. +#include <signal.h>
  3769. +typedef void (*sighandler_t)(int);
  3770. +
  3771. +#include "pkg.h"
  3772. +#include "pkg_hash.h"
  3773. +#include "pkg_extract.h"
  3774. +
  3775. +#include "ipkg_install.h"
  3776. +#include "ipkg_configure.h"
  3777. +#include "ipkg_download.h"
  3778. +#include "ipkg_remove.h"
  3779. +
  3780. +#include "ipkg_utils.h"
  3781. +#include "ipkg_message.h"
  3782. +
  3783. +#include "sprintf_alloc.h"
  3784. +#include "file_util.h"
  3785. +#include "str_util.h"
  3786. +#include "xsystem.h"
  3787. +#include "user.h"
  3788. +
  3789. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3790. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3791. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3792. +
  3793. +/*
  3794. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3795. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3796. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3797. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3798. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3799. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3800. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3802. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3803. +*/
  3804. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3805. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3806. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3807. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3808. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3809. +
  3810. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3811. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3812. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3813. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3814. +
  3815. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3816. +
  3817. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3818. +
  3819. +static char *backup_filename_alloc(const char *file_name);
  3820. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3821. +static int backup_exists_for(const char *file_name);
  3822. +static int backup_remove(const char *file_name);
  3823. +
  3824. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3825. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3826. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3827. +
  3828. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3829. +{
  3830. + int err, cmp;
  3831. + pkg_t *pkg, *old;
  3832. + char *old_version, *new_version;
  3833. +
  3834. + pkg = pkg_new();
  3835. + if (pkg == NULL) {
  3836. + return ENOMEM;
  3837. + }
  3838. +
  3839. + err = pkg_init_from_file(pkg, filename);
  3840. + if (err) {
  3841. + return err;
  3842. + }
  3843. +
  3844. + if (!pkg->architecture) {
  3845. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3846. + return -EINVAL;
  3847. + }
  3848. +
  3849. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3850. + freeing the pkg that we pass in. It might be nice to clean this up
  3851. + if possible. */
  3852. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3853. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3854. +
  3855. + pkg->local_filename = strdup(filename);
  3856. +
  3857. + if (old) {
  3858. + old_version = pkg_version_str_alloc(old);
  3859. + new_version = pkg_version_str_alloc(pkg);
  3860. +
  3861. + cmp = pkg_compare_versions(old, pkg);
  3862. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3863. + cmp = -1 ; /* then we force ipkg to downgrade */
  3864. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3865. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3866. + }
  3867. + if (cmp > 0) {
  3868. + ipkg_message(conf, IPKG_NOTICE,
  3869. + "Not downgrading package %s on %s from %s to %s.\n",
  3870. + old->name, old->dest->name, old_version, new_version);
  3871. + pkg->state_want = SW_DEINSTALL;
  3872. + pkg->state_flag |= SF_OBSOLETE;
  3873. + free(old_version);
  3874. + free(new_version);
  3875. + return 0;
  3876. + } else {
  3877. + free(old_version);
  3878. + free(new_version);
  3879. + }
  3880. + }
  3881. +
  3882. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3883. + return ipkg_install_pkg(conf, pkg,0);
  3884. +}
  3885. +
  3886. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3887. +{
  3888. + int cmp;
  3889. + pkg_t *old, *new;
  3890. + char *old_version, *new_version;
  3891. +
  3892. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3893. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3894. + if ( old )
  3895. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3896. +
  3897. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3898. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3899. + if ( new )
  3900. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3901. +
  3902. +/* Pigi Basically here is broken the version stuff.
  3903. + What's happening is that nothing provide the version to differents
  3904. + functions, so the returned struct is always the latest.
  3905. + That's why the install by name don't work.
  3906. +*/
  3907. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3908. +
  3909. + if ( old )
  3910. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3911. + if ( new )
  3912. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3913. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3914. +
  3915. + if (new == NULL) {
  3916. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3917. + }
  3918. +
  3919. + new->state_flag |= SF_USER;
  3920. + if (old) {
  3921. + old_version = pkg_version_str_alloc(old);
  3922. + new_version = pkg_version_str_alloc(new);
  3923. +
  3924. + cmp = pkg_compare_versions(old, new);
  3925. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3926. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3927. + cmp = -1 ; /* then we force ipkg to downgrade */
  3928. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3929. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3930. + }
  3931. + ipkg_message(conf, IPKG_DEBUG,
  3932. + "Comparing visible versions of pkg %s:"
  3933. + "\n\t%s is installed "
  3934. + "\n\t%s is available "
  3935. + "\n\t%d was comparison result\n",
  3936. + pkg_name, old_version, new_version, cmp);
  3937. + if (cmp == 0 && !conf->force_reinstall) {
  3938. + ipkg_message(conf, IPKG_NOTICE,
  3939. + "Package %s (%s) installed in %s is up to date.\n",
  3940. + old->name, old_version, old->dest->name);
  3941. + free(old_version);
  3942. + free(new_version);
  3943. + return 0;
  3944. + } else if (cmp > 0) {
  3945. + ipkg_message(conf, IPKG_NOTICE,
  3946. + "Not downgrading package %s on %s from %s to %s.\n",
  3947. + old->name, old->dest->name, old_version, new_version);
  3948. + free(old_version);
  3949. + free(new_version);
  3950. + return 0;
  3951. + } else if (cmp < 0) {
  3952. + new->dest = old->dest;
  3953. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3954. + }
  3955. + }
  3956. +
  3957. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3958. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3959. + return any kind of integer, (might be errno from a syscall,
  3960. + etc.). This is a real mess and will need to be cleaned up if
  3961. + anyone ever wants to make a nice libipkg. */
  3962. +
  3963. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3964. + return ipkg_install_pkg(conf, new,0);
  3965. +}
  3966. +
  3967. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3968. +{
  3969. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3970. + int i;
  3971. + ipkg_error_t err;
  3972. + abstract_pkg_t *ppkg ;
  3973. +
  3974. + if (providers == NULL)
  3975. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3976. +
  3977. + for (i = 0; i < providers->len; i++) {
  3978. + ppkg = abstract_pkg_vec_get(providers, i);
  3979. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3980. + err = ipkg_install_by_name(conf, ppkg->name);
  3981. + if (err)
  3982. + return err;
  3983. +/* XXX Maybe ppkg should be freed ? */
  3984. + }
  3985. + return 0;
  3986. +}
  3987. +
  3988. +/*
  3989. + * Walk dependence graph starting with pkg, collect packages to be
  3990. + * installed into pkgs_needed, in dependence order.
  3991. + */
  3992. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3993. +{
  3994. + int i, err;
  3995. + pkg_vec_t *depends = pkg_vec_alloc();
  3996. + char **unresolved = NULL;
  3997. + int ndepends;
  3998. +
  3999. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4000. + pkg, depends,
  4001. + &unresolved);
  4002. +
  4003. + if (unresolved) {
  4004. + ipkg_message(conf, IPKG_ERROR,
  4005. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4006. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4007. + while (*unresolved) {
  4008. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4009. + unresolved++;
  4010. + }
  4011. + ipkg_message(conf, IPKG_ERROR, "\n");
  4012. + if (! conf->force_depends) {
  4013. + ipkg_message(conf, IPKG_INFO,
  4014. + "This could mean that your package list is out of date or that the packages\n"
  4015. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4016. + "of this problem try again with the '-force-depends' option.\n");
  4017. + pkg_vec_free(depends);
  4018. + return IPKG_PKG_DEPS_UNSATISFIED;
  4019. + }
  4020. + }
  4021. +
  4022. + if (ndepends <= 0) {
  4023. + pkg_vec_free(depends);
  4024. + return 0;
  4025. + }
  4026. +
  4027. + for (i = 0; i < depends->len; i++) {
  4028. + pkg_t *dep = depends->pkgs[i];
  4029. + /* The package was uninstalled when we started, but another
  4030. + dep earlier in this loop may have depended on it and pulled
  4031. + it in, so check first. */
  4032. + if ((dep->state_status != SS_INSTALLED)
  4033. + && (dep->state_status != SS_UNPACKED)
  4034. + && (dep->state_want != SW_INSTALL)) {
  4035. +
  4036. + /* Mark packages as to-be-installed */
  4037. + dep->state_want = SW_INSTALL;
  4038. +
  4039. + /* Dependencies should be installed the same place as pkg */
  4040. + if (dep->dest == NULL) {
  4041. + dep->dest = pkg->dest;
  4042. + }
  4043. +
  4044. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4045. + if (err) {
  4046. + pkg_vec_free(depends);
  4047. + return err;
  4048. + }
  4049. + }
  4050. + }
  4051. + if (pkgs_needed)
  4052. + pkg_vec_insert(pkgs_needed, pkg);
  4053. +
  4054. + pkg_vec_free(depends);
  4055. +
  4056. + return 0;
  4057. +}
  4058. +
  4059. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4060. +{
  4061. + int cmp;
  4062. + pkg_t *old, *new;
  4063. + char *old_version, *new_version;
  4064. +
  4065. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4066. +
  4067. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4068. + if (new == NULL) {
  4069. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4070. + }
  4071. + if (old) {
  4072. + old_version = pkg_version_str_alloc(old);
  4073. + new_version = pkg_version_str_alloc(new);
  4074. +
  4075. + cmp = pkg_compare_versions(old, new);
  4076. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4077. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4078. + cmp = -1 ; /* then we force ipkg to downgrade */
  4079. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4080. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4081. + }
  4082. + ipkg_message(conf, IPKG_DEBUG,
  4083. + "comparing visible versions of pkg %s:"
  4084. + "\n\t%s is installed "
  4085. + "\n\t%s is available "
  4086. + "\n\t%d was comparison result\n",
  4087. + pkg_name, old_version, new_version, cmp);
  4088. + if (cmp == 0 && !conf->force_reinstall) {
  4089. + ipkg_message(conf, IPKG_NOTICE,
  4090. + "Package %s (%s) installed in %s is up to date.\n",
  4091. + old->name, old_version, old->dest->name);
  4092. + free(old_version);
  4093. + free(new_version);
  4094. + return 0;
  4095. + } else if (cmp > 0) {
  4096. + ipkg_message(conf, IPKG_NOTICE,
  4097. + "Not downgrading package %s on %s from %s to %s.\n",
  4098. + old->name, old->dest->name, old_version, new_version);
  4099. + free(old_version);
  4100. + free(new_version);
  4101. + return 0;
  4102. + } else if (cmp < 0) {
  4103. + new->dest = old->dest;
  4104. + old->state_want = SW_DEINSTALL;
  4105. + old->state_flag |= SF_OBSOLETE;
  4106. + }
  4107. + }
  4108. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4109. +}
  4110. +
  4111. +
  4112. +
  4113. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4114. +{
  4115. + int i, err;
  4116. + pkg_vec_t *depends = pkg_vec_alloc();
  4117. + pkg_t *dep;
  4118. + char **unresolved = NULL;
  4119. + int ndepends;
  4120. +
  4121. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4122. + pkg, depends,
  4123. + &unresolved);
  4124. +
  4125. + if (unresolved) {
  4126. + ipkg_message(conf, IPKG_ERROR,
  4127. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4128. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4129. + while (*unresolved) {
  4130. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4131. + unresolved++;
  4132. + }
  4133. + ipkg_message(conf, IPKG_ERROR, "\n");
  4134. + if (! conf->force_depends) {
  4135. + ipkg_message(conf, IPKG_INFO,
  4136. + "This could mean that your package list is out of date or that the packages\n"
  4137. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4138. + "of this problem try again with the '-force-depends' option.\n");
  4139. + pkg_vec_free(depends);
  4140. + return IPKG_PKG_DEPS_UNSATISFIED;
  4141. + }
  4142. + }
  4143. +
  4144. + if (ndepends <= 0) {
  4145. + return 0;
  4146. + }
  4147. +
  4148. + /* Mark packages as to-be-installed */
  4149. + for (i=0; i < depends->len; i++) {
  4150. + /* Dependencies should be installed the same place as pkg */
  4151. + if (depends->pkgs[i]->dest == NULL) {
  4152. + depends->pkgs[i]->dest = pkg->dest;
  4153. + }
  4154. + depends->pkgs[i]->state_want = SW_INSTALL;
  4155. + }
  4156. +
  4157. + for (i = 0; i < depends->len; i++) {
  4158. + dep = depends->pkgs[i];
  4159. + /* The package was uninstalled when we started, but another
  4160. + dep earlier in this loop may have depended on it and pulled
  4161. + it in, so check first. */
  4162. + if ((dep->state_status != SS_INSTALLED)
  4163. + && (dep->state_status != SS_UNPACKED)) {
  4164. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4165. + err = ipkg_install_pkg(conf, dep,0);
  4166. + if (err) {
  4167. + pkg_vec_free(depends);
  4168. + return err;
  4169. + }
  4170. + }
  4171. + }
  4172. +
  4173. + pkg_vec_free(depends);
  4174. +
  4175. + return 0;
  4176. +}
  4177. +
  4178. +
  4179. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4180. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4181. +{
  4182. + if (conf->nodeps == 0) {
  4183. + int i;
  4184. + pkg_vec_t *installed = pkg_vec_alloc();
  4185. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4186. + for (i = 0; i < installed->len; i++) {
  4187. + pkg_t *pkg = installed->pkgs[i];
  4188. + satisfy_dependencies_for(conf, pkg);
  4189. + }
  4190. + pkg_vec_free(installed);
  4191. + }
  4192. + return 0;
  4193. +}
  4194. +
  4195. +
  4196. +
  4197. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4198. +{
  4199. + int i;
  4200. + pkg_vec_t *conflicts = NULL;
  4201. + int level;
  4202. + const char *prefix;
  4203. + if (conf->force_depends) {
  4204. + level = IPKG_NOTICE;
  4205. + prefix = "Warning";
  4206. + } else {
  4207. + level = IPKG_ERROR;
  4208. + prefix = "ERROR";
  4209. + }
  4210. +
  4211. + if (!conf->force_depends)
  4212. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4213. +
  4214. + if (conflicts) {
  4215. + ipkg_message(conf, level,
  4216. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4217. + i = 0;
  4218. + while (i < conflicts->len)
  4219. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4220. + ipkg_message(conf, level, "\n");
  4221. + pkg_vec_free(conflicts);
  4222. + return IPKG_PKG_DEPS_UNSATISFIED;
  4223. + }
  4224. + return 0;
  4225. +}
  4226. +
  4227. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4228. +{
  4229. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4230. + str_list_elt_t *iter;
  4231. +
  4232. + for (iter = new_list->head; iter; iter = iter->next) {
  4233. + char *new_file = iter->data;
  4234. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4235. + if (!new_file)
  4236. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4237. + if (!owner || (owner == old_pkg))
  4238. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4239. + }
  4240. + if (old_pkg) {
  4241. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4242. + for (iter = old_list->head; iter; iter = iter->next) {
  4243. + char *old_file = iter->data;
  4244. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4245. + if (owner == old_pkg) {
  4246. + /* obsolete */
  4247. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4248. + }
  4249. + }
  4250. + }
  4251. + return 0;
  4252. +}
  4253. +
  4254. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4255. +{
  4256. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4257. +
  4258. + /* sma 6.20.02: yup; here's the first bit */
  4259. + /*
  4260. + * XXX: BUG easy for cworth
  4261. + * 1) please point the call below to the correct current root destination
  4262. + * 2) we need to resolve how to check the required space for a pending pkg,
  4263. + * my diddling with the .ipk file size below isn't going to cut it.
  4264. + * 3) return a proper error code instead of 1
  4265. + */
  4266. + int comp_size, blocks_available;
  4267. +
  4268. + if (!conf->force_space && pkg->installed_size != NULL) {
  4269. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4270. +
  4271. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4272. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4273. + comp_size = (int)((comp_size + 1023) / 1024);
  4274. +
  4275. + if (comp_size >= blocks_available) {
  4276. + ipkg_message(conf, IPKG_ERROR,
  4277. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4278. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4279. + return ENOSPC;
  4280. + }
  4281. + }
  4282. + return 0;
  4283. +}
  4284. +
  4285. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4286. +{
  4287. + int err;
  4288. + char *conffiles_file_name;
  4289. + char *root_dir;
  4290. + FILE *conffiles_file;
  4291. +
  4292. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4293. +
  4294. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4295. + if (pkg->tmp_unpack_dir == NULL) {
  4296. + ipkg_message(conf, IPKG_ERROR,
  4297. + "%s: Failed to create temporary directory '%s': %s\n",
  4298. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4299. + return errno;
  4300. + }
  4301. +
  4302. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4303. + if (err) {
  4304. + return err;
  4305. + }
  4306. +
  4307. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4308. + conffiles. Seems like I should be able to get everything to go
  4309. + through pkg_init_from_file. If so, maybe it would make sense to
  4310. + move all of unpack_pkg_control_files to that function. */
  4311. +
  4312. + /* Don't need to re-read conffiles if we already have it */
  4313. + if (pkg->conffiles.head) {
  4314. + return 0;
  4315. + }
  4316. +
  4317. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4318. + if (! file_exists(conffiles_file_name)) {
  4319. + free(conffiles_file_name);
  4320. + return 0;
  4321. + }
  4322. +
  4323. + conffiles_file = fopen(conffiles_file_name, "r");
  4324. + if (conffiles_file == NULL) {
  4325. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4326. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4327. + free(conffiles_file_name);
  4328. + return errno;
  4329. + }
  4330. + free(conffiles_file_name);
  4331. +
  4332. + while (1) {
  4333. + char *cf_name;
  4334. + char *cf_name_in_dest;
  4335. +
  4336. + cf_name = file_read_line_alloc(conffiles_file);
  4337. + if (cf_name == NULL) {
  4338. + break;
  4339. + }
  4340. + str_chomp(cf_name);
  4341. + if (cf_name[0] == '\0') {
  4342. + continue;
  4343. + }
  4344. +
  4345. + /* Prepend dest->root_dir to conffile name.
  4346. + Take pains to avoid multiple slashes. */
  4347. + root_dir = pkg->dest->root_dir;
  4348. + if (conf->offline_root)
  4349. + /* skip the offline_root prefix */
  4350. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4351. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4352. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4353. +
  4354. + /* Can't get an md5sum now, (file isn't extracted yet).
  4355. + We'll wait until resolve_conffiles */
  4356. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4357. +
  4358. + free(cf_name);
  4359. + free(cf_name_in_dest);
  4360. + }
  4361. +
  4362. + fclose(conffiles_file);
  4363. +
  4364. + return 0;
  4365. +}
  4366. +
  4367. +/* returns number of installed replacees */
  4368. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4369. +{
  4370. + abstract_pkg_t **replaces = pkg->replaces;
  4371. + int replaces_count = pkg->replaces_count;
  4372. + int i, j;
  4373. + for (i = 0; i < replaces_count; i++) {
  4374. + abstract_pkg_t *ab_pkg = replaces[i];
  4375. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4376. + if (pkg_vec) {
  4377. + for (j = 0; j < pkg_vec->len; j++) {
  4378. + pkg_t *replacee = pkg_vec->pkgs[j];
  4379. + if (!pkg_conflicts(pkg, replacee))
  4380. + continue;
  4381. + if (replacee->state_status == SS_INSTALLED) {
  4382. + pkg_vec_insert(installed_replacees, replacee);
  4383. + }
  4384. + }
  4385. + }
  4386. + }
  4387. + return installed_replacees->len;
  4388. +}
  4389. +
  4390. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4391. +{
  4392. + int i;
  4393. + int replaces_count = replacees->len;
  4394. + for (i = 0; i < replaces_count; i++) {
  4395. + pkg_t *replacee = replacees->pkgs[i];
  4396. + int err;
  4397. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4398. + err = ipkg_remove_pkg(conf, replacee,0);
  4399. + if (err)
  4400. + return err;
  4401. + }
  4402. + return 0;
  4403. +}
  4404. +
  4405. +/* to unwind the removal: make sure they are installed */
  4406. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4407. +{
  4408. + int i, err;
  4409. + int replaces_count = replacees->len;
  4410. + for (i = 0; i < replaces_count; i++) {
  4411. + pkg_t *replacee = replacees->pkgs[i];
  4412. + if (replacee->state_status != SS_INSTALLED) {
  4413. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4414. + err = ipkg_install_pkg(conf, replacee,0);
  4415. + if (err)
  4416. + return err;
  4417. + }
  4418. + }
  4419. + return 0;
  4420. +}
  4421. +
  4422. +int caught_sigint = 0;
  4423. +static void ipkg_install_pkg_sigint_handler(int sig)
  4424. +{
  4425. + caught_sigint = sig;
  4426. +}
  4427. +
  4428. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4429. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4430. +{
  4431. + if (old_pkg) {
  4432. + char message_out[15];
  4433. + char *old_version = pkg_version_str_alloc(old_pkg);
  4434. + char *new_version = pkg_version_str_alloc(pkg);
  4435. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4436. + int rc = 0;
  4437. +
  4438. + memset(message_out,'\x0',15);
  4439. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4440. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4441. + cmp = -1 ; /* then we force ipkg to downgrade */
  4442. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4443. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4444. + }
  4445. +
  4446. + if (cmp > 0) {
  4447. + ipkg_message(conf, IPKG_NOTICE,
  4448. + "Not downgrading package %s on %s from %s to %s.\n",
  4449. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4450. + rc = 1;
  4451. + } else if (cmp < 0) {
  4452. + ipkg_message(conf, IPKG_NOTICE,
  4453. + "%s%s on %s from %s to %s...\n",
  4454. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4455. + pkg->dest = old_pkg->dest;
  4456. + rc = 0;
  4457. + } else /* cmp == 0 */ {
  4458. + if (conf->force_reinstall) {
  4459. + ipkg_message(conf, IPKG_NOTICE,
  4460. + "Reinstalling %s (%s) on %s...\n",
  4461. + pkg->name, new_version, old_pkg->dest->name);
  4462. + pkg->dest = old_pkg->dest;
  4463. + rc = 0;
  4464. + } else {
  4465. + ipkg_message(conf, IPKG_NOTICE,
  4466. + "Not installing %s (%s) on %s -- already installed.\n",
  4467. + pkg->name, new_version, old_pkg->dest->name);
  4468. + rc = 1;
  4469. + }
  4470. + }
  4471. + free(old_version);
  4472. + free(new_version);
  4473. + return rc;
  4474. + } else {
  4475. + char message_out[15], *version ;
  4476. + memset(message_out,'\x0',15);
  4477. + if ( message )
  4478. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4479. + else
  4480. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4481. + version = pkg_version_str_alloc(pkg);
  4482. +
  4483. + ipkg_message(conf, IPKG_NOTICE,
  4484. + "%s%s (%s) to %s...\n", message_out,
  4485. + pkg->name, version, pkg->dest->name);
  4486. + free(version);
  4487. + return 0;
  4488. + }
  4489. +}
  4490. +
  4491. +/* and now the meat... */
  4492. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4493. +{
  4494. + int err = 0;
  4495. + int message = 0;
  4496. + pkg_t *old_pkg = NULL;
  4497. + pkg_vec_t *replacees;
  4498. + abstract_pkg_t *ab_pkg = NULL;
  4499. + int old_state_flag;
  4500. + uint8_t *file_md5;
  4501. +
  4502. +
  4503. + if ( from_upgrade )
  4504. + message = 1; /* Coming from an upgrade, and should change the output message */
  4505. +
  4506. + if (!pkg) {
  4507. + ipkg_message(conf, IPKG_ERROR,
  4508. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4509. + return -EINVAL;
  4510. + }
  4511. +
  4512. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4513. +
  4514. + if (!pkg_arch_supported(conf, pkg)) {
  4515. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4516. + pkg->architecture, pkg->name);
  4517. + return -EINVAL;
  4518. + }
  4519. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4520. + err = satisfy_dependencies_for(conf, pkg);
  4521. + if (err) { return err; }
  4522. +
  4523. + ipkg_message(conf, IPKG_NOTICE,
  4524. + "Package %s is already installed in %s.\n",
  4525. + pkg->name, pkg->dest->name);
  4526. + return 0;
  4527. + }
  4528. +
  4529. + if (pkg->dest == NULL) {
  4530. + pkg->dest = conf->default_dest;
  4531. + }
  4532. +
  4533. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4534. +
  4535. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4536. + if (err) { return err; }
  4537. +
  4538. + pkg->state_want = SW_INSTALL;
  4539. + if (old_pkg){
  4540. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4541. + }
  4542. +
  4543. +
  4544. + /* Abhaya: conflicts check */
  4545. + err = check_conflicts_for(conf, pkg);
  4546. + if (err) { return err; }
  4547. +
  4548. + /* this setup is to remove the upgrade scenario in the end when
  4549. + installing pkg A, A deps B & B deps on A. So both B and A are
  4550. + installed. Then A's installation is started resulting in an
  4551. + uncecessary upgrade */
  4552. + if (pkg->state_status == SS_INSTALLED
  4553. + && conf->force_reinstall == 0) return 0;
  4554. +
  4555. + err = verify_pkg_installable(conf, pkg);
  4556. + if (err) { return err; }
  4557. +
  4558. + if (pkg->local_filename == NULL) {
  4559. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4560. + if (err) {
  4561. + ipkg_message(conf, IPKG_ERROR,
  4562. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4563. + pkg->name);
  4564. + return err;
  4565. + }
  4566. + }
  4567. +
  4568. +/* Check for md5 values */
  4569. + if (pkg->md5sum)
  4570. + {
  4571. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4572. + if (strcmp((char *)file_md5, pkg->md5sum))
  4573. + {
  4574. + ipkg_message(conf, IPKG_ERROR,
  4575. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4576. + pkg->name);
  4577. + free(file_md5);
  4578. + return err;
  4579. + }
  4580. + free(file_md5);
  4581. + }
  4582. +
  4583. + if (pkg->tmp_unpack_dir == NULL) {
  4584. + unpack_pkg_control_files(conf, pkg);
  4585. + }
  4586. +
  4587. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4588. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4589. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4590. + err = update_file_ownership(conf, pkg, old_pkg);
  4591. + if (err) { return err; }
  4592. +
  4593. + if (conf->nodeps == 0) {
  4594. + err = satisfy_dependencies_for(conf, pkg);
  4595. + if (err) { return err; }
  4596. + }
  4597. +
  4598. + replacees = pkg_vec_alloc();
  4599. + pkg_get_installed_replacees(pkg, replacees);
  4600. +
  4601. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4602. + {
  4603. + sigset_t newset, oldset;
  4604. + sighandler_t old_handler = NULL;
  4605. + int use_signal = 0;
  4606. + caught_sigint = 0;
  4607. + if (use_signal) {
  4608. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4609. + } else {
  4610. + sigemptyset(&newset);
  4611. + sigaddset(&newset, SIGINT);
  4612. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4613. + }
  4614. +
  4615. + ipkg_state_changed++;
  4616. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4617. +
  4618. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4619. + * Instead, we're going to remove the replacees
  4620. + */
  4621. + err = pkg_remove_installed_replacees(conf, replacees);
  4622. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4623. +
  4624. + /*
  4625. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4626. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4627. +
  4628. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4629. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4630. + */
  4631. +
  4632. + err = preinst_configure(conf, pkg, old_pkg);
  4633. + /*
  4634. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4635. + */
  4636. +
  4637. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4638. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4639. +
  4640. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4641. + /*
  4642. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4643. +
  4644. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4645. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4646. + */
  4647. +
  4648. + if (conf->noaction) return 0;
  4649. +
  4650. + /* point of no return: no unwinding after this */
  4651. + if (old_pkg && !conf->force_reinstall) {
  4652. + old_pkg->state_want = SW_DEINSTALL;
  4653. +
  4654. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4655. + ipkg_message(conf, IPKG_INFO,
  4656. + " not removing obsolesced files because package marked noprune\n");
  4657. + } else {
  4658. + ipkg_message(conf, IPKG_INFO,
  4659. + " removing obsolesced files\n");
  4660. + remove_obsolesced_files(conf, pkg, old_pkg);
  4661. + }
  4662. + /* removing files from old package, to avoid ghost files */
  4663. + remove_data_files_and_list(conf, old_pkg);
  4664. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4665. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4666. + remove_postrm(conf, old_pkg);
  4667. +/* Pigi */
  4668. +
  4669. + }
  4670. +
  4671. +
  4672. + ipkg_message(conf, IPKG_INFO,
  4673. + " installing maintainer scripts\n");
  4674. + install_maintainer_scripts(conf, pkg, old_pkg);
  4675. +
  4676. + /* the following just returns 0
  4677. + remove_disappeared(conf, pkg);
  4678. + */
  4679. +
  4680. + ipkg_message(conf, IPKG_INFO,
  4681. + " installing data files\n");
  4682. + install_data_files(conf, pkg);
  4683. +
  4684. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4685. + err = check_data_file_clashes_change(conf, pkg);
  4686. +
  4687. + ipkg_message(conf, IPKG_INFO,
  4688. + " resolving conf files\n");
  4689. + resolve_conffiles(conf, pkg);
  4690. +
  4691. + pkg->state_status = SS_UNPACKED;
  4692. + old_state_flag = pkg->state_flag;
  4693. + pkg->state_flag &= ~SF_PREFER;
  4694. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4695. +
  4696. + if (old_pkg && !conf->force_reinstall) {
  4697. + old_pkg->state_status = SS_NOT_INSTALLED;
  4698. + }
  4699. +
  4700. + time(&pkg->installed_time);
  4701. +
  4702. + ipkg_message(conf, IPKG_INFO,
  4703. + " cleanup temp files\n");
  4704. + cleanup_temporary_files(conf, pkg);
  4705. +
  4706. + ab_pkg = pkg->parent;
  4707. + if (ab_pkg)
  4708. + ab_pkg->state_status = pkg->state_status;
  4709. +
  4710. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4711. +
  4712. + if (use_signal)
  4713. + signal(SIGINT, old_handler);
  4714. + else
  4715. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4716. +
  4717. + return 0;
  4718. +
  4719. +
  4720. + /*
  4721. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4722. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4723. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4724. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4725. + */
  4726. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4727. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4728. + /*
  4729. + UNWIND_PREINST_CONFIGURE:
  4730. + preinst_configure_unwind(conf, pkg, old_pkg);
  4731. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4732. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4733. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4734. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4735. + */
  4736. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4737. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4738. +
  4739. + ipkg_message(conf, IPKG_INFO,
  4740. + " cleanup temp files\n");
  4741. + cleanup_temporary_files(conf, pkg);
  4742. +
  4743. + ipkg_message(conf, IPKG_INFO,
  4744. + "Failed.\n");
  4745. + if (use_signal)
  4746. + signal(SIGINT, old_handler);
  4747. + else
  4748. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4749. +
  4750. + return err;
  4751. + }
  4752. +}
  4753. +
  4754. +/*
  4755. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4756. +{
  4757. + DPKG_INCOMPATIBILITY:
  4758. + dpkg does some things here that we don't do yet. Do we care?
  4759. +
  4760. + 1. If a version of the package is already installed, call
  4761. + old-prerm upgrade new-version
  4762. + 2. If the script runs but exits with a non-zero exit status
  4763. + new-prerm failed-upgrade old-version
  4764. + Error unwind, for both the above cases:
  4765. + old-postinst abort-upgrade new-version
  4766. + return 0;
  4767. +}
  4768. +*/
  4769. +
  4770. +/*
  4771. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4772. +{
  4773. + DPKG_INCOMPATIBILITY:
  4774. + dpkg does some things here that we don't do yet. Do we care?
  4775. + (See prerm_upgrade_old_package for details)
  4776. +
  4777. + return 0;
  4778. +}
  4779. +*/
  4780. +
  4781. +/*
  4782. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4783. +{
  4784. + DPKG_INCOMPATIBILITY:
  4785. + dpkg does some things here that we don't do yet. Do we care?
  4786. + 2. If a 'conflicting' package is being removed at the same time:
  4787. + 1. If any packages depended on that conflicting package and
  4788. + --auto-deconfigure is specified, call, for each such package:
  4789. + deconfigured's-prerm deconfigure \
  4790. + in-favour package-being-installed version \
  4791. + removing conflicting-package version
  4792. + Error unwind:
  4793. + deconfigured's-postinst abort-deconfigure \
  4794. + in-favour package-being-installed-but-failed version \
  4795. + removing conflicting-package version
  4796. +
  4797. + The deconfigured packages are marked as requiring
  4798. + configuration, so that if --install is used they will be
  4799. + configured again if possible.
  4800. + 2. To prepare for removal of the conflicting package, call:
  4801. + conflictor's-prerm remove in-favour package new-version
  4802. + Error unwind:
  4803. + conflictor's-postinst abort-remove in-favour package new-version
  4804. + return 0;
  4805. +}
  4806. +*/
  4807. +
  4808. +/*
  4809. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4810. +{
  4811. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4812. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4813. + details)
  4814. + return 0;
  4815. +}
  4816. +*/
  4817. +
  4818. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4819. +{
  4820. + int err;
  4821. + char *preinst_args;
  4822. +
  4823. + if (old_pkg) {
  4824. + char *old_version = pkg_version_str_alloc(old_pkg);
  4825. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4826. + free(old_version);
  4827. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4828. + char *pkg_version = pkg_version_str_alloc(pkg);
  4829. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4830. + free(pkg_version);
  4831. + } else {
  4832. + preinst_args = strdup("install");
  4833. + }
  4834. +
  4835. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4836. + if (err) {
  4837. + ipkg_message(conf, IPKG_ERROR,
  4838. + "Aborting installation of %s\n", pkg->name);
  4839. + return 1;
  4840. + }
  4841. +
  4842. + free(preinst_args);
  4843. +
  4844. + return 0;
  4845. +}
  4846. +
  4847. +/*
  4848. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4849. +{
  4850. + DPKG_INCOMPATIBILITY:
  4851. + dpkg does the following error unwind, should we?
  4852. + pkg->postrm abort-upgrade old-version
  4853. + OR pkg->postrm abort-install old-version
  4854. + OR pkg->postrm abort-install
  4855. + return 0;
  4856. +}
  4857. +*/
  4858. +
  4859. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4860. +{
  4861. + int err;
  4862. + conffile_list_elt_t *iter;
  4863. + conffile_t *cf;
  4864. +
  4865. + if (conf->noaction) return 0;
  4866. +
  4867. + /* Backup all modified conffiles */
  4868. + if (old_pkg) {
  4869. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4870. + char *cf_name;
  4871. +
  4872. + cf = iter->data;
  4873. + cf_name = root_filename_alloc(conf, cf->name);
  4874. +
  4875. + /* Don't worry if the conffile is just plain gone */
  4876. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4877. + err = backup_make_backup(conf, cf_name);
  4878. + if (err) {
  4879. + return err;
  4880. + }
  4881. + }
  4882. + free(cf_name);
  4883. + }
  4884. + }
  4885. +
  4886. + /* Backup all conffiles that were not conffiles in old_pkg */
  4887. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4888. + char *cf_name;
  4889. + cf = iter->data;
  4890. + cf_name = root_filename_alloc(conf, cf->name);
  4891. + /* Ignore if this was a conffile in old_pkg as well */
  4892. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4893. + continue;
  4894. + }
  4895. +
  4896. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4897. + err = backup_make_backup(conf, cf_name);
  4898. + if (err) {
  4899. + return err;
  4900. + }
  4901. + }
  4902. + free(cf_name);
  4903. + }
  4904. +
  4905. + return 0;
  4906. +}
  4907. +
  4908. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4909. +{
  4910. + conffile_list_elt_t *iter;
  4911. +
  4912. + if (old_pkg) {
  4913. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4914. + backup_remove(iter->data->name);
  4915. + }
  4916. + }
  4917. +
  4918. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4919. + backup_remove(iter->data->name);
  4920. + }
  4921. +
  4922. + return 0;
  4923. +}
  4924. +
  4925. +
  4926. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4927. +{
  4928. + /* DPKG_INCOMPATIBILITY:
  4929. + ipkg takes a slightly different approach than dpkg at this
  4930. + point. dpkg installs each file in the new package while
  4931. + creating a backup for any file that is replaced, (so that it
  4932. + can unwind if necessary). To avoid complexity and redundant
  4933. + storage, ipkg doesn't do any installation until later, (at the
  4934. + point at which dpkg removes the backups.
  4935. +
  4936. + But, we do have to check for data file clashes, since after
  4937. + installing a package with a file clash, removing either of the
  4938. + packages involved in the clash has the potential to break the
  4939. + other package.
  4940. + */
  4941. + str_list_t *files_list;
  4942. + str_list_elt_t *iter;
  4943. +
  4944. + int clashes = 0;
  4945. +
  4946. + files_list = pkg_get_installed_files(pkg);
  4947. + for (iter = files_list->head; iter; iter = iter->next) {
  4948. + char *root_filename;
  4949. + char *filename = iter->data;
  4950. + root_filename = root_filename_alloc(conf, filename);
  4951. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4952. + pkg_t *owner;
  4953. + pkg_t *obs;
  4954. + /* Pre-existing conffiles are OK */
  4955. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4956. + if (backup_exists_for(root_filename)) {
  4957. + continue;
  4958. + }
  4959. +
  4960. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4961. + if (conf->force_overwrite) {
  4962. + /* but we need to change who owns this file */
  4963. + file_hash_set_file_owner(conf, filename, pkg);
  4964. + continue;
  4965. + }
  4966. +
  4967. + owner = file_hash_get_file_owner(conf, filename);
  4968. +
  4969. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4970. + if (owner && old_pkg) {
  4971. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4972. + continue;
  4973. + }
  4974. + }
  4975. +
  4976. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4977. + if (owner) {
  4978. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4979. + if (pkg_replaces(pkg, owner)) {
  4980. + continue;
  4981. + }
  4982. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4983. + then it's ok to overwrite. */
  4984. + if (strcmp(owner->name,pkg->name)==0){
  4985. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4986. + continue;
  4987. + }
  4988. + }
  4989. +
  4990. + /* Pre-existing files are OK if they are obsolete */
  4991. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4992. + if (obs) {
  4993. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4994. + continue;
  4995. + }
  4996. +
  4997. + /* We have found a clash. */
  4998. + ipkg_message(conf, IPKG_ERROR,
  4999. + "Package %s wants to install file %s\n"
  5000. + "\tBut that file is already provided by package ",
  5001. + pkg->name, filename);
  5002. + if (owner) {
  5003. + ipkg_message(conf, IPKG_ERROR,
  5004. + "%s\n", owner->name);
  5005. + } else {
  5006. + ipkg_message(conf, IPKG_ERROR,
  5007. + "<no package>\nPlease move this file out of the way and try again.\n");
  5008. + }
  5009. + clashes++;
  5010. + }
  5011. + free(root_filename);
  5012. + }
  5013. + pkg_free_installed_files(pkg);
  5014. +
  5015. + return clashes;
  5016. +}
  5017. +
  5018. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5019. +{
  5020. + /* Basically that's the worst hack I could do to be able to change ownership of
  5021. + file list, but, being that we have no way to unwind the mods, due to structure
  5022. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5023. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5024. + happens )
  5025. + Only the action that are needed to change name should be considered.
  5026. + @@@ To change after 1.0 release.
  5027. + */
  5028. + str_list_t *files_list;
  5029. + str_list_elt_t *iter;
  5030. +
  5031. + int clashes = 0;
  5032. +
  5033. + files_list = pkg_get_installed_files(pkg);
  5034. + for (iter = files_list->head; iter; iter = iter->next) {
  5035. + char *root_filename;
  5036. + char *filename = iter->data;
  5037. + root_filename = root_filename_alloc(conf, filename);
  5038. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5039. + pkg_t *owner;
  5040. +
  5041. + if (conf->force_overwrite) {
  5042. + /* but we need to change who owns this file */
  5043. + file_hash_set_file_owner(conf, filename, pkg);
  5044. + continue;
  5045. + }
  5046. +
  5047. + owner = file_hash_get_file_owner(conf, filename);
  5048. +
  5049. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5050. + if (owner) {
  5051. + if (pkg_replaces(pkg, owner)) {
  5052. +/* It's now time to change the owner of that file.
  5053. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5054. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5055. + file_hash_set_file_owner(conf, filename, pkg);
  5056. + continue;
  5057. + }
  5058. + }
  5059. +
  5060. + }
  5061. + free(root_filename);
  5062. + }
  5063. + pkg_free_installed_files(pkg);
  5064. +
  5065. + return clashes;
  5066. +}
  5067. +
  5068. +/*
  5069. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5070. +{
  5071. + Nothing to do since check_data_file_clashes doesn't change state
  5072. + return 0;
  5073. +}
  5074. +*/
  5075. +
  5076. +/*
  5077. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5078. +{
  5079. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5080. + 1. If the package is being upgraded, call
  5081. + old-postrm upgrade new-version
  5082. + 2. If this fails, attempt:
  5083. + new-postrm failed-upgrade old-version
  5084. + Error unwind, for both cases:
  5085. + old-preinst abort-upgrade new-version
  5086. + return 0;
  5087. +}
  5088. +*/
  5089. +
  5090. +/*
  5091. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5092. +{
  5093. + DPKG_INCOMPATIBILITY:
  5094. + dpkg does some things here that we don't do yet. Do we care?
  5095. + (See postrm_upgrade_old_pkg for details)
  5096. + return 0;
  5097. +}
  5098. +*/
  5099. +
  5100. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5101. +{
  5102. + int err;
  5103. + str_list_t *old_files;
  5104. + str_list_elt_t *of;
  5105. + str_list_t *new_files;
  5106. + str_list_elt_t *nf;
  5107. +
  5108. + if (old_pkg == NULL) {
  5109. + return 0;
  5110. + }
  5111. +
  5112. + old_files = pkg_get_installed_files(old_pkg);
  5113. + new_files = pkg_get_installed_files(pkg);
  5114. +
  5115. + for (of = old_files->head; of; of = of->next) {
  5116. + pkg_t *owner;
  5117. + char *old, *new;
  5118. + old = of->data;
  5119. + for (nf = new_files->head; nf; nf = nf->next) {
  5120. + new = nf->data;
  5121. + if (strcmp(old, new) == 0) {
  5122. + goto NOT_OBSOLETE;
  5123. + }
  5124. + }
  5125. + if (file_is_dir(old)) {
  5126. + continue;
  5127. + }
  5128. + owner = file_hash_get_file_owner(conf, old);
  5129. + if (owner != old_pkg) {
  5130. + /* in case obsolete file no longer belongs to old_pkg */
  5131. + continue;
  5132. + }
  5133. +
  5134. + /* old file is obsolete */
  5135. + ipkg_message(conf, IPKG_INFO,
  5136. + " removing obsolete file %s\n", old);
  5137. + if (!conf->noaction) {
  5138. + err = unlink(old);
  5139. + if (err) {
  5140. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5141. + strerror(errno));
  5142. + }
  5143. + }
  5144. +
  5145. + NOT_OBSOLETE:
  5146. + ;
  5147. + }
  5148. +
  5149. + pkg_free_installed_files(old_pkg);
  5150. + pkg_free_installed_files(pkg);
  5151. +
  5152. + return 0;
  5153. +}
  5154. +
  5155. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5156. +{
  5157. + int i;
  5158. + int err = 0;
  5159. + char *globpattern;
  5160. + glob_t globbuf;
  5161. + if (0) {
  5162. + if (!pkg->dest) {
  5163. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5164. + return -1;
  5165. + }
  5166. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5167. + err = glob(globpattern, 0, NULL, &globbuf);
  5168. + free(globpattern);
  5169. + if (err) {
  5170. + return err;
  5171. + }
  5172. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5173. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5174. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5175. + globbuf.gl_pathv[i], old_pkg->name);
  5176. + if (!conf->noaction)
  5177. + unlink(globbuf.gl_pathv[i]);
  5178. + }
  5179. + globfree(&globbuf);
  5180. + }
  5181. + return err;
  5182. +}
  5183. +
  5184. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5185. +{
  5186. + int ret;
  5187. + char *prefix;
  5188. +
  5189. + if (old_pkg)
  5190. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5191. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5192. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5193. + pkg->dest->info_dir,
  5194. + prefix);
  5195. + free(prefix);
  5196. + return ret;
  5197. +}
  5198. +
  5199. +/*
  5200. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5201. +{
  5202. + DPKG_INCOMPATIBILITY:
  5203. + This is a fairly sophisticated dpkg operation. Shall we
  5204. + skip it?
  5205. +
  5206. + Any packages all of whose files have been overwritten during the
  5207. + installation, and which aren't required for dependencies, are
  5208. + considered to have been removed. For each such package
  5209. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5210. + 2. The package's maintainer scripts are removed
  5211. + 3. It is noted in the status database as being in a sane state,
  5212. + namely not installed (any conffiles it may have are ignored,
  5213. + rather than being removed by dpkg). Note that disappearing
  5214. + packages do not have their prerm called, because dpkg doesn't
  5215. + know in advance that the package is going to vanish.
  5216. +
  5217. +
  5218. + return 0;
  5219. +}
  5220. +*/
  5221. +
  5222. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5223. +{
  5224. + int err;
  5225. +
  5226. + /* ipkg takes a slightly different approach to data file backups
  5227. + than dpkg. Rather than removing backups at this point, we
  5228. + actually do the data file installation now. See comments in
  5229. + check_data_file_clashes() for more details. */
  5230. +
  5231. + ipkg_message(conf, IPKG_INFO,
  5232. + " extracting data files to %s\n", pkg->dest->root_dir);
  5233. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5234. + if (err) {
  5235. + return err;
  5236. + }
  5237. +
  5238. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5239. + so we can't save ourself from removing important packages
  5240. + At this point we (should) have extracted the .control file, so it
  5241. + would be a good idea to reload the data in it, and set the Essential
  5242. + state in *pkg. From now on the Essential is back in status file and
  5243. + we can protect again.
  5244. + We should operate this way:
  5245. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5246. + check for "Essential" in it
  5247. + set the value in pkg->essential.
  5248. + This new routine could be useful also for every other flag
  5249. + Pigi: 16/03/2004 */
  5250. + set_flags_from_control(conf, pkg) ;
  5251. +
  5252. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5253. + err = pkg_write_filelist(conf, pkg);
  5254. + if (err)
  5255. + return err;
  5256. +
  5257. + /* XXX: FEATURE: ipkg should identify any files which existed
  5258. + before installation and which were overwritten, (see
  5259. + check_data_file_clashes()). What it must do is remove any such
  5260. + files from the filelist of the old package which provided the
  5261. + file. Otherwise, if the old package were removed at some point
  5262. + it would break the new package. Removing the new package will
  5263. + also break the old one, but this cannot be helped since the old
  5264. + package's file has already been deleted. This is the importance
  5265. + of check_data_file_clashes(), and only allowing ipkg to install
  5266. + a clashing package with a user force. */
  5267. +
  5268. + return 0;
  5269. +}
  5270. +
  5271. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5272. +{
  5273. + conffile_list_elt_t *iter;
  5274. + conffile_t *cf;
  5275. + char *cf_backup;
  5276. + uint8_t *md5sum;
  5277. +
  5278. +
  5279. + if (conf->noaction) return 0;
  5280. +
  5281. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5282. + char *root_filename;
  5283. + cf = iter->data;
  5284. + root_filename = root_filename_alloc(conf, cf->name);
  5285. +
  5286. + /* Might need to initialize the md5sum for each conffile */
  5287. + if (cf->value == NULL) {
  5288. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5289. + }
  5290. +
  5291. + if (!file_exists(root_filename)) {
  5292. + free(root_filename);
  5293. + continue;
  5294. + }
  5295. +
  5296. + cf_backup = backup_filename_alloc(root_filename);
  5297. +
  5298. +
  5299. + if (file_exists(cf_backup)) {
  5300. + /* Let's compute md5 to test if files are changed */
  5301. + md5sum = file_md5sum_alloc(cf_backup);
  5302. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5303. + if (conf->force_defaults
  5304. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5305. + rename(cf_backup, root_filename);
  5306. + }
  5307. + }
  5308. + unlink(cf_backup);
  5309. + free(md5sum);
  5310. + }
  5311. +
  5312. + free(cf_backup);
  5313. + free(root_filename);
  5314. + }
  5315. +
  5316. + return 0;
  5317. +}
  5318. +
  5319. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5320. +{
  5321. + char *response;
  5322. + const char *short_file_name;
  5323. +
  5324. + short_file_name = strrchr(file_name, '/');
  5325. + if (short_file_name) {
  5326. + short_file_name++;
  5327. + } else {
  5328. + short_file_name = file_name;
  5329. + }
  5330. +
  5331. + while (1) {
  5332. + response = get_user_response(" Configuration file '%s'\n"
  5333. + " ==> File on system created by you or by a script.\n"
  5334. + " ==> File also in package provided by package maintainer.\n"
  5335. + " What would you like to do about it ? Your options are:\n"
  5336. + " Y or I : install the package maintainer's version\n"
  5337. + " N or O : keep your currently-installed version\n"
  5338. +#ifdef CONFIG_DIFF
  5339. + " D : show the differences between the versions\n"
  5340. +#endif
  5341. + " The default action is to keep your current version.\n"
  5342. + " *** %s (Y/I/N/O"
  5343. +#ifdef CONFIG_DIFF
  5344. + "/D"
  5345. +#endif
  5346. + ") [default=N] ? ", file_name, short_file_name);
  5347. + if (strcmp(response, "y") == 0
  5348. + || strcmp(response, "i") == 0
  5349. + || strcmp(response, "yes") == 0) {
  5350. + free(response);
  5351. + return 0;
  5352. + }
  5353. +
  5354. +#ifdef CONFIG_DIFF
  5355. + if (strcmp(response, "d") == 0) {
  5356. + char *cmd;
  5357. +
  5358. + free(response);
  5359. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5360. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5361. + xsystem(cmd);
  5362. + free(cmd);
  5363. + printf(" [Press ENTER to continue]\n");
  5364. + response = file_read_line_alloc(stdin);
  5365. + free(response);
  5366. + continue;
  5367. + }
  5368. +#endif
  5369. +
  5370. + free(response);
  5371. + return 1;
  5372. + }
  5373. +}
  5374. +
  5375. +/* XXX: CLEANUP: I'd like to move all of the code for
  5376. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5377. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5378. + pkg_deinit for example). */
  5379. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5380. +{
  5381. + DIR *tmp_dir;
  5382. + struct dirent *dirent;
  5383. + char *tmp_file;
  5384. +
  5385. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5386. +#error
  5387. + ipkg_message(conf, IPKG_DEBUG,
  5388. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5389. + __FUNCTION__, pkg->tmp_unpack_dir);
  5390. + return 0;
  5391. +#endif
  5392. +
  5393. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5394. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5395. + if (tmp_dir) {
  5396. + while (1) {
  5397. + dirent = readdir(tmp_dir);
  5398. + if (dirent == NULL) {
  5399. + break;
  5400. + }
  5401. + sprintf_alloc(&tmp_file, "%s/%s",
  5402. + pkg->tmp_unpack_dir, dirent->d_name);
  5403. + if (! file_is_dir(tmp_file)) {
  5404. + unlink(tmp_file);
  5405. + }
  5406. + free(tmp_file);
  5407. + }
  5408. + closedir(tmp_dir);
  5409. + rmdir(pkg->tmp_unpack_dir);
  5410. + free(pkg->tmp_unpack_dir);
  5411. + pkg->tmp_unpack_dir = NULL;
  5412. + }
  5413. + }
  5414. +
  5415. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5416. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5417. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5418. + unlink(pkg->local_filename);
  5419. + free(pkg->local_filename);
  5420. + pkg->local_filename = NULL;
  5421. + }
  5422. +
  5423. + return 0;
  5424. +}
  5425. +
  5426. +static char *backup_filename_alloc(const char *file_name)
  5427. +{
  5428. + char *backup;
  5429. +
  5430. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5431. +
  5432. + return backup;
  5433. +}
  5434. +
  5435. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5436. +{
  5437. + int err;
  5438. + char *backup;
  5439. +
  5440. + backup = backup_filename_alloc(file_name);
  5441. + err = file_copy(file_name, backup);
  5442. + if (err) {
  5443. + ipkg_message(conf, IPKG_ERROR,
  5444. + "%s: Failed to copy %s to %s\n",
  5445. + __FUNCTION__, file_name, backup);
  5446. + }
  5447. +
  5448. + free(backup);
  5449. +
  5450. + return err;
  5451. +}
  5452. +
  5453. +static int backup_exists_for(const char *file_name)
  5454. +{
  5455. + int ret;
  5456. + char *backup;
  5457. +
  5458. + backup = backup_filename_alloc(file_name);
  5459. +
  5460. + ret = file_exists(backup);
  5461. +
  5462. + free(backup);
  5463. +
  5464. + return ret;
  5465. +}
  5466. +
  5467. +static int backup_remove(const char *file_name)
  5468. +{
  5469. + char *backup;
  5470. +
  5471. + backup = backup_filename_alloc(file_name);
  5472. + unlink(backup);
  5473. + free(backup);
  5474. +
  5475. + return 0;
  5476. +}
  5477. +
  5478. +
  5479. +
  5480. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5481. +
  5482. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5483. +{
  5484. + /* first, remove the packages that need removing */
  5485. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5486. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5487. + err = ipkg_remove_pkg(conf, pkg,0);
  5488. + if (err) return err;
  5489. + }
  5490. + return 0;
  5491. +}
  5492. +
  5493. +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)
  5494. +{
  5495. + int i;
  5496. + /* now one more pass checking on the ones that need to be installed */
  5497. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5498. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5499. + if (pkg->dest == NULL)
  5500. + pkg->dest = conf->default_dest;
  5501. +
  5502. + pkg->state_want = SW_INSTALL;
  5503. +
  5504. + /* Abhaya: conflicts check */
  5505. + err = check_conflicts_for(conf, pkg);
  5506. + if (err) { return err; }
  5507. + }
  5508. + return 0;
  5509. +}
  5510. +
  5511. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5512. +{
  5513. + int i;
  5514. + /* now one more pass checking on the ones that need to be installed */
  5515. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5516. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5517. +
  5518. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5519. + pkg_vec_t *replacees = pkg_vec_alloc();
  5520. + pkg_get_installed_replacees(pkg, replacees);
  5521. +
  5522. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5523. + * Instead, we're going to remove the replacees
  5524. + */
  5525. + err = pkg_remove_installed_replacees(conf, replacees);
  5526. + if (err) return err;
  5527. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5528. + }
  5529. + return 0;
  5530. +}
  5531. +
  5532. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5533. +{
  5534. + int i;
  5535. + /* now one more pass checking on the ones that need to be installed */
  5536. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5537. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5538. + if (pkg->local_filename == NULL) {
  5539. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5540. + if (err) {
  5541. + ipkg_message(conf, IPKG_ERROR,
  5542. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5543. + pkg->name);
  5544. + return err;
  5545. + }
  5546. + }
  5547. + if (pkg->tmp_unpack_dir == NULL) {
  5548. + err = unpack_pkg_control_files(conf, pkg);
  5549. + if (err) return err;
  5550. + }
  5551. + }
  5552. + return 0;
  5553. +}
  5554. +
  5555. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5556. +{
  5557. + int i;
  5558. + /* now one more pass checking on the ones that need to be installed */
  5559. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5560. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5561. + pkg_t *old_pkg = pkg->old_pkg;
  5562. +
  5563. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5564. + if (err) return err;
  5565. +
  5566. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5567. + if (err) return err;
  5568. +
  5569. + err = preinst_configure(conf, pkg, old_pkg);
  5570. + if (err) return err;
  5571. +
  5572. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5573. + if (err) return err;
  5574. +
  5575. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5576. + if (err) return err;
  5577. + }
  5578. + return 0;
  5579. +}
  5580. +
  5581. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5582. +{
  5583. + int i;
  5584. + /* now one more pass checking on the ones that need to be installed */
  5585. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5586. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5587. + pkg_t *old_pkg = pkg->old_pkg;
  5588. +
  5589. + if (old_pkg) {
  5590. + old_pkg->state_want = SW_DEINSTALL;
  5591. +
  5592. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5593. + ipkg_message(conf, IPKG_INFO,
  5594. + " not removing obsolesced files because package marked noprune\n");
  5595. + } else {
  5596. + ipkg_message(conf, IPKG_INFO,
  5597. + " removing obsolesced files\n");
  5598. + remove_obsolesced_files(conf, pkg, old_pkg);
  5599. + }
  5600. + }
  5601. +
  5602. + ipkg_message(conf, IPKG_INFO,
  5603. + " installing maintainer scripts\n");
  5604. + install_maintainer_scripts(conf, pkg, old_pkg);
  5605. +
  5606. + /* the following just returns 0 */
  5607. + remove_disappeared(conf, pkg);
  5608. +
  5609. + ipkg_message(conf, IPKG_INFO,
  5610. + " installing data files\n");
  5611. + install_data_files(conf, pkg);
  5612. +
  5613. + ipkg_message(conf, IPKG_INFO,
  5614. + " resolving conf files\n");
  5615. + resolve_conffiles(conf, pkg);
  5616. +
  5617. + pkg->state_status = SS_UNPACKED;
  5618. +
  5619. + if (old_pkg) {
  5620. + old_pkg->state_status = SS_NOT_INSTALLED;
  5621. + }
  5622. +
  5623. + time(&pkg->installed_time);
  5624. +
  5625. + ipkg_message(conf, IPKG_INFO,
  5626. + " cleanup temp files\n");
  5627. + cleanup_temporary_files(conf, pkg);
  5628. +
  5629. + if (pkg->parent)
  5630. + pkg->parent->state_status = pkg->state_status;
  5631. + }
  5632. + return 0;
  5633. +}
  5634. +
  5635. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5636. +{
  5637. + int i;
  5638. + /* now one more pass checking on the ones that need to be installed */
  5639. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5640. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5641. + pkg_t *old_pkg = pkg->old_pkg;
  5642. +
  5643. + if (old_pkg) {
  5644. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5645. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5646. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5647. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5648. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5649. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5650. + */
  5651. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5652. + preinst_configure_unwind(conf, pkg, old_pkg);
  5653. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5654. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5655. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5656. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5657. + */
  5658. +
  5659. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5660. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5661. +
  5662. + }
  5663. + }
  5664. + return 0;
  5665. +}
  5666. +
  5667. +/*
  5668. + * Perform all the actions.
  5669. + *
  5670. + * pkgs_to_remove are packages marked for removal.
  5671. + * pkgs_superseded are the old packages being replaced by upgrades.
  5672. + *
  5673. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5674. + */
  5675. +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)
  5676. +{
  5677. + int err;
  5678. + int i;
  5679. +
  5680. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5681. + if (err) return err;
  5682. +
  5683. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5684. + if (err) return err;
  5685. +
  5686. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5687. + if (err) goto UNWIND;
  5688. +
  5689. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5690. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5691. + if (err) goto UNWIND;
  5692. +
  5693. + /*
  5694. + * Now that we have the packages unpacked, we can look for data
  5695. + * file clashes. First, we mark the files from the superseded
  5696. + * packages as obsolete. Then we scan the files in
  5697. + * pkgs_to_install, and only complain about clashes with
  5698. + * non-obsolete files.
  5699. + */
  5700. +
  5701. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5702. + if (err) goto UNWIND;
  5703. +
  5704. + /* this was before checking data file clashes */
  5705. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5706. + if (err) goto UNWIND;
  5707. +
  5708. + /* point of no return: no unwinding after this */
  5709. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5710. + if (err) return err;
  5711. +
  5712. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5713. + return 0;
  5714. +
  5715. + UNWIND:
  5716. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5717. +
  5718. + ipkg_message(conf, IPKG_INFO,
  5719. + " cleanup temp files\n");
  5720. + cleanup_temporary_files(conf, pkg);
  5721. +
  5722. + ipkg_message(conf, IPKG_INFO,
  5723. + "Failed.\n");
  5724. + return err;
  5725. +}
  5726. +
  5727. +#endif
  5728. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_install.h busybox-1.23.0/archival/libipkg/ipkg_install.h
  5729. --- busybox-1.23.0.orig/archival/libipkg/ipkg_install.h 1969-12-31 18:00:00.000000000 -0600
  5730. +++ busybox-1.23.0/archival/libipkg/ipkg_install.h 2015-01-09 11:18:22.428197243 -0600
  5731. @@ -0,0 +1,35 @@
  5732. +/* ipkg_install.h - the itsy package management system
  5733. +
  5734. + Carl D. Worth
  5735. +
  5736. + Copyright (C) 2001 University of Southern California
  5737. +
  5738. + This program is free software; you can redistribute it and/or
  5739. + modify it under the terms of the GNU General Public License as
  5740. + published by the Free Software Foundation; either version 2, or (at
  5741. + your option) any later version.
  5742. +
  5743. + This program is distributed in the hope that it will be useful, but
  5744. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5745. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5746. + General Public License for more details.
  5747. +*/
  5748. +
  5749. +#ifndef IPKG_INSTALL_H
  5750. +#define IPKG_INSTALL_H
  5751. +
  5752. +#include "pkg.h"
  5753. +#include "ipkg_conf.h"
  5754. +
  5755. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5756. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5757. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5758. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5759. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5760. +
  5761. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5762. +
  5763. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5764. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5765. +
  5766. +#endif
  5767. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_message.c busybox-1.23.0/archival/libipkg/ipkg_message.c
  5768. --- busybox-1.23.0.orig/archival/libipkg/ipkg_message.c 1969-12-31 18:00:00.000000000 -0600
  5769. +++ busybox-1.23.0/archival/libipkg/ipkg_message.c 2015-01-09 11:18:22.428197243 -0600
  5770. @@ -0,0 +1,35 @@
  5771. +/* ipkg_message.c - the itsy package management system
  5772. +
  5773. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5774. +
  5775. + This program is free software; you can redistribute it and/or
  5776. + modify it under the terms of the GNU General Public License as
  5777. + published by the Free Software Foundation; either version 2, or (at
  5778. + your option) any later version.
  5779. +
  5780. + This program is distributed in the hope that it will be useful, but
  5781. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5782. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5783. + General Public License for more details.
  5784. +*/
  5785. +
  5786. +
  5787. +#include "ipkg.h"
  5788. +#include "ipkg_conf.h"
  5789. +#include "ipkg_message.h"
  5790. +#include "libipkg.h"
  5791. +
  5792. +void
  5793. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5794. +{
  5795. + va_list ap;
  5796. + char ts[256];
  5797. +
  5798. + if (ipkg_cb_message)
  5799. + {
  5800. + va_start (ap, fmt);
  5801. + vsnprintf (ts,256,fmt, ap);
  5802. + va_end (ap);
  5803. + ipkg_cb_message(conf,level,ts);
  5804. + }
  5805. +}
  5806. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_message.h busybox-1.23.0/archival/libipkg/ipkg_message.h
  5807. --- busybox-1.23.0.orig/archival/libipkg/ipkg_message.h 1969-12-31 18:00:00.000000000 -0600
  5808. +++ busybox-1.23.0/archival/libipkg/ipkg_message.h 2015-01-09 11:18:22.428197243 -0600
  5809. @@ -0,0 +1,32 @@
  5810. +/* ipkg_message.h - the itsy package management system
  5811. +
  5812. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5813. +
  5814. + This program is free software; you can redistribute it and/or
  5815. + modify it under the terms of the GNU General Public License as
  5816. + published by the Free Software Foundation; either version 2, or (at
  5817. + your option) any later version.
  5818. +
  5819. + This program is distributed in the hope that it will be useful, but
  5820. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5821. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5822. + General Public License for more details.
  5823. +*/
  5824. +
  5825. +#ifndef _IPKG_MESSAGE_H_
  5826. +#define _IPKG_MESSAGE_H_
  5827. +
  5828. +#include "ipkg.h"
  5829. +#include "ipkg_conf.h"
  5830. +
  5831. +typedef enum {
  5832. + IPKG_ERROR, /* error conditions */
  5833. + IPKG_NOTICE, /* normal but significant condition */
  5834. + IPKG_INFO, /* informational message */
  5835. + IPKG_DEBUG, /* debug level message */
  5836. + IPKG_DEBUG2, /* more debug level message */
  5837. +} message_level_t;
  5838. +
  5839. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5840. +
  5841. +#endif /* _IPKG_MESSAGE_H_ */
  5842. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_remove.c busybox-1.23.0/archival/libipkg/ipkg_remove.c
  5843. --- busybox-1.23.0.orig/archival/libipkg/ipkg_remove.c 1969-12-31 18:00:00.000000000 -0600
  5844. +++ busybox-1.23.0/archival/libipkg/ipkg_remove.c 2015-01-09 11:18:22.428197243 -0600
  5845. @@ -0,0 +1,385 @@
  5846. +/* ipkg_remove.c - the itsy package management system
  5847. +
  5848. + Carl D. Worth
  5849. +
  5850. + Copyright (C) 2001 University of Southern California
  5851. +
  5852. + This program is free software; you can redistribute it and/or
  5853. + modify it under the terms of the GNU General Public License as
  5854. + published by the Free Software Foundation; either version 2, or (at
  5855. + your option) any later version.
  5856. +
  5857. + This program is distributed in the hope that it will be useful, but
  5858. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5859. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5860. + General Public License for more details.
  5861. +*/
  5862. +
  5863. +#include "ipkg.h"
  5864. +#include "ipkg_message.h"
  5865. +
  5866. +#include <glob.h>
  5867. +
  5868. +#include "ipkg_remove.h"
  5869. +
  5870. +#include "file_util.h"
  5871. +#include "sprintf_alloc.h"
  5872. +#include "str_util.h"
  5873. +
  5874. +#include "ipkg_cmd.h"
  5875. +
  5876. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5877. +
  5878. +/*
  5879. + * Returns number of the number of packages depending on the packages provided by this package.
  5880. + * Every package implicitly provides itself.
  5881. + */
  5882. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5883. +{
  5884. + int nprovides = pkg->provides_count;
  5885. + abstract_pkg_t **provides = pkg->provides;
  5886. + int n_installed_dependents = 0;
  5887. + int i;
  5888. + for (i = 0; i <= nprovides; i++) {
  5889. + abstract_pkg_t *providee = provides[i];
  5890. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5891. + abstract_pkg_t *dep_ab_pkg;
  5892. + if (dependers == NULL)
  5893. + continue;
  5894. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5895. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5896. + n_installed_dependents++;
  5897. + }
  5898. + }
  5899. +
  5900. + }
  5901. + /* if caller requested the set of installed dependents */
  5902. + if (pdependents) {
  5903. + int p = 0;
  5904. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5905. +
  5906. + if ( dependents == NULL ){
  5907. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5908. + return -1;
  5909. + }
  5910. +
  5911. + *pdependents = dependents;
  5912. + for (i = 0; i <= nprovides; i++) {
  5913. + abstract_pkg_t *providee = provides[i];
  5914. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5915. + abstract_pkg_t *dep_ab_pkg;
  5916. + if (dependers == NULL)
  5917. + continue;
  5918. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5919. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5920. + dependents[p++] = dep_ab_pkg;
  5921. + dep_ab_pkg->state_flag |= SF_MARKED;
  5922. + }
  5923. + }
  5924. + }
  5925. + dependents[p] = NULL;
  5926. + /* now clear the marks */
  5927. + for (i = 0; i < p; i++) {
  5928. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5929. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5930. + }
  5931. + }
  5932. + return n_installed_dependents;
  5933. +}
  5934. +
  5935. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5936. +{
  5937. + int i;
  5938. + int a;
  5939. + int count;
  5940. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5941. + abstract_pkg_t * ab_pkg;
  5942. +
  5943. + if((ab_pkg = pkg->parent) == NULL){
  5944. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5945. + __FUNCTION__, pkg->name);
  5946. + return 0;
  5947. + }
  5948. +
  5949. + if (dependents == NULL)
  5950. + return 0;
  5951. +
  5952. + // here i am using the dependencies_checked
  5953. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5954. + return 0; // has already been encountered in the process
  5955. + // of marking packages for removal - Karthik
  5956. + ab_pkg->dependencies_checked = 2;
  5957. +
  5958. + i = 0;
  5959. + count = 1;
  5960. + while (dependents [i] != NULL) {
  5961. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5962. +
  5963. + if (dep_ab_pkg->dependencies_checked == 2){
  5964. + i++;
  5965. + continue;
  5966. + }
  5967. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5968. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5969. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5970. + if (dep_pkg->state_status == SS_INSTALLED) {
  5971. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5972. + count++;
  5973. + }
  5974. + }
  5975. + }
  5976. + i++;
  5977. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5978. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5979. + }
  5980. +
  5981. + if (count == 1)
  5982. + return 0;
  5983. +
  5984. +
  5985. + for (i = 0; i < dependent_pkgs->len; i++) {
  5986. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5987. + if (err)
  5988. + return err;
  5989. + }
  5990. + return 0;
  5991. +}
  5992. +
  5993. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5994. +{
  5995. + abstract_pkg_t *dep_ab_pkg;
  5996. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5997. + while ((dep_ab_pkg = *dependents++) != NULL) {
  5998. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  5999. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6000. + }
  6001. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6002. + ipkg_message(conf, IPKG_ERROR, "");
  6003. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6004. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6005. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6006. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6007. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6008. + return 0;
  6009. +}
  6010. +
  6011. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6012. +{
  6013. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6014. + thus I wan't check for essential, as I'm upgrading.
  6015. + I hope it won't break anything :)
  6016. +*/
  6017. + int err;
  6018. + abstract_pkg_t *parent_pkg = NULL;
  6019. +
  6020. + if (pkg->essential && !message) {
  6021. + if (conf->force_removal_of_essential_packages) {
  6022. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6023. + "\tIf your system breaks, you get to keep both pieces\n",
  6024. + pkg->name);
  6025. + } else {
  6026. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6027. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6028. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6029. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6030. + pkg->name);
  6031. + return IPKG_PKG_IS_ESSENTIAL;
  6032. + }
  6033. + }
  6034. +
  6035. + if ((parent_pkg = pkg->parent) == NULL)
  6036. + return 0;
  6037. +
  6038. + /* only attempt to remove dependent installed packages if
  6039. + * force_depends is not specified or the package is being
  6040. + * replaced.
  6041. + */
  6042. + if (!conf->force_depends
  6043. + && !(pkg->state_flag & SF_REPLACE)) {
  6044. + abstract_pkg_t **dependents;
  6045. + int has_installed_dependents =
  6046. + pkg_has_installed_dependents(pkg, &dependents);
  6047. +
  6048. + if (has_installed_dependents) {
  6049. + /*
  6050. + * if this package is depended up by others, then either we should
  6051. + * not remove it or we should remove it and all of its dependents
  6052. + */
  6053. +
  6054. + if (!conf->force_removal_of_dependent_packages
  6055. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6056. + return IPKG_PKG_HAS_DEPENDENTS;
  6057. + }
  6058. +
  6059. + /* remove packages depending on this package - Karthik */
  6060. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6061. + free(dependents);
  6062. + if (err) return err;
  6063. + }
  6064. + }
  6065. +
  6066. + if ( message==0 ){
  6067. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6068. + fflush(stdout);
  6069. + }
  6070. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6071. +
  6072. + pkg->state_want = SW_DEINSTALL;
  6073. + ipkg_state_changed++;
  6074. +
  6075. + pkg_run_script(conf, pkg, "prerm", "remove");
  6076. +
  6077. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6078. + maintains an empty filelist rather than deleting it. That seems
  6079. + like a big pain, and I don't see that that should make a big
  6080. + difference, but for anyone who wants tighter compatibility,
  6081. + feel free to fix this. */
  6082. + remove_data_files_and_list(conf, pkg);
  6083. +
  6084. + pkg_run_script(conf, pkg, "postrm", "remove");
  6085. +
  6086. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6087. +
  6088. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6089. + * space, it doesn't make sense to leave extra configurations, files,
  6090. + * and maintainer scripts left around. So, we make remove like purge,
  6091. + * and take out all the crap :) */
  6092. +
  6093. + remove_postrm(conf, pkg);
  6094. + pkg->state_status = SS_NOT_INSTALLED;
  6095. +
  6096. + if (parent_pkg)
  6097. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6098. +
  6099. + return 0;
  6100. +}
  6101. +
  6102. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6103. +{
  6104. + ipkg_remove_pkg(conf, pkg,0);
  6105. + return 0;
  6106. +}
  6107. +
  6108. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6109. +{
  6110. + str_list_t installed_dirs;
  6111. + str_list_t *installed_files;
  6112. + str_list_elt_t *iter;
  6113. + char *file_name;
  6114. + conffile_t *conffile;
  6115. + int removed_a_dir;
  6116. + pkg_t *owner;
  6117. +
  6118. + str_list_init(&installed_dirs);
  6119. + installed_files = pkg_get_installed_files(pkg);
  6120. +
  6121. + for (iter = installed_files->head; iter; iter = iter->next) {
  6122. + file_name = iter->data;
  6123. +
  6124. + if (file_is_dir(file_name)) {
  6125. + str_list_append(&installed_dirs, strdup(file_name));
  6126. + continue;
  6127. + }
  6128. +
  6129. + conffile = pkg_get_conffile(pkg, file_name);
  6130. + if (conffile) {
  6131. + /* XXX: QUESTION: Is this right? I figure we only need to
  6132. + save the conffile if it has been modified. Is that what
  6133. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6134. + this seems like a better thing to do to conserve
  6135. + space. */
  6136. + if (conffile_has_been_modified(conf, conffile)) {
  6137. + printf(" not deleting modified conffile %s\n", file_name);
  6138. + fflush(stdout);
  6139. + continue;
  6140. + }
  6141. + }
  6142. +
  6143. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6144. + if (!conf->noaction)
  6145. + unlink(file_name);
  6146. + }
  6147. +
  6148. + if (!conf->noaction) {
  6149. + do {
  6150. + removed_a_dir = 0;
  6151. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6152. + file_name = iter->data;
  6153. +
  6154. + if (rmdir(file_name) == 0) {
  6155. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6156. + removed_a_dir = 1;
  6157. + str_list_remove(&installed_dirs, &iter);
  6158. + }
  6159. + }
  6160. + } while (removed_a_dir);
  6161. + }
  6162. +
  6163. + pkg_free_installed_files(pkg);
  6164. + /* We have to remove the file list now, so that
  6165. + find_pkg_owning_file does not always just report this package */
  6166. + pkg_remove_installed_files_list(conf, pkg);
  6167. +
  6168. + /* Don't print warning for dirs that are provided by other packages */
  6169. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6170. + file_name = iter->data;
  6171. +
  6172. + owner = file_hash_get_file_owner(conf, file_name);
  6173. + if (owner) {
  6174. + free(iter->data);
  6175. + iter->data = NULL;
  6176. + str_list_remove(&installed_dirs, &iter);
  6177. + }
  6178. + }
  6179. +
  6180. + /* cleanup */
  6181. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6182. + free(iter->data);
  6183. + iter->data = NULL;
  6184. + }
  6185. + str_list_deinit(&installed_dirs);
  6186. +
  6187. + return 0;
  6188. +}
  6189. +
  6190. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6191. +{
  6192. + int i, err;
  6193. + char *globpattern;
  6194. + glob_t globbuf;
  6195. +
  6196. + if (conf->noaction) return 0;
  6197. +
  6198. + sprintf_alloc(&globpattern, "%s/%s.*",
  6199. + pkg->dest->info_dir, pkg->name);
  6200. + err = glob(globpattern, 0, NULL, &globbuf);
  6201. + free(globpattern);
  6202. + if (err) {
  6203. + return 0;
  6204. + }
  6205. +
  6206. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6207. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6208. + continue;
  6209. + }
  6210. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6211. + unlink(globbuf.gl_pathv[i]);
  6212. + }
  6213. + globfree(&globbuf);
  6214. +
  6215. + return 0;
  6216. +}
  6217. +
  6218. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6219. +{
  6220. + char *postrm_file_name;
  6221. +
  6222. + if (conf->noaction) return 0;
  6223. +
  6224. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6225. + pkg->dest->info_dir, pkg->name);
  6226. + unlink(postrm_file_name);
  6227. + free(postrm_file_name);
  6228. +
  6229. + return 0;
  6230. +}
  6231. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_remove.h busybox-1.23.0/archival/libipkg/ipkg_remove.h
  6232. --- busybox-1.23.0.orig/archival/libipkg/ipkg_remove.h 1969-12-31 18:00:00.000000000 -0600
  6233. +++ busybox-1.23.0/archival/libipkg/ipkg_remove.h 2015-01-09 11:18:22.428197243 -0600
  6234. @@ -0,0 +1,33 @@
  6235. +/* ipkg_remove.h - the itsy package management system
  6236. +
  6237. + Carl D. Worth
  6238. +
  6239. + Copyright (C) 2001 University of Southern California
  6240. +
  6241. + This program is free software; you can redistribute it and/or
  6242. + modify it under the terms of the GNU General Public License as
  6243. + published by the Free Software Foundation; either version 2, or (at
  6244. + your option) any later version.
  6245. +
  6246. + This program is distributed in the hope that it will be useful, but
  6247. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6248. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6249. + General Public License for more details.
  6250. +*/
  6251. +
  6252. +#ifndef IPKG_REMOVE_H
  6253. +#define IPKG_REMOVE_H
  6254. +
  6255. +#include "pkg.h"
  6256. +#include "ipkg_conf.h"
  6257. +
  6258. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6259. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6260. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6261. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6262. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6263. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6264. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6265. +
  6266. +
  6267. +#endif
  6268. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_upgrade.c busybox-1.23.0/archival/libipkg/ipkg_upgrade.c
  6269. --- busybox-1.23.0.orig/archival/libipkg/ipkg_upgrade.c 1969-12-31 18:00:00.000000000 -0600
  6270. +++ busybox-1.23.0/archival/libipkg/ipkg_upgrade.c 2015-01-09 11:18:22.428197243 -0600
  6271. @@ -0,0 +1,79 @@
  6272. +/* ipkg_upgrade.c - the itsy package management system
  6273. +
  6274. + Carl D. Worth
  6275. + Copyright (C) 2001 University of Southern California
  6276. +
  6277. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6278. +
  6279. + This program is free software; you can redistribute it and/or
  6280. + modify it under the terms of the GNU General Public License as
  6281. + published by the Free Software Foundation; either version 2, or (at
  6282. + your option) any later version.
  6283. +
  6284. + This program is distributed in the hope that it will be useful, but
  6285. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6286. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6287. + General Public License for more details.
  6288. +*/
  6289. +
  6290. +#include "ipkg.h"
  6291. +#include "ipkg_install.h"
  6292. +#include "ipkg_message.h"
  6293. +
  6294. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6295. +
  6296. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6297. +{
  6298. + pkg_t *new;
  6299. + int cmp;
  6300. + char *old_version, *new_version;
  6301. +
  6302. + if (old->state_flag & SF_HOLD) {
  6303. + ipkg_message(conf, IPKG_NOTICE,
  6304. + "Not upgrading package %s which is marked "
  6305. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6306. + return 0;
  6307. + }
  6308. +
  6309. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6310. + if (new == NULL) {
  6311. + old_version = pkg_version_str_alloc(old);
  6312. + ipkg_message(conf, IPKG_NOTICE,
  6313. + "Assuming locally installed package %s (%s) "
  6314. + "is up to date.\n", old->name, old_version);
  6315. + free(old_version);
  6316. + return 0;
  6317. + }
  6318. +
  6319. + old_version = pkg_version_str_alloc(old);
  6320. + new_version = pkg_version_str_alloc(new);
  6321. +
  6322. + cmp = pkg_compare_versions(old, new);
  6323. + ipkg_message(conf, IPKG_DEBUG,
  6324. + "comparing visible versions of pkg %s:"
  6325. + "\n\t%s is installed "
  6326. + "\n\t%s is available "
  6327. + "\n\t%d was comparison result\n",
  6328. + old->name, old_version, new_version, cmp);
  6329. + if (cmp == 0) {
  6330. + ipkg_message(conf, IPKG_INFO,
  6331. + "Package %s (%s) installed in %s is up to date.\n",
  6332. + old->name, old_version, old->dest->name);
  6333. + free(old_version);
  6334. + free(new_version);
  6335. + return 0;
  6336. + } else if (cmp > 0) {
  6337. + ipkg_message(conf, IPKG_NOTICE,
  6338. + "Not downgrading package %s on %s from %s to %s.\n",
  6339. + old->name, old->dest->name, old_version, new_version);
  6340. + free(old_version);
  6341. + free(new_version);
  6342. + return 0;
  6343. + } else if (cmp < 0) {
  6344. + new->dest = old->dest;
  6345. + old->state_want = SW_DEINSTALL;
  6346. + }
  6347. +
  6348. + new->state_flag |= SF_USER;
  6349. + return ipkg_install_pkg(conf, new,1);
  6350. +}
  6351. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_upgrade.h busybox-1.23.0/archival/libipkg/ipkg_upgrade.h
  6352. --- busybox-1.23.0.orig/archival/libipkg/ipkg_upgrade.h 1969-12-31 18:00:00.000000000 -0600
  6353. +++ busybox-1.23.0/archival/libipkg/ipkg_upgrade.h 2015-01-09 11:18:22.428197243 -0600
  6354. @@ -0,0 +1,18 @@
  6355. +/* ipkg_upgrade.c - the itsy package management system
  6356. +
  6357. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6358. +
  6359. + This program is free software; you can redistribute it and/or
  6360. + modify it under the terms of the GNU General Public License as
  6361. + published by the Free Software Foundation; either version 2, or (at
  6362. + your option) any later version.
  6363. +
  6364. + This program is distributed in the hope that it will be useful, but
  6365. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6366. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6367. + General Public License for more details.
  6368. +*/
  6369. +
  6370. +#include "ipkg.h"
  6371. +
  6372. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6373. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_utils.c busybox-1.23.0/archival/libipkg/ipkg_utils.c
  6374. --- busybox-1.23.0.orig/archival/libipkg/ipkg_utils.c 1969-12-31 18:00:00.000000000 -0600
  6375. +++ busybox-1.23.0/archival/libipkg/ipkg_utils.c 2015-01-09 11:18:22.428197243 -0600
  6376. @@ -0,0 +1,185 @@
  6377. +/* ipkg_utils.c - the itsy package management system
  6378. +
  6379. + Steven M. Ayer
  6380. +
  6381. + Copyright (C) 2002 Compaq Computer Corporation
  6382. +
  6383. + This program is free software; you can redistribute it and/or
  6384. + modify it under the terms of the GNU General Public License as
  6385. + published by the Free Software Foundation; either version 2, or (at
  6386. + your option) any later version.
  6387. +
  6388. + This program is distributed in the hope that it will be useful, but
  6389. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6390. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6391. + General Public License for more details.
  6392. +*/
  6393. +
  6394. +#include "ipkg.h"
  6395. +#include <errno.h>
  6396. +#include <ctype.h>
  6397. +#include <sys/vfs.h>
  6398. +
  6399. +#include "ipkg_utils.h"
  6400. +#include "pkg.h"
  6401. +#include "pkg_hash.h"
  6402. +
  6403. +void push_error_list(struct errlist ** errors, char * msg);
  6404. +void reverse_error_list(struct errlist **errors);
  6405. +void free_error_list(struct errlist **errors);
  6406. +
  6407. +struct errlist* error_list;
  6408. +
  6409. +int get_available_blocks(char * filesystem)
  6410. +{
  6411. + struct statfs sfs;
  6412. +
  6413. + if(statfs(filesystem, &sfs)){
  6414. + fprintf(stderr, "bad statfs\n");
  6415. + return 0;
  6416. + }
  6417. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6418. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6419. +}
  6420. +
  6421. +char **read_raw_pkgs_from_file(const char *file_name)
  6422. +{
  6423. + FILE *fp;
  6424. + char **ret;
  6425. +
  6426. + if(!(fp = fopen(file_name, "r"))){
  6427. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6428. + return NULL;
  6429. + }
  6430. +
  6431. + ret = read_raw_pkgs_from_stream(fp);
  6432. +
  6433. + fclose(fp);
  6434. +
  6435. + return ret;
  6436. +}
  6437. +
  6438. +char **read_raw_pkgs_from_stream(FILE *fp)
  6439. +{
  6440. + char **raw = NULL, *buf, *scout;
  6441. + int count = 0;
  6442. + size_t size = 512;
  6443. +
  6444. + buf = malloc (size);
  6445. +
  6446. + while (fgets(buf, size, fp)) {
  6447. + while (strlen (buf) == (size - 1)
  6448. + && buf[size-2] != '\n') {
  6449. + size_t o = size - 1;
  6450. + size *= 2;
  6451. + buf = realloc (buf, size);
  6452. + if (fgets (buf + o, size - o, fp) == NULL)
  6453. + break;
  6454. + }
  6455. +
  6456. + if(!(count % 50))
  6457. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6458. +
  6459. + if((scout = strchr(buf, '\n')))
  6460. + *scout = '\0';
  6461. +
  6462. + raw[count++] = strdup(buf);
  6463. + }
  6464. +
  6465. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6466. + raw[count] = NULL;
  6467. +
  6468. + free (buf);
  6469. +
  6470. + return raw;
  6471. +}
  6472. +
  6473. +/* something to remove whitespace, a hash pooper */
  6474. +char *trim_alloc(char *line)
  6475. +{
  6476. + char *new;
  6477. + char *dest, *src, *end;
  6478. +
  6479. + new = malloc(strlen(line) + 1);
  6480. + if ( new == NULL ){
  6481. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6482. + return NULL;
  6483. + }
  6484. + dest = new, src = line, end = line + (strlen(line) - 1);
  6485. +
  6486. + /* remove it from the front */
  6487. + while(src &&
  6488. + isspace(*src) &&
  6489. + *src)
  6490. + src++;
  6491. + /* and now from the back */
  6492. + while((end > src) &&
  6493. + isspace(*end))
  6494. + end--;
  6495. + end++;
  6496. + *end = '\0';
  6497. + strcpy(new, src);
  6498. + /* this does from the first space
  6499. + * blasting away any versions stuff in depends
  6500. + while(src &&
  6501. + !isspace(*src) &&
  6502. + *src)
  6503. + *dest++ = *src++;
  6504. + *dest = '\0';
  6505. + */
  6506. +
  6507. + return new;
  6508. +}
  6509. +
  6510. +int line_is_blank(const char *line)
  6511. +{
  6512. + const char *s;
  6513. +
  6514. + for (s = line; *s; s++) {
  6515. + if (!isspace(*s))
  6516. + return 0;
  6517. + }
  6518. + return 1;
  6519. +}
  6520. +
  6521. +void push_error_list(struct errlist ** errors, char * msg){
  6522. + struct errlist *err_lst_tmp;
  6523. +
  6524. +
  6525. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6526. + err_lst_tmp->errmsg=strdup(msg) ;
  6527. + err_lst_tmp->next = *errors;
  6528. + *errors = err_lst_tmp;
  6529. +}
  6530. +
  6531. +
  6532. +void reverse_error_list(struct errlist **errors){
  6533. + struct errlist *result=NULL;
  6534. + struct errlist *current= *errors;
  6535. + struct errlist *next;
  6536. +
  6537. + while ( current != NULL ) {
  6538. + next = current->next;
  6539. + current->next=result;
  6540. + result=current;
  6541. + current=next;
  6542. + }
  6543. + *errors=result;
  6544. +
  6545. +}
  6546. +
  6547. +
  6548. +void free_error_list(struct errlist **errors){
  6549. + struct errlist *current = *errors;
  6550. +
  6551. + while (current != NULL) {
  6552. + free(current->errmsg);
  6553. + current = (*errors)->next;
  6554. + free(*errors);
  6555. + *errors = current;
  6556. + }
  6557. +
  6558. +
  6559. +}
  6560. +
  6561. +
  6562. diff -Nur busybox-1.23.0.orig/archival/libipkg/ipkg_utils.h busybox-1.23.0/archival/libipkg/ipkg_utils.h
  6563. --- busybox-1.23.0.orig/archival/libipkg/ipkg_utils.h 1969-12-31 18:00:00.000000000 -0600
  6564. +++ busybox-1.23.0/archival/libipkg/ipkg_utils.h 2015-01-09 11:18:22.428197243 -0600
  6565. @@ -0,0 +1,29 @@
  6566. +/* ipkg_utils.h - the itsy package management system
  6567. +
  6568. + Steven M. Ayer
  6569. +
  6570. + Copyright (C) 2002 Compaq Computer Corporation
  6571. +
  6572. + This program is free software; you can redistribute it and/or
  6573. + modify it under the terms of the GNU General Public License as
  6574. + published by the Free Software Foundation; either version 2, or (at
  6575. + your option) any later version.
  6576. +
  6577. + This program is distributed in the hope that it will be useful, but
  6578. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6579. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6580. + General Public License for more details.
  6581. +*/
  6582. +
  6583. +#ifndef IPKG_UTILS_H
  6584. +#define IPKG_UTILS_H
  6585. +
  6586. +#include "pkg.h"
  6587. +
  6588. +int get_available_blocks(char * filesystem);
  6589. +char **read_raw_pkgs_from_file(const char *file_name);
  6590. +char **read_raw_pkgs_from_stream(FILE *fp);
  6591. +char *trim_alloc(char * line);
  6592. +int line_is_blank(const char *line);
  6593. +
  6594. +#endif
  6595. diff -Nur busybox-1.23.0.orig/archival/libipkg/Kbuild busybox-1.23.0/archival/libipkg/Kbuild
  6596. --- busybox-1.23.0.orig/archival/libipkg/Kbuild 1969-12-31 18:00:00.000000000 -0600
  6597. +++ busybox-1.23.0/archival/libipkg/Kbuild 2015-01-09 11:18:22.424197243 -0600
  6598. @@ -0,0 +1,60 @@
  6599. +# Makefile for busybox
  6600. +#
  6601. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6602. +# Copyright (C) 2006 OpenWrt.org
  6603. +#
  6604. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6605. +
  6606. +LIBIPKG_CORE_OBJS:= \
  6607. + args.o \
  6608. + libipkg.o \
  6609. + user.o \
  6610. +
  6611. +LIBIPKG_CMD_OBJS:= \
  6612. + ipkg_cmd.o \
  6613. + ipkg_configure.o \
  6614. + ipkg_download.o \
  6615. + ipkg_install.o \
  6616. + ipkg_remove.o \
  6617. + ipkg_upgrade.o \
  6618. +
  6619. +LIBIPKG_DB_OBJS:= \
  6620. + hash_table.o \
  6621. + ipkg_conf.o \
  6622. + ipkg_utils.o \
  6623. + pkg.o \
  6624. + pkg_depends.o \
  6625. + pkg_extract.o \
  6626. + pkg_hash.o \
  6627. + pkg_parse.o \
  6628. + pkg_vec.o \
  6629. +
  6630. +LIBIPKG_LIST_OBJS:= \
  6631. + conffile.o \
  6632. + conffile_list.o \
  6633. + nv_pair.o \
  6634. + nv_pair_list.o \
  6635. + pkg_dest.o \
  6636. + pkg_dest_list.o \
  6637. + pkg_src.o \
  6638. + pkg_src_list.o \
  6639. + str_list.o \
  6640. + void_list.o \
  6641. +
  6642. +LIBIPKG_UTIL_OBJS:= \
  6643. + file_util.o \
  6644. + ipkg_message.o \
  6645. + str_util.o \
  6646. + xsystem.o \
  6647. +
  6648. +lib-y :=
  6649. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6650. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6651. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6652. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6653. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6654. +
  6655. +ifeq ($(strip $(IPKG_ARCH)),)
  6656. +IPKG_ARCH:=$(TARGET_ARCH)
  6657. +endif
  6658. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6659. diff -Nur busybox-1.23.0.orig/archival/libipkg/libipkg.c busybox-1.23.0/archival/libipkg/libipkg.c
  6660. --- busybox-1.23.0.orig/archival/libipkg/libipkg.c 1969-12-31 18:00:00.000000000 -0600
  6661. +++ busybox-1.23.0/archival/libipkg/libipkg.c 2015-01-09 11:18:22.428197243 -0600
  6662. @@ -0,0 +1,583 @@
  6663. +/* ipkglib.c - the itsy package management system
  6664. +
  6665. + Florina Boor
  6666. +
  6667. + Copyright (C) 2003 kernel concepts
  6668. +
  6669. + This program is free software; you can redistribute it and/or
  6670. + modify it under the terms of the GNU General Public License as
  6671. + published by the Free Software Foundation; either version 2, or (at
  6672. + your option) any later version.
  6673. +
  6674. + This program is distributed in the hope that it will be useful, but
  6675. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6676. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6677. + General Public License for more details.
  6678. +*/
  6679. +
  6680. +#include "ipkg.h"
  6681. +#include "ipkg_includes.h"
  6682. +#include "libipkg.h"
  6683. +
  6684. +#include "args.h"
  6685. +#include "ipkg_conf.h"
  6686. +#include "ipkg_cmd.h"
  6687. +#include "file_util.h"
  6688. +
  6689. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6690. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6691. + char *msg);
  6692. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6693. +int default_ipkg_files_callback(char *desc);
  6694. +int default_ipkg_status_callback(char *desc);
  6695. +char* default_ipkg_response_callback(char *question);
  6696. +
  6697. +
  6698. +ipkg_message_callback ipkg_cb_message = NULL;
  6699. +ipkg_response_callback ipkg_cb_response = NULL;
  6700. +ipkg_status_callback ipkg_cb_status = NULL;
  6701. +ipkg_list_callback ipkg_cb_list = NULL;
  6702. +
  6703. +
  6704. +int
  6705. +ipkg_init (ipkg_message_callback mcall,
  6706. + ipkg_response_callback rcall,
  6707. + args_t * args)
  6708. +{
  6709. + ipkg_cb_message = mcall;
  6710. + ipkg_cb_response = rcall;
  6711. +
  6712. + args_init (args);
  6713. +
  6714. + return 0;
  6715. +}
  6716. +
  6717. +
  6718. +int
  6719. +ipkg_deinit (args_t * args)
  6720. +{
  6721. + args_deinit (args);
  6722. + ipkg_cb_message = NULL;
  6723. + ipkg_cb_response = NULL;
  6724. +
  6725. + /* place other cleanup stuff here */
  6726. +
  6727. + return 0;
  6728. +}
  6729. +
  6730. +
  6731. +int
  6732. +ipkg_packages_list(args_t *args,
  6733. + const char *packages,
  6734. + ipkg_list_callback cblist,
  6735. + void *userdata)
  6736. +{
  6737. + ipkg_cmd_t *cmd;
  6738. + ipkg_conf_t ipkg_conf;
  6739. + int err;
  6740. +
  6741. + err = ipkg_conf_init (&ipkg_conf, args);
  6742. + if (err)
  6743. + {
  6744. + return err;
  6745. + }
  6746. +
  6747. + ipkg_cb_list = cblist;
  6748. + /* we need to do this because of static declarations,
  6749. + * maybe a good idea to change */
  6750. + cmd = ipkg_cmd_find ("list");
  6751. + if (packages)
  6752. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6753. + else
  6754. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6755. + ipkg_cb_list = NULL;
  6756. + ipkg_conf_deinit (&ipkg_conf);
  6757. + return (err);
  6758. +}
  6759. +
  6760. +
  6761. +int
  6762. +ipkg_packages_status(args_t *args,
  6763. + const char *packages,
  6764. + ipkg_status_callback cbstatus,
  6765. + void *userdata)
  6766. +{
  6767. + ipkg_cmd_t *cmd;
  6768. + ipkg_conf_t ipkg_conf;
  6769. + int err;
  6770. +
  6771. + err = ipkg_conf_init (&ipkg_conf, args);
  6772. + if (err)
  6773. + {
  6774. + return err;
  6775. + }
  6776. +
  6777. + ipkg_cb_status = cbstatus;
  6778. +
  6779. + /* we need to do this because of static declarations,
  6780. + * maybe a good idea to change */
  6781. + cmd = ipkg_cmd_find ("status");
  6782. + if (packages)
  6783. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6784. + else
  6785. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6786. +
  6787. + ipkg_cb_status = NULL;
  6788. + ipkg_conf_deinit (&ipkg_conf);
  6789. + return (err);
  6790. +}
  6791. +
  6792. +
  6793. +int
  6794. +ipkg_packages_info(args_t *args,
  6795. + const char *packages,
  6796. + ipkg_status_callback cbstatus,
  6797. + void *userdata)
  6798. +{
  6799. + ipkg_cmd_t *cmd;
  6800. + ipkg_conf_t ipkg_conf;
  6801. + int err;
  6802. +
  6803. + err = ipkg_conf_init (&ipkg_conf, args);
  6804. + if (err)
  6805. + {
  6806. + return err;
  6807. + }
  6808. +
  6809. + ipkg_cb_status = cbstatus;
  6810. +
  6811. + /* we need to do this because of static declarations,
  6812. + * maybe a good idea to change */
  6813. + cmd = ipkg_cmd_find ("info");
  6814. + if (packages)
  6815. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6816. + else
  6817. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6818. +
  6819. + ipkg_cb_status = NULL;
  6820. + ipkg_conf_deinit (&ipkg_conf);
  6821. + return (err);
  6822. +}
  6823. +
  6824. +
  6825. +int
  6826. +ipkg_packages_install (args_t * args, const char *name)
  6827. +{
  6828. + ipkg_cmd_t *cmd;
  6829. + ipkg_conf_t ipkg_conf;
  6830. + int err;
  6831. +
  6832. + /* this error should be handled in application */
  6833. + if (!name || !strlen (name))
  6834. + return (-1);
  6835. +
  6836. + err = ipkg_conf_init (&ipkg_conf, args);
  6837. + if (err)
  6838. + {
  6839. + return err;
  6840. + }
  6841. +
  6842. + /* we need to do this because of static declarations,
  6843. + * maybe a good idea to change */
  6844. + cmd = ipkg_cmd_find ("install");
  6845. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6846. +
  6847. + ipkg_conf_deinit(&ipkg_conf);
  6848. + return (err);
  6849. +}
  6850. +
  6851. +
  6852. +int
  6853. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6854. +{
  6855. + ipkg_cmd_t *cmd;
  6856. + ipkg_conf_t ipkg_conf;
  6857. + int err;
  6858. +
  6859. + /* this error should be handled in application */
  6860. + if (!name || !strlen (name))
  6861. + return (-1);
  6862. +
  6863. + err = ipkg_conf_init (&ipkg_conf, args);
  6864. + if (err)
  6865. + {
  6866. + return err;
  6867. + }
  6868. +
  6869. + /* we need to do this because of static declarations,
  6870. + * maybe a good idea to change */
  6871. + if (purge)
  6872. + cmd = ipkg_cmd_find ("purge");
  6873. + else
  6874. + cmd = ipkg_cmd_find ("remove");
  6875. +
  6876. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6877. +
  6878. + ipkg_conf_deinit(&ipkg_conf);
  6879. + return (err);
  6880. +}
  6881. +
  6882. +
  6883. +int
  6884. +ipkg_lists_update(args_t *args)
  6885. +{
  6886. + ipkg_cmd_t *cmd;
  6887. + ipkg_conf_t ipkg_conf;
  6888. + int err;
  6889. +
  6890. + err = ipkg_conf_init (&ipkg_conf, args);
  6891. + if (err)
  6892. + {
  6893. + return err;
  6894. + }
  6895. +
  6896. + /* we need to do this because of static declarations,
  6897. + * maybe a good idea to change */
  6898. + cmd = ipkg_cmd_find ("update");
  6899. +
  6900. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6901. +
  6902. + ipkg_conf_deinit(&ipkg_conf);
  6903. + return (err);
  6904. +}
  6905. +
  6906. +
  6907. +int
  6908. +ipkg_packages_upgrade(args_t *args)
  6909. +{
  6910. + ipkg_cmd_t *cmd;
  6911. + ipkg_conf_t ipkg_conf;
  6912. + int err;
  6913. +
  6914. + err = ipkg_conf_init (&ipkg_conf, args);
  6915. + if (err)
  6916. + {
  6917. + return err;
  6918. + }
  6919. +
  6920. + /* we need to do this because of static declarations,
  6921. + * maybe a good idea to change */
  6922. + cmd = ipkg_cmd_find ("upgrade");
  6923. +
  6924. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6925. +
  6926. + ipkg_conf_deinit(&ipkg_conf);
  6927. + return (err);
  6928. +}
  6929. +
  6930. +
  6931. +int
  6932. +ipkg_packages_download (args_t * args, const char *name)
  6933. +{
  6934. + ipkg_cmd_t *cmd;
  6935. + ipkg_conf_t ipkg_conf;
  6936. + int err;
  6937. +
  6938. + /* this error should be handled in application */
  6939. + if (!name || !strlen (name))
  6940. + return (-1);
  6941. +
  6942. + err = ipkg_conf_init (&ipkg_conf, args);
  6943. + if (err)
  6944. + {
  6945. + return err;
  6946. + }
  6947. +
  6948. + /* we need to do this because of static declarations,
  6949. + * maybe a good idea to change */
  6950. + cmd = ipkg_cmd_find ("download");
  6951. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6952. +
  6953. + ipkg_conf_deinit(&ipkg_conf);
  6954. + return (err);
  6955. +}
  6956. +
  6957. +
  6958. +int
  6959. +ipkg_package_files(args_t *args,
  6960. + const char *name,
  6961. + ipkg_list_callback cblist,
  6962. + void *userdata)
  6963. +{
  6964. + ipkg_cmd_t *cmd;
  6965. + ipkg_conf_t ipkg_conf;
  6966. + int err;
  6967. +
  6968. + /* this error should be handled in application */
  6969. + if (!name || !strlen (name))
  6970. + return (-1);
  6971. +
  6972. + err = ipkg_conf_init (&ipkg_conf, args);
  6973. + if (err)
  6974. + {
  6975. + return err;
  6976. + }
  6977. +
  6978. + ipkg_cb_list = cblist;
  6979. +
  6980. + /* we need to do this because of static declarations,
  6981. + * maybe a good idea to change */
  6982. + cmd = ipkg_cmd_find ("files");
  6983. +
  6984. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6985. +
  6986. + ipkg_cb_list = NULL;
  6987. + ipkg_conf_deinit(&ipkg_conf);
  6988. + return (err);
  6989. +}
  6990. +
  6991. +
  6992. +int
  6993. +ipkg_file_search(args_t *args,
  6994. + const char *file,
  6995. + ipkg_list_callback cblist,
  6996. + void *userdata)
  6997. +{
  6998. + ipkg_cmd_t *cmd;
  6999. + ipkg_conf_t ipkg_conf;
  7000. + int err;
  7001. +
  7002. + /* this error should be handled in application */
  7003. + if (!file || !strlen (file))
  7004. + return (-1);
  7005. +
  7006. + err = ipkg_conf_init (&ipkg_conf, args);
  7007. + if (err)
  7008. + {
  7009. + return err;
  7010. + }
  7011. +
  7012. + ipkg_cb_list = cblist;
  7013. +
  7014. + /* we need to do this because of static declarations,
  7015. + * maybe a good idea to change */
  7016. + cmd = ipkg_cmd_find ("search");
  7017. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7018. +
  7019. + ipkg_cb_list = NULL;
  7020. + ipkg_conf_deinit(&ipkg_conf);
  7021. + return(err);
  7022. +}
  7023. +
  7024. +
  7025. +int
  7026. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7027. +{
  7028. + ipkg_cmd_t *cmd;
  7029. + ipkg_conf_t ipkg_conf;
  7030. + int err;
  7031. +
  7032. + /* this error should be handled in application */
  7033. + if (!file || !strlen (file))
  7034. + return (-1);
  7035. +
  7036. + err = ipkg_conf_init (&ipkg_conf, args);
  7037. + if (err)
  7038. + {
  7039. + return err;
  7040. + }
  7041. +
  7042. + /* we need to do this because of static declarations,
  7043. + * maybe a good idea to change */
  7044. + cmd = ipkg_cmd_find (command);
  7045. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7046. +
  7047. + ipkg_conf_deinit(&ipkg_conf);
  7048. + return(err);
  7049. +}
  7050. +
  7051. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7052. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7053. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7054. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7055. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7056. +
  7057. +
  7058. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7059. + char *msg)
  7060. +{
  7061. + if (conf && (conf->verbosity < level)) {
  7062. + return 0;
  7063. + } else {
  7064. + if ( level == IPKG_ERROR )
  7065. + push_error_list(&error_list, msg);
  7066. + else
  7067. + printf(msg);
  7068. + }
  7069. + return 0;
  7070. +}
  7071. +
  7072. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7073. +{
  7074. + if (desc)
  7075. + printf("%s - %s - %s\n", name, version, desc);
  7076. + else
  7077. + printf("%s - %s\n", name, version);
  7078. + return 0;
  7079. +}
  7080. +
  7081. +int default_ipkg_files_callback(char *desc)
  7082. +{
  7083. + if (desc)
  7084. + printf("%s\n", desc);
  7085. + return 0;
  7086. +}
  7087. +
  7088. +int default_ipkg_status_callback(char *desc)
  7089. +{
  7090. + printf("%s\n", desc);
  7091. + return 0;
  7092. +}
  7093. +
  7094. +char* default_ipkg_response_callback(char *question)
  7095. +{
  7096. + char *response = NULL;
  7097. + printf(question);
  7098. + fflush(stdout);
  7099. + do {
  7100. + response = (char *)file_read_line_alloc(stdin);
  7101. + } while (response == NULL);
  7102. + return response;
  7103. +}
  7104. +
  7105. +/* This is used for backward compatibility */
  7106. +int
  7107. +ipkg_op (int argc, char *argv[])
  7108. +{
  7109. + int err, optind_;
  7110. + args_t args;
  7111. + char *cmd_name;
  7112. + ipkg_cmd_t *cmd;
  7113. + ipkg_conf_t ipkg_conf;
  7114. + const char *message = "ipkg must have one sub-command argument";
  7115. + FILE *f;
  7116. + struct mntent *mnt;
  7117. + int remountroot;
  7118. +
  7119. + args_init (&args);
  7120. +
  7121. + optind_ = args_parse (&args, argc, argv);
  7122. + if (optind_ == argc || optind_ < 0)
  7123. + {
  7124. + args_usage(message);
  7125. + }
  7126. +
  7127. + cmd_name = argv[optind_++];
  7128. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7129. + read anything from there.
  7130. +*/
  7131. + if ( !strcmp(cmd_name,"print-architecture") ||
  7132. + !strcmp(cmd_name,"print_architecture") ||
  7133. + !strcmp(cmd_name,"print-installation-architecture") ||
  7134. + !strcmp(cmd_name,"print_installation_architecture") )
  7135. + args.nocheckfordirorfile = 1;
  7136. +
  7137. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7138. + read anything from there.
  7139. +*/
  7140. + if ( !strcmp(cmd_name,"flag") ||
  7141. + !strcmp(cmd_name,"configure") ||
  7142. + !strcmp(cmd_name,"remove") ||
  7143. + !strcmp(cmd_name,"files") ||
  7144. + !strcmp(cmd_name,"search") ||
  7145. + !strcmp(cmd_name,"compare_versions") ||
  7146. + !strcmp(cmd_name,"compare-versions") ||
  7147. + !strcmp(cmd_name,"list_installed") ||
  7148. + !strcmp(cmd_name,"list-installed") ||
  7149. + !strcmp(cmd_name,"status") )
  7150. + args.noreadfeedsfile = 1;
  7151. +
  7152. +
  7153. +
  7154. +
  7155. + err = ipkg_conf_init (&ipkg_conf, &args);
  7156. + if (err)
  7157. + {
  7158. + return err;
  7159. + }
  7160. +
  7161. + args_deinit (&args);
  7162. +
  7163. + ipkg_cb_message = default_ipkg_message_callback;
  7164. + ipkg_cb_response = default_ipkg_response_callback;
  7165. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7166. + if ( strcmp(cmd_name, "files")==0)
  7167. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7168. + else
  7169. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7170. +
  7171. + cmd = ipkg_cmd_find (cmd_name);
  7172. + if (cmd == NULL)
  7173. + {
  7174. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7175. + cmd_name);
  7176. + args_usage (NULL);
  7177. + }
  7178. +
  7179. + if (cmd->requires_args && optind_ == argc)
  7180. + {
  7181. + fprintf (stderr,
  7182. + "%s: the ``%s'' command requires at least one argument\n",
  7183. + __FUNCTION__, cmd_name);
  7184. + args_usage (NULL);
  7185. + }
  7186. +
  7187. + remountroot = 0;
  7188. + /* check if /dev/root is mounted read-only */
  7189. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7190. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7191. +
  7192. + while ((mnt = getmntent(f)) != NULL) {
  7193. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7194. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7195. + remountroot = 1;
  7196. + }
  7197. + }
  7198. +
  7199. + endmntent(f);
  7200. +
  7201. + if (remountroot) {
  7202. + if ( !strcmp(cmd_name,"install") ||
  7203. + !strcmp(cmd_name,"update") ||
  7204. + !strcmp(cmd_name,"upgrade") ||
  7205. + !strcmp(cmd_name,"flag") ||
  7206. + !strcmp(cmd_name,"configure") ||
  7207. + !strcmp(cmd_name,"remove") ) {
  7208. + /* mount rootfs read-write */
  7209. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7210. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7211. + }
  7212. + }
  7213. +
  7214. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7215. +
  7216. + ipkg_conf_deinit (&ipkg_conf);
  7217. +
  7218. + if (remountroot) {
  7219. + if ( !strcmp(cmd_name,"install") ||
  7220. + !strcmp(cmd_name,"update") ||
  7221. + !strcmp(cmd_name,"upgrade") ||
  7222. + !strcmp(cmd_name,"flag") ||
  7223. + !strcmp(cmd_name,"configure") ||
  7224. + !strcmp(cmd_name,"remove") ) {
  7225. + sync();
  7226. + /* mount rootfs read-only */
  7227. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7228. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7229. + }
  7230. + }
  7231. +
  7232. + /* check if cfgfs exists */
  7233. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7234. + if ( !strcmp(cmd_name,"install") ||
  7235. + !strcmp(cmd_name,"update") ||
  7236. + !strcmp(cmd_name,"upgrade")) {
  7237. + if (system("cfgfs status -q") != 0) {
  7238. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7239. + fprintf (stdout, "You can check via cfgfs status\n");
  7240. + }
  7241. + }
  7242. + }
  7243. +
  7244. + return err;
  7245. +}
  7246. diff -Nur busybox-1.23.0.orig/archival/libipkg/libipkg.h busybox-1.23.0/archival/libipkg/libipkg.h
  7247. --- busybox-1.23.0.orig/archival/libipkg/libipkg.h 1969-12-31 18:00:00.000000000 -0600
  7248. +++ busybox-1.23.0/archival/libipkg/libipkg.h 2015-01-09 11:18:22.428197243 -0600
  7249. @@ -0,0 +1,78 @@
  7250. +/* ipkglib.h - the itsy package management system
  7251. +
  7252. + Florian Boor <florian.boor@kernelconcepts.de>
  7253. +
  7254. + This program is free software; you can redistribute it and/or
  7255. + modify it under the terms of the GNU General Public License as
  7256. + published by the Free Software Foundation; either version 2, or (at
  7257. + your option) any later version.
  7258. +
  7259. + This program is distributed in the hope that it will be useful, but
  7260. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7261. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7262. + General Public License for more details.
  7263. +*/
  7264. +
  7265. +#ifndef IPKGLIB_H
  7266. +#define IPKGLIB_H
  7267. +
  7268. +#include "ipkg_conf.h"
  7269. +#include "ipkg_message.h"
  7270. +
  7271. +#include "args.h"
  7272. +#include "pkg.h"
  7273. +
  7274. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7275. + char *msg);
  7276. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7277. + pkg_state_status_t status, void *userdata);
  7278. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7279. + void *userdata);
  7280. +typedef char* (*ipkg_response_callback)(char *question);
  7281. +
  7282. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7283. +extern int ipkg_init (ipkg_message_callback mcall,
  7284. + ipkg_response_callback rcall,
  7285. + args_t * args);
  7286. +
  7287. +extern int ipkg_deinit (args_t *args);
  7288. +extern int ipkg_packages_list(args_t *args,
  7289. + const char *packages,
  7290. + ipkg_list_callback cblist,
  7291. + void *userdata);
  7292. +extern int ipkg_packages_status(args_t *args,
  7293. + const char *packages,
  7294. + ipkg_status_callback cbstatus,
  7295. + void *userdata);
  7296. +extern int ipkg_packages_info(args_t *args,
  7297. + const char *packages,
  7298. + ipkg_status_callback cbstatus,
  7299. + void *userdata);
  7300. +extern int ipkg_packages_install(args_t *args, const char *name);
  7301. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7302. +extern int ipkg_lists_update(args_t *args);
  7303. +extern int ipkg_packages_upgrade(args_t *args);
  7304. +extern int ipkg_packages_download(args_t *args, const char *name);
  7305. +extern int ipkg_package_files(args_t *args,
  7306. + const char *name,
  7307. + ipkg_list_callback cblist,
  7308. + void *userdata);
  7309. +extern int ipkg_file_search(args_t *args,
  7310. + const char *file,
  7311. + ipkg_list_callback cblist,
  7312. + void *userdata);
  7313. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7314. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7315. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7316. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7317. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7318. +
  7319. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7320. +extern ipkg_response_callback ipkg_cb_response;
  7321. +extern ipkg_status_callback ipkg_cb_status;
  7322. +extern ipkg_list_callback ipkg_cb_list;
  7323. +extern void push_error_list(struct errlist **errors,char * msg);
  7324. +extern void reverse_error_list(struct errlist **errors);
  7325. +extern void free_error_list(struct errlist **errors);
  7326. +
  7327. +#endif
  7328. diff -Nur busybox-1.23.0.orig/archival/libipkg/nv_pair.c busybox-1.23.0/archival/libipkg/nv_pair.c
  7329. --- busybox-1.23.0.orig/archival/libipkg/nv_pair.c 1969-12-31 18:00:00.000000000 -0600
  7330. +++ busybox-1.23.0/archival/libipkg/nv_pair.c 2015-01-09 11:18:22.428197243 -0600
  7331. @@ -0,0 +1,40 @@
  7332. +/* nv_pair.c - the itsy package management system
  7333. +
  7334. + Carl D. Worth
  7335. +
  7336. + Copyright (C) 2001 University of Southern California
  7337. +
  7338. + This program is free software; you can redistribute it and/or
  7339. + modify it under the terms of the GNU General Public License as
  7340. + published by the Free Software Foundation; either version 2, or (at
  7341. + your option) any later version.
  7342. +
  7343. + This program is distributed in the hope that it will be useful, but
  7344. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7345. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7346. + General Public License for more details.
  7347. +*/
  7348. +
  7349. +#include "ipkg.h"
  7350. +
  7351. +#include "nv_pair.h"
  7352. +#include "str_util.h"
  7353. +
  7354. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7355. +{
  7356. + nv_pair->name = str_dup_safe(name);
  7357. + nv_pair->value = str_dup_safe(value);
  7358. +
  7359. + return 0;
  7360. +}
  7361. +
  7362. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7363. +{
  7364. + free(nv_pair->name);
  7365. + nv_pair->name = NULL;
  7366. +
  7367. + free(nv_pair->value);
  7368. + nv_pair->value = NULL;
  7369. +}
  7370. +
  7371. +
  7372. diff -Nur busybox-1.23.0.orig/archival/libipkg/nv_pair.h busybox-1.23.0/archival/libipkg/nv_pair.h
  7373. --- busybox-1.23.0.orig/archival/libipkg/nv_pair.h 1969-12-31 18:00:00.000000000 -0600
  7374. +++ busybox-1.23.0/archival/libipkg/nv_pair.h 2015-01-09 11:18:22.428197243 -0600
  7375. @@ -0,0 +1,32 @@
  7376. +/* nv_pair.h - the itsy package management system
  7377. +
  7378. + Carl D. Worth
  7379. +
  7380. + Copyright (C) 2001 University of Southern California
  7381. +
  7382. + This program is free software; you can redistribute it and/or
  7383. + modify it under the terms of the GNU General Public License as
  7384. + published by the Free Software Foundation; either version 2, or (at
  7385. + your option) any later version.
  7386. +
  7387. + This program is distributed in the hope that it will be useful, but
  7388. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7389. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7390. + General Public License for more details.
  7391. +*/
  7392. +
  7393. +#ifndef NV_PAIR_H
  7394. +#define NV_PAIR_H
  7395. +
  7396. +typedef struct nv_pair nv_pair_t;
  7397. +struct nv_pair
  7398. +{
  7399. + char *name;
  7400. + char *value;
  7401. +};
  7402. +
  7403. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7404. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7405. +
  7406. +#endif
  7407. +
  7408. diff -Nur busybox-1.23.0.orig/archival/libipkg/nv_pair_list.c busybox-1.23.0/archival/libipkg/nv_pair_list.c
  7409. --- busybox-1.23.0.orig/archival/libipkg/nv_pair_list.c 1969-12-31 18:00:00.000000000 -0600
  7410. +++ busybox-1.23.0/archival/libipkg/nv_pair_list.c 2015-01-09 11:18:22.428197243 -0600
  7411. @@ -0,0 +1,98 @@
  7412. +/* nv_pair_list.c - the itsy package management system
  7413. +
  7414. + Carl D. Worth
  7415. +
  7416. + Copyright (C) 2001 University of Southern California
  7417. +
  7418. + This program is free software; you can redistribute it and/or
  7419. + modify it under the terms of the GNU General Public License as
  7420. + published by the Free Software Foundation; either version 2, or (at
  7421. + your option) any later version.
  7422. +
  7423. + This program is distributed in the hope that it will be useful, but
  7424. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7425. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7426. + General Public License for more details.
  7427. +*/
  7428. +
  7429. +#include "ipkg.h"
  7430. +
  7431. +#include "nv_pair.h"
  7432. +#include "void_list.h"
  7433. +#include "nv_pair_list.h"
  7434. +
  7435. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7436. +{
  7437. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7438. +}
  7439. +
  7440. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7441. +{
  7442. + void_list_elt_deinit((void_list_elt_t *) elt);
  7443. +}
  7444. +
  7445. +int nv_pair_list_init(nv_pair_list_t *list)
  7446. +{
  7447. + return void_list_init((void_list_t *) list);
  7448. +}
  7449. +
  7450. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7451. +{
  7452. + nv_pair_list_elt_t *iter;
  7453. + nv_pair_t *nv_pair;
  7454. +
  7455. + for (iter = list->head; iter; iter = iter->next) {
  7456. + nv_pair = iter->data;
  7457. + nv_pair_deinit(nv_pair);
  7458. +
  7459. + /* malloced in nv_pair_list_append */
  7460. + free(nv_pair);
  7461. + iter->data = NULL;
  7462. + }
  7463. + void_list_deinit((void_list_t *) list);
  7464. +}
  7465. +
  7466. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7467. +{
  7468. + int err;
  7469. +
  7470. + /* freed in nv_pair_list_deinit */
  7471. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7472. +
  7473. + if (nv_pair == NULL) {
  7474. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7475. + return NULL;
  7476. + }
  7477. + nv_pair_init(nv_pair, name, value);
  7478. +
  7479. + err = void_list_append((void_list_t *) list, nv_pair);
  7480. + if (err) {
  7481. + return NULL;
  7482. + }
  7483. +
  7484. + return nv_pair;
  7485. +}
  7486. +
  7487. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7488. +{
  7489. + return void_list_push((void_list_t *) list, data);
  7490. +}
  7491. +
  7492. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7493. +{
  7494. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7495. +}
  7496. +
  7497. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7498. +{
  7499. + nv_pair_list_elt_t *iter;
  7500. + nv_pair_t *nv_pair;
  7501. +
  7502. + for (iter = list->head; iter; iter = iter->next) {
  7503. + nv_pair = iter->data;
  7504. + if (strcmp(nv_pair->name, name) == 0) {
  7505. + return nv_pair->value;
  7506. + }
  7507. + }
  7508. + return NULL;
  7509. +}
  7510. diff -Nur busybox-1.23.0.orig/archival/libipkg/nv_pair_list.h busybox-1.23.0/archival/libipkg/nv_pair_list.h
  7511. --- busybox-1.23.0.orig/archival/libipkg/nv_pair_list.h 1969-12-31 18:00:00.000000000 -0600
  7512. +++ busybox-1.23.0/archival/libipkg/nv_pair_list.h 2015-01-09 11:18:22.428197243 -0600
  7513. @@ -0,0 +1,60 @@
  7514. +/* nv_pair_list.h - the itsy package management system
  7515. +
  7516. + Carl D. Worth
  7517. +
  7518. + Copyright (C) 2001 University of Southern California
  7519. +
  7520. + This program is free software; you can redistribute it and/or
  7521. + modify it under the terms of the GNU General Public License as
  7522. + published by the Free Software Foundation; either version 2, or (at
  7523. + your option) any later version.
  7524. +
  7525. + This program is distributed in the hope that it will be useful, but
  7526. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7527. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7528. + General Public License for more details.
  7529. +*/
  7530. +
  7531. +#ifndef NV_PAIR_LIST_H
  7532. +#define NV_PAIR_LIST_H
  7533. +
  7534. +#include "nv_pair.h"
  7535. +#include "void_list.h"
  7536. +
  7537. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7538. +struct nv_pair_list_elt
  7539. +{
  7540. + nv_pair_list_elt_t *next;
  7541. + nv_pair_t *data;
  7542. +};
  7543. +
  7544. +typedef struct nv_pair_list nv_pair_list_t;
  7545. +struct nv_pair_list
  7546. +{
  7547. + nv_pair_list_elt_t pre_head;
  7548. + nv_pair_list_elt_t *head;
  7549. + nv_pair_list_elt_t *tail;
  7550. +};
  7551. +
  7552. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7553. +{
  7554. + if (list->head == NULL)
  7555. + return 1;
  7556. + else
  7557. + return 0;
  7558. +}
  7559. +
  7560. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7561. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7562. +
  7563. +int nv_pair_list_init(nv_pair_list_t *list);
  7564. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7565. +
  7566. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7567. + const char *name, const char *value);
  7568. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7569. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7570. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7571. +
  7572. +#endif
  7573. +
  7574. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg.c busybox-1.23.0/archival/libipkg/pkg.c
  7575. --- busybox-1.23.0.orig/archival/libipkg/pkg.c 1969-12-31 18:00:00.000000000 -0600
  7576. +++ busybox-1.23.0/archival/libipkg/pkg.c 2015-01-09 11:18:22.428197243 -0600
  7577. @@ -0,0 +1,1757 @@
  7578. +/* pkg.c - the itsy package management system
  7579. +
  7580. + Carl D. Worth
  7581. +
  7582. + Copyright (C) 2001 University of Southern California
  7583. +
  7584. + This program is free software; you can redistribute it and/or
  7585. + modify it under the terms of the GNU General Public License as
  7586. + published by the Free Software Foundation; either version 2, or (at
  7587. + your option) any later version.
  7588. +
  7589. + This program is distributed in the hope that it will be useful, but
  7590. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7591. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7592. + General Public License for more details.
  7593. +*/
  7594. +
  7595. +#include "ipkg.h"
  7596. +#include <ctype.h>
  7597. +#include <string.h>
  7598. +#include <errno.h>
  7599. +
  7600. +#include "pkg.h"
  7601. +
  7602. +#include "pkg_parse.h"
  7603. +#include "pkg_extract.h"
  7604. +#include "ipkg_message.h"
  7605. +#include "ipkg_utils.h"
  7606. +
  7607. +#include "sprintf_alloc.h"
  7608. +#include "file_util.h"
  7609. +#include "str_util.h"
  7610. +#include "xsystem.h"
  7611. +#include "ipkg_conf.h"
  7612. +
  7613. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7614. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7615. +
  7616. +typedef struct enum_map enum_map_t;
  7617. +struct enum_map
  7618. +{
  7619. + int value;
  7620. + const char *str;
  7621. +};
  7622. +
  7623. +static const enum_map_t pkg_state_want_map[] = {
  7624. + { SW_UNKNOWN, "unknown"},
  7625. + { SW_INSTALL, "install"},
  7626. + { SW_DEINSTALL, "deinstall"},
  7627. + { SW_PURGE, "purge"}
  7628. +};
  7629. +
  7630. +static const enum_map_t pkg_state_flag_map[] = {
  7631. + { SF_OK, "ok"},
  7632. + { SF_REINSTREQ, "reinstreq"},
  7633. + { SF_HOLD, "hold"},
  7634. + { SF_REPLACE, "replace"},
  7635. + { SF_NOPRUNE, "noprune"},
  7636. + { SF_PREFER, "prefer"},
  7637. + { SF_OBSOLETE, "obsolete"},
  7638. + { SF_USER, "user"},
  7639. +};
  7640. +
  7641. +static const enum_map_t pkg_state_status_map[] = {
  7642. + { SS_NOT_INSTALLED, "not-installed" },
  7643. + { SS_UNPACKED, "unpacked" },
  7644. + { SS_HALF_CONFIGURED, "half-configured" },
  7645. + { SS_INSTALLED, "installed" },
  7646. + { SS_HALF_INSTALLED, "half-installed" },
  7647. + { SS_CONFIG_FILES, "config-files" },
  7648. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7649. + { SS_REMOVAL_FAILED, "removal-failed" }
  7650. +};
  7651. +
  7652. +static int verrevcmp(const char *val, const char *ref);
  7653. +
  7654. +
  7655. +pkg_t *pkg_new(void)
  7656. +{
  7657. + pkg_t *pkg;
  7658. +
  7659. + pkg = malloc(sizeof(pkg_t));
  7660. + if (pkg == NULL) {
  7661. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7662. + return NULL;
  7663. + }
  7664. +
  7665. + pkg_init(pkg);
  7666. +
  7667. + return pkg;
  7668. +}
  7669. +
  7670. +int pkg_init(pkg_t *pkg)
  7671. +{
  7672. + memset(pkg, 0, sizeof(pkg_t));
  7673. + pkg->name = NULL;
  7674. + pkg->epoch = 0;
  7675. + pkg->version = NULL;
  7676. + pkg->revision = NULL;
  7677. + pkg->familiar_revision = NULL;
  7678. + pkg->dest = NULL;
  7679. + pkg->src = NULL;
  7680. + pkg->architecture = NULL;
  7681. + pkg->maintainer = NULL;
  7682. + pkg->section = NULL;
  7683. + pkg->description = NULL;
  7684. + pkg->state_want = SW_UNKNOWN;
  7685. + pkg->state_flag = SF_OK;
  7686. + pkg->state_status = SS_NOT_INSTALLED;
  7687. + pkg->depends_str = NULL;
  7688. + pkg->provides_str = NULL;
  7689. + pkg->depends_count = 0;
  7690. + pkg->depends = NULL;
  7691. + pkg->suggests_str = NULL;
  7692. + pkg->recommends_str = NULL;
  7693. + pkg->suggests_count = 0;
  7694. + pkg->recommends_count = 0;
  7695. +
  7696. + /* Abhaya: added init for conflicts fields */
  7697. + pkg->conflicts = NULL;
  7698. + pkg->conflicts_count = 0;
  7699. +
  7700. + /* added for replaces. Jamey 7/23/2002 */
  7701. + pkg->replaces = NULL;
  7702. + pkg->replaces_count = 0;
  7703. +
  7704. + pkg->pre_depends_count = 0;
  7705. + pkg->pre_depends_str = NULL;
  7706. + pkg->provides_count = 0;
  7707. + pkg->provides = NULL;
  7708. + pkg->filename = NULL;
  7709. + pkg->local_filename = NULL;
  7710. + pkg->tmp_unpack_dir = NULL;
  7711. + pkg->md5sum = NULL;
  7712. + pkg->size = NULL;
  7713. + pkg->installed_size = NULL;
  7714. + pkg->priority = NULL;
  7715. + pkg->source = NULL;
  7716. + conffile_list_init(&pkg->conffiles);
  7717. + pkg->installed_files = NULL;
  7718. + pkg->installed_files_ref_cnt = 0;
  7719. + pkg->essential = 0;
  7720. + pkg->provided_by_hand = 0;
  7721. +
  7722. + return 0;
  7723. +}
  7724. +
  7725. +void pkg_deinit(pkg_t *pkg)
  7726. +{
  7727. + free(pkg->name);
  7728. + pkg->name = NULL;
  7729. + pkg->epoch = 0;
  7730. + free(pkg->version);
  7731. + pkg->version = NULL;
  7732. + /* revision and familiar_revision share storage with version, so
  7733. + don't free */
  7734. + pkg->revision = NULL;
  7735. + pkg->familiar_revision = NULL;
  7736. + /* owned by ipkg_conf_t */
  7737. + pkg->dest = NULL;
  7738. + /* owned by ipkg_conf_t */
  7739. + pkg->src = NULL;
  7740. + free(pkg->architecture);
  7741. + pkg->architecture = NULL;
  7742. + free(pkg->maintainer);
  7743. + pkg->maintainer = NULL;
  7744. + free(pkg->section);
  7745. + pkg->section = NULL;
  7746. + free(pkg->description);
  7747. + pkg->description = NULL;
  7748. + pkg->state_want = SW_UNKNOWN;
  7749. + pkg->state_flag = SF_OK;
  7750. + pkg->state_status = SS_NOT_INSTALLED;
  7751. + free(pkg->depends_str);
  7752. + pkg->depends_str = NULL;
  7753. + free(pkg->provides_str);
  7754. + pkg->provides_str = NULL;
  7755. + pkg->depends_count = 0;
  7756. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7757. + pkg->pre_depends_count = 0;
  7758. + free(pkg->pre_depends_str);
  7759. + pkg->pre_depends_str = NULL;
  7760. + pkg->provides_count = 0;
  7761. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7762. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7763. + free(pkg->filename);
  7764. + pkg->filename = NULL;
  7765. + free(pkg->local_filename);
  7766. + pkg->local_filename = NULL;
  7767. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7768. + ipkg_install.c here. See comment in
  7769. + ipkg_install.c:cleanup_temporary_files */
  7770. + free(pkg->tmp_unpack_dir);
  7771. + pkg->tmp_unpack_dir = NULL;
  7772. + free(pkg->md5sum);
  7773. + pkg->md5sum = NULL;
  7774. + free(pkg->size);
  7775. + pkg->size = NULL;
  7776. + free(pkg->installed_size);
  7777. + pkg->installed_size = NULL;
  7778. + free(pkg->priority);
  7779. + pkg->priority = NULL;
  7780. + free(pkg->source);
  7781. + pkg->source = NULL;
  7782. + conffile_list_deinit(&pkg->conffiles);
  7783. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7784. + since if they are calling deinit, they should know. Maybe do an
  7785. + assertion here instead? */
  7786. + pkg->installed_files_ref_cnt = 1;
  7787. + pkg_free_installed_files(pkg);
  7788. + pkg->essential = 0;
  7789. +}
  7790. +
  7791. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7792. +{
  7793. + int err;
  7794. + char **raw;
  7795. + FILE *control_file;
  7796. +
  7797. + err = pkg_init(pkg);
  7798. + if (err) { return err; }
  7799. +
  7800. + pkg->local_filename = strdup(filename);
  7801. +
  7802. + control_file = tmpfile();
  7803. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7804. + if (err) { return err; }
  7805. +
  7806. + rewind(control_file);
  7807. + raw = read_raw_pkgs_from_stream(control_file);
  7808. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7809. +
  7810. + fclose(control_file);
  7811. +
  7812. + return 0;
  7813. +}
  7814. +
  7815. +/* Merge any new information in newpkg into oldpkg */
  7816. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7817. + newpkg, but should leave it usable. This rework is so that
  7818. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7819. +/*
  7820. + * uh, i thought that i had originally written this so that it took
  7821. + * two pkgs and returned a new one? we can do that again... -sma
  7822. + */
  7823. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7824. +{
  7825. + if (oldpkg == newpkg) {
  7826. + return 0;
  7827. + }
  7828. +
  7829. + if (!oldpkg->src)
  7830. + oldpkg->src = newpkg->src;
  7831. + if (!oldpkg->dest)
  7832. + oldpkg->dest = newpkg->dest;
  7833. + if (!oldpkg->architecture)
  7834. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7835. + if (!oldpkg->arch_priority)
  7836. + oldpkg->arch_priority = newpkg->arch_priority;
  7837. + if (!oldpkg->section)
  7838. + oldpkg->section = str_dup_safe(newpkg->section);
  7839. + if(!oldpkg->maintainer)
  7840. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7841. + if(!oldpkg->description)
  7842. + oldpkg->description = str_dup_safe(newpkg->description);
  7843. + if (set_status) {
  7844. + /* merge the state_flags from the new package */
  7845. + oldpkg->state_want = newpkg->state_want;
  7846. + oldpkg->state_status = newpkg->state_status;
  7847. + oldpkg->state_flag = newpkg->state_flag;
  7848. + } else {
  7849. + if (oldpkg->state_want == SW_UNKNOWN)
  7850. + oldpkg->state_want = newpkg->state_want;
  7851. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7852. + oldpkg->state_status = newpkg->state_status;
  7853. + oldpkg->state_flag |= newpkg->state_flag;
  7854. + }
  7855. +
  7856. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7857. + oldpkg->depends_str = newpkg->depends_str;
  7858. + newpkg->depends_str = NULL;
  7859. + oldpkg->depends_count = newpkg->depends_count;
  7860. + newpkg->depends_count = 0;
  7861. +
  7862. + oldpkg->depends = newpkg->depends;
  7863. + newpkg->depends = NULL;
  7864. +
  7865. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7866. + newpkg->pre_depends_str = NULL;
  7867. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7868. + newpkg->pre_depends_count = 0;
  7869. +
  7870. + oldpkg->recommends_str = newpkg->recommends_str;
  7871. + newpkg->recommends_str = NULL;
  7872. + oldpkg->recommends_count = newpkg->recommends_count;
  7873. + newpkg->recommends_count = 0;
  7874. +
  7875. + oldpkg->suggests_str = newpkg->suggests_str;
  7876. + newpkg->suggests_str = NULL;
  7877. + oldpkg->suggests_count = newpkg->suggests_count;
  7878. + newpkg->suggests_count = 0;
  7879. + }
  7880. +
  7881. + if (!oldpkg->provides_str) {
  7882. + oldpkg->provides_str = newpkg->provides_str;
  7883. + newpkg->provides_str = NULL;
  7884. + oldpkg->provides_count = newpkg->provides_count;
  7885. + newpkg->provides_count = 0;
  7886. +
  7887. + oldpkg->provides = newpkg->provides;
  7888. + newpkg->provides = NULL;
  7889. + }
  7890. +
  7891. + if (!oldpkg->conflicts_str) {
  7892. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7893. + newpkg->conflicts_str = NULL;
  7894. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7895. + newpkg->conflicts_count = 0;
  7896. +
  7897. + oldpkg->conflicts = newpkg->conflicts;
  7898. + newpkg->conflicts = NULL;
  7899. + }
  7900. +
  7901. + if (!oldpkg->replaces_str) {
  7902. + oldpkg->replaces_str = newpkg->replaces_str;
  7903. + newpkg->replaces_str = NULL;
  7904. + oldpkg->replaces_count = newpkg->replaces_count;
  7905. + newpkg->replaces_count = 0;
  7906. +
  7907. + oldpkg->replaces = newpkg->replaces;
  7908. + newpkg->replaces = NULL;
  7909. + }
  7910. +
  7911. + if (!oldpkg->filename)
  7912. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7913. + if (0)
  7914. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7915. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7916. + if (!oldpkg->local_filename)
  7917. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7918. + if (!oldpkg->tmp_unpack_dir)
  7919. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7920. + if (!oldpkg->md5sum)
  7921. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7922. + if (!oldpkg->size)
  7923. + oldpkg->size = str_dup_safe(newpkg->size);
  7924. + if (!oldpkg->installed_size)
  7925. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7926. + if (!oldpkg->priority)
  7927. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7928. + if (!oldpkg->source)
  7929. + oldpkg->source = str_dup_safe(newpkg->source);
  7930. + if (oldpkg->conffiles.head == NULL){
  7931. + oldpkg->conffiles = newpkg->conffiles;
  7932. + conffile_list_init(&newpkg->conffiles);
  7933. + }
  7934. + if (!oldpkg->installed_files){
  7935. + oldpkg->installed_files = newpkg->installed_files;
  7936. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7937. + newpkg->installed_files = NULL;
  7938. + }
  7939. + if (!oldpkg->essential)
  7940. + oldpkg->essential = newpkg->essential;
  7941. +
  7942. + return 0;
  7943. +}
  7944. +
  7945. +abstract_pkg_t *abstract_pkg_new(void)
  7946. +{
  7947. + abstract_pkg_t * ab_pkg;
  7948. +
  7949. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7950. +
  7951. + if (ab_pkg == NULL) {
  7952. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7953. + return NULL;
  7954. + }
  7955. +
  7956. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7957. + return NULL;
  7958. +
  7959. + return ab_pkg;
  7960. +}
  7961. +
  7962. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7963. +{
  7964. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7965. +
  7966. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7967. + if (ab_pkg->provided_by==NULL){
  7968. + return -1;
  7969. + }
  7970. + ab_pkg->dependencies_checked = 0;
  7971. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7972. +
  7973. + return 0;
  7974. +}
  7975. +
  7976. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7977. + char * temp_str;
  7978. + char **raw =NULL;
  7979. + char **raw_start=NULL;
  7980. +
  7981. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7982. + if (temp_str == NULL ){
  7983. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7984. + return;
  7985. + }
  7986. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7987. +
  7988. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7989. + if (raw == NULL ){
  7990. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7991. + return;
  7992. + }
  7993. +
  7994. + while(*raw){
  7995. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7996. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7997. + }
  7998. + }
  7999. + raw = raw_start;
  8000. + while (*raw) {
  8001. + if (raw!=NULL)
  8002. + free(*raw++);
  8003. + }
  8004. +
  8005. + free(raw_start);
  8006. + free(temp_str);
  8007. +
  8008. + return ;
  8009. +
  8010. +}
  8011. +
  8012. +char * pkg_formatted_info(pkg_t *pkg )
  8013. +{
  8014. + char *line;
  8015. + char * buff;
  8016. +
  8017. + buff = malloc(8192);
  8018. + if (buff == NULL) {
  8019. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8020. + return NULL;
  8021. + }
  8022. +
  8023. + buff[0] = '\0';
  8024. +
  8025. + line = pkg_formatted_field(pkg, "Package");
  8026. + strncat(buff ,line, strlen(line));
  8027. + free(line);
  8028. +
  8029. + line = pkg_formatted_field(pkg, "Version");
  8030. + strncat(buff ,line, strlen(line));
  8031. + free(line);
  8032. +
  8033. + line = pkg_formatted_field(pkg, "Depends");
  8034. + strncat(buff ,line, strlen(line));
  8035. + free(line);
  8036. +
  8037. + line = pkg_formatted_field(pkg, "Recommends");
  8038. + strncat(buff ,line, strlen(line));
  8039. + free(line);
  8040. +
  8041. + line = pkg_formatted_field(pkg, "Suggests");
  8042. + strncat(buff ,line, strlen(line));
  8043. + free(line);
  8044. +
  8045. + line = pkg_formatted_field(pkg, "Provides");
  8046. + strncat(buff ,line, strlen(line));
  8047. + free(line);
  8048. +
  8049. + line = pkg_formatted_field(pkg, "Replaces");
  8050. + strncat(buff ,line, strlen(line));
  8051. + free(line);
  8052. +
  8053. + line = pkg_formatted_field(pkg, "Conflicts");
  8054. + strncat(buff ,line, strlen(line));
  8055. + free(line);
  8056. +
  8057. + line = pkg_formatted_field(pkg, "Status");
  8058. + strncat(buff ,line, strlen(line));
  8059. + free(line);
  8060. +
  8061. + line = pkg_formatted_field(pkg, "Section");
  8062. + strncat(buff ,line, strlen(line));
  8063. + free(line);
  8064. +
  8065. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8066. + strncat(buff ,line, strlen(line));
  8067. + free(line);
  8068. +
  8069. + line = pkg_formatted_field(pkg, "Architecture");
  8070. + strncat(buff ,line, strlen(line));
  8071. + free(line);
  8072. +
  8073. + line = pkg_formatted_field(pkg, "Maintainer");
  8074. + strncat(buff ,line, strlen(line));
  8075. + free(line);
  8076. +
  8077. + line = pkg_formatted_field(pkg, "MD5sum");
  8078. + strncat(buff ,line, strlen(line));
  8079. + free(line);
  8080. +
  8081. + line = pkg_formatted_field(pkg, "Size");
  8082. + strncat(buff ,line, strlen(line));
  8083. + free(line);
  8084. +
  8085. + line = pkg_formatted_field(pkg, "Filename");
  8086. + strncat(buff ,line, strlen(line));
  8087. + free(line);
  8088. +
  8089. + line = pkg_formatted_field(pkg, "Conffiles");
  8090. + strncat(buff ,line, strlen(line));
  8091. + free(line);
  8092. +
  8093. + line = pkg_formatted_field(pkg, "Source");
  8094. + strncat(buff ,line, strlen(line));
  8095. + free(line);
  8096. +
  8097. + line = pkg_formatted_field(pkg, "Description");
  8098. + strncat(buff ,line, strlen(line));
  8099. + free(line);
  8100. +
  8101. + line = pkg_formatted_field(pkg, "Installed-Time");
  8102. + strncat(buff ,line, strlen(line));
  8103. + free(line);
  8104. +
  8105. + return buff;
  8106. +}
  8107. +
  8108. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8109. +{
  8110. + static size_t LINE_LEN = 128;
  8111. + char * temp = (char *)malloc(1);
  8112. + int len = 0;
  8113. + int flag_provide_false = 0;
  8114. +
  8115. +/*
  8116. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8117. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8118. +*/
  8119. +
  8120. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8121. + goto UNKNOWN_FMT_FIELD;
  8122. + }
  8123. +
  8124. + temp[0]='\0';
  8125. +
  8126. + switch (field[0])
  8127. + {
  8128. + case 'a':
  8129. + case 'A':
  8130. + if (strcasecmp(field, "Architecture") == 0) {
  8131. + /* Architecture */
  8132. + if (pkg->architecture) {
  8133. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8134. + if ( temp == NULL ){
  8135. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8136. + return NULL;
  8137. + }
  8138. + temp[0]='\0';
  8139. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8140. + }
  8141. + } else {
  8142. + goto UNKNOWN_FMT_FIELD;
  8143. + }
  8144. + break;
  8145. + case 'c':
  8146. + case 'C':
  8147. + if (strcasecmp(field, "Conffiles") == 0) {
  8148. + /* Conffiles */
  8149. + conffile_list_elt_t *iter;
  8150. + char confstr_[LINE_LEN];
  8151. +
  8152. + if (pkg->conffiles.head == NULL) {
  8153. + return temp;
  8154. + }
  8155. +
  8156. + len = 14 ;
  8157. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8158. + if (iter->data->name && iter->data->value) {
  8159. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8160. + }
  8161. + }
  8162. + temp = (char *)realloc(temp,len);
  8163. + if ( temp == NULL ){
  8164. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8165. + return NULL;
  8166. + }
  8167. + temp[0]='\0';
  8168. + strncpy(temp, "Conffiles:\n", 12);
  8169. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8170. + if (iter->data->name && iter->data->value) {
  8171. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8172. + strncat(temp, confstr_, strlen(confstr_));
  8173. + }
  8174. + }
  8175. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8176. + int i;
  8177. +
  8178. + if (pkg->conflicts_count) {
  8179. + char conflictstr[LINE_LEN];
  8180. + len = 14 ;
  8181. + for(i = 0; i < pkg->conflicts_count; i++) {
  8182. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8183. + }
  8184. + temp = (char *)realloc(temp,len);
  8185. + if ( temp == NULL ){
  8186. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8187. + return NULL;
  8188. + }
  8189. + temp[0]='\0';
  8190. + strncpy(temp, "Conflicts:", 11);
  8191. + for(i = 0; i < pkg->conflicts_count; i++) {
  8192. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8193. + strncat(temp, conflictstr, strlen(conflictstr));
  8194. + }
  8195. + strncat(temp, "\n", strlen("\n"));
  8196. + }
  8197. + } else {
  8198. + goto UNKNOWN_FMT_FIELD;
  8199. + }
  8200. + break;
  8201. + case 'd':
  8202. + case 'D':
  8203. + if (strcasecmp(field, "Depends") == 0) {
  8204. + /* Depends */
  8205. + int i;
  8206. +
  8207. + if (pkg->depends_count) {
  8208. + char depstr[LINE_LEN];
  8209. + len = 14 ;
  8210. + for(i = 0; i < pkg->depends_count; i++) {
  8211. + len = len + (strlen(pkg->depends_str[i])+4);
  8212. + }
  8213. + temp = (char *)realloc(temp,len);
  8214. + if ( temp == NULL ){
  8215. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8216. + return NULL;
  8217. + }
  8218. + temp[0]='\0';
  8219. + strncpy(temp, "Depends:", 10);
  8220. + for(i = 0; i < pkg->depends_count; i++) {
  8221. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8222. + strncat(temp, depstr, strlen(depstr));
  8223. + }
  8224. + strncat(temp, "\n", strlen("\n"));
  8225. + }
  8226. + } else if (strcasecmp(field, "Description") == 0) {
  8227. + /* Description */
  8228. + if (pkg->description) {
  8229. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8230. + if ( temp == NULL ){
  8231. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8232. + return NULL;
  8233. + }
  8234. + temp[0]='\0';
  8235. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8236. + }
  8237. + } else {
  8238. + goto UNKNOWN_FMT_FIELD;
  8239. + }
  8240. + break;
  8241. + case 'e':
  8242. + case 'E': {
  8243. + /* Essential */
  8244. + if (pkg->essential) {
  8245. + temp = (char *)realloc(temp,16);
  8246. + if ( temp == NULL ){
  8247. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8248. + return NULL;
  8249. + }
  8250. + temp[0]='\0';
  8251. + snprintf(temp, (16), "Essential: yes\n");
  8252. + }
  8253. + }
  8254. + break;
  8255. + case 'f':
  8256. + case 'F': {
  8257. + /* Filename */
  8258. + if (pkg->filename) {
  8259. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8260. + if ( temp == NULL ){
  8261. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8262. + return NULL;
  8263. + }
  8264. + temp[0]='\0';
  8265. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8266. + }
  8267. + }
  8268. + break;
  8269. + case 'i':
  8270. + case 'I': {
  8271. + if (strcasecmp(field, "Installed-Size") == 0) {
  8272. + /* Installed-Size */
  8273. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8274. + if ( temp == NULL ){
  8275. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8276. + return NULL;
  8277. + }
  8278. + temp[0]='\0';
  8279. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8280. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8281. + temp = (char *)realloc(temp,29);
  8282. + if ( temp == NULL ){
  8283. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8284. + return NULL;
  8285. + }
  8286. + temp[0]='\0';
  8287. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8288. + }
  8289. + }
  8290. + break;
  8291. + case 'm':
  8292. + case 'M': {
  8293. + /* Maintainer | MD5sum */
  8294. + if (strcasecmp(field, "Maintainer") == 0) {
  8295. + /* Maintainer */
  8296. + if (pkg->maintainer) {
  8297. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8298. + if ( temp == NULL ){
  8299. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8300. + return NULL;
  8301. + }
  8302. + temp[0]='\0';
  8303. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8304. + }
  8305. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8306. + /* MD5sum */
  8307. + if (pkg->md5sum) {
  8308. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8309. + if ( temp == NULL ){
  8310. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8311. + return NULL;
  8312. + }
  8313. + temp[0]='\0';
  8314. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8315. + }
  8316. + } else {
  8317. + goto UNKNOWN_FMT_FIELD;
  8318. + }
  8319. + }
  8320. + break;
  8321. + case 'p':
  8322. + case 'P': {
  8323. + if (strcasecmp(field, "Package") == 0) {
  8324. + /* Package */
  8325. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8326. + if ( temp == NULL ){
  8327. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8328. + return NULL;
  8329. + }
  8330. + temp[0]='\0';
  8331. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8332. + } else if (strcasecmp(field, "Priority") == 0) {
  8333. + /* Priority */
  8334. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8335. + if ( temp == NULL ){
  8336. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8337. + return NULL;
  8338. + }
  8339. + temp[0]='\0';
  8340. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8341. + } else if (strcasecmp(field, "Provides") == 0) {
  8342. + /* Provides */
  8343. + int i;
  8344. +
  8345. + if (pkg->provides_count) {
  8346. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8347. + for ( i=0; i < pkg->provides_count; i++ ){
  8348. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8349. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8350. + flag_provide_false = 1;
  8351. + }
  8352. + }
  8353. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8354. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8355. + char provstr[LINE_LEN];
  8356. + len = 15;
  8357. + for(i = 0; i < pkg->provides_count; i++) {
  8358. + len = len + (strlen(pkg->provides_str[i])+5);
  8359. + }
  8360. + temp = (char *)realloc(temp,len);
  8361. + if ( temp == NULL ){
  8362. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8363. + return NULL;
  8364. + }
  8365. + temp[0]='\0';
  8366. + strncpy(temp, "Provides:", 12);
  8367. + for(i = 0; i < pkg->provides_count; i++) {
  8368. + if (strlen(pkg->provides_str[i])>0){;
  8369. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8370. + strncat(temp, provstr, strlen(provstr));
  8371. + }
  8372. + }
  8373. + strncat(temp, "\n", strlen("\n"));
  8374. + }
  8375. + }
  8376. + } else {
  8377. + goto UNKNOWN_FMT_FIELD;
  8378. + }
  8379. + }
  8380. + break;
  8381. + case 'r':
  8382. + case 'R': {
  8383. + int i;
  8384. + /* Replaces | Recommends*/
  8385. + if (strcasecmp (field, "Replaces") == 0) {
  8386. + if (pkg->replaces_count) {
  8387. + char replstr[LINE_LEN];
  8388. + len = 14;
  8389. + for (i = 0; i < pkg->replaces_count; i++) {
  8390. + len = len + (strlen(pkg->replaces_str[i])+5);
  8391. + }
  8392. + temp = (char *)realloc(temp,len);
  8393. + if ( temp == NULL ){
  8394. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8395. + return NULL;
  8396. + }
  8397. + temp[0]='\0';
  8398. + strncpy(temp, "Replaces:", 12);
  8399. + for (i = 0; i < pkg->replaces_count; i++) {
  8400. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8401. + strncat(temp, replstr, strlen(replstr));
  8402. + }
  8403. + strncat(temp, "\n", strlen("\n"));
  8404. + }
  8405. + } else if (strcasecmp (field, "Recommends") == 0) {
  8406. + if (pkg->recommends_count) {
  8407. + char recstr[LINE_LEN];
  8408. + len = 15;
  8409. + for(i = 0; i < pkg->recommends_count; i++) {
  8410. + len = len + (strlen( pkg->recommends_str[i])+5);
  8411. + }
  8412. + temp = (char *)realloc(temp,len);
  8413. + if ( temp == NULL ){
  8414. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8415. + return NULL;
  8416. + }
  8417. + temp[0]='\0';
  8418. + strncpy(temp, "Recommends:", 13);
  8419. + for(i = 0; i < pkg->recommends_count; i++) {
  8420. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8421. + strncat(temp, recstr, strlen(recstr));
  8422. + }
  8423. + strncat(temp, "\n", strlen("\n"));
  8424. + }
  8425. + } else {
  8426. + goto UNKNOWN_FMT_FIELD;
  8427. + }
  8428. + }
  8429. + break;
  8430. + case 's':
  8431. + case 'S': {
  8432. + /* Section | Size | Source | Status | Suggests */
  8433. + if (strcasecmp(field, "Section") == 0) {
  8434. + /* Section */
  8435. + if (pkg->section) {
  8436. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8437. + if ( temp == NULL ){
  8438. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8439. + return NULL;
  8440. + }
  8441. + temp[0]='\0';
  8442. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8443. + }
  8444. + } else if (strcasecmp(field, "Size") == 0) {
  8445. + /* Size */
  8446. + if (pkg->size) {
  8447. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8448. + if ( temp == NULL ){
  8449. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8450. + return NULL;
  8451. + }
  8452. + temp[0]='\0';
  8453. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8454. + }
  8455. + } else if (strcasecmp(field, "Source") == 0) {
  8456. + /* Source */
  8457. + if (pkg->source) {
  8458. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8459. + if ( temp == NULL ){
  8460. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8461. + return NULL;
  8462. + }
  8463. + temp[0]='\0';
  8464. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8465. + }
  8466. + } else if (strcasecmp(field, "Status") == 0) {
  8467. + /* Status */
  8468. + /* Benjamin Pineau note: we should avoid direct usage of
  8469. + * strlen(arg) without keeping "arg" for later free()
  8470. + */
  8471. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8472. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8473. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8474. +
  8475. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8476. + temp = (char *)realloc(temp,sum_of_sizes);
  8477. + if ( temp == NULL ){
  8478. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8479. + return NULL;
  8480. + }
  8481. + temp[0]='\0';
  8482. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8483. + free(pflag);
  8484. + free(pwant);
  8485. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8486. + free(pstat);
  8487. + } else if (strcasecmp(field, "Suggests") == 0) {
  8488. + if (pkg->suggests_count) {
  8489. + int i;
  8490. + char sugstr[LINE_LEN];
  8491. + len = 13;
  8492. + for(i = 0; i < pkg->suggests_count; i++) {
  8493. + len = len + (strlen(pkg->suggests_str[i])+5);
  8494. + }
  8495. + temp = (char *)realloc(temp,len);
  8496. + if ( temp == NULL ){
  8497. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8498. + return NULL;
  8499. + }
  8500. + temp[0]='\0';
  8501. + strncpy(temp, "Suggests:", 10);
  8502. + for(i = 0; i < pkg->suggests_count; i++) {
  8503. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8504. + strncat(temp, sugstr, strlen(sugstr));
  8505. + }
  8506. + strncat(temp, "\n", strlen("\n"));
  8507. + }
  8508. + } else {
  8509. + goto UNKNOWN_FMT_FIELD;
  8510. + }
  8511. + }
  8512. + break;
  8513. + case 'v':
  8514. + case 'V': {
  8515. + /* Version */
  8516. + char *version = pkg_version_str_alloc(pkg);
  8517. + temp = (char *)realloc(temp,strlen(version)+14);
  8518. + if ( temp == NULL ){
  8519. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8520. + return NULL;
  8521. + }
  8522. + temp[0]='\0';
  8523. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8524. + free(version);
  8525. + }
  8526. + break;
  8527. + default:
  8528. + goto UNKNOWN_FMT_FIELD;
  8529. + }
  8530. +
  8531. + if ( strlen(temp)<2 ) {
  8532. + temp[0]='\0';
  8533. + }
  8534. + return temp;
  8535. +
  8536. + UNKNOWN_FMT_FIELD:
  8537. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8538. + if ( strlen(temp)<2 ) {
  8539. + temp[0]='\0';
  8540. + }
  8541. +
  8542. + return temp;
  8543. +}
  8544. +
  8545. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8546. +{
  8547. + char * buff;
  8548. + if (pkg == NULL) {
  8549. + return;
  8550. + }
  8551. +
  8552. + buff = pkg_formatted_info(pkg);
  8553. + if ( buff == NULL )
  8554. + return;
  8555. + if (strlen(buff)>2){
  8556. + fwrite(buff, 1, strlen(buff), file);
  8557. + }
  8558. + free(buff);
  8559. +}
  8560. +
  8561. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8562. +{
  8563. + if (pkg == NULL) {
  8564. + return;
  8565. + }
  8566. +
  8567. + /* XXX: QUESTION: Do we actually want more fields here? The
  8568. + original idea was to save space by installing only what was
  8569. + needed for actual computation, (package, version, status,
  8570. + essential, conffiles). The assumption is that all other fields
  8571. + can be found in th available file.
  8572. +
  8573. + But, someone proposed the idea to make it possible to
  8574. + reconstruct a .ipk from an installed package, (ie. for beaming
  8575. + from one handheld to another). So, maybe we actually want a few
  8576. + more fields here, (depends, suggests, etc.), so that that would
  8577. + be guaranteed to work even in the absence of more information
  8578. + from the available file.
  8579. +
  8580. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8581. + the essential info needs to be here for all installed packages
  8582. + because they may not appear in the Packages files on various
  8583. + feeds. Furthermore, one should be able to install from URL or
  8584. + local storage without requiring a Packages file from any feed.
  8585. + -Jamey
  8586. + */
  8587. + pkg_print_field(pkg, file, "Package");
  8588. + pkg_print_field(pkg, file, "Version");
  8589. + pkg_print_field(pkg, file, "Depends");
  8590. + pkg_print_field(pkg, file, "Recommends");
  8591. + pkg_print_field(pkg, file, "Suggests");
  8592. + pkg_print_field(pkg, file, "Provides");
  8593. + pkg_print_field(pkg, file, "Replaces");
  8594. + pkg_print_field(pkg, file, "Conflicts");
  8595. + pkg_print_field(pkg, file, "Status");
  8596. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8597. + pkg_print_field(pkg, file, "Architecture");
  8598. + pkg_print_field(pkg, file, "Conffiles");
  8599. + pkg_print_field(pkg, file, "Installed-Time");
  8600. + fputs("\n", file);
  8601. +}
  8602. +
  8603. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8604. +{
  8605. + char *buff;
  8606. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8607. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8608. + __FUNCTION__, field);
  8609. + }
  8610. + buff = pkg_formatted_field(pkg, field);
  8611. + if (strlen(buff)>2) {
  8612. + fprintf(file, "%s", buff);
  8613. + fflush(file);
  8614. + }
  8615. + free(buff);
  8616. + return;
  8617. +}
  8618. +
  8619. +/*
  8620. + * libdpkg - Debian packaging suite library routines
  8621. + * vercmp.c - comparison of version numbers
  8622. + *
  8623. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8624. + */
  8625. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8626. +{
  8627. + int r;
  8628. +
  8629. + if (pkg->epoch > ref_pkg->epoch) {
  8630. + return 1;
  8631. + }
  8632. +
  8633. + if (pkg->epoch < ref_pkg->epoch) {
  8634. + return -1;
  8635. + }
  8636. +
  8637. + r = verrevcmp(pkg->version, ref_pkg->version);
  8638. + if (r) {
  8639. + return r;
  8640. + }
  8641. +
  8642. +#ifdef USE_DEBVERSION
  8643. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8644. + if (r) {
  8645. + return r;
  8646. + }
  8647. +
  8648. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8649. +#endif
  8650. +
  8651. + return r;
  8652. +}
  8653. +
  8654. +int verrevcmp(const char *val, const char *ref)
  8655. +{
  8656. + int vc, rc;
  8657. + long vl, rl;
  8658. + const char *vp, *rp;
  8659. + const char *vsep, *rsep;
  8660. +
  8661. + if (!val) val= "";
  8662. + if (!ref) ref= "";
  8663. + for (;;) {
  8664. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8665. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8666. + for (;;) {
  8667. + vc= (val == vp) ? 0 : *val++;
  8668. + rc= (ref == rp) ? 0 : *ref++;
  8669. + if (!rc && !vc) break;
  8670. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8671. + if (rc && !isalpha(rc)) rc += 256;
  8672. + if (vc != rc) return vc - rc;
  8673. + }
  8674. + val= vp;
  8675. + ref= rp;
  8676. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8677. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8678. + if (vl != rl) return vl - rl;
  8679. +
  8680. + vc = *val;
  8681. + rc = *ref;
  8682. + vsep = strchr(".-", vc);
  8683. + rsep = strchr(".-", rc);
  8684. + if (vsep && !rsep) return -1;
  8685. + if (!vsep && rsep) return +1;
  8686. +
  8687. + if (!*val && !*ref) return 0;
  8688. + if (!*val) return -1;
  8689. + if (!*ref) return +1;
  8690. + }
  8691. +}
  8692. +
  8693. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8694. +{
  8695. + int r;
  8696. +
  8697. + r = pkg_compare_versions(it, ref);
  8698. +
  8699. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8700. + return r <= 0;
  8701. + }
  8702. +
  8703. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8704. + return r >= 0;
  8705. + }
  8706. +
  8707. + if (strcmp(op, "<<") == 0) {
  8708. + return r < 0;
  8709. + }
  8710. +
  8711. + if (strcmp(op, ">>") == 0) {
  8712. + return r > 0;
  8713. + }
  8714. +
  8715. + if (strcmp(op, "=") == 0) {
  8716. + return r == 0;
  8717. + }
  8718. +
  8719. + fprintf(stderr, "unknown operator: %s", op);
  8720. + return 0;
  8721. +}
  8722. +
  8723. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8724. +{
  8725. + const pkg_t *a = *(const pkg_t **)p1;
  8726. + const pkg_t *b = *(const pkg_t **)p2;
  8727. + int namecmp;
  8728. + int vercmp;
  8729. + if (!a->name || !b->name) {
  8730. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8731. + a, a->name, b, b->name);
  8732. + return 0;
  8733. + }
  8734. +
  8735. + namecmp = strcmp(a->name, b->name);
  8736. + if (namecmp)
  8737. + return namecmp;
  8738. + vercmp = pkg_compare_versions(a, b);
  8739. + if (vercmp)
  8740. + return vercmp;
  8741. + if (!a->arch_priority || !b->arch_priority) {
  8742. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8743. + a, a->arch_priority, b, b->arch_priority);
  8744. + return 0;
  8745. + }
  8746. + if (a->arch_priority > b->arch_priority)
  8747. + return 1;
  8748. + if (a->arch_priority < b->arch_priority)
  8749. + return -1;
  8750. + return 0;
  8751. +}
  8752. +
  8753. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8754. +{
  8755. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8756. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8757. + if (!a->name || !b->name) {
  8758. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8759. + a, a->name, b, b->name);
  8760. + return 0;
  8761. + }
  8762. + return strcmp(a->name, b->name);
  8763. +}
  8764. +
  8765. +
  8766. +char *pkg_version_str_alloc(pkg_t *pkg)
  8767. +{
  8768. + char *complete_version;
  8769. + char *epoch_str;
  8770. +#ifdef USE_DEBVERSION
  8771. + char *revision_str;
  8772. + char *familiar_revision_str;
  8773. +#endif
  8774. +
  8775. + if (pkg->epoch) {
  8776. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8777. + } else {
  8778. + epoch_str = strdup("");
  8779. + }
  8780. +
  8781. +#ifdef USE_DEBVERSION
  8782. + if (pkg->revision && strlen(pkg->revision)) {
  8783. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8784. + } else {
  8785. + revision_str = strdup("");
  8786. + }
  8787. +
  8788. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8789. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8790. + } else {
  8791. + familiar_revision_str = strdup("");
  8792. + }
  8793. +#endif
  8794. +
  8795. +#ifdef USE_DEBVERSION
  8796. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8797. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8798. +#else
  8799. + sprintf_alloc(&complete_version, "%s%s",
  8800. + epoch_str, pkg->version);
  8801. +#endif
  8802. +
  8803. + free(epoch_str);
  8804. +#ifdef USE_DEBVERSION
  8805. + free(revision_str);
  8806. + free(familiar_revision_str);
  8807. +#endif
  8808. +
  8809. + return complete_version;
  8810. +}
  8811. +
  8812. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8813. +{
  8814. + int err;
  8815. + char *list_file_name = NULL;
  8816. + FILE *list_file = NULL;
  8817. + char *line;
  8818. + char *installed_file_name;
  8819. + int rootdirlen;
  8820. +
  8821. + pkg->installed_files_ref_cnt++;
  8822. +
  8823. + if (pkg->installed_files) {
  8824. + return pkg->installed_files;
  8825. + }
  8826. +
  8827. + pkg->installed_files = str_list_alloc();
  8828. + if (pkg->installed_files == NULL) {
  8829. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8830. + return NULL;
  8831. + }
  8832. +
  8833. + /* For uninstalled packages, get the file list firectly from the package.
  8834. + For installed packages, look at the package.list file in the database.
  8835. + */
  8836. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8837. + if (pkg->local_filename == NULL) {
  8838. + return pkg->installed_files;
  8839. + }
  8840. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8841. + file. In other words, change deb_extract so that it can
  8842. + simply return the file list as a char *[] rather than
  8843. + insisting on writing in to a FILE * as it does now. */
  8844. + list_file = tmpfile();
  8845. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8846. + if (err) {
  8847. + fclose(list_file);
  8848. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8849. + __FUNCTION__, pkg->local_filename, strerror(err));
  8850. + return pkg->installed_files;
  8851. + }
  8852. + rewind(list_file);
  8853. + } else {
  8854. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8855. + pkg->dest->info_dir, pkg->name);
  8856. + if (! file_exists(list_file_name)) {
  8857. + free(list_file_name);
  8858. + return pkg->installed_files;
  8859. + }
  8860. +
  8861. + list_file = fopen(list_file_name, "r");
  8862. + if (list_file == NULL) {
  8863. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8864. + list_file_name, strerror(errno));
  8865. + free(list_file_name);
  8866. + return pkg->installed_files;
  8867. + }
  8868. + free(list_file_name);
  8869. + }
  8870. +
  8871. + rootdirlen = strlen( pkg->dest->root_dir );
  8872. + while (1) {
  8873. + char *file_name;
  8874. +
  8875. + line = file_read_line_alloc(list_file);
  8876. + if (line == NULL) {
  8877. + break;
  8878. + }
  8879. + str_chomp(line);
  8880. + file_name = line;
  8881. +
  8882. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8883. + if( strncmp( pkg->dest->root_dir,
  8884. + file_name,
  8885. + rootdirlen ) ) {
  8886. + if (*file_name == '.') {
  8887. + file_name++;
  8888. + }
  8889. + if (*file_name == '/') {
  8890. + file_name++;
  8891. + }
  8892. +
  8893. + /* Freed in pkg_free_installed_files */
  8894. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8895. + } else {
  8896. + // already contains root_dir as header -> ABSOLUTE
  8897. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8898. + }
  8899. + str_list_append(pkg->installed_files, installed_file_name);
  8900. + free(line);
  8901. + }
  8902. +
  8903. + fclose(list_file);
  8904. +
  8905. + return pkg->installed_files;
  8906. +}
  8907. +
  8908. +/* XXX: CLEANUP: This function and it's counterpart,
  8909. + (pkg_get_installed_files), do not match our init/deinit naming
  8910. + convention. Nor the alloc/free convention. But, then again, neither
  8911. + of these conventions currrently fit the way these two functions
  8912. + work. */
  8913. +int pkg_free_installed_files(pkg_t *pkg)
  8914. +{
  8915. + str_list_elt_t *iter;
  8916. +
  8917. + pkg->installed_files_ref_cnt--;
  8918. + if (pkg->installed_files_ref_cnt > 0) {
  8919. + return 0;
  8920. + }
  8921. +
  8922. + if (pkg->installed_files) {
  8923. +
  8924. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8925. + /* malloced in pkg_get_installed_files */
  8926. + free (iter->data);
  8927. + iter->data = NULL;
  8928. + }
  8929. +
  8930. + str_list_deinit(pkg->installed_files);
  8931. + }
  8932. +
  8933. + pkg->installed_files = NULL;
  8934. +
  8935. + return 0;
  8936. +}
  8937. +
  8938. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8939. +{
  8940. + int err;
  8941. + char *list_file_name;
  8942. +
  8943. + //I don't think pkg_free_installed_files should be called here. Jamey
  8944. + //pkg_free_installed_files(pkg);
  8945. +
  8946. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8947. + pkg->dest->info_dir, pkg->name);
  8948. + if (!conf->noaction) {
  8949. + err = unlink(list_file_name);
  8950. + free(list_file_name);
  8951. +
  8952. + if (err) {
  8953. + return errno;
  8954. + }
  8955. + }
  8956. + return 0;
  8957. +}
  8958. +
  8959. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8960. +{
  8961. + conffile_list_elt_t *iter;
  8962. + conffile_t *conffile;
  8963. +
  8964. + if (pkg == NULL) {
  8965. + return NULL;
  8966. + }
  8967. +
  8968. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8969. + conffile = iter->data;
  8970. +
  8971. + if (strcmp(conffile->name, file_name) == 0) {
  8972. + return conffile;
  8973. + }
  8974. + }
  8975. +
  8976. + return NULL;
  8977. +}
  8978. +
  8979. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8980. + const char *script, const char *args)
  8981. +{
  8982. + int err;
  8983. + char *path;
  8984. + char *cmd;
  8985. +
  8986. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8987. + maintainer script within a chroot environment. */
  8988. +
  8989. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8990. + have scripts in pkg->tmp_unpack_dir. */
  8991. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8992. + if (pkg->dest == NULL) {
  8993. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8994. + __FUNCTION__, pkg->name);
  8995. + return EINVAL;
  8996. + }
  8997. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  8998. + } else {
  8999. + if (pkg->tmp_unpack_dir == NULL) {
  9000. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9001. + __FUNCTION__, pkg->name);
  9002. + return EINVAL;
  9003. + }
  9004. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9005. + }
  9006. +
  9007. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9008. + if (conf->noaction) return 0;
  9009. +
  9010. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9011. + scripts when running with offline_root mode and/or a dest other
  9012. + than '/'. I've been playing around with some clever chroot
  9013. + tricks and I might come up with something workable. */
  9014. + if (conf->offline_root) {
  9015. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9016. + }
  9017. +
  9018. + setenv("PKG_ROOT",
  9019. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9020. +
  9021. + if (! file_exists(path)) {
  9022. + free(path);
  9023. + return 0;
  9024. + }
  9025. +
  9026. + if (conf->offline_root) {
  9027. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9028. + free(path);
  9029. + return 0;
  9030. + }
  9031. +
  9032. + sprintf_alloc(&cmd, "%s %s", path, args);
  9033. + free(path);
  9034. +
  9035. + err = xsystem(cmd);
  9036. + free(cmd);
  9037. +
  9038. + if (err) {
  9039. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9040. + return err;
  9041. + }
  9042. +
  9043. + return 0;
  9044. +}
  9045. +
  9046. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9047. +{
  9048. + int i;
  9049. +
  9050. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9051. + if (pkg_state_want_map[i].value == sw) {
  9052. + return strdup(pkg_state_want_map[i].str);
  9053. + }
  9054. + }
  9055. +
  9056. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9057. + __FUNCTION__, sw);
  9058. + return strdup("<STATE_WANT_UNKNOWN>");
  9059. +}
  9060. +
  9061. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9062. +{
  9063. + int i;
  9064. +
  9065. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9066. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9067. + return pkg_state_want_map[i].value;
  9068. + }
  9069. + }
  9070. +
  9071. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9072. + __FUNCTION__, str);
  9073. + return SW_UNKNOWN;
  9074. +}
  9075. +
  9076. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9077. +{
  9078. + int i;
  9079. + int len = 3; /* ok\000 is minimum */
  9080. + char *str = NULL;
  9081. +
  9082. + /* clear the temporary flags before converting to string */
  9083. + sf &= SF_NONVOLATILE_FLAGS;
  9084. +
  9085. + if (sf == 0) {
  9086. + return strdup("ok");
  9087. + } else {
  9088. +
  9089. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9090. + if (sf & pkg_state_flag_map[i].value) {
  9091. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9092. + }
  9093. + }
  9094. + str = malloc(len);
  9095. + if ( str == NULL ) {
  9096. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9097. + return NULL;
  9098. + }
  9099. + str[0] = 0;
  9100. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9101. + if (sf & pkg_state_flag_map[i].value) {
  9102. + strcat(str, pkg_state_flag_map[i].str);
  9103. + strcat(str, ",");
  9104. + }
  9105. + }
  9106. + len = strlen(str);
  9107. + str[len-1] = 0; /* squash last comma */
  9108. + return str;
  9109. + }
  9110. +}
  9111. +
  9112. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9113. +{
  9114. + int i;
  9115. + int sf = SF_OK;
  9116. +
  9117. + if (strcmp(str, "ok") == 0) {
  9118. + return SF_OK;
  9119. + }
  9120. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9121. + const char *sfname = pkg_state_flag_map[i].str;
  9122. + int sfname_len = strlen(sfname);
  9123. + if (strncmp(str, sfname, sfname_len) == 0) {
  9124. + sf |= pkg_state_flag_map[i].value;
  9125. + str += sfname_len;
  9126. + if (str[0] == ',') {
  9127. + str++;
  9128. + } else {
  9129. + break;
  9130. + }
  9131. + }
  9132. + }
  9133. +
  9134. + return sf;
  9135. +}
  9136. +
  9137. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9138. +{
  9139. + int i;
  9140. +
  9141. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9142. + if (pkg_state_status_map[i].value == ss) {
  9143. + return strdup(pkg_state_status_map[i].str);
  9144. + }
  9145. + }
  9146. +
  9147. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9148. + __FUNCTION__, ss);
  9149. + return strdup("<STATE_STATUS_UNKNOWN>");
  9150. +}
  9151. +
  9152. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9153. +{
  9154. + int i;
  9155. +
  9156. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9157. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9158. + return pkg_state_status_map[i].value;
  9159. + }
  9160. + }
  9161. +
  9162. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9163. + __FUNCTION__, str);
  9164. + return SS_NOT_INSTALLED;
  9165. +}
  9166. +
  9167. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9168. +{
  9169. + nv_pair_list_elt_t *l;
  9170. +
  9171. + if (!pkg->architecture)
  9172. + return 1;
  9173. +
  9174. + l = conf->arch_list.head;
  9175. +
  9176. + while (l) {
  9177. + nv_pair_t *nv = l->data;
  9178. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9179. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9180. + return 1;
  9181. + }
  9182. + l = l->next;
  9183. + }
  9184. +
  9185. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9186. + return 0;
  9187. +}
  9188. +
  9189. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9190. +{
  9191. + nv_pair_list_elt_t *l;
  9192. +
  9193. + l = conf->arch_list.head;
  9194. +
  9195. + while (l) {
  9196. + nv_pair_t *nv = l->data;
  9197. + if (strcmp(nv->name, archname) == 0) {
  9198. + int priority = strtol(nv->value, NULL, 0);
  9199. + return priority;
  9200. + }
  9201. + l = l->next;
  9202. + }
  9203. + return 0;
  9204. +}
  9205. +
  9206. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9207. +{
  9208. + int i;
  9209. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9210. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9211. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9212. +
  9213. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9214. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9215. + /* update arch_priority for each package */
  9216. + for (i = 0; i < available_pkgs->len; i++) {
  9217. + pkg_t *pkg = available_pkgs->pkgs[i];
  9218. + int arch_priority = 1;
  9219. + if (!pkg)
  9220. + continue;
  9221. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9222. + if (pkg->architecture)
  9223. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9224. + else
  9225. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9226. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9227. + pkg->arch_priority = arch_priority;
  9228. + }
  9229. +
  9230. + for (i = 0; i < available_pkgs->len; i++) {
  9231. + pkg_t *pkg = available_pkgs->pkgs[i];
  9232. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9233. + /* clear flags and want for any uninstallable package */
  9234. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9235. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9236. + pkg->state_want = SW_UNKNOWN;
  9237. + pkg->state_flag = 0;
  9238. + }
  9239. + }
  9240. + pkg_vec_free(available_pkgs);
  9241. +
  9242. + /* update the file owner data structure */
  9243. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9244. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9245. + for (i = 0; i < installed_pkgs->len; i++) {
  9246. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9247. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9248. + str_list_elt_t *iter;
  9249. + if (installed_files == NULL) {
  9250. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9251. + break;
  9252. + }
  9253. + for (iter = installed_files->head; iter; iter = iter->next) {
  9254. + char *installed_file = iter->data;
  9255. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9256. + file_hash_set_file_owner(conf, installed_file, pkg);
  9257. + }
  9258. + }
  9259. + pkg_vec_free(installed_pkgs);
  9260. +
  9261. + return 0;
  9262. +}
  9263. +
  9264. +struct pkg_write_filelist_data {
  9265. + ipkg_conf_t *conf;
  9266. + pkg_t *pkg;
  9267. + FILE *stream;
  9268. +};
  9269. +
  9270. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9271. +{
  9272. + struct pkg_write_filelist_data *data = data_;
  9273. + pkg_t *entry = entry_;
  9274. + if (entry == data->pkg) {
  9275. + fprintf(data->stream, "%s\n", key);
  9276. + }
  9277. +}
  9278. +
  9279. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9280. +{
  9281. + struct pkg_write_filelist_data data;
  9282. + char *list_file_name = NULL;
  9283. + int err = 0;
  9284. +
  9285. + if (!pkg) {
  9286. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9287. + return -EINVAL;
  9288. + }
  9289. + ipkg_message(conf, IPKG_INFO,
  9290. + " creating %s.list file\n", pkg->name);
  9291. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9292. + if (!list_file_name) {
  9293. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9294. + return -ENOMEM;
  9295. + }
  9296. + ipkg_message(conf, IPKG_INFO,
  9297. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9298. + data.stream = fopen(list_file_name, "w");
  9299. + if (!data.stream) {
  9300. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9301. + list_file_name, strerror(errno));
  9302. + return errno;
  9303. + }
  9304. + data.pkg = pkg;
  9305. + data.conf = conf;
  9306. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9307. + fclose(data.stream);
  9308. + free(list_file_name);
  9309. +
  9310. + return err;
  9311. +}
  9312. +
  9313. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9314. +{
  9315. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9316. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9317. + int i;
  9318. + int err;
  9319. + if (conf->noaction)
  9320. + return 0;
  9321. +
  9322. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9323. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9324. + for (i = 0; i < installed_pkgs->len; i++) {
  9325. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9326. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9327. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9328. + err = pkg_write_filelist(conf, pkg);
  9329. + if (err)
  9330. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9331. + }
  9332. + }
  9333. + return 0;
  9334. +}
  9335. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_depends.c busybox-1.23.0/archival/libipkg/pkg_depends.c
  9336. --- busybox-1.23.0.orig/archival/libipkg/pkg_depends.c 1969-12-31 18:00:00.000000000 -0600
  9337. +++ busybox-1.23.0/archival/libipkg/pkg_depends.c 2015-01-09 11:18:22.428197243 -0600
  9338. @@ -0,0 +1,1032 @@
  9339. +/* pkg_depends.c - the itsy package management system
  9340. +
  9341. + Steven M. Ayer
  9342. +
  9343. + Copyright (C) 2002 Compaq Computer Corporation
  9344. +
  9345. + This program is free software; you can redistribute it and/or
  9346. + modify it under the terms of the GNU General Public License as
  9347. + published by the Free Software Foundation; either version 2, or (at
  9348. + your option) any later version.
  9349. +
  9350. + This program is distributed in the hope that it will be useful, but
  9351. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9352. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9353. + General Public License for more details.
  9354. +*/
  9355. +
  9356. +#include "ipkg.h"
  9357. +#include <errno.h>
  9358. +#include <ctype.h>
  9359. +
  9360. +#include "pkg.h"
  9361. +#include "ipkg_utils.h"
  9362. +#include "pkg_hash.h"
  9363. +#include "ipkg_message.h"
  9364. +#include "pkg_parse.h"
  9365. +#include "hash_table.h"
  9366. +
  9367. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9368. +static depend_t * depend_init(void);
  9369. +static void depend_deinit(depend_t *d);
  9370. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9371. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9372. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9373. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9374. +
  9375. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9376. +{
  9377. + depend_t *depend = (depend_t *)cdata;
  9378. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9379. + return 1;
  9380. + else
  9381. + return 0;
  9382. +}
  9383. +
  9384. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9385. +{
  9386. + depend_t *depend = (depend_t *)cdata;
  9387. +#if 0
  9388. + pkg_t * temp = pkg_new();
  9389. + int comparison;
  9390. + parseVersion(temp, depend->version);
  9391. + comparison = pkg_compare_versions(pkg, temp);
  9392. + free(temp);
  9393. +
  9394. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9395. + __FUNCTION__, pkg->name, pkg->version,
  9396. + depend, depend->constraint, depend->version,
  9397. + comparison, version_constraints_satisfied(depend, pkg));
  9398. +#endif
  9399. + if (version_constraints_satisfied(depend, pkg))
  9400. + return 1;
  9401. + else
  9402. + return 0;
  9403. +}
  9404. +
  9405. +/* returns ndependences or negative error value */
  9406. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9407. + pkg_vec_t *unsatisfied, char *** unresolved)
  9408. +{
  9409. + pkg_t * satisfier_entry_pkg;
  9410. + register int i, j, k, l;
  9411. + int count, found;
  9412. + char ** the_lost;
  9413. + abstract_pkg_t * ab_pkg;
  9414. +
  9415. + /*
  9416. + * this is a setup to check for redundant/cyclic dependency checks,
  9417. + * which are marked at the abstract_pkg level
  9418. + */
  9419. + if (!(ab_pkg = pkg->parent)) {
  9420. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9421. + *unresolved = NULL;
  9422. + return 0;
  9423. + }
  9424. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9425. + *unresolved = NULL;
  9426. + return 0;
  9427. + } else {
  9428. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9429. + }
  9430. + /**/
  9431. +
  9432. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9433. + if (!count){
  9434. + *unresolved = NULL;
  9435. + return 0;
  9436. + }
  9437. +
  9438. + the_lost = NULL;
  9439. +
  9440. + /* foreach dependency */
  9441. + for (i = 0; i < count; i++) {
  9442. + compound_depend_t * compound_depend = &pkg->depends[i];
  9443. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9444. + found = 0;
  9445. + satisfier_entry_pkg = NULL;
  9446. +
  9447. + if (compound_depend->type == GREEDY_DEPEND) {
  9448. + /* foreach possible satisfier */
  9449. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9450. + /* foreach provided_by, which includes the abstract_pkg itself */
  9451. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9452. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9453. + int nposs = ab_provider_vec->len;
  9454. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9455. + for (l = 0; l < nposs; l++) {
  9456. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9457. + /* if no depends on this one, try the first package that Provides this one */
  9458. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9459. + continue;
  9460. + }
  9461. +
  9462. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9463. + for (k = 0; k < test_vec->len; k++) {
  9464. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9465. + /* not installed, and not already known about? */
  9466. + if ((pkg_scout->state_want != SW_INSTALL)
  9467. + && !pkg_scout->parent->dependencies_checked
  9468. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9469. + char ** newstuff = NULL;
  9470. + int rc;
  9471. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9472. + /* check for not-already-installed dependencies */
  9473. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9474. + pkg_scout,
  9475. + tmp_vec,
  9476. + &newstuff);
  9477. + if (newstuff == NULL) {
  9478. + int ok = 1;
  9479. + for (i = 0; i < rc; i++) {
  9480. + pkg_t *p = tmp_vec->pkgs[i];
  9481. + if (p->state_want == SW_INSTALL)
  9482. + continue;
  9483. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9484. + ok = 0;
  9485. + break;
  9486. + }
  9487. + pkg_vec_free (tmp_vec);
  9488. + if (ok) {
  9489. + /* mark this one for installation */
  9490. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9491. + pkg_vec_insert(unsatisfied, pkg_scout);
  9492. + }
  9493. + } else {
  9494. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9495. + free (newstuff);
  9496. + }
  9497. + }
  9498. + }
  9499. + }
  9500. + }
  9501. +
  9502. + continue;
  9503. + }
  9504. +
  9505. + /* foreach possible satisfier, look for installed package */
  9506. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9507. + /* foreach provided_by, which includes the abstract_pkg itself */
  9508. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9509. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9510. + pkg_t *satisfying_pkg =
  9511. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9512. + pkg_installed_and_constraint_satisfied,
  9513. + dependence_to_satisfy, 1);
  9514. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9515. + if (satisfying_pkg != NULL) {
  9516. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9517. + satisfying_pkg = NULL;
  9518. + }
  9519. + }
  9520. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9521. + if (satisfying_pkg != NULL) {
  9522. + found = 1;
  9523. + break;
  9524. + }
  9525. +
  9526. + }
  9527. + /* if nothing installed matches, then look for uninstalled satisfier */
  9528. + if (!found) {
  9529. + /* foreach possible satisfier, look for installed package */
  9530. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9531. + /* foreach provided_by, which includes the abstract_pkg itself */
  9532. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9533. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9534. + pkg_t *satisfying_pkg =
  9535. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9536. + pkg_constraint_satisfied,
  9537. + dependence_to_satisfy, 1);
  9538. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9539. + if (satisfying_pkg != NULL) {
  9540. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9541. + satisfying_pkg = NULL;
  9542. + }
  9543. + }
  9544. +
  9545. + /* user request overrides package recommendation */
  9546. + if (satisfying_pkg != NULL
  9547. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9548. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9549. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9550. + pkg->name, satisfying_pkg->name);
  9551. + continue;
  9552. + }
  9553. +
  9554. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9555. + if (satisfying_pkg != NULL) {
  9556. + satisfier_entry_pkg = satisfying_pkg;
  9557. + break;
  9558. + }
  9559. + }
  9560. + }
  9561. +
  9562. + /* we didn't find one, add something to the unsatisfied vector */
  9563. + if (!found) {
  9564. + if (!satisfier_entry_pkg) {
  9565. + /* failure to meet recommendations is not an error */
  9566. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9567. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9568. + else
  9569. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9570. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9571. + }
  9572. + else {
  9573. + if (compound_depend->type == SUGGEST) {
  9574. + /* just mention it politely */
  9575. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9576. + pkg->name, satisfier_entry_pkg->name);
  9577. + } else {
  9578. + char ** newstuff = NULL;
  9579. +
  9580. + if (satisfier_entry_pkg != pkg &&
  9581. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9582. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9583. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9584. + satisfier_entry_pkg,
  9585. + unsatisfied,
  9586. + &newstuff);
  9587. + the_lost = merge_unresolved(the_lost, newstuff);
  9588. + }
  9589. + }
  9590. + }
  9591. + }
  9592. + }
  9593. + *unresolved = the_lost;
  9594. +
  9595. + return unsatisfied->len;
  9596. +}
  9597. +
  9598. +/*checking for conflicts !in replaces
  9599. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9600. + really conflicts
  9601. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9602. +*/
  9603. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9604. +{
  9605. + int i ;
  9606. + int replaces_count = pkg->replaces_count;
  9607. + abstract_pkg_t **replaces;
  9608. +
  9609. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9610. + return 0;
  9611. +
  9612. + replaces = pkg->replaces;
  9613. +
  9614. + for (i = 0; i < replaces_count; i++) {
  9615. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9616. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9617. + return 1;
  9618. + }
  9619. + }
  9620. + return 0;
  9621. +
  9622. +}
  9623. +
  9624. +
  9625. +/* Abhaya: added support for conflicts */
  9626. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9627. +{
  9628. + pkg_vec_t * installed_conflicts, * test_vec;
  9629. + compound_depend_t * conflicts;
  9630. + depend_t ** possible_satisfiers;
  9631. + depend_t * possible_satisfier;
  9632. + register int i, j, k;
  9633. + int count;
  9634. + abstract_pkg_t * ab_pkg;
  9635. + pkg_t **pkg_scouts;
  9636. + pkg_t *pkg_scout;
  9637. +
  9638. + /*
  9639. + * this is a setup to check for redundant/cyclic dependency checks,
  9640. + * which are marked at the abstract_pkg level
  9641. + */
  9642. + if(!(ab_pkg = pkg->parent)){
  9643. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9644. + return (pkg_vec_t *)NULL;
  9645. + }
  9646. +
  9647. + conflicts = pkg->conflicts;
  9648. + if(!conflicts){
  9649. + return (pkg_vec_t *)NULL;
  9650. + }
  9651. + installed_conflicts = pkg_vec_alloc();
  9652. +
  9653. + count = pkg->conflicts_count;
  9654. +
  9655. +
  9656. +
  9657. + /* foreach conflict */
  9658. + for(i = 0; i < pkg->conflicts_count; i++){
  9659. +
  9660. + possible_satisfiers = conflicts->possibilities;
  9661. +
  9662. + /* foreach possible satisfier */
  9663. + for(j = 0; j < conflicts->possibility_count; j++){
  9664. + possible_satisfier = possible_satisfiers[j];
  9665. + if (!possible_satisfier)
  9666. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9667. + if (!possible_satisfier->pkg)
  9668. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9669. + test_vec = possible_satisfier->pkg->pkgs;
  9670. + if (test_vec) {
  9671. + /* pkg_vec found, it is an actual package conflict
  9672. + * cruise this possiblity's pkg_vec looking for an installed version */
  9673. + pkg_scouts = test_vec->pkgs;
  9674. + for(k = 0; k < test_vec->len; k++){
  9675. + pkg_scout = pkg_scouts[k];
  9676. + if (!pkg_scout) {
  9677. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9678. + continue;
  9679. + }
  9680. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9681. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9682. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9683. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9684. + }
  9685. + }
  9686. + }
  9687. + }
  9688. + }
  9689. + conflicts++;
  9690. + }
  9691. +
  9692. + if (installed_conflicts->len)
  9693. + return installed_conflicts;
  9694. + pkg_vec_free(installed_conflicts);
  9695. + return (pkg_vec_t *)NULL;
  9696. +}
  9697. +
  9698. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9699. +{
  9700. + pkg_t * temp;
  9701. + int comparison;
  9702. +
  9703. + if(depends->constraint == NONE)
  9704. + return 1;
  9705. +
  9706. + temp = pkg_new();
  9707. +
  9708. + parseVersion(temp, depends->version);
  9709. +
  9710. + comparison = pkg_compare_versions(pkg, temp);
  9711. +
  9712. + free(temp);
  9713. +
  9714. + if((depends->constraint == EARLIER) &&
  9715. + (comparison < 0))
  9716. + return 1;
  9717. + else if((depends->constraint == LATER) &&
  9718. + (comparison > 0))
  9719. + return 1;
  9720. + else if(comparison == 0)
  9721. + return 1;
  9722. + else if((depends->constraint == LATER_EQUAL) &&
  9723. + (comparison >= 0))
  9724. + return 1;
  9725. + else if((depends->constraint == EARLIER_EQUAL) &&
  9726. + (comparison <= 0))
  9727. + return 1;
  9728. +
  9729. + return 0;
  9730. +}
  9731. +
  9732. +int pkg_dependence_satisfiable(depend_t *depend)
  9733. +{
  9734. + abstract_pkg_t *apkg = depend->pkg;
  9735. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9736. + int n_providers = provider_apkgs->len;
  9737. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9738. + pkg_vec_t *pkg_vec;
  9739. + int n_pkgs ;
  9740. + int i;
  9741. + int j;
  9742. +
  9743. + for (i = 0; i < n_providers; i++) {
  9744. + abstract_pkg_t *papkg = apkgs[i];
  9745. + pkg_vec = papkg->pkgs;
  9746. + if (pkg_vec) {
  9747. + n_pkgs = pkg_vec->len;
  9748. + for (j = 0; j < n_pkgs; j++) {
  9749. + pkg_t *pkg = pkg_vec->pkgs[j];
  9750. + if (version_constraints_satisfied(depend, pkg)) {
  9751. + return 1;
  9752. + }
  9753. + }
  9754. + }
  9755. + }
  9756. + return 0;
  9757. +}
  9758. +
  9759. +int pkg_dependence_satisfied(depend_t *depend)
  9760. +{
  9761. + abstract_pkg_t *apkg = depend->pkg;
  9762. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9763. + int n_providers = provider_apkgs->len;
  9764. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9765. + int i;
  9766. + int n_pkgs;
  9767. + int j;
  9768. +
  9769. + for (i = 0; i < n_providers; i++) {
  9770. + abstract_pkg_t *papkg = apkgs[i];
  9771. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9772. + if (pkg_vec) {
  9773. + n_pkgs = pkg_vec->len;
  9774. + for (j = 0; j < n_pkgs; j++) {
  9775. + pkg_t *pkg = pkg_vec->pkgs[j];
  9776. + if (version_constraints_satisfied(depend, pkg)) {
  9777. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9778. + return 1;
  9779. + }
  9780. + }
  9781. + }
  9782. + }
  9783. + return 0;
  9784. +}
  9785. +
  9786. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9787. +{
  9788. + register int i;
  9789. + pkg_t ** pkgs = vec->pkgs;
  9790. +
  9791. + for(i = 0; i < vec->len; i++)
  9792. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9793. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9794. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9795. + return 1;
  9796. + return 0;
  9797. +}
  9798. +
  9799. +
  9800. +#ifdef DeadCode
  9801. +/**
  9802. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9803. + * the same abstract package and 0 otherwise.
  9804. + */
  9805. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9806. +{
  9807. + abstract_pkg_t **provides = pkg->provides;
  9808. + int provides_count = pkg->provides_count;
  9809. + abstract_pkg_t **replacee_provides = replacee->provides;
  9810. + int replacee_provides_count = replacee->provides_count;
  9811. + int i, j;
  9812. + for (i = 0; i < provides_count; i++) {
  9813. + abstract_pkg_t *apkg = provides[i];
  9814. + for (j = 0; j < replacee_provides_count; j++) {
  9815. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9816. + if (apkg == replacee_apkg)
  9817. + return 1;
  9818. + }
  9819. + }
  9820. + return 0;
  9821. +}
  9822. +#endif
  9823. +
  9824. +/**
  9825. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9826. + * and 0 otherwise.
  9827. + */
  9828. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9829. +{
  9830. + abstract_pkg_t **provides = pkg->provides;
  9831. + int provides_count = pkg->provides_count;
  9832. + int i;
  9833. + for (i = 0; i < provides_count; i++) {
  9834. + if (provides[i] == providee)
  9835. + return 1;
  9836. + }
  9837. + return 0;
  9838. +}
  9839. +
  9840. +/**
  9841. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9842. + * otherwise.
  9843. + */
  9844. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9845. +{
  9846. + abstract_pkg_t **replaces = pkg->replaces;
  9847. + int replaces_count = pkg->replaces_count;
  9848. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9849. + int replacee_provides_count = pkg->provides_count; */
  9850. + int i, j;
  9851. + for (i = 0; i < replaces_count; i++) {
  9852. + abstract_pkg_t *abstract_replacee = replaces[i];
  9853. + for (j = 0; j < replaces_count; j++) {
  9854. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9855. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9856. + if (replacee->provides[j] == abstract_replacee)
  9857. + return 1;
  9858. + }
  9859. + }
  9860. + return 0;
  9861. +}
  9862. +
  9863. +
  9864. +/**
  9865. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9866. + * otherwise.
  9867. + */
  9868. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9869. +{
  9870. + compound_depend_t *conflicts = pkg->conflicts;
  9871. + int conflicts_count = pkg->conflicts_count;
  9872. + int i, j;
  9873. + for (i = 0; i < conflicts_count; i++) {
  9874. + int possibility_count = conflicts[i].possibility_count;
  9875. + struct depend **possibilities = conflicts[i].possibilities;
  9876. + for (j = 0; j < possibility_count; j++) {
  9877. + if (possibilities[j]->pkg == conflictee) {
  9878. + return 1;
  9879. + }
  9880. + }
  9881. + }
  9882. + return 0;
  9883. +}
  9884. +
  9885. +/**
  9886. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9887. + * conflictee's provides and 0 otherwise.
  9888. + */
  9889. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9890. +{
  9891. + compound_depend_t *conflicts = pkg->conflicts;
  9892. + int conflicts_count = pkg->conflicts_count;
  9893. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9894. + int conflictee_provides_count = conflictee->provides_count;
  9895. + int i, j, k;
  9896. + int possibility_count;
  9897. + struct depend **possibilities;
  9898. + abstract_pkg_t *possibility ;
  9899. +
  9900. + for (i = 0; i < conflicts_count; i++) {
  9901. + possibility_count = conflicts[i].possibility_count;
  9902. + possibilities = conflicts[i].possibilities;
  9903. + for (j = 0; j < possibility_count; j++) {
  9904. + possibility = possibilities[j]->pkg;
  9905. + for (k = 0; k < conflictee_provides_count; k++) {
  9906. + if (possibility == conflictee_provides[k]) {
  9907. + return 1;
  9908. + }
  9909. + }
  9910. + }
  9911. + }
  9912. + return 0;
  9913. +}
  9914. +
  9915. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9916. +{
  9917. + int oldlen = 0, newlen = 0;
  9918. + char ** result;
  9919. + register int i, j;
  9920. +
  9921. + if(!newstuff)
  9922. + return oldstuff;
  9923. +
  9924. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9925. + while(newstuff && newstuff[newlen]) newlen++;
  9926. +
  9927. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9928. + if (result == NULL) {
  9929. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9930. + return NULL;
  9931. + }
  9932. +
  9933. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9934. + *(result + i) = *(newstuff + j);
  9935. +
  9936. + *(result + i) = NULL;
  9937. +
  9938. + return result;
  9939. +}
  9940. +
  9941. +/*
  9942. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9943. + * this is null terminated, no count is carried around
  9944. + */
  9945. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9946. +{
  9947. + int count;
  9948. + char ** resized;
  9949. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9950. +
  9951. + count = 0;
  9952. + while(the_lost && the_lost[count]) count++;
  9953. +
  9954. + count++; /* need one to hold the null */
  9955. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9956. + if (resized == NULL) {
  9957. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9958. + return NULL;
  9959. + }
  9960. + resized[count - 1] = strdup(depend_str);
  9961. + resized[count] = NULL;
  9962. +
  9963. + return resized;
  9964. +}
  9965. +
  9966. +void printDepends(pkg_t * pkg)
  9967. +{
  9968. + register int i, j;
  9969. + compound_depend_t * depend;
  9970. + int count;
  9971. +
  9972. + count = pkg->pre_depends_count + pkg->depends_count;
  9973. +
  9974. + depend = pkg->depends;
  9975. + if(!depend){
  9976. + fprintf(stderr, "Depends pointer is NULL\n");
  9977. + return;
  9978. + }
  9979. + for(i = 0; i < count; i++){
  9980. + fprintf(stderr, "%s has %d possibilities:\n",
  9981. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9982. + depend->possibility_count);
  9983. + for(j = 0; j < depend->possibility_count; j++)
  9984. + fprintf(stderr, "\t%s version %s (%d)\n",
  9985. + depend->possibilities[j]->pkg->name,
  9986. + depend->possibilities[j]->version,
  9987. + depend->possibilities[j]->constraint);
  9988. + depend++;
  9989. + }
  9990. +}
  9991. +
  9992. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9993. +{
  9994. + register int i, j;
  9995. +
  9996. + /* every pkg provides itself */
  9997. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  9998. +
  9999. + if (!pkg->provides_count)
  10000. + return 0;
  10001. +
  10002. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10003. + if (pkg->provides == NULL) {
  10004. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10005. + return -1 ;
  10006. + }
  10007. + pkg->provides[0] = ab_pkg;
  10008. +
  10009. + // if (strcmp(ab_pkg->name, pkg->name))
  10010. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10011. +
  10012. + for(i = 0; i < pkg->provides_count; i++){
  10013. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10014. +
  10015. + pkg->provides[i+1] = provided_abpkg;
  10016. +
  10017. + j = 0;
  10018. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10019. + }
  10020. + return 0;
  10021. +}
  10022. +
  10023. +/* Abhaya: added conflicts support */
  10024. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10025. +{
  10026. + register int i;
  10027. + compound_depend_t * conflicts;
  10028. +
  10029. + if (!pkg->conflicts_count)
  10030. + return 0;
  10031. +
  10032. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10033. + pkg->conflicts_count);
  10034. + if (conflicts == NULL) {
  10035. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10036. + return -1;
  10037. + }
  10038. + for (i = 0; i < pkg->conflicts_count; i++) {
  10039. + conflicts->type = CONFLICTS;
  10040. + parseDepends(conflicts, hash,
  10041. + pkg->conflicts_str[i]);
  10042. +#if 0
  10043. + for (j = 0; j < conflicts->possibility_count; j++) {
  10044. + depend_t *possibility = conflicts->possibilities[j];
  10045. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10046. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10047. + }
  10048. +#endif
  10049. + conflicts++;
  10050. + }
  10051. + return 0;
  10052. +}
  10053. +
  10054. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10055. +{
  10056. + register int i, j;
  10057. +
  10058. + if (!pkg->replaces_count)
  10059. + return 0;
  10060. +
  10061. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10062. + if (pkg->replaces == NULL) {
  10063. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10064. + return -1;
  10065. + }
  10066. +
  10067. + // if (strcmp(ab_pkg->name, pkg->name))
  10068. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10069. +
  10070. + for(i = 0; i < pkg->replaces_count; i++){
  10071. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10072. +
  10073. + pkg->replaces[i] = old_abpkg;
  10074. +
  10075. + j = 0;
  10076. + if (!old_abpkg->replaced_by)
  10077. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10078. + if ( old_abpkg->replaced_by == NULL ){
  10079. + return -1;
  10080. + }
  10081. + /* if a package pkg both replaces and conflicts old_abpkg,
  10082. + * then add it to the replaced_by vector so that old_abpkg
  10083. + * will be upgraded to ab_pkg automatically */
  10084. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10085. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10086. + }
  10087. + return 0;
  10088. +}
  10089. +
  10090. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10091. +{
  10092. + int count;
  10093. + register int i;
  10094. + compound_depend_t * depends;
  10095. +
  10096. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10097. + return 0;
  10098. +
  10099. + if (0 && pkg->pre_depends_count)
  10100. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10101. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10102. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10103. + if (depends == NULL) {
  10104. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10105. + return -1;
  10106. + }
  10107. +
  10108. +
  10109. + for(i = 0; i < pkg->pre_depends_count; i++){
  10110. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10111. + if (0 && pkg->pre_depends_count)
  10112. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10113. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10114. + depends->type = PREDEPEND;
  10115. + depends++;
  10116. + }
  10117. +
  10118. + for(i = 0; i < pkg->recommends_count; i++){
  10119. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10120. + if (0 && pkg->recommends_count)
  10121. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10122. + pkg->recommends_str[i], depends, depends->possibility_count);
  10123. + depends->type = RECOMMEND;
  10124. + depends++;
  10125. + }
  10126. +
  10127. + for(i = 0; i < pkg->suggests_count; i++){
  10128. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10129. + if (0 && pkg->suggests_count)
  10130. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10131. + pkg->suggests_str[i], depends, depends->possibility_count);
  10132. + depends->type = SUGGEST;
  10133. + depends++;
  10134. + }
  10135. +
  10136. + for(i = 0; i < pkg->depends_count; i++){
  10137. + parseDepends(depends, hash, pkg->depends_str[i]);
  10138. + if (0 && pkg->depends_count)
  10139. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10140. + pkg->depends_str[i], depends, depends->possibility_count);
  10141. + depends++;
  10142. + }
  10143. + return 0;
  10144. +}
  10145. +
  10146. +/*
  10147. + * pkg_depend_string: returns the depends string specified by index_.
  10148. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10149. + * [0,npredepends) -> returns pre_depends_str[index_]
  10150. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10151. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10152. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10153. + */
  10154. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10155. +{
  10156. + if (index_ < pkg->pre_depends_count) {
  10157. + return pkg->pre_depends_str[index_];
  10158. + }
  10159. + index_ -= pkg->pre_depends_count;
  10160. +
  10161. + if (index_ < pkg->recommends_count) {
  10162. + return pkg->recommends_str[index_];
  10163. + }
  10164. + index_ -= pkg->recommends_count;
  10165. +
  10166. + if (index_ < pkg->suggests_count) {
  10167. + return pkg->suggests_str[index_];
  10168. + }
  10169. + index_ -= pkg->suggests_count;
  10170. +
  10171. + if (index_ < pkg->depends_count) {
  10172. + return pkg->depends_str[index_];
  10173. + }
  10174. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10175. + return NULL;
  10176. +}
  10177. +
  10178. +void freeDepends(pkg_t *pkg)
  10179. +{
  10180. + int i;
  10181. +
  10182. + if (pkg == NULL || pkg->depends == NULL) {
  10183. + return;
  10184. + }
  10185. +
  10186. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10187. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10188. + depend_deinit(pkg->depends->possibilities[i]);
  10189. + }
  10190. + free(pkg->depends->possibilities);
  10191. + free(pkg->depends);
  10192. + pkg->depends = NULL;
  10193. +}
  10194. +
  10195. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10196. +{
  10197. + compound_depend_t * depends;
  10198. + int count, othercount;
  10199. + register int i, j;
  10200. + abstract_pkg_t * ab_depend;
  10201. + abstract_pkg_t ** temp;
  10202. +
  10203. + count = pkg->pre_depends_count + pkg->depends_count;
  10204. + depends = pkg->depends;
  10205. +
  10206. + if (0 && pkg->pre_depends_count)
  10207. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10208. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10209. + for (i = 0; i < count; i++) {
  10210. + if (0 && pkg->pre_depends_count)
  10211. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10212. + for (j = 0; j < depends->possibility_count; j++){
  10213. + ab_depend = depends->possibilities[j]->pkg;
  10214. + if(!ab_depend->depended_upon_by)
  10215. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10216. +
  10217. + temp = ab_depend->depended_upon_by;
  10218. + othercount = 1;
  10219. + while(*temp){
  10220. + temp++;
  10221. + othercount++;
  10222. + }
  10223. + *temp = ab_pkg;
  10224. +
  10225. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10226. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10227. + /* the array may have moved */
  10228. + temp = ab_depend->depended_upon_by + othercount;
  10229. + *temp = NULL;
  10230. + }
  10231. + depends++;
  10232. + }
  10233. +}
  10234. +
  10235. +static depend_t * depend_init(void)
  10236. +{
  10237. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10238. + if ( d==NULL ){
  10239. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10240. + return NULL;
  10241. + }
  10242. + d->constraint = NONE;
  10243. + d->version = NULL;
  10244. + d->pkg = NULL;
  10245. +
  10246. + return d;
  10247. +}
  10248. +
  10249. +static void depend_deinit(depend_t *d)
  10250. +{
  10251. + free(d);
  10252. +}
  10253. +
  10254. +static int parseDepends(compound_depend_t *compound_depend,
  10255. + hash_table_t * hash, char * depend_str)
  10256. +{
  10257. + char * pkg_name, buffer[2048];
  10258. + int num_of_ors = 0;
  10259. + register int i;
  10260. + register char * src, * dest;
  10261. + depend_t ** possibilities;
  10262. +
  10263. + /* first count the number of ored possibilities for satisfying dependency */
  10264. + src = depend_str;
  10265. + while(*src)
  10266. + if(*src++ == '|')
  10267. + num_of_ors++;
  10268. +
  10269. + compound_depend->type = DEPEND;
  10270. +
  10271. + compound_depend->possibility_count = num_of_ors + 1;
  10272. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10273. + if (!possibilities)
  10274. + return -ENOMEM;
  10275. + compound_depend->possibilities = possibilities;
  10276. +
  10277. + src = depend_str;
  10278. + for(i = 0; i < num_of_ors + 1; i++){
  10279. + possibilities[i] = depend_init();
  10280. + if (!possibilities[i])
  10281. + return -ENOMEM;
  10282. + /* gobble up just the name first */
  10283. + dest = buffer;
  10284. + while(*src &&
  10285. + !isspace(*src) &&
  10286. + (*src != '(') &&
  10287. + (*src != '*') &&
  10288. + (*src != '|'))
  10289. + *dest++ = *src++;
  10290. + *dest = '\0';
  10291. + pkg_name = trim_alloc(buffer);
  10292. + if (pkg_name == NULL )
  10293. + return -ENOMEM;
  10294. +
  10295. + /* now look at possible version info */
  10296. +
  10297. + /* skip to next chars */
  10298. + if(isspace(*src))
  10299. + while(*src && isspace(*src)) src++;
  10300. +
  10301. + /* extract constraint and version */
  10302. + if(*src == '('){
  10303. + src++;
  10304. + if(!strncmp(src, "<<", 2)){
  10305. + possibilities[i]->constraint = EARLIER;
  10306. + src += 2;
  10307. + }
  10308. + else if(!strncmp(src, "<=", 2)){
  10309. + possibilities[i]->constraint = EARLIER_EQUAL;
  10310. + src += 2;
  10311. + }
  10312. + else if(!strncmp(src, ">=", 2)){
  10313. + possibilities[i]->constraint = LATER_EQUAL;
  10314. + src += 2;
  10315. + }
  10316. + else if(!strncmp(src, ">>", 2)){
  10317. + possibilities[i]->constraint = LATER;
  10318. + src += 2;
  10319. + }
  10320. + else if(!strncmp(src, "=", 1)){
  10321. + possibilities[i]->constraint = EQUAL;
  10322. + src++;
  10323. + }
  10324. + /* should these be here to support deprecated designations; dpkg does */
  10325. + else if(!strncmp(src, "<", 1)){
  10326. + possibilities[i]->constraint = EARLIER_EQUAL;
  10327. + src++;
  10328. + }
  10329. + else if(!strncmp(src, ">", 1)){
  10330. + possibilities[i]->constraint = LATER_EQUAL;
  10331. + src++;
  10332. + }
  10333. +
  10334. + /* now we have any constraint, pass space to version string */
  10335. + while(isspace(*src)) src++;
  10336. +
  10337. + /* this would be the version string */
  10338. + dest = buffer;
  10339. + while(*src && *src != ')')
  10340. + *dest++ = *src++;
  10341. + *dest = '\0';
  10342. +
  10343. + possibilities[i]->version = trim_alloc(buffer);
  10344. + /* fprintf(stderr, "let's print the depends version string:");
  10345. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10346. + if (possibilities[i]->version == NULL )
  10347. + return -ENOMEM;
  10348. +
  10349. +
  10350. + }
  10351. + /* hook up the dependency to its abstract pkg */
  10352. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10353. +
  10354. + free(pkg_name);
  10355. +
  10356. + /* now get past the ) and any possible | chars */
  10357. + while(*src &&
  10358. + (isspace(*src) ||
  10359. + (*src == ')') ||
  10360. + (*src == '|')))
  10361. + src++;
  10362. + if (*src == '*')
  10363. + {
  10364. + compound_depend->type = GREEDY_DEPEND;
  10365. + src++;
  10366. + }
  10367. + }
  10368. +
  10369. + return 0;
  10370. +}
  10371. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_depends.h busybox-1.23.0/archival/libipkg/pkg_depends.h
  10372. --- busybox-1.23.0.orig/archival/libipkg/pkg_depends.h 1969-12-31 18:00:00.000000000 -0600
  10373. +++ busybox-1.23.0/archival/libipkg/pkg_depends.h 2015-01-09 11:18:22.432197244 -0600
  10374. @@ -0,0 +1,105 @@
  10375. +/* pkg_depends.h - the itsy package management system
  10376. +
  10377. + Steven M. Ayer
  10378. +
  10379. + Copyright (C) 2002 Compaq Computer Corporation
  10380. +
  10381. + This program is free software; you can redistribute it and/or
  10382. + modify it under the terms of the GNU General Public License as
  10383. + published by the Free Software Foundation; either version 2, or (at
  10384. + your option) any later version.
  10385. +
  10386. + This program is distributed in the hope that it will be useful, but
  10387. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10388. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10389. + General Public License for more details.
  10390. +*/
  10391. +
  10392. +#ifndef PKG_DEPENDS_H
  10393. +#define PKG_DEPENDS_H
  10394. +
  10395. +#include "pkg.h"
  10396. +#include "pkg_hash.h"
  10397. +
  10398. +enum depend_type {
  10399. + PREDEPEND,
  10400. + DEPEND,
  10401. + CONFLICTS,
  10402. + GREEDY_DEPEND,
  10403. + RECOMMEND,
  10404. + SUGGEST
  10405. +};
  10406. +typedef enum depend_type depend_type_t;
  10407. +
  10408. +enum version_constraint {
  10409. + NONE,
  10410. + EARLIER,
  10411. + EARLIER_EQUAL,
  10412. + EQUAL,
  10413. + LATER_EQUAL,
  10414. + LATER
  10415. +};
  10416. +typedef enum version_constraint version_constraint_t;
  10417. +
  10418. +struct depend{
  10419. + version_constraint_t constraint;
  10420. + char * version;
  10421. + abstract_pkg_t * pkg;
  10422. +};
  10423. +typedef struct depend depend_t;
  10424. +
  10425. +struct compound_depend{
  10426. + depend_type_t type;
  10427. + int possibility_count;
  10428. + struct depend ** possibilities;
  10429. +};
  10430. +typedef struct compound_depend compound_depend_t;
  10431. +
  10432. +#include "hash_table.h"
  10433. +
  10434. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10435. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10436. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10437. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10438. +
  10439. +/**
  10440. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10441. + * the same abstract package and 0 otherwise.
  10442. + */
  10443. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10444. +
  10445. +/**
  10446. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10447. + * otherwise.
  10448. + */
  10449. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10450. +
  10451. +/**
  10452. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10453. + * otherwise.
  10454. + */
  10455. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10456. +
  10457. +/**
  10458. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10459. + * otherwise.
  10460. + */
  10461. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10462. +
  10463. +/**
  10464. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10465. + * otherwise.
  10466. + */
  10467. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10468. +
  10469. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10470. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10471. +void freeDepends(pkg_t *pkg);
  10472. +void printDepends(pkg_t * pkg);
  10473. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10474. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10475. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10476. +int pkg_dependence_satisfiable(depend_t *depend);
  10477. +int pkg_dependence_satisfied(depend_t *depend);
  10478. +
  10479. +#endif
  10480. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_dest.c busybox-1.23.0/archival/libipkg/pkg_dest.c
  10481. --- busybox-1.23.0.orig/archival/libipkg/pkg_dest.c 1969-12-31 18:00:00.000000000 -0600
  10482. +++ busybox-1.23.0/archival/libipkg/pkg_dest.c 2015-01-09 11:18:22.432197244 -0600
  10483. @@ -0,0 +1,92 @@
  10484. +/* pkg_dest.c - the itsy package management system
  10485. +
  10486. + Carl D. Worth
  10487. +
  10488. + Copyright (C) 2001 University of Southern California
  10489. +
  10490. + This program is free software; you can redistribute it and/or
  10491. + modify it under the terms of the GNU General Public License as
  10492. + published by the Free Software Foundation; either version 2, or (at
  10493. + your option) any later version.
  10494. +
  10495. + This program is distributed in the hope that it will be useful, but
  10496. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10497. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10498. + General Public License for more details.
  10499. +*/
  10500. +
  10501. +#include "ipkg.h"
  10502. +
  10503. +#include "pkg_dest.h"
  10504. +#include "file_util.h"
  10505. +#include "str_util.h"
  10506. +#include "sprintf_alloc.h"
  10507. +
  10508. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10509. +{
  10510. + dest->name = strdup(name);
  10511. +
  10512. + /* Guarantee that dest->root_dir ends with a '/' */
  10513. + if (str_ends_with(root_dir, "/")) {
  10514. + dest->root_dir = strdup(root_dir);
  10515. + } else {
  10516. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10517. + }
  10518. + file_mkdir_hier(dest->root_dir, 0755);
  10519. +
  10520. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10521. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10522. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10523. +
  10524. + if (str_starts_with (lists_dir, "/"))
  10525. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10526. + else
  10527. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10528. +
  10529. + file_mkdir_hier(dest->lists_dir, 0755);
  10530. +
  10531. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10532. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10533. + file_mkdir_hier(dest->info_dir, 0755);
  10534. +
  10535. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10536. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10537. +
  10538. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10539. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10540. +
  10541. + dest->status_file = NULL;
  10542. +
  10543. + return 0;
  10544. +}
  10545. +
  10546. +void pkg_dest_deinit(pkg_dest_t *dest)
  10547. +{
  10548. + free(dest->name);
  10549. + dest->name = NULL;
  10550. +
  10551. + free(dest->root_dir);
  10552. + dest->root_dir = NULL;
  10553. +
  10554. + free(dest->ipkg_dir);
  10555. + dest->ipkg_dir = NULL;
  10556. +
  10557. + free(dest->lists_dir);
  10558. + dest->lists_dir = NULL;
  10559. +
  10560. + free(dest->info_dir);
  10561. + dest->info_dir = NULL;
  10562. +
  10563. + free(dest->status_file_name);
  10564. + dest->status_file_name = NULL;
  10565. +
  10566. + free(dest->status_file_tmp_name);
  10567. + dest->status_file_tmp_name = NULL;
  10568. +
  10569. + if (dest->status_file) {
  10570. + fclose(dest->status_file);
  10571. + }
  10572. + dest->status_file = NULL;
  10573. +
  10574. + dest->root_dir = NULL;
  10575. +}
  10576. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_dest.h busybox-1.23.0/archival/libipkg/pkg_dest.h
  10577. --- busybox-1.23.0.orig/archival/libipkg/pkg_dest.h 1969-12-31 18:00:00.000000000 -0600
  10578. +++ busybox-1.23.0/archival/libipkg/pkg_dest.h 2015-01-09 11:18:22.432197244 -0600
  10579. @@ -0,0 +1,38 @@
  10580. +/* pkg_dest.h - the itsy package management system
  10581. +
  10582. + Carl D. Worth
  10583. +
  10584. + Copyright (C) 2001 University of Southern California
  10585. +
  10586. + This program is free software; you can redistribute it and/or
  10587. + modify it under the terms of the GNU General Public License as
  10588. + published by the Free Software Foundation; either version 2, or (at
  10589. + your option) any later version.
  10590. +
  10591. + This program is distributed in the hope that it will be useful, but
  10592. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10593. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10594. + General Public License for more details.
  10595. +*/
  10596. +
  10597. +#ifndef PKG_DEST_H
  10598. +#define PKG_DEST_H
  10599. +
  10600. +typedef struct pkg_dest pkg_dest_t;
  10601. +struct pkg_dest
  10602. +{
  10603. + char *name;
  10604. + char *root_dir;
  10605. + char *ipkg_dir;
  10606. + char *lists_dir;
  10607. + char *info_dir;
  10608. + char *status_file_name;
  10609. + char *status_file_tmp_name;
  10610. + FILE *status_file;
  10611. +};
  10612. +
  10613. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10614. +void pkg_dest_deinit(pkg_dest_t *dest);
  10615. +
  10616. +#endif
  10617. +
  10618. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_dest_list.c busybox-1.23.0/archival/libipkg/pkg_dest_list.c
  10619. --- busybox-1.23.0.orig/archival/libipkg/pkg_dest_list.c 1969-12-31 18:00:00.000000000 -0600
  10620. +++ busybox-1.23.0/archival/libipkg/pkg_dest_list.c 2015-01-09 11:18:22.432197244 -0600
  10621. @@ -0,0 +1,85 @@
  10622. +/* pkg_dest_list.c - the itsy package management system
  10623. +
  10624. + Carl D. Worth
  10625. +
  10626. + Copyright (C) 2001 University of Southern California
  10627. +
  10628. + This program is free software; you can redistribute it and/or
  10629. + modify it under the terms of the GNU General Public License as
  10630. + published by the Free Software Foundation; either version 2, or (at
  10631. + your option) any later version.
  10632. +
  10633. + This program is distributed in the hope that it will be useful, but
  10634. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10635. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10636. + General Public License for more details.
  10637. +*/
  10638. +
  10639. +#include "ipkg.h"
  10640. +
  10641. +#include "pkg_dest.h"
  10642. +#include "void_list.h"
  10643. +#include "pkg_dest_list.h"
  10644. +
  10645. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10646. +{
  10647. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10648. +}
  10649. +
  10650. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10651. +{
  10652. + void_list_elt_deinit((void_list_elt_t *) elt);
  10653. +}
  10654. +
  10655. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10656. +{
  10657. + return void_list_init((void_list_t *) list);
  10658. +}
  10659. +
  10660. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10661. +{
  10662. + pkg_dest_list_elt_t *iter;
  10663. + pkg_dest_t *pkg_dest;
  10664. +
  10665. + for (iter = list->head; iter; iter = iter->next) {
  10666. + pkg_dest = iter->data;
  10667. + pkg_dest_deinit(pkg_dest);
  10668. +
  10669. + /* malloced in pkg_dest_list_append */
  10670. + free(pkg_dest);
  10671. + iter->data = NULL;
  10672. + }
  10673. + void_list_deinit((void_list_t *) list);
  10674. +}
  10675. +
  10676. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10677. + const char *root_dir,const char *lists_dir)
  10678. +{
  10679. + int err;
  10680. + pkg_dest_t *pkg_dest;
  10681. +
  10682. + /* freed in plg_dest_list_deinit */
  10683. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10684. + if (pkg_dest == NULL) {
  10685. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10686. + return NULL;
  10687. + }
  10688. +
  10689. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10690. + err = void_list_append((void_list_t *) list, pkg_dest);
  10691. + if (err) {
  10692. + return NULL;
  10693. + }
  10694. +
  10695. + return pkg_dest;
  10696. +}
  10697. +
  10698. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10699. +{
  10700. + return void_list_push((void_list_t *) list, data);
  10701. +}
  10702. +
  10703. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10704. +{
  10705. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10706. +}
  10707. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_dest_list.h busybox-1.23.0/archival/libipkg/pkg_dest_list.h
  10708. --- busybox-1.23.0.orig/archival/libipkg/pkg_dest_list.h 1969-12-31 18:00:00.000000000 -0600
  10709. +++ busybox-1.23.0/archival/libipkg/pkg_dest_list.h 2015-01-09 11:18:22.432197244 -0600
  10710. @@ -0,0 +1,50 @@
  10711. +/* pkg_dest_list.h - the itsy package management system
  10712. +
  10713. + Carl D. Worth
  10714. +
  10715. + Copyright (C) 2001 University of Southern California
  10716. +
  10717. + This program is free software; you can redistribute it and/or
  10718. + modify it under the terms of the GNU General Public License as
  10719. + published by the Free Software Foundation; either version 2, or (at
  10720. + your option) any later version.
  10721. +
  10722. + This program is distributed in the hope that it will be useful, but
  10723. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10724. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10725. + General Public License for more details.
  10726. +*/
  10727. +
  10728. +#ifndef PKG_DEST_LIST_H
  10729. +#define PKG_DEST_LIST_H
  10730. +
  10731. +#include "pkg_dest.h"
  10732. +
  10733. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10734. +struct pkg_dest_list_elt
  10735. +{
  10736. + pkg_dest_list_elt_t *next;
  10737. + pkg_dest_t *data;
  10738. +};
  10739. +
  10740. +typedef struct pkg_dest_list pkg_dest_list_t;
  10741. +struct pkg_dest_list
  10742. +{
  10743. + pkg_dest_list_elt_t pre_head;
  10744. + pkg_dest_list_elt_t *head;
  10745. + pkg_dest_list_elt_t *tail;
  10746. +};
  10747. +
  10748. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10749. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10750. +
  10751. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10752. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10753. +
  10754. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10755. + const char *root_dir,const char* lists_dir);
  10756. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10757. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10758. +
  10759. +#endif
  10760. +
  10761. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_extract.c busybox-1.23.0/archival/libipkg/pkg_extract.c
  10762. --- busybox-1.23.0.orig/archival/libipkg/pkg_extract.c 1969-12-31 18:00:00.000000000 -0600
  10763. +++ busybox-1.23.0/archival/libipkg/pkg_extract.c 2015-01-09 11:18:22.432197244 -0600
  10764. @@ -0,0 +1,255 @@
  10765. +/* pkg_extract.c - the itsy package management system
  10766. +
  10767. + Carl D. Worth
  10768. +
  10769. + Copyright (C) 2001 University of Southern California
  10770. +
  10771. + This program is free software; you can redistribute it and/or
  10772. + modify it under the terms of the GNU General Public License as
  10773. + published by the Free Software Foundation; either version 2, or (at
  10774. + your option) any later version.
  10775. +
  10776. + This program is distributed in the hope that it will be useful, but
  10777. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10778. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10779. + General Public License for more details.
  10780. +*/
  10781. +
  10782. +#include "ipkg.h"
  10783. +#include <errno.h>
  10784. +#include <fcntl.h>
  10785. +#include <stdio.h>
  10786. +
  10787. +#include "pkg_extract.h"
  10788. +
  10789. +#include "libbb.h"
  10790. +#include "file_util.h"
  10791. +#include "sprintf_alloc.h"
  10792. +#include "bb_archive.h"
  10793. +
  10794. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10795. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10796. +#define IPKG_CONTROL_FILE "control"
  10797. +
  10798. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10799. +{
  10800. + char *name_ptr = archive_handle->file_header->name;
  10801. +
  10802. + /* Skip all leading "/" */
  10803. + while (*name_ptr == '/')
  10804. + name_ptr++;
  10805. + /* Skip all leading "./" and "../" */
  10806. + while (name_ptr[0] == '.') {
  10807. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10808. + name_ptr++;
  10809. + if (name_ptr[1] != '/')
  10810. + break;
  10811. + name_ptr += 2;
  10812. + }
  10813. +
  10814. + if (name_ptr[0] != '\0') {
  10815. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10816. + data_extract_all(archive_handle);
  10817. + }
  10818. +}
  10819. +
  10820. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10821. +{
  10822. + unsigned size = archive_handle->file_header->size;
  10823. +
  10824. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10825. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10826. +}
  10827. +
  10828. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10829. +{
  10830. + archive_handle_t *archive;
  10831. + char *path;
  10832. +
  10833. + sprintf_alloc(&path, "%s/", dir);
  10834. + archive = init_handle();
  10835. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10836. + archive->filter = filter_accept_list;
  10837. + llist_add_to(&(archive->accept), (char *)filename);
  10838. + archive->dpkg__buffer = path;
  10839. + archive->action_data = ipkg_data_extract_all_prefix;
  10840. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10841. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10842. + close(archive->src_fd);
  10843. + free(archive->accept);
  10844. + free(archive);
  10845. + free(path);
  10846. +}
  10847. +
  10848. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10849. +{
  10850. + unsigned int size = strlen(archive->file_header->name) + 2;
  10851. +
  10852. + if (archive->dpkg__buffer == NULL) {
  10853. + archive->dpkg__buffer = xmalloc(size);
  10854. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10855. + } else {
  10856. + size += strlen(archive->dpkg__buffer);
  10857. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10858. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10859. + }
  10860. + strcat(archive->dpkg__buffer, "\n");
  10861. + data_skip(archive);
  10862. +}
  10863. +
  10864. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10865. +{
  10866. + archive_handle_t *archive;
  10867. + char *name;
  10868. + const char *filename = IPKG_CONTROL_FILE;
  10869. +
  10870. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10871. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10872. + archive = init_handle();
  10873. + archive->src_fd = xopen(name, O_RDONLY);
  10874. + archive->filter = filter_accept_list;
  10875. + llist_add_to(&(archive->accept), (char *)filename);
  10876. + archive->action_data = ipkg_data_extract_to_buffer;
  10877. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10878. + close(archive->src_fd);
  10879. + fputs(archive->dpkg__buffer, stream);
  10880. + free(archive->dpkg__buffer);
  10881. + free(archive->accept);
  10882. + free(archive);
  10883. + free(name);
  10884. +
  10885. + return 0;
  10886. +}
  10887. +
  10888. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10889. +{
  10890. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10891. +}
  10892. +
  10893. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10894. +{
  10895. + archive_handle_t *archive;
  10896. + char *name;
  10897. + char *path;
  10898. +
  10899. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10900. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10901. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10902. + archive = init_handle();
  10903. + archive->src_fd = xopen(name, O_RDONLY);
  10904. + archive->filter = filter_accept_all;
  10905. + archive->dpkg__buffer = path;
  10906. + archive->action_data = ipkg_data_extract_all_prefix;
  10907. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10908. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10909. + close(archive->src_fd);
  10910. + free(archive);
  10911. + free(path);
  10912. + free(name);
  10913. +
  10914. + return 0;
  10915. +}
  10916. +
  10917. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10918. +{
  10919. + archive_handle_t *archive;
  10920. + char *name;
  10921. + char *path;
  10922. +
  10923. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10924. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10925. + sprintf_alloc(&path, "%s/", dir);
  10926. + archive = init_handle();
  10927. + archive->src_fd = xopen(name, O_RDONLY);
  10928. + archive->filter = filter_accept_all;
  10929. + archive->dpkg__buffer = path;
  10930. + archive->action_data = ipkg_data_extract_all_prefix;
  10931. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10932. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10933. + close(archive->src_fd);
  10934. + free(archive);
  10935. + free(path);
  10936. + free(name);
  10937. +
  10938. + return 0;
  10939. +}
  10940. +
  10941. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10942. +{
  10943. + int err=0;
  10944. + char *line, *data_file;
  10945. + FILE *file;
  10946. + FILE *tmp;
  10947. +
  10948. + file = fopen(file_name, "w");
  10949. + if (file == NULL) {
  10950. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10951. + __FUNCTION__, file_name);
  10952. + return EINVAL;
  10953. + }
  10954. +
  10955. + tmp = tmpfile();
  10956. + if (pkg->installed_files) {
  10957. + str_list_elt_t *elt;
  10958. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10959. + fprintf(file, "%s\n", elt->data);
  10960. + }
  10961. + } else {
  10962. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10963. + if (err) {
  10964. + fclose(file);
  10965. + fclose(tmp);
  10966. + return err;
  10967. + }
  10968. +
  10969. + /* Fixup data file names by removing the initial '.' */
  10970. + rewind(tmp);
  10971. + while (1) {
  10972. + line = file_read_line_alloc(tmp);
  10973. + if (line == NULL) {
  10974. + break;
  10975. + }
  10976. +
  10977. + data_file = line;
  10978. + if (*data_file == '.') {
  10979. + data_file++;
  10980. + }
  10981. +
  10982. + if (*data_file != '/') {
  10983. + fputs("/", file);
  10984. + }
  10985. +
  10986. + /* I have no idea why, but this is what dpkg does */
  10987. + if (strcmp(data_file, "/\n") == 0) {
  10988. + fputs("/.\n", file);
  10989. + } else {
  10990. + fputs(data_file, file);
  10991. + }
  10992. + }
  10993. + }
  10994. + fclose(tmp);
  10995. + fclose(file);
  10996. +
  10997. + return err;
  10998. +}
  10999. +
  11000. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11001. +{
  11002. + archive_handle_t *archive;
  11003. + char *name;
  11004. +
  11005. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11006. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11007. + archive = init_handle();
  11008. + archive->src_fd = xopen(name, O_RDONLY);
  11009. + archive->filter = filter_accept_all;
  11010. + archive->action_data = data_extract_file_name_to_buffer;
  11011. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11012. + close(archive->src_fd);
  11013. + fputs(archive->dpkg__buffer, file);
  11014. + free(archive->dpkg__buffer);
  11015. + free(archive);
  11016. + free(name);
  11017. +
  11018. + return 0;
  11019. +}
  11020. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_extract.h busybox-1.23.0/archival/libipkg/pkg_extract.h
  11021. --- busybox-1.23.0.orig/archival/libipkg/pkg_extract.h 1969-12-31 18:00:00.000000000 -0600
  11022. +++ busybox-1.23.0/archival/libipkg/pkg_extract.h 2015-01-09 11:18:22.432197244 -0600
  11023. @@ -0,0 +1,32 @@
  11024. +/* pkg_extract.c - the itsy package management system
  11025. +
  11026. + Carl D. Worth
  11027. +
  11028. + Copyright (C) 2001 University of Southern California
  11029. +
  11030. + This program is free software; you can redistribute it and/or
  11031. + modify it under the terms of the GNU General Public License as
  11032. + published by the Free Software Foundation; either version 2, or (at
  11033. + your option) any later version.
  11034. +
  11035. + This program is distributed in the hope that it will be useful, but
  11036. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11037. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11038. + General Public License for more details.
  11039. +*/
  11040. +
  11041. +#ifndef PKG_EXTRACT_H
  11042. +#define PKG_EXTRACT_H
  11043. +
  11044. +#include "pkg.h"
  11045. +
  11046. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11047. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11048. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11049. + const char *dir,
  11050. + const char *prefix);
  11051. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11052. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11053. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11054. +
  11055. +#endif
  11056. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg.h busybox-1.23.0/archival/libipkg/pkg.h
  11057. --- busybox-1.23.0.orig/archival/libipkg/pkg.h 1969-12-31 18:00:00.000000000 -0600
  11058. +++ busybox-1.23.0/archival/libipkg/pkg.h 2015-01-09 11:18:22.428197243 -0600
  11059. @@ -0,0 +1,229 @@
  11060. +/* pkg.h - the itsy package management system
  11061. +
  11062. + Carl D. Worth
  11063. +
  11064. + Copyright (C) 2001 University of Southern California
  11065. +
  11066. + This program is free software; you can redistribute it and/or
  11067. + modify it under the terms of the GNU General Public License as
  11068. + published by the Free Software Foundation; either version 2, or (at
  11069. + your option) any later version.
  11070. +
  11071. + This program is distributed in the hope that it will be useful, but
  11072. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11073. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11074. + General Public License for more details.
  11075. +*/
  11076. +
  11077. +#ifndef PKG_H
  11078. +#define PKG_H
  11079. +
  11080. +#include <sys/types.h>
  11081. +#include <sys/stat.h>
  11082. +#include <unistd.h>
  11083. +
  11084. +#include "pkg_vec.h"
  11085. +#include "str_list.h"
  11086. +#include "pkg_src.h"
  11087. +#include "pkg_dest.h"
  11088. +#include "ipkg_conf.h"
  11089. +#include "conffile_list.h"
  11090. +
  11091. +struct ipkg_conf;
  11092. +
  11093. +/* I think "Size" is currently the shortest field name */
  11094. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11095. +
  11096. +enum pkg_state_want
  11097. +{
  11098. + SW_UNKNOWN = 1,
  11099. + SW_INSTALL,
  11100. + SW_DEINSTALL,
  11101. + SW_PURGE,
  11102. + SW_LAST_STATE_WANT
  11103. +};
  11104. +typedef enum pkg_state_want pkg_state_want_t;
  11105. +
  11106. +enum pkg_state_flag
  11107. +{
  11108. + SF_OK = 0,
  11109. + SF_REINSTREQ = 1,
  11110. + SF_HOLD = 2, /* do not upgrade version */
  11111. + SF_REPLACE = 4, /* replace this package */
  11112. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11113. + SF_PREFER = 16, /* prefer this version */
  11114. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11115. + SF_MARKED = 64, /* temporary mark */
  11116. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11117. + SF_USER = 256,
  11118. + SF_LAST_STATE_FLAG
  11119. +};
  11120. +typedef enum pkg_state_flag pkg_state_flag_t;
  11121. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11122. +
  11123. +enum pkg_state_status
  11124. +{
  11125. + SS_NOT_INSTALLED = 1,
  11126. + SS_UNPACKED,
  11127. + SS_HALF_CONFIGURED,
  11128. + SS_INSTALLED,
  11129. + SS_HALF_INSTALLED,
  11130. + SS_CONFIG_FILES,
  11131. + SS_POST_INST_FAILED,
  11132. + SS_REMOVAL_FAILED,
  11133. + SS_LAST_STATE_STATUS
  11134. +};
  11135. +typedef enum pkg_state_status pkg_state_status_t;
  11136. +
  11137. +struct abstract_pkg{
  11138. + char * name;
  11139. + int dependencies_checked;
  11140. + pkg_vec_t * pkgs;
  11141. + pkg_state_status_t state_status;
  11142. + pkg_state_flag_t state_flag;
  11143. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11144. + abstract_pkg_vec_t * provided_by;
  11145. + abstract_pkg_vec_t * replaced_by;
  11146. +};
  11147. +
  11148. +#include "pkg_depends.h"
  11149. +
  11150. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11151. +
  11152. + The 3 version fields should go into a single version struct. (This
  11153. + is especially important since, currently, pkg->version can easily
  11154. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11155. + distinct. This has been the source of multiple bugs.
  11156. +
  11157. + The 3 state fields could possibly also go into their own struct.
  11158. +
  11159. + All fields which deal with lists of packages, (Depends,
  11160. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11161. + be handled by a single struct in pkg_t
  11162. +
  11163. + All string fields for which there is a small set of possible
  11164. + values, (section, maintainer, architecture, maybe version?), that
  11165. + are reused among different packages -- for all such packages we
  11166. + should move from "char *"s to some atom datatype to share data
  11167. + storage and use less memory. We might even do reference counting,
  11168. + but probably not since most often we only create new pkg_t structs,
  11169. + we don't often free them. */
  11170. +struct pkg
  11171. +{
  11172. + char *name;
  11173. + unsigned long epoch;
  11174. + char *version;
  11175. + char *revision;
  11176. + char *familiar_revision;
  11177. + pkg_src_t *src;
  11178. + pkg_dest_t *dest;
  11179. + char *architecture;
  11180. + char *section;
  11181. + char *maintainer;
  11182. + char *description;
  11183. + pkg_state_want_t state_want;
  11184. + pkg_state_flag_t state_flag;
  11185. + pkg_state_status_t state_status;
  11186. + char **depends_str;
  11187. + int depends_count;
  11188. + char **pre_depends_str;
  11189. + int pre_depends_count;
  11190. + char **recommends_str;
  11191. + int recommends_count;
  11192. + char **suggests_str;
  11193. + int suggests_count;
  11194. + compound_depend_t * depends;
  11195. +
  11196. + /* Abhaya: new conflicts */
  11197. + char **conflicts_str;
  11198. + compound_depend_t * conflicts;
  11199. + int conflicts_count;
  11200. +
  11201. + char **replaces_str;
  11202. + int replaces_count;
  11203. + abstract_pkg_t ** replaces;
  11204. +
  11205. + char **provides_str;
  11206. + int provides_count;
  11207. + abstract_pkg_t ** provides;
  11208. +
  11209. + abstract_pkg_t *parent;
  11210. +
  11211. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11212. +
  11213. + char *filename;
  11214. + char *local_filename;
  11215. + char *url;
  11216. + char *tmp_unpack_dir;
  11217. + char *md5sum;
  11218. + char *size;
  11219. + char *installed_size;
  11220. + char *priority;
  11221. + char *source;
  11222. + conffile_list_t conffiles;
  11223. + time_t installed_time;
  11224. + /* As pointer for lazy evaluation */
  11225. + str_list_t *installed_files;
  11226. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11227. + mechanism to avoid the problem here, (which is that the
  11228. + installed_files list was being freed from an inner loop while
  11229. + still being used within an outer loop. */
  11230. + int installed_files_ref_cnt;
  11231. + int essential;
  11232. + int arch_priority;
  11233. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11234. + int provided_by_hand;
  11235. +};
  11236. +
  11237. +pkg_t *pkg_new(void);
  11238. +int pkg_init(pkg_t *pkg);
  11239. +void pkg_deinit(pkg_t *pkg);
  11240. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11241. +abstract_pkg_t *abstract_pkg_new(void);
  11242. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11243. +
  11244. +/*
  11245. + * merges fields from newpkg into oldpkg.
  11246. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11247. + */
  11248. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11249. +
  11250. +char *pkg_version_str_alloc(pkg_t *pkg);
  11251. +
  11252. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11253. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11254. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11255. +
  11256. +char * pkg_formatted_info(pkg_t *pkg );
  11257. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11258. +
  11259. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11260. +
  11261. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11262. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11263. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11264. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11265. +int pkg_free_installed_files(pkg_t *pkg);
  11266. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11267. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11268. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11269. + const char *script, const char *args);
  11270. +
  11271. +/* enum mappings */
  11272. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11273. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11274. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11275. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11276. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11277. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11278. +
  11279. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11280. +
  11281. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11282. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11283. +int pkg_free_installed_files(pkg_t *pkg);
  11284. +
  11285. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11286. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11287. +
  11288. +#endif
  11289. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_hash.c busybox-1.23.0/archival/libipkg/pkg_hash.c
  11290. --- busybox-1.23.0.orig/archival/libipkg/pkg_hash.c 1969-12-31 18:00:00.000000000 -0600
  11291. +++ busybox-1.23.0/archival/libipkg/pkg_hash.c 2015-01-09 11:18:22.440197244 -0600
  11292. @@ -0,0 +1,623 @@
  11293. +/* ipkg_hash.c - the itsy package management system
  11294. +
  11295. + Steven M. Ayer
  11296. +
  11297. + Copyright (C) 2002 Compaq Computer Corporation
  11298. +
  11299. + This program is free software; you can redistribute it and/or
  11300. + modify it under the terms of the GNU General Public License as
  11301. + published by the Free Software Foundation; either version 2, or (at
  11302. + your option) any later version.
  11303. +
  11304. + This program is distributed in the hope that it will be useful, but
  11305. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11306. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11307. + General Public License for more details.
  11308. +*/
  11309. +
  11310. +#include "ipkg.h"
  11311. +#include <errno.h>
  11312. +#include <ctype.h>
  11313. +#include <stdlib.h>
  11314. +#include <string.h>
  11315. +
  11316. +#include "hash_table.h"
  11317. +#include "pkg.h"
  11318. +#include "ipkg_message.h"
  11319. +#include "pkg_vec.h"
  11320. +#include "pkg_hash.h"
  11321. +#include "pkg_parse.h"
  11322. +#include "ipkg_utils.h"
  11323. +
  11324. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11325. +
  11326. +/*
  11327. + * this will talk to both feeds-lists files and installed status files
  11328. + * example api:
  11329. + *
  11330. + * hash_table_t hash;
  11331. + * pkg_hash_init(name, &hash, 1000);
  11332. + * pkg_hash_add_from_file(<feed filename>);
  11333. + *
  11334. + * the query function is just there as a shell to prove to me that this
  11335. + * sort of works, but isn't far from doing something useful
  11336. + *
  11337. + * -sma, 12/21/01
  11338. + * modified: CDW 3 Jan. 2002
  11339. + */
  11340. +
  11341. +
  11342. +
  11343. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11344. +{
  11345. + return hash_table_init(name, hash, len);
  11346. +}
  11347. +
  11348. +void pkg_hash_deinit(hash_table_t *hash)
  11349. +{
  11350. + hash_table_deinit(hash);
  11351. +}
  11352. +
  11353. +
  11354. +/* Find the default arch for a given package status file if none is given. */
  11355. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11356. +{
  11357. + nv_pair_list_elt_t *l;
  11358. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11359. + int def_prio = 0; /* Other archs override this */
  11360. +
  11361. + l = conf->arch_list.head;
  11362. +
  11363. + while (l) {
  11364. + nv_pair_t *nv = l->data;
  11365. + int priority = strtol(nv->value, NULL, 0);
  11366. +
  11367. + /* Check if this arch has higher priority, and is valid */
  11368. + if ((priority > def_prio) &&
  11369. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11370. + /* Our new default */
  11371. + def_prio = priority;
  11372. + def_arch = nv->name;
  11373. + }
  11374. + l = l->next;
  11375. + }
  11376. +
  11377. + return strdup(def_arch);
  11378. +}
  11379. +
  11380. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11381. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11382. +{
  11383. + hash_table_t *hash = &conf->pkg_hash;
  11384. + char **raw;
  11385. + char **raw_start;
  11386. + pkg_t *pkg;
  11387. +
  11388. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11389. + if (!raw)
  11390. + return -ENOMEM;
  11391. +
  11392. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11393. + pkg = pkg_new();
  11394. + if (!pkg)
  11395. + return -ENOMEM;
  11396. +
  11397. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11398. + if (!pkg->architecture) {
  11399. + char *version_str = pkg_version_str_alloc(pkg);
  11400. + pkg->architecture = pkg_get_default_arch(conf);
  11401. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11402. + pkg->name, version_str, pkg->architecture);
  11403. + free(version_str);
  11404. + }
  11405. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11406. + } else {
  11407. + free(pkg);
  11408. + }
  11409. + }
  11410. +
  11411. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11412. + memory after read_raw_pkgs_from_file */
  11413. + raw = raw_start;
  11414. + while (*raw) {
  11415. + free(*raw++);
  11416. + }
  11417. + free(raw_start);
  11418. + return 0;
  11419. +}
  11420. +
  11421. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11422. +{
  11423. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11424. +}
  11425. +
  11426. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11427. +{
  11428. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11429. + if (apkg)
  11430. + return NULL;
  11431. + return apkg->provided_by;
  11432. +}
  11433. +
  11434. +
  11435. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11436. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11437. +{
  11438. + int i;
  11439. + int nprovides = 0;
  11440. + int nmatching = 0;
  11441. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11442. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11443. + abstract_pkg_vec_t *provided_apkg_vec;
  11444. + abstract_pkg_t **provided_apkgs;
  11445. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11446. + pkg_t *latest_installed_parent = NULL;
  11447. + pkg_t *latest_matching = NULL;
  11448. + pkg_t *held_pkg = NULL;
  11449. + pkg_t *good_pkg_by_name = NULL;
  11450. +
  11451. + if (matching_apkgs == NULL || providers == NULL ||
  11452. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11453. + return NULL;
  11454. +
  11455. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11456. +
  11457. + provided_apkg_vec = apkg->provided_by;
  11458. + nprovides = provided_apkg_vec->len;
  11459. + provided_apkgs = provided_apkg_vec->pkgs;
  11460. + if (nprovides > 1)
  11461. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11462. +
  11463. + /* accumulate all the providers */
  11464. + for (i = 0; i < nprovides; i++) {
  11465. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11466. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11467. + abstract_pkg_vec_insert(providers, provider_apkg);
  11468. + }
  11469. + nprovides = providers->len;
  11470. +
  11471. + for (i = 0; i < nprovides; i++) {
  11472. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11473. + abstract_pkg_t *replacement_apkg = NULL;
  11474. + pkg_vec_t *vec;
  11475. +
  11476. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11477. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11478. + if (provider_apkg->replaced_by->len > 1) {
  11479. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11480. + provider_apkg->name, replacement_apkg->name);
  11481. + }
  11482. + }
  11483. +
  11484. + if (replacement_apkg)
  11485. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11486. + replacement_apkg->name, provider_apkg->name);
  11487. +
  11488. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11489. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11490. + continue;
  11491. + else
  11492. + provider_apkg = replacement_apkg;
  11493. + }
  11494. +
  11495. + if (!(vec = provider_apkg->pkgs)) {
  11496. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11497. + continue;
  11498. + }
  11499. +
  11500. +
  11501. + /* now check for supported architecture */
  11502. + {
  11503. + int max_count = 0;
  11504. + int j;
  11505. +
  11506. + /* count packages matching max arch priority and keep track of last one */
  11507. + for (j = 0; j < vec->len; j++) {
  11508. + pkg_t *maybe = vec->pkgs[j];
  11509. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11510. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11511. + if (maybe->arch_priority > 0) {
  11512. + max_count++;
  11513. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11514. + pkg_vec_insert(matching_pkgs, maybe);
  11515. + }
  11516. + }
  11517. + }
  11518. + }
  11519. +
  11520. + if (matching_pkgs->len > 1)
  11521. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11522. + if (matching_apkgs->len > 1)
  11523. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11524. +
  11525. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11526. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11527. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11528. + Until now I always got the latest, but that breaks the downgrade option.
  11529. + If I stop at the first one, I would probably miss the new ones
  11530. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11531. + or from a Packages feed.
  11532. + 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*/
  11533. +/*Pigi*/
  11534. +
  11535. + for (i = 0; i < matching_pkgs->len; i++) {
  11536. + pkg_t *matching = matching_pkgs->pkgs[i];
  11537. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11538. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11539. + good_pkg_by_name = matching;
  11540. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11541. + break;
  11542. + }
  11543. + }
  11544. +
  11545. +
  11546. + for (i = 0; i < matching_pkgs->len; i++) {
  11547. + pkg_t *matching = matching_pkgs->pkgs[i];
  11548. + latest_matching = matching;
  11549. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11550. + latest_installed_parent = matching;
  11551. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11552. + if (held_pkg)
  11553. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11554. + held_pkg->name, matching->name);
  11555. + held_pkg = matching;
  11556. + }
  11557. + }
  11558. +
  11559. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11560. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11561. + apkg->name, matching_apkgs->len);
  11562. + for (i = 0; i < matching_apkgs->len; i++) {
  11563. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11564. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11565. + }
  11566. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11567. + }
  11568. +
  11569. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11570. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11571. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11572. + for (i = 0; i < matching_pkgs->len; i++) {
  11573. + pkg_t *matching = matching_pkgs->pkgs[i];
  11574. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11575. + matching->name, matching->version, matching->architecture);
  11576. + }
  11577. + }
  11578. +
  11579. + nmatching = matching_apkgs->len;
  11580. +
  11581. + pkg_vec_free(matching_pkgs);
  11582. + abstract_pkg_vec_free(matching_apkgs);
  11583. + abstract_pkg_vec_free(providers);
  11584. +
  11585. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11586. + return good_pkg_by_name;
  11587. + }
  11588. + if (held_pkg) {
  11589. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11590. + return held_pkg;
  11591. + }
  11592. + if (latest_installed_parent) {
  11593. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11594. + return latest_installed_parent;
  11595. + }
  11596. + if (nmatching > 1) {
  11597. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11598. + return NULL;
  11599. + }
  11600. + if (latest_matching) {
  11601. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11602. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11603. + return latest_matching;
  11604. + }
  11605. + return NULL;
  11606. +}
  11607. +
  11608. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11609. +{
  11610. + const char *name = (const char *)cdata;
  11611. + if (strcmp(pkg->name, name) == 0)
  11612. + return 1;
  11613. + else
  11614. + return 0;
  11615. +}
  11616. +
  11617. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11618. +{
  11619. + hash_table_t *hash = &conf->pkg_hash;
  11620. + abstract_pkg_t *apkg = NULL;
  11621. +
  11622. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11623. + return NULL;
  11624. +
  11625. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11626. +}
  11627. +
  11628. +
  11629. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11630. + const char *pkg_name,
  11631. + const char * version)
  11632. +{
  11633. + pkg_vec_t * vec;
  11634. + register int i;
  11635. + char *version_str = NULL;
  11636. +
  11637. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11638. + return NULL;
  11639. +
  11640. + for(i = 0; i < vec->len; i++) {
  11641. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11642. + if(!strcmp(version_str, version)) {
  11643. + free(version_str);
  11644. + break;
  11645. + }
  11646. + free(version_str);
  11647. + }
  11648. +
  11649. + if(i == vec->len)
  11650. + return NULL;
  11651. +
  11652. + return vec->pkgs[i];
  11653. +}
  11654. +
  11655. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11656. + const char *pkg_name,
  11657. + pkg_dest_t *dest)
  11658. +{
  11659. + pkg_vec_t * vec;
  11660. + register int i;
  11661. +
  11662. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11663. + return NULL;
  11664. + }
  11665. +
  11666. + for(i = 0; i < vec->len; i++)
  11667. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11668. + return vec->pkgs[i];
  11669. + }
  11670. + return NULL;
  11671. +}
  11672. +
  11673. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11674. + const char *pkg_name)
  11675. +{
  11676. + pkg_vec_t * vec;
  11677. + register int i;
  11678. +
  11679. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11680. + return NULL;
  11681. + }
  11682. +
  11683. + for(i = 0; i < vec->len; i++)
  11684. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11685. + return vec->pkgs[i];
  11686. + }
  11687. +
  11688. + return NULL;
  11689. +}
  11690. +
  11691. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11692. +{
  11693. + abstract_pkg_t * ab_pkg;
  11694. +
  11695. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11696. + return NULL;
  11697. + }
  11698. +
  11699. + if (ab_pkg->pkgs) {
  11700. + return ab_pkg->pkgs;
  11701. + } else if (ab_pkg->provided_by) {
  11702. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11703. + if (abpkg != NULL){
  11704. + return abpkg->pkgs;
  11705. + } else {
  11706. + return ab_pkg->pkgs;
  11707. + }
  11708. + } else {
  11709. + return NULL;
  11710. + }
  11711. +}
  11712. +
  11713. +static int pkg_compare_names(const void *p1, const void *p2)
  11714. +{
  11715. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11716. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11717. + if (pkg1->name == NULL)
  11718. + return 1;
  11719. + if (pkg2->name == NULL)
  11720. + return -1;
  11721. + return(strcmp(pkg1->name, pkg2->name));
  11722. +}
  11723. +
  11724. +
  11725. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11726. +{
  11727. + int j;
  11728. + const char *name;
  11729. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11730. + pkg_vec_t *all = (pkg_vec_t *)data;
  11731. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11732. + name = pkg_name;
  11733. + if (pkg_vec) {
  11734. + for (j = 0; j < pkg_vec->len; j++) {
  11735. + pkg_t *pkg = pkg_vec->pkgs[j];
  11736. + pkg_vec_insert(all, pkg);
  11737. + }
  11738. + }
  11739. +}
  11740. +
  11741. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11742. +{
  11743. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11744. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11745. +}
  11746. +
  11747. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11748. +{
  11749. + const char *name;
  11750. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11751. + pkg_vec_t *all = (pkg_vec_t *)data;
  11752. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11753. + int j;
  11754. + name = pkg_name;
  11755. + if (pkg_vec) {
  11756. + for (j = 0; j < pkg_vec->len; j++) {
  11757. + pkg_t *pkg = pkg_vec->pkgs[j];
  11758. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11759. + pkg_vec_insert(all, pkg);
  11760. + }
  11761. + }
  11762. + }
  11763. +}
  11764. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11765. +{
  11766. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11767. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11768. +}
  11769. +
  11770. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11771. +{
  11772. + int i;
  11773. + pkg_t *pkg;
  11774. + const char *name;
  11775. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11776. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11777. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11778. + name = pkg_name;
  11779. + fprintf(stdout, "%s\n", ab_pkg->name);
  11780. + i = 0;
  11781. + if (dependents != NULL)
  11782. + while (dependents [i] != NULL)
  11783. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11784. + dependents = ab_pkg->provided_by->pkgs;
  11785. + i = 0;
  11786. + if (dependents != NULL)
  11787. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11788. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11789. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11790. + if (pkg) {
  11791. + i = 0;
  11792. + while (i < pkg->depends_count)
  11793. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11794. + }
  11795. +}
  11796. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11797. +{
  11798. +
  11799. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11800. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11801. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11802. +}
  11803. +
  11804. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11805. +{
  11806. + abstract_pkg_t * ab_pkg;
  11807. +
  11808. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11809. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11810. +
  11811. + return ab_pkg;
  11812. +}
  11813. +
  11814. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11815. +{
  11816. + abstract_pkg_t * ab_pkg;
  11817. + int arch_priority;
  11818. +
  11819. + if(!pkg)
  11820. + return pkg;
  11821. +
  11822. + arch_priority = pkg->arch_priority;
  11823. +
  11824. + if (buildDepends(hash, pkg)<0){
  11825. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11826. + return NULL;
  11827. + }
  11828. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11829. +
  11830. + if (set_status) {
  11831. + if (pkg->state_status == SS_INSTALLED) {
  11832. + ab_pkg->state_status = SS_INSTALLED;
  11833. + } else if (pkg->state_status == SS_UNPACKED) {
  11834. + ab_pkg->state_status = SS_UNPACKED;
  11835. + }
  11836. + }
  11837. +
  11838. + if(!ab_pkg->pkgs)
  11839. + ab_pkg->pkgs = pkg_vec_alloc();
  11840. +
  11841. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11842. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11843. + pkg->parent = ab_pkg;
  11844. +
  11845. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11846. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11847. + return NULL;
  11848. + }
  11849. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11850. + if (buildConflicts(hash, pkg)<0){
  11851. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11852. + return NULL;
  11853. + }
  11854. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11855. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11856. + return NULL;
  11857. + }
  11858. +
  11859. + buildDependedUponBy(pkg, ab_pkg);
  11860. + return pkg;
  11861. +}
  11862. +
  11863. +/*
  11864. + * this will assume that we've already determined that
  11865. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11866. + */
  11867. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11868. +{
  11869. + abstract_pkg_t * ab_pkg;
  11870. +
  11871. + ab_pkg = abstract_pkg_new();
  11872. + if (ab_pkg == NULL) { return NULL; }
  11873. +
  11874. + ab_pkg->name = strdup(pkg_name);
  11875. + hash_table_insert(hash, pkg_name, ab_pkg);
  11876. +
  11877. + return ab_pkg;
  11878. +}
  11879. +
  11880. +
  11881. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11882. +{
  11883. + hash_table_t *file_hash = &conf->file_hash;
  11884. +
  11885. + return hash_table_get(file_hash, file_name);
  11886. +}
  11887. +
  11888. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11889. +{
  11890. + hash_table_t *file_hash = &conf->file_hash;
  11891. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11892. + int file_name_len = strlen(file_name);
  11893. +
  11894. + if (file_name[file_name_len -1] == '/')
  11895. + return 0;
  11896. +
  11897. + if (conf->offline_root) {
  11898. + int len = strlen(conf->offline_root);
  11899. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11900. + file_name += len;
  11901. + }
  11902. + }
  11903. +
  11904. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11905. + hash_table_insert(file_hash, file_name, owning_pkg);
  11906. + if (old_owning_pkg) {
  11907. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11908. + /* mark this package to have its filelist written */
  11909. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11910. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11911. + }
  11912. + return 0;
  11913. +}
  11914. +
  11915. +
  11916. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_hash.h busybox-1.23.0/archival/libipkg/pkg_hash.h
  11917. --- busybox-1.23.0.orig/archival/libipkg/pkg_hash.h 1969-12-31 18:00:00.000000000 -0600
  11918. +++ busybox-1.23.0/archival/libipkg/pkg_hash.h 2015-01-09 11:18:22.440197244 -0600
  11919. @@ -0,0 +1,61 @@
  11920. +/* pkg_hash.h - the itsy package management system
  11921. +
  11922. + Steven M. Ayer
  11923. +
  11924. + Copyright (C) 2002 Compaq Computer Corporation
  11925. +
  11926. + This program is free software; you can redistribute it and/or
  11927. + modify it under the terms of the GNU General Public License as
  11928. + published by the Free Software Foundation; either version 2, or (at
  11929. + your option) any later version.
  11930. +
  11931. + This program is distributed in the hope that it will be useful, but
  11932. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11933. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11934. + General Public License for more details.
  11935. +*/
  11936. +
  11937. +#ifndef PKG_HASH_H
  11938. +#define PKG_HASH_H
  11939. +
  11940. +#include "pkg.h"
  11941. +#include "pkg_vec.h"
  11942. +#include "hash_table.h"
  11943. +
  11944. +
  11945. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11946. +void pkg_hash_deinit(hash_table_t *hash);
  11947. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11948. +
  11949. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11950. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11951. +
  11952. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11953. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11954. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11955. +
  11956. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11957. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11958. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11959. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11960. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11961. + const char *pkg_name,
  11962. + const char * version);
  11963. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11964. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11965. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11966. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11967. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11968. + const char *pkg_name);
  11969. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11970. + const char *pkg_name,
  11971. + pkg_dest_t *dest);
  11972. +
  11973. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11974. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11975. +
  11976. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11977. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11978. +
  11979. +#endif
  11980. +
  11981. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_parse.c busybox-1.23.0/archival/libipkg/pkg_parse.c
  11982. --- busybox-1.23.0.orig/archival/libipkg/pkg_parse.c 1969-12-31 18:00:00.000000000 -0600
  11983. +++ busybox-1.23.0/archival/libipkg/pkg_parse.c 2015-01-09 11:18:22.440197244 -0600
  11984. @@ -0,0 +1,368 @@
  11985. +/* pkg_parse.c - the itsy package management system
  11986. +
  11987. + Steven M. Ayer
  11988. +
  11989. + Copyright (C) 2002 Compaq Computer Corporation
  11990. +
  11991. + This program is free software; you can redistribute it and/or
  11992. + modify it under the terms of the GNU General Public License as
  11993. + published by the Free Software Foundation; either version 2, or (at
  11994. + your option) any later version.
  11995. +
  11996. + This program is distributed in the hope that it will be useful, but
  11997. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11998. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11999. + General Public License for more details.
  12000. +*/
  12001. +
  12002. +#include "ipkg.h"
  12003. +#include <errno.h>
  12004. +#include <ctype.h>
  12005. +
  12006. +#include "pkg.h"
  12007. +#include "ipkg_utils.h"
  12008. +#include "pkg_parse.h"
  12009. +
  12010. +int alterProvidesLine(char *raw, char *temp);
  12011. +
  12012. +int isGenericFieldType(char * type, char * line)
  12013. +{
  12014. + if(!strncmp(line, type, strlen(type)))
  12015. + return 1;
  12016. + return 0;
  12017. +}
  12018. +
  12019. +char * parseGenericFieldType(char * type, char * raw)
  12020. +{
  12021. + char * field_value = raw + (strlen(type) + 1);
  12022. + return trim_alloc(field_value);
  12023. +}
  12024. +
  12025. +void parseStatus(pkg_t *pkg, char * raw)
  12026. +{
  12027. + char sw_str[64], sf_str[64], ss_str[64];
  12028. +
  12029. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12030. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12031. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12032. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12033. +}
  12034. +
  12035. +char ** parseDependsString(char * raw, int * depends_count)
  12036. +{
  12037. + char ** depends = NULL;
  12038. + int line_count = 0;
  12039. + char buff[2048], * dest;
  12040. +
  12041. + while(raw && *raw && !isspace(*raw)) {
  12042. + raw++;
  12043. + }
  12044. +
  12045. + if(line_is_blank(raw)){
  12046. + *depends_count = line_count;
  12047. + return NULL;
  12048. + }
  12049. + while(raw && *raw){
  12050. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12051. +
  12052. + while(isspace(*raw)) raw++;
  12053. +
  12054. + dest = buff;
  12055. + while((*raw != ',') && *raw)
  12056. + *dest++ = *raw++;
  12057. +
  12058. + *dest = '\0';
  12059. + depends[line_count] = trim_alloc(buff);
  12060. + if(depends[line_count] ==NULL)
  12061. + return NULL;
  12062. + line_count++;
  12063. + if(*raw == ',')
  12064. + raw++;
  12065. + }
  12066. + *depends_count = line_count;
  12067. + return depends;
  12068. +}
  12069. +
  12070. +void parseConffiles(pkg_t * pkg, char * raw)
  12071. +{
  12072. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12073. +
  12074. + if(!strncmp(raw, "Conffiles:", 10))
  12075. + raw += strlen("Conffiles:");
  12076. +
  12077. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12078. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12079. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12080. + while (*raw && isspace(*raw)) {
  12081. + raw++;
  12082. + }
  12083. + raw += strlen(file_name);
  12084. + while (*raw && isspace(*raw)) {
  12085. + raw++;
  12086. + }
  12087. + raw += strlen(md5sum);
  12088. + }
  12089. +}
  12090. +
  12091. +int parseVersion(pkg_t *pkg, char *raw)
  12092. +{
  12093. + char *colon, *eepochcolon;
  12094. +#ifdef USE_DEBVERSION
  12095. + char *hyphen;
  12096. +#endif
  12097. + unsigned long epoch;
  12098. +
  12099. + if (!*raw) {
  12100. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12101. + return EINVAL;
  12102. + }
  12103. +
  12104. + if (strncmp(raw, "Version:", 8) == 0) {
  12105. + raw += 8;
  12106. + }
  12107. + while (*raw && isspace(*raw)) {
  12108. + raw++;
  12109. + }
  12110. +
  12111. + colon= strchr(raw,':');
  12112. + if (colon) {
  12113. + epoch= strtoul(raw,&eepochcolon,10);
  12114. + if (colon != eepochcolon) {
  12115. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12116. + return EINVAL;
  12117. + }
  12118. + if (!*++colon) {
  12119. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12120. + return EINVAL;
  12121. + }
  12122. + raw= colon;
  12123. + pkg->epoch= epoch;
  12124. + } else {
  12125. + pkg->epoch= 0;
  12126. + }
  12127. +
  12128. + pkg->revision = (char *)"";
  12129. + pkg->familiar_revision = (char *)"";
  12130. +
  12131. + pkg->version= malloc(strlen(raw)+1);
  12132. + if ( pkg->version == NULL ) {
  12133. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12134. + return ENOMEM;
  12135. + }
  12136. + strcpy(pkg->version, raw);
  12137. +
  12138. +#ifdef USE_DEBVERSION
  12139. + hyphen= strrchr(pkg->version,'-');
  12140. +
  12141. + if (hyphen) {
  12142. + *hyphen++= 0;
  12143. + if (strncmp("fam", hyphen, 3) == 0) {
  12144. + pkg->familiar_revision=hyphen+3;
  12145. + hyphen= strrchr(pkg->version,'-');
  12146. + if (hyphen) {
  12147. + *hyphen++= 0;
  12148. + pkg->revision = hyphen;
  12149. + }
  12150. + } else {
  12151. + pkg->revision = hyphen;
  12152. + }
  12153. + }
  12154. +#endif
  12155. +
  12156. +/*
  12157. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12158. + pkg->epoch,
  12159. + pkg->version,
  12160. + pkg->revision,
  12161. + pkg->familiar_revision);
  12162. +*/
  12163. +
  12164. + return 0;
  12165. +}
  12166. +
  12167. +
  12168. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12169. +
  12170. +int alterProvidesLine(char *raw, char *temp)
  12171. +{
  12172. +
  12173. +
  12174. + if (!*raw) {
  12175. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12176. + return -EINVAL;
  12177. + }
  12178. +
  12179. + if ( temp == NULL ) {
  12180. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12181. + return -ENOMEM;
  12182. + }
  12183. +
  12184. + if (strncmp(raw, "Provides:", 9) == 0) {
  12185. + raw += 9;
  12186. + }
  12187. + while (*raw && isspace(*raw)) {
  12188. + raw++;
  12189. + }
  12190. +
  12191. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12192. + while (*raw) {
  12193. + strncat( temp, raw++, 1);
  12194. + }
  12195. + return 0;
  12196. +
  12197. +}
  12198. +
  12199. +/* Some random thoughts from Carl:
  12200. +
  12201. + This function could be considerably simplified if we just kept
  12202. + an array of all the generic string-valued field names, and looped
  12203. + through those looking for a match. Also, these fields could perhaps
  12204. + be stored in the package as an array as well, (or, probably better,
  12205. + as an nv_pair_list_t).
  12206. +
  12207. + Fields which require special parsing or storage, (such as Depends:
  12208. + and Status:) could be handled as they are now.
  12209. +*/
  12210. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12211. + to a dependency list. And, since we already have
  12212. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12213. + Enhances, perhaps we could generalize all of these and save some
  12214. + code duplication.
  12215. +*/
  12216. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12217. +{
  12218. + int reading_conffiles, reading_description;
  12219. + int pkg_false_provides=1;
  12220. + char ** lines;
  12221. + char * provide=NULL;
  12222. +
  12223. + pkg->src = src;
  12224. + pkg->dest = dest;
  12225. +
  12226. + reading_conffiles = reading_description = 0;
  12227. +
  12228. + for (lines = *raw; *lines; lines++) {
  12229. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12230. + if(isGenericFieldType((char *)"Package:", *lines))
  12231. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12232. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12233. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12234. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12235. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12236. + else if(isGenericFieldType((char *)"Section:", *lines))
  12237. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12238. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12239. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12240. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12241. + let's parse it either way */
  12242. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12243. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12244. + else if(isGenericFieldType((char *)"Size:", *lines))
  12245. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12246. + else if(isGenericFieldType((char *)"Source:", *lines))
  12247. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12248. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12249. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12250. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12251. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12252. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12253. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12254. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12255. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12256. + char *essential_value;
  12257. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12258. + if (strcmp(essential_value, "yes") == 0) {
  12259. + pkg->essential = 1;
  12260. + }
  12261. + free(essential_value);
  12262. + }
  12263. + else if(isGenericFieldType((char *)"Status", *lines))
  12264. + parseStatus(pkg, *lines);
  12265. + else if(isGenericFieldType((char *)"Version", *lines))
  12266. + parseVersion(pkg, *lines);
  12267. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12268. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12269. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12270. + parseConffiles(pkg, *lines);
  12271. + reading_conffiles = 1;
  12272. + }
  12273. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12274. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12275. + reading_conffiles = 0;
  12276. + reading_description = 1;
  12277. + }
  12278. +
  12279. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12280. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12281. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12282. + if ( alterProvidesLine(*lines,provide) ){
  12283. + return EINVAL;
  12284. + }
  12285. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12286. +/* Let's try to hack a bit here.
  12287. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12288. + in alot of other places. We will remove it before writing down the status database */
  12289. + pkg_false_provides=0;
  12290. + free(provide);
  12291. + }
  12292. +
  12293. + else if(isGenericFieldType((char *)"Depends", *lines))
  12294. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12295. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12296. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12297. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12298. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12299. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12300. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12301. + /* Abhaya: support for conflicts */
  12302. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12303. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12304. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12305. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12306. + else if(line_is_blank(*lines)) {
  12307. + lines++;
  12308. + break;
  12309. + }
  12310. + else if(**lines == ' '){
  12311. + if(reading_description) {
  12312. + /* we already know it's not blank, so the rest of description */
  12313. + pkg->description = realloc(pkg->description,
  12314. + strlen(pkg->description)
  12315. + + 1 + strlen(*lines) + 1);
  12316. + strcat(pkg->description, "\n");
  12317. + strcat(pkg->description, (*lines));
  12318. + }
  12319. + else if(reading_conffiles)
  12320. + parseConffiles(pkg, *lines);
  12321. + }
  12322. + }
  12323. + *raw = lines;
  12324. +/* If the ipk has not a Provides line, we insert our false line */
  12325. + if ( pkg_false_provides==1)
  12326. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12327. +
  12328. + if (pkg->name) {
  12329. + return 0;
  12330. + } else {
  12331. + return EINVAL;
  12332. + }
  12333. +}
  12334. +
  12335. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12336. +{
  12337. + char ** lines;
  12338. +
  12339. + for (lines = *raw; *lines; lines++) {
  12340. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12341. + char *essential_value;
  12342. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12343. + if (strcmp(essential_value, "yes") == 0) {
  12344. + pkg->essential = 1;
  12345. + }
  12346. + free(essential_value);
  12347. + }
  12348. + }
  12349. + *raw = lines;
  12350. +
  12351. + return 0;
  12352. +}
  12353. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_parse.h busybox-1.23.0/archival/libipkg/pkg_parse.h
  12354. --- busybox-1.23.0.orig/archival/libipkg/pkg_parse.h 1969-12-31 18:00:00.000000000 -0600
  12355. +++ busybox-1.23.0/archival/libipkg/pkg_parse.h 2015-01-09 11:18:22.440197244 -0600
  12356. @@ -0,0 +1,31 @@
  12357. +/* pkg_parse.h - the itsy package management system
  12358. +
  12359. + Steven M. Ayer
  12360. +
  12361. + Copyright (C) 2002 Compaq Computer Corporation
  12362. +
  12363. + This program is free software; you can redistribute it and/or
  12364. + modify it under the terms of the GNU General Public License as
  12365. + published by the Free Software Foundation; either version 2, or (at
  12366. + your option) any later version.
  12367. +
  12368. + This program is distributed in the hope that it will be useful, but
  12369. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12370. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12371. + General Public License for more details.
  12372. +*/
  12373. +
  12374. +#ifndef PKG_PARSE_H
  12375. +#define PKG_PARSE_H
  12376. +
  12377. +int isGenericFieldType(char * type, char * line);
  12378. +char * parseGenericFieldType(char * type, char * raw);
  12379. +void parseStatus(pkg_t *pkg, char * raw);
  12380. +int parseVersion(pkg_t *pkg, char *raw);
  12381. +char ** parseDependsString(char * raw, int * depends_count);
  12382. +int parseVersion(pkg_t *pkg, char *raw);
  12383. +void parseConffiles(pkg_t * pkg, char * raw);
  12384. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12385. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12386. +
  12387. +#endif
  12388. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_src.c busybox-1.23.0/archival/libipkg/pkg_src.c
  12389. --- busybox-1.23.0.orig/archival/libipkg/pkg_src.c 1969-12-31 18:00:00.000000000 -0600
  12390. +++ busybox-1.23.0/archival/libipkg/pkg_src.c 2015-01-09 11:18:22.440197244 -0600
  12391. @@ -0,0 +1,43 @@
  12392. +/* pkg_src.c - the itsy package management system
  12393. +
  12394. + Carl D. Worth
  12395. +
  12396. + Copyright (C) 2001 University of Southern California
  12397. +
  12398. + This program is free software; you can redistribute it and/or
  12399. + modify it under the terms of the GNU General Public License as
  12400. + published by the Free Software Foundation; either version 2, or (at
  12401. + your option) any later version.
  12402. +
  12403. + This program is distributed in the hope that it will be useful, but
  12404. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12405. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12406. + General Public License for more details.
  12407. +*/
  12408. +
  12409. +#include "ipkg.h"
  12410. +
  12411. +#include "pkg_src.h"
  12412. +#include "str_util.h"
  12413. +
  12414. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12415. +{
  12416. + src->gzip = gzip;
  12417. + src->name = str_dup_safe (name);
  12418. + src->value = str_dup_safe (base_url);
  12419. + if (extra_data)
  12420. + src->extra_data = str_dup_safe (extra_data);
  12421. + else
  12422. + src->extra_data = NULL;
  12423. + return 0;
  12424. +}
  12425. +
  12426. +void pkg_src_deinit(pkg_src_t *src)
  12427. +{
  12428. + free (src->name);
  12429. + free (src->value);
  12430. + if (src->extra_data)
  12431. + free (src->extra_data);
  12432. +}
  12433. +
  12434. +
  12435. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_src.h busybox-1.23.0/archival/libipkg/pkg_src.h
  12436. --- busybox-1.23.0.orig/archival/libipkg/pkg_src.h 1969-12-31 18:00:00.000000000 -0600
  12437. +++ busybox-1.23.0/archival/libipkg/pkg_src.h 2015-01-09 11:18:22.440197244 -0600
  12438. @@ -0,0 +1,34 @@
  12439. +/* pkg_src.h - the itsy package management system
  12440. +
  12441. + Carl D. Worth
  12442. +
  12443. + Copyright (C) 2001 University of Southern California
  12444. +
  12445. + This program is free software; you can redistribute it and/or
  12446. + modify it under the terms of the GNU General Public License as
  12447. + published by the Free Software Foundation; either version 2, or (at
  12448. + your option) any later version.
  12449. +
  12450. + This program is distributed in the hope that it will be useful, but
  12451. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12452. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12453. + General Public License for more details.
  12454. +*/
  12455. +
  12456. +#ifndef PKG_SRC_H
  12457. +#define PKG_SRC_H
  12458. +
  12459. +#include "nv_pair.h"
  12460. +
  12461. +typedef struct
  12462. +{
  12463. + char *name;
  12464. + char *value;
  12465. + char *extra_data;
  12466. + int gzip;
  12467. +} pkg_src_t;
  12468. +
  12469. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12470. +void pkg_src_deinit(pkg_src_t *src);
  12471. +
  12472. +#endif
  12473. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_src_list.c busybox-1.23.0/archival/libipkg/pkg_src_list.c
  12474. --- busybox-1.23.0.orig/archival/libipkg/pkg_src_list.c 1969-12-31 18:00:00.000000000 -0600
  12475. +++ busybox-1.23.0/archival/libipkg/pkg_src_list.c 2015-01-09 11:18:22.440197244 -0600
  12476. @@ -0,0 +1,75 @@
  12477. +/* pkg_src_list.c - the itsy package management system
  12478. +
  12479. + Carl D. Worth
  12480. +
  12481. + Copyright (C) 2001 University of Southern California
  12482. +
  12483. + This program is free software; you can redistribute it and/or
  12484. + modify it under the terms of the GNU General Public License as
  12485. + published by the Free Software Foundation; either version 2, or (at
  12486. + your option) any later version.
  12487. +
  12488. + This program is distributed in the hope that it will be useful, but
  12489. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12490. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12491. + General Public License for more details.
  12492. +*/
  12493. +
  12494. +#include "ipkg.h"
  12495. +
  12496. +#include "pkg_src_list.h"
  12497. +#include "void_list.h"
  12498. +
  12499. +int pkg_src_list_init(pkg_src_list_t *list)
  12500. +{
  12501. + return void_list_init((void_list_t *) list);
  12502. +}
  12503. +
  12504. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12505. +{
  12506. + pkg_src_list_elt_t *iter;
  12507. + pkg_src_t *pkg_src;
  12508. +
  12509. + for (iter = list->head; iter; iter = iter->next) {
  12510. + pkg_src = iter->data;
  12511. + pkg_src_deinit(pkg_src);
  12512. +
  12513. + /* malloced in pkg_src_list_append */
  12514. + free(pkg_src);
  12515. + iter->data = NULL;
  12516. + }
  12517. + void_list_deinit((void_list_t *) list);
  12518. +}
  12519. +
  12520. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12521. + const char *name, const char *base_url, const char *extra_data,
  12522. + int gzip)
  12523. +{
  12524. + int err;
  12525. +
  12526. + /* freed in pkg_src_list_deinit */
  12527. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12528. +
  12529. + if (pkg_src == NULL) {
  12530. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12531. + return NULL;
  12532. + }
  12533. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12534. +
  12535. + err = void_list_append((void_list_t *) list, pkg_src);
  12536. + if (err) {
  12537. + return NULL;
  12538. + }
  12539. +
  12540. + return pkg_src;
  12541. +}
  12542. +
  12543. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12544. +{
  12545. + return void_list_push((void_list_t *) list, data);
  12546. +}
  12547. +
  12548. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12549. +{
  12550. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12551. +}
  12552. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_src_list.h busybox-1.23.0/archival/libipkg/pkg_src_list.h
  12553. --- busybox-1.23.0.orig/archival/libipkg/pkg_src_list.h 1969-12-31 18:00:00.000000000 -0600
  12554. +++ busybox-1.23.0/archival/libipkg/pkg_src_list.h 2015-01-09 11:18:22.440197244 -0600
  12555. @@ -0,0 +1,57 @@
  12556. +/* pkg_src_list.h - the itsy package management system
  12557. +
  12558. + Carl D. Worth
  12559. +
  12560. + Copyright (C) 2001 University of Southern California
  12561. +
  12562. + This program is free software; you can redistribute it and/or
  12563. + modify it under the terms of the GNU General Public License as
  12564. + published by the Free Software Foundation; either version 2, or (at
  12565. + your option) any later version.
  12566. +
  12567. + This program is distributed in the hope that it will be useful, but
  12568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12570. + General Public License for more details.
  12571. +*/
  12572. +
  12573. +#ifndef PKG_SRC_LIST_H
  12574. +#define PKG_SRC_LIST_H
  12575. +
  12576. +#include "pkg_src.h"
  12577. +
  12578. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12579. +struct pkg_src_list_elt
  12580. +{
  12581. + pkg_src_list_elt_t *next;
  12582. + pkg_src_t *data;
  12583. +};
  12584. +
  12585. +typedef struct pkg_src_list pkg_src_list_t;
  12586. +struct pkg_src_list
  12587. +{
  12588. + pkg_src_list_elt_t pre_head;
  12589. + pkg_src_list_elt_t *head;
  12590. + pkg_src_list_elt_t *tail;
  12591. +};
  12592. +
  12593. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12594. +{
  12595. + if (list->head == NULL)
  12596. + return 1;
  12597. + else
  12598. + return 0;
  12599. +}
  12600. +
  12601. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12602. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12603. +
  12604. +int pkg_src_list_init(pkg_src_list_t *list);
  12605. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12606. +
  12607. +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);
  12608. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12609. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12610. +
  12611. +#endif
  12612. +
  12613. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_vec.c busybox-1.23.0/archival/libipkg/pkg_vec.c
  12614. --- busybox-1.23.0.orig/archival/libipkg/pkg_vec.c 1969-12-31 18:00:00.000000000 -0600
  12615. +++ busybox-1.23.0/archival/libipkg/pkg_vec.c 2015-01-09 11:18:22.440197244 -0600
  12616. @@ -0,0 +1,231 @@
  12617. +/* pkg_vec.c - the itsy package management system
  12618. +
  12619. + Steven M. Ayer
  12620. +
  12621. + Copyright (C) 2002 Compaq Computer Corporation
  12622. +
  12623. + This program is free software; you can redistribute it and/or
  12624. + modify it under the terms of the GNU General Public License as
  12625. + published by the Free Software Foundation; either version 2, or (at
  12626. + your option) any later version.
  12627. +
  12628. + This program is distributed in the hope that it will be useful, but
  12629. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12630. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12631. + General Public License for more details.
  12632. +*/
  12633. +
  12634. +#include <stdlib.h>
  12635. +#include <fnmatch.h>
  12636. +#include "libbb.h"
  12637. +#include "xregex.h"
  12638. +#include "ipkg.h"
  12639. +#include "pkg.h"
  12640. +
  12641. +pkg_vec_t * pkg_vec_alloc(void)
  12642. +{
  12643. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12644. + if (!vec) {
  12645. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12646. + return NULL;
  12647. + }
  12648. + vec->pkgs = NULL;
  12649. + vec->len = 0;
  12650. +
  12651. + return vec;
  12652. +}
  12653. +
  12654. +void pkg_vec_free(pkg_vec_t *vec)
  12655. +{
  12656. + free(vec->pkgs);
  12657. + free(vec);
  12658. +}
  12659. +
  12660. +/*
  12661. + * assumption: all names in a vector are identical
  12662. + * assumption: all version strings are trimmed,
  12663. + * so identical versions have identical version strings,
  12664. + * implying identical packages; let's marry these
  12665. + */
  12666. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12667. +{
  12668. + int i;
  12669. + int found = 0;
  12670. +
  12671. + /* look for a duplicate pkg by name, version, and architecture */
  12672. + for (i = 0; i < vec->len; i++){
  12673. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12674. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12675. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12676. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12677. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12678. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12679. + found = 1;
  12680. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12681. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12682. + break;
  12683. + }
  12684. + }
  12685. +
  12686. + /* we didn't find one, add it */
  12687. + if (!found){
  12688. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12689. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12690. +
  12691. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12692. + vec->pkgs[vec->len] = pkg;
  12693. + vec->len++;
  12694. + return pkg;
  12695. + }
  12696. + /* update the one that we have */
  12697. + else {
  12698. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12699. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12700. + if (set_status) {
  12701. + /* this is from the status file, so need to merge with existing database */
  12702. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12703. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12704. + /* XXX: CLEANUP: It's not so polite to free something here
  12705. + that was passed in from above. */
  12706. + pkg_deinit(pkg);
  12707. + free(pkg);
  12708. + } else {
  12709. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12710. + /* just overwrite the old one */
  12711. + pkg_deinit(vec->pkgs[i]);
  12712. + free(vec->pkgs[i]);
  12713. + vec->pkgs[i] = pkg;
  12714. + }
  12715. + return vec->pkgs[i];
  12716. + }
  12717. +}
  12718. +
  12719. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12720. +{
  12721. + int i;
  12722. + int found = 0;
  12723. +
  12724. + /* look for a duplicate pkg by name, version, and architecture */
  12725. + for (i = 0; i < vec->len; i++)
  12726. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12727. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12728. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12729. + found = 1;
  12730. + break;
  12731. + }
  12732. +
  12733. + /* we didn't find one, add it */
  12734. + if(!found){
  12735. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12736. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12737. + vec->len++;
  12738. + }
  12739. +}
  12740. +
  12741. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12742. +{
  12743. + int i;
  12744. + for (i = 0; i < vec->len; i++)
  12745. + if (vec->pkgs[i] == apkg)
  12746. + return 1;
  12747. + return 0;
  12748. +}
  12749. +
  12750. +typedef int (*compare_fcn_t)(const void *, const void *);
  12751. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12752. +{
  12753. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12754. +}
  12755. +
  12756. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12757. +{
  12758. + int npkgs = vec->len;
  12759. + int i;
  12760. + for (i = 0; i < npkgs; i++) {
  12761. + pkg_t *pkg = vec->pkgs[i];
  12762. + pkg->state_flag &= ~SF_MARKED;
  12763. + }
  12764. + return 0;
  12765. +}
  12766. +
  12767. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12768. +{
  12769. + int matching_count = 0;
  12770. + pkg_t **pkgs = vec->pkgs;
  12771. + int npkgs = vec->len;
  12772. + int i;
  12773. + for (i = 0; i < npkgs; i++) {
  12774. + pkg_t *pkg = pkgs[i];
  12775. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12776. + pkg->state_flag |= SF_MARKED;
  12777. + matching_count++;
  12778. + }
  12779. + }
  12780. + return matching_count;
  12781. +}
  12782. +
  12783. +
  12784. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12785. +{
  12786. + abstract_pkg_vec_t * vec ;
  12787. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12788. + if (!vec) {
  12789. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12790. + return NULL;
  12791. + }
  12792. + vec->pkgs = NULL;
  12793. + vec->len = 0;
  12794. +
  12795. + return vec;
  12796. +}
  12797. +
  12798. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12799. +{
  12800. + free(vec->pkgs);
  12801. + free(vec);
  12802. +}
  12803. +
  12804. +/*
  12805. + * assumption: all names in a vector are unique
  12806. + */
  12807. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12808. +{
  12809. + int i;
  12810. +
  12811. + /* look for a duplicate pkg by name */
  12812. + for(i = 0; i < vec->len; i++)
  12813. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12814. + break;
  12815. +
  12816. + /* we didn't find one, add it */
  12817. + if(i == vec->len){
  12818. + vec->pkgs =
  12819. + (abstract_pkg_t **)
  12820. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12821. + vec->pkgs[vec->len] = pkg;
  12822. + vec->len++;
  12823. + }
  12824. +}
  12825. +
  12826. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12827. +{
  12828. + if (vec->len > i)
  12829. + return vec->pkgs[i];
  12830. + else
  12831. + return NULL;
  12832. +}
  12833. +
  12834. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12835. +{
  12836. + int i;
  12837. + for (i = 0; i < vec->len; i++)
  12838. + if (vec->pkgs[i] == apkg)
  12839. + return 1;
  12840. + return 0;
  12841. +}
  12842. +
  12843. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12844. +{
  12845. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12846. +}
  12847. +
  12848. diff -Nur busybox-1.23.0.orig/archival/libipkg/pkg_vec.h busybox-1.23.0/archival/libipkg/pkg_vec.h
  12849. --- busybox-1.23.0.orig/archival/libipkg/pkg_vec.h 1969-12-31 18:00:00.000000000 -0600
  12850. +++ busybox-1.23.0/archival/libipkg/pkg_vec.h 2015-01-09 11:18:22.440197244 -0600
  12851. @@ -0,0 +1,62 @@
  12852. +/* pkg_vec.h - the itsy package management system
  12853. +
  12854. + Steven M. Ayer
  12855. +
  12856. + Copyright (C) 2002 Compaq Computer Corporation
  12857. +
  12858. + This program is free software; you can redistribute it and/or
  12859. + modify it under the terms of the GNU General Public License as
  12860. + published by the Free Software Foundation; either version 2, or (at
  12861. + your option) any later version.
  12862. +
  12863. + This program is distributed in the hope that it will be useful, but
  12864. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12865. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12866. + General Public License for more details.
  12867. +*/
  12868. +
  12869. +#ifndef PKG_VEC_H
  12870. +#define PKG_VEC_H
  12871. +
  12872. +typedef struct pkg pkg_t;
  12873. +typedef struct abstract_pkg abstract_pkg_t;
  12874. +
  12875. +struct pkg_vec
  12876. +{
  12877. + pkg_t **pkgs;
  12878. + int len;
  12879. +};
  12880. +typedef struct pkg_vec pkg_vec_t;
  12881. +
  12882. +struct abstract_pkg_vec
  12883. +{
  12884. + abstract_pkg_t **pkgs;
  12885. + int len;
  12886. +};
  12887. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12888. +
  12889. +
  12890. +pkg_vec_t * pkg_vec_alloc(void);
  12891. +void pkg_vec_free(pkg_vec_t *vec);
  12892. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12893. +
  12894. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12895. +/* pkg_vec_insert_merge: might munge pkg.
  12896. +* returns the pkg that is in the pkg graph */
  12897. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12898. +/* this one never munges pkg */
  12899. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12900. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12901. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12902. +
  12903. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12904. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12905. +
  12906. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12907. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12908. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12909. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12910. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12911. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12912. +#endif
  12913. +
  12914. diff -Nur busybox-1.23.0.orig/archival/libipkg/sprintf_alloc.h busybox-1.23.0/archival/libipkg/sprintf_alloc.h
  12915. --- busybox-1.23.0.orig/archival/libipkg/sprintf_alloc.h 1969-12-31 18:00:00.000000000 -0600
  12916. +++ busybox-1.23.0/archival/libipkg/sprintf_alloc.h 2015-01-09 11:18:22.440197244 -0600
  12917. @@ -0,0 +1,25 @@
  12918. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12919. +
  12920. + Carl D. Worth
  12921. +
  12922. + Copyright (C) 2001 University of Southern California
  12923. +
  12924. + This program is free software; you can redistribute it and/or modify
  12925. + it under the terms of the GNU General Public License as published by
  12926. + the Free Software Foundation; either version 2, or (at your option)
  12927. + any later version.
  12928. +
  12929. + This program is distributed in the hope that it will be useful,
  12930. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12931. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12932. + GNU General Public License for more details.
  12933. +*/
  12934. +
  12935. +#ifndef SPRINTF_ALLOC_H
  12936. +#define SPRINTF_ALLOC_H
  12937. +
  12938. +#include "libbb.h"
  12939. +
  12940. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12941. +
  12942. +#endif
  12943. diff -Nur busybox-1.23.0.orig/archival/libipkg/str_list.c busybox-1.23.0/archival/libipkg/str_list.c
  12944. --- busybox-1.23.0.orig/archival/libipkg/str_list.c 1969-12-31 18:00:00.000000000 -0600
  12945. +++ busybox-1.23.0/archival/libipkg/str_list.c 2015-01-09 11:18:22.440197244 -0600
  12946. @@ -0,0 +1,76 @@
  12947. +/* str_list.c - the itsy package management system
  12948. +
  12949. + Carl D. Worth
  12950. +
  12951. + Copyright (C) 2001 University of Southern California
  12952. +
  12953. + This program is free software; you can redistribute it and/or
  12954. + modify it under the terms of the GNU General Public License as
  12955. + published by the Free Software Foundation; either version 2, or (at
  12956. + your option) any later version.
  12957. +
  12958. + This program is distributed in the hope that it will be useful, but
  12959. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12960. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12961. + General Public License for more details.
  12962. +*/
  12963. +
  12964. +#include "ipkg.h"
  12965. +
  12966. +#include "str_list.h"
  12967. +
  12968. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12969. +{
  12970. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12971. +}
  12972. +
  12973. +void str_list_elt_deinit(str_list_elt_t *elt)
  12974. +{
  12975. + void_list_elt_deinit((void_list_elt_t *) elt);
  12976. +}
  12977. +
  12978. +str_list_t *str_list_alloc(void)
  12979. +{
  12980. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12981. + if (list)
  12982. + str_list_init(list);
  12983. + return list;
  12984. +}
  12985. +
  12986. +int str_list_init(str_list_t *list)
  12987. +{
  12988. + return void_list_init((void_list_t *) list);
  12989. +}
  12990. +
  12991. +void str_list_deinit(str_list_t *list)
  12992. +{
  12993. + void_list_deinit((void_list_t *) list);
  12994. +}
  12995. +
  12996. +int str_list_append(str_list_t *list, char *data)
  12997. +{
  12998. + return void_list_append((void_list_t *) list, data);
  12999. +}
  13000. +
  13001. +int str_list_push(str_list_t *list, char *data)
  13002. +{
  13003. + return void_list_push((void_list_t *) list, data);
  13004. +}
  13005. +
  13006. +str_list_elt_t *str_list_pop(str_list_t *list)
  13007. +{
  13008. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13009. +}
  13010. +
  13011. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13012. +{
  13013. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13014. + (void_list_elt_t **) iter);
  13015. +}
  13016. +
  13017. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13018. +{
  13019. + return (char *)void_list_remove_elt((void_list_t *) list,
  13020. + (void *)target_str,
  13021. + (void_list_cmp_t)strcmp);
  13022. +}
  13023. diff -Nur busybox-1.23.0.orig/archival/libipkg/str_list.h busybox-1.23.0/archival/libipkg/str_list.h
  13024. --- busybox-1.23.0.orig/archival/libipkg/str_list.h 1969-12-31 18:00:00.000000000 -0600
  13025. +++ busybox-1.23.0/archival/libipkg/str_list.h 2015-01-09 11:18:22.440197244 -0600
  13026. @@ -0,0 +1,51 @@
  13027. +/* str_list.h - the itsy package management system
  13028. +
  13029. + Carl D. Worth
  13030. +
  13031. + Copyright (C) 2001 University of Southern California
  13032. +
  13033. + This program is free software; you can redistribute it and/or
  13034. + modify it under the terms of the GNU General Public License as
  13035. + published by the Free Software Foundation; either version 2, or (at
  13036. + your option) any later version.
  13037. +
  13038. + This program is distributed in the hope that it will be useful, but
  13039. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13040. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13041. + General Public License for more details.
  13042. +*/
  13043. +
  13044. +#ifndef STR_LIST_H
  13045. +#define STR_LIST_H
  13046. +
  13047. +#include "void_list.h"
  13048. +
  13049. +typedef struct str_list_elt str_list_elt_t;
  13050. +struct str_list_elt
  13051. +{
  13052. + str_list_elt_t *next;
  13053. + char *data;
  13054. +};
  13055. +
  13056. +typedef struct xstr_list str_list_t;
  13057. +struct xstr_list
  13058. +{
  13059. + str_list_elt_t pre_head;
  13060. + str_list_elt_t *head;
  13061. + str_list_elt_t *tail;
  13062. +};
  13063. +
  13064. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13065. +void str_list_elt_deinit(str_list_elt_t *elt);
  13066. +
  13067. +str_list_t *str_list_alloc(void);
  13068. +int str_list_init(str_list_t *list);
  13069. +void str_list_deinit(str_list_t *list);
  13070. +
  13071. +int str_list_append(str_list_t *list, char *data);
  13072. +int str_list_push(str_list_t *list, char *data);
  13073. +str_list_elt_t *str_list_pop(str_list_t *list);
  13074. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13075. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13076. +
  13077. +#endif
  13078. diff -Nur busybox-1.23.0.orig/archival/libipkg/str_util.c busybox-1.23.0/archival/libipkg/str_util.c
  13079. --- busybox-1.23.0.orig/archival/libipkg/str_util.c 1969-12-31 18:00:00.000000000 -0600
  13080. +++ busybox-1.23.0/archival/libipkg/str_util.c 2015-01-09 11:18:22.440197244 -0600
  13081. @@ -0,0 +1,69 @@
  13082. +/* str_utils.c - the itsy package management system
  13083. +
  13084. + Carl D. Worth
  13085. +
  13086. + Copyright (C) 2001 University of Southern California
  13087. +
  13088. + This program is free software; you can redistribute it and/or
  13089. + modify it under the terms of the GNU General Public License as
  13090. + published by the Free Software Foundation; either version 2, or (at
  13091. + your option) any later version.
  13092. +
  13093. + This program is distributed in the hope that it will be useful, but
  13094. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13095. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13096. + General Public License for more details.
  13097. +*/
  13098. +
  13099. +#include "ipkg.h"
  13100. +
  13101. +int str_starts_with(const char *str, const char *prefix);
  13102. +int str_ends_with(const char *str, const char *suffix);
  13103. +int str_chomp(char *str);
  13104. +int str_toupper(char *str);
  13105. +char *str_dup_safe(const char *str);
  13106. +
  13107. +int str_starts_with(const char *str, const char *prefix)
  13108. +{
  13109. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13110. +}
  13111. +
  13112. +int str_ends_with(const char *str, const char *suffix)
  13113. +{
  13114. + int suffix_len;
  13115. + int str_len;
  13116. +
  13117. + str_len = strlen(str);
  13118. + suffix_len = strlen(suffix);
  13119. +
  13120. + if (str_len < suffix_len) {
  13121. + return 0;
  13122. + }
  13123. +
  13124. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13125. +}
  13126. +
  13127. +int str_chomp(char *str)
  13128. +{
  13129. + if (str[strlen(str) - 1] == '\n') {
  13130. + str[strlen(str) - 1] = '\0';
  13131. + return 1;
  13132. + }
  13133. + return 0;
  13134. +}
  13135. +
  13136. +int str_toupper(char *str)
  13137. +{
  13138. + while (*str) {
  13139. + *str = toupper(*str);
  13140. + str++;
  13141. + }
  13142. +
  13143. + return 0;
  13144. +}
  13145. +
  13146. +char *str_dup_safe(const char *str)
  13147. +{
  13148. + return str ? strdup(str) : NULL;
  13149. +}
  13150. +
  13151. diff -Nur busybox-1.23.0.orig/archival/libipkg/str_util.h busybox-1.23.0/archival/libipkg/str_util.h
  13152. --- busybox-1.23.0.orig/archival/libipkg/str_util.h 1969-12-31 18:00:00.000000000 -0600
  13153. +++ busybox-1.23.0/archival/libipkg/str_util.h 2015-01-09 11:18:22.440197244 -0600
  13154. @@ -0,0 +1,27 @@
  13155. +/* str_utils.h - the itsy package management system
  13156. +
  13157. + Carl D. Worth
  13158. +
  13159. + Copyright (C) 2001 University of Southern California
  13160. +
  13161. + This program is free software; you can redistribute it and/or
  13162. + modify it under the terms of the GNU General Public License as
  13163. + published by the Free Software Foundation; either version 2, or (at
  13164. + your option) any later version.
  13165. +
  13166. + This program is distributed in the hope that it will be useful, but
  13167. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13168. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13169. + General Public License for more details.
  13170. +*/
  13171. +
  13172. +#ifndef STR_UTILS_H
  13173. +#define STR_UTILS_H
  13174. +
  13175. +int str_starts_with(const char *str, const char *prefix);
  13176. +int str_ends_with(const char *str, const char *suffix);
  13177. +int str_chomp(char *str);
  13178. +int str_toupper(char *str);
  13179. +char *str_dup_safe(const char *str);
  13180. +
  13181. +#endif
  13182. diff -Nur busybox-1.23.0.orig/archival/libipkg/user.c busybox-1.23.0/archival/libipkg/user.c
  13183. --- busybox-1.23.0.orig/archival/libipkg/user.c 1969-12-31 18:00:00.000000000 -0600
  13184. +++ busybox-1.23.0/archival/libipkg/user.c 2015-01-09 11:18:22.440197244 -0600
  13185. @@ -0,0 +1,49 @@
  13186. +/* user.c - the itsy package management system
  13187. +
  13188. + Jamey Hicks
  13189. +
  13190. + Copyright (C) 2002 Hewlett Packard Company
  13191. + Copyright (C) 2001 University of Southern California
  13192. +
  13193. + This program is free software; you can redistribute it and/or
  13194. + modify it under the terms of the GNU General Public License as
  13195. + published by the Free Software Foundation; either version 2, or (at
  13196. + your option) any later version.
  13197. +
  13198. + This program is distributed in the hope that it will be useful, but
  13199. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13200. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13201. + General Public License for more details.
  13202. +*/
  13203. +
  13204. +#include <stdio.h>
  13205. +#include <stdarg.h>
  13206. +#include "libbb.h"
  13207. +#include "file_util.h"
  13208. +#include "str_util.h"
  13209. +#include "libipkg.h"
  13210. +
  13211. +char *get_user_response(const char *format, ...);
  13212. +static char *question = NULL;
  13213. +static int question_len = 255;
  13214. +
  13215. +char *get_user_response(const char *format, ...)
  13216. +{
  13217. + int len = question_len;
  13218. + va_list ap;
  13219. + char *response;
  13220. + va_start(ap, format);
  13221. +
  13222. + do {
  13223. + if (question == NULL || len > question_len) {
  13224. + question = realloc(question, len + 1);
  13225. + question_len = len;
  13226. + }
  13227. + len = vsnprintf(question,question_len,format,ap);
  13228. + } while (len > question_len);
  13229. + response = strdup(ipkg_cb_response(question));
  13230. + str_chomp(response);
  13231. + str_tolower(response);
  13232. +
  13233. + return response;
  13234. +}
  13235. diff -Nur busybox-1.23.0.orig/archival/libipkg/user.h busybox-1.23.0/archival/libipkg/user.h
  13236. --- busybox-1.23.0.orig/archival/libipkg/user.h 1969-12-31 18:00:00.000000000 -0600
  13237. +++ busybox-1.23.0/archival/libipkg/user.h 2015-01-09 11:18:22.440197244 -0600
  13238. @@ -0,0 +1,23 @@
  13239. +/* user.c - the itsy package management system
  13240. +
  13241. + Jamey Hicks
  13242. +
  13243. + Copyright (C) 2002 Hewlett Packard Company
  13244. + Copyright (C) 2001 University of Southern California
  13245. +
  13246. + This program is free software; you can redistribute it and/or
  13247. + modify it under the terms of the GNU General Public License as
  13248. + published by the Free Software Foundation; either version 2, or (at
  13249. + your option) any later version.
  13250. +
  13251. + This program is distributed in the hope that it will be useful, but
  13252. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13253. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13254. + General Public License for more details.
  13255. +*/
  13256. +
  13257. +#include <stdio.h>
  13258. +#include <stdarg.h>
  13259. +
  13260. +char *get_user_response(const char *format, ...);
  13261. +
  13262. diff -Nur busybox-1.23.0.orig/archival/libipkg/void_list.c busybox-1.23.0/archival/libipkg/void_list.c
  13263. --- busybox-1.23.0.orig/archival/libipkg/void_list.c 1969-12-31 18:00:00.000000000 -0600
  13264. +++ busybox-1.23.0/archival/libipkg/void_list.c 2015-01-09 11:18:22.440197244 -0600
  13265. @@ -0,0 +1,194 @@
  13266. +/* void_list.c - the itsy package management system
  13267. +
  13268. + Carl D. Worth
  13269. +
  13270. + Copyright (C) 2001 University of Southern California
  13271. +
  13272. + This program is free software; you can redistribute it and/or
  13273. + modify it under the terms of the GNU General Public License as
  13274. + published by the Free Software Foundation; either version 2, or (at
  13275. + your option) any later version.
  13276. +
  13277. + This program is distributed in the hope that it will be useful, but
  13278. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13279. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13280. + General Public License for more details.
  13281. +*/
  13282. +
  13283. +#include "ipkg.h"
  13284. +#include <errno.h>
  13285. +
  13286. +#include "void_list.h"
  13287. +
  13288. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13289. +{
  13290. + elt->next = NULL;
  13291. + elt->data = data;
  13292. +
  13293. + return 0;
  13294. +}
  13295. +
  13296. +void void_list_elt_deinit(void_list_elt_t *elt)
  13297. +{
  13298. + void_list_elt_init(elt, NULL);
  13299. +}
  13300. +
  13301. +int void_list_init(void_list_t *list)
  13302. +{
  13303. + void_list_elt_init(&list->pre_head, NULL);
  13304. + list->head = NULL;
  13305. + list->pre_head.next = list->head;
  13306. + list->tail = NULL;
  13307. +
  13308. + return 0;
  13309. +}
  13310. +
  13311. +void void_list_deinit(void_list_t *list)
  13312. +{
  13313. + void_list_elt_t *elt;
  13314. +
  13315. + while (list->head) {
  13316. + elt = void_list_pop(list);
  13317. + void_list_elt_deinit(elt);
  13318. + /* malloced in void_list_append */
  13319. + free(elt);
  13320. + }
  13321. +}
  13322. +
  13323. +int void_list_append(void_list_t *list, void *data)
  13324. +{
  13325. + void_list_elt_t *elt;
  13326. +
  13327. + /* freed in void_list_deinit */
  13328. + elt = malloc(sizeof(void_list_elt_t));
  13329. + if (elt == NULL) {
  13330. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13331. + return ENOMEM;
  13332. + }
  13333. +
  13334. + void_list_elt_init(elt, data);
  13335. +
  13336. + if (list->tail) {
  13337. + list->tail->next = elt;
  13338. + list->tail = elt;
  13339. + } else {
  13340. + list->head = elt;
  13341. + list->pre_head.next = list->head;
  13342. + list->tail = elt;
  13343. + }
  13344. +
  13345. + return 0;
  13346. +}
  13347. +
  13348. +int void_list_push(void_list_t *list, void *data)
  13349. +{
  13350. + void_list_elt_t *elt;
  13351. +
  13352. + elt = malloc(sizeof(void_list_elt_t));
  13353. + if (elt == NULL) {
  13354. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13355. + return ENOMEM;
  13356. + }
  13357. +
  13358. + void_list_elt_init(elt, data);
  13359. +
  13360. + elt->next = list->head;
  13361. + list->head->next = elt;
  13362. + if (list->tail == NULL) {
  13363. + list->tail = list->head;
  13364. + }
  13365. +
  13366. + return 0;
  13367. +}
  13368. +
  13369. +void_list_elt_t *void_list_pop(void_list_t *list)
  13370. +{
  13371. + void_list_elt_t *elt;
  13372. +
  13373. + elt = list->head;
  13374. +
  13375. + if (list->head) {
  13376. + list->head = list->head->next;
  13377. + list->pre_head.next = list->head;
  13378. + if (list->head == NULL) {
  13379. + list->tail = NULL;
  13380. + }
  13381. + }
  13382. +
  13383. + return elt;
  13384. +}
  13385. +
  13386. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13387. +{
  13388. + void_list_elt_t *prior;
  13389. + void_list_elt_t *old_elt;
  13390. + void *old_data;
  13391. +
  13392. + old_elt = *iter;
  13393. + old_data = old_elt->data;
  13394. +
  13395. + if (old_elt == list->head) {
  13396. + prior = &list->pre_head;
  13397. + void_list_pop(list);
  13398. + } else {
  13399. + for (prior = list->head; prior; prior = prior->next) {
  13400. + if (prior->next == old_elt) {
  13401. + break;
  13402. + }
  13403. + }
  13404. + if (prior == NULL || prior->next != old_elt) {
  13405. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13406. + return NULL;
  13407. + }
  13408. + prior->next = old_elt->next;
  13409. +
  13410. + if (old_elt == list->tail) {
  13411. + list->tail = prior;
  13412. + }
  13413. + }
  13414. +
  13415. + void_list_elt_deinit(old_elt);
  13416. + *iter = prior;
  13417. +
  13418. + return old_data;
  13419. +}
  13420. +
  13421. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13422. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13423. +{
  13424. + void_list_elt_t *prior;
  13425. + void_list_elt_t *old_elt = NULL;
  13426. + void *old_data = NULL;
  13427. +
  13428. + /* first element */
  13429. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13430. + old_elt = list->head;
  13431. + old_data = list->head->data;
  13432. + void_list_pop(list);
  13433. + } else {
  13434. + int found = 0;
  13435. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13436. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13437. + old_elt = prior->next;
  13438. + old_data = old_elt->data;
  13439. + found = 1;
  13440. + break;
  13441. + }
  13442. + }
  13443. + if (!found) {
  13444. + return NULL;
  13445. + }
  13446. + prior->next = old_elt->next;
  13447. +
  13448. + if (old_elt == list->tail) {
  13449. + list->tail = prior;
  13450. + }
  13451. + }
  13452. + if (old_elt)
  13453. + void_list_elt_deinit(old_elt);
  13454. +
  13455. + if (old_data)
  13456. + return old_data;
  13457. + else
  13458. + return NULL;
  13459. +}
  13460. diff -Nur busybox-1.23.0.orig/archival/libipkg/void_list.h busybox-1.23.0/archival/libipkg/void_list.h
  13461. --- busybox-1.23.0.orig/archival/libipkg/void_list.h 1969-12-31 18:00:00.000000000 -0600
  13462. +++ busybox-1.23.0/archival/libipkg/void_list.h 2015-01-09 11:18:22.440197244 -0600
  13463. @@ -0,0 +1,59 @@
  13464. +/* void_list.h - the itsy package management system
  13465. +
  13466. + Carl D. Worth
  13467. +
  13468. + Copyright (C) 2001 University of Southern California
  13469. +
  13470. + This program is free software; you can redistribute it and/or
  13471. + modify it under the terms of the GNU General Public License as
  13472. + published by the Free Software Foundation; either version 2, or (at
  13473. + your option) any later version.
  13474. +
  13475. + This program is distributed in the hope that it will be useful, but
  13476. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13477. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13478. + General Public License for more details.
  13479. +*/
  13480. +
  13481. +#ifndef VOID_LIST_H
  13482. +#define VOID_LIST_H
  13483. +
  13484. +typedef struct void_list_elt void_list_elt_t;
  13485. +struct void_list_elt
  13486. +{
  13487. + void_list_elt_t *next;
  13488. + void *data;
  13489. +};
  13490. +
  13491. +typedef struct void_list void_list_t;
  13492. +struct void_list
  13493. +{
  13494. + void_list_elt_t pre_head;
  13495. + void_list_elt_t *head;
  13496. + void_list_elt_t *tail;
  13497. +};
  13498. +
  13499. +static inline int void_list_empty(void_list_t *list)
  13500. +{
  13501. + if (list->head == NULL)
  13502. + return 1;
  13503. + else
  13504. + return 0;
  13505. +}
  13506. +
  13507. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13508. +void void_list_elt_deinit(void_list_elt_t *elt);
  13509. +
  13510. +int void_list_init(void_list_t *list);
  13511. +void void_list_deinit(void_list_t *list);
  13512. +
  13513. +int void_list_append(void_list_t *list, void *data);
  13514. +int void_list_push(void_list_t *list, void *data);
  13515. +void_list_elt_t *void_list_pop(void_list_t *list);
  13516. +
  13517. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13518. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13519. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13520. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13521. +
  13522. +#endif
  13523. diff -Nur busybox-1.23.0.orig/archival/libipkg/xsystem.c busybox-1.23.0/archival/libipkg/xsystem.c
  13524. --- busybox-1.23.0.orig/archival/libipkg/xsystem.c 1969-12-31 18:00:00.000000000 -0600
  13525. +++ busybox-1.23.0/archival/libipkg/xsystem.c 2015-01-09 11:18:22.440197244 -0600
  13526. @@ -0,0 +1,64 @@
  13527. +/* xsystem.c - system(3) with error messages
  13528. +
  13529. + Carl D. Worth
  13530. +
  13531. + Copyright (C) 2001 University of Southern California
  13532. +
  13533. + This program is free software; you can redistribute it and/or
  13534. + modify it under the terms of the GNU General Public License as
  13535. + published by the Free Software Foundation; either version 2, or (at
  13536. + your option) any later version.
  13537. +
  13538. + This program is distributed in the hope that it will be useful, but
  13539. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13540. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13541. + General Public License for more details.
  13542. +*/
  13543. +
  13544. +#include "ipkg.h"
  13545. +#include <sys/wait.h>
  13546. +
  13547. +#include "xsystem.h"
  13548. +
  13549. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13550. + really need the /bin/sh invocation which takes resources and
  13551. + introduces security problems. I should switch all of this to a sort
  13552. + of execl() or execv() interface/implementation.
  13553. +*/
  13554. +
  13555. +/* Like system(3), but with error messages printed if the fork fails
  13556. + or if the child process dies due to an uncaught signal. Also, the
  13557. + return value is a bit simpler:
  13558. +
  13559. + -1 if there was any problem
  13560. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13561. + as defined in <sys/wait.h>.
  13562. +*/
  13563. +int xsystem(const char *cmd)
  13564. +{
  13565. + int err;
  13566. +
  13567. + err = system(cmd);
  13568. +
  13569. + if (err == -1) {
  13570. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13571. + __FUNCTION__, cmd);
  13572. + return -1;
  13573. + }
  13574. +
  13575. + if (WIFSIGNALED(err)) {
  13576. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13577. + __FUNCTION__, WTERMSIG(err), cmd);
  13578. + return -1;
  13579. + }
  13580. +
  13581. + if (WIFEXITED(err)) {
  13582. + /* Normal child exit */
  13583. + return WEXITSTATUS(err);
  13584. + }
  13585. +
  13586. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13587. + __FUNCTION__, err);
  13588. + return -1;
  13589. +}
  13590. +
  13591. diff -Nur busybox-1.23.0.orig/archival/libipkg/xsystem.h busybox-1.23.0/archival/libipkg/xsystem.h
  13592. --- busybox-1.23.0.orig/archival/libipkg/xsystem.h 1969-12-31 18:00:00.000000000 -0600
  13593. +++ busybox-1.23.0/archival/libipkg/xsystem.h 2015-01-09 11:18:22.440197244 -0600
  13594. @@ -0,0 +1,34 @@
  13595. +/* xsystem.h - system(3) with error messages
  13596. +
  13597. + Carl D. Worth
  13598. +
  13599. + Copyright (C) 2001 University of Southern California
  13600. +
  13601. + This program is free software; you can redistribute it and/or
  13602. + modify it under the terms of the GNU General Public License as
  13603. + published by the Free Software Foundation; either version 2, or (at
  13604. + your option) any later version.
  13605. +
  13606. + This program is distributed in the hope that it will be useful, but
  13607. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13608. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13609. + General Public License for more details.
  13610. +*/
  13611. +
  13612. +#ifndef XSYSTEM_H
  13613. +#define XSYSTEM_H
  13614. +
  13615. +#include <stdlib.h>
  13616. +
  13617. +/* Like system(3), but with error messages printed if the fork fails
  13618. + or if the child process dies due to an uncaught signal. Also, the
  13619. + return value is a bit simpler:
  13620. +
  13621. + -1 if there was any problem
  13622. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13623. + as defined in <sys/wait.h>.
  13624. +*/
  13625. +int xsystem(const char *cmd);
  13626. +
  13627. +#endif
  13628. +
  13629. diff -Nur busybox-1.23.0.orig/include/applets.src.h busybox-1.23.0/include/applets.src.h
  13630. --- busybox-1.23.0.orig/include/applets.src.h 2014-10-04 15:35:59.000000000 -0500
  13631. +++ busybox-1.23.0/include/applets.src.h 2015-01-09 11:18:22.440197244 -0600
  13632. @@ -193,6 +193,7 @@
  13633. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13634. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13635. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13636. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13637. IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
  13638. IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
  13639. IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
  13640. diff -Nur busybox-1.23.0.orig/include/applets.src.h.orig busybox-1.23.0/include/applets.src.h.orig
  13641. --- busybox-1.23.0.orig/include/applets.src.h.orig 1969-12-31 18:00:00.000000000 -0600
  13642. +++ busybox-1.23.0/include/applets.src.h.orig 2014-10-04 15:35:59.000000000 -0500
  13643. @@ -0,0 +1,400 @@
  13644. +/* vi: set sw=4 ts=4: */
  13645. +/*
  13646. + * applets.h - a listing of all busybox applets.
  13647. + *
  13648. + * If you write a new applet, you need to add an entry to this list to make
  13649. + * busybox aware of it.
  13650. + */
  13651. +
  13652. +/*
  13653. +name - applet name as it is typed on command line
  13654. +help - applet name, converted to C (ether-wake: help = ether_wake)
  13655. +main - corresponding <applet>_main to call (bzcat: main = bunzip2)
  13656. +l - location to install link to: [/usr]/[s]bin
  13657. +s - suid type:
  13658. + BB_SUID_REQUIRE: will complain if busybox isn't suid
  13659. + and is run by non-root (applet_main() will not be called at all)
  13660. + BB_SUID_DROP: will drop suid prior to applet_main()
  13661. + BB_SUID_MAYBE: neither of the above
  13662. + (every instance of BB_SUID_REQUIRE and BB_SUID_MAYBE
  13663. + needs to be justified in comment)
  13664. + NB: please update FEATURE_SUID help text whenever you add/remove
  13665. + BB_SUID_REQUIRE or BB_SUID_MAYBE applet.
  13666. +*/
  13667. +
  13668. +#if defined(PROTOTYPES)
  13669. +# define APPLET(name,l,s) int name##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  13670. +# define APPLET_ODDNAME(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  13671. +# define APPLET_NOEXEC(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  13672. +# define APPLET_NOFORK(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  13673. +
  13674. +#elif defined(NAME_MAIN)
  13675. +# define APPLET(name,l,s) name name##_main
  13676. +# define APPLET_ODDNAME(name,main,l,s,help) name main##_main
  13677. +# define APPLET_NOEXEC(name,main,l,s,help) name main##_main
  13678. +# define APPLET_NOFORK(name,main,l,s,help) name main##_main
  13679. +
  13680. +#elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE
  13681. +# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage name##_full_usage)
  13682. +# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
  13683. +# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
  13684. +# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
  13685. +
  13686. +#elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE
  13687. +# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage)
  13688. +# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
  13689. +# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
  13690. +# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
  13691. +
  13692. +#elif defined(MAKE_LINKS)
  13693. +# define APPLET(name,l,c) LINK l name
  13694. +# define APPLET_ODDNAME(name,main,l,s,help) LINK l name
  13695. +# define APPLET_NOEXEC(name,main,l,s,help) LINK l name
  13696. +# define APPLET_NOFORK(name,main,l,s,help) LINK l name
  13697. +
  13698. +#elif defined(MAKE_SUID)
  13699. +# define APPLET(name,l,s) SUID s l name
  13700. +# define APPLET_ODDNAME(name,main,l,s,help) SUID s l name
  13701. +# define APPLET_NOEXEC(name,main,l,s,help) SUID s l name
  13702. +# define APPLET_NOFORK(name,main,l,s,help) SUID s l name
  13703. +
  13704. +#else
  13705. + static struct bb_applet applets[] = { /* name, main, location, need_suid */
  13706. +# define APPLET(name,l,s) { #name, #name, l, s },
  13707. +# define APPLET_ODDNAME(name,main,l,s,help) { #name, #main, l, s },
  13708. +# define APPLET_NOEXEC(name,main,l,s,help) { #name, #main, l, s, 1 },
  13709. +# define APPLET_NOFORK(name,main,l,s,help) { #name, #main, l, s, 1, 1 },
  13710. +#endif
  13711. +
  13712. +#if ENABLE_INSTALL_NO_USR
  13713. +# define BB_DIR_USR_BIN BB_DIR_BIN
  13714. +# define BB_DIR_USR_SBIN BB_DIR_SBIN
  13715. +#endif
  13716. +
  13717. +
  13718. +INSERT
  13719. +IF_TEST(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
  13720. +IF_TEST(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
  13721. +IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP))
  13722. +IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13723. +IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13724. +IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP))
  13725. +IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP))
  13726. +IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13727. +IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename))
  13728. +IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP))
  13729. +IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP))
  13730. +IF_BLKID(APPLET(blkid, BB_DIR_SBIN, BB_SUID_DROP))
  13731. +IF_BRCTL(APPLET(brctl, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13732. +IF_CAL(APPLET(cal, BB_DIR_USR_BIN, BB_SUID_DROP))
  13733. +IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
  13734. +IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP))
  13735. +IF_CHAT(APPLET(chat, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13736. +IF_CHATTR(APPLET(chattr, BB_DIR_BIN, BB_SUID_DROP))
  13737. +IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP))
  13738. +IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp))
  13739. +IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod))
  13740. +IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown))
  13741. +IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13742. +IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP))
  13743. +IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13744. +IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP))
  13745. +IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP))
  13746. +IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
  13747. +IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
  13748. +IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13749. +IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
  13750. +/* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */
  13751. +IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
  13752. +IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP))
  13753. +IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut))
  13754. +IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP))
  13755. +IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
  13756. +IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP))
  13757. +IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup))
  13758. +IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13759. +IF_DEVFSD(APPLET(devfsd, BB_DIR_SBIN, BB_SUID_DROP))
  13760. +IF_DEVMEM(APPLET(devmem, BB_DIR_SBIN, BB_SUID_DROP))
  13761. +IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
  13762. +IF_DHCPRELAY(APPLET(dhcprelay, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13763. +IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname))
  13764. +IF_DMESG(APPLET(dmesg, BB_DIR_BIN, BB_SUID_DROP))
  13765. +IF_DNSD(APPLET(dnsd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13766. +IF_HOSTNAME(APPLET_ODDNAME(dnsdomainname, hostname, BB_DIR_BIN, BB_SUID_DROP, dnsdomainname))
  13767. +IF_DOS2UNIX(APPLET_NOEXEC(dos2unix, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, dos2unix))
  13768. +IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP))
  13769. +IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP))
  13770. +IF_DUMPLEASES(APPLET(dumpleases, BB_DIR_USR_BIN, BB_SUID_DROP))
  13771. +//IF_E2FSCK(APPLET(e2fsck, BB_DIR_SBIN, BB_SUID_DROP))
  13772. +//IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, e2label))
  13773. +IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo))
  13774. +IF_EJECT(APPLET(eject, BB_DIR_USR_BIN, BB_SUID_DROP))
  13775. +IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
  13776. +IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir))
  13777. +IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid))
  13778. +IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake))
  13779. +IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP))
  13780. +IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
  13781. +IF_FAKEIDENTD(APPLET(fakeidentd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13782. +IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
  13783. +IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13784. +IF_FBSPLASH(APPLET(fbsplash, BB_DIR_SBIN, BB_SUID_DROP))
  13785. +IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, BB_DIR_BIN, BB_SUID_DROP, fdflush))
  13786. +IF_FDFORMAT(APPLET(fdformat, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13787. +IF_FDISK(APPLET(fdisk, BB_DIR_SBIN, BB_SUID_DROP))
  13788. +IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
  13789. +/* Benefits from suid root: better access to /dev/BLOCKDEVs: */
  13790. +IF_FINDFS(APPLET(findfs, BB_DIR_SBIN, BB_SUID_MAYBE))
  13791. +IF_FLASH_ERASEALL(APPLET(flash_eraseall, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13792. +IF_FLASH_LOCK(APPLET_ODDNAME(flash_lock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_lock))
  13793. +IF_FLASH_UNLOCK(APPLET_ODDNAME(flash_unlock, flash_lock_unlock, BB_DIR_USR_SBIN, BB_SUID_DROP, flash_unlock))
  13794. +IF_FLASHCP(APPLET(flashcp, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13795. +IF_FLOCK(APPLET(flock, BB_DIR_USR_BIN, BB_SUID_DROP))
  13796. +IF_FOLD(APPLET_NOEXEC(fold, fold, BB_DIR_USR_BIN, BB_SUID_DROP, fold))
  13797. +IF_FREE(APPLET(free, BB_DIR_USR_BIN, BB_SUID_DROP))
  13798. +IF_FREERAMDISK(APPLET(freeramdisk, BB_DIR_SBIN, BB_SUID_DROP))
  13799. +IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP))
  13800. +//IF_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext2))
  13801. +//IF_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext3))
  13802. +IF_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, BB_DIR_SBIN, BB_SUID_DROP, fsck_minix))
  13803. +IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
  13804. +IF_FTPD(APPLET(ftpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13805. +IF_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpget))
  13806. +IF_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpput))
  13807. +IF_FUSER(APPLET(fuser, BB_DIR_USR_BIN, BB_SUID_DROP))
  13808. +IF_GETENFORCE(APPLET(getenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13809. +IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP))
  13810. +IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13811. +IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP))
  13812. +IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd))
  13813. +IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP))
  13814. +IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head))
  13815. +IF_HEXDUMP(APPLET_NOEXEC(hexdump, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hexdump))
  13816. +IF_HOSTNAME(APPLET(hostname, BB_DIR_BIN, BB_SUID_DROP))
  13817. +IF_HTTPD(APPLET(httpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13818. +IF_HWCLOCK(APPLET(hwclock, BB_DIR_SBIN, BB_SUID_DROP))
  13819. +IF_IFCONFIG(APPLET(ifconfig, BB_DIR_SBIN, BB_SUID_DROP))
  13820. +IF_IFUPDOWN(APPLET_ODDNAME(ifdown, ifupdown, BB_DIR_SBIN, BB_SUID_DROP, ifdown))
  13821. +IF_IFENSLAVE(APPLET(ifenslave, BB_DIR_SBIN, BB_SUID_DROP))
  13822. +IF_IFPLUGD(APPLET(ifplugd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13823. +IF_IFUPDOWN(APPLET_ODDNAME(ifup, ifupdown, BB_DIR_SBIN, BB_SUID_DROP, ifup))
  13824. +IF_INETD(APPLET(inetd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13825. +IF_INOTIFYD(APPLET(inotifyd, BB_DIR_SBIN, BB_SUID_DROP))
  13826. +IF_INSTALL(APPLET(install, BB_DIR_USR_BIN, BB_SUID_DROP))
  13827. +IF_IONICE(APPLET(ionice, BB_DIR_BIN, BB_SUID_DROP))
  13828. +#if ENABLE_FEATURE_IP_ADDRESS \
  13829. + || ENABLE_FEATURE_IP_ROUTE \
  13830. + || ENABLE_FEATURE_IP_LINK \
  13831. + || ENABLE_FEATURE_IP_TUNNEL \
  13832. + || ENABLE_FEATURE_IP_RULE
  13833. +IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP))
  13834. +#endif
  13835. +IF_IPADDR(APPLET(ipaddr, BB_DIR_SBIN, BB_SUID_DROP))
  13836. +IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13837. +IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13838. +IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13839. +IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
  13840. +IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
  13841. +IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
  13842. +IF_IPTUNNEL(APPLET(iptunnel, BB_DIR_SBIN, BB_SUID_DROP))
  13843. +IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP))
  13844. +IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP))
  13845. +IF_KILLALL(APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall))
  13846. +IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5))
  13847. +IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP))
  13848. +IF_LAST(APPLET(last, BB_DIR_USR_BIN, BB_SUID_DROP))
  13849. +//IF_LENGTH(APPLET_NOFORK(length, length, BB_DIR_USR_BIN, BB_SUID_DROP, length))
  13850. +IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP))
  13851. +IF_SETARCH(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32))
  13852. +IF_SETARCH(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64))
  13853. +IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln))
  13854. +IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13855. +IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13856. +IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP))
  13857. +IF_LOGGER(APPLET(logger, BB_DIR_USR_BIN, BB_SUID_DROP))
  13858. +/* Needs to be run by root or be suid root - needs to change uid and gid: */
  13859. +IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE))
  13860. +IF_LOGNAME(APPLET_NOFORK(logname, logname, BB_DIR_USR_BIN, BB_SUID_DROP, logname))
  13861. +IF_LOGREAD(APPLET(logread, BB_DIR_SBIN, BB_SUID_DROP))
  13862. +IF_LOSETUP(APPLET(losetup, BB_DIR_SBIN, BB_SUID_DROP))
  13863. +IF_LPD(APPLET(lpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13864. +IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq))
  13865. +IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr))
  13866. +IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls))
  13867. +IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP))
  13868. +IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP))
  13869. +IF_LSUSB(APPLET(lsusb, BB_DIR_USR_BIN, BB_SUID_DROP))
  13870. +IF_MAKEDEVS(APPLET(makedevs, BB_DIR_SBIN, BB_SUID_DROP))
  13871. +IF_MAKEMIME(APPLET(makemime, BB_DIR_BIN, BB_SUID_DROP))
  13872. +IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
  13873. +IF_MATCHPATHCON(APPLET(matchpathcon, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13874. +IF_MD5SUM(APPLET_NOEXEC(md5sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, md5sum))
  13875. +IF_MICROCOM(APPLET(microcom, BB_DIR_USR_BIN, BB_SUID_DROP))
  13876. +IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
  13877. +IF_MKFS_VFAT(APPLET_ODDNAME(mkdosfs, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat))
  13878. +IF_MKFS_EXT2(APPLET_ODDNAME(mke2fs, mkfs_ext2, BB_DIR_SBIN, BB_SUID_DROP, mkfs_ext2))
  13879. +IF_MKFIFO(APPLET_NOEXEC(mkfifo, mkfifo, BB_DIR_USR_BIN, BB_SUID_DROP, mkfifo))
  13880. +IF_MKFS_EXT2(APPLET_ODDNAME(mkfs.ext2, mkfs_ext2, BB_DIR_SBIN, BB_SUID_DROP, mkfs_ext2))
  13881. +//IF_MKE2FS(APPLET_ODDNAME(mkfs.ext3, mke2fs, BB_DIR_SBIN, BB_SUID_DROP, mkfs_ext3))
  13882. +IF_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix, mkfs_minix, BB_DIR_SBIN, BB_SUID_DROP, mkfs_minix))
  13883. +IF_MKFS_REISER(APPLET_ODDNAME(mkfs.reiser, mkfs_reiser, BB_DIR_SBIN, BB_SUID_DROP, mkfs_reiser))
  13884. +IF_MKFS_VFAT(APPLET_ODDNAME(mkfs.vfat, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat))
  13885. +IF_MKNOD(APPLET_NOEXEC(mknod, mknod, BB_DIR_BIN, BB_SUID_DROP, mknod))
  13886. +IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, mkpasswd))
  13887. +IF_MKSWAP(APPLET(mkswap, BB_DIR_SBIN, BB_SUID_DROP))
  13888. +IF_MKTEMP(APPLET(mktemp, BB_DIR_BIN, BB_SUID_DROP))
  13889. +IF_MORE(APPLET(more, BB_DIR_BIN, BB_SUID_DROP))
  13890. +/* On full-blown systems, requires suid for user mounts.
  13891. + * But it's not unthinkable to have it available in non-suid flavor on some systems,
  13892. + * for viewing mount table.
  13893. + * Therefore we use BB_SUID_MAYBE instead of BB_SUID_REQUIRE: */
  13894. +IF_MOUNT(APPLET(mount, BB_DIR_BIN, IF_DESKTOP(BB_SUID_MAYBE) IF_NOT_DESKTOP(BB_SUID_DROP)))
  13895. +IF_MOUNTPOINT(APPLET(mountpoint, BB_DIR_BIN, BB_SUID_DROP))
  13896. +IF_MT(APPLET(mt, BB_DIR_BIN, BB_SUID_DROP))
  13897. +IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
  13898. +IF_NAMEIF(APPLET(nameif, BB_DIR_SBIN, BB_SUID_DROP))
  13899. +IF_NC(APPLET(nc, BB_DIR_USR_BIN, BB_SUID_DROP))
  13900. +IF_NETSTAT(APPLET(netstat, BB_DIR_BIN, BB_SUID_DROP))
  13901. +IF_NICE(APPLET(nice, BB_DIR_BIN, BB_SUID_DROP))
  13902. +IF_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP))
  13903. +IF_NSLOOKUP(APPLET(nslookup, BB_DIR_USR_BIN, BB_SUID_DROP))
  13904. +IF_NTPD(APPLET(ntpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13905. +IF_OD(APPLET(od, BB_DIR_USR_BIN, BB_SUID_DROP))
  13906. +IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP))
  13907. +//IF_PARSE(APPLET(parse, BB_DIR_USR_BIN, BB_SUID_DROP))
  13908. +/* Needs to be run by root or be suid root - needs to change /etc/{passwd,shadow}: */
  13909. +IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
  13910. +IF_PGREP(APPLET(pgrep, BB_DIR_USR_BIN, BB_SUID_DROP))
  13911. +IF_PIDOF(APPLET(pidof, BB_DIR_BIN, BB_SUID_DROP))
  13912. +IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP))
  13913. +IF_PIVOT_ROOT(APPLET(pivot_root, BB_DIR_SBIN, BB_SUID_DROP))
  13914. +IF_PKILL(APPLET_ODDNAME(pkill, pgrep, BB_DIR_USR_BIN, BB_SUID_DROP, pkill))
  13915. +IF_POPMAILDIR(APPLET(popmaildir, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13916. +IF_PRINTENV(APPLET_NOFORK(printenv, printenv, BB_DIR_BIN, BB_SUID_DROP, printenv))
  13917. +IF_PRINTF(APPLET_NOFORK(printf, printf, BB_DIR_USR_BIN, BB_SUID_DROP, printf))
  13918. +IF_PS(APPLET(ps, BB_DIR_BIN, BB_SUID_DROP))
  13919. +IF_PSCAN(APPLET(pscan, BB_DIR_USR_BIN, BB_SUID_DROP))
  13920. +IF_PWD(APPLET_NOFORK(pwd, pwd, BB_DIR_BIN, BB_SUID_DROP, pwd))
  13921. +IF_RAIDAUTORUN(APPLET(raidautorun, BB_DIR_SBIN, BB_SUID_DROP))
  13922. +IF_RDATE(APPLET(rdate, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13923. +IF_RDEV(APPLET(rdev, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13924. +IF_READAHEAD(APPLET(readahead, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13925. +IF_READLINK(APPLET(readlink, BB_DIR_USR_BIN, BB_SUID_DROP))
  13926. +IF_READPROFILE(APPLET(readprofile, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13927. +IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP))
  13928. +IF_REFORMIME(APPLET(reformime, BB_DIR_BIN, BB_SUID_DROP))
  13929. +IF_RENICE(APPLET(renice, BB_DIR_USR_BIN, BB_SUID_DROP))
  13930. +IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP))
  13931. +IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP))
  13932. +IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, BB_DIR_SBIN, BB_SUID_DROP, restorecon))
  13933. +IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
  13934. +IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir))
  13935. +IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP))
  13936. +IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13937. +IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts))
  13938. +IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP))
  13939. +IF_RUNLEVEL(APPLET(runlevel, BB_DIR_SBIN, BB_SUID_DROP))
  13940. +IF_RUNSV(APPLET(runsv, BB_DIR_USR_BIN, BB_SUID_DROP))
  13941. +IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP))
  13942. +IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP))
  13943. +IF_SCRIPT(APPLET(script, BB_DIR_USR_BIN, BB_SUID_DROP))
  13944. +IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP))
  13945. +IF_SELINUXENABLED(APPLET(selinuxenabled, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13946. +IF_SENDMAIL(APPLET(sendmail, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13947. +IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
  13948. +IF_SESTATUS(APPLET(sestatus, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13949. +IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP))
  13950. +IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
  13951. +IF_SETENFORCE(APPLET(setenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13952. +IF_SETFILES(APPLET(setfiles, BB_DIR_SBIN, BB_SUID_DROP))
  13953. +IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13954. +IF_SETKEYCODES(APPLET(setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP))
  13955. +IF_SETLOGCONS(APPLET(setlogcons, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13956. +IF_SETSEBOOL(APPLET(setsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13957. +IF_SETSID(APPLET(setsid, BB_DIR_USR_BIN, BB_SUID_DROP))
  13958. +IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid))
  13959. +IF_SHA1SUM(APPLET_NOEXEC(sha1sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha1sum))
  13960. +IF_SHA3SUM(APPLET_NOEXEC(sha3sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha3sum))
  13961. +IF_SHA256SUM(APPLET_NOEXEC(sha256sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha256sum))
  13962. +IF_SHA512SUM(APPLET_NOEXEC(sha512sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha512sum))
  13963. +IF_SHOWKEY(APPLET(showkey, BB_DIR_USR_BIN, BB_SUID_DROP))
  13964. +IF_SLATTACH(APPLET(slattach, BB_DIR_SBIN, BB_SUID_DROP))
  13965. +/* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells: */
  13966. +IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP))
  13967. +IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit))
  13968. +IF_SORT(APPLET_NOEXEC(sort, sort, BB_DIR_USR_BIN, BB_SUID_DROP, sort))
  13969. +IF_SPLIT(APPLET(split, BB_DIR_USR_BIN, BB_SUID_DROP))
  13970. +IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon))
  13971. +IF_STAT(APPLET(stat, BB_DIR_BIN, BB_SUID_DROP))
  13972. +IF_STRINGS(APPLET(strings, BB_DIR_USR_BIN, BB_SUID_DROP))
  13973. +IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP))
  13974. +/* Needs to be run by root or be suid root - needs to change uid and gid: */
  13975. +IF_SU(APPLET(su, BB_DIR_BIN, BB_SUID_REQUIRE))
  13976. +IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP))
  13977. +IF_SUM(APPLET(sum, BB_DIR_USR_BIN, BB_SUID_DROP))
  13978. +IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP))
  13979. +IF_SVLOGD(APPLET(svlogd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13980. +IF_SWAPONOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapoff))
  13981. +IF_SWAPONOFF(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon))
  13982. +IF_SWITCH_ROOT(APPLET(switch_root, BB_DIR_SBIN, BB_SUID_DROP))
  13983. +IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync))
  13984. +IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP))
  13985. +IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP))
  13986. +IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac))
  13987. +IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP))
  13988. +/* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */
  13989. +IF_TCPSVD(APPLET_ODDNAME(tcpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, tcpsvd))
  13990. +IF_TEE(APPLET(tee, BB_DIR_USR_BIN, BB_SUID_DROP))
  13991. +IF_TELNET(APPLET(telnet, BB_DIR_USR_BIN, BB_SUID_DROP))
  13992. +IF_TELNETD(APPLET(telnetd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13993. +IF_TEST(APPLET_NOFORK(test, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
  13994. +#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
  13995. +IF_TFTP(APPLET(tftp, BB_DIR_USR_BIN, BB_SUID_DROP))
  13996. +IF_TFTPD(APPLET(tftpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  13997. +#endif
  13998. +IF_TIME(APPLET(time, BB_DIR_USR_BIN, BB_SUID_DROP))
  13999. +IF_TIMEOUT(APPLET(timeout, BB_DIR_USR_BIN, BB_SUID_DROP))
  14000. +IF_TOP(APPLET(top, BB_DIR_USR_BIN, BB_SUID_DROP))
  14001. +IF_TR(APPLET(tr, BB_DIR_USR_BIN, BB_SUID_DROP))
  14002. +/* Needs socket(AF_INET, SOCK_RAW, IPPROTO_ICMP), therefore BB_SUID_MAYBE: */
  14003. +IF_TRACEROUTE(APPLET(traceroute, BB_DIR_USR_BIN, BB_SUID_MAYBE))
  14004. +IF_TRACEROUTE6(APPLET(traceroute6, BB_DIR_USR_BIN, BB_SUID_MAYBE))
  14005. +IF_TRUE(APPLET_NOFORK(true, true, BB_DIR_BIN, BB_SUID_DROP, true))
  14006. +IF_TTY(APPLET(tty, BB_DIR_USR_BIN, BB_SUID_DROP))
  14007. +IF_TTYSIZE(APPLET(ttysize, BB_DIR_USR_BIN, BB_SUID_DROP))
  14008. +IF_TUNCTL(APPLET(tunctl, BB_DIR_SBIN, BB_SUID_DROP))
  14009. +IF_TUNE2FS(APPLET(tune2fs, BB_DIR_SBIN, BB_SUID_DROP))
  14010. +IF_UDHCPC(APPLET(udhcpc, BB_DIR_SBIN, BB_SUID_DROP))
  14011. +IF_UDHCPD(APPLET(udhcpd, BB_DIR_USR_SBIN, BB_SUID_DROP))
  14012. +IF_UDPSVD(APPLET_ODDNAME(udpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, udpsvd))
  14013. +IF_UMOUNT(APPLET(umount, BB_DIR_BIN, BB_SUID_DROP))
  14014. +IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP))
  14015. +IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand))
  14016. +IF_UNIQ(APPLET(uniq, BB_DIR_USR_BIN, BB_SUID_DROP))
  14017. +IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos))
  14018. +IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP))
  14019. +IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep))
  14020. +IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP))
  14021. +IF_UUENCODE(APPLET(uuencode, BB_DIR_USR_BIN, BB_SUID_DROP))
  14022. +IF_VCONFIG(APPLET(vconfig, BB_DIR_SBIN, BB_SUID_DROP))
  14023. +/* Needs to be run by root or be suid root - needs to change uid and gid: */
  14024. +IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
  14025. +IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP))
  14026. +IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP))
  14027. +IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP))
  14028. +IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
  14029. +IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP))
  14030. +IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP))
  14031. +IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami))
  14032. +IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
  14033. +IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP))
  14034. +
  14035. +#if !defined(PROTOTYPES) && !defined(NAME_MAIN) && !defined(MAKE_USAGE) \
  14036. + && !defined(MAKE_LINKS) && !defined(MAKE_SUID)
  14037. +};
  14038. +#endif
  14039. +
  14040. +#undef APPLET
  14041. +#undef APPLET_ODDNAME
  14042. +#undef APPLET_NOEXEC
  14043. +#undef APPLET_NOFORK
  14044. diff -Nur busybox-1.23.0.orig/include/bb_archive.h busybox-1.23.0/include/bb_archive.h
  14045. --- busybox-1.23.0.orig/include/bb_archive.h 2014-12-10 23:00:17.000000000 -0600
  14046. +++ busybox-1.23.0/include/bb_archive.h 2015-01-09 11:18:22.440197244 -0600
  14047. @@ -79,7 +79,6 @@
  14048. /* Archiver specific. Can make it a union if it ever gets big */
  14049. #define PAX_NEXT_FILE 0
  14050. #define PAX_GLOBAL 1
  14051. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  14052. smallint tar__end;
  14053. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  14054. char* tar__longname;
  14055. @@ -92,13 +91,12 @@
  14056. # if ENABLE_FEATURE_TAR_SELINUX
  14057. char* tar__sctx[2];
  14058. # endif
  14059. -#endif
  14060. #if ENABLE_CPIO || ENABLE_RPM2CPIO || ENABLE_RPM
  14061. uoff_t cpio__blocks;
  14062. struct hardlinks_t *cpio__hardlinks_to_create;
  14063. struct hardlinks_t *cpio__created_hardlinks;
  14064. #endif
  14065. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  14066. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  14067. /* Temporary storage */
  14068. char *dpkg__buffer;
  14069. /* How to process any sub archive, e.g. get_header_tar_gz */
  14070. diff -Nur busybox-1.23.0.orig/include/usage.src.h busybox-1.23.0/include/usage.src.h
  14071. --- busybox-1.23.0.orig/include/usage.src.h 2014-10-04 15:35:59.000000000 -0500
  14072. +++ busybox-1.23.0/include/usage.src.h 2015-01-09 11:18:22.440197244 -0600
  14073. @@ -19,4 +19,80 @@
  14074. #define busybox_notes_usage \
  14075. "Hello world!\n"
  14076. +#define ipkg_trivial_usage \
  14077. + "[options]... sub-command [arguments]..."
  14078. +#define ipkg_full_usage \
  14079. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  14080. + "\n" \
  14081. + "Sub-commands:\n" \
  14082. + "\nPackage Manipulation:\n" \
  14083. + "\tupdate Update list of available packages\n" \
  14084. + "\tupgrade Upgrade all installed packages to latest version\n" \
  14085. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  14086. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  14087. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  14088. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  14089. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  14090. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  14091. + "\n" \
  14092. + "Informational Commands:\n" \
  14093. + "\tlist List available packages and descriptions\n" \
  14094. + "\tlist_installed List all and only the installed packages and description \n" \
  14095. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  14096. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  14097. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  14098. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  14099. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  14100. + "\tcompare_versions <v1> <op> <v2>\n" \
  14101. + "\t compare versions using <= < > >= = << >>\n" \
  14102. + "\tprint_architecture prints the architecture.\n" \
  14103. + "\tprint_installation_architecture\n" \
  14104. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  14105. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  14106. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  14107. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  14108. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  14109. + "\t prints the installation architecture.\n" \
  14110. + "\n" \
  14111. + "\nOptions:\n" \
  14112. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  14113. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  14114. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  14115. + "\t 0 errors only\n" \
  14116. + "\t 1 normal messages (default)\n" \
  14117. + "\t 2 informative messages\n" \
  14118. + "\t 3 debug output\n" \
  14119. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  14120. + "\t-conf <conf_file> Default configuration file location\n" \
  14121. + " is /etc/ipkg.conf\n" \
  14122. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  14123. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  14124. + " <dest_name> should be a defined dest name from\n" \
  14125. + " the configuration file, (but can also be a\n" \
  14126. + " directory name in a pinch).\n" \
  14127. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  14128. + "\t-offline <offline_root> offline installation of packages.\n" \
  14129. + "\t-verbose_wget more wget messages\n" \
  14130. + "\n" \
  14131. + "Force Options (use when ipkg is too smart for its own good):\n" \
  14132. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  14133. + "\t Install/remove package in spite of failed dependences\n" \
  14134. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  14135. + " (no prompts). Note that this will not prevent\n" \
  14136. + " package installation scripts from prompting.\n" \
  14137. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  14138. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  14139. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  14140. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  14141. + "\t-noaction No action -- test only\n" \
  14142. + "\t-nodeps Do not follow dependences\n" \
  14143. + "\t-force-removal-of-dependent-packages\n" \
  14144. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  14145. + "\t-test No action -- test only\n" \
  14146. + "\t-t Specify tmp-dir.\n" \
  14147. + "\t--tmp-dir Specify tmp-dir.\n" \
  14148. + "\n" \
  14149. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  14150. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  14151. +
  14152. #endif
  14153. diff -Nur busybox-1.23.0.orig/Makefile busybox-1.23.0/Makefile
  14154. --- busybox-1.23.0.orig/Makefile 2014-12-23 18:48:20.000000000 -0600
  14155. +++ busybox-1.23.0/Makefile 2015-01-09 11:18:22.424197243 -0600
  14156. @@ -466,6 +466,7 @@
  14157. libs-y := \
  14158. archival/ \
  14159. archival/libarchive/ \
  14160. + archival/libipkg/ \
  14161. console-tools/ \
  14162. coreutils/ \
  14163. coreutils/libcoreutils/ \