001-ipkg.patch 424 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763
  1. diff -Nur busybox-1.24.1.orig/archival/ipkg.c busybox-1.24.1/archival/ipkg.c
  2. --- busybox-1.24.1.orig/archival/ipkg.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ busybox-1.24.1/archival/ipkg.c 2015-10-31 19:00:22.000000000 +0100
  4. @@ -0,0 +1,39 @@
  5. +/* ipkg.c - the itsy package management system
  6. +
  7. + Florina Boor
  8. +
  9. + Copyright (C) 2003 kernel concepts
  10. +
  11. + This program is free software; you can redistribute it and/or
  12. + modify it under the terms of the GNU General Public License as
  13. + published by the Free Software Foundation; either version 2, or (at
  14. + your option) any later version.
  15. +
  16. + This program is distributed in the hope that it will be useful, but
  17. + WITHOUT ANY WARRANTY; without even the implied warranty of
  18. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. + General Public License for more details.
  20. +
  21. + ipkg command line frontend using libipkg
  22. +
  23. +*/
  24. +
  25. +//config:config IPKG
  26. +//config: bool "ipkg"
  27. +//config: default n
  28. +//config: help
  29. +//config: ipkg is a tool to install, build, remove and manage
  30. +//config: packages.
  31. +//config:
  32. +
  33. +//applet:IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  34. +//kbuild:lib-$(CONFIG_IPKG) += ipkg.o
  35. +
  36. +#include "libbb.h"
  37. +#include "libipkg/libipkg.h"
  38. +
  39. +int ipkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  40. +int ipkg_main(int argc, char **argv)
  41. +{
  42. + return ipkg_op(argc, argv);
  43. +}
  44. diff -Nur busybox-1.24.1.orig/archival/libarchive/Kbuild.src busybox-1.24.1/archival/libarchive/Kbuild.src
  45. --- busybox-1.24.1.orig/archival/libarchive/Kbuild.src 2015-10-24 02:24:35.000000000 +0200
  46. +++ busybox-1.24.1/archival/libarchive/Kbuild.src 2015-10-31 19:01:17.000000000 +0100
  47. @@ -25,6 +25,8 @@
  48. \
  49. data_align.o \
  50. find_list_entry.o \
  51. + get_header_tar.o \
  52. + get_header_tar_gz.o \
  53. init_handle.o
  54. DPKG_FILES:= \
  55. @@ -32,8 +34,6 @@
  56. filter_accept_list_reassign.o \
  57. unsafe_prefix.o \
  58. get_header_ar.o \
  59. - get_header_tar.o \
  60. - get_header_tar_gz.o \
  61. get_header_tar_bz2.o \
  62. get_header_tar_lzma.o \
  63. get_header_tar_xz.o \
  64. diff -Nur busybox-1.24.1.orig/archival/libipkg/args.c busybox-1.24.1/archival/libipkg/args.c
  65. --- busybox-1.24.1.orig/archival/libipkg/args.c 1970-01-01 01:00:00.000000000 +0100
  66. +++ busybox-1.24.1/archival/libipkg/args.c 2015-10-31 19:00:22.000000000 +0100
  67. @@ -0,0 +1,242 @@
  68. +/* args.c - parse command-line args
  69. +
  70. + Carl D. Worth
  71. +
  72. + Copyright 2001 University of Southern California
  73. +
  74. + This program is free software; you can redistribute it and/or modify
  75. + it under the terms of the GNU General Public License as published by
  76. + the Free Software Foundation; either version 2, or (at your option)
  77. + any later version.
  78. +
  79. + This program is distributed in the hope that it will be useful,
  80. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  81. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  82. + GNU General Public License for more details.
  83. + */
  84. +
  85. +#include <getopt.h>
  86. +#include <stdlib.h>
  87. +#include <string.h>
  88. +#include <unistd.h>
  89. +
  90. +#include "ipkg.h"
  91. +#include "ipkg_message.h"
  92. +
  93. +#include "args.h"
  94. +#include "sprintf_alloc.h"
  95. +
  96. +#include "libbb.h"
  97. +
  98. +
  99. +static void print_version(void);
  100. +
  101. +enum long_args_opt
  102. +{
  103. + ARGS_OPT_FORCE_DEFAULTS = 129,
  104. + ARGS_OPT_FORCE_DEPENDS,
  105. + ARGS_OPT_FORCE_OVERWRITE,
  106. + ARGS_OPT_FORCE_DOWNGRADE,
  107. + ARGS_OPT_FORCE_REINSTALL,
  108. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
  109. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
  110. + ARGS_OPT_FORCE_SPACE,
  111. + ARGS_OPT_NOACTION,
  112. + ARGS_OPT_NODEPS,
  113. + ARGS_OPT_VERBOSE_WGET,
  114. + ARGS_OPT_VERBOSITY,
  115. + ARGS_OPT_MULTIPLE_PROVIDERS
  116. +};
  117. +
  118. +int args_init(args_t *args)
  119. +{
  120. + const char *conf_file_dir;
  121. +
  122. + memset(args, 0, sizeof(args_t));
  123. +
  124. + args->dest = ARGS_DEFAULT_DEST;
  125. +
  126. + conf_file_dir = getenv("IPKG_CONF_DIR");
  127. + if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
  128. + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
  129. + }
  130. + sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
  131. + ARGS_DEFAULT_CONF_FILE_NAME);
  132. +
  133. + args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
  134. + args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
  135. + args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
  136. + args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
  137. + args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
  138. + args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
  139. + args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
  140. + args->noaction = ARGS_DEFAULT_NOACTION;
  141. + args->nodeps = ARGS_DEFAULT_NODEPS;
  142. + args->verbose_wget = ARGS_DEFAULT_VERBOSE_WGET;
  143. + args->verbosity = ARGS_DEFAULT_VERBOSITY;
  144. + args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
  145. + args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
  146. + args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
  147. + args->multiple_providers = 0;
  148. + args->nocheckfordirorfile = 0;
  149. + args->noreadfeedsfile = 0;
  150. +
  151. + return 1;
  152. +}
  153. +
  154. +void args_deinit(args_t *args)
  155. +{
  156. + free(args->conf_file);
  157. + args->conf_file = NULL;
  158. +}
  159. +
  160. +int args_parse(args_t *args, int argc, char *argv[])
  161. +{
  162. + int c;
  163. + int option_index = 0;
  164. + int parse_err = 0;
  165. + static struct option long_options[] = {
  166. + {"query-all", 0, 0, 'A'},
  167. + {"conf-file", 1, 0, 'f'},
  168. + {"conf", 1, 0, 'f'},
  169. + {"dest", 1, 0, 'd'},
  170. + {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  171. + {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
  172. + {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  173. + {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
  174. + {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  175. + {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
  176. + {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  177. + {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
  178. + {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  179. + {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
  180. + {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
  181. + {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
  182. + {"recursive", 0, 0,
  183. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  184. + {"force-removal-of-dependent-packages", 0, 0,
  185. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  186. + {"force_removal_of_dependent_packages", 0, 0,
  187. + ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
  188. + {"force-removal-of-essential-packages", 0, 0,
  189. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  190. + {"force_removal_of_essential_packages", 0, 0,
  191. + ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
  192. + {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  193. + {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
  194. + {"noaction", 0, 0, ARGS_OPT_NOACTION},
  195. + {"nodeps", 0, 0, ARGS_OPT_NODEPS},
  196. + {"offline", 1, 0, 'o'},
  197. + {"offline-root", 1, 0, 'o'},
  198. + {"test", 0, 0, ARGS_OPT_NOACTION},
  199. + {"tmp-dir", 1, 0, 't'},
  200. + {"verbose-wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  201. + {"verbose_wget", 0, 0, ARGS_OPT_VERBOSE_WGET},
  202. + {"verbosity", 2, 0, 'V'},
  203. + {"version", 0, 0, 'v'},
  204. + {0, 0, 0, 0}
  205. + };
  206. +
  207. + while (1) {
  208. + c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
  209. + if (c == -1)
  210. + break;
  211. +
  212. + switch (c) {
  213. + case 'A':
  214. + args->query_all = 1;
  215. + break;
  216. + case 'd':
  217. + args->dest = optarg;
  218. + break;
  219. + case 'f':
  220. + free(args->conf_file);
  221. + args->conf_file = strdup(optarg);
  222. + break;
  223. + case 'o':
  224. + args->offline_root = optarg;
  225. + break;
  226. + case 'n':
  227. + args->noaction = 1;
  228. + break;
  229. + case 't':
  230. + args->tmp_dir = strdup(optarg);
  231. + break;
  232. + case 'v':
  233. + print_version();
  234. + exit(0);
  235. + case 'V':
  236. + case ARGS_OPT_VERBOSITY:
  237. + if (optarg)
  238. + args->verbosity = atoi(optarg);
  239. + else
  240. + args->verbosity += 1;
  241. + break;
  242. + case ARGS_OPT_FORCE_DEFAULTS:
  243. + args->force_defaults = 1;
  244. + break;
  245. + case ARGS_OPT_FORCE_DEPENDS:
  246. + args->force_depends = 1;
  247. + break;
  248. + case ARGS_OPT_FORCE_OVERWRITE:
  249. + args->force_overwrite = 1;
  250. + break;
  251. + case ARGS_OPT_FORCE_DOWNGRADE:
  252. + args->force_downgrade = 1;
  253. + break;
  254. + case ARGS_OPT_FORCE_REINSTALL:
  255. + args->force_reinstall = 1;
  256. + break;
  257. + case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
  258. + args->force_removal_of_essential_packages = 1;
  259. + break;
  260. + case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
  261. + args->force_removal_of_dependent_packages = 1;
  262. + break;
  263. + case ARGS_OPT_FORCE_SPACE:
  264. + args->force_space = 1;
  265. + break;
  266. + case ARGS_OPT_VERBOSE_WGET:
  267. + args->verbose_wget = 1;
  268. + break;
  269. + case ARGS_OPT_MULTIPLE_PROVIDERS:
  270. + args->multiple_providers = 1;
  271. + break;
  272. + case ARGS_OPT_NODEPS:
  273. + args->nodeps = 1;
  274. + break;
  275. + case ARGS_OPT_NOACTION:
  276. + args->noaction = 1;
  277. + break;
  278. + case ':':
  279. + parse_err++;
  280. + break;
  281. + case '?':
  282. + parse_err++;
  283. + break;
  284. + default:
  285. + bb_error_msg("Confusion: getopt_long returned %d\n", c);
  286. + }
  287. + }
  288. +
  289. + if (parse_err) {
  290. + return -parse_err;
  291. + } else {
  292. + return optind;
  293. + }
  294. +}
  295. +
  296. +void args_usage(const char *complaint)
  297. +{
  298. + if (complaint) {
  299. + bb_error_msg("%s\n", complaint);
  300. + }
  301. + print_version();
  302. + bb_show_usage();
  303. + exit(1);
  304. +}
  305. +
  306. +static void print_version(void)
  307. +{
  308. + bb_error_msg("version %s\n", IPKG_VERSION);
  309. +}
  310. diff -Nur busybox-1.24.1.orig/archival/libipkg/args.h busybox-1.24.1/archival/libipkg/args.h
  311. --- busybox-1.24.1.orig/archival/libipkg/args.h 1970-01-01 01:00:00.000000000 +0100
  312. +++ busybox-1.24.1/archival/libipkg/args.h 2015-10-31 19:00:22.000000000 +0100
  313. @@ -0,0 +1,72 @@
  314. +/* args.h - parse command-line args
  315. +
  316. + Carl D. Worth
  317. +
  318. + Copyright 2001 University of Southern California
  319. +
  320. + This program is free software; you can redistribute it and/or modify
  321. + it under the terms of the GNU General Public License as published by
  322. + the Free Software Foundation; either version 2, or (at your option)
  323. + any later version.
  324. +
  325. + This program is distributed in the hope that it will be useful,
  326. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  327. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  328. + GNU General Public License for more details.
  329. +*/
  330. +
  331. +#ifndef ARGS_H
  332. +#define ARGS_H
  333. +
  334. +struct args
  335. +{
  336. + char *conf_file;
  337. + char *dest;
  338. + char *tmp_dir;
  339. + int force_defaults;
  340. + int force_depends;
  341. + int force_overwrite;
  342. + int force_downgrade;
  343. + int force_reinstall;
  344. + int force_removal_of_essential_packages;
  345. + int force_removal_of_dependent_packages;
  346. + int force_space;
  347. + int noaction;
  348. + int nodeps;
  349. + int multiple_providers;
  350. + int query_all;
  351. + int verbose_wget;
  352. + int verbosity;
  353. + int nocheckfordirorfile;
  354. + int noreadfeedsfile;
  355. + char *offline_root;
  356. + char *offline_root_pre_script_cmd;
  357. + char *offline_root_post_script_cmd;
  358. +};
  359. +typedef struct args args_t;
  360. +
  361. +#define ARGS_DEFAULT_CONF_FILE_DIR "/etc"
  362. +#define ARGS_DEFAULT_CONF_FILE_NAME "ipkg.conf"
  363. +#define ARGS_DEFAULT_DEST NULL
  364. +#define ARGS_DEFAULT_FORCE_DEFAULTS 0
  365. +#define ARGS_DEFAULT_FORCE_DEPENDS 0
  366. +#define ARGS_DEFAULT_FORCE_OVERWRITE 0
  367. +#define ARGS_DEFAULT_FORCE_DOWNGRADE 0
  368. +#define ARGS_DEFAULT_FORCE_REINSTALL 0
  369. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0
  370. +#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0
  371. +#define ARGS_DEFAULT_FORCE_SPACE 0
  372. +#define ARGS_DEFAULT_OFFLINE_ROOT NULL
  373. +#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL
  374. +#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL
  375. +#define ARGS_DEFAULT_NOACTION 0
  376. +#define ARGS_DEFAULT_NODEPS 0
  377. +#define ARGS_DEFAULT_VERBOSE_WGET 0
  378. +#define ARGS_DEFAULT_VERBOSITY 1
  379. +
  380. +int args_init(args_t *args);
  381. +void args_deinit(args_t *args);
  382. +int args_parse(args_t *args, int argc, char *argv[]);
  383. +void args_usage(const char *complaint);
  384. +
  385. +#endif
  386. diff -Nur busybox-1.24.1.orig/archival/libipkg/conffile.c busybox-1.24.1/archival/libipkg/conffile.c
  387. --- busybox-1.24.1.orig/archival/libipkg/conffile.c 1970-01-01 01:00:00.000000000 +0100
  388. +++ busybox-1.24.1/archival/libipkg/conffile.c 2015-10-31 19:00:22.000000000 +0100
  389. @@ -0,0 +1,65 @@
  390. +/* conffile.c - the itsy package management system
  391. +
  392. + Carl D. Worth
  393. +
  394. + Copyright (C) 2001 University of Southern California
  395. +
  396. + This program is free software; you can redistribute it and/or
  397. + modify it under the terms of the GNU General Public License as
  398. + published by the Free Software Foundation; either version 2, or (at
  399. + your option) any later version.
  400. +
  401. + This program is distributed in the hope that it will be useful, but
  402. + WITHOUT ANY WARRANTY; without even the implied warranty of
  403. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  404. + General Public License for more details.
  405. +*/
  406. +
  407. +#include <string.h>
  408. +#include <stdlib.h>
  409. +
  410. +#include "libbb.h"
  411. +#include "ipkg.h"
  412. +#include "ipkg_message.h"
  413. +
  414. +#include "conffile.h"
  415. +#include "file_util.h"
  416. +#include "sprintf_alloc.h"
  417. +
  418. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum)
  419. +{
  420. + return nv_pair_init(conffile, file_name, (char *)md5sum);
  421. +}
  422. +
  423. +void conffile_deinit(conffile_t *conffile)
  424. +{
  425. + nv_pair_deinit(conffile);
  426. +}
  427. +
  428. +int conffile_has_been_modified(ipkg_conf_t *conf, conffile_t *conffile)
  429. +{
  430. + uint8_t *md5sum;
  431. + char *filename = conffile->name;
  432. + char *root_filename;
  433. + int ret;
  434. +
  435. + if (conffile->value == NULL) {
  436. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name);
  437. + return 1;
  438. + }
  439. +
  440. + root_filename = root_filename_alloc(conf, filename);
  441. +
  442. + md5sum = file_md5sum_alloc(root_filename);
  443. +
  444. + ret = strcmp((char *)md5sum, conffile->value);
  445. + if (ret) {
  446. + ipkg_message(conf, IPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__,
  447. + conffile->name, md5sum, conffile->value);
  448. + }
  449. +
  450. + free(root_filename);
  451. + free(md5sum);
  452. +
  453. + return ret;
  454. +}
  455. diff -Nur busybox-1.24.1.orig/archival/libipkg/conffile.h busybox-1.24.1/archival/libipkg/conffile.h
  456. --- busybox-1.24.1.orig/archival/libipkg/conffile.h 1970-01-01 01:00:00.000000000 +0100
  457. +++ busybox-1.24.1/archival/libipkg/conffile.h 2015-10-31 19:00:22.000000000 +0100
  458. @@ -0,0 +1,30 @@
  459. +/* conffile.h - the itsy package management system
  460. +
  461. + Carl D. Worth
  462. +
  463. + Copyright (C) 2001 University of Southern California
  464. +
  465. + This program is free software; you can redistribute it and/or
  466. + modify it under the terms of the GNU General Public License as
  467. + published by the Free Software Foundation; either version 2, or (at
  468. + your option) any later version.
  469. +
  470. + This program is distributed in the hope that it will be useful, but
  471. + WITHOUT ANY WARRANTY; without even the implied warranty of
  472. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  473. + General Public License for more details.
  474. +*/
  475. +
  476. +#ifndef CONFFILE_H
  477. +#define CONFFILE_H
  478. +
  479. +#include "nv_pair.h"
  480. +
  481. +typedef struct nv_pair conffile_t;
  482. +
  483. +int conffile_init(conffile_t *conffile, const char *file_name, const uint8_t *md5sum);
  484. +void conffile_deinit(conffile_t *conffile);
  485. +int conffile_has_been_modified(struct ipkg_conf *conf, conffile_t *conffile);
  486. +
  487. +#endif
  488. +
  489. diff -Nur busybox-1.24.1.orig/archival/libipkg/conffile_list.c busybox-1.24.1/archival/libipkg/conffile_list.c
  490. --- busybox-1.24.1.orig/archival/libipkg/conffile_list.c 1970-01-01 01:00:00.000000000 +0100
  491. +++ busybox-1.24.1/archival/libipkg/conffile_list.c 2015-10-31 19:00:22.000000000 +0100
  492. @@ -0,0 +1,47 @@
  493. +/* conffile_list.c - the itsy package management system
  494. +
  495. + Carl D. Worth
  496. +
  497. + Copyright (C) 2001 University of Southern California
  498. +
  499. + This program is free software; you can redistribute it and/or
  500. + modify it under the terms of the GNU General Public License as
  501. + published by the Free Software Foundation; either version 2, or (at
  502. + your option) any later version.
  503. +
  504. + This program is distributed in the hope that it will be useful, but
  505. + WITHOUT ANY WARRANTY; without even the implied warranty of
  506. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  507. + General Public License for more details.
  508. +*/
  509. +
  510. +#include "ipkg.h"
  511. +
  512. +#include "conffile_list.h"
  513. +
  514. +int conffile_list_init(conffile_list_t *list)
  515. +{
  516. + return nv_pair_list_init(list);
  517. +}
  518. +
  519. +void conffile_list_deinit(conffile_list_t *list)
  520. +{
  521. + nv_pair_list_deinit(list);
  522. +}
  523. +
  524. +conffile_t *conffile_list_append(conffile_list_t *list, const char *file_name,
  525. + const char *md5sum)
  526. +{
  527. + return nv_pair_list_append(list, file_name, md5sum);
  528. +}
  529. +
  530. +int conffile_list_push(conffile_list_t *list, conffile_t *data)
  531. +{
  532. + return nv_pair_list_push(list, data);
  533. +}
  534. +
  535. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
  536. +{
  537. + return nv_pair_list_pop(list);
  538. +}
  539. +
  540. diff -Nur busybox-1.24.1.orig/archival/libipkg/conffile_list.h busybox-1.24.1/archival/libipkg/conffile_list.h
  541. --- busybox-1.24.1.orig/archival/libipkg/conffile_list.h 1970-01-01 01:00:00.000000000 +0100
  542. +++ busybox-1.24.1/archival/libipkg/conffile_list.h 2015-10-31 19:00:22.000000000 +0100
  543. @@ -0,0 +1,36 @@
  544. +/* conffile_list.h - the itsy package management system
  545. +
  546. + Carl D. Worth
  547. +
  548. + Copyright (C) 2001 University of Southern California
  549. +
  550. + This program is free software; you can redistribute it and/or
  551. + modify it under the terms of the GNU General Public License as
  552. + published by the Free Software Foundation; either version 2, or (at
  553. + your option) any later version.
  554. +
  555. + This program is distributed in the hope that it will be useful, but
  556. + WITHOUT ANY WARRANTY; without even the implied warranty of
  557. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  558. + General Public License for more details.
  559. +*/
  560. +
  561. +#ifndef CONFFILE_LIST_H
  562. +#define CONFFILE_LIST_H
  563. +
  564. +#include "conffile.h"
  565. +#include "nv_pair_list.h"
  566. +
  567. +typedef struct nv_pair_list_elt conffile_list_elt_t;
  568. +typedef struct nv_pair_list conffile_list_t;
  569. +
  570. +int conffile_list_init(conffile_list_t *list);
  571. +void conffile_list_deinit(conffile_list_t *list);
  572. +
  573. +conffile_t *conffile_list_append(conffile_list_t *list, const char *name,
  574. + const char *root_dir);
  575. +int conffile_list_push(conffile_list_t *list, conffile_t *data);
  576. +conffile_list_elt_t *conffile_list_pop(conffile_list_t *list);
  577. +
  578. +#endif
  579. +
  580. diff -Nur busybox-1.24.1.orig/archival/libipkg/file_util.c busybox-1.24.1/archival/libipkg/file_util.c
  581. --- busybox-1.24.1.orig/archival/libipkg/file_util.c 1970-01-01 01:00:00.000000000 +0100
  582. +++ busybox-1.24.1/archival/libipkg/file_util.c 2015-10-31 19:00:22.000000000 +0100
  583. @@ -0,0 +1,186 @@
  584. +/* file_util.c - convenience routines for common stat operations
  585. +
  586. + Carl D. Worth
  587. +
  588. + Copyright (C) 2001 University of Southern California
  589. +
  590. + This program is free software; you can redistribute it and/or
  591. + modify it under the terms of the GNU General Public License as
  592. + published by the Free Software Foundation; either version 2, or (at
  593. + your option) any later version.
  594. +
  595. + This program is distributed in the hope that it will be useful, but
  596. + WITHOUT ANY WARRANTY; without even the implied warranty of
  597. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  598. + General Public License for more details.
  599. +*/
  600. +
  601. +#include "ipkg.h"
  602. +#include <sys/types.h>
  603. +#include <sys/stat.h>
  604. +
  605. +#include "sprintf_alloc.h"
  606. +#include "file_util.h"
  607. +#include "libbb.h"
  608. +#undef strlen
  609. +
  610. +int file_exists(const char *file_name)
  611. +{
  612. + int err;
  613. + struct stat stat_buf;
  614. +
  615. + err = stat(file_name, &stat_buf);
  616. + if (err == 0) {
  617. + return 1;
  618. + } else {
  619. + return 0;
  620. + }
  621. +}
  622. +
  623. +int file_is_dir(const char *file_name)
  624. +{
  625. + int err;
  626. + struct stat stat_buf;
  627. +
  628. + err = stat(file_name, &stat_buf);
  629. + if (err) {
  630. + return 0;
  631. + }
  632. +
  633. + return S_ISDIR(stat_buf.st_mode);
  634. +}
  635. +
  636. +/* read a single line from a file, stopping at a newline or EOF.
  637. + If a newline is read, it will appear in the resulting string.
  638. + Return value is a malloc'ed char * which should be freed at
  639. + some point by the caller.
  640. +
  641. + Return value is NULL if the file is at EOF when called.
  642. +*/
  643. +#define FILE_READ_LINE_BUF_SIZE 1024
  644. +char *file_read_line_alloc(FILE *file)
  645. +{
  646. + char buf[FILE_READ_LINE_BUF_SIZE];
  647. + int buf_len;
  648. + char *line = NULL;
  649. + int line_size = 0;
  650. +
  651. + memset(buf, 0, FILE_READ_LINE_BUF_SIZE);
  652. + while (fgets(buf, FILE_READ_LINE_BUF_SIZE, file)) {
  653. + buf_len = strlen(buf);
  654. + if (line) {
  655. + line_size += buf_len;
  656. + line = realloc(line, line_size);
  657. + if (line == NULL) {
  658. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  659. + break;
  660. + }
  661. + strcat(line, buf);
  662. + } else {
  663. + line_size = buf_len + 1;
  664. + line = strdup(buf);
  665. + }
  666. + if (buf[buf_len - 1] == '\n') {
  667. + break;
  668. + }
  669. + }
  670. +
  671. + return line;
  672. +}
  673. +
  674. +int file_move(const char *src, const char *dest)
  675. +{
  676. + int err;
  677. +
  678. + err = rename(src, dest);
  679. +
  680. + if (err && errno == EXDEV) {
  681. + err = file_copy(src, dest);
  682. + unlink(src);
  683. + } else if (err) {
  684. + fprintf(stderr, "%s: ERROR: failed to rename %s to %s: %s\n",
  685. + __FUNCTION__, src, dest, strerror(errno));
  686. + }
  687. +
  688. + return err;
  689. +}
  690. +
  691. +/* I put these here to keep libbb dependencies from creeping all over
  692. + the ipkg code */
  693. +int file_copy(const char *src, const char *dest)
  694. +{
  695. + int err;
  696. +
  697. + err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS);
  698. + if (err) {
  699. + fprintf(stderr, "%s: ERROR: failed to copy %s to %s\n",
  700. + __FUNCTION__, src, dest);
  701. + }
  702. +
  703. + return err;
  704. +}
  705. +
  706. +int file_mkdir_hier(char *path, long mode)
  707. +{
  708. + return bb_make_directory(path, mode, FILEUTILS_RECUR);
  709. +}
  710. +
  711. +static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
  712. + unsigned hash_length)
  713. +{
  714. + /* xzalloc zero-terminates */
  715. + char *hex_value = xzalloc((hash_length * 2) + 1);
  716. + bin2hex(hex_value, (char*)hash_value, hash_length);
  717. + return (unsigned char *)hex_value;
  718. +}
  719. +
  720. +static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
  721. +{
  722. + int src_fd, hash_len, count;
  723. + union _ctx_ {
  724. + sha1_ctx_t sha1;
  725. + md5_ctx_t md5;
  726. + } context;
  727. + uint8_t *hash_value = NULL;
  728. + RESERVE_CONFIG_UBUFFER(in_buf, 4096);
  729. + void FAST_FUNC (*update)(void*, const void*, size_t);
  730. + void FAST_FUNC (*final)(void*, void*);
  731. +
  732. + src_fd = open_or_warn_stdin(filename);
  733. + if (src_fd < 0) {
  734. + return NULL;
  735. + }
  736. +
  737. + /* figure specific hash algorithims */
  738. + if (ENABLE_MD5SUM && hash_algo == HASH_MD5) {
  739. + md5_begin(&context.md5);
  740. + update = (void*)md5_hash;
  741. + final = (void*)md5_end;
  742. + hash_len = 16;
  743. + } else {
  744. + bb_error_msg_and_die("algorithm not supported");
  745. + }
  746. +
  747. + while ((count = safe_read(src_fd, in_buf, 4096)) > 0) {
  748. + update(&context, in_buf, count);
  749. + }
  750. +
  751. + if (count == 0) {
  752. + final(&context, in_buf);
  753. + hash_value = hash_bin_to_hex(in_buf, hash_len);
  754. + }
  755. +
  756. + RELEASE_CONFIG_BUFFER(in_buf);
  757. +
  758. + if (src_fd != STDIN_FILENO) {
  759. + close(src_fd);
  760. + }
  761. +
  762. + return hash_value;
  763. +}
  764. +
  765. +uint8_t *file_md5sum_alloc(const char *file_name)
  766. +{
  767. + return hash_file(file_name, HASH_MD5);
  768. +}
  769. +
  770. diff -Nur busybox-1.24.1.orig/archival/libipkg/file_util.h busybox-1.24.1/archival/libipkg/file_util.h
  771. --- busybox-1.24.1.orig/archival/libipkg/file_util.h 1970-01-01 01:00:00.000000000 +0100
  772. +++ busybox-1.24.1/archival/libipkg/file_util.h 2015-10-31 19:00:22.000000000 +0100
  773. @@ -0,0 +1,29 @@
  774. +/* file_util.h - convenience routines for common file operations
  775. +
  776. + Carl D. Worth
  777. +
  778. + Copyright (C) 2001 University of Southern California
  779. +
  780. + This program is free software; you can redistribute it and/or
  781. + modify it under the terms of the GNU General Public License as
  782. + published by the Free Software Foundation; either version 2, or (at
  783. + your option) any later version.
  784. +
  785. + This program is distributed in the hope that it will be useful, but
  786. + WITHOUT ANY WARRANTY; without even the implied warranty of
  787. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  788. + General Public License for more details.
  789. +*/
  790. +
  791. +#ifndef FILE_UTIL_H
  792. +#define FILE_UTIL_H
  793. +
  794. +int file_exists(const char *file_name);
  795. +int file_is_dir(const char *file_name);
  796. +char *file_read_line_alloc(FILE *file);
  797. +int file_move(const char *src, const char *dest);
  798. +int file_copy(const char *src, const char *dest);
  799. +int file_mkdir_hier(char *path, long mode);
  800. +uint8_t *file_md5sum_alloc(const char *file_name);
  801. +
  802. +#endif
  803. diff -Nur busybox-1.24.1.orig/archival/libipkg/hash_table.c busybox-1.24.1/archival/libipkg/hash_table.c
  804. --- busybox-1.24.1.orig/archival/libipkg/hash_table.c 1970-01-01 01:00:00.000000000 +0100
  805. +++ busybox-1.24.1/archival/libipkg/hash_table.c 2015-10-31 19:00:22.000000000 +0100
  806. @@ -0,0 +1,155 @@
  807. +/* hash.c - hash tables for ipkg
  808. +
  809. + Steven M. Ayer, Jamey Hicks
  810. +
  811. + Copyright (C) 2002 Compaq Computer Corporation
  812. +
  813. + This program is free software; you can redistribute it and/or
  814. + modify it under the terms of the GNU General Public License as
  815. + published by the Free Software Foundation; either version 2, or (at
  816. + your option) any later version.
  817. +
  818. + This program is distributed in the hope that it will be useful, but
  819. + WITHOUT ANY WARRANTY; without even the implied warranty of
  820. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  821. + General Public License for more details.
  822. +*/
  823. +
  824. +#include <errno.h>
  825. +#include <stdio.h>
  826. +#include <stdlib.h>
  827. +#include <string.h>
  828. +#include "hash_table.h"
  829. +#include "ipkg_message.h"
  830. +
  831. +
  832. +static int hash_index(hash_table_t *hash, const char *pkg_name);
  833. +static int rotating(const char *key, int len, int prime);
  834. +
  835. +static int hash_index(hash_table_t *hash, const char *pkg_name)
  836. +{
  837. + return rotating(pkg_name, strlen(pkg_name), hash->n_entries);
  838. +}
  839. +
  840. +static int rotating(const char *key, int len, int prime)
  841. +{
  842. + unsigned int hash, i;
  843. + for (hash=len, i=0; i<len; ++i)
  844. + hash = (hash<<4)^(hash>>28)^key[i];
  845. + return (hash % prime);
  846. +}
  847. +
  848. +
  849. +/*
  850. + * this is an open table keyed by strings
  851. + */
  852. +int hash_table_init(const char *name, hash_table_t *hash, int len)
  853. +{
  854. + static int primes_table[] = {
  855. + 379, 761, 983, 1423, 2711, 3361, 3931, 4679, 5519, 6701, 9587,
  856. + 19471, 23143, 33961, 46499, 49727, 99529, 0
  857. + };
  858. + int *picker;
  859. +
  860. + if (hash->entries != NULL) {
  861. + /* we have been here already */
  862. + return 0;
  863. + }
  864. +
  865. + hash->name = name;
  866. + hash->entries = NULL;
  867. + hash->n_entries = 0;
  868. + hash->hash_entry_key = NULL;
  869. +
  870. + picker = primes_table;
  871. + while(*picker && (*picker++ < len));
  872. + if(!*picker)
  873. + fprintf(stderr, "%s: primes table might not be big enough (! << %d)\n", __FUNCTION__, len);
  874. + --picker;
  875. +
  876. + hash->n_entries = *picker;
  877. + hash->entries = (hash_entry_t *)calloc(hash->n_entries, sizeof(hash_entry_t));
  878. + if (hash->entries == NULL) {
  879. + fprintf(stderr, "%s: Out of memory.\n", __FUNCTION__);
  880. + return ENOMEM;
  881. + }
  882. + return 0;
  883. +}
  884. +
  885. +void hash_table_deinit(hash_table_t *hash)
  886. +{
  887. + free(hash->entries);
  888. + hash->entries = NULL;
  889. + hash->n_entries = 0;
  890. +}
  891. +
  892. +void *hash_table_get(hash_table_t *hash, const char *key)
  893. +{
  894. + int ndx= hash_index(hash, key);
  895. + hash_entry_t *hash_entry = hash->entries + ndx;
  896. + while (hash_entry)
  897. + {
  898. + if (hash_entry->key)
  899. + {
  900. + if (strcmp(key, hash_entry->key) == 0) {
  901. + // ipkg_message(NULL, IPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key);
  902. + return hash_entry->data;
  903. + }
  904. + }
  905. + hash_entry = hash_entry->next;
  906. + }
  907. + return NULL;
  908. +}
  909. +
  910. +int hash_table_insert(hash_table_t *hash, const char *key, void *value)
  911. +{
  912. + int ndx= hash_index(hash, key);
  913. + hash_entry_t *hash_entry = hash->entries + ndx;
  914. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Inserting in hash for '%s' \n", __FUNCTION__, key);
  915. + if (hash_entry->key) {
  916. + if (strcmp(hash_entry->key, key) == 0) {
  917. + /* alread in table, update the value */
  918. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash for '%s' \n", __FUNCTION__, key);
  919. + hash_entry->data = value;
  920. + return 0;
  921. + } else {
  922. + /*
  923. + * if this is a collision, we have to go to the end of the ll,
  924. + * then add a new entry
  925. + * before we can hook up the value
  926. + */
  927. + if (0) ipkg_message(NULL, IPKG_DEBUG2, "Function: %s. Value already in hash by collision for '%s' \n", __FUNCTION__, key);
  928. + while (hash_entry->next)
  929. + hash_entry = hash_entry->next;
  930. + hash_entry->next = (hash_entry_t *)malloc(sizeof(hash_entry_t));
  931. + if (!hash_entry->next) {
  932. + return -ENOMEM;
  933. + }
  934. + hash_entry = hash_entry->next;
  935. + hash_entry->next = NULL;
  936. + }
  937. + }
  938. + hash->n_elements++;
  939. + hash_entry->key = strdup(key);
  940. + hash_entry->data = value;
  941. +
  942. + return 0;
  943. +}
  944. +
  945. +
  946. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data)
  947. +{
  948. + int i;
  949. + if (!hash || !f)
  950. + return;
  951. +
  952. + for (i = 0; i < hash->n_entries; i++) {
  953. + hash_entry_t *hash_entry = (hash->entries + i);
  954. + do {
  955. + if(hash_entry->key) {
  956. + f(hash_entry->key, hash_entry->data, data);
  957. + }
  958. + } while((hash_entry = hash_entry->next));
  959. + }
  960. +}
  961. +
  962. diff -Nur busybox-1.24.1.orig/archival/libipkg/hash_table.h busybox-1.24.1/archival/libipkg/hash_table.h
  963. --- busybox-1.24.1.orig/archival/libipkg/hash_table.h 1970-01-01 01:00:00.000000000 +0100
  964. +++ busybox-1.24.1/archival/libipkg/hash_table.h 2015-10-31 19:00:22.000000000 +0100
  965. @@ -0,0 +1,44 @@
  966. +/* hash.h - hash tables for ipkg
  967. +
  968. + Steven M. Ayer, Jamey Hicks
  969. +
  970. + Copyright (C) 2002 Compaq Computer Corporation
  971. +
  972. + This program is free software; you can redistribute it and/or
  973. + modify it under the terms of the GNU General Public License as
  974. + published by the Free Software Foundation; either version 2, or (at
  975. + your option) any later version.
  976. +
  977. + This program is distributed in the hope that it will be useful, but
  978. + WITHOUT ANY WARRANTY; without even the implied warranty of
  979. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  980. + General Public License for more details.
  981. +*/
  982. +
  983. +#ifndef _HASH_TABLE_H_
  984. +#define _HASH_TABLE_H_
  985. +
  986. +typedef struct hash_entry hash_entry_t;
  987. +typedef struct hash_table hash_table_t;
  988. +
  989. +struct hash_entry {
  990. + const char * key;
  991. + void * data;
  992. + struct hash_entry * next;
  993. +};
  994. +
  995. +struct hash_table {
  996. + const char *name;
  997. + hash_entry_t * entries;
  998. + int n_entries; /* number of buckets */
  999. + int n_elements;
  1000. + const char * (*hash_entry_key)(void * data);
  1001. +};
  1002. +
  1003. +int hash_table_init(const char *name, hash_table_t *hash, int len);
  1004. +void hash_table_deinit(hash_table_t *hash);
  1005. +void *hash_table_get(hash_table_t *hash, const char *key);
  1006. +int hash_table_insert(hash_table_t *hash, const char *key, void *value);
  1007. +void hash_table_foreach(hash_table_t *hash, void (*f)(const char *key, void *entry, void *data), void *data);
  1008. +
  1009. +#endif /* _HASH_TABLE_H_ */
  1010. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_cmd.c busybox-1.24.1/archival/libipkg/ipkg_cmd.c
  1011. --- busybox-1.24.1.orig/archival/libipkg/ipkg_cmd.c 1970-01-01 01:00:00.000000000 +0100
  1012. +++ busybox-1.24.1/archival/libipkg/ipkg_cmd.c 2015-10-31 19:00:22.000000000 +0100
  1013. @@ -0,0 +1,1367 @@
  1014. +/* ipkg_cmd.c - the itsy package management system
  1015. +
  1016. + Carl D. Worth
  1017. +
  1018. + Copyright (C) 2001 University of Southern California
  1019. +
  1020. + This program is free software; you can redistribute it and/or
  1021. + modify it under the terms of the GNU General Public License as
  1022. + published by the Free Software Foundation; either version 2, or (at
  1023. + your option) any later version.
  1024. +
  1025. + This program is distributed in the hope that it will be useful, but
  1026. + WITHOUT ANY WARRANTY; without even the implied warranty of
  1027. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1028. + General Public License for more details.
  1029. +*/
  1030. +
  1031. +#include <string.h>
  1032. +
  1033. +#include "ipkg.h"
  1034. +#include <libgen.h>
  1035. +#include <glob.h>
  1036. +#include <errno.h>
  1037. +#include <stdlib.h>
  1038. +#include <unistd.h>
  1039. +#include <signal.h>
  1040. +#include <stdio.h>
  1041. +#include <dirent.h>
  1042. +
  1043. +#include "ipkg_conf.h"
  1044. +#include "ipkg_cmd.h"
  1045. +#include "ipkg_message.h"
  1046. +#include "pkg.h"
  1047. +#include "pkg_dest.h"
  1048. +#include "pkg_parse.h"
  1049. +#include "sprintf_alloc.h"
  1050. +#include "pkg.h"
  1051. +#include "file_util.h"
  1052. +#include "str_util.h"
  1053. +#include "bb_archive.h"
  1054. +
  1055. +#include <fnmatch.h>
  1056. +
  1057. +
  1058. +#include "ipkg_download.h"
  1059. +#include "ipkg_install.h"
  1060. +#include "ipkg_upgrade.h"
  1061. +#include "ipkg_remove.h"
  1062. +#include "ipkg_configure.h"
  1063. +#include "ipkg_message.h"
  1064. +
  1065. +#include "libipkg.h"
  1066. +static void *p_userdata = NULL;
  1067. +
  1068. +static int ipkg_update_cmd(ipkg_conf_t *conf);
  1069. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1070. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1071. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1072. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1073. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf);
  1074. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1075. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1076. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1077. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1078. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1079. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1080. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1081. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1082. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1083. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1084. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1085. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1086. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1087. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1088. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1089. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1090. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1091. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf);
  1092. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv);
  1093. +
  1094. +/* XXX: CLEANUP: The usage strings should be incorporated into this
  1095. + array for easier maintenance */
  1096. +static ipkg_cmd_t cmds[] = {
  1097. + {"update", 0, (ipkg_cmd_fun_t)ipkg_update_cmd},
  1098. + {"upgrade", 0, (ipkg_cmd_fun_t)ipkg_upgrade_cmd},
  1099. + {"list", 0, (ipkg_cmd_fun_t)ipkg_list_cmd},
  1100. + {"list_installed", 0, (ipkg_cmd_fun_t)ipkg_list_installed_cmd},
  1101. + {"info", 0, (ipkg_cmd_fun_t)ipkg_info_cmd},
  1102. + {"flag", 1, (ipkg_cmd_fun_t)ipkg_flag_cmd},
  1103. + {"status", 0, (ipkg_cmd_fun_t)ipkg_status_cmd},
  1104. + {"install_pending", 0, (ipkg_cmd_fun_t)ipkg_install_pending_cmd},
  1105. + {"install", 1, (ipkg_cmd_fun_t)ipkg_install_cmd},
  1106. + {"remove", 1, (ipkg_cmd_fun_t)ipkg_remove_cmd},
  1107. + {"purge", 1, (ipkg_cmd_fun_t)ipkg_purge_cmd},
  1108. + {"configure", 0, (ipkg_cmd_fun_t)ipkg_configure_cmd},
  1109. + {"files", 1, (ipkg_cmd_fun_t)ipkg_files_cmd},
  1110. + {"search", 1, (ipkg_cmd_fun_t)ipkg_search_cmd},
  1111. + {"download", 1, (ipkg_cmd_fun_t)ipkg_download_cmd},
  1112. + {"compare_versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1113. + {"compare-versions", 1, (ipkg_cmd_fun_t)ipkg_compare_versions_cmd},
  1114. + {"print-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1115. + {"print_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1116. + {"print-installation-architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1117. + {"print_installation_architecture", 0, (ipkg_cmd_fun_t)ipkg_print_architecture_cmd},
  1118. + {"depends", 1, (ipkg_cmd_fun_t)ipkg_depends_cmd},
  1119. + {"whatdepends", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_cmd},
  1120. + {"whatdependsrec", 1, (ipkg_cmd_fun_t)ipkg_whatdepends_recursively_cmd},
  1121. + {"whatrecommends", 1, (ipkg_cmd_fun_t)ipkg_whatrecommends_cmd},
  1122. + {"whatsuggests", 1, (ipkg_cmd_fun_t)ipkg_whatsuggests_cmd},
  1123. + {"whatprovides", 1, (ipkg_cmd_fun_t)ipkg_whatprovides_cmd},
  1124. + {"whatreplaces", 1, (ipkg_cmd_fun_t)ipkg_whatreplaces_cmd},
  1125. + {"whatconflicts", 1, (ipkg_cmd_fun_t)ipkg_whatconflicts_cmd},
  1126. +};
  1127. +
  1128. +int ipkg_state_changed;
  1129. +static void write_status_files_if_changed(ipkg_conf_t *conf)
  1130. +{
  1131. + if (ipkg_state_changed && !conf->noaction) {
  1132. + ipkg_message(conf, IPKG_INFO,
  1133. + " writing status file\n");
  1134. + ipkg_conf_write_status_files(conf);
  1135. + pkg_write_changed_filelists(conf);
  1136. + } else {
  1137. + ipkg_message(conf, IPKG_NOTICE, "Nothing to be done\n");
  1138. + }
  1139. +}
  1140. +
  1141. +
  1142. +static int num_cmds = sizeof(cmds) / sizeof(ipkg_cmd_t);
  1143. +
  1144. +ipkg_cmd_t *ipkg_cmd_find(const char *name)
  1145. +{
  1146. + int i;
  1147. + ipkg_cmd_t *cmd;
  1148. +
  1149. + for (i=0; i < num_cmds; i++) {
  1150. + cmd = &cmds[i];
  1151. + if (strcmp(name, cmd->name) == 0) {
  1152. + return cmd;
  1153. + }
  1154. + }
  1155. +
  1156. + return NULL;
  1157. +}
  1158. +
  1159. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc, const char **argv, void *userdata)
  1160. +{
  1161. + int result;
  1162. + p_userdata = userdata;
  1163. +
  1164. +
  1165. + result = (cmd->fun)(conf, argc, argv);
  1166. + if ( result == 0 ) {
  1167. + ipkg_message(conf, IPKG_NOTICE, "Done.\n");
  1168. + } else {
  1169. + ipkg_message(conf, IPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
  1170. +
  1171. + }
  1172. + if ( error_list ) {
  1173. + reverse_error_list(&error_list);
  1174. +
  1175. + ipkg_message(conf, IPKG_NOTICE, "Collected errors:\n");
  1176. + /* Here we print the errors collected and free the list */
  1177. + while (error_list != NULL) {
  1178. + ipkg_message(conf, IPKG_NOTICE, "%s",error_list->errmsg);
  1179. + error_list = error_list->next;
  1180. +
  1181. + }
  1182. + free_error_list(&error_list);
  1183. +
  1184. + }
  1185. +
  1186. + p_userdata = NULL;
  1187. + return result;
  1188. +}
  1189. +
  1190. +static int ipkg_update_cmd(ipkg_conf_t *conf)
  1191. +{
  1192. + int err;
  1193. + int failures;
  1194. + char *lists_dir;
  1195. + pkg_src_list_elt_t *iter;
  1196. + pkg_src_t *src;
  1197. +
  1198. +
  1199. + sprintf_alloc(&lists_dir, "%s", conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir);
  1200. +
  1201. + if (! file_is_dir(lists_dir)) {
  1202. + if (file_exists(lists_dir)) {
  1203. + ipkg_message(conf, IPKG_ERROR,
  1204. + "%s: ERROR: %s exists, but is not a directory\n",
  1205. + __FUNCTION__, lists_dir);
  1206. + free(lists_dir);
  1207. + return EINVAL;
  1208. + }
  1209. + err = file_mkdir_hier(lists_dir, 0755);
  1210. + if (err) {
  1211. + ipkg_message(conf, IPKG_ERROR,
  1212. + "%s: ERROR: failed to make directory %s: %s\n",
  1213. + __FUNCTION__, lists_dir, strerror(errno));
  1214. + free(lists_dir);
  1215. + return EINVAL;
  1216. + }
  1217. + }
  1218. +
  1219. + failures = 0;
  1220. + for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
  1221. + char *url, *list_file_name;
  1222. +
  1223. + src = iter->data;
  1224. +
  1225. + if (src->extra_data) /* debian style? */
  1226. + sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
  1227. + src->gzip ? "Packages.gz" : "Packages");
  1228. + else
  1229. + sprintf_alloc(&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
  1230. +
  1231. + sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
  1232. + if (src->gzip) {
  1233. + char *tmp;
  1234. + char *tmp_file_name;
  1235. + FILE *in, *out;
  1236. +
  1237. + tmp = strdup ("/tmp/ipkg.XXXXXX");
  1238. +
  1239. + if (mkdtemp (tmp) == NULL) {
  1240. + perror ("mkdtemp");
  1241. + failures++;
  1242. + continue;
  1243. + }
  1244. +
  1245. + sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
  1246. + err = ipkg_download(conf, url, tmp_file_name);
  1247. + if (err == 0) {
  1248. + ipkg_message (conf, IPKG_NOTICE, "Inflating %s\n", url);
  1249. + in = fopen (tmp_file_name, "r");
  1250. + out = fopen (list_file_name, "w");
  1251. + if (in && out) {
  1252. + transformer_state_t xstate;
  1253. + init_transformer_state(&xstate);
  1254. + inflate_unzip (&xstate);
  1255. + } else
  1256. + err = 1;
  1257. + if (in)
  1258. + fclose (in);
  1259. + if (out)
  1260. + fclose (out);
  1261. + unlink (tmp_file_name);
  1262. + rmdir (tmp);
  1263. + free (tmp);
  1264. + }
  1265. + } else
  1266. + err = ipkg_download(conf, url, list_file_name);
  1267. + if (err) {
  1268. + failures++;
  1269. + } else {
  1270. + ipkg_message(conf, IPKG_NOTICE,
  1271. + "Updated list of available packages in %s\n",
  1272. + list_file_name);
  1273. + }
  1274. + free(url);
  1275. + free(list_file_name);
  1276. + }
  1277. + free(lists_dir);
  1278. +
  1279. +#ifdef CONFIG_CLEAR_SW_INSTALL_FLAG
  1280. +#warning here
  1281. + /* clear SW_INSTALL on any package where state is SS_NOT_INSTALLED.
  1282. + * this is a hack to work around poor bookkeeping in old ipkg upgrade code
  1283. + * -Jamey 3/1/03
  1284. + */
  1285. + {
  1286. + int i;
  1287. + int changed = 0;
  1288. + pkg_vec_t *available = pkg_vec_alloc();
  1289. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1290. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL for SS_NOT_INSTALLED packages.\n");
  1291. + for (i = 0; i < available->len; i++) {
  1292. + pkg_t *pkg = available->pkgs[i];
  1293. + if (pkg->state_want == SW_INSTALL && pkg->state_status == SS_NOT_INSTALLED) {
  1294. + ipkg_message(conf, IPKG_DEBUG, "Clearing SW_INSTALL on package %s.\n", pkg->name);
  1295. + pkg->state_want = SW_UNKNOWN;
  1296. + changed = 1;
  1297. + }
  1298. + }
  1299. + pkg_vec_free(available);
  1300. + if (changed) {
  1301. + write_status_files_if_changed(conf);
  1302. + }
  1303. + }
  1304. +#endif
  1305. +
  1306. + return failures;
  1307. +}
  1308. +
  1309. +
  1310. +/* scan the args passed and cache the local filenames of the packages */
  1311. +int ipkg_multiple_files_scan(ipkg_conf_t *conf, int argc, char **argv)
  1312. +{
  1313. + int i;
  1314. + int err;
  1315. +
  1316. + /*
  1317. + * First scan through package names/urls
  1318. + * For any urls, download the packages and install in database.
  1319. + * For any files, install package info in database.
  1320. + */
  1321. + for (i = 0; i < argc; i ++) {
  1322. + char *filename = argv [i];
  1323. + //char *tmp = basename (tmp);
  1324. + //int tmplen = strlen (tmp);
  1325. +
  1326. + //if (strcmp (tmp + (tmplen - strlen (IPKG_PKG_EXTENSION)), IPKG_PKG_EXTENSION) != 0)
  1327. + // continue;
  1328. + //if (strcmp (tmp + (tmplen - strlen (DPKG_PKG_EXTENSION)), DPKG_PKG_EXTENSION) != 0)
  1329. + // continue;
  1330. +
  1331. + ipkg_message(conf, IPKG_DEBUG2, "Debug mfs: %s \n",filename );
  1332. +
  1333. + err = ipkg_prepare_url_for_install(conf, filename, &argv[i]);
  1334. + if (err)
  1335. + return err;
  1336. + }
  1337. + return 0;
  1338. +}
  1339. +
  1340. +struct ipkg_intercept
  1341. +{
  1342. + char *oldpath;
  1343. + char *statedir;
  1344. +};
  1345. +
  1346. +typedef struct ipkg_intercept *ipkg_intercept_t;
  1347. +ipkg_intercept_t ipkg_prep_intercepts(void);
  1348. +
  1349. +ipkg_intercept_t ipkg_prep_intercepts(void)
  1350. +{
  1351. + ipkg_intercept_t ctx;
  1352. + char *newpath;
  1353. + int gen;
  1354. +
  1355. + ctx = malloc (sizeof (*ctx));
  1356. + ctx->oldpath = strdup (getenv ("PATH"));
  1357. +
  1358. + sprintf_alloc (&newpath, "%s/ipkg/intercept:%s", IPKGLIBDIR, ctx->oldpath);
  1359. + setenv ("PATH", newpath, 1);
  1360. + free (newpath);
  1361. +
  1362. + gen = 0;
  1363. + retry:
  1364. + sprintf_alloc (&ctx->statedir, "/tmp/ipkg-intercept-%d-%d", getpid (), gen);
  1365. + if (mkdir (ctx->statedir, 0770) < 0) {
  1366. + if (errno == EEXIST) {
  1367. + free (ctx->statedir);
  1368. + gen++;
  1369. + goto retry;
  1370. + }
  1371. + perror (ctx->statedir);
  1372. + return NULL;
  1373. + }
  1374. + setenv ("IPKG_INTERCEPT_DIR", ctx->statedir, 1);
  1375. + return ctx;
  1376. +}
  1377. +
  1378. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx);
  1379. +
  1380. +int ipkg_finalize_intercepts(ipkg_intercept_t ctx)
  1381. +{
  1382. + char *cmd;
  1383. + DIR *dir;
  1384. + int err = 0;
  1385. +
  1386. + setenv ("PATH", ctx->oldpath, 1);
  1387. + free (ctx->oldpath);
  1388. +
  1389. + dir = opendir (ctx->statedir);
  1390. + if (dir) {
  1391. + struct dirent *de;
  1392. + while (de = readdir (dir), de != NULL) {
  1393. + char *path;
  1394. +
  1395. + if (de->d_name[0] == '.')
  1396. + continue;
  1397. +
  1398. + sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
  1399. + if (access (path, X_OK) == 0) {
  1400. + if (system (path)) {
  1401. + err = errno;
  1402. + perror (de->d_name);
  1403. + }
  1404. + }
  1405. + free (path);
  1406. + }
  1407. + } else
  1408. + perror (ctx->statedir);
  1409. +
  1410. + sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
  1411. + system (cmd);
  1412. + free (cmd);
  1413. +
  1414. + free (ctx->statedir);
  1415. + free (ctx);
  1416. +
  1417. + return err;
  1418. +}
  1419. +
  1420. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name)
  1421. +{
  1422. + pkg_vec_t *all;
  1423. + int i;
  1424. + pkg_t *pkg;
  1425. + ipkg_intercept_t ic;
  1426. + int r, err = 0;
  1427. +
  1428. + ipkg_message(conf, IPKG_INFO,
  1429. + "Configuring unpacked packages\n");
  1430. + fflush( stdout );
  1431. +
  1432. + all = pkg_vec_alloc();
  1433. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  1434. +
  1435. + ic = ipkg_prep_intercepts();
  1436. +
  1437. + for(i = 0; i < all->len; i++) {
  1438. + pkg = all->pkgs[i];
  1439. +
  1440. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1441. + continue;
  1442. +
  1443. + if (pkg->state_status == SS_UNPACKED) {
  1444. + ipkg_message(conf, IPKG_NOTICE,
  1445. + "Configuring %s\n", pkg->name);
  1446. + fflush( stdout );
  1447. + r = ipkg_configure(conf, pkg);
  1448. + if (r == 0) {
  1449. + pkg->state_status = SS_INSTALLED;
  1450. + pkg->parent->state_status = SS_INSTALLED;
  1451. + pkg->state_flag &= ~SF_PREFER;
  1452. + } else {
  1453. + if (!err)
  1454. + err = r;
  1455. + }
  1456. + }
  1457. + }
  1458. +
  1459. + r = ipkg_finalize_intercepts (ic);
  1460. + if (r && !err)
  1461. + err = r;
  1462. +
  1463. + pkg_vec_free(all);
  1464. + return err;
  1465. +}
  1466. +
  1467. +static void sigint_handler(int sig)
  1468. +{
  1469. + signal(sig, SIG_DFL);
  1470. + ipkg_message(NULL, IPKG_NOTICE,
  1471. + "ipkg: interrupted. writing out status database\n");
  1472. + write_status_files_if_changed(global_conf);
  1473. + exit(128 + sig);
  1474. +}
  1475. +
  1476. +static int ipkg_install_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1477. +{
  1478. + int i;
  1479. + char *arg;
  1480. + int err=0;
  1481. +
  1482. + global_conf = conf;
  1483. + signal(SIGINT, sigint_handler);
  1484. +
  1485. + /*
  1486. + * Now scan through package names and install
  1487. + */
  1488. + for (i=0; i < argc; i++) {
  1489. + arg = argv[i];
  1490. +
  1491. + ipkg_message(conf, IPKG_DEBUG2, "Debug install_cmd: %s \n",arg );
  1492. + err = ipkg_prepare_url_for_install(conf, arg, &argv[i]);
  1493. + if (err != EINVAL && err != 0)
  1494. + return err;
  1495. + }
  1496. + pkg_info_preinstall_check(conf);
  1497. +
  1498. + for (i=0; i < argc; i++) {
  1499. + arg = argv[i];
  1500. + if (conf->multiple_providers)
  1501. + err = ipkg_install_multi_by_name(conf, arg);
  1502. + else{
  1503. + err = ipkg_install_by_name(conf, arg);
  1504. + }
  1505. + if (err == IPKG_PKG_HAS_NO_CANDIDATE) {
  1506. + ipkg_message(conf, IPKG_ERROR,
  1507. + "Cannot find package %s.\n"
  1508. + "Check the spelling or perhaps run 'ipkg update'\n",
  1509. + arg);
  1510. + }
  1511. + }
  1512. +
  1513. + /* recheck to verify that all dependences are satisfied */
  1514. + if (0) ipkg_satisfy_all_dependences(conf);
  1515. +
  1516. + ipkg_configure_packages(conf, NULL);
  1517. +
  1518. + write_status_files_if_changed(conf);
  1519. +
  1520. + return err;
  1521. +}
  1522. +
  1523. +static int ipkg_upgrade_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1524. +{
  1525. + int i;
  1526. + pkg_t *pkg;
  1527. + int err;
  1528. +
  1529. + global_conf = conf;
  1530. + signal(SIGINT, sigint_handler);
  1531. +
  1532. + if (argc) {
  1533. + for (i=0; i < argc; i++) {
  1534. + char *arg = argv[i];
  1535. +
  1536. + err = ipkg_prepare_url_for_install(conf, arg, &arg);
  1537. + if (err != EINVAL && err != 0)
  1538. + return err;
  1539. + }
  1540. + pkg_info_preinstall_check(conf);
  1541. +
  1542. + for (i=0; i < argc; i++) {
  1543. + char *arg = argv[i];
  1544. + if (conf->restrict_to_default_dest) {
  1545. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1546. + argv[i],
  1547. + conf->default_dest);
  1548. + if (pkg == NULL) {
  1549. + ipkg_message(conf, IPKG_NOTICE,
  1550. + "Package %s not installed in %s\n",
  1551. + argv[i], conf->default_dest->name);
  1552. + continue;
  1553. + }
  1554. + } else {
  1555. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  1556. + argv[i]);
  1557. + }
  1558. + if (pkg)
  1559. + ipkg_upgrade_pkg(conf, pkg);
  1560. + else {
  1561. + ipkg_install_by_name(conf, arg);
  1562. + }
  1563. + }
  1564. + } else {
  1565. + pkg_vec_t *installed = pkg_vec_alloc();
  1566. +
  1567. + pkg_info_preinstall_check(conf);
  1568. +
  1569. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  1570. + for (i = 0; i < installed->len; i++) {
  1571. + pkg = installed->pkgs[i];
  1572. + ipkg_upgrade_pkg(conf, pkg);
  1573. + }
  1574. + pkg_vec_free(installed);
  1575. + }
  1576. +
  1577. + /* recheck to verify that all dependences are satisfied */
  1578. + if (0) ipkg_satisfy_all_dependences(conf);
  1579. +
  1580. + ipkg_configure_packages(conf, NULL);
  1581. +
  1582. + write_status_files_if_changed(conf);
  1583. +
  1584. + return 0;
  1585. +}
  1586. +
  1587. +static int ipkg_download_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1588. +{
  1589. + int i, err;
  1590. + char *arg;
  1591. + pkg_t *pkg;
  1592. +
  1593. + pkg_info_preinstall_check(conf);
  1594. + for (i = 0; i < argc; i++) {
  1595. + arg = argv[i];
  1596. +
  1597. + pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg);
  1598. + if (pkg == NULL) {
  1599. + ipkg_message(conf, IPKG_ERROR,
  1600. + "Cannot find package %s.\n"
  1601. + "Check the spelling or perhaps run 'ipkg update'\n",
  1602. + arg);
  1603. + continue;
  1604. + }
  1605. +
  1606. + err = ipkg_download_pkg(conf, pkg, ".");
  1607. +
  1608. + if (err) {
  1609. + ipkg_message(conf, IPKG_ERROR,
  1610. + "Failed to download %s\n", pkg->name);
  1611. + } else {
  1612. + ipkg_message(conf, IPKG_NOTICE,
  1613. + "Downloaded %s as %s\n",
  1614. + pkg->name, pkg->local_filename);
  1615. + }
  1616. + }
  1617. +
  1618. + return 0;
  1619. +}
  1620. +
  1621. +
  1622. +static int ipkg_list_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1623. +{
  1624. + int i ;
  1625. + pkg_vec_t *available;
  1626. + pkg_t *pkg;
  1627. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1628. + char *newline;
  1629. + char *pkg_name = NULL;
  1630. + char *version_str;
  1631. +
  1632. + if (argc > 0) {
  1633. + pkg_name = argv[0];
  1634. + }
  1635. + available = pkg_vec_alloc();
  1636. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1637. + for (i=0; i < available->len; i++) {
  1638. + pkg = available->pkgs[i];
  1639. + /* if we have package name or pattern and pkg does not match, then skip it */
  1640. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1641. + continue;
  1642. + if (pkg->description) {
  1643. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1644. + } else {
  1645. + desc_short[0] = '\0';
  1646. + }
  1647. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1648. + newline = strchr(desc_short, '\n');
  1649. + if (newline) {
  1650. + *newline = '\0';
  1651. + }
  1652. + if (ipkg_cb_list) {
  1653. + version_str = pkg_version_str_alloc(pkg);
  1654. + ipkg_cb_list(pkg->name,desc_short,
  1655. + version_str,
  1656. + pkg->state_status,
  1657. + p_userdata);
  1658. + free(version_str);
  1659. + }
  1660. + }
  1661. + pkg_vec_free(available);
  1662. +
  1663. + return 0;
  1664. +}
  1665. +
  1666. +
  1667. +static int ipkg_list_installed_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1668. +{
  1669. + int i ;
  1670. + pkg_vec_t *available;
  1671. + pkg_t *pkg;
  1672. + char desc_short[IPKG_LIST_DESCRIPTION_LENGTH];
  1673. + char *newline;
  1674. + char *pkg_name = NULL;
  1675. + char *version_str;
  1676. +
  1677. + if (argc > 0) {
  1678. + pkg_name = argv[0];
  1679. + }
  1680. + available = pkg_vec_alloc();
  1681. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1682. + for (i=0; i < available->len; i++) {
  1683. + pkg = available->pkgs[i];
  1684. + /* if we have package name or pattern and pkg does not match, then skip it */
  1685. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
  1686. + continue;
  1687. + if (pkg->description) {
  1688. + strncpy(desc_short, pkg->description, IPKG_LIST_DESCRIPTION_LENGTH);
  1689. + } else {
  1690. + desc_short[0] = '\0';
  1691. + }
  1692. + desc_short[IPKG_LIST_DESCRIPTION_LENGTH - 1] = '\0';
  1693. + newline = strchr(desc_short, '\n');
  1694. + if (newline) {
  1695. + *newline = '\0';
  1696. + }
  1697. + if (ipkg_cb_list) {
  1698. + version_str = pkg_version_str_alloc(pkg);
  1699. + ipkg_cb_list(pkg->name,desc_short,
  1700. + version_str,
  1701. + pkg->state_status,
  1702. + p_userdata);
  1703. + free(version_str);
  1704. + }
  1705. + }
  1706. +
  1707. + return 0;
  1708. +}
  1709. +
  1710. +static int ipkg_info_status_cmd(ipkg_conf_t *conf, int argc, char **argv, int installed_only)
  1711. +{
  1712. + int i;
  1713. + pkg_vec_t *available;
  1714. + pkg_t *pkg;
  1715. + char *pkg_name = NULL;
  1716. + char **pkg_fields = NULL;
  1717. + int n_fields = 0;
  1718. + char *buff ; // = (char *)malloc(1);
  1719. +
  1720. + if (argc > 0) {
  1721. + pkg_name = argv[0];
  1722. + }
  1723. + if (argc > 1) {
  1724. + pkg_fields = &argv[1];
  1725. + n_fields = argc - 1;
  1726. + }
  1727. +
  1728. + available = pkg_vec_alloc();
  1729. + if (installed_only)
  1730. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1731. + else
  1732. + pkg_hash_fetch_available(&conf->pkg_hash, available);
  1733. + for (i=0; i < available->len; i++) {
  1734. + pkg = available->pkgs[i];
  1735. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1736. + continue;
  1737. + }
  1738. + buff = pkg_formatted_info(pkg);
  1739. + if ( buff ) {
  1740. + if (ipkg_cb_status) ipkg_cb_status(pkg->name,
  1741. + pkg->state_status,
  1742. + buff,
  1743. + p_userdata);
  1744. + free(buff);
  1745. + }
  1746. + if (conf->verbosity > 1) {
  1747. + conffile_list_elt_t *iter;
  1748. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  1749. + conffile_t *cf = iter->data;
  1750. + int modified = conffile_has_been_modified(conf, cf);
  1751. + ipkg_message(conf, IPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
  1752. + cf->name, cf->value, modified);
  1753. + }
  1754. + }
  1755. + }
  1756. + pkg_vec_free(available);
  1757. +
  1758. + return 0;
  1759. +}
  1760. +
  1761. +static int ipkg_info_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1762. +{
  1763. + return ipkg_info_status_cmd(conf, argc, argv, 0);
  1764. +}
  1765. +
  1766. +static int ipkg_status_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1767. +{
  1768. + return ipkg_info_status_cmd(conf, argc, argv, 1);
  1769. +}
  1770. +
  1771. +static int ipkg_configure_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1772. +{
  1773. +
  1774. + int err;
  1775. + if (argc > 0) {
  1776. + char *pkg_name = NULL;
  1777. +
  1778. + pkg_name = argv[0];
  1779. +
  1780. + err = ipkg_configure_packages (conf, pkg_name);
  1781. +
  1782. + } else {
  1783. + err = ipkg_configure_packages (conf, NULL);
  1784. + }
  1785. +
  1786. + write_status_files_if_changed(conf);
  1787. +
  1788. + return err;
  1789. +}
  1790. +
  1791. +static int ipkg_install_pending_cmd(ipkg_conf_t *conf)
  1792. +{
  1793. + int i, err;
  1794. + char *globpattern;
  1795. + glob_t globbuf;
  1796. +
  1797. + sprintf_alloc(&globpattern, "%s/*" IPKG_PKG_EXTENSION, conf->pending_dir);
  1798. + err = glob(globpattern, 0, NULL, &globbuf);
  1799. + free(globpattern);
  1800. + if (err) {
  1801. + return 0;
  1802. + }
  1803. +
  1804. + ipkg_message(conf, IPKG_NOTICE,
  1805. + "The following packages in %s will now be installed.\n",
  1806. + conf->pending_dir);
  1807. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1808. + ipkg_message(conf, IPKG_NOTICE,
  1809. + "%s%s", i == 0 ? "" : " ", globbuf.gl_pathv[i]);
  1810. + }
  1811. + ipkg_message(conf, IPKG_NOTICE, "\n");
  1812. + for (i = 0; i < globbuf.gl_pathc; i++) {
  1813. + err = ipkg_install_from_file(conf, globbuf.gl_pathv[i]);
  1814. + if (err == 0) {
  1815. + err = unlink(globbuf.gl_pathv[i]);
  1816. + if (err) {
  1817. + ipkg_message(conf, IPKG_ERROR,
  1818. + "%s: ERROR: failed to unlink %s: %s\n",
  1819. + __FUNCTION__, globbuf.gl_pathv[i], strerror(err));
  1820. + return err;
  1821. + }
  1822. + }
  1823. + }
  1824. + globfree(&globbuf);
  1825. +
  1826. + return err;
  1827. +}
  1828. +
  1829. +static int ipkg_remove_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1830. +{
  1831. + int i,a,done;
  1832. + pkg_t *pkg;
  1833. + pkg_t *pkg_to_remove;
  1834. + pkg_vec_t *available;
  1835. + char *pkg_name = NULL;
  1836. + global_conf = conf;
  1837. + signal(SIGINT, sigint_handler);
  1838. +
  1839. +// ENH: Add the "no pkg removed" just in case.
  1840. +
  1841. + done = 0;
  1842. +
  1843. + available = pkg_vec_alloc();
  1844. + pkg_info_preinstall_check(conf);
  1845. + if ( argc > 0 ) {
  1846. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
  1847. + for (i=0; i < argc; i++) {
  1848. + pkg_name = malloc(strlen(argv[i])+2);
  1849. + strcpy(pkg_name,argv[i]);
  1850. + for (a=0; a < available->len; a++) {
  1851. + pkg = available->pkgs[a];
  1852. + if (pkg_name && fnmatch(pkg_name, pkg->name, 0)) {
  1853. + continue;
  1854. + }
  1855. + if (conf->restrict_to_default_dest) {
  1856. + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1857. + pkg->name,
  1858. + conf->default_dest);
  1859. + } else {
  1860. + pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name );
  1861. + }
  1862. +
  1863. + if (pkg == NULL) {
  1864. + ipkg_message(conf, IPKG_ERROR, "Package %s is not installed.\n", pkg->name);
  1865. + continue;
  1866. + }
  1867. + if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped
  1868. + ipkg_message(conf, IPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name);
  1869. + continue;
  1870. + }
  1871. + ipkg_remove_pkg(conf, pkg_to_remove,0);
  1872. + done = 1;
  1873. + }
  1874. + free (pkg_name);
  1875. + }
  1876. + pkg_vec_free(available);
  1877. + } else {
  1878. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  1879. + int flagged_pkg_count = 0;
  1880. + int removed;
  1881. +
  1882. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed_pkgs);
  1883. +
  1884. + for (i = 0; i < installed_pkgs->len; i++) {
  1885. + pkg = installed_pkgs->pkgs[i];
  1886. + if (pkg->state_flag & SF_USER) {
  1887. + flagged_pkg_count++;
  1888. + } else {
  1889. + if (!pkg_has_installed_dependents(pkg, NULL))
  1890. + ipkg_message(conf, IPKG_NOTICE, "Non-user leaf package: %s\n", pkg->name);
  1891. + }
  1892. + }
  1893. + if (!flagged_pkg_count) {
  1894. + ipkg_message(conf, IPKG_NOTICE, "No packages flagged as installed by user, \n"
  1895. + "so refusing to uninstall unflagged non-leaf packages\n");
  1896. + return 0;
  1897. + }
  1898. +
  1899. + /* find packages not flagged SF_USER (i.e., installed to
  1900. + * satisfy a dependence) and not having any dependents, and
  1901. + * remove them */
  1902. + do {
  1903. + removed = 0;
  1904. + for (i = 0; i < installed_pkgs->len; i++) {
  1905. + pkg = installed_pkgs->pkgs[i];
  1906. + if (!(pkg->state_flag & SF_USER)
  1907. + && !pkg_has_installed_dependents(pkg, NULL)) {
  1908. + removed++;
  1909. + ipkg_message(conf, IPKG_NOTICE, "Removing non-user leaf package %s\n");
  1910. + ipkg_remove_pkg(conf, pkg,0);
  1911. + done = 1;
  1912. + }
  1913. + }
  1914. + } while (removed);
  1915. + pkg_vec_free(installed_pkgs);
  1916. + }
  1917. +
  1918. + if ( done == 0 )
  1919. + ipkg_message(conf, IPKG_NOTICE, "No packages removed.\n");
  1920. +
  1921. + write_status_files_if_changed(conf);
  1922. + return 0;
  1923. +}
  1924. +
  1925. +static int ipkg_purge_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1926. +{
  1927. + int i;
  1928. + pkg_t *pkg;
  1929. +
  1930. + global_conf = conf;
  1931. + signal(SIGINT, sigint_handler);
  1932. +
  1933. + pkg_info_preinstall_check(conf);
  1934. +
  1935. + for (i=0; i < argc; i++) {
  1936. + if (conf->restrict_to_default_dest) {
  1937. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1938. + argv[i],
  1939. + conf->default_dest);
  1940. + } else {
  1941. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1942. + }
  1943. +
  1944. + if (pkg == NULL) {
  1945. + ipkg_message(conf, IPKG_ERROR,
  1946. + "Package %s is not installed.\n", argv[i]);
  1947. + continue;
  1948. + }
  1949. + ipkg_purge_pkg(conf, pkg);
  1950. + }
  1951. +
  1952. + write_status_files_if_changed(conf);
  1953. + return 0;
  1954. +}
  1955. +
  1956. +static int ipkg_flag_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1957. +{
  1958. + int i;
  1959. + pkg_t *pkg;
  1960. + char *flags = argv[0];
  1961. +
  1962. + global_conf = conf;
  1963. + signal(SIGINT, sigint_handler);
  1964. +
  1965. + for (i=1; i < argc; i++) {
  1966. + if (conf->restrict_to_default_dest) {
  1967. + pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash,
  1968. + argv[i],
  1969. + conf->default_dest);
  1970. + } else {
  1971. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]);
  1972. + }
  1973. +
  1974. + if (pkg == NULL) {
  1975. + ipkg_message(conf, IPKG_ERROR,
  1976. + "Package %s is not installed.\n", argv[i]);
  1977. + continue;
  1978. + }
  1979. + if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)||
  1980. + ( strcmp(flags,"user")==0)||( strcmp(flags,"ok")==0)) {
  1981. + pkg->state_flag = pkg_state_flag_from_str(flags);
  1982. + }
  1983. +/* pb_ asked this feature 03292004 */
  1984. +/* Actually I will use only this two, but this is an open for various status */
  1985. + if (( strcmp(flags,"installed")==0)||( strcmp(flags,"unpacked")==0)){
  1986. + pkg->state_status = pkg_state_status_from_str(flags);
  1987. + }
  1988. + ipkg_state_changed++;
  1989. + ipkg_message(conf, IPKG_NOTICE,
  1990. + "Setting flags for package %s to %s\n",
  1991. + pkg->name, flags);
  1992. + }
  1993. +
  1994. + write_status_files_if_changed(conf);
  1995. + return 0;
  1996. +}
  1997. +
  1998. +static int ipkg_files_cmd(ipkg_conf_t *conf, int argc, char **argv)
  1999. +{
  2000. + pkg_t *pkg;
  2001. + str_list_t *installed_files;
  2002. + str_list_elt_t *iter;
  2003. + char *pkg_version;
  2004. + size_t buff_len = 8192;
  2005. + size_t used_len;
  2006. + char *buff ;
  2007. +
  2008. + buff = (char *)malloc(buff_len);
  2009. + if ( buff == NULL ) {
  2010. + fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__);
  2011. + return ENOMEM;
  2012. + }
  2013. +
  2014. + if (argc < 1) {
  2015. + return EINVAL;
  2016. + }
  2017. +
  2018. + pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash,
  2019. + argv[0]);
  2020. + if (pkg == NULL) {
  2021. + ipkg_message(conf, IPKG_ERROR,
  2022. + "Package %s not installed.\n", argv[0]);
  2023. + return 0;
  2024. + }
  2025. +
  2026. + installed_files = pkg_get_installed_files(pkg);
  2027. + pkg_version = pkg_version_str_alloc(pkg);
  2028. +
  2029. + printf("Package %s (%s) is installed on %s and has the following files:\n",
  2030. + pkg->name, pkg_version, pkg->dest->name);
  2031. + for (iter = installed_files->head; iter; iter = iter->next) {
  2032. + puts(iter->data);
  2033. + }
  2034. +
  2035. + free(pkg_version);
  2036. + pkg_free_installed_files(pkg);
  2037. +
  2038. + return 0;
  2039. +}
  2040. +
  2041. +static int ipkg_depends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2042. +{
  2043. +
  2044. + if (argc > 0) {
  2045. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2046. + const char *rel_str = "depends on";
  2047. + int i;
  2048. +
  2049. + pkg_info_preinstall_check(conf);
  2050. +
  2051. + if (conf->query_all)
  2052. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2053. + else
  2054. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2055. + for (i = 0; i < argc; i++) {
  2056. + const char *target = argv[i];
  2057. + int j;
  2058. +
  2059. + ipkg_message(conf, IPKG_ERROR, "target=%s\n", target);
  2060. +
  2061. + for (j = 0; j < available_pkgs->len; j++) {
  2062. + pkg_t *pkg = available_pkgs->pkgs[j];
  2063. + if (fnmatch(target, pkg->name, 0) == 0) {
  2064. + int k;
  2065. + int count = pkg->depends_count + pkg->pre_depends_count;
  2066. + ipkg_message(conf, IPKG_ERROR, "What %s (arch=%s) %s\n",
  2067. + target, pkg->architecture, rel_str);
  2068. + for (k = 0; k < count; k++) {
  2069. + compound_depend_t *cdepend = &pkg->depends[k];
  2070. + int l;
  2071. + for (l = 0; l < cdepend->possibility_count; l++) {
  2072. + depend_t *possibility = cdepend->possibilities[l];
  2073. + ipkg_message(conf, IPKG_ERROR, " %s", possibility->pkg->name);
  2074. + if (conf->verbosity > 0) {
  2075. + // char *ver = abstract_pkg_version_str_alloc(possibility->pkg);
  2076. + ipkg_message(conf, IPKG_NOTICE, " %s", possibility->version);
  2077. + if (possibility->version) {
  2078. + const char *typestr = NULL;
  2079. + switch (possibility->constraint) {
  2080. + case NONE: typestr = "none"; break;
  2081. + case EARLIER: typestr = "<"; break;
  2082. + case EARLIER_EQUAL: typestr = "<="; break;
  2083. + case EQUAL: typestr = "="; break;
  2084. + case LATER_EQUAL: typestr = ">="; break;
  2085. + case LATER: typestr = ">"; break;
  2086. + }
  2087. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2088. + }
  2089. + // free(ver);
  2090. + }
  2091. + ipkg_message(conf, IPKG_ERROR, "\n");
  2092. + }
  2093. + }
  2094. + }
  2095. + }
  2096. + }
  2097. + pkg_vec_free(available_pkgs);
  2098. + }
  2099. + return 0;
  2100. +}
  2101. +
  2102. +enum what_field_type {
  2103. + WHATDEPENDS,
  2104. + WHATCONFLICTS,
  2105. + WHATPROVIDES,
  2106. + WHATREPLACES,
  2107. + WHATRECOMMENDS,
  2108. + WHATSUGGESTS
  2109. +};
  2110. +
  2111. +static int ipkg_what_depends_conflicts_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int recursive, int argc, char **argv)
  2112. +{
  2113. +
  2114. + if (argc > 0) {
  2115. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2116. + const char *rel_str = NULL;
  2117. + int i;
  2118. + int changed;
  2119. +
  2120. + switch (what_field_type) {
  2121. + case WHATDEPENDS: rel_str = "depends on"; break;
  2122. + case WHATCONFLICTS: rel_str = "conflicts with"; break;
  2123. + case WHATSUGGESTS: rel_str = "suggests"; break;
  2124. + case WHATRECOMMENDS: rel_str = "recommends"; break;
  2125. + case WHATPROVIDES: rel_str = "provides"; break;
  2126. + case WHATREPLACES: rel_str = "replaces"; break;
  2127. + }
  2128. +
  2129. + if (conf->query_all)
  2130. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2131. + else
  2132. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2133. +
  2134. + /* mark the root set */
  2135. + pkg_vec_clear_marks(available_pkgs);
  2136. + ipkg_message(conf, IPKG_NOTICE, "Root set:\n");
  2137. + for (i = 0; i < argc; i++) {
  2138. + const char *dependee_pattern = argv[i];
  2139. + pkg_vec_mark_if_matches(available_pkgs, dependee_pattern);
  2140. + }
  2141. + for (i = 0; i < available_pkgs->len; i++) {
  2142. + pkg_t *pkg = available_pkgs->pkgs[i];
  2143. + if (pkg->state_flag & SF_MARKED) {
  2144. + /* mark the parent (abstract) package */
  2145. + pkg_mark_provides(pkg);
  2146. + ipkg_message(conf, IPKG_NOTICE, " %s\n", pkg->name);
  2147. + }
  2148. + }
  2149. +
  2150. + ipkg_message(conf, IPKG_NOTICE, "What %s root set\n", rel_str);
  2151. + do {
  2152. + int j;
  2153. + changed = 0;
  2154. +
  2155. + for (j = 0; j < available_pkgs->len; j++) {
  2156. + pkg_t *pkg = available_pkgs->pkgs[j];
  2157. + int k;
  2158. + int count = ((what_field_type == WHATCONFLICTS)
  2159. + ? pkg->conflicts_count
  2160. + : pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count);
  2161. + /* skip this package if it is already marked */
  2162. + if (pkg->parent->state_flag & SF_MARKED) {
  2163. + continue;
  2164. + }
  2165. + for (k = 0; k < count; k++) {
  2166. + compound_depend_t *cdepend =
  2167. + (what_field_type == WHATCONFLICTS) ? &pkg->conflicts[k] : &pkg->depends[k];
  2168. + int l;
  2169. + for (l = 0; l < cdepend->possibility_count; l++) {
  2170. + depend_t *possibility = cdepend->possibilities[l];
  2171. + if (possibility->pkg->state_flag & SF_MARKED) {
  2172. + /* mark the depending package so we won't visit it again */
  2173. + pkg->state_flag |= SF_MARKED;
  2174. + pkg_mark_provides(pkg);
  2175. + changed++;
  2176. +
  2177. + ipkg_message(conf, IPKG_NOTICE, " %s", pkg->name);
  2178. + if (conf->verbosity > 0) {
  2179. + char *ver = pkg_version_str_alloc(pkg);
  2180. + ipkg_message(conf, IPKG_NOTICE, " %s", ver);
  2181. + ipkg_message(conf, IPKG_NOTICE, "\t%s %s", rel_str, possibility->pkg->name);
  2182. + if (possibility->version) {
  2183. + const char *typestr = NULL;
  2184. + switch (possibility->constraint) {
  2185. + case NONE: typestr = "none"; break;
  2186. + case EARLIER: typestr = "<"; break;
  2187. + case EARLIER_EQUAL: typestr = "<="; break;
  2188. + case EQUAL: typestr = "="; break;
  2189. + case LATER_EQUAL: typestr = ">="; break;
  2190. + case LATER: typestr = ">"; break;
  2191. + }
  2192. + ipkg_message(conf, IPKG_NOTICE, " (%s %s)", typestr, possibility->version);
  2193. + }
  2194. + free(ver);
  2195. + if (!pkg_dependence_satisfiable(possibility))
  2196. + ipkg_message(conf, IPKG_NOTICE, " unsatisfiable");
  2197. + }
  2198. + ipkg_message(conf, IPKG_NOTICE, "\n");
  2199. + goto next_package;
  2200. + }
  2201. + }
  2202. + }
  2203. + next_package:
  2204. + ;
  2205. + }
  2206. + } while (changed && recursive);
  2207. + pkg_vec_free(available_pkgs);
  2208. + }
  2209. +
  2210. + return 0;
  2211. +}
  2212. +
  2213. +int pkg_mark_provides(pkg_t *pkg)
  2214. +{
  2215. + int provides_count = pkg->provides_count;
  2216. + abstract_pkg_t **provides = pkg->provides;
  2217. + int i;
  2218. + pkg->parent->state_flag |= SF_MARKED;
  2219. + for (i = 0; i < provides_count; i++) {
  2220. + provides[i]->state_flag |= SF_MARKED;
  2221. + }
  2222. + return 0;
  2223. +}
  2224. +
  2225. +static int ipkg_whatdepends_recursively_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2226. +{
  2227. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 1, argc, argv);
  2228. +}
  2229. +static int ipkg_whatdepends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2230. +{
  2231. + return ipkg_what_depends_conflicts_cmd(conf, WHATDEPENDS, 0, argc, argv);
  2232. +}
  2233. +
  2234. +static int ipkg_whatsuggests_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2235. +{
  2236. + return ipkg_what_depends_conflicts_cmd(conf, WHATSUGGESTS, 0, argc, argv);
  2237. +}
  2238. +
  2239. +static int ipkg_whatrecommends_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2240. +{
  2241. + return ipkg_what_depends_conflicts_cmd(conf, WHATRECOMMENDS, 0, argc, argv);
  2242. +}
  2243. +
  2244. +static int ipkg_whatconflicts_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2245. +{
  2246. + return ipkg_what_depends_conflicts_cmd(conf, WHATCONFLICTS, 0, argc, argv);
  2247. +}
  2248. +
  2249. +static int ipkg_what_provides_replaces_cmd(ipkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv)
  2250. +{
  2251. +
  2252. + if (argc > 0) {
  2253. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  2254. + const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces");
  2255. + int i;
  2256. +
  2257. + pkg_info_preinstall_check(conf);
  2258. +
  2259. + if (conf->query_all)
  2260. + pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs);
  2261. + else
  2262. + pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs);
  2263. + for (i = 0; i < argc; i++) {
  2264. + const char *target = argv[i];
  2265. + int j;
  2266. +
  2267. + ipkg_message(conf, IPKG_ERROR, "What %s %s\n",
  2268. + rel_str, target);
  2269. + for (j = 0; j < available_pkgs->len; j++) {
  2270. + pkg_t *pkg = available_pkgs->pkgs[j];
  2271. + int k;
  2272. + int count = (what_field_type == WHATPROVIDES) ? pkg->provides_count : pkg->replaces_count;
  2273. + for (k = 0; k < count; k++) {
  2274. + abstract_pkg_t *apkg =
  2275. + ((what_field_type == WHATPROVIDES)
  2276. + ? pkg->provides[k]
  2277. + : pkg->replaces[k]);
  2278. + if (fnmatch(target, apkg->name, 0) == 0) {
  2279. + ipkg_message(conf, IPKG_ERROR, " %s", pkg->name);
  2280. + if (strcmp(target, apkg->name) != 0)
  2281. + ipkg_message(conf, IPKG_ERROR, "\t%s %s\n", rel_str, apkg->name);
  2282. + ipkg_message(conf, IPKG_ERROR, "\n");
  2283. + }
  2284. + }
  2285. + }
  2286. + }
  2287. + pkg_vec_free(available_pkgs);
  2288. + }
  2289. + return 0;
  2290. +}
  2291. +
  2292. +static int ipkg_whatprovides_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2293. +{
  2294. + return ipkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv);
  2295. +}
  2296. +
  2297. +static int ipkg_whatreplaces_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2298. +{
  2299. + return ipkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv);
  2300. +}
  2301. +
  2302. +static int ipkg_search_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2303. +{
  2304. + int i;
  2305. +
  2306. + pkg_vec_t *installed;
  2307. + pkg_t *pkg;
  2308. + str_list_t *installed_files;
  2309. + str_list_elt_t *iter;
  2310. + char *installed_file;
  2311. +
  2312. + if (argc < 1) {
  2313. + return EINVAL;
  2314. + }
  2315. +
  2316. + installed = pkg_vec_alloc();
  2317. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  2318. +
  2319. + for (i=0; i < installed->len; i++) {
  2320. + pkg = installed->pkgs[i];
  2321. +
  2322. + installed_files = pkg_get_installed_files(pkg);
  2323. +
  2324. + for (iter = installed_files->head; iter; iter = iter->next) {
  2325. + installed_file = iter->data;
  2326. + if (fnmatch(argv[0], installed_file, 0)==0) {
  2327. + if (ipkg_cb_list) ipkg_cb_list(pkg->name,
  2328. + installed_file,
  2329. + pkg_version_str_alloc(pkg),
  2330. + pkg->state_status, p_userdata);
  2331. + }
  2332. + }
  2333. +
  2334. + pkg_free_installed_files(pkg);
  2335. + }
  2336. +
  2337. + /* XXX: CLEANUP: It's not obvious from the name of
  2338. + pkg_hash_fetch_all_installed that we need to call
  2339. + pkg_vec_free to avoid a memory leak. */
  2340. + pkg_vec_free(installed);
  2341. +
  2342. + return 0;
  2343. +}
  2344. +
  2345. +static int ipkg_compare_versions_cmd(ipkg_conf_t *conf, int argc, char **argv)
  2346. +{
  2347. + if (argc == 3) {
  2348. + /* this is a bit gross */
  2349. + struct pkg p1, p2;
  2350. + parseVersion(&p1, argv[0]);
  2351. + parseVersion(&p2, argv[2]);
  2352. + return pkg_version_satisfied(&p1, &p2, argv[1]);
  2353. + } else {
  2354. + ipkg_message(conf, IPKG_ERROR,
  2355. + "ipkg compare_versions <v1> <op> <v2>\n"
  2356. + "<op> is one of <= >= << >> =\n");
  2357. + return -1;
  2358. + }
  2359. +}
  2360. +
  2361. +#ifndef HOST_CPU_STR
  2362. +#define HOST_CPU_STR__(X) #X
  2363. +#define HOST_CPU_STR_(X) HOST_CPU_STR__(X)
  2364. +#define HOST_CPU_STR HOST_CPU_STR_(HOST_CPU_FOO)
  2365. +#endif
  2366. +
  2367. +static int ipkg_print_architecture_cmd(ipkg_conf_t *conf)
  2368. +{
  2369. + nv_pair_list_elt_t *l;
  2370. +
  2371. + l = conf->arch_list.head;
  2372. + while (l) {
  2373. + nv_pair_t *nv = l->data;
  2374. + printf("arch %s %s\n", nv->name, nv->value);
  2375. + l = l->next;
  2376. + }
  2377. + return 0;
  2378. +}
  2379. +
  2380. +
  2381. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_cmd.h busybox-1.24.1/archival/libipkg/ipkg_cmd.h
  2382. --- busybox-1.24.1.orig/archival/libipkg/ipkg_cmd.h 1970-01-01 01:00:00.000000000 +0100
  2383. +++ busybox-1.24.1/archival/libipkg/ipkg_cmd.h 2015-10-31 19:00:22.000000000 +0100
  2384. @@ -0,0 +1,41 @@
  2385. +/* ipkg_cmd.h - the itsy package management system
  2386. +
  2387. + Carl D. Worth
  2388. +
  2389. + Copyright (C) 2001 University of Southern California
  2390. +
  2391. + This program is free software; you can redistribute it and/or
  2392. + modify it under the terms of the GNU General Public License as
  2393. + published by the Free Software Foundation; either version 2, or (at
  2394. + your option) any later version.
  2395. +
  2396. + This program is distributed in the hope that it will be useful, but
  2397. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2398. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2399. + General Public License for more details.
  2400. +*/
  2401. +
  2402. +#ifndef IPKG_CMD_H
  2403. +#define IPKG_CMD_H
  2404. +
  2405. +typedef int (*ipkg_cmd_fun_t)(ipkg_conf_t *conf, int argc, const char **argv);
  2406. +
  2407. +struct ipkg_cmd
  2408. +{
  2409. + const char *name;
  2410. + int requires_args;
  2411. + ipkg_cmd_fun_t fun;
  2412. +};
  2413. +typedef struct ipkg_cmd ipkg_cmd_t;
  2414. +
  2415. +ipkg_cmd_t *ipkg_cmd_find(const char *name);
  2416. +int ipkg_cmd_exec(ipkg_cmd_t *cmd, ipkg_conf_t *conf, int argc,
  2417. + const char **argv, void *userdata);
  2418. +int ipkg_multiple_files_scan (ipkg_conf_t *conf, int argc, char *argv[]);
  2419. +/* install any packges with state_want == SW_INSTALL */
  2420. +int ipkg_install_wanted_packages(ipkg_conf_t *conf);
  2421. +/* ensure that all dependences are satisfied */
  2422. +int ipkg_configure_packages(ipkg_conf_t *conf, char *pkg_name);
  2423. +int pkg_mark_provides(pkg_t *pkg);
  2424. +
  2425. +#endif
  2426. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_conf.c busybox-1.24.1/archival/libipkg/ipkg_conf.c
  2427. --- busybox-1.24.1.orig/archival/libipkg/ipkg_conf.c 1970-01-01 01:00:00.000000000 +0100
  2428. +++ busybox-1.24.1/archival/libipkg/ipkg_conf.c 2015-10-31 19:00:22.000000000 +0100
  2429. @@ -0,0 +1,739 @@
  2430. +/* ipkg_conf.c - the itsy package management system
  2431. +
  2432. + Carl D. Worth
  2433. +
  2434. + Copyright (C) 2001 University of Southern California
  2435. +
  2436. + This program is free software; you can redistribute it and/or
  2437. + modify it under the terms of the GNU General Public License as
  2438. + published by the Free Software Foundation; either version 2, or (at
  2439. + your option) any later version.
  2440. +
  2441. + This program is distributed in the hope that it will be useful, but
  2442. + WITHOUT ANY WARRANTY; without even the implied warranty of
  2443. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2444. + General Public License for more details.
  2445. +*/
  2446. +
  2447. +#include <glob.h>
  2448. +
  2449. +#include "ipkg.h"
  2450. +#include "ipkg_conf.h"
  2451. +
  2452. +#include "xregex.h"
  2453. +#include "sprintf_alloc.h"
  2454. +#include "ipkg_conf.h"
  2455. +#include "ipkg_message.h"
  2456. +#include "file_util.h"
  2457. +#include "str_util.h"
  2458. +#include "xsystem.h"
  2459. +
  2460. +
  2461. +ipkg_conf_t *global_conf;
  2462. +
  2463. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2464. + pkg_src_list_t *pkg_src_list,
  2465. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2466. + char **tmp_lists_dir);
  2467. +static int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options);
  2468. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  2469. + const char *name, const char *value);
  2470. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2471. + const char *default_dest_name);
  2472. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf,
  2473. + pkg_src_list_t *nv_pair_list);
  2474. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf,
  2475. + nv_pair_list_t *nv_pair_list, char * lists_dir);
  2476. +
  2477. +int ipkg_init_options_array(const ipkg_conf_t *conf, ipkg_option_t **options)
  2478. +{
  2479. + ipkg_option_t tmp[] = {
  2480. + { "force_defaults", IPKG_OPT_TYPE_BOOL, &conf->force_defaults },
  2481. + { "force_depends", IPKG_OPT_TYPE_BOOL, &conf->force_depends },
  2482. + { "force_overwrite", IPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
  2483. + { "force_downgrade", IPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
  2484. + { "force_reinstall", IPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
  2485. + { "force_space", IPKG_OPT_TYPE_BOOL, &conf->force_space },
  2486. + { "ftp_proxy", IPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
  2487. + { "http_proxy", IPKG_OPT_TYPE_STRING, &conf->http_proxy },
  2488. + { "multiple_providers", IPKG_OPT_TYPE_BOOL, &conf->multiple_providers },
  2489. + { "no_proxy", IPKG_OPT_TYPE_STRING, &conf->no_proxy },
  2490. + { "test", IPKG_OPT_TYPE_INT, &conf->noaction },
  2491. + { "noaction", IPKG_OPT_TYPE_INT, &conf->noaction },
  2492. + { "nodeps", IPKG_OPT_TYPE_BOOL, &conf->nodeps },
  2493. + { "offline_root", IPKG_OPT_TYPE_STRING, &conf->offline_root },
  2494. + { "offline_root_post_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
  2495. + { "offline_root_pre_script_cmd", IPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
  2496. + { "proxy_passwd", IPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
  2497. + { "proxy_user", IPKG_OPT_TYPE_STRING, &conf->proxy_user },
  2498. + { "query-all", IPKG_OPT_TYPE_BOOL, &conf->query_all },
  2499. + { "verbose-wget", IPKG_OPT_TYPE_BOOL, &conf->verbose_wget },
  2500. + { "verbosity", IPKG_OPT_TYPE_BOOL, &conf->verbosity },
  2501. + { NULL }
  2502. + };
  2503. +
  2504. + *options = (ipkg_option_t *)malloc(sizeof(tmp));
  2505. + if ( options == NULL ){
  2506. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  2507. + return -1;
  2508. + }
  2509. +
  2510. + memcpy(*options, tmp, sizeof(tmp));
  2511. + return 0;
  2512. +};
  2513. +
  2514. +static void ipkg_conf_override_string(char **conf_str, char *arg_str)
  2515. +{
  2516. + if (arg_str) {
  2517. + if (*conf_str) {
  2518. + free(*conf_str);
  2519. + }
  2520. + *conf_str = strdup(arg_str);
  2521. + }
  2522. +}
  2523. +
  2524. +static void ipkg_conf_free_string(char **conf_str)
  2525. +{
  2526. + if (*conf_str) {
  2527. + free(*conf_str);
  2528. + *conf_str = NULL;
  2529. + }
  2530. +}
  2531. +
  2532. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args)
  2533. +{
  2534. + int err;
  2535. + int remountroot;
  2536. + struct mntent *mnt;
  2537. + FILE *f;
  2538. + char *tmp_dir_base;
  2539. + nv_pair_list_t tmp_dest_nv_pair_list;
  2540. + char * lists_dir =NULL;
  2541. + glob_t globbuf;
  2542. + const char *etc_ipkg_conf_pattern = "/etc/ipkg/*.conf";
  2543. + char *pending_dir =NULL;
  2544. +
  2545. + memset(conf, 0, sizeof(ipkg_conf_t));
  2546. +
  2547. + pkg_src_list_init(&conf->pkg_src_list);
  2548. +
  2549. + nv_pair_list_init(&tmp_dest_nv_pair_list);
  2550. + pkg_dest_list_init(&conf->pkg_dest_list);
  2551. +
  2552. + nv_pair_list_init(&conf->arch_list);
  2553. +
  2554. + conf->restrict_to_default_dest = 0;
  2555. + conf->default_dest = NULL;
  2556. +
  2557. +
  2558. + if (args->tmp_dir)
  2559. + tmp_dir_base = args->tmp_dir;
  2560. + else
  2561. + tmp_dir_base = getenv("IPKGTMPDIR");
  2562. + sprintf_alloc(&conf->tmp_dir, "%s/%s",
  2563. + tmp_dir_base ? tmp_dir_base : IPKG_CONF_DEFAULT_TMP_DIR_BASE,
  2564. + IPKG_CONF_TMP_DIR_SUFFIX);
  2565. +
  2566. + remountroot = 0;
  2567. + /* check if /dev/root is mounted read-only */
  2568. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  2569. + fprintf (stderr, "Checking /proc/mounts failed\n");
  2570. + while ((mnt = getmntent(f)) != NULL) {
  2571. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  2572. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  2573. + remountroot = 1;
  2574. + }
  2575. + }
  2576. + endmntent(f);
  2577. +
  2578. + if (remountroot) {
  2579. + /* mount rootfs read-write */
  2580. + if (mount("","/",0,MS_REMOUNT,0)<0)
  2581. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  2582. + }
  2583. + mkdir(tmp_dir_base, S_IRWXU);
  2584. + conf->tmp_dir = mkdtemp(conf->tmp_dir);
  2585. + if (conf->tmp_dir == NULL) {
  2586. + fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
  2587. + __FUNCTION__, conf->tmp_dir, strerror(errno));
  2588. + return errno;
  2589. + }
  2590. + if (remountroot) {
  2591. + sync();
  2592. + /* mount rootfs read-only */
  2593. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  2594. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  2595. + }
  2596. +
  2597. + conf->force_depends = 0;
  2598. + conf->force_defaults = 0;
  2599. + conf->force_overwrite = 0;
  2600. + conf->force_downgrade = 0;
  2601. + conf->force_reinstall = 0;
  2602. + conf->force_space = 0;
  2603. + conf->force_removal_of_essential_packages = 0;
  2604. + conf->force_removal_of_dependent_packages = 0;
  2605. + conf->nodeps = 0;
  2606. + conf->verbose_wget = 0;
  2607. + conf->offline_root = NULL;
  2608. + conf->offline_root_pre_script_cmd = NULL;
  2609. + conf->offline_root_post_script_cmd = NULL;
  2610. + conf->multiple_providers = 0;
  2611. + conf->verbosity = 1;
  2612. + conf->noaction = 0;
  2613. +
  2614. + conf->http_proxy = NULL;
  2615. + conf->ftp_proxy = NULL;
  2616. + conf->no_proxy = NULL;
  2617. + conf->proxy_user = NULL;
  2618. + conf->proxy_passwd = NULL;
  2619. +
  2620. + pkg_hash_init("pkg-hash", &conf->pkg_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2621. + hash_table_init("file-hash", &conf->file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2622. + hash_table_init("obs-file-hash", &conf->obs_file_hash, IPKG_CONF_DEFAULT_HASH_LEN);
  2623. + lists_dir=(char *)malloc(1);
  2624. + lists_dir[0]='\0';
  2625. + if (args->conf_file) {
  2626. + struct stat stat_buf;
  2627. + err = stat(args->conf_file, &stat_buf);
  2628. + if (err == 0)
  2629. + if (ipkg_conf_parse_file(conf, args->conf_file,
  2630. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2631. + /* Memory leakage from ipkg_conf_parse-file */
  2632. + return -1;
  2633. + }
  2634. +
  2635. + }
  2636. +
  2637. + /* if (!lists_dir ){*/
  2638. + if (strlen(lists_dir)<=1 ){
  2639. + lists_dir = realloc(lists_dir,strlen(IPKG_CONF_LISTS_DIR)+2);
  2640. + sprintf (lists_dir,"%s",IPKG_CONF_LISTS_DIR);
  2641. + }
  2642. +
  2643. + if (args->offline_root) {
  2644. + char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
  2645. + sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
  2646. + free(lists_dir);
  2647. + lists_dir = tmp;
  2648. + }
  2649. +
  2650. + pending_dir = malloc(strlen(lists_dir)+strlen("/pending")+5);
  2651. + snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
  2652. +
  2653. + conf->lists_dir = strdup(lists_dir);
  2654. + conf->pending_dir = strdup(pending_dir);
  2655. +
  2656. + if (args->offline_root)
  2657. + sprintf_alloc(&etc_ipkg_conf_pattern, "%s/etc/ipkg/*.conf", args->offline_root);
  2658. + memset(&globbuf, 0, sizeof(globbuf));
  2659. + err = glob(etc_ipkg_conf_pattern, 0, NULL, &globbuf);
  2660. + if (!err) {
  2661. + int i;
  2662. + for (i = 0; i < globbuf.gl_pathc; i++) {
  2663. + if (globbuf.gl_pathv[i])
  2664. + if ( ipkg_conf_parse_file(conf, globbuf.gl_pathv[i],
  2665. + &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
  2666. + /* Memory leakage from ipkg_conf_parse-file */
  2667. + return -1;
  2668. + }
  2669. + }
  2670. + }
  2671. + globfree(&globbuf);
  2672. +
  2673. + /* if no architectures were defined, then default all, noarch, and host architecture */
  2674. + if (nv_pair_list_empty(&conf->arch_list)) {
  2675. + nv_pair_list_append(&conf->arch_list, "all", "1");
  2676. + nv_pair_list_append(&conf->arch_list, "noarch", "1");
  2677. + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
  2678. + }
  2679. +
  2680. + /* Even if there is no conf file, we'll need at least one dest. */
  2681. + if (tmp_dest_nv_pair_list.head == NULL) {
  2682. + nv_pair_list_append(&tmp_dest_nv_pair_list,
  2683. + IPKG_CONF_DEFAULT_DEST_NAME,
  2684. + IPKG_CONF_DEFAULT_DEST_ROOT_DIR);
  2685. + }
  2686. +
  2687. + /* After parsing the file, set options from command-line, (so that
  2688. + command-line arguments take precedence) */
  2689. + /* XXX: CLEANUP: The interaction between args.c and ipkg_conf.c
  2690. + really needs to be cleaned up. There is so much duplication
  2691. + right now it is ridiculous. Maybe ipkg_conf_t should just save
  2692. + a pointer to args_t (which could then not be freed), rather
  2693. + than duplicating every field here? */
  2694. + if (args->force_depends) {
  2695. + conf->force_depends = 1;
  2696. + }
  2697. + if (args->force_defaults) {
  2698. + conf->force_defaults = 1;
  2699. + }
  2700. + if (args->force_overwrite) {
  2701. + conf->force_overwrite = 1;
  2702. + }
  2703. + if (args->force_downgrade) {
  2704. + conf->force_downgrade = 1;
  2705. + }
  2706. + if (args->force_reinstall) {
  2707. + conf->force_reinstall = 1;
  2708. + }
  2709. + if (args->force_removal_of_dependent_packages) {
  2710. + conf->force_removal_of_dependent_packages = 1;
  2711. + }
  2712. + if (args->force_removal_of_essential_packages) {
  2713. + conf->force_removal_of_essential_packages = 1;
  2714. + }
  2715. + if (args->nodeps) {
  2716. + conf->nodeps = 1;
  2717. + }
  2718. + if (args->noaction) {
  2719. + conf->noaction = 1;
  2720. + }
  2721. + if (args->query_all) {
  2722. + conf->query_all = 1;
  2723. + }
  2724. + if (args->verbose_wget) {
  2725. + conf->verbose_wget = 1;
  2726. + }
  2727. + if (args->multiple_providers) {
  2728. + conf->multiple_providers = 1;
  2729. + }
  2730. + if (args->verbosity != conf->verbosity) {
  2731. + conf->verbosity = args->verbosity;
  2732. + }
  2733. +
  2734. + ipkg_conf_override_string(&conf->offline_root,
  2735. + args->offline_root);
  2736. + ipkg_conf_override_string(&conf->offline_root_pre_script_cmd,
  2737. + args->offline_root_pre_script_cmd);
  2738. + ipkg_conf_override_string(&conf->offline_root_post_script_cmd,
  2739. + args->offline_root_post_script_cmd);
  2740. +
  2741. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  2742. + read anything from there.
  2743. +*/
  2744. + if ( !(args->nocheckfordirorfile)){
  2745. + /* need to run load the source list before dest list -Jamey */
  2746. + if ( !(args->noreadfeedsfile))
  2747. + set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
  2748. +
  2749. + /* Now that we have resolved conf->offline_root, we can commit to
  2750. + the directory names for the dests and load in all the package
  2751. + lists. */
  2752. + set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
  2753. +
  2754. + if (args->dest) {
  2755. + err = ipkg_conf_set_default_dest(conf, args->dest);
  2756. + if (err) {
  2757. + return err;
  2758. + }
  2759. + }
  2760. + }
  2761. + nv_pair_list_deinit(&tmp_dest_nv_pair_list);
  2762. + free(lists_dir);
  2763. + free(pending_dir);
  2764. +
  2765. + return 0;
  2766. +}
  2767. +
  2768. +void ipkg_conf_deinit(ipkg_conf_t *conf)
  2769. +{
  2770. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  2771. +#error
  2772. + fprintf(stderr, "%s: Not cleaning up %s since ipkg compiled "
  2773. + "with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  2774. + __FUNCTION__, conf->tmp_dir);
  2775. +#else
  2776. + int err;
  2777. +
  2778. + err = rmdir(conf->tmp_dir);
  2779. + if (err) {
  2780. + if (errno == ENOTEMPTY) {
  2781. + char *cmd;
  2782. + sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
  2783. + err = xsystem(cmd);
  2784. + free(cmd);
  2785. + }
  2786. + if (err)
  2787. + fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
  2788. + }
  2789. +#endif /* IPKG_DEBUG_NO_TMP_CLEANUP */
  2790. +
  2791. + free(conf->tmp_dir); /*XXX*/
  2792. +
  2793. + pkg_src_list_deinit(&conf->pkg_src_list);
  2794. + pkg_dest_list_deinit(&conf->pkg_dest_list);
  2795. + nv_pair_list_deinit(&conf->arch_list);
  2796. + if (&conf->pkg_hash)
  2797. + pkg_hash_deinit(&conf->pkg_hash);
  2798. + if (&conf->file_hash)
  2799. + hash_table_deinit(&conf->file_hash);
  2800. + if (&conf->obs_file_hash)
  2801. + hash_table_deinit(&conf->obs_file_hash);
  2802. +
  2803. + ipkg_conf_free_string(&conf->offline_root);
  2804. + ipkg_conf_free_string(&conf->offline_root_pre_script_cmd);
  2805. + ipkg_conf_free_string(&conf->offline_root_post_script_cmd);
  2806. +
  2807. + if (conf->verbosity > 1) {
  2808. + int i;
  2809. + hash_table_t *hashes[] = {
  2810. + &conf->pkg_hash,
  2811. + &conf->file_hash,
  2812. + &conf->obs_file_hash };
  2813. + for (i = 0; i < 3; i++) {
  2814. + hash_table_t *hash = hashes[i];
  2815. + int c = 0;
  2816. + int n_conflicts = 0;
  2817. + int j;
  2818. + for (j = 0; j < hash->n_entries; j++) {
  2819. + int len = 0;
  2820. + hash_entry_t *e = &hash->entries[j];
  2821. + if (e->next)
  2822. + n_conflicts++;
  2823. + while (e && e->key) {
  2824. + len++;
  2825. + e = e->next;
  2826. + }
  2827. + if (len > c)
  2828. + c = len;
  2829. + }
  2830. + ipkg_message(conf, IPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
  2831. + hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
  2832. + hash_table_deinit(hash);
  2833. + }
  2834. + }
  2835. +}
  2836. +
  2837. +static int ipkg_conf_set_default_dest(ipkg_conf_t *conf,
  2838. + const char *default_dest_name)
  2839. +{
  2840. + pkg_dest_list_elt_t *iter;
  2841. + pkg_dest_t *dest;
  2842. +
  2843. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  2844. + dest = iter->data;
  2845. + if (strcmp(dest->name, default_dest_name) == 0) {
  2846. + conf->default_dest = dest;
  2847. + conf->restrict_to_default_dest = 1;
  2848. + return 0;
  2849. + }
  2850. + }
  2851. +
  2852. + fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
  2853. +
  2854. + return 1;
  2855. +}
  2856. +
  2857. +static int set_and_load_pkg_src_list(ipkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
  2858. +{
  2859. + pkg_src_list_elt_t *iter;
  2860. + pkg_src_t *src;
  2861. + char *list_file;
  2862. +
  2863. + for (iter = pkg_src_list->head; iter; iter = iter->next) {
  2864. + src = iter->data;
  2865. + if (src == NULL) {
  2866. + continue;
  2867. + }
  2868. +
  2869. + sprintf_alloc(&list_file, "%s/%s",
  2870. + conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
  2871. + src->name);
  2872. +
  2873. + if (file_exists(list_file)) {
  2874. + pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
  2875. + }
  2876. + free(list_file);
  2877. + }
  2878. +
  2879. + return 0;
  2880. +}
  2881. +
  2882. +static int set_and_load_pkg_dest_list(ipkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
  2883. +{
  2884. + nv_pair_list_elt_t *iter;
  2885. + nv_pair_t *nv_pair;
  2886. + pkg_dest_t *dest;
  2887. + char *root_dir;
  2888. +
  2889. + for (iter = nv_pair_list->head; iter; iter = iter->next) {
  2890. + nv_pair = iter->data;
  2891. +
  2892. + if (conf->offline_root) {
  2893. + sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
  2894. + } else {
  2895. + root_dir = strdup(nv_pair->value);
  2896. + }
  2897. + dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
  2898. + free(root_dir);
  2899. + if (dest == NULL) {
  2900. + continue;
  2901. + }
  2902. + if (conf->default_dest == NULL) {
  2903. + conf->default_dest = dest;
  2904. + }
  2905. + if (file_exists(dest->status_file_name)) {
  2906. + pkg_hash_add_from_file(conf, dest->status_file_name,
  2907. + NULL, dest, 1);
  2908. + }
  2909. + }
  2910. +
  2911. + return 0;
  2912. +}
  2913. +
  2914. +static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
  2915. + pkg_src_list_t *pkg_src_list,
  2916. + nv_pair_list_t *tmp_dest_nv_pair_list,
  2917. + char **lists_dir)
  2918. +{
  2919. + ipkg_option_t * options;
  2920. + FILE *file = fopen(filename, "r");
  2921. + regex_t valid_line_re, comment_re;
  2922. +#define regmatch_size 12
  2923. + regmatch_t regmatch[regmatch_size];
  2924. +
  2925. + if (ipkg_init_options_array(conf, &options)<0)
  2926. + return ENOMEM;
  2927. +
  2928. + if (file == NULL) {
  2929. + fprintf(stderr, "%s: failed to open %s: %s\n",
  2930. + __FUNCTION__, filename, strerror(errno));
  2931. + free(options);
  2932. + return errno;
  2933. + }
  2934. + ipkg_message(conf, IPKG_NOTICE, "loading conf file %s\n", filename);
  2935. +
  2936. + xregcomp(&comment_re,
  2937. + "^[[:space:]]*(#.*|[[:space:]]*)$",
  2938. + REG_EXTENDED);
  2939. + xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
  2940. +
  2941. + while(1) {
  2942. + int line_num = 0;
  2943. + char *line;
  2944. + char *type, *name, *value, *extra;
  2945. +
  2946. + line = file_read_line_alloc(file);
  2947. + line_num++;
  2948. + if (line == NULL) {
  2949. + break;
  2950. + }
  2951. +
  2952. + str_chomp(line);
  2953. +
  2954. + if (regexec(&comment_re, line, 0, 0, 0) == 0) {
  2955. + goto NEXT_LINE;
  2956. + }
  2957. +
  2958. + if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
  2959. + str_chomp(line);
  2960. + fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
  2961. + filename, line_num, line);
  2962. + goto NEXT_LINE;
  2963. + }
  2964. +
  2965. + /* This has to be so ugly to deal with optional quotation marks */
  2966. + if (regmatch[2].rm_so > 0) {
  2967. + type = strndup(line + regmatch[2].rm_so,
  2968. + regmatch[2].rm_eo - regmatch[2].rm_so);
  2969. + } else {
  2970. + type = strndup(line + regmatch[3].rm_so,
  2971. + regmatch[3].rm_eo - regmatch[3].rm_so);
  2972. + }
  2973. + if (regmatch[5].rm_so > 0) {
  2974. + name = strndup(line + regmatch[5].rm_so,
  2975. + regmatch[5].rm_eo - regmatch[5].rm_so);
  2976. + } else {
  2977. + name = strndup(line + regmatch[6].rm_so,
  2978. + regmatch[6].rm_eo - regmatch[6].rm_so);
  2979. + }
  2980. + if (regmatch[8].rm_so > 0) {
  2981. + value = strndup(line + regmatch[8].rm_so,
  2982. + regmatch[8].rm_eo - regmatch[8].rm_so);
  2983. + } else {
  2984. + value = strndup(line + regmatch[9].rm_so,
  2985. + regmatch[9].rm_eo - regmatch[9].rm_so);
  2986. + }
  2987. + extra = NULL;
  2988. + if (regmatch[11].rm_so > 0) {
  2989. + extra = strndup (line + regmatch[11].rm_so,
  2990. + regmatch[11].rm_eo - regmatch[11].rm_so);
  2991. + }
  2992. +
  2993. + /* We use the tmp_dest_nv_pair_list below instead of
  2994. + conf->pkg_dest_list because we might encounter an
  2995. + offline_root option later and that would invalidate the
  2996. + directories we would have computed in
  2997. + pkg_dest_list_init. (We do a similar thing with
  2998. + tmp_src_nv_pair_list for sake of symmetry.) */
  2999. + if (strcmp(type, "option") == 0) {
  3000. + ipkg_conf_set_option(options, name, value);
  3001. + } else if (strcmp(type, "src") == 0) {
  3002. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3003. + pkg_src_list_append (pkg_src_list, name, value, extra, 0);
  3004. + } else {
  3005. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3006. + name, value);
  3007. + }
  3008. + } else if (strcmp(type, "src/gz") == 0) {
  3009. + if (!nv_pair_list_find((nv_pair_list_t *)pkg_src_list, name)) {
  3010. + pkg_src_list_append (pkg_src_list, name, value, extra, 1);
  3011. + } else {
  3012. + ipkg_message(conf, IPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
  3013. + name, value);
  3014. + }
  3015. + } else if (strcmp(type, "dest") == 0) {
  3016. + nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
  3017. + } else if (strcmp(type, "lists_dir") == 0) {
  3018. + *lists_dir = realloc(*lists_dir,strlen(value)+1);
  3019. + if (*lists_dir == NULL) {
  3020. + ipkg_message(conf, IPKG_ERROR, "ERROR: Not enough memory\n");
  3021. + free(options);
  3022. + return EINVAL;
  3023. + }
  3024. + sprintf (*lists_dir,"%s",value);
  3025. + } else if (strcmp(type, "arch") == 0) {
  3026. + ipkg_message(conf, IPKG_INFO, "supported arch %s priority (%s)\n", name, value);
  3027. + if (!value) {
  3028. + ipkg_message(conf, IPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
  3029. + value = strdup("10");
  3030. + }
  3031. + nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
  3032. + } else {
  3033. + fprintf(stderr, "WARNING: Ignoring unknown configuration "
  3034. + "parameter: %s %s %s\n", type, name, value);
  3035. + free(options);
  3036. + return EINVAL;
  3037. + }
  3038. +
  3039. + free(type);
  3040. + free(name);
  3041. + free(value);
  3042. + if (extra)
  3043. + free (extra);
  3044. +
  3045. + NEXT_LINE:
  3046. + free(line);
  3047. + }
  3048. +
  3049. + free(options);
  3050. + regfree(&comment_re);
  3051. + regfree(&valid_line_re);
  3052. + fclose(file);
  3053. +
  3054. + return 0;
  3055. +}
  3056. +
  3057. +static int ipkg_conf_set_option(const ipkg_option_t *options,
  3058. + const char *name, const char *value)
  3059. +{
  3060. + int i = 0;
  3061. + while (options[i].name) {
  3062. + if (strcmp(options[i].name, name) == 0) {
  3063. + switch (options[i].type) {
  3064. + case IPKG_OPT_TYPE_BOOL:
  3065. + *((int *)options[i].value) = 1;
  3066. + return 0;
  3067. + case IPKG_OPT_TYPE_INT:
  3068. + if (value) {
  3069. + *((int *)options[i].value) = atoi(value);
  3070. + return 0;
  3071. + } else {
  3072. + printf("%s: Option %s need an argument\n",
  3073. + __FUNCTION__, name);
  3074. + return EINVAL;
  3075. + }
  3076. + case IPKG_OPT_TYPE_STRING:
  3077. + if (value) {
  3078. + *((char **)options[i].value) = strdup(value);
  3079. + return 0;
  3080. + } else {
  3081. + printf("%s: Option %s need an argument\n",
  3082. + __FUNCTION__, name);
  3083. + return EINVAL;
  3084. + }
  3085. + }
  3086. + }
  3087. + i++;
  3088. + }
  3089. +
  3090. + fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
  3091. + __FUNCTION__, name, value);
  3092. + return EINVAL;
  3093. +}
  3094. +
  3095. +int ipkg_conf_write_status_files(ipkg_conf_t *conf)
  3096. +{
  3097. + pkg_dest_list_elt_t *iter;
  3098. + pkg_dest_t *dest;
  3099. + pkg_vec_t *all;
  3100. + pkg_t *pkg;
  3101. + register int i;
  3102. + int err;
  3103. +
  3104. + if (conf->noaction)
  3105. + return 0;
  3106. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3107. + dest = iter->data;
  3108. + dest->status_file = fopen(dest->status_file_tmp_name, "w");
  3109. + if (dest->status_file == NULL) {
  3110. + fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
  3111. + __FUNCTION__, dest->status_file_name, strerror(errno));
  3112. + }
  3113. + }
  3114. +
  3115. + all = pkg_vec_alloc();
  3116. + pkg_hash_fetch_available(&conf->pkg_hash, all);
  3117. +
  3118. + for(i = 0; i < all->len; i++) {
  3119. + pkg = all->pkgs[i];
  3120. + /* We don't need most uninstalled packages in the status file */
  3121. + if (pkg->state_status == SS_NOT_INSTALLED
  3122. + && (pkg->state_want == SW_UNKNOWN
  3123. + || pkg->state_want == SW_DEINSTALL
  3124. + || pkg->state_want == SW_PURGE)) {
  3125. + continue;
  3126. + }
  3127. + if (!pkg) {
  3128. + fprintf(stderr, "Null package\n");
  3129. + }
  3130. + if (pkg->dest == NULL) {
  3131. + fprintf(stderr, "%s: ERROR: Can't write status for "
  3132. + "package %s since it has a NULL dest\n",
  3133. + __FUNCTION__, pkg->name);
  3134. + continue;
  3135. + }
  3136. + if (pkg->dest->status_file) {
  3137. + pkg_print_status(pkg, pkg->dest->status_file);
  3138. + }
  3139. + }
  3140. +
  3141. + pkg_vec_free(all);
  3142. +
  3143. + for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
  3144. + dest = iter->data;
  3145. + if (dest->status_file) {
  3146. + err = ferror(dest->status_file);
  3147. + fclose(dest->status_file);
  3148. + dest->status_file = NULL;
  3149. + if (!err) {
  3150. + file_move(dest->status_file_tmp_name, dest->status_file_name);
  3151. + } else {
  3152. + fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
  3153. + "retaining old %s\n", __FUNCTION__,
  3154. + dest->status_file_tmp_name, dest->status_file_name);
  3155. + }
  3156. + }
  3157. + }
  3158. +
  3159. + return 0;
  3160. +}
  3161. +
  3162. +
  3163. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename)
  3164. +{
  3165. + char *root_filename;
  3166. + sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
  3167. + return root_filename;
  3168. +}
  3169. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_conf.h busybox-1.24.1/archival/libipkg/ipkg_conf.h
  3170. --- busybox-1.24.1.orig/archival/libipkg/ipkg_conf.h 1970-01-01 01:00:00.000000000 +0100
  3171. +++ busybox-1.24.1/archival/libipkg/ipkg_conf.h 2015-10-31 19:00:22.000000000 +0100
  3172. @@ -0,0 +1,107 @@
  3173. +/* ipkg_conf.h - the itsy package management system
  3174. +
  3175. + Carl D. Worth
  3176. +
  3177. + Copyright (C) 2001 University of Southern California
  3178. +
  3179. + This program is free software; you can redistribute it and/or
  3180. + modify it under the terms of the GNU General Public License as
  3181. + published by the Free Software Foundation; either version 2, or (at
  3182. + your option) any later version.
  3183. +
  3184. + This program is distributed in the hope that it will be useful, but
  3185. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3186. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3187. + General Public License for more details.
  3188. +*/
  3189. +
  3190. +#ifndef IPKG_CONF_H
  3191. +#define IPKG_CONF_H
  3192. +
  3193. +typedef struct ipkg_conf ipkg_conf_t;
  3194. +
  3195. +#include "hash_table.h"
  3196. +#include "ipkg.h"
  3197. +#include "args.h"
  3198. +#include "pkg.h"
  3199. +#include "pkg_hash.h"
  3200. +#include "pkg_src_list.h"
  3201. +#include "pkg_dest_list.h"
  3202. +#include "nv_pair_list.h"
  3203. +
  3204. +#define IPKG_CONF_DEFAULT_TMP_DIR_BASE "/tmp"
  3205. +#define IPKG_CONF_TMP_DIR_SUFFIX "ipkg-XXXXXX"
  3206. +#define IPKG_CONF_LISTS_DIR IPKG_STATE_DIR_PREFIX "/lists"
  3207. +#define IPKG_CONF_PENDING_DIR IPKG_STATE_DIR_PREFIX "/pending"
  3208. +
  3209. +/* In case the config file defines no dest */
  3210. +#define IPKG_CONF_DEFAULT_DEST_NAME "root"
  3211. +#define IPKG_CONF_DEFAULT_DEST_ROOT_DIR "/"
  3212. +
  3213. +#define IPKG_CONF_DEFAULT_HASH_LEN 1024
  3214. +
  3215. +struct ipkg_conf
  3216. +{
  3217. + pkg_src_list_t pkg_src_list;
  3218. + pkg_dest_list_t pkg_dest_list;
  3219. + nv_pair_list_t arch_list;
  3220. +
  3221. + int restrict_to_default_dest;
  3222. + pkg_dest_t *default_dest;
  3223. +
  3224. + char *tmp_dir;
  3225. + char *lists_dir;
  3226. + char *pending_dir;
  3227. +
  3228. + /* options */
  3229. + int force_depends;
  3230. + int force_defaults;
  3231. + int force_overwrite;
  3232. + int force_downgrade;
  3233. + int force_reinstall;
  3234. + int force_space;
  3235. + int force_removal_of_dependent_packages;
  3236. + int force_removal_of_essential_packages;
  3237. + int nodeps; /* do not follow dependences */
  3238. + int verbose_wget;
  3239. + int multiple_providers;
  3240. + char *offline_root;
  3241. + char *offline_root_pre_script_cmd;
  3242. + char *offline_root_post_script_cmd;
  3243. + int query_all;
  3244. + int verbosity;
  3245. + int noaction;
  3246. +
  3247. + /* proxy options */
  3248. + char *http_proxy;
  3249. + char *ftp_proxy;
  3250. + char *no_proxy;
  3251. + char *proxy_user;
  3252. + char *proxy_passwd;
  3253. +
  3254. + hash_table_t pkg_hash;
  3255. + hash_table_t file_hash;
  3256. + hash_table_t obs_file_hash;
  3257. +};
  3258. +
  3259. +enum ipkg_option_type {
  3260. + IPKG_OPT_TYPE_BOOL,
  3261. + IPKG_OPT_TYPE_INT,
  3262. + IPKG_OPT_TYPE_STRING
  3263. +};
  3264. +typedef enum ipkg_option_type ipkg_option_type_t;
  3265. +
  3266. +typedef struct ipkg_option ipkg_option_t;
  3267. +struct ipkg_option {
  3268. + const char *name;
  3269. + const ipkg_option_type_t type;
  3270. + const void *value;
  3271. +};
  3272. +
  3273. +int ipkg_conf_init(ipkg_conf_t *conf, const args_t *args);
  3274. +void ipkg_conf_deinit(ipkg_conf_t *conf);
  3275. +
  3276. +int ipkg_conf_write_status_files(ipkg_conf_t *conf);
  3277. +char *root_filename_alloc(ipkg_conf_t *conf, char *filename);
  3278. +
  3279. +#endif
  3280. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_configure.c busybox-1.24.1/archival/libipkg/ipkg_configure.c
  3281. --- busybox-1.24.1.orig/archival/libipkg/ipkg_configure.c 1970-01-01 01:00:00.000000000 +0100
  3282. +++ busybox-1.24.1/archival/libipkg/ipkg_configure.c 2015-10-31 19:00:22.000000000 +0100
  3283. @@ -0,0 +1,40 @@
  3284. +/* ipkg_configure.c - the itsy package management system
  3285. +
  3286. + Carl D. Worth
  3287. +
  3288. + Copyright (C) 2001 University of Southern California
  3289. +
  3290. + This program is free software; you can redistribute it and/or
  3291. + modify it under the terms of the GNU General Public License as
  3292. + published by the Free Software Foundation; either version 2, or (at
  3293. + your option) any later version.
  3294. +
  3295. + This program is distributed in the hope that it will be useful, but
  3296. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3297. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3298. + General Public License for more details.
  3299. +*/
  3300. +
  3301. +#include "ipkg.h"
  3302. +
  3303. +#include "ipkg_configure.h"
  3304. +
  3305. +int ipkg_configure(ipkg_conf_t *conf, pkg_t *pkg)
  3306. +{
  3307. + int err;
  3308. +
  3309. + /* DPKG_INCOMPATIBILITY:
  3310. + dpkg actually does some conffile handling here, rather than at the
  3311. + end of ipkg_install(). Do we care? */
  3312. + /* DPKG_INCOMPATIBILITY:
  3313. + dpkg actually includes a version number to this script call */
  3314. + err = pkg_run_script(conf, pkg, "postinst", "configure");
  3315. + if (err) {
  3316. + printf("ERROR: %s.postinst returned %d\n", pkg->name, err);
  3317. + return err;
  3318. + }
  3319. +
  3320. + ipkg_state_changed++;
  3321. + return 0;
  3322. +}
  3323. +
  3324. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_configure.h busybox-1.24.1/archival/libipkg/ipkg_configure.h
  3325. --- busybox-1.24.1.orig/archival/libipkg/ipkg_configure.h 1970-01-01 01:00:00.000000000 +0100
  3326. +++ busybox-1.24.1/archival/libipkg/ipkg_configure.h 2015-10-31 19:00:22.000000000 +0100
  3327. @@ -0,0 +1,25 @@
  3328. +/* ipkg_configure.h - the itsy package management system
  3329. +
  3330. + Carl D. Worth
  3331. +
  3332. + Copyright (C) 2001 University of Southern California
  3333. +
  3334. + This program is free software; you can redistribute it and/or
  3335. + modify it under the terms of the GNU General Public License as
  3336. + published by the Free Software Foundation; either version 2, or (at
  3337. + your option) any later version.
  3338. +
  3339. + This program is distributed in the hope that it will be useful, but
  3340. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3341. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3342. + General Public License for more details.
  3343. +*/
  3344. +
  3345. +#ifndef IPKG_CONFIGURE_H
  3346. +#define IPKG_CONFIGURE_H
  3347. +
  3348. +#include "ipkg_conf.h"
  3349. +
  3350. +int ipkg_configure(ipkg_conf_t *ipkg_conf, pkg_t *pkg);
  3351. +
  3352. +#endif
  3353. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_download.c busybox-1.24.1/archival/libipkg/ipkg_download.c
  3354. --- busybox-1.24.1.orig/archival/libipkg/ipkg_download.c 1970-01-01 01:00:00.000000000 +0100
  3355. +++ busybox-1.24.1/archival/libipkg/ipkg_download.c 2015-10-31 19:00:22.000000000 +0100
  3356. @@ -0,0 +1,195 @@
  3357. +/* ipkg_download.c - the itsy package management system
  3358. +
  3359. + Carl D. Worth
  3360. +
  3361. + Copyright (C) 2001 University of Southern California
  3362. +
  3363. + This program is free software; you can redistribute it and/or
  3364. + modify it under the terms of the GNU General Public License as
  3365. + published by the Free Software Foundation; either version 2, or (at
  3366. + your option) any later version.
  3367. +
  3368. + This program is distributed in the hope that it will be useful, but
  3369. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3370. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3371. + General Public License for more details.
  3372. +*/
  3373. +
  3374. +#include "ipkg.h"
  3375. +#include "ipkg_download.h"
  3376. +#include "ipkg_message.h"
  3377. +
  3378. +#include "sprintf_alloc.h"
  3379. +#include "xsystem.h"
  3380. +#include "file_util.h"
  3381. +#include "str_util.h"
  3382. +
  3383. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name)
  3384. +{
  3385. + int err = 0;
  3386. +
  3387. + char *src_basec = strdup(src);
  3388. + char *src_base = bb_basename(src_basec);
  3389. + char *tmp_file_location;
  3390. + char *cmd;
  3391. +
  3392. + ipkg_message(conf,IPKG_NOTICE,"Downloading %s\n", src);
  3393. +
  3394. + fflush(stdout);
  3395. +
  3396. + if (str_starts_with(src, "file:")) {
  3397. + int ret;
  3398. + const char *file_src = src + 5;
  3399. + ipkg_message(conf,IPKG_INFO,"Copying %s to %s...", file_src, dest_file_name);
  3400. + ret = file_copy(src + 5, dest_file_name);
  3401. + ipkg_message(conf,IPKG_INFO,"Done.\n");
  3402. + return ret;
  3403. + }
  3404. +
  3405. + sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base);
  3406. + err = unlink(tmp_file_location);
  3407. + if (err && errno != ENOENT) {
  3408. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n",
  3409. + __FUNCTION__, tmp_file_location, strerror(errno));
  3410. + free(tmp_file_location);
  3411. + return errno;
  3412. + }
  3413. +
  3414. + if (conf->http_proxy) {
  3415. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy);
  3416. + setenv("http_proxy", conf->http_proxy, 1);
  3417. + }
  3418. + if (conf->ftp_proxy) {
  3419. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy);
  3420. + setenv("ftp_proxy", conf->ftp_proxy, 1);
  3421. + }
  3422. + if (conf->no_proxy) {
  3423. + ipkg_message(conf,IPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy);
  3424. + setenv("no_proxy", conf->no_proxy, 1);
  3425. + }
  3426. +
  3427. + /* XXX: BUG rewrite to use execvp or else busybox's internal wget -Jamey 7/23/2002 */
  3428. + sprintf_alloc(&cmd, "wget %s %s%s %s%s %s -P %s %s",
  3429. + (conf->http_proxy || conf->ftp_proxy) ? "-Y on" : "",
  3430. + conf->proxy_user ? "--proxy-user=" : "",
  3431. + conf->proxy_user ? conf->proxy_user : "",
  3432. + conf->proxy_passwd ? "--proxy-passwd=" : "",
  3433. + conf->proxy_passwd ? conf->proxy_passwd : "",
  3434. + conf->verbose_wget ? "" : "-q",
  3435. + conf->tmp_dir,
  3436. + src);
  3437. + err = xsystem(cmd);
  3438. + if (err) {
  3439. + if (err != -1) {
  3440. + ipkg_message(conf,IPKG_ERROR, "%s: ERROR: Command failed with return value %d: `%s'\n",
  3441. + __FUNCTION__, err, cmd);
  3442. + }
  3443. + unlink(tmp_file_location);
  3444. + free(tmp_file_location);
  3445. + free(src_basec);
  3446. + free(cmd);
  3447. + return EINVAL;
  3448. + }
  3449. + free(cmd);
  3450. +
  3451. + err = file_move(tmp_file_location, dest_file_name);
  3452. +
  3453. + free(tmp_file_location);
  3454. + free(src_basec);
  3455. +
  3456. + if (err) {
  3457. + return err;
  3458. + }
  3459. +
  3460. + return 0;
  3461. +}
  3462. +
  3463. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir)
  3464. +{
  3465. + int err;
  3466. + char *url;
  3467. +
  3468. + if (pkg->src == NULL) {
  3469. + ipkg_message(conf,IPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n",
  3470. + pkg->name, pkg->parent->name);
  3471. + return -1;
  3472. + }
  3473. +
  3474. + sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
  3475. +
  3476. + /* XXX: BUG: The pkg->filename might be something like
  3477. + "../../foo.ipk". While this is correct, and exactly what we
  3478. + want to use to construct url above, here we actually need to
  3479. + use just the filename part, without any directory. */
  3480. + sprintf_alloc(&pkg->local_filename, "%s/%s", dir, pkg->filename);
  3481. +
  3482. + err = ipkg_download(conf, url, pkg->local_filename);
  3483. + free(url);
  3484. +
  3485. + return err;
  3486. +}
  3487. +
  3488. +/*
  3489. + * Downloads file from url, installs in package database, return package name.
  3490. + */
  3491. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep)
  3492. +{
  3493. + int err = 0;
  3494. + pkg_t *pkg;
  3495. + pkg = pkg_new();
  3496. + if (pkg == NULL)
  3497. + return ENOMEM;
  3498. +
  3499. + if (str_starts_with(url, "http://")
  3500. + || str_starts_with(url, "ftp://")) {
  3501. + char *tmp_file;
  3502. + char *file_basec = strdup(url);
  3503. + char *file_base = bb_basename(file_basec);
  3504. +
  3505. + sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base);
  3506. + err = ipkg_download(conf, url, tmp_file);
  3507. + if (err)
  3508. + return err;
  3509. +
  3510. + err = pkg_init_from_file(pkg, tmp_file);
  3511. + if (err)
  3512. + return err;
  3513. + pkg->local_filename = strdup(tmp_file);
  3514. +
  3515. + free(tmp_file);
  3516. + free(file_basec);
  3517. +
  3518. + } else if (strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0
  3519. + || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) {
  3520. +
  3521. + err = pkg_init_from_file(pkg, url);
  3522. + if (err)
  3523. + return err;
  3524. + pkg->local_filename = strdup(url);
  3525. + ipkg_message(conf, IPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename);
  3526. + pkg->provided_by_hand = 1;
  3527. +
  3528. + } else {
  3529. + pkg_deinit(pkg);
  3530. + free(pkg);
  3531. + return 0;
  3532. + }
  3533. +
  3534. + if (!pkg->architecture) {
  3535. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3536. + return -EINVAL;
  3537. + }
  3538. +
  3539. + pkg->dest = conf->default_dest;
  3540. + pkg->state_want = SW_INSTALL;
  3541. + pkg->state_flag |= SF_PREFER;
  3542. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3543. + if ( pkg == NULL ){
  3544. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  3545. + return 0;
  3546. + }
  3547. + if (namep) {
  3548. + *namep = strdup(pkg->name);
  3549. + }
  3550. + return 0;
  3551. +}
  3552. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_download.h busybox-1.24.1/archival/libipkg/ipkg_download.h
  3553. --- busybox-1.24.1.orig/archival/libipkg/ipkg_download.h 1970-01-01 01:00:00.000000000 +0100
  3554. +++ busybox-1.24.1/archival/libipkg/ipkg_download.h 2015-10-31 19:00:22.000000000 +0100
  3555. @@ -0,0 +1,30 @@
  3556. +/* ipkg_download.h - the itsy package management system
  3557. +
  3558. + Carl D. Worth
  3559. +
  3560. + Copyright (C) 2001 University of Southern California
  3561. +
  3562. + This program is free software; you can redistribute it and/or
  3563. + modify it under the terms of the GNU General Public License as
  3564. + published by the Free Software Foundation; either version 2, or (at
  3565. + your option) any later version.
  3566. +
  3567. + This program is distributed in the hope that it will be useful, but
  3568. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3569. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3570. + General Public License for more details.
  3571. +*/
  3572. +
  3573. +#ifndef IPKG_DOWNLOAD_H
  3574. +#define IPKG_DOWNLOAD_H
  3575. +
  3576. +#include "ipkg_conf.h"
  3577. +
  3578. +int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name);
  3579. +int ipkg_download_pkg(ipkg_conf_t *conf, pkg_t *pkg, const char *dir);
  3580. +/*
  3581. + * Downloads file from url, installs in package database, return package name.
  3582. + */
  3583. +int ipkg_prepare_url_for_install(ipkg_conf_t *conf, const char *url, char **namep);
  3584. +
  3585. +#endif
  3586. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg.h busybox-1.24.1/archival/libipkg/ipkg.h
  3587. --- busybox-1.24.1.orig/archival/libipkg/ipkg.h 1970-01-01 01:00:00.000000000 +0100
  3588. +++ busybox-1.24.1/archival/libipkg/ipkg.h 2015-10-31 19:00:22.000000000 +0100
  3589. @@ -0,0 +1,68 @@
  3590. +/* ipkg.h - the itsy package management system
  3591. +
  3592. + Carl D. Worth
  3593. +
  3594. + Copyright (C) 2001 University of Southern California
  3595. +
  3596. + This program is free software; you can redistribute it and/or
  3597. + modify it under the terms of the GNU General Public License as
  3598. + published by the Free Software Foundation; either version 2, or (at
  3599. + your option) any later version.
  3600. +
  3601. + This program is distributed in the hope that it will be useful, but
  3602. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3603. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3604. + General Public License for more details.
  3605. +*/
  3606. +
  3607. +#ifndef IPKG_H
  3608. +#define IPKG_H
  3609. +
  3610. +#include "libbb.h"
  3611. +
  3612. +#include "ipkg_includes.h"
  3613. +#include "ipkg_conf.h"
  3614. +#include "ipkg_message.h"
  3615. +
  3616. +#define IPKG_PKG_EXTENSION ".ipk"
  3617. +#define DPKG_PKG_EXTENSION ".deb"
  3618. +
  3619. +#define IPKG_LEGAL_PKG_NAME_CHARS "abcdefghijklmnopqrstuvwxyz0123456789.+-"
  3620. +#define IPKG_PKG_VERSION_SEP_CHAR '_'
  3621. +
  3622. +#define IPKG_STATE_DIR_PREFIX IPKGLIBDIR"/ipkg"
  3623. +#define IPKG_LISTS_DIR_SUFFIX "lists"
  3624. +#define IPKG_INFO_DIR_SUFFIX "info"
  3625. +#define IPKG_STATUS_FILE_SUFFIX "status"
  3626. +
  3627. +#define IPKG_BACKUP_SUFFIX "-ipkg.backup"
  3628. +
  3629. +#define IPKG_LIST_DESCRIPTION_LENGTH 128
  3630. +
  3631. +#define IPKG_VERSION "1.00"
  3632. +
  3633. +
  3634. +enum ipkg_error {
  3635. + IPKG_SUCCESS = 0,
  3636. + IPKG_PKG_DEPS_UNSATISFIED,
  3637. + IPKG_PKG_IS_ESSENTIAL,
  3638. + IPKG_PKG_HAS_DEPENDENTS,
  3639. + IPKG_PKG_HAS_NO_CANDIDATE
  3640. +};
  3641. +typedef enum ipkg_error ipkg_error_t;
  3642. +
  3643. +extern int ipkg_state_changed;
  3644. +
  3645. +
  3646. +struct errlist {
  3647. + char * errmsg;
  3648. + struct errlist * next;
  3649. +} ;
  3650. +
  3651. +extern struct errlist* error_list;
  3652. +
  3653. +extern ipkg_conf_t *global_conf;
  3654. +
  3655. +typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
  3656. +
  3657. +#endif
  3658. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_includes.h busybox-1.24.1/archival/libipkg/ipkg_includes.h
  3659. --- busybox-1.24.1.orig/archival/libipkg/ipkg_includes.h 1970-01-01 01:00:00.000000000 +0100
  3660. +++ busybox-1.24.1/archival/libipkg/ipkg_includes.h 2015-10-31 19:00:22.000000000 +0100
  3661. @@ -0,0 +1,82 @@
  3662. +#ifndef IPKG_INCLUDES_H
  3663. +#define IPKG_INCLUDES_H
  3664. +
  3665. +/* Define to 1 if you have the <memory.h> header file. */
  3666. +#define HAVE_MEMORY_H 1
  3667. +
  3668. +/* Define to 1 if you have the <regex.h> header file. */
  3669. +#define HAVE_REGEX_H 1
  3670. +
  3671. +/* Define to 1 if you have the <stdlib.h> header file. */
  3672. +#define HAVE_STDLIB_H 1
  3673. +
  3674. +/* Define to 1 if you have the <strings.h> header file. */
  3675. +#define HAVE_STRINGS_H 1
  3676. +
  3677. +/* Define to 1 if you have the <string.h> header file. */
  3678. +#define HAVE_STRING_H 1
  3679. +
  3680. +/* Define to 1 if you have the <sys/stat.h> header file. */
  3681. +#define HAVE_SYS_STAT_H 1
  3682. +
  3683. +/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
  3684. +#define HAVE_SYS_WAIT_H 1
  3685. +
  3686. +/* Define to 1 if you have the <unistd.h> header file. */
  3687. +#define HAVE_UNISTD_H 1
  3688. +
  3689. +/* Define to 1 if you have the ANSI C header files. */
  3690. +#define STDC_HEADERS 1
  3691. +
  3692. +
  3693. +#include <stdio.h>
  3694. +
  3695. +#if STDC_HEADERS
  3696. +# include <stdlib.h>
  3697. +# include <stdarg.h>
  3698. +# include <stddef.h>
  3699. +# include <ctype.h>
  3700. +# include <errno.h>
  3701. +#else
  3702. +# if HAVE_STDLIB_H
  3703. +# include <stdlib.h>
  3704. +# endif
  3705. +#endif
  3706. +
  3707. +#if HAVE_REGEX_H
  3708. +# include <regex.h>
  3709. +#endif
  3710. +
  3711. +#if HAVE_STRING_H
  3712. +# if !STDC_HEADERS && HAVE_MEMORY_H
  3713. +# include <memory.h>
  3714. +# endif
  3715. +/* XXX: What's the right way to pick up GNU's strndup declaration? */
  3716. +# if __GNUC__
  3717. +# define __USE_GNU 1
  3718. +# endif
  3719. +# include <string.h>
  3720. +# undef __USE_GNU
  3721. +#endif
  3722. +
  3723. +#if HAVE_STRINGS_H
  3724. +# include <strings.h>
  3725. +#endif
  3726. +
  3727. +#if HAVE_SYS_STAT_H
  3728. +# include <sys/stat.h>
  3729. +#endif
  3730. +
  3731. +#if HAVE_SYS_WAIT_H
  3732. +# include <sys/wait.h>
  3733. +#endif
  3734. +
  3735. +#if HAVE_UNISTD_H
  3736. +# include <sys/types.h>
  3737. +# include <unistd.h>
  3738. +#endif
  3739. +
  3740. +#include <sys/mount.h>
  3741. +#include <mntent.h>
  3742. +
  3743. +#endif /* IPKG_INCLUDES_H */
  3744. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_install.c busybox-1.24.1/archival/libipkg/ipkg_install.c
  3745. --- busybox-1.24.1.orig/archival/libipkg/ipkg_install.c 1970-01-01 01:00:00.000000000 +0100
  3746. +++ busybox-1.24.1/archival/libipkg/ipkg_install.c 2015-10-31 19:00:22.000000000 +0100
  3747. @@ -0,0 +1,1982 @@
  3748. +/* ipkg_install.c - the itsy package management system
  3749. +
  3750. + Carl D. Worth
  3751. +
  3752. + Copyright (C) 2001 University of Southern California
  3753. +
  3754. + This program is free software; you can redistribute it and/or
  3755. + modify it under the terms of the GNU General Public License as
  3756. + published by the Free Software Foundation; either version 2, or (at
  3757. + your option) any later version.
  3758. +
  3759. + This program is distributed in the hope that it will be useful, but
  3760. + WITHOUT ANY WARRANTY; without even the implied warranty of
  3761. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3762. + General Public License for more details.
  3763. +*/
  3764. +
  3765. +#include "ipkg.h"
  3766. +#include <errno.h>
  3767. +#include <dirent.h>
  3768. +#include <glob.h>
  3769. +#include <time.h>
  3770. +#include <signal.h>
  3771. +typedef void (*sighandler_t)(int);
  3772. +
  3773. +#include "pkg.h"
  3774. +#include "pkg_hash.h"
  3775. +#include "pkg_extract.h"
  3776. +
  3777. +#include "ipkg_install.h"
  3778. +#include "ipkg_configure.h"
  3779. +#include "ipkg_download.h"
  3780. +#include "ipkg_remove.h"
  3781. +
  3782. +#include "ipkg_utils.h"
  3783. +#include "ipkg_message.h"
  3784. +
  3785. +#include "sprintf_alloc.h"
  3786. +#include "file_util.h"
  3787. +#include "str_util.h"
  3788. +#include "xsystem.h"
  3789. +#include "user.h"
  3790. +
  3791. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  3792. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg);
  3793. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg);
  3794. +
  3795. +/*
  3796. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3797. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3798. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3799. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors);
  3800. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3801. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3802. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3803. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg);
  3804. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3805. +*/
  3806. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3807. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3808. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg);
  3809. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3810. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg);
  3811. +
  3812. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3813. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg);
  3814. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg);
  3815. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg);
  3816. +
  3817. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg);
  3818. +
  3819. +static int user_prefers_old_conffile(const char *file, const char *backup);
  3820. +
  3821. +static char *backup_filename_alloc(const char *file_name);
  3822. +static int backup_make_backup(ipkg_conf_t *conf, const char *file_name);
  3823. +static int backup_exists_for(const char *file_name);
  3824. +static int backup_remove(const char *file_name);
  3825. +
  3826. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees);
  3827. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3828. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees);
  3829. +
  3830. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename)
  3831. +{
  3832. + int err, cmp;
  3833. + pkg_t *pkg, *old;
  3834. + char *old_version, *new_version;
  3835. +
  3836. + pkg = pkg_new();
  3837. + if (pkg == NULL) {
  3838. + return ENOMEM;
  3839. + }
  3840. +
  3841. + err = pkg_init_from_file(pkg, filename);
  3842. + if (err) {
  3843. + return err;
  3844. + }
  3845. +
  3846. + if (!pkg->architecture) {
  3847. + ipkg_message(conf, IPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name);
  3848. + return -EINVAL;
  3849. + }
  3850. +
  3851. + /* XXX: CLEANUP: hash_insert_pkg has a nasty side effect of possibly
  3852. + freeing the pkg that we pass in. It might be nice to clean this up
  3853. + if possible. */
  3854. + pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf);
  3855. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  3856. +
  3857. + pkg->local_filename = strdup(filename);
  3858. +
  3859. + if (old) {
  3860. + old_version = pkg_version_str_alloc(old);
  3861. + new_version = pkg_version_str_alloc(pkg);
  3862. +
  3863. + cmp = pkg_compare_versions(old, pkg);
  3864. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3865. + cmp = -1 ; /* then we force ipkg to downgrade */
  3866. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3867. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3868. + }
  3869. + if (cmp > 0) {
  3870. + ipkg_message(conf, IPKG_NOTICE,
  3871. + "Not downgrading package %s on %s from %s to %s.\n",
  3872. + old->name, old->dest->name, old_version, new_version);
  3873. + pkg->state_want = SW_DEINSTALL;
  3874. + pkg->state_flag |= SF_OBSOLETE;
  3875. + free(old_version);
  3876. + free(new_version);
  3877. + return 0;
  3878. + } else {
  3879. + free(old_version);
  3880. + free(new_version);
  3881. + }
  3882. + }
  3883. +
  3884. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3885. + return ipkg_install_pkg(conf, pkg,0);
  3886. +}
  3887. +
  3888. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3889. +{
  3890. + int cmp;
  3891. + pkg_t *old, *new;
  3892. + char *old_version, *new_version;
  3893. +
  3894. + ipkg_message(conf, IPKG_DEBUG2, " Getting old from pkg_hash_fetch \n" );
  3895. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  3896. + if ( old )
  3897. + ipkg_message(conf, IPKG_DEBUG2, " Old versions from pkg_hash_fetch %s \n", old->version );
  3898. +
  3899. + ipkg_message(conf, IPKG_DEBUG2, " Getting new from pkg_hash_fetch \n" );
  3900. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  3901. + if ( new )
  3902. + ipkg_message(conf, IPKG_DEBUG2, " New versions from pkg_hash_fetch %s \n", new->version );
  3903. +
  3904. +/* Pigi Basically here is broken the version stuff.
  3905. + What's happening is that nothing provide the version to differents
  3906. + functions, so the returned struct is always the latest.
  3907. + That's why the install by name don't work.
  3908. +*/
  3909. + ipkg_message(conf, IPKG_DEBUG2, " Versions from pkg_hash_fetch in %s ", __FUNCTION__ );
  3910. +
  3911. + if ( old )
  3912. + ipkg_message(conf, IPKG_DEBUG2, " old %s ", old->version );
  3913. + if ( new )
  3914. + ipkg_message(conf, IPKG_DEBUG2, " new %s ", new->version );
  3915. + ipkg_message(conf, IPKG_DEBUG2, " \n");
  3916. +
  3917. + if (new == NULL) {
  3918. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3919. + }
  3920. +
  3921. + new->state_flag |= SF_USER;
  3922. + if (old) {
  3923. + old_version = pkg_version_str_alloc(old);
  3924. + new_version = pkg_version_str_alloc(new);
  3925. +
  3926. + cmp = pkg_compare_versions(old, new);
  3927. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  3928. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade \n");
  3929. + cmp = -1 ; /* then we force ipkg to downgrade */
  3930. + /* We need to use a value < 0 because in the 0 case we are asking to */
  3931. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  3932. + }
  3933. + ipkg_message(conf, IPKG_DEBUG,
  3934. + "Comparing visible versions of pkg %s:"
  3935. + "\n\t%s is installed "
  3936. + "\n\t%s is available "
  3937. + "\n\t%d was comparison result\n",
  3938. + pkg_name, old_version, new_version, cmp);
  3939. + if (cmp == 0 && !conf->force_reinstall) {
  3940. + ipkg_message(conf, IPKG_NOTICE,
  3941. + "Package %s (%s) installed in %s is up to date.\n",
  3942. + old->name, old_version, old->dest->name);
  3943. + free(old_version);
  3944. + free(new_version);
  3945. + return 0;
  3946. + } else if (cmp > 0) {
  3947. + ipkg_message(conf, IPKG_NOTICE,
  3948. + "Not downgrading package %s on %s from %s to %s.\n",
  3949. + old->name, old->dest->name, old_version, new_version);
  3950. + free(old_version);
  3951. + free(new_version);
  3952. + return 0;
  3953. + } else if (cmp < 0) {
  3954. + new->dest = old->dest;
  3955. + old->state_want = SW_DEINSTALL; /* Here probably the problem for bug 1277 */
  3956. + }
  3957. + }
  3958. +
  3959. + /* XXX: CLEANUP: The error code of ipkg_install_by_name is really
  3960. + supposed to be an ipkg_error_t, but ipkg_install_pkg could
  3961. + return any kind of integer, (might be errno from a syscall,
  3962. + etc.). This is a real mess and will need to be cleaned up if
  3963. + anyone ever wants to make a nice libipkg. */
  3964. +
  3965. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  3966. + return ipkg_install_pkg(conf, new,0);
  3967. +}
  3968. +
  3969. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name)
  3970. +{
  3971. + abstract_pkg_vec_t *providers = pkg_hash_fetch_all_installation_candidates (&conf->pkg_hash, pkg_name);
  3972. + int i;
  3973. + ipkg_error_t err;
  3974. + abstract_pkg_t *ppkg ;
  3975. +
  3976. + if (providers == NULL)
  3977. + return IPKG_PKG_HAS_NO_CANDIDATE;
  3978. +
  3979. + for (i = 0; i < providers->len; i++) {
  3980. + ppkg = abstract_pkg_vec_get(providers, i);
  3981. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_by_name %d \n",__FUNCTION__, i);
  3982. + err = ipkg_install_by_name(conf, ppkg->name);
  3983. + if (err)
  3984. + return err;
  3985. +/* XXX Maybe ppkg should be freed ? */
  3986. + }
  3987. + return 0;
  3988. +}
  3989. +
  3990. +/*
  3991. + * Walk dependence graph starting with pkg, collect packages to be
  3992. + * installed into pkgs_needed, in dependence order.
  3993. + */
  3994. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *pkgs_needed)
  3995. +{
  3996. + int i, err;
  3997. + pkg_vec_t *depends = pkg_vec_alloc();
  3998. + char **unresolved = NULL;
  3999. + int ndepends;
  4000. +
  4001. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4002. + pkg, depends,
  4003. + &unresolved);
  4004. +
  4005. + if (unresolved) {
  4006. + ipkg_message(conf, IPKG_ERROR,
  4007. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4008. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4009. + while (*unresolved) {
  4010. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4011. + unresolved++;
  4012. + }
  4013. + ipkg_message(conf, IPKG_ERROR, "\n");
  4014. + if (! conf->force_depends) {
  4015. + ipkg_message(conf, IPKG_INFO,
  4016. + "This could mean that your package list is out of date or that the packages\n"
  4017. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4018. + "of this problem try again with the '-force-depends' option.\n");
  4019. + pkg_vec_free(depends);
  4020. + return IPKG_PKG_DEPS_UNSATISFIED;
  4021. + }
  4022. + }
  4023. +
  4024. + if (ndepends <= 0) {
  4025. + pkg_vec_free(depends);
  4026. + return 0;
  4027. + }
  4028. +
  4029. + for (i = 0; i < depends->len; i++) {
  4030. + pkg_t *dep = depends->pkgs[i];
  4031. + /* The package was uninstalled when we started, but another
  4032. + dep earlier in this loop may have depended on it and pulled
  4033. + it in, so check first. */
  4034. + if ((dep->state_status != SS_INSTALLED)
  4035. + && (dep->state_status != SS_UNPACKED)
  4036. + && (dep->state_want != SW_INSTALL)) {
  4037. +
  4038. + /* Mark packages as to-be-installed */
  4039. + dep->state_want = SW_INSTALL;
  4040. +
  4041. + /* Dependencies should be installed the same place as pkg */
  4042. + if (dep->dest == NULL) {
  4043. + dep->dest = pkg->dest;
  4044. + }
  4045. +
  4046. + err = pkg_mark_dependencies_for_installation(conf, dep, pkgs_needed);
  4047. + if (err) {
  4048. + pkg_vec_free(depends);
  4049. + return err;
  4050. + }
  4051. + }
  4052. + }
  4053. + if (pkgs_needed)
  4054. + pkg_vec_insert(pkgs_needed, pkg);
  4055. +
  4056. + pkg_vec_free(depends);
  4057. +
  4058. + return 0;
  4059. +}
  4060. +
  4061. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed)
  4062. +{
  4063. + int cmp;
  4064. + pkg_t *old, *new;
  4065. + char *old_version, *new_version;
  4066. +
  4067. + old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name);
  4068. +
  4069. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name);
  4070. + if (new == NULL) {
  4071. + return IPKG_PKG_HAS_NO_CANDIDATE;
  4072. + }
  4073. + if (old) {
  4074. + old_version = pkg_version_str_alloc(old);
  4075. + new_version = pkg_version_str_alloc(new);
  4076. +
  4077. + cmp = pkg_compare_versions(old, new);
  4078. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4079. + ipkg_message(conf, IPKG_DEBUG, " Forcing downgrade ");
  4080. + cmp = -1 ; /* then we force ipkg to downgrade */
  4081. + /* We need to use a value < 0 because in the 0 case we are asking to */
  4082. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4083. + }
  4084. + ipkg_message(conf, IPKG_DEBUG,
  4085. + "comparing visible versions of pkg %s:"
  4086. + "\n\t%s is installed "
  4087. + "\n\t%s is available "
  4088. + "\n\t%d was comparison result\n",
  4089. + pkg_name, old_version, new_version, cmp);
  4090. + if (cmp == 0 && !conf->force_reinstall) {
  4091. + ipkg_message(conf, IPKG_NOTICE,
  4092. + "Package %s (%s) installed in %s is up to date.\n",
  4093. + old->name, old_version, old->dest->name);
  4094. + free(old_version);
  4095. + free(new_version);
  4096. + return 0;
  4097. + } else if (cmp > 0) {
  4098. + ipkg_message(conf, IPKG_NOTICE,
  4099. + "Not downgrading package %s on %s from %s to %s.\n",
  4100. + old->name, old->dest->name, old_version, new_version);
  4101. + free(old_version);
  4102. + free(new_version);
  4103. + return 0;
  4104. + } else if (cmp < 0) {
  4105. + new->dest = old->dest;
  4106. + old->state_want = SW_DEINSTALL;
  4107. + old->state_flag |= SF_OBSOLETE;
  4108. + }
  4109. + }
  4110. + return pkg_mark_dependencies_for_installation(conf, new, pkgs_needed);
  4111. +}
  4112. +
  4113. +
  4114. +
  4115. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg)
  4116. +{
  4117. + int i, err;
  4118. + pkg_vec_t *depends = pkg_vec_alloc();
  4119. + pkg_t *dep;
  4120. + char **unresolved = NULL;
  4121. + int ndepends;
  4122. +
  4123. + ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf,
  4124. + pkg, depends,
  4125. + &unresolved);
  4126. +
  4127. + if (unresolved) {
  4128. + ipkg_message(conf, IPKG_ERROR,
  4129. + "%s: Cannot satisfy the following dependencies for %s:\n\t",
  4130. + conf->force_depends ? "Warning" : "ERROR", pkg->name);
  4131. + while (*unresolved) {
  4132. + ipkg_message(conf, IPKG_ERROR, " %s", *unresolved);
  4133. + unresolved++;
  4134. + }
  4135. + ipkg_message(conf, IPKG_ERROR, "\n");
  4136. + if (! conf->force_depends) {
  4137. + ipkg_message(conf, IPKG_INFO,
  4138. + "This could mean that your package list is out of date or that the packages\n"
  4139. + "mentioned above do not yet exist (try 'ipkg update'). To proceed in spite\n"
  4140. + "of this problem try again with the '-force-depends' option.\n");
  4141. + pkg_vec_free(depends);
  4142. + return IPKG_PKG_DEPS_UNSATISFIED;
  4143. + }
  4144. + }
  4145. +
  4146. + if (ndepends <= 0) {
  4147. + return 0;
  4148. + }
  4149. +
  4150. + /* Mark packages as to-be-installed */
  4151. + for (i=0; i < depends->len; i++) {
  4152. + /* Dependencies should be installed the same place as pkg */
  4153. + if (depends->pkgs[i]->dest == NULL) {
  4154. + depends->pkgs[i]->dest = pkg->dest;
  4155. + }
  4156. + depends->pkgs[i]->state_want = SW_INSTALL;
  4157. + }
  4158. +
  4159. + for (i = 0; i < depends->len; i++) {
  4160. + dep = depends->pkgs[i];
  4161. + /* The package was uninstalled when we started, but another
  4162. + dep earlier in this loop may have depended on it and pulled
  4163. + it in, so check first. */
  4164. + if ((dep->state_status != SS_INSTALLED)
  4165. + && (dep->state_status != SS_UNPACKED)) {
  4166. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4167. + err = ipkg_install_pkg(conf, dep,0);
  4168. + if (err) {
  4169. + pkg_vec_free(depends);
  4170. + return err;
  4171. + }
  4172. + }
  4173. + }
  4174. +
  4175. + pkg_vec_free(depends);
  4176. +
  4177. + return 0;
  4178. +}
  4179. +
  4180. +
  4181. +/* check all packages have their dependences satisfied, e.g., in case an upgraded package split */
  4182. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf)
  4183. +{
  4184. + if (conf->nodeps == 0) {
  4185. + int i;
  4186. + pkg_vec_t *installed = pkg_vec_alloc();
  4187. + pkg_hash_fetch_all_installed(&conf->pkg_hash, installed);
  4188. + for (i = 0; i < installed->len; i++) {
  4189. + pkg_t *pkg = installed->pkgs[i];
  4190. + satisfy_dependencies_for(conf, pkg);
  4191. + }
  4192. + pkg_vec_free(installed);
  4193. + }
  4194. + return 0;
  4195. +}
  4196. +
  4197. +
  4198. +
  4199. +static int check_conflicts_for(ipkg_conf_t *conf, pkg_t *pkg)
  4200. +{
  4201. + int i;
  4202. + pkg_vec_t *conflicts = NULL;
  4203. + int level;
  4204. + const char *prefix;
  4205. + if (conf->force_depends) {
  4206. + level = IPKG_NOTICE;
  4207. + prefix = "Warning";
  4208. + } else {
  4209. + level = IPKG_ERROR;
  4210. + prefix = "ERROR";
  4211. + }
  4212. +
  4213. + if (!conf->force_depends)
  4214. + conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(pkg);
  4215. +
  4216. + if (conflicts) {
  4217. + ipkg_message(conf, level,
  4218. + "%s: The following packages conflict with %s:\n\t", prefix, pkg->name);
  4219. + i = 0;
  4220. + while (i < conflicts->len)
  4221. + ipkg_message(conf, level, " %s", conflicts->pkgs[i++]->name);
  4222. + ipkg_message(conf, level, "\n");
  4223. + pkg_vec_free(conflicts);
  4224. + return IPKG_PKG_DEPS_UNSATISFIED;
  4225. + }
  4226. + return 0;
  4227. +}
  4228. +
  4229. +static int update_file_ownership(ipkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
  4230. +{
  4231. + str_list_t *new_list = pkg_get_installed_files(new_pkg);
  4232. + str_list_elt_t *iter;
  4233. +
  4234. + for (iter = new_list->head; iter; iter = iter->next) {
  4235. + char *new_file = iter->data;
  4236. + pkg_t *owner = file_hash_get_file_owner(conf, new_file);
  4237. + if (!new_file)
  4238. + ipkg_message(conf, IPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
  4239. + if (!owner || (owner == old_pkg))
  4240. + file_hash_set_file_owner(conf, new_file, new_pkg);
  4241. + }
  4242. + if (old_pkg) {
  4243. + str_list_t *old_list = pkg_get_installed_files(old_pkg);
  4244. + for (iter = old_list->head; iter; iter = iter->next) {
  4245. + char *old_file = iter->data;
  4246. + pkg_t *owner = file_hash_get_file_owner(conf, old_file);
  4247. + if (owner == old_pkg) {
  4248. + /* obsolete */
  4249. + hash_table_insert(&conf->obs_file_hash, old_file, old_pkg);
  4250. + }
  4251. + }
  4252. + }
  4253. + return 0;
  4254. +}
  4255. +
  4256. +static int verify_pkg_installable(ipkg_conf_t *conf, pkg_t *pkg)
  4257. +{
  4258. + /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */
  4259. +
  4260. + /* sma 6.20.02: yup; here's the first bit */
  4261. + /*
  4262. + * XXX: BUG easy for cworth
  4263. + * 1) please point the call below to the correct current root destination
  4264. + * 2) we need to resolve how to check the required space for a pending pkg,
  4265. + * my diddling with the .ipk file size below isn't going to cut it.
  4266. + * 3) return a proper error code instead of 1
  4267. + */
  4268. + int comp_size, blocks_available;
  4269. +
  4270. + if (!conf->force_space && pkg->installed_size != NULL) {
  4271. + blocks_available = get_available_blocks(conf->default_dest->root_dir);
  4272. +
  4273. + comp_size = strtoul(pkg->installed_size, NULL, 0);
  4274. + /* round up a blocks count without doing fancy-but-slow casting jazz */
  4275. + comp_size = (int)((comp_size + 1023) / 1024);
  4276. +
  4277. + if (comp_size >= blocks_available) {
  4278. + ipkg_message(conf, IPKG_ERROR,
  4279. + "Only have %d available blocks on filesystem %s, pkg %s needs %d\n",
  4280. + blocks_available, conf->default_dest->root_dir, pkg->name, comp_size);
  4281. + return ENOSPC;
  4282. + }
  4283. + }
  4284. + return 0;
  4285. +}
  4286. +
  4287. +static int unpack_pkg_control_files(ipkg_conf_t *conf, pkg_t *pkg)
  4288. +{
  4289. + int err;
  4290. + char *conffiles_file_name;
  4291. + char *root_dir;
  4292. + FILE *conffiles_file;
  4293. +
  4294. + sprintf_alloc(&pkg->tmp_unpack_dir, "%s/%s-XXXXXX", conf->tmp_dir, pkg->name);
  4295. +
  4296. + pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir);
  4297. + if (pkg->tmp_unpack_dir == NULL) {
  4298. + ipkg_message(conf, IPKG_ERROR,
  4299. + "%s: Failed to create temporary directory '%s': %s\n",
  4300. + __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno));
  4301. + return errno;
  4302. + }
  4303. +
  4304. + err = pkg_extract_control_files_to_dir(pkg, pkg->tmp_unpack_dir);
  4305. + if (err) {
  4306. + return err;
  4307. + }
  4308. +
  4309. + /* XXX: CLEANUP: There might be a cleaner place to read in the
  4310. + conffiles. Seems like I should be able to get everything to go
  4311. + through pkg_init_from_file. If so, maybe it would make sense to
  4312. + move all of unpack_pkg_control_files to that function. */
  4313. +
  4314. + /* Don't need to re-read conffiles if we already have it */
  4315. + if (pkg->conffiles.head) {
  4316. + return 0;
  4317. + }
  4318. +
  4319. + sprintf_alloc(&conffiles_file_name, "%s/conffiles", pkg->tmp_unpack_dir);
  4320. + if (! file_exists(conffiles_file_name)) {
  4321. + free(conffiles_file_name);
  4322. + return 0;
  4323. + }
  4324. +
  4325. + conffiles_file = fopen(conffiles_file_name, "r");
  4326. + if (conffiles_file == NULL) {
  4327. + fprintf(stderr, "%s: failed to open %s: %s\n",
  4328. + __FUNCTION__, conffiles_file_name, strerror(errno));
  4329. + free(conffiles_file_name);
  4330. + return errno;
  4331. + }
  4332. + free(conffiles_file_name);
  4333. +
  4334. + while (1) {
  4335. + char *cf_name;
  4336. + char *cf_name_in_dest;
  4337. +
  4338. + cf_name = file_read_line_alloc(conffiles_file);
  4339. + if (cf_name == NULL) {
  4340. + break;
  4341. + }
  4342. + str_chomp(cf_name);
  4343. + if (cf_name[0] == '\0') {
  4344. + continue;
  4345. + }
  4346. +
  4347. + /* Prepend dest->root_dir to conffile name.
  4348. + Take pains to avoid multiple slashes. */
  4349. + root_dir = pkg->dest->root_dir;
  4350. + if (conf->offline_root)
  4351. + /* skip the offline_root prefix */
  4352. + root_dir = pkg->dest->root_dir + strlen(conf->offline_root);
  4353. + sprintf_alloc(&cf_name_in_dest, "%s%s", root_dir,
  4354. + cf_name[0] == '/' ? (cf_name + 1) : cf_name);
  4355. +
  4356. + /* Can't get an md5sum now, (file isn't extracted yet).
  4357. + We'll wait until resolve_conffiles */
  4358. + conffile_list_append(&pkg->conffiles, cf_name_in_dest, NULL);
  4359. +
  4360. + free(cf_name);
  4361. + free(cf_name_in_dest);
  4362. + }
  4363. +
  4364. + fclose(conffiles_file);
  4365. +
  4366. + return 0;
  4367. +}
  4368. +
  4369. +/* returns number of installed replacees */
  4370. +int pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees)
  4371. +{
  4372. + abstract_pkg_t **replaces = pkg->replaces;
  4373. + int replaces_count = pkg->replaces_count;
  4374. + int i, j;
  4375. + for (i = 0; i < replaces_count; i++) {
  4376. + abstract_pkg_t *ab_pkg = replaces[i];
  4377. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  4378. + if (pkg_vec) {
  4379. + for (j = 0; j < pkg_vec->len; j++) {
  4380. + pkg_t *replacee = pkg_vec->pkgs[j];
  4381. + if (!pkg_conflicts(pkg, replacee))
  4382. + continue;
  4383. + if (replacee->state_status == SS_INSTALLED) {
  4384. + pkg_vec_insert(installed_replacees, replacee);
  4385. + }
  4386. + }
  4387. + }
  4388. + }
  4389. + return installed_replacees->len;
  4390. +}
  4391. +
  4392. +int pkg_remove_installed_replacees(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4393. +{
  4394. + int i;
  4395. + int replaces_count = replacees->len;
  4396. + for (i = 0; i < replaces_count; i++) {
  4397. + pkg_t *replacee = replacees->pkgs[i];
  4398. + int err;
  4399. + replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */
  4400. + err = ipkg_remove_pkg(conf, replacee,0);
  4401. + if (err)
  4402. + return err;
  4403. + }
  4404. + return 0;
  4405. +}
  4406. +
  4407. +/* to unwind the removal: make sure they are installed */
  4408. +int pkg_remove_installed_replacees_unwind(ipkg_conf_t *conf, pkg_vec_t *replacees)
  4409. +{
  4410. + int i, err;
  4411. + int replaces_count = replacees->len;
  4412. + for (i = 0; i < replaces_count; i++) {
  4413. + pkg_t *replacee = replacees->pkgs[i];
  4414. + if (replacee->state_status != SS_INSTALLED) {
  4415. + ipkg_message(conf, IPKG_DEBUG2,"Function: %s calling ipkg_install_pkg \n",__FUNCTION__);
  4416. + err = ipkg_install_pkg(conf, replacee,0);
  4417. + if (err)
  4418. + return err;
  4419. + }
  4420. + }
  4421. + return 0;
  4422. +}
  4423. +
  4424. +int caught_sigint = 0;
  4425. +static void ipkg_install_pkg_sigint_handler(int sig)
  4426. +{
  4427. + caught_sigint = sig;
  4428. +}
  4429. +
  4430. +/* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */
  4431. +static int ipkg_install_check_downgrade(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message)
  4432. +{
  4433. + if (old_pkg) {
  4434. + char message_out[15];
  4435. + char *old_version = pkg_version_str_alloc(old_pkg);
  4436. + char *new_version = pkg_version_str_alloc(pkg);
  4437. + int cmp = pkg_compare_versions(old_pkg, pkg);
  4438. + int rc = 0;
  4439. +
  4440. + memset(message_out,'\x0',15);
  4441. + strncpy (message_out,"Upgrading ",strlen("Upgrading "));
  4442. + if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */
  4443. + cmp = -1 ; /* then we force ipkg to downgrade */
  4444. + strncpy (message_out,"Downgrading ",strlen("Downgrading ")); /* We need to use a value < 0 because in the 0 case we are asking to */
  4445. + /* reinstall, and some check could fail asking the "force-reinstall" option */
  4446. + }
  4447. +
  4448. + if (cmp > 0) {
  4449. + ipkg_message(conf, IPKG_NOTICE,
  4450. + "Not downgrading package %s on %s from %s to %s.\n",
  4451. + old_pkg->name, old_pkg->dest->name, old_version, new_version);
  4452. + rc = 1;
  4453. + } else if (cmp < 0) {
  4454. + ipkg_message(conf, IPKG_NOTICE,
  4455. + "%s%s on %s from %s to %s...\n",
  4456. + message_out, pkg->name, old_pkg->dest->name, old_version, new_version);
  4457. + pkg->dest = old_pkg->dest;
  4458. + rc = 0;
  4459. + } else /* cmp == 0 */ {
  4460. + if (conf->force_reinstall) {
  4461. + ipkg_message(conf, IPKG_NOTICE,
  4462. + "Reinstalling %s (%s) on %s...\n",
  4463. + pkg->name, new_version, old_pkg->dest->name);
  4464. + pkg->dest = old_pkg->dest;
  4465. + rc = 0;
  4466. + } else {
  4467. + ipkg_message(conf, IPKG_NOTICE,
  4468. + "Not installing %s (%s) on %s -- already installed.\n",
  4469. + pkg->name, new_version, old_pkg->dest->name);
  4470. + rc = 1;
  4471. + }
  4472. + }
  4473. + free(old_version);
  4474. + free(new_version);
  4475. + return rc;
  4476. + } else {
  4477. + char message_out[15], *version ;
  4478. + memset(message_out,'\x0',15);
  4479. + if ( message )
  4480. + strncpy( message_out,"Upgrading ",strlen("Upgrading ") );
  4481. + else
  4482. + strncpy( message_out,"Installing ",strlen("Installing ") );
  4483. + version = pkg_version_str_alloc(pkg);
  4484. +
  4485. + ipkg_message(conf, IPKG_NOTICE,
  4486. + "%s%s (%s) to %s...\n", message_out,
  4487. + pkg->name, version, pkg->dest->name);
  4488. + free(version);
  4489. + return 0;
  4490. + }
  4491. +}
  4492. +
  4493. +/* and now the meat... */
  4494. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
  4495. +{
  4496. + int err = 0;
  4497. + int message = 0;
  4498. + pkg_t *old_pkg = NULL;
  4499. + pkg_vec_t *replacees;
  4500. + abstract_pkg_t *ab_pkg = NULL;
  4501. + int old_state_flag;
  4502. + uint8_t *file_md5;
  4503. +
  4504. +
  4505. + if ( from_upgrade )
  4506. + message = 1; /* Coming from an upgrade, and should change the output message */
  4507. +
  4508. + if (!pkg) {
  4509. + ipkg_message(conf, IPKG_ERROR,
  4510. + "INTERNAL ERROR: null pkg passed to ipkg_install_pkg\n");
  4511. + return -EINVAL;
  4512. + }
  4513. +
  4514. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__);
  4515. +
  4516. + if (!pkg_arch_supported(conf, pkg)) {
  4517. + ipkg_message(conf, IPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n",
  4518. + pkg->architecture, pkg->name);
  4519. + return -EINVAL;
  4520. + }
  4521. + if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) {
  4522. + err = satisfy_dependencies_for(conf, pkg);
  4523. + if (err) { return err; }
  4524. +
  4525. + ipkg_message(conf, IPKG_NOTICE,
  4526. + "Package %s is already installed in %s.\n",
  4527. + pkg->name, pkg->dest->name);
  4528. + return 0;
  4529. + }
  4530. +
  4531. + if (pkg->dest == NULL) {
  4532. + pkg->dest = conf->default_dest;
  4533. + }
  4534. +
  4535. + old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name);
  4536. +
  4537. + err = ipkg_install_check_downgrade(conf, pkg, old_pkg, message);
  4538. + if (err) { return err; }
  4539. +
  4540. + pkg->state_want = SW_INSTALL;
  4541. + if (old_pkg){
  4542. + old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */
  4543. + }
  4544. +
  4545. +
  4546. + /* Abhaya: conflicts check */
  4547. + err = check_conflicts_for(conf, pkg);
  4548. + if (err) { return err; }
  4549. +
  4550. + /* this setup is to remove the upgrade scenario in the end when
  4551. + installing pkg A, A deps B & B deps on A. So both B and A are
  4552. + installed. Then A's installation is started resulting in an
  4553. + uncecessary upgrade */
  4554. + if (pkg->state_status == SS_INSTALLED
  4555. + && conf->force_reinstall == 0) return 0;
  4556. +
  4557. + err = verify_pkg_installable(conf, pkg);
  4558. + if (err) { return err; }
  4559. +
  4560. + if (pkg->local_filename == NULL) {
  4561. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  4562. + if (err) {
  4563. + ipkg_message(conf, IPKG_ERROR,
  4564. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  4565. + pkg->name);
  4566. + return err;
  4567. + }
  4568. + }
  4569. +
  4570. +/* Check for md5 values */
  4571. + if (pkg->md5sum)
  4572. + {
  4573. + file_md5 = file_md5sum_alloc(pkg->local_filename);
  4574. + if (strcmp((char *)file_md5, pkg->md5sum))
  4575. + {
  4576. + ipkg_message(conf, IPKG_ERROR,
  4577. + "Package %s md5sum mismatch. Either the ipkg or the package index are corrupt. Try 'ipkg update'.\n",
  4578. + pkg->name);
  4579. + free(file_md5);
  4580. + return err;
  4581. + }
  4582. + free(file_md5);
  4583. + }
  4584. +
  4585. + if (pkg->tmp_unpack_dir == NULL) {
  4586. + unpack_pkg_control_files(conf, pkg);
  4587. + }
  4588. +
  4589. + /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */
  4590. +/* Pigi: check if it will pass from here when replacing. It seems to fail */
  4591. +/* That's rather strange that files don't change owner. Investigate !!!!!!*/
  4592. + err = update_file_ownership(conf, pkg, old_pkg);
  4593. + if (err) { return err; }
  4594. +
  4595. + if (conf->nodeps == 0) {
  4596. + err = satisfy_dependencies_for(conf, pkg);
  4597. + if (err) { return err; }
  4598. + }
  4599. +
  4600. + replacees = pkg_vec_alloc();
  4601. + pkg_get_installed_replacees(pkg, replacees);
  4602. +
  4603. + /* this next section we do with SIGINT blocked to prevent inconsistency between ipkg database and filesystem */
  4604. + {
  4605. + sigset_t newset, oldset;
  4606. + sighandler_t old_handler = NULL;
  4607. + int use_signal = 0;
  4608. + caught_sigint = 0;
  4609. + if (use_signal) {
  4610. + old_handler = signal(SIGINT, ipkg_install_pkg_sigint_handler);
  4611. + } else {
  4612. + sigemptyset(&newset);
  4613. + sigaddset(&newset, SIGINT);
  4614. + sigprocmask(SIG_BLOCK, &newset, &oldset);
  4615. + }
  4616. +
  4617. + ipkg_state_changed++;
  4618. + pkg->state_flag |= SF_FILELIST_CHANGED;
  4619. +
  4620. + /* XXX: BUG: we really should treat replacement more like an upgrade
  4621. + * Instead, we're going to remove the replacees
  4622. + */
  4623. + err = pkg_remove_installed_replacees(conf, replacees);
  4624. + if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES;
  4625. +
  4626. + /*
  4627. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  4628. + if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG;
  4629. +
  4630. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  4631. + if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS;
  4632. + */
  4633. +
  4634. + err = preinst_configure(conf, pkg, old_pkg);
  4635. + /*
  4636. + if (err) goto UNWIND_PREINST_CONFIGURE;
  4637. + */
  4638. +
  4639. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  4640. + if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES;
  4641. +
  4642. + err = check_data_file_clashes(conf, pkg, old_pkg);
  4643. + /*
  4644. + if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES;
  4645. +
  4646. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  4647. + if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG;
  4648. + */
  4649. +
  4650. + if (conf->noaction) return 0;
  4651. +
  4652. + /* point of no return: no unwinding after this */
  4653. + if (old_pkg && !conf->force_reinstall) {
  4654. + old_pkg->state_want = SW_DEINSTALL;
  4655. +
  4656. + if (old_pkg->state_flag & SF_NOPRUNE) {
  4657. + ipkg_message(conf, IPKG_INFO,
  4658. + " not removing obsolesced files because package marked noprune\n");
  4659. + } else {
  4660. + ipkg_message(conf, IPKG_INFO,
  4661. + " removing obsolesced files\n");
  4662. + remove_obsolesced_files(conf, pkg, old_pkg);
  4663. + }
  4664. + /* removing files from old package, to avoid ghost files */
  4665. + remove_data_files_and_list(conf, old_pkg);
  4666. +/* Pigi : It should be better to remove also maintainer and postrem scripts here, just in case*/
  4667. + remove_maintainer_scripts_except_postrm(conf, old_pkg);
  4668. + remove_postrm(conf, old_pkg);
  4669. +/* Pigi */
  4670. +
  4671. + }
  4672. +
  4673. +
  4674. + ipkg_message(conf, IPKG_INFO,
  4675. + " installing maintainer scripts\n");
  4676. + install_maintainer_scripts(conf, pkg, old_pkg);
  4677. +
  4678. + /* the following just returns 0
  4679. + remove_disappeared(conf, pkg);
  4680. + */
  4681. +
  4682. + ipkg_message(conf, IPKG_INFO,
  4683. + " installing data files\n");
  4684. + install_data_files(conf, pkg);
  4685. +
  4686. +/* read comments from function for detail but I will execute this here as all other tests are ok.*/
  4687. + err = check_data_file_clashes_change(conf, pkg);
  4688. +
  4689. + ipkg_message(conf, IPKG_INFO,
  4690. + " resolving conf files\n");
  4691. + resolve_conffiles(conf, pkg);
  4692. +
  4693. + pkg->state_status = SS_UNPACKED;
  4694. + old_state_flag = pkg->state_flag;
  4695. + pkg->state_flag &= ~SF_PREFER;
  4696. + ipkg_message(conf, IPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag);
  4697. +
  4698. + if (old_pkg && !conf->force_reinstall) {
  4699. + old_pkg->state_status = SS_NOT_INSTALLED;
  4700. + }
  4701. +
  4702. + time(&pkg->installed_time);
  4703. +
  4704. + ipkg_message(conf, IPKG_INFO,
  4705. + " cleanup temp files\n");
  4706. + cleanup_temporary_files(conf, pkg);
  4707. +
  4708. + ab_pkg = pkg->parent;
  4709. + if (ab_pkg)
  4710. + ab_pkg->state_status = pkg->state_status;
  4711. +
  4712. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  4713. +
  4714. + if (use_signal)
  4715. + signal(SIGINT, old_handler);
  4716. + else
  4717. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4718. +
  4719. + return 0;
  4720. +
  4721. +
  4722. + /*
  4723. + UNWIND_POSTRM_UPGRADE_OLD_PKG:
  4724. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4725. + UNWIND_CHECK_DATA_FILE_CLASHES:
  4726. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  4727. + */
  4728. + UNWIND_BACKUP_MODIFIED_CONFFILES:
  4729. + backup_modified_conffiles_unwind(pkg, old_pkg);
  4730. + /*
  4731. + UNWIND_PREINST_CONFIGURE:
  4732. + preinst_configure_unwind(conf, pkg, old_pkg);
  4733. + UNWIND_PRERM_DECONFIGURE_CONFLICTORS:
  4734. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  4735. + UNWIND_PRERM_UPGRADE_OLD_PKG:
  4736. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  4737. + */
  4738. + UNWIND_REMOVE_INSTALLED_REPLACEES:
  4739. + pkg_remove_installed_replacees_unwind(conf, replacees);
  4740. +
  4741. + ipkg_message(conf, IPKG_INFO,
  4742. + " cleanup temp files\n");
  4743. + cleanup_temporary_files(conf, pkg);
  4744. +
  4745. + ipkg_message(conf, IPKG_INFO,
  4746. + "Failed.\n");
  4747. + if (use_signal)
  4748. + signal(SIGINT, old_handler);
  4749. + else
  4750. + sigprocmask(SIG_UNBLOCK, &newset, &oldset);
  4751. +
  4752. + return err;
  4753. + }
  4754. +}
  4755. +
  4756. +/*
  4757. +static int prerm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4758. +{
  4759. + DPKG_INCOMPATIBILITY:
  4760. + dpkg does some things here that we don't do yet. Do we care?
  4761. +
  4762. + 1. If a version of the package is already installed, call
  4763. + old-prerm upgrade new-version
  4764. + 2. If the script runs but exits with a non-zero exit status
  4765. + new-prerm failed-upgrade old-version
  4766. + Error unwind, for both the above cases:
  4767. + old-postinst abort-upgrade new-version
  4768. + return 0;
  4769. +}
  4770. +*/
  4771. +
  4772. +/*
  4773. +static int prerm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4774. +{
  4775. + DPKG_INCOMPATIBILITY:
  4776. + dpkg does some things here that we don't do yet. Do we care?
  4777. + (See prerm_upgrade_old_package for details)
  4778. +
  4779. + return 0;
  4780. +}
  4781. +*/
  4782. +
  4783. +/*
  4784. +static int prerm_deconfigure_conflictors(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4785. +{
  4786. + DPKG_INCOMPATIBILITY:
  4787. + dpkg does some things here that we don't do yet. Do we care?
  4788. + 2. If a 'conflicting' package is being removed at the same time:
  4789. + 1. If any packages depended on that conflicting package and
  4790. + --auto-deconfigure is specified, call, for each such package:
  4791. + deconfigured's-prerm deconfigure \
  4792. + in-favour package-being-installed version \
  4793. + removing conflicting-package version
  4794. + Error unwind:
  4795. + deconfigured's-postinst abort-deconfigure \
  4796. + in-favour package-being-installed-but-failed version \
  4797. + removing conflicting-package version
  4798. +
  4799. + The deconfigured packages are marked as requiring
  4800. + configuration, so that if --install is used they will be
  4801. + configured again if possible.
  4802. + 2. To prepare for removal of the conflicting package, call:
  4803. + conflictor's-prerm remove in-favour package new-version
  4804. + Error unwind:
  4805. + conflictor's-postinst abort-remove in-favour package new-version
  4806. + return 0;
  4807. +}
  4808. +*/
  4809. +
  4810. +/*
  4811. +static int prerm_deconfigure_conflictors_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors)
  4812. +{
  4813. + DPKG_INCOMPATIBILITY: dpkg does some things here that we don't
  4814. + do yet. Do we care? (See prerm_deconfigure_conflictors for
  4815. + details)
  4816. + return 0;
  4817. +}
  4818. +*/
  4819. +
  4820. +static int preinst_configure(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4821. +{
  4822. + int err;
  4823. + char *preinst_args;
  4824. +
  4825. + if (old_pkg) {
  4826. + char *old_version = pkg_version_str_alloc(old_pkg);
  4827. + sprintf_alloc(&preinst_args, "upgrade %s", old_version);
  4828. + free(old_version);
  4829. + } else if (pkg->state_status == SS_CONFIG_FILES) {
  4830. + char *pkg_version = pkg_version_str_alloc(pkg);
  4831. + sprintf_alloc(&preinst_args, "install %s", pkg_version);
  4832. + free(pkg_version);
  4833. + } else {
  4834. + preinst_args = strdup("install");
  4835. + }
  4836. +
  4837. + err = pkg_run_script(conf, pkg, "preinst", preinst_args);
  4838. + if (err) {
  4839. + ipkg_message(conf, IPKG_ERROR,
  4840. + "Aborting installation of %s\n", pkg->name);
  4841. + return 1;
  4842. + }
  4843. +
  4844. + free(preinst_args);
  4845. +
  4846. + return 0;
  4847. +}
  4848. +
  4849. +/*
  4850. +static int preinst_configure_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4851. +{
  4852. + DPKG_INCOMPATIBILITY:
  4853. + dpkg does the following error unwind, should we?
  4854. + pkg->postrm abort-upgrade old-version
  4855. + OR pkg->postrm abort-install old-version
  4856. + OR pkg->postrm abort-install
  4857. + return 0;
  4858. +}
  4859. +*/
  4860. +
  4861. +static int backup_modified_conffiles(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4862. +{
  4863. + int err;
  4864. + conffile_list_elt_t *iter;
  4865. + conffile_t *cf;
  4866. +
  4867. + if (conf->noaction) return 0;
  4868. +
  4869. + /* Backup all modified conffiles */
  4870. + if (old_pkg) {
  4871. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4872. + char *cf_name;
  4873. +
  4874. + cf = iter->data;
  4875. + cf_name = root_filename_alloc(conf, cf->name);
  4876. +
  4877. + /* Don't worry if the conffile is just plain gone */
  4878. + if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) {
  4879. + err = backup_make_backup(conf, cf_name);
  4880. + if (err) {
  4881. + return err;
  4882. + }
  4883. + }
  4884. + free(cf_name);
  4885. + }
  4886. + }
  4887. +
  4888. + /* Backup all conffiles that were not conffiles in old_pkg */
  4889. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4890. + char *cf_name;
  4891. + cf = iter->data;
  4892. + cf_name = root_filename_alloc(conf, cf->name);
  4893. + /* Ignore if this was a conffile in old_pkg as well */
  4894. + if (pkg_get_conffile(old_pkg, cf->name)) {
  4895. + continue;
  4896. + }
  4897. +
  4898. + if (file_exists(cf_name) && (! backup_exists_for(cf_name))) {
  4899. + err = backup_make_backup(conf, cf_name);
  4900. + if (err) {
  4901. + return err;
  4902. + }
  4903. + }
  4904. + free(cf_name);
  4905. + }
  4906. +
  4907. + return 0;
  4908. +}
  4909. +
  4910. +static int backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg)
  4911. +{
  4912. + conffile_list_elt_t *iter;
  4913. +
  4914. + if (old_pkg) {
  4915. + for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
  4916. + backup_remove(iter->data->name);
  4917. + }
  4918. + }
  4919. +
  4920. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  4921. + backup_remove(iter->data->name);
  4922. + }
  4923. +
  4924. + return 0;
  4925. +}
  4926. +
  4927. +
  4928. +static int check_data_file_clashes(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  4929. +{
  4930. + /* DPKG_INCOMPATIBILITY:
  4931. + ipkg takes a slightly different approach than dpkg at this
  4932. + point. dpkg installs each file in the new package while
  4933. + creating a backup for any file that is replaced, (so that it
  4934. + can unwind if necessary). To avoid complexity and redundant
  4935. + storage, ipkg doesn't do any installation until later, (at the
  4936. + point at which dpkg removes the backups.
  4937. +
  4938. + But, we do have to check for data file clashes, since after
  4939. + installing a package with a file clash, removing either of the
  4940. + packages involved in the clash has the potential to break the
  4941. + other package.
  4942. + */
  4943. + str_list_t *files_list;
  4944. + str_list_elt_t *iter;
  4945. +
  4946. + int clashes = 0;
  4947. +
  4948. + files_list = pkg_get_installed_files(pkg);
  4949. + for (iter = files_list->head; iter; iter = iter->next) {
  4950. + char *root_filename;
  4951. + char *filename = iter->data;
  4952. + root_filename = root_filename_alloc(conf, filename);
  4953. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  4954. + pkg_t *owner;
  4955. + pkg_t *obs;
  4956. + /* Pre-existing conffiles are OK */
  4957. + /* @@@@ should have way to check that it is a conffile -Jamey */
  4958. + if (backup_exists_for(root_filename)) {
  4959. + continue;
  4960. + }
  4961. +
  4962. + /* Pre-existing files are OK if force-overwrite was asserted. */
  4963. + if (conf->force_overwrite) {
  4964. + /* but we need to change who owns this file */
  4965. + file_hash_set_file_owner(conf, filename, pkg);
  4966. + continue;
  4967. + }
  4968. +
  4969. + owner = file_hash_get_file_owner(conf, filename);
  4970. +
  4971. + /* Pre-existing files are OK if owned by the pkg being upgraded. */
  4972. + if (owner && old_pkg) {
  4973. + if (strcmp(owner->name, old_pkg->name) == 0) {
  4974. + continue;
  4975. + }
  4976. + }
  4977. +
  4978. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  4979. + if (owner) {
  4980. + ipkg_message(conf, IPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name);
  4981. + if (pkg_replaces(pkg, owner)) {
  4982. + continue;
  4983. + }
  4984. +/* If the file that would be installed is owned by the same package, ( as per a reinstall or similar )
  4985. + then it's ok to overwrite. */
  4986. + if (strcmp(owner->name,pkg->name)==0){
  4987. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  4988. + continue;
  4989. + }
  4990. + }
  4991. +
  4992. + /* Pre-existing files are OK if they are obsolete */
  4993. + obs = hash_table_get(&conf->obs_file_hash, filename);
  4994. + if (obs) {
  4995. + ipkg_message(conf, IPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name);
  4996. + continue;
  4997. + }
  4998. +
  4999. + /* We have found a clash. */
  5000. + ipkg_message(conf, IPKG_ERROR,
  5001. + "Package %s wants to install file %s\n"
  5002. + "\tBut that file is already provided by package ",
  5003. + pkg->name, filename);
  5004. + if (owner) {
  5005. + ipkg_message(conf, IPKG_ERROR,
  5006. + "%s\n", owner->name);
  5007. + } else {
  5008. + ipkg_message(conf, IPKG_ERROR,
  5009. + "<no package>\nPlease move this file out of the way and try again.\n");
  5010. + }
  5011. + clashes++;
  5012. + }
  5013. + free(root_filename);
  5014. + }
  5015. + pkg_free_installed_files(pkg);
  5016. +
  5017. + return clashes;
  5018. +}
  5019. +
  5020. +static int check_data_file_clashes_change(ipkg_conf_t *conf, pkg_t *pkg)
  5021. +{
  5022. + /* Basically that's the worst hack I could do to be able to change ownership of
  5023. + file list, but, being that we have no way to unwind the mods, due to structure
  5024. + of hash table, probably is the quickest hack too, whishing it would not slow-up thing too much.
  5025. + What we do here is change the ownership of file in hash if a replace ( or similar events
  5026. + happens )
  5027. + Only the action that are needed to change name should be considered.
  5028. + @@@ To change after 1.0 release.
  5029. + */
  5030. + str_list_t *files_list;
  5031. + str_list_elt_t *iter;
  5032. +
  5033. + int clashes = 0;
  5034. +
  5035. + files_list = pkg_get_installed_files(pkg);
  5036. + for (iter = files_list->head; iter; iter = iter->next) {
  5037. + char *root_filename;
  5038. + char *filename = iter->data;
  5039. + root_filename = root_filename_alloc(conf, filename);
  5040. + if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
  5041. + pkg_t *owner;
  5042. +
  5043. + if (conf->force_overwrite) {
  5044. + /* but we need to change who owns this file */
  5045. + file_hash_set_file_owner(conf, filename, pkg);
  5046. + continue;
  5047. + }
  5048. +
  5049. + owner = file_hash_get_file_owner(conf, filename);
  5050. +
  5051. + /* Pre-existing files are OK if owned by a package replaced by new pkg. */
  5052. + if (owner) {
  5053. + if (pkg_replaces(pkg, owner)) {
  5054. +/* It's now time to change the owner of that file.
  5055. + It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */
  5056. + ipkg_message(conf, IPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name);
  5057. + file_hash_set_file_owner(conf, filename, pkg);
  5058. + continue;
  5059. + }
  5060. + }
  5061. +
  5062. + }
  5063. + free(root_filename);
  5064. + }
  5065. + pkg_free_installed_files(pkg);
  5066. +
  5067. + return clashes;
  5068. +}
  5069. +
  5070. +/*
  5071. +static int check_data_file_clashes_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5072. +{
  5073. + Nothing to do since check_data_file_clashes doesn't change state
  5074. + return 0;
  5075. +}
  5076. +*/
  5077. +
  5078. +/*
  5079. +static int postrm_upgrade_old_pkg(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5080. +{
  5081. + DPKG_INCOMPATIBILITY: dpkg does the following here, should we?
  5082. + 1. If the package is being upgraded, call
  5083. + old-postrm upgrade new-version
  5084. + 2. If this fails, attempt:
  5085. + new-postrm failed-upgrade old-version
  5086. + Error unwind, for both cases:
  5087. + old-preinst abort-upgrade new-version
  5088. + return 0;
  5089. +}
  5090. +*/
  5091. +
  5092. +/*
  5093. +static int postrm_upgrade_old_pkg_unwind(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5094. +{
  5095. + DPKG_INCOMPATIBILITY:
  5096. + dpkg does some things here that we don't do yet. Do we care?
  5097. + (See postrm_upgrade_old_pkg for details)
  5098. + return 0;
  5099. +}
  5100. +*/
  5101. +
  5102. +static int remove_obsolesced_files(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5103. +{
  5104. + int err;
  5105. + str_list_t *old_files;
  5106. + str_list_elt_t *of;
  5107. + str_list_t *new_files;
  5108. + str_list_elt_t *nf;
  5109. +
  5110. + if (old_pkg == NULL) {
  5111. + return 0;
  5112. + }
  5113. +
  5114. + old_files = pkg_get_installed_files(old_pkg);
  5115. + new_files = pkg_get_installed_files(pkg);
  5116. +
  5117. + for (of = old_files->head; of; of = of->next) {
  5118. + pkg_t *owner;
  5119. + char *old, *new;
  5120. + old = of->data;
  5121. + for (nf = new_files->head; nf; nf = nf->next) {
  5122. + new = nf->data;
  5123. + if (strcmp(old, new) == 0) {
  5124. + goto NOT_OBSOLETE;
  5125. + }
  5126. + }
  5127. + if (file_is_dir(old)) {
  5128. + continue;
  5129. + }
  5130. + owner = file_hash_get_file_owner(conf, old);
  5131. + if (owner != old_pkg) {
  5132. + /* in case obsolete file no longer belongs to old_pkg */
  5133. + continue;
  5134. + }
  5135. +
  5136. + /* old file is obsolete */
  5137. + ipkg_message(conf, IPKG_INFO,
  5138. + " removing obsolete file %s\n", old);
  5139. + if (!conf->noaction) {
  5140. + err = unlink(old);
  5141. + if (err) {
  5142. + ipkg_message(conf, IPKG_ERROR, " Warning: remove %s failed: %s\n", old,
  5143. + strerror(errno));
  5144. + }
  5145. + }
  5146. +
  5147. + NOT_OBSOLETE:
  5148. + ;
  5149. + }
  5150. +
  5151. + pkg_free_installed_files(old_pkg);
  5152. + pkg_free_installed_files(pkg);
  5153. +
  5154. + return 0;
  5155. +}
  5156. +
  5157. +static int remove_obsolete_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5158. +{
  5159. + int i;
  5160. + int err = 0;
  5161. + char *globpattern;
  5162. + glob_t globbuf;
  5163. + if (0) {
  5164. + if (!pkg->dest) {
  5165. + ipkg_message(conf, IPKG_ERROR, "%s: no dest for package %s\n", __FUNCTION__, pkg->name);
  5166. + return -1;
  5167. + }
  5168. + sprintf_alloc(&globpattern, "%s/%s.*", pkg->dest->info_dir, pkg->name);
  5169. + err = glob(globpattern, 0, NULL, &globbuf);
  5170. + free(globpattern);
  5171. + if (err) {
  5172. + return err;
  5173. + }
  5174. + /* XXXX this should perhaps only remove the ones that are not overwritten in new package. Jamey 11/11/2003 */
  5175. + for (i = 0; i < globbuf.gl_pathc; i++) {
  5176. + ipkg_message(conf, IPKG_DEBUG, "Removing control file %s from old_pkg %s\n",
  5177. + globbuf.gl_pathv[i], old_pkg->name);
  5178. + if (!conf->noaction)
  5179. + unlink(globbuf.gl_pathv[i]);
  5180. + }
  5181. + globfree(&globbuf);
  5182. + }
  5183. + return err;
  5184. +}
  5185. +
  5186. +static int install_maintainer_scripts(ipkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)
  5187. +{
  5188. + int ret;
  5189. + char *prefix;
  5190. +
  5191. + if (old_pkg)
  5192. + remove_obsolete_maintainer_scripts(conf, pkg, old_pkg);
  5193. + sprintf_alloc(&prefix, "%s.", pkg->name);
  5194. + ret = pkg_extract_control_files_to_dir_with_prefix(pkg,
  5195. + pkg->dest->info_dir,
  5196. + prefix);
  5197. + free(prefix);
  5198. + return ret;
  5199. +}
  5200. +
  5201. +/*
  5202. +static int remove_disappeared(ipkg_conf_t *conf, pkg_t *pkg)
  5203. +{
  5204. + DPKG_INCOMPATIBILITY:
  5205. + This is a fairly sophisticated dpkg operation. Shall we
  5206. + skip it?
  5207. +
  5208. + Any packages all of whose files have been overwritten during the
  5209. + installation, and which aren't required for dependencies, are
  5210. + considered to have been removed. For each such package
  5211. + 1. disappearer's-postrm disappear overwriter overwriter-version
  5212. + 2. The package's maintainer scripts are removed
  5213. + 3. It is noted in the status database as being in a sane state,
  5214. + namely not installed (any conffiles it may have are ignored,
  5215. + rather than being removed by dpkg). Note that disappearing
  5216. + packages do not have their prerm called, because dpkg doesn't
  5217. + know in advance that the package is going to vanish.
  5218. +
  5219. +
  5220. + return 0;
  5221. +}
  5222. +*/
  5223. +
  5224. +static int install_data_files(ipkg_conf_t *conf, pkg_t *pkg)
  5225. +{
  5226. + int err;
  5227. +
  5228. + /* ipkg takes a slightly different approach to data file backups
  5229. + than dpkg. Rather than removing backups at this point, we
  5230. + actually do the data file installation now. See comments in
  5231. + check_data_file_clashes() for more details. */
  5232. +
  5233. + ipkg_message(conf, IPKG_INFO,
  5234. + " extracting data files to %s\n", pkg->dest->root_dir);
  5235. + err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir);
  5236. + if (err) {
  5237. + return err;
  5238. + }
  5239. +
  5240. + /* XXX: BUG or FEATURE : We are actually loosing the Essential flag,
  5241. + so we can't save ourself from removing important packages
  5242. + At this point we (should) have extracted the .control file, so it
  5243. + would be a good idea to reload the data in it, and set the Essential
  5244. + state in *pkg. From now on the Essential is back in status file and
  5245. + we can protect again.
  5246. + We should operate this way:
  5247. + fopen the file ( pkg->dest->root_dir/pkg->name.control )
  5248. + check for "Essential" in it
  5249. + set the value in pkg->essential.
  5250. + This new routine could be useful also for every other flag
  5251. + Pigi: 16/03/2004 */
  5252. + set_flags_from_control(conf, pkg) ;
  5253. +
  5254. + ipkg_message(conf, IPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__);
  5255. + err = pkg_write_filelist(conf, pkg);
  5256. + if (err)
  5257. + return err;
  5258. +
  5259. + /* XXX: FEATURE: ipkg should identify any files which existed
  5260. + before installation and which were overwritten, (see
  5261. + check_data_file_clashes()). What it must do is remove any such
  5262. + files from the filelist of the old package which provided the
  5263. + file. Otherwise, if the old package were removed at some point
  5264. + it would break the new package. Removing the new package will
  5265. + also break the old one, but this cannot be helped since the old
  5266. + package's file has already been deleted. This is the importance
  5267. + of check_data_file_clashes(), and only allowing ipkg to install
  5268. + a clashing package with a user force. */
  5269. +
  5270. + return 0;
  5271. +}
  5272. +
  5273. +static int resolve_conffiles(ipkg_conf_t *conf, pkg_t *pkg)
  5274. +{
  5275. + conffile_list_elt_t *iter;
  5276. + conffile_t *cf;
  5277. + char *cf_backup;
  5278. + uint8_t *md5sum;
  5279. +
  5280. +
  5281. + if (conf->noaction) return 0;
  5282. +
  5283. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  5284. + char *root_filename;
  5285. + cf = iter->data;
  5286. + root_filename = root_filename_alloc(conf, cf->name);
  5287. +
  5288. + /* Might need to initialize the md5sum for each conffile */
  5289. + if (cf->value == NULL) {
  5290. + cf->value = (char *)file_md5sum_alloc(root_filename);
  5291. + }
  5292. +
  5293. + if (!file_exists(root_filename)) {
  5294. + free(root_filename);
  5295. + continue;
  5296. + }
  5297. +
  5298. + cf_backup = backup_filename_alloc(root_filename);
  5299. +
  5300. +
  5301. + if (file_exists(cf_backup)) {
  5302. + /* Let's compute md5 to test if files are changed */
  5303. + md5sum = file_md5sum_alloc(cf_backup);
  5304. + if (strcmp( cf->value, (char *)md5sum) != 0 ) {
  5305. + if (conf->force_defaults
  5306. + || user_prefers_old_conffile(cf->name, cf_backup) ) {
  5307. + rename(cf_backup, root_filename);
  5308. + }
  5309. + }
  5310. + unlink(cf_backup);
  5311. + free(md5sum);
  5312. + }
  5313. +
  5314. + free(cf_backup);
  5315. + free(root_filename);
  5316. + }
  5317. +
  5318. + return 0;
  5319. +}
  5320. +
  5321. +static int user_prefers_old_conffile(const char *file_name, const char *backup)
  5322. +{
  5323. + char *response;
  5324. + const char *short_file_name;
  5325. +
  5326. + short_file_name = strrchr(file_name, '/');
  5327. + if (short_file_name) {
  5328. + short_file_name++;
  5329. + } else {
  5330. + short_file_name = file_name;
  5331. + }
  5332. +
  5333. + while (1) {
  5334. + response = get_user_response(" Configuration file '%s'\n"
  5335. + " ==> File on system created by you or by a script.\n"
  5336. + " ==> File also in package provided by package maintainer.\n"
  5337. + " What would you like to do about it ? Your options are:\n"
  5338. + " Y or I : install the package maintainer's version\n"
  5339. + " N or O : keep your currently-installed version\n"
  5340. +#ifdef CONFIG_DIFF
  5341. + " D : show the differences between the versions\n"
  5342. +#endif
  5343. + " The default action is to keep your current version.\n"
  5344. + " *** %s (Y/I/N/O"
  5345. +#ifdef CONFIG_DIFF
  5346. + "/D"
  5347. +#endif
  5348. + ") [default=N] ? ", file_name, short_file_name);
  5349. + if (strcmp(response, "y") == 0
  5350. + || strcmp(response, "i") == 0
  5351. + || strcmp(response, "yes") == 0) {
  5352. + free(response);
  5353. + return 0;
  5354. + }
  5355. +
  5356. +#ifdef CONFIG_DIFF
  5357. + if (strcmp(response, "d") == 0) {
  5358. + char *cmd;
  5359. +
  5360. + free(response);
  5361. + /* XXX: BUG rewrite to use exec or busybox's internal diff */
  5362. + sprintf_alloc(&cmd, "diff -u %s %s", backup, file_name);
  5363. + xsystem(cmd);
  5364. + free(cmd);
  5365. + printf(" [Press ENTER to continue]\n");
  5366. + response = file_read_line_alloc(stdin);
  5367. + free(response);
  5368. + continue;
  5369. + }
  5370. +#endif
  5371. +
  5372. + free(response);
  5373. + return 1;
  5374. + }
  5375. +}
  5376. +
  5377. +/* XXX: CLEANUP: I'd like to move all of the code for
  5378. + creating/cleaning pkg->tmp_unpack_dir directly into pkg.c. (Then,
  5379. + it would make sense to cleanup pkg->tmp_unpack_dir directly from
  5380. + pkg_deinit for example). */
  5381. +static int cleanup_temporary_files(ipkg_conf_t *conf, pkg_t *pkg)
  5382. +{
  5383. + DIR *tmp_dir;
  5384. + struct dirent *dirent;
  5385. + char *tmp_file;
  5386. +
  5387. +#ifdef IPKG_DEBUG_NO_TMP_CLEANUP
  5388. +#error
  5389. + ipkg_message(conf, IPKG_DEBUG,
  5390. + "%s: Not cleaning up %s since ipkg compiled with IPKG_DEBUG_NO_TMP_CLEANUP\n",
  5391. + __FUNCTION__, pkg->tmp_unpack_dir);
  5392. + return 0;
  5393. +#endif
  5394. +
  5395. + if (pkg->tmp_unpack_dir && file_is_dir(pkg->tmp_unpack_dir)) {
  5396. + tmp_dir = opendir(pkg->tmp_unpack_dir);
  5397. + if (tmp_dir) {
  5398. + while (1) {
  5399. + dirent = readdir(tmp_dir);
  5400. + if (dirent == NULL) {
  5401. + break;
  5402. + }
  5403. + sprintf_alloc(&tmp_file, "%s/%s",
  5404. + pkg->tmp_unpack_dir, dirent->d_name);
  5405. + if (! file_is_dir(tmp_file)) {
  5406. + unlink(tmp_file);
  5407. + }
  5408. + free(tmp_file);
  5409. + }
  5410. + closedir(tmp_dir);
  5411. + rmdir(pkg->tmp_unpack_dir);
  5412. + free(pkg->tmp_unpack_dir);
  5413. + pkg->tmp_unpack_dir = NULL;
  5414. + }
  5415. + }
  5416. +
  5417. + ipkg_message(conf, IPKG_INFO, "cleanup_temporary_files: pkg=%s local_filename=%s tmp_dir=%s\n",
  5418. + pkg->name, pkg->local_filename, conf->tmp_dir);
  5419. + if (pkg->local_filename && strncmp(pkg->local_filename, conf->tmp_dir, strlen(conf->tmp_dir)) == 0) {
  5420. + unlink(pkg->local_filename);
  5421. + free(pkg->local_filename);
  5422. + pkg->local_filename = NULL;
  5423. + }
  5424. +
  5425. + return 0;
  5426. +}
  5427. +
  5428. +static char *backup_filename_alloc(const char *file_name)
  5429. +{
  5430. + char *backup;
  5431. +
  5432. + sprintf_alloc(&backup, "%s%s", file_name, IPKG_BACKUP_SUFFIX);
  5433. +
  5434. + return backup;
  5435. +}
  5436. +
  5437. +int backup_make_backup(ipkg_conf_t *conf, const char *file_name)
  5438. +{
  5439. + int err;
  5440. + char *backup;
  5441. +
  5442. + backup = backup_filename_alloc(file_name);
  5443. + err = file_copy(file_name, backup);
  5444. + if (err) {
  5445. + ipkg_message(conf, IPKG_ERROR,
  5446. + "%s: Failed to copy %s to %s\n",
  5447. + __FUNCTION__, file_name, backup);
  5448. + }
  5449. +
  5450. + free(backup);
  5451. +
  5452. + return err;
  5453. +}
  5454. +
  5455. +static int backup_exists_for(const char *file_name)
  5456. +{
  5457. + int ret;
  5458. + char *backup;
  5459. +
  5460. + backup = backup_filename_alloc(file_name);
  5461. +
  5462. + ret = file_exists(backup);
  5463. +
  5464. + free(backup);
  5465. +
  5466. + return ret;
  5467. +}
  5468. +
  5469. +static int backup_remove(const char *file_name)
  5470. +{
  5471. + char *backup;
  5472. +
  5473. + backup = backup_filename_alloc(file_name);
  5474. + unlink(backup);
  5475. + free(backup);
  5476. +
  5477. + return 0;
  5478. +}
  5479. +
  5480. +
  5481. +
  5482. +#ifdef CONFIG_IPKG_PROCESS_ACTIONS
  5483. +
  5484. +int ipkg_remove_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove)
  5485. +{
  5486. + /* first, remove the packages that need removing */
  5487. + for (i = 0 ; i < pkgs_to_remove->len; i++ ) {
  5488. + pkg_t *pkg = pkgs_to_remove->pkgs[i];
  5489. + err = ipkg_remove_pkg(conf, pkg,0);
  5490. + if (err) return err;
  5491. + }
  5492. + return 0;
  5493. +}
  5494. +
  5495. +int ipkg_process_actions_sanity_check(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5496. +{
  5497. + int i;
  5498. + /* now one more pass checking on the ones that need to be installed */
  5499. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5500. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5501. + if (pkg->dest == NULL)
  5502. + pkg->dest = conf->default_dest;
  5503. +
  5504. + pkg->state_want = SW_INSTALL;
  5505. +
  5506. + /* Abhaya: conflicts check */
  5507. + err = check_conflicts_for(conf, pkg);
  5508. + if (err) { return err; }
  5509. + }
  5510. + return 0;
  5511. +}
  5512. +
  5513. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5514. +{
  5515. + int i;
  5516. + /* now one more pass checking on the ones that need to be installed */
  5517. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5518. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5519. +
  5520. + /* XXX: FEATURE: Need to really support Provides/Replaces: here at some point */
  5521. + pkg_vec_t *replacees = pkg_vec_alloc();
  5522. + pkg_get_installed_replacees(pkg, replacees);
  5523. +
  5524. + /* XXX: BUG: we really should treat replacement more like an upgrade
  5525. + * Instead, we're going to remove the replacees
  5526. + */
  5527. + err = pkg_remove_installed_replacees(conf, replacees);
  5528. + if (err) return err;
  5529. + pkg->state_flag |= SF_REMOVED_REPLACEES;
  5530. + }
  5531. + return 0;
  5532. +}
  5533. +
  5534. +int ipkg_process_actions_unpack_packages(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_to_install)
  5535. +{
  5536. + int i;
  5537. + /* now one more pass checking on the ones that need to be installed */
  5538. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5539. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5540. + if (pkg->local_filename == NULL) {
  5541. + err = ipkg_download_pkg(conf, pkg, conf->tmp_dir);
  5542. + if (err) {
  5543. + ipkg_message(conf, IPKG_ERROR,
  5544. + "Failed to download %s. Perhaps you need to run 'ipkg update'?\n",
  5545. + pkg->name);
  5546. + return err;
  5547. + }
  5548. + }
  5549. + if (pkg->tmp_unpack_dir == NULL) {
  5550. + err = unpack_pkg_control_files(conf, pkg);
  5551. + if (err) return err;
  5552. + }
  5553. + }
  5554. + return 0;
  5555. +}
  5556. +
  5557. +int ipkg_process_actions_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5558. +{
  5559. + int i;
  5560. + /* now one more pass checking on the ones that need to be installed */
  5561. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5562. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5563. + pkg_t *old_pkg = pkg->old_pkg;
  5564. +
  5565. + err = prerm_upgrade_old_pkg(conf, pkg, old_pkg);
  5566. + if (err) return err;
  5567. +
  5568. + err = prerm_deconfigure_conflictors(conf, pkg, replacees);
  5569. + if (err) return err;
  5570. +
  5571. + err = preinst_configure(conf, pkg, old_pkg);
  5572. + if (err) return err;
  5573. +
  5574. + err = backup_modified_conffiles(conf, pkg, old_pkg);
  5575. + if (err) return err;
  5576. +
  5577. + err = postrm_upgrade_old_pkg(conf, pkg, old_pkg);
  5578. + if (err) return err;
  5579. + }
  5580. + return 0;
  5581. +}
  5582. +
  5583. +int ipkg_process_actions_install(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5584. +{
  5585. + int i;
  5586. + /* now one more pass checking on the ones that need to be installed */
  5587. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5588. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5589. + pkg_t *old_pkg = pkg->old_pkg;
  5590. +
  5591. + if (old_pkg) {
  5592. + old_pkg->state_want = SW_DEINSTALL;
  5593. +
  5594. + if (old_pkg->state_flag & SF_NOPRUNE) {
  5595. + ipkg_message(conf, IPKG_INFO,
  5596. + " not removing obsolesced files because package marked noprune\n");
  5597. + } else {
  5598. + ipkg_message(conf, IPKG_INFO,
  5599. + " removing obsolesced files\n");
  5600. + remove_obsolesced_files(conf, pkg, old_pkg);
  5601. + }
  5602. + }
  5603. +
  5604. + ipkg_message(conf, IPKG_INFO,
  5605. + " installing maintainer scripts\n");
  5606. + install_maintainer_scripts(conf, pkg, old_pkg);
  5607. +
  5608. + /* the following just returns 0 */
  5609. + remove_disappeared(conf, pkg);
  5610. +
  5611. + ipkg_message(conf, IPKG_INFO,
  5612. + " installing data files\n");
  5613. + install_data_files(conf, pkg);
  5614. +
  5615. + ipkg_message(conf, IPKG_INFO,
  5616. + " resolving conf files\n");
  5617. + resolve_conffiles(conf, pkg);
  5618. +
  5619. + pkg->state_status = SS_UNPACKED;
  5620. +
  5621. + if (old_pkg) {
  5622. + old_pkg->state_status = SS_NOT_INSTALLED;
  5623. + }
  5624. +
  5625. + time(&pkg->installed_time);
  5626. +
  5627. + ipkg_message(conf, IPKG_INFO,
  5628. + " cleanup temp files\n");
  5629. + cleanup_temporary_files(conf, pkg);
  5630. +
  5631. + if (pkg->parent)
  5632. + pkg->parent->state_status = pkg->state_status;
  5633. + }
  5634. + return 0;
  5635. +}
  5636. +
  5637. +int ipkg_process_actions_unwind_prerm(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_install)
  5638. +{
  5639. + int i;
  5640. + /* now one more pass checking on the ones that need to be installed */
  5641. + for (i = 0 ; i < pkgs_to_install->len; i++ ) {
  5642. + pkg_t *pkg = pkgs_to_install->pkgs[i];
  5643. + pkg_t *old_pkg = pkg->old_pkg;
  5644. +
  5645. + if (old_pkg) {
  5646. + if (old_pkg->state_flags & SF_POSTRM_UPGRADE)
  5647. + postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5648. + if (old_pkg->state_flags & SF_CHECK_DATA_FILE_CLASHES)
  5649. + check_data_file_clashes_unwind(conf, pkg, old_pkg);
  5650. + if (old_pkg->state_flags & SF_BACKUP_MODIFIED_CONFFILES)
  5651. + backup_modified_conffiles_unwind(pkg, old_pkg);
  5652. + */
  5653. + if (old_pkg->state_flags & SF_PREINST_CONFIGURE)
  5654. + preinst_configure_unwind(conf, pkg, old_pkg);
  5655. + if (old_pkg->state_flags & SF_DECONFIGURE_CONFLICTORS)
  5656. + prerm_deconfigure_conflictors_unwind(conf, pkg, replacees);
  5657. + if (old_pkg->state_flags & SF_PRERM_UPGRADE)
  5658. + prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg);
  5659. + */
  5660. +
  5661. + if (old_pkg->state_flags & SF_REMOVED_REPLACEES)
  5662. + remove_installed_replacees_unwind(conf, pkg, old_pkg);
  5663. +
  5664. + }
  5665. + }
  5666. + return 0;
  5667. +}
  5668. +
  5669. +/*
  5670. + * Perform all the actions.
  5671. + *
  5672. + * pkgs_to_remove are packages marked for removal.
  5673. + * pkgs_superseded are the old packages being replaced by upgrades.
  5674. + *
  5675. + * Assumes pkgs_to_install includes all dependences, recursively, sorted in installable order.
  5676. + */
  5677. +int ipkg_process_actions(ipkg_conf_t *conf, pkg_vec_t *pkgs_to_remove, pkg_vec_t *pkgs_superseded, pkg_vec_t *pkgs_to_install)
  5678. +{
  5679. + int err;
  5680. + int i;
  5681. +
  5682. + err = ipkg_remove_packages(conf, pkgs_to_remove);
  5683. + if (err) return err;
  5684. +
  5685. + err = ipkg_process_actions_sanity_check(conf, pkgs_superseded, pkgs_to_install);
  5686. + if (err) return err;
  5687. +
  5688. + err = ipkg_process_actions_remove_replacees(conf, pkgs_to_install);
  5689. + if (err) goto UNWIND;
  5690. +
  5691. + /* @@@@ look at ipkg_install_pkg for handling replacements */
  5692. + err = ipkg_process_actions_unpack_packages(conf, pkgs_to_install);
  5693. + if (err) goto UNWIND;
  5694. +
  5695. + /*
  5696. + * Now that we have the packages unpacked, we can look for data
  5697. + * file clashes. First, we mark the files from the superseded
  5698. + * packages as obsolete. Then we scan the files in
  5699. + * pkgs_to_install, and only complain about clashes with
  5700. + * non-obsolete files.
  5701. + */
  5702. +
  5703. + err = ipkg_process_actions_check_data_file_clashes(conf, pkgs_superseded, pkgs_to_install);
  5704. + if (err) goto UNWIND;
  5705. +
  5706. + /* this was before checking data file clashes */
  5707. + err = ipkg_process_actions_prerm(conf, pkgs_superseded, pkgs_to_install);
  5708. + if (err) goto UNWIND;
  5709. +
  5710. + /* point of no return: no unwinding after this */
  5711. + err = ipkg_process_actions_install(conf, pkgs_to_install);
  5712. + if (err) return err;
  5713. +
  5714. + ipkg_message(conf, IPKG_INFO, "Done.\n");
  5715. + return 0;
  5716. +
  5717. + UNWIND:
  5718. + ipkg_process_actions_unwind(conf, pkgs_to_install);
  5719. +
  5720. + ipkg_message(conf, IPKG_INFO,
  5721. + " cleanup temp files\n");
  5722. + cleanup_temporary_files(conf, pkg);
  5723. +
  5724. + ipkg_message(conf, IPKG_INFO,
  5725. + "Failed.\n");
  5726. + return err;
  5727. +}
  5728. +
  5729. +#endif
  5730. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_install.h busybox-1.24.1/archival/libipkg/ipkg_install.h
  5731. --- busybox-1.24.1.orig/archival/libipkg/ipkg_install.h 1970-01-01 01:00:00.000000000 +0100
  5732. +++ busybox-1.24.1/archival/libipkg/ipkg_install.h 2015-10-31 19:00:22.000000000 +0100
  5733. @@ -0,0 +1,35 @@
  5734. +/* ipkg_install.h - the itsy package management system
  5735. +
  5736. + Carl D. Worth
  5737. +
  5738. + Copyright (C) 2001 University of Southern California
  5739. +
  5740. + This program is free software; you can redistribute it and/or
  5741. + modify it under the terms of the GNU General Public License as
  5742. + published by the Free Software Foundation; either version 2, or (at
  5743. + your option) any later version.
  5744. +
  5745. + This program is distributed in the hope that it will be useful, but
  5746. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5747. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5748. + General Public License for more details.
  5749. +*/
  5750. +
  5751. +#ifndef IPKG_INSTALL_H
  5752. +#define IPKG_INSTALL_H
  5753. +
  5754. +#include "pkg.h"
  5755. +#include "ipkg_conf.h"
  5756. +
  5757. +ipkg_error_t ipkg_install_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5758. +ipkg_error_t ipkg_install_multi_by_name(ipkg_conf_t *conf, const char *pkg_name);
  5759. +int ipkg_install_from_file(ipkg_conf_t *conf, const char *filename);
  5760. +int ipkg_install_pkg(ipkg_conf_t *conf, pkg_t *pkg,int from_upgrading);
  5761. +int satisfy_dependencies_for(ipkg_conf_t *conf, pkg_t *pkg);
  5762. +
  5763. +int ipkg_satisfy_all_dependences(ipkg_conf_t *conf);
  5764. +
  5765. +int pkg_mark_dependencies_for_installation(ipkg_conf_t *conf, pkg_t *pkg_name, pkg_vec_t *pkgs_needed);
  5766. +int name_mark_dependencies_for_installation(ipkg_conf_t *conf, const char *pkg_name, pkg_vec_t *pkgs_needed);
  5767. +
  5768. +#endif
  5769. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_message.c busybox-1.24.1/archival/libipkg/ipkg_message.c
  5770. --- busybox-1.24.1.orig/archival/libipkg/ipkg_message.c 1970-01-01 01:00:00.000000000 +0100
  5771. +++ busybox-1.24.1/archival/libipkg/ipkg_message.c 2015-10-31 19:00:22.000000000 +0100
  5772. @@ -0,0 +1,35 @@
  5773. +/* ipkg_message.c - the itsy package management system
  5774. +
  5775. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5776. +
  5777. + This program is free software; you can redistribute it and/or
  5778. + modify it under the terms of the GNU General Public License as
  5779. + published by the Free Software Foundation; either version 2, or (at
  5780. + your option) any later version.
  5781. +
  5782. + This program is distributed in the hope that it will be useful, but
  5783. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5784. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5785. + General Public License for more details.
  5786. +*/
  5787. +
  5788. +
  5789. +#include "ipkg.h"
  5790. +#include "ipkg_conf.h"
  5791. +#include "ipkg_message.h"
  5792. +#include "libipkg.h"
  5793. +
  5794. +void
  5795. +ipkg_message (ipkg_conf_t * conf, message_level_t level, const char *fmt, ...)
  5796. +{
  5797. + va_list ap;
  5798. + char ts[256];
  5799. +
  5800. + if (ipkg_cb_message)
  5801. + {
  5802. + va_start (ap, fmt);
  5803. + vsnprintf (ts,256,fmt, ap);
  5804. + va_end (ap);
  5805. + ipkg_cb_message(conf,level,ts);
  5806. + }
  5807. +}
  5808. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_message.h busybox-1.24.1/archival/libipkg/ipkg_message.h
  5809. --- busybox-1.24.1.orig/archival/libipkg/ipkg_message.h 1970-01-01 01:00:00.000000000 +0100
  5810. +++ busybox-1.24.1/archival/libipkg/ipkg_message.h 2015-10-31 19:00:22.000000000 +0100
  5811. @@ -0,0 +1,32 @@
  5812. +/* ipkg_message.h - the itsy package management system
  5813. +
  5814. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  5815. +
  5816. + This program is free software; you can redistribute it and/or
  5817. + modify it under the terms of the GNU General Public License as
  5818. + published by the Free Software Foundation; either version 2, or (at
  5819. + your option) any later version.
  5820. +
  5821. + This program is distributed in the hope that it will be useful, but
  5822. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5823. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5824. + General Public License for more details.
  5825. +*/
  5826. +
  5827. +#ifndef _IPKG_MESSAGE_H_
  5828. +#define _IPKG_MESSAGE_H_
  5829. +
  5830. +#include "ipkg.h"
  5831. +#include "ipkg_conf.h"
  5832. +
  5833. +typedef enum {
  5834. + IPKG_ERROR, /* error conditions */
  5835. + IPKG_NOTICE, /* normal but significant condition */
  5836. + IPKG_INFO, /* informational message */
  5837. + IPKG_DEBUG, /* debug level message */
  5838. + IPKG_DEBUG2, /* more debug level message */
  5839. +} message_level_t;
  5840. +
  5841. +extern void ipkg_message(ipkg_conf_t *conf, message_level_t level, const char *fmt, ...);
  5842. +
  5843. +#endif /* _IPKG_MESSAGE_H_ */
  5844. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_remove.c busybox-1.24.1/archival/libipkg/ipkg_remove.c
  5845. --- busybox-1.24.1.orig/archival/libipkg/ipkg_remove.c 1970-01-01 01:00:00.000000000 +0100
  5846. +++ busybox-1.24.1/archival/libipkg/ipkg_remove.c 2015-10-31 19:00:22.000000000 +0100
  5847. @@ -0,0 +1,385 @@
  5848. +/* ipkg_remove.c - the itsy package management system
  5849. +
  5850. + Carl D. Worth
  5851. +
  5852. + Copyright (C) 2001 University of Southern California
  5853. +
  5854. + This program is free software; you can redistribute it and/or
  5855. + modify it under the terms of the GNU General Public License as
  5856. + published by the Free Software Foundation; either version 2, or (at
  5857. + your option) any later version.
  5858. +
  5859. + This program is distributed in the hope that it will be useful, but
  5860. + WITHOUT ANY WARRANTY; without even the implied warranty of
  5861. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  5862. + General Public License for more details.
  5863. +*/
  5864. +
  5865. +#include "ipkg.h"
  5866. +#include "ipkg_message.h"
  5867. +
  5868. +#include <glob.h>
  5869. +
  5870. +#include "ipkg_remove.h"
  5871. +
  5872. +#include "file_util.h"
  5873. +#include "sprintf_alloc.h"
  5874. +#include "str_util.h"
  5875. +
  5876. +#include "ipkg_cmd.h"
  5877. +
  5878. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents);
  5879. +
  5880. +/*
  5881. + * Returns number of the number of packages depending on the packages provided by this package.
  5882. + * Every package implicitly provides itself.
  5883. + */
  5884. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents)
  5885. +{
  5886. + int nprovides = pkg->provides_count;
  5887. + abstract_pkg_t **provides = pkg->provides;
  5888. + int n_installed_dependents = 0;
  5889. + int i;
  5890. + for (i = 0; i <= nprovides; i++) {
  5891. + abstract_pkg_t *providee = provides[i];
  5892. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5893. + abstract_pkg_t *dep_ab_pkg;
  5894. + if (dependers == NULL)
  5895. + continue;
  5896. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5897. + if (dep_ab_pkg->state_status == SS_INSTALLED){
  5898. + n_installed_dependents++;
  5899. + }
  5900. + }
  5901. +
  5902. + }
  5903. + /* if caller requested the set of installed dependents */
  5904. + if (pdependents) {
  5905. + int p = 0;
  5906. + abstract_pkg_t **dependents = (abstract_pkg_t **)malloc((n_installed_dependents+1)*sizeof(abstract_pkg_t *));
  5907. +
  5908. + if ( dependents == NULL ){
  5909. + fprintf(stderr,"%s Unable to allocate memory. REPORT THIS BUG IN BUGZILLA PLEASE\n", __FUNCTION__);
  5910. + return -1;
  5911. + }
  5912. +
  5913. + *pdependents = dependents;
  5914. + for (i = 0; i <= nprovides; i++) {
  5915. + abstract_pkg_t *providee = provides[i];
  5916. + abstract_pkg_t **dependers = providee->depended_upon_by;
  5917. + abstract_pkg_t *dep_ab_pkg;
  5918. + if (dependers == NULL)
  5919. + continue;
  5920. + while ((dep_ab_pkg = *dependers++) != NULL) {
  5921. + if (dep_ab_pkg->state_status == SS_INSTALLED && !(dep_ab_pkg->state_flag & SF_MARKED)) {
  5922. + dependents[p++] = dep_ab_pkg;
  5923. + dep_ab_pkg->state_flag |= SF_MARKED;
  5924. + }
  5925. + }
  5926. + }
  5927. + dependents[p] = NULL;
  5928. + /* now clear the marks */
  5929. + for (i = 0; i < p; i++) {
  5930. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5931. + dep_ab_pkg->state_flag &= ~SF_MARKED;
  5932. + }
  5933. + }
  5934. + return n_installed_dependents;
  5935. +}
  5936. +
  5937. +int ipkg_remove_dependent_pkgs (ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5938. +{
  5939. + int i;
  5940. + int a;
  5941. + int count;
  5942. + pkg_vec_t *dependent_pkgs = pkg_vec_alloc();
  5943. + abstract_pkg_t * ab_pkg;
  5944. +
  5945. + if((ab_pkg = pkg->parent) == NULL){
  5946. + fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n",
  5947. + __FUNCTION__, pkg->name);
  5948. + return 0;
  5949. + }
  5950. +
  5951. + if (dependents == NULL)
  5952. + return 0;
  5953. +
  5954. + // here i am using the dependencies_checked
  5955. + if (ab_pkg->dependencies_checked == 2) // variable to make out whether this package
  5956. + return 0; // has already been encountered in the process
  5957. + // of marking packages for removal - Karthik
  5958. + ab_pkg->dependencies_checked = 2;
  5959. +
  5960. + i = 0;
  5961. + count = 1;
  5962. + while (dependents [i] != NULL) {
  5963. + abstract_pkg_t *dep_ab_pkg = dependents[i];
  5964. +
  5965. + if (dep_ab_pkg->dependencies_checked == 2){
  5966. + i++;
  5967. + continue;
  5968. + }
  5969. + if (dep_ab_pkg->state_status == SS_INSTALLED) {
  5970. + for (a = 0; a < dep_ab_pkg->pkgs->len; a++) {
  5971. + pkg_t *dep_pkg = dep_ab_pkg->pkgs->pkgs[a];
  5972. + if (dep_pkg->state_status == SS_INSTALLED) {
  5973. + pkg_vec_insert(dependent_pkgs, dep_pkg);
  5974. + count++;
  5975. + }
  5976. + }
  5977. + }
  5978. + i++;
  5979. + /* 1 - to keep track of visited ab_pkgs when checking for possiblility of a broken removal of pkgs.
  5980. + * 2 - to keep track of pkgs whose deps have been checked alrdy - Karthik */
  5981. + }
  5982. +
  5983. + if (count == 1)
  5984. + return 0;
  5985. +
  5986. +
  5987. + for (i = 0; i < dependent_pkgs->len; i++) {
  5988. + int err = ipkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0);
  5989. + if (err)
  5990. + return err;
  5991. + }
  5992. + return 0;
  5993. +}
  5994. +
  5995. +static int user_prefers_removing_dependents(ipkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents)
  5996. +{
  5997. + abstract_pkg_t *dep_ab_pkg;
  5998. + ipkg_message(conf, IPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name);
  5999. + while ((dep_ab_pkg = *dependents++) != NULL) {
  6000. + if (dep_ab_pkg->state_status == SS_INSTALLED)
  6001. + ipkg_message(conf, IPKG_ERROR, "\t%s\n", dep_ab_pkg->name);
  6002. + }
  6003. + ipkg_message(conf, IPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name);
  6004. + ipkg_message(conf, IPKG_ERROR, "");
  6005. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package with -force-depends.\n");
  6006. + ipkg_message(conf, IPKG_ERROR, "You can force removal of this package and its dependents\n");
  6007. + ipkg_message(conf, IPKG_ERROR, "with -force-removal-of-dependent-packages or -recursive\n");
  6008. + ipkg_message(conf, IPKG_ERROR, "or by setting option force_removal_of_dependent_packages\n");
  6009. + ipkg_message(conf, IPKG_ERROR, "in ipkg.conf.\n");
  6010. + return 0;
  6011. +}
  6012. +
  6013. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message)
  6014. +{
  6015. +/* Actually, when "message == 1" I have been called from an upgrade, and not from a normal remove
  6016. + thus I wan't check for essential, as I'm upgrading.
  6017. + I hope it won't break anything :)
  6018. +*/
  6019. + int err;
  6020. + abstract_pkg_t *parent_pkg = NULL;
  6021. +
  6022. + if (pkg->essential && !message) {
  6023. + if (conf->force_removal_of_essential_packages) {
  6024. + fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n"
  6025. + "\tIf your system breaks, you get to keep both pieces\n",
  6026. + pkg->name);
  6027. + } else {
  6028. + fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n"
  6029. + "\tRemoving an essential package may lead to an unusable system, but if\n"
  6030. + "\tyou enjoy that kind of pain, you can force ipkg to proceed against\n"
  6031. + "\tits will with the option: -force-removal-of-essential-packages\n",
  6032. + pkg->name);
  6033. + return IPKG_PKG_IS_ESSENTIAL;
  6034. + }
  6035. + }
  6036. +
  6037. + if ((parent_pkg = pkg->parent) == NULL)
  6038. + return 0;
  6039. +
  6040. + /* only attempt to remove dependent installed packages if
  6041. + * force_depends is not specified or the package is being
  6042. + * replaced.
  6043. + */
  6044. + if (!conf->force_depends
  6045. + && !(pkg->state_flag & SF_REPLACE)) {
  6046. + abstract_pkg_t **dependents;
  6047. + int has_installed_dependents =
  6048. + pkg_has_installed_dependents(pkg, &dependents);
  6049. +
  6050. + if (has_installed_dependents) {
  6051. + /*
  6052. + * if this package is depended up by others, then either we should
  6053. + * not remove it or we should remove it and all of its dependents
  6054. + */
  6055. +
  6056. + if (!conf->force_removal_of_dependent_packages
  6057. + && !user_prefers_removing_dependents(conf, pkg, dependents)) {
  6058. + return IPKG_PKG_HAS_DEPENDENTS;
  6059. + }
  6060. +
  6061. + /* remove packages depending on this package - Karthik */
  6062. + err = ipkg_remove_dependent_pkgs (conf, pkg, dependents);
  6063. + free(dependents);
  6064. + if (err) return err;
  6065. + }
  6066. + }
  6067. +
  6068. + if ( message==0 ){
  6069. + printf("Removing package %s from %s...\n", pkg->name, pkg->dest->name);
  6070. + fflush(stdout);
  6071. + }
  6072. + pkg->state_flag |= SF_FILELIST_CHANGED;
  6073. +
  6074. + pkg->state_want = SW_DEINSTALL;
  6075. + ipkg_state_changed++;
  6076. +
  6077. + pkg_run_script(conf, pkg, "prerm", "remove");
  6078. +
  6079. + /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It
  6080. + maintains an empty filelist rather than deleting it. That seems
  6081. + like a big pain, and I don't see that that should make a big
  6082. + difference, but for anyone who wants tighter compatibility,
  6083. + feel free to fix this. */
  6084. + remove_data_files_and_list(conf, pkg);
  6085. +
  6086. + pkg_run_script(conf, pkg, "postrm", "remove");
  6087. +
  6088. + remove_maintainer_scripts_except_postrm(conf, pkg);
  6089. +
  6090. + /* Aman Gupta - Since ipkg is made for handheld devices with limited
  6091. + * space, it doesn't make sense to leave extra configurations, files,
  6092. + * and maintainer scripts left around. So, we make remove like purge,
  6093. + * and take out all the crap :) */
  6094. +
  6095. + remove_postrm(conf, pkg);
  6096. + pkg->state_status = SS_NOT_INSTALLED;
  6097. +
  6098. + if (parent_pkg)
  6099. + parent_pkg->state_status = SS_NOT_INSTALLED;
  6100. +
  6101. + return 0;
  6102. +}
  6103. +
  6104. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg)
  6105. +{
  6106. + ipkg_remove_pkg(conf, pkg,0);
  6107. + return 0;
  6108. +}
  6109. +
  6110. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg)
  6111. +{
  6112. + str_list_t installed_dirs;
  6113. + str_list_t *installed_files;
  6114. + str_list_elt_t *iter;
  6115. + char *file_name;
  6116. + conffile_t *conffile;
  6117. + int removed_a_dir;
  6118. + pkg_t *owner;
  6119. +
  6120. + str_list_init(&installed_dirs);
  6121. + installed_files = pkg_get_installed_files(pkg);
  6122. +
  6123. + for (iter = installed_files->head; iter; iter = iter->next) {
  6124. + file_name = iter->data;
  6125. +
  6126. + if (file_is_dir(file_name)) {
  6127. + str_list_append(&installed_dirs, strdup(file_name));
  6128. + continue;
  6129. + }
  6130. +
  6131. + conffile = pkg_get_conffile(pkg, file_name);
  6132. + if (conffile) {
  6133. + /* XXX: QUESTION: Is this right? I figure we only need to
  6134. + save the conffile if it has been modified. Is that what
  6135. + dpkg does? Or does dpkg preserve all conffiles? If so,
  6136. + this seems like a better thing to do to conserve
  6137. + space. */
  6138. + if (conffile_has_been_modified(conf, conffile)) {
  6139. + printf(" not deleting modified conffile %s\n", file_name);
  6140. + fflush(stdout);
  6141. + continue;
  6142. + }
  6143. + }
  6144. +
  6145. + ipkg_message(conf, IPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction);
  6146. + if (!conf->noaction)
  6147. + unlink(file_name);
  6148. + }
  6149. +
  6150. + if (!conf->noaction) {
  6151. + do {
  6152. + removed_a_dir = 0;
  6153. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6154. + file_name = iter->data;
  6155. +
  6156. + if (rmdir(file_name) == 0) {
  6157. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", file_name);
  6158. + removed_a_dir = 1;
  6159. + str_list_remove(&installed_dirs, &iter);
  6160. + }
  6161. + }
  6162. + } while (removed_a_dir);
  6163. + }
  6164. +
  6165. + pkg_free_installed_files(pkg);
  6166. + /* We have to remove the file list now, so that
  6167. + find_pkg_owning_file does not always just report this package */
  6168. + pkg_remove_installed_files_list(conf, pkg);
  6169. +
  6170. + /* Don't print warning for dirs that are provided by other packages */
  6171. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6172. + file_name = iter->data;
  6173. +
  6174. + owner = file_hash_get_file_owner(conf, file_name);
  6175. + if (owner) {
  6176. + free(iter->data);
  6177. + iter->data = NULL;
  6178. + str_list_remove(&installed_dirs, &iter);
  6179. + }
  6180. + }
  6181. +
  6182. + /* cleanup */
  6183. + for (iter = installed_dirs.head; iter; iter = iter->next) {
  6184. + free(iter->data);
  6185. + iter->data = NULL;
  6186. + }
  6187. + str_list_deinit(&installed_dirs);
  6188. +
  6189. + return 0;
  6190. +}
  6191. +
  6192. +int remove_maintainer_scripts_except_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6193. +{
  6194. + int i, err;
  6195. + char *globpattern;
  6196. + glob_t globbuf;
  6197. +
  6198. + if (conf->noaction) return 0;
  6199. +
  6200. + sprintf_alloc(&globpattern, "%s/%s.*",
  6201. + pkg->dest->info_dir, pkg->name);
  6202. + err = glob(globpattern, 0, NULL, &globbuf);
  6203. + free(globpattern);
  6204. + if (err) {
  6205. + return 0;
  6206. + }
  6207. +
  6208. + for (i = 0; i < globbuf.gl_pathc; i++) {
  6209. + if (str_ends_with(globbuf.gl_pathv[i], ".postrm")) {
  6210. + continue;
  6211. + }
  6212. + ipkg_message(conf, IPKG_INFO, " deleting %s\n", globbuf.gl_pathv[i]);
  6213. + unlink(globbuf.gl_pathv[i]);
  6214. + }
  6215. + globfree(&globbuf);
  6216. +
  6217. + return 0;
  6218. +}
  6219. +
  6220. +int remove_postrm(ipkg_conf_t *conf, pkg_t *pkg)
  6221. +{
  6222. + char *postrm_file_name;
  6223. +
  6224. + if (conf->noaction) return 0;
  6225. +
  6226. + sprintf_alloc(&postrm_file_name, "%s/%s.postrm",
  6227. + pkg->dest->info_dir, pkg->name);
  6228. + unlink(postrm_file_name);
  6229. + free(postrm_file_name);
  6230. +
  6231. + return 0;
  6232. +}
  6233. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_remove.h busybox-1.24.1/archival/libipkg/ipkg_remove.h
  6234. --- busybox-1.24.1.orig/archival/libipkg/ipkg_remove.h 1970-01-01 01:00:00.000000000 +0100
  6235. +++ busybox-1.24.1/archival/libipkg/ipkg_remove.h 2015-10-31 19:00:22.000000000 +0100
  6236. @@ -0,0 +1,33 @@
  6237. +/* ipkg_remove.h - the itsy package management system
  6238. +
  6239. + Carl D. Worth
  6240. +
  6241. + Copyright (C) 2001 University of Southern California
  6242. +
  6243. + This program is free software; you can redistribute it and/or
  6244. + modify it under the terms of the GNU General Public License as
  6245. + published by the Free Software Foundation; either version 2, or (at
  6246. + your option) any later version.
  6247. +
  6248. + This program is distributed in the hope that it will be useful, but
  6249. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6250. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6251. + General Public License for more details.
  6252. +*/
  6253. +
  6254. +#ifndef IPKG_REMOVE_H
  6255. +#define IPKG_REMOVE_H
  6256. +
  6257. +#include "pkg.h"
  6258. +#include "ipkg_conf.h"
  6259. +
  6260. +int ipkg_remove_pkg(ipkg_conf_t *conf, pkg_t *pkg,int message);
  6261. +int ipkg_purge_pkg(ipkg_conf_t *conf, pkg_t *pkg);
  6262. +int possible_broken_removal_of_packages (ipkg_conf_t *conf, pkg_t *pkg);
  6263. +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents);
  6264. +int remove_data_files_and_list(ipkg_conf_t *conf, pkg_t *pkg);
  6265. +int remove_maintainer_scripts_except_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6266. +int remove_postrm (ipkg_conf_t *conf, pkg_t *pkg);
  6267. +
  6268. +
  6269. +#endif
  6270. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_upgrade.c busybox-1.24.1/archival/libipkg/ipkg_upgrade.c
  6271. --- busybox-1.24.1.orig/archival/libipkg/ipkg_upgrade.c 1970-01-01 01:00:00.000000000 +0100
  6272. +++ busybox-1.24.1/archival/libipkg/ipkg_upgrade.c 2015-10-31 19:00:22.000000000 +0100
  6273. @@ -0,0 +1,79 @@
  6274. +/* ipkg_upgrade.c - the itsy package management system
  6275. +
  6276. + Carl D. Worth
  6277. + Copyright (C) 2001 University of Southern California
  6278. +
  6279. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6280. +
  6281. + This program is free software; you can redistribute it and/or
  6282. + modify it under the terms of the GNU General Public License as
  6283. + published by the Free Software Foundation; either version 2, or (at
  6284. + your option) any later version.
  6285. +
  6286. + This program is distributed in the hope that it will be useful, but
  6287. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6288. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6289. + General Public License for more details.
  6290. +*/
  6291. +
  6292. +#include "ipkg.h"
  6293. +#include "ipkg_install.h"
  6294. +#include "ipkg_message.h"
  6295. +
  6296. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6297. +
  6298. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old)
  6299. +{
  6300. + pkg_t *new;
  6301. + int cmp;
  6302. + char *old_version, *new_version;
  6303. +
  6304. + if (old->state_flag & SF_HOLD) {
  6305. + ipkg_message(conf, IPKG_NOTICE,
  6306. + "Not upgrading package %s which is marked "
  6307. + "hold (flags=%#x)\n", old->name, old->state_flag);
  6308. + return 0;
  6309. + }
  6310. +
  6311. + new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name);
  6312. + if (new == NULL) {
  6313. + old_version = pkg_version_str_alloc(old);
  6314. + ipkg_message(conf, IPKG_NOTICE,
  6315. + "Assuming locally installed package %s (%s) "
  6316. + "is up to date.\n", old->name, old_version);
  6317. + free(old_version);
  6318. + return 0;
  6319. + }
  6320. +
  6321. + old_version = pkg_version_str_alloc(old);
  6322. + new_version = pkg_version_str_alloc(new);
  6323. +
  6324. + cmp = pkg_compare_versions(old, new);
  6325. + ipkg_message(conf, IPKG_DEBUG,
  6326. + "comparing visible versions of pkg %s:"
  6327. + "\n\t%s is installed "
  6328. + "\n\t%s is available "
  6329. + "\n\t%d was comparison result\n",
  6330. + old->name, old_version, new_version, cmp);
  6331. + if (cmp == 0) {
  6332. + ipkg_message(conf, IPKG_INFO,
  6333. + "Package %s (%s) installed in %s is up to date.\n",
  6334. + old->name, old_version, old->dest->name);
  6335. + free(old_version);
  6336. + free(new_version);
  6337. + return 0;
  6338. + } else if (cmp > 0) {
  6339. + ipkg_message(conf, IPKG_NOTICE,
  6340. + "Not downgrading package %s on %s from %s to %s.\n",
  6341. + old->name, old->dest->name, old_version, new_version);
  6342. + free(old_version);
  6343. + free(new_version);
  6344. + return 0;
  6345. + } else if (cmp < 0) {
  6346. + new->dest = old->dest;
  6347. + old->state_want = SW_DEINSTALL;
  6348. + }
  6349. +
  6350. + new->state_flag |= SF_USER;
  6351. + return ipkg_install_pkg(conf, new,1);
  6352. +}
  6353. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_upgrade.h busybox-1.24.1/archival/libipkg/ipkg_upgrade.h
  6354. --- busybox-1.24.1.orig/archival/libipkg/ipkg_upgrade.h 1970-01-01 01:00:00.000000000 +0100
  6355. +++ busybox-1.24.1/archival/libipkg/ipkg_upgrade.h 2015-10-31 19:00:22.000000000 +0100
  6356. @@ -0,0 +1,18 @@
  6357. +/* ipkg_upgrade.c - the itsy package management system
  6358. +
  6359. + Copyright (C) 2003 Daniele Nicolodi <daniele@grinta.net>
  6360. +
  6361. + This program is free software; you can redistribute it and/or
  6362. + modify it under the terms of the GNU General Public License as
  6363. + published by the Free Software Foundation; either version 2, or (at
  6364. + your option) any later version.
  6365. +
  6366. + This program is distributed in the hope that it will be useful, but
  6367. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6368. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6369. + General Public License for more details.
  6370. +*/
  6371. +
  6372. +#include "ipkg.h"
  6373. +
  6374. +int ipkg_upgrade_pkg(ipkg_conf_t *conf, pkg_t *old);
  6375. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_utils.c busybox-1.24.1/archival/libipkg/ipkg_utils.c
  6376. --- busybox-1.24.1.orig/archival/libipkg/ipkg_utils.c 1970-01-01 01:00:00.000000000 +0100
  6377. +++ busybox-1.24.1/archival/libipkg/ipkg_utils.c 2015-10-31 19:00:22.000000000 +0100
  6378. @@ -0,0 +1,185 @@
  6379. +/* ipkg_utils.c - the itsy package management system
  6380. +
  6381. + Steven M. Ayer
  6382. +
  6383. + Copyright (C) 2002 Compaq Computer Corporation
  6384. +
  6385. + This program is free software; you can redistribute it and/or
  6386. + modify it under the terms of the GNU General Public License as
  6387. + published by the Free Software Foundation; either version 2, or (at
  6388. + your option) any later version.
  6389. +
  6390. + This program is distributed in the hope that it will be useful, but
  6391. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6392. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6393. + General Public License for more details.
  6394. +*/
  6395. +
  6396. +#include "ipkg.h"
  6397. +#include <errno.h>
  6398. +#include <ctype.h>
  6399. +#include <sys/vfs.h>
  6400. +
  6401. +#include "ipkg_utils.h"
  6402. +#include "pkg.h"
  6403. +#include "pkg_hash.h"
  6404. +
  6405. +void push_error_list(struct errlist ** errors, char * msg);
  6406. +void reverse_error_list(struct errlist **errors);
  6407. +void free_error_list(struct errlist **errors);
  6408. +
  6409. +struct errlist* error_list;
  6410. +
  6411. +int get_available_blocks(char * filesystem)
  6412. +{
  6413. + struct statfs sfs;
  6414. +
  6415. + if(statfs(filesystem, &sfs)){
  6416. + fprintf(stderr, "bad statfs\n");
  6417. + return 0;
  6418. + }
  6419. + /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */
  6420. + return ((sfs.f_bavail * sfs.f_bsize) / 1024);
  6421. +}
  6422. +
  6423. +char **read_raw_pkgs_from_file(const char *file_name)
  6424. +{
  6425. + FILE *fp;
  6426. + char **ret;
  6427. +
  6428. + if(!(fp = fopen(file_name, "r"))){
  6429. + fprintf(stderr, "can't get %s open for read\n", file_name);
  6430. + return NULL;
  6431. + }
  6432. +
  6433. + ret = read_raw_pkgs_from_stream(fp);
  6434. +
  6435. + fclose(fp);
  6436. +
  6437. + return ret;
  6438. +}
  6439. +
  6440. +char **read_raw_pkgs_from_stream(FILE *fp)
  6441. +{
  6442. + char **raw = NULL, *buf, *scout;
  6443. + int count = 0;
  6444. + size_t size = 512;
  6445. +
  6446. + buf = malloc (size);
  6447. +
  6448. + while (fgets(buf, size, fp)) {
  6449. + while (strlen (buf) == (size - 1)
  6450. + && buf[size-2] != '\n') {
  6451. + size_t o = size - 1;
  6452. + size *= 2;
  6453. + buf = realloc (buf, size);
  6454. + if (fgets (buf + o, size - o, fp) == NULL)
  6455. + break;
  6456. + }
  6457. +
  6458. + if(!(count % 50))
  6459. + raw = realloc(raw, (count + 50) * sizeof(char *));
  6460. +
  6461. + if((scout = strchr(buf, '\n')))
  6462. + *scout = '\0';
  6463. +
  6464. + raw[count++] = strdup(buf);
  6465. + }
  6466. +
  6467. + raw = realloc(raw, (count + 1) * sizeof(char *));
  6468. + raw[count] = NULL;
  6469. +
  6470. + free (buf);
  6471. +
  6472. + return raw;
  6473. +}
  6474. +
  6475. +/* something to remove whitespace, a hash pooper */
  6476. +char *trim_alloc(char *line)
  6477. +{
  6478. + char *new;
  6479. + char *dest, *src, *end;
  6480. +
  6481. + new = malloc(strlen(line) + 1);
  6482. + if ( new == NULL ){
  6483. + fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
  6484. + return NULL;
  6485. + }
  6486. + dest = new, src = line, end = line + (strlen(line) - 1);
  6487. +
  6488. + /* remove it from the front */
  6489. + while(src &&
  6490. + isspace(*src) &&
  6491. + *src)
  6492. + src++;
  6493. + /* and now from the back */
  6494. + while((end > src) &&
  6495. + isspace(*end))
  6496. + end--;
  6497. + end++;
  6498. + *end = '\0';
  6499. + strcpy(new, src);
  6500. + /* this does from the first space
  6501. + * blasting away any versions stuff in depends
  6502. + while(src &&
  6503. + !isspace(*src) &&
  6504. + *src)
  6505. + *dest++ = *src++;
  6506. + *dest = '\0';
  6507. + */
  6508. +
  6509. + return new;
  6510. +}
  6511. +
  6512. +int line_is_blank(const char *line)
  6513. +{
  6514. + const char *s;
  6515. +
  6516. + for (s = line; *s; s++) {
  6517. + if (!isspace(*s))
  6518. + return 0;
  6519. + }
  6520. + return 1;
  6521. +}
  6522. +
  6523. +void push_error_list(struct errlist ** errors, char * msg){
  6524. + struct errlist *err_lst_tmp;
  6525. +
  6526. +
  6527. + err_lst_tmp = malloc ( sizeof (err_lst_tmp) );
  6528. + err_lst_tmp->errmsg=strdup(msg) ;
  6529. + err_lst_tmp->next = *errors;
  6530. + *errors = err_lst_tmp;
  6531. +}
  6532. +
  6533. +
  6534. +void reverse_error_list(struct errlist **errors){
  6535. + struct errlist *result=NULL;
  6536. + struct errlist *current= *errors;
  6537. + struct errlist *next;
  6538. +
  6539. + while ( current != NULL ) {
  6540. + next = current->next;
  6541. + current->next=result;
  6542. + result=current;
  6543. + current=next;
  6544. + }
  6545. + *errors=result;
  6546. +
  6547. +}
  6548. +
  6549. +
  6550. +void free_error_list(struct errlist **errors){
  6551. + struct errlist *current = *errors;
  6552. +
  6553. + while (current != NULL) {
  6554. + free(current->errmsg);
  6555. + current = (*errors)->next;
  6556. + free(*errors);
  6557. + *errors = current;
  6558. + }
  6559. +
  6560. +
  6561. +}
  6562. +
  6563. +
  6564. diff -Nur busybox-1.24.1.orig/archival/libipkg/ipkg_utils.h busybox-1.24.1/archival/libipkg/ipkg_utils.h
  6565. --- busybox-1.24.1.orig/archival/libipkg/ipkg_utils.h 1970-01-01 01:00:00.000000000 +0100
  6566. +++ busybox-1.24.1/archival/libipkg/ipkg_utils.h 2015-10-31 19:00:22.000000000 +0100
  6567. @@ -0,0 +1,29 @@
  6568. +/* ipkg_utils.h - the itsy package management system
  6569. +
  6570. + Steven M. Ayer
  6571. +
  6572. + Copyright (C) 2002 Compaq Computer Corporation
  6573. +
  6574. + This program is free software; you can redistribute it and/or
  6575. + modify it under the terms of the GNU General Public License as
  6576. + published by the Free Software Foundation; either version 2, or (at
  6577. + your option) any later version.
  6578. +
  6579. + This program is distributed in the hope that it will be useful, but
  6580. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6581. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6582. + General Public License for more details.
  6583. +*/
  6584. +
  6585. +#ifndef IPKG_UTILS_H
  6586. +#define IPKG_UTILS_H
  6587. +
  6588. +#include "pkg.h"
  6589. +
  6590. +int get_available_blocks(char * filesystem);
  6591. +char **read_raw_pkgs_from_file(const char *file_name);
  6592. +char **read_raw_pkgs_from_stream(FILE *fp);
  6593. +char *trim_alloc(char * line);
  6594. +int line_is_blank(const char *line);
  6595. +
  6596. +#endif
  6597. diff -Nur busybox-1.24.1.orig/archival/libipkg/Kbuild busybox-1.24.1/archival/libipkg/Kbuild
  6598. --- busybox-1.24.1.orig/archival/libipkg/Kbuild 1970-01-01 01:00:00.000000000 +0100
  6599. +++ busybox-1.24.1/archival/libipkg/Kbuild 2015-10-31 19:00:22.000000000 +0100
  6600. @@ -0,0 +1,60 @@
  6601. +# Makefile for busybox
  6602. +#
  6603. +# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6604. +# Copyright (C) 2006 OpenWrt.org
  6605. +#
  6606. +# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6607. +
  6608. +LIBIPKG_CORE_OBJS:= \
  6609. + args.o \
  6610. + libipkg.o \
  6611. + user.o \
  6612. +
  6613. +LIBIPKG_CMD_OBJS:= \
  6614. + ipkg_cmd.o \
  6615. + ipkg_configure.o \
  6616. + ipkg_download.o \
  6617. + ipkg_install.o \
  6618. + ipkg_remove.o \
  6619. + ipkg_upgrade.o \
  6620. +
  6621. +LIBIPKG_DB_OBJS:= \
  6622. + hash_table.o \
  6623. + ipkg_conf.o \
  6624. + ipkg_utils.o \
  6625. + pkg.o \
  6626. + pkg_depends.o \
  6627. + pkg_extract.o \
  6628. + pkg_hash.o \
  6629. + pkg_parse.o \
  6630. + pkg_vec.o \
  6631. +
  6632. +LIBIPKG_LIST_OBJS:= \
  6633. + conffile.o \
  6634. + conffile_list.o \
  6635. + nv_pair.o \
  6636. + nv_pair_list.o \
  6637. + pkg_dest.o \
  6638. + pkg_dest_list.o \
  6639. + pkg_src.o \
  6640. + pkg_src_list.o \
  6641. + str_list.o \
  6642. + void_list.o \
  6643. +
  6644. +LIBIPKG_UTIL_OBJS:= \
  6645. + file_util.o \
  6646. + ipkg_message.o \
  6647. + str_util.o \
  6648. + xsystem.o \
  6649. +
  6650. +lib-y :=
  6651. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CORE_OBJS)
  6652. +lib-$(CONFIG_IPKG) += $(LIBIPKG_CMD_OBJS)
  6653. +lib-$(CONFIG_IPKG) += $(LIBIPKG_DB_OBJS)
  6654. +lib-$(CONFIG_IPKG) += $(LIBIPKG_LIST_OBJS)
  6655. +lib-$(CONFIG_IPKG) += $(LIBIPKG_UTIL_OBJS)
  6656. +
  6657. +ifeq ($(strip $(IPKG_ARCH)),)
  6658. +IPKG_ARCH:=$(TARGET_ARCH)
  6659. +endif
  6660. +CFLAGS += -DIPKGLIBDIR="\"/usr/lib\"" -DHOST_CPU_STR="\"$(IPKG_ARCH)\""
  6661. diff -Nur busybox-1.24.1.orig/archival/libipkg/libipkg.c busybox-1.24.1/archival/libipkg/libipkg.c
  6662. --- busybox-1.24.1.orig/archival/libipkg/libipkg.c 1970-01-01 01:00:00.000000000 +0100
  6663. +++ busybox-1.24.1/archival/libipkg/libipkg.c 2015-10-31 19:00:22.000000000 +0100
  6664. @@ -0,0 +1,583 @@
  6665. +/* ipkglib.c - the itsy package management system
  6666. +
  6667. + Florina Boor
  6668. +
  6669. + Copyright (C) 2003 kernel concepts
  6670. +
  6671. + This program is free software; you can redistribute it and/or
  6672. + modify it under the terms of the GNU General Public License as
  6673. + published by the Free Software Foundation; either version 2, or (at
  6674. + your option) any later version.
  6675. +
  6676. + This program is distributed in the hope that it will be useful, but
  6677. + WITHOUT ANY WARRANTY; without even the implied warranty of
  6678. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  6679. + General Public License for more details.
  6680. +*/
  6681. +
  6682. +#include "ipkg.h"
  6683. +#include "ipkg_includes.h"
  6684. +#include "libipkg.h"
  6685. +
  6686. +#include "args.h"
  6687. +#include "ipkg_conf.h"
  6688. +#include "ipkg_cmd.h"
  6689. +#include "file_util.h"
  6690. +
  6691. +int ipkg_file_what(args_t *args, const char *file, const char* command);
  6692. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  6693. + char *msg);
  6694. +int default_ipkg_list_callback(char *name, char *desc, char *version);
  6695. +int default_ipkg_files_callback(char *desc);
  6696. +int default_ipkg_status_callback(char *desc);
  6697. +char* default_ipkg_response_callback(char *question);
  6698. +
  6699. +
  6700. +ipkg_message_callback ipkg_cb_message = NULL;
  6701. +ipkg_response_callback ipkg_cb_response = NULL;
  6702. +ipkg_status_callback ipkg_cb_status = NULL;
  6703. +ipkg_list_callback ipkg_cb_list = NULL;
  6704. +
  6705. +
  6706. +int
  6707. +ipkg_init (ipkg_message_callback mcall,
  6708. + ipkg_response_callback rcall,
  6709. + args_t * args)
  6710. +{
  6711. + ipkg_cb_message = mcall;
  6712. + ipkg_cb_response = rcall;
  6713. +
  6714. + args_init (args);
  6715. +
  6716. + return 0;
  6717. +}
  6718. +
  6719. +
  6720. +int
  6721. +ipkg_deinit (args_t * args)
  6722. +{
  6723. + args_deinit (args);
  6724. + ipkg_cb_message = NULL;
  6725. + ipkg_cb_response = NULL;
  6726. +
  6727. + /* place other cleanup stuff here */
  6728. +
  6729. + return 0;
  6730. +}
  6731. +
  6732. +
  6733. +int
  6734. +ipkg_packages_list(args_t *args,
  6735. + const char *packages,
  6736. + ipkg_list_callback cblist,
  6737. + void *userdata)
  6738. +{
  6739. + ipkg_cmd_t *cmd;
  6740. + ipkg_conf_t ipkg_conf;
  6741. + int err;
  6742. +
  6743. + err = ipkg_conf_init (&ipkg_conf, args);
  6744. + if (err)
  6745. + {
  6746. + return err;
  6747. + }
  6748. +
  6749. + ipkg_cb_list = cblist;
  6750. + /* we need to do this because of static declarations,
  6751. + * maybe a good idea to change */
  6752. + cmd = ipkg_cmd_find ("list");
  6753. + if (packages)
  6754. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6755. + else
  6756. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6757. + ipkg_cb_list = NULL;
  6758. + ipkg_conf_deinit (&ipkg_conf);
  6759. + return (err);
  6760. +}
  6761. +
  6762. +
  6763. +int
  6764. +ipkg_packages_status(args_t *args,
  6765. + const char *packages,
  6766. + ipkg_status_callback cbstatus,
  6767. + void *userdata)
  6768. +{
  6769. + ipkg_cmd_t *cmd;
  6770. + ipkg_conf_t ipkg_conf;
  6771. + int err;
  6772. +
  6773. + err = ipkg_conf_init (&ipkg_conf, args);
  6774. + if (err)
  6775. + {
  6776. + return err;
  6777. + }
  6778. +
  6779. + ipkg_cb_status = cbstatus;
  6780. +
  6781. + /* we need to do this because of static declarations,
  6782. + * maybe a good idea to change */
  6783. + cmd = ipkg_cmd_find ("status");
  6784. + if (packages)
  6785. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6786. + else
  6787. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6788. +
  6789. + ipkg_cb_status = NULL;
  6790. + ipkg_conf_deinit (&ipkg_conf);
  6791. + return (err);
  6792. +}
  6793. +
  6794. +
  6795. +int
  6796. +ipkg_packages_info(args_t *args,
  6797. + const char *packages,
  6798. + ipkg_status_callback cbstatus,
  6799. + void *userdata)
  6800. +{
  6801. + ipkg_cmd_t *cmd;
  6802. + ipkg_conf_t ipkg_conf;
  6803. + int err;
  6804. +
  6805. + err = ipkg_conf_init (&ipkg_conf, args);
  6806. + if (err)
  6807. + {
  6808. + return err;
  6809. + }
  6810. +
  6811. + ipkg_cb_status = cbstatus;
  6812. +
  6813. + /* we need to do this because of static declarations,
  6814. + * maybe a good idea to change */
  6815. + cmd = ipkg_cmd_find ("info");
  6816. + if (packages)
  6817. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &packages, userdata);
  6818. + else
  6819. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, userdata);
  6820. +
  6821. + ipkg_cb_status = NULL;
  6822. + ipkg_conf_deinit (&ipkg_conf);
  6823. + return (err);
  6824. +}
  6825. +
  6826. +
  6827. +int
  6828. +ipkg_packages_install (args_t * args, const char *name)
  6829. +{
  6830. + ipkg_cmd_t *cmd;
  6831. + ipkg_conf_t ipkg_conf;
  6832. + int err;
  6833. +
  6834. + /* this error should be handled in application */
  6835. + if (!name || !strlen (name))
  6836. + return (-1);
  6837. +
  6838. + err = ipkg_conf_init (&ipkg_conf, args);
  6839. + if (err)
  6840. + {
  6841. + return err;
  6842. + }
  6843. +
  6844. + /* we need to do this because of static declarations,
  6845. + * maybe a good idea to change */
  6846. + cmd = ipkg_cmd_find ("install");
  6847. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6848. +
  6849. + ipkg_conf_deinit(&ipkg_conf);
  6850. + return (err);
  6851. +}
  6852. +
  6853. +
  6854. +int
  6855. +ipkg_packages_remove(args_t *args, const char *name, int purge)
  6856. +{
  6857. + ipkg_cmd_t *cmd;
  6858. + ipkg_conf_t ipkg_conf;
  6859. + int err;
  6860. +
  6861. + /* this error should be handled in application */
  6862. + if (!name || !strlen (name))
  6863. + return (-1);
  6864. +
  6865. + err = ipkg_conf_init (&ipkg_conf, args);
  6866. + if (err)
  6867. + {
  6868. + return err;
  6869. + }
  6870. +
  6871. + /* we need to do this because of static declarations,
  6872. + * maybe a good idea to change */
  6873. + if (purge)
  6874. + cmd = ipkg_cmd_find ("purge");
  6875. + else
  6876. + cmd = ipkg_cmd_find ("remove");
  6877. +
  6878. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6879. +
  6880. + ipkg_conf_deinit(&ipkg_conf);
  6881. + return (err);
  6882. +}
  6883. +
  6884. +
  6885. +int
  6886. +ipkg_lists_update(args_t *args)
  6887. +{
  6888. + ipkg_cmd_t *cmd;
  6889. + ipkg_conf_t ipkg_conf;
  6890. + int err;
  6891. +
  6892. + err = ipkg_conf_init (&ipkg_conf, args);
  6893. + if (err)
  6894. + {
  6895. + return err;
  6896. + }
  6897. +
  6898. + /* we need to do this because of static declarations,
  6899. + * maybe a good idea to change */
  6900. + cmd = ipkg_cmd_find ("update");
  6901. +
  6902. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6903. +
  6904. + ipkg_conf_deinit(&ipkg_conf);
  6905. + return (err);
  6906. +}
  6907. +
  6908. +
  6909. +int
  6910. +ipkg_packages_upgrade(args_t *args)
  6911. +{
  6912. + ipkg_cmd_t *cmd;
  6913. + ipkg_conf_t ipkg_conf;
  6914. + int err;
  6915. +
  6916. + err = ipkg_conf_init (&ipkg_conf, args);
  6917. + if (err)
  6918. + {
  6919. + return err;
  6920. + }
  6921. +
  6922. + /* we need to do this because of static declarations,
  6923. + * maybe a good idea to change */
  6924. + cmd = ipkg_cmd_find ("upgrade");
  6925. +
  6926. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 0, NULL, NULL);
  6927. +
  6928. + ipkg_conf_deinit(&ipkg_conf);
  6929. + return (err);
  6930. +}
  6931. +
  6932. +
  6933. +int
  6934. +ipkg_packages_download (args_t * args, const char *name)
  6935. +{
  6936. + ipkg_cmd_t *cmd;
  6937. + ipkg_conf_t ipkg_conf;
  6938. + int err;
  6939. +
  6940. + /* this error should be handled in application */
  6941. + if (!name || !strlen (name))
  6942. + return (-1);
  6943. +
  6944. + err = ipkg_conf_init (&ipkg_conf, args);
  6945. + if (err)
  6946. + {
  6947. + return err;
  6948. + }
  6949. +
  6950. + /* we need to do this because of static declarations,
  6951. + * maybe a good idea to change */
  6952. + cmd = ipkg_cmd_find ("download");
  6953. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, NULL);
  6954. +
  6955. + ipkg_conf_deinit(&ipkg_conf);
  6956. + return (err);
  6957. +}
  6958. +
  6959. +
  6960. +int
  6961. +ipkg_package_files(args_t *args,
  6962. + const char *name,
  6963. + ipkg_list_callback cblist,
  6964. + void *userdata)
  6965. +{
  6966. + ipkg_cmd_t *cmd;
  6967. + ipkg_conf_t ipkg_conf;
  6968. + int err;
  6969. +
  6970. + /* this error should be handled in application */
  6971. + if (!name || !strlen (name))
  6972. + return (-1);
  6973. +
  6974. + err = ipkg_conf_init (&ipkg_conf, args);
  6975. + if (err)
  6976. + {
  6977. + return err;
  6978. + }
  6979. +
  6980. + ipkg_cb_list = cblist;
  6981. +
  6982. + /* we need to do this because of static declarations,
  6983. + * maybe a good idea to change */
  6984. + cmd = ipkg_cmd_find ("files");
  6985. +
  6986. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &name, userdata);
  6987. +
  6988. + ipkg_cb_list = NULL;
  6989. + ipkg_conf_deinit(&ipkg_conf);
  6990. + return (err);
  6991. +}
  6992. +
  6993. +
  6994. +int
  6995. +ipkg_file_search(args_t *args,
  6996. + const char *file,
  6997. + ipkg_list_callback cblist,
  6998. + void *userdata)
  6999. +{
  7000. + ipkg_cmd_t *cmd;
  7001. + ipkg_conf_t ipkg_conf;
  7002. + int err;
  7003. +
  7004. + /* this error should be handled in application */
  7005. + if (!file || !strlen (file))
  7006. + return (-1);
  7007. +
  7008. + err = ipkg_conf_init (&ipkg_conf, args);
  7009. + if (err)
  7010. + {
  7011. + return err;
  7012. + }
  7013. +
  7014. + ipkg_cb_list = cblist;
  7015. +
  7016. + /* we need to do this because of static declarations,
  7017. + * maybe a good idea to change */
  7018. + cmd = ipkg_cmd_find ("search");
  7019. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, userdata);
  7020. +
  7021. + ipkg_cb_list = NULL;
  7022. + ipkg_conf_deinit(&ipkg_conf);
  7023. + return(err);
  7024. +}
  7025. +
  7026. +
  7027. +int
  7028. +ipkg_file_what(args_t *args, const char *file, const char* command)
  7029. +{
  7030. + ipkg_cmd_t *cmd;
  7031. + ipkg_conf_t ipkg_conf;
  7032. + int err;
  7033. +
  7034. + /* this error should be handled in application */
  7035. + if (!file || !strlen (file))
  7036. + return (-1);
  7037. +
  7038. + err = ipkg_conf_init (&ipkg_conf, args);
  7039. + if (err)
  7040. + {
  7041. + return err;
  7042. + }
  7043. +
  7044. + /* we need to do this because of static declarations,
  7045. + * maybe a good idea to change */
  7046. + cmd = ipkg_cmd_find (command);
  7047. + err = ipkg_cmd_exec (cmd, &ipkg_conf, 1, &file, NULL);
  7048. +
  7049. + ipkg_conf_deinit(&ipkg_conf);
  7050. + return(err);
  7051. +}
  7052. +
  7053. +#define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
  7054. +#define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
  7055. +#define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
  7056. +#define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
  7057. +#define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
  7058. +
  7059. +
  7060. +int default_ipkg_message_callback(ipkg_conf_t *conf, message_level_t level,
  7061. + char *msg)
  7062. +{
  7063. + if (conf && (conf->verbosity < level)) {
  7064. + return 0;
  7065. + } else {
  7066. + if ( level == IPKG_ERROR )
  7067. + push_error_list(&error_list, msg);
  7068. + else
  7069. + printf(msg);
  7070. + }
  7071. + return 0;
  7072. +}
  7073. +
  7074. +int default_ipkg_list_callback(char *name, char *desc, char *version)
  7075. +{
  7076. + if (desc)
  7077. + printf("%s - %s - %s\n", name, version, desc);
  7078. + else
  7079. + printf("%s - %s\n", name, version);
  7080. + return 0;
  7081. +}
  7082. +
  7083. +int default_ipkg_files_callback(char *desc)
  7084. +{
  7085. + if (desc)
  7086. + printf("%s\n", desc);
  7087. + return 0;
  7088. +}
  7089. +
  7090. +int default_ipkg_status_callback(char *desc)
  7091. +{
  7092. + printf("%s\n", desc);
  7093. + return 0;
  7094. +}
  7095. +
  7096. +char* default_ipkg_response_callback(char *question)
  7097. +{
  7098. + char *response = NULL;
  7099. + printf(question);
  7100. + fflush(stdout);
  7101. + do {
  7102. + response = (char *)file_read_line_alloc(stdin);
  7103. + } while (response == NULL);
  7104. + return response;
  7105. +}
  7106. +
  7107. +/* This is used for backward compatibility */
  7108. +int
  7109. +ipkg_op (int argc, char *argv[])
  7110. +{
  7111. + int err, optind_;
  7112. + args_t args;
  7113. + char *cmd_name;
  7114. + ipkg_cmd_t *cmd;
  7115. + ipkg_conf_t ipkg_conf;
  7116. + const char *message = "ipkg must have one sub-command argument";
  7117. + FILE *f;
  7118. + struct mntent *mnt;
  7119. + int remountroot;
  7120. +
  7121. + args_init (&args);
  7122. +
  7123. + optind_ = args_parse (&args, argc, argv);
  7124. + if (optind_ == argc || optind_ < 0)
  7125. + {
  7126. + args_usage(message);
  7127. + }
  7128. +
  7129. + cmd_name = argv[optind_++];
  7130. +/* Pigi: added a flag to disable the checking of structures if the command does not need to
  7131. + read anything from there.
  7132. +*/
  7133. + if ( !strcmp(cmd_name,"print-architecture") ||
  7134. + !strcmp(cmd_name,"print_architecture") ||
  7135. + !strcmp(cmd_name,"print-installation-architecture") ||
  7136. + !strcmp(cmd_name,"print_installation_architecture") )
  7137. + args.nocheckfordirorfile = 1;
  7138. +
  7139. +/* Pigi: added a flag to disable the reading of feed files if the command does not need to
  7140. + read anything from there.
  7141. +*/
  7142. + if ( !strcmp(cmd_name,"flag") ||
  7143. + !strcmp(cmd_name,"configure") ||
  7144. + !strcmp(cmd_name,"remove") ||
  7145. + !strcmp(cmd_name,"files") ||
  7146. + !strcmp(cmd_name,"search") ||
  7147. + !strcmp(cmd_name,"compare_versions") ||
  7148. + !strcmp(cmd_name,"compare-versions") ||
  7149. + !strcmp(cmd_name,"list_installed") ||
  7150. + !strcmp(cmd_name,"list-installed") ||
  7151. + !strcmp(cmd_name,"status") )
  7152. + args.noreadfeedsfile = 1;
  7153. +
  7154. +
  7155. +
  7156. +
  7157. + err = ipkg_conf_init (&ipkg_conf, &args);
  7158. + if (err)
  7159. + {
  7160. + return err;
  7161. + }
  7162. +
  7163. + args_deinit (&args);
  7164. +
  7165. + ipkg_cb_message = default_ipkg_message_callback;
  7166. + ipkg_cb_response = default_ipkg_response_callback;
  7167. + ipkg_cb_status = (ipkg_status_callback)default_ipkg_status_callback;
  7168. + if ( strcmp(cmd_name, "files")==0)
  7169. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_files_callback;
  7170. + else
  7171. + ipkg_cb_list = (ipkg_list_callback)default_ipkg_list_callback;
  7172. +
  7173. + cmd = ipkg_cmd_find (cmd_name);
  7174. + if (cmd == NULL)
  7175. + {
  7176. + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
  7177. + cmd_name);
  7178. + args_usage (NULL);
  7179. + }
  7180. +
  7181. + if (cmd->requires_args && optind_ == argc)
  7182. + {
  7183. + fprintf (stderr,
  7184. + "%s: the ``%s'' command requires at least one argument\n",
  7185. + __FUNCTION__, cmd_name);
  7186. + args_usage (NULL);
  7187. + }
  7188. +
  7189. + remountroot = 0;
  7190. + /* check if /dev/root is mounted read-only */
  7191. + if ((f = setmntent("/proc/mounts", "r")) == NULL)
  7192. + fprintf (stderr, "Checking /proc/mounts failed\n");
  7193. +
  7194. + while ((mnt = getmntent(f)) != NULL) {
  7195. + if (strcmp(mnt->mnt_fsname, "/dev/root") == 0 &&
  7196. + hasmntopt(mnt, MNTOPT_RO) != NULL) {
  7197. + remountroot = 1;
  7198. + }
  7199. + }
  7200. +
  7201. + endmntent(f);
  7202. +
  7203. + if (remountroot) {
  7204. + if ( !strcmp(cmd_name,"install") ||
  7205. + !strcmp(cmd_name,"update") ||
  7206. + !strcmp(cmd_name,"upgrade") ||
  7207. + !strcmp(cmd_name,"flag") ||
  7208. + !strcmp(cmd_name,"configure") ||
  7209. + !strcmp(cmd_name,"remove") ) {
  7210. + /* mount rootfs read-write */
  7211. + if (mount("","/",0,MS_REMOUNT,0)<0)
  7212. + fprintf (stderr, "Mounting rootfs read-write failed\n");
  7213. + }
  7214. + }
  7215. +
  7216. + err = ipkg_cmd_exec (cmd, &ipkg_conf, argc - optind_, (const char **) (argv + optind_), NULL);
  7217. +
  7218. + ipkg_conf_deinit (&ipkg_conf);
  7219. +
  7220. + if (remountroot) {
  7221. + if ( !strcmp(cmd_name,"install") ||
  7222. + !strcmp(cmd_name,"update") ||
  7223. + !strcmp(cmd_name,"upgrade") ||
  7224. + !strcmp(cmd_name,"flag") ||
  7225. + !strcmp(cmd_name,"configure") ||
  7226. + !strcmp(cmd_name,"remove") ) {
  7227. + sync();
  7228. + /* mount rootfs read-only */
  7229. + if (mount("","/",0,MS_REMOUNT|MS_RDONLY,0)<0)
  7230. + fprintf (stderr, "Mounting rootfs read-only failed\n");
  7231. + }
  7232. + }
  7233. +
  7234. + /* check if cfgfs exists */
  7235. + if (access("/sbin/cfgfs", X_OK) == 0) {
  7236. + if ( !strcmp(cmd_name,"install") ||
  7237. + !strcmp(cmd_name,"update") ||
  7238. + !strcmp(cmd_name,"upgrade")) {
  7239. + if (system("cfgfs status -q") != 0) {
  7240. + fprintf (stdout, "Updates in /etc, please review changes\n");
  7241. + fprintf (stdout, "You can check via cfgfs status\n");
  7242. + }
  7243. + }
  7244. + }
  7245. +
  7246. + return err;
  7247. +}
  7248. diff -Nur busybox-1.24.1.orig/archival/libipkg/libipkg.h busybox-1.24.1/archival/libipkg/libipkg.h
  7249. --- busybox-1.24.1.orig/archival/libipkg/libipkg.h 1970-01-01 01:00:00.000000000 +0100
  7250. +++ busybox-1.24.1/archival/libipkg/libipkg.h 2015-10-31 19:00:22.000000000 +0100
  7251. @@ -0,0 +1,78 @@
  7252. +/* ipkglib.h - the itsy package management system
  7253. +
  7254. + Florian Boor <florian.boor@kernelconcepts.de>
  7255. +
  7256. + This program is free software; you can redistribute it and/or
  7257. + modify it under the terms of the GNU General Public License as
  7258. + published by the Free Software Foundation; either version 2, or (at
  7259. + your option) any later version.
  7260. +
  7261. + This program is distributed in the hope that it will be useful, but
  7262. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7263. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7264. + General Public License for more details.
  7265. +*/
  7266. +
  7267. +#ifndef IPKGLIB_H
  7268. +#define IPKGLIB_H
  7269. +
  7270. +#include "ipkg_conf.h"
  7271. +#include "ipkg_message.h"
  7272. +
  7273. +#include "args.h"
  7274. +#include "pkg.h"
  7275. +
  7276. +typedef int (*ipkg_message_callback)(ipkg_conf_t *conf, message_level_t level,
  7277. + char *msg);
  7278. +typedef int (*ipkg_list_callback)(char *name, char *desc, char *version,
  7279. + pkg_state_status_t status, void *userdata);
  7280. +typedef int (*ipkg_status_callback)(char *name, int istatus, char *desc,
  7281. + void *userdata);
  7282. +typedef char* (*ipkg_response_callback)(char *question);
  7283. +
  7284. +extern int ipkg_op(int argc, char *argv[]); /* ipkglib.c */
  7285. +extern int ipkg_init (ipkg_message_callback mcall,
  7286. + ipkg_response_callback rcall,
  7287. + args_t * args);
  7288. +
  7289. +extern int ipkg_deinit (args_t *args);
  7290. +extern int ipkg_packages_list(args_t *args,
  7291. + const char *packages,
  7292. + ipkg_list_callback cblist,
  7293. + void *userdata);
  7294. +extern int ipkg_packages_status(args_t *args,
  7295. + const char *packages,
  7296. + ipkg_status_callback cbstatus,
  7297. + void *userdata);
  7298. +extern int ipkg_packages_info(args_t *args,
  7299. + const char *packages,
  7300. + ipkg_status_callback cbstatus,
  7301. + void *userdata);
  7302. +extern int ipkg_packages_install(args_t *args, const char *name);
  7303. +extern int ipkg_packages_remove(args_t *args, const char *name, int purge);
  7304. +extern int ipkg_lists_update(args_t *args);
  7305. +extern int ipkg_packages_upgrade(args_t *args);
  7306. +extern int ipkg_packages_download(args_t *args, const char *name);
  7307. +extern int ipkg_package_files(args_t *args,
  7308. + const char *name,
  7309. + ipkg_list_callback cblist,
  7310. + void *userdata);
  7311. +extern int ipkg_file_search(args_t *args,
  7312. + const char *file,
  7313. + ipkg_list_callback cblist,
  7314. + void *userdata);
  7315. +extern int ipkg_package_whatdepends(args_t *args, const char *file);
  7316. +extern int ipkg_package_whatrecommends(args_t *args, const char *file);
  7317. +extern int ipkg_package_whatprovides(args_t *args, const char *file);
  7318. +extern int ipkg_package_whatconflicts(args_t *args, const char *file);
  7319. +extern int ipkg_package_whatreplaces(args_t *args, const char *file);
  7320. +
  7321. +extern ipkg_message_callback ipkg_cb_message; /* ipkglib.c */
  7322. +extern ipkg_response_callback ipkg_cb_response;
  7323. +extern ipkg_status_callback ipkg_cb_status;
  7324. +extern ipkg_list_callback ipkg_cb_list;
  7325. +extern void push_error_list(struct errlist **errors,char * msg);
  7326. +extern void reverse_error_list(struct errlist **errors);
  7327. +extern void free_error_list(struct errlist **errors);
  7328. +
  7329. +#endif
  7330. diff -Nur busybox-1.24.1.orig/archival/libipkg/nv_pair.c busybox-1.24.1/archival/libipkg/nv_pair.c
  7331. --- busybox-1.24.1.orig/archival/libipkg/nv_pair.c 1970-01-01 01:00:00.000000000 +0100
  7332. +++ busybox-1.24.1/archival/libipkg/nv_pair.c 2015-10-31 19:00:22.000000000 +0100
  7333. @@ -0,0 +1,40 @@
  7334. +/* nv_pair.c - the itsy package management system
  7335. +
  7336. + Carl D. Worth
  7337. +
  7338. + Copyright (C) 2001 University of Southern California
  7339. +
  7340. + This program is free software; you can redistribute it and/or
  7341. + modify it under the terms of the GNU General Public License as
  7342. + published by the Free Software Foundation; either version 2, or (at
  7343. + your option) any later version.
  7344. +
  7345. + This program is distributed in the hope that it will be useful, but
  7346. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7347. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7348. + General Public License for more details.
  7349. +*/
  7350. +
  7351. +#include "ipkg.h"
  7352. +
  7353. +#include "nv_pair.h"
  7354. +#include "str_util.h"
  7355. +
  7356. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
  7357. +{
  7358. + nv_pair->name = str_dup_safe(name);
  7359. + nv_pair->value = str_dup_safe(value);
  7360. +
  7361. + return 0;
  7362. +}
  7363. +
  7364. +void nv_pair_deinit(nv_pair_t *nv_pair)
  7365. +{
  7366. + free(nv_pair->name);
  7367. + nv_pair->name = NULL;
  7368. +
  7369. + free(nv_pair->value);
  7370. + nv_pair->value = NULL;
  7371. +}
  7372. +
  7373. +
  7374. diff -Nur busybox-1.24.1.orig/archival/libipkg/nv_pair.h busybox-1.24.1/archival/libipkg/nv_pair.h
  7375. --- busybox-1.24.1.orig/archival/libipkg/nv_pair.h 1970-01-01 01:00:00.000000000 +0100
  7376. +++ busybox-1.24.1/archival/libipkg/nv_pair.h 2015-10-31 19:00:22.000000000 +0100
  7377. @@ -0,0 +1,32 @@
  7378. +/* nv_pair.h - the itsy package management system
  7379. +
  7380. + Carl D. Worth
  7381. +
  7382. + Copyright (C) 2001 University of Southern California
  7383. +
  7384. + This program is free software; you can redistribute it and/or
  7385. + modify it under the terms of the GNU General Public License as
  7386. + published by the Free Software Foundation; either version 2, or (at
  7387. + your option) any later version.
  7388. +
  7389. + This program is distributed in the hope that it will be useful, but
  7390. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7391. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7392. + General Public License for more details.
  7393. +*/
  7394. +
  7395. +#ifndef NV_PAIR_H
  7396. +#define NV_PAIR_H
  7397. +
  7398. +typedef struct nv_pair nv_pair_t;
  7399. +struct nv_pair
  7400. +{
  7401. + char *name;
  7402. + char *value;
  7403. +};
  7404. +
  7405. +int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value);
  7406. +void nv_pair_deinit(nv_pair_t *nv_pair);
  7407. +
  7408. +#endif
  7409. +
  7410. diff -Nur busybox-1.24.1.orig/archival/libipkg/nv_pair_list.c busybox-1.24.1/archival/libipkg/nv_pair_list.c
  7411. --- busybox-1.24.1.orig/archival/libipkg/nv_pair_list.c 1970-01-01 01:00:00.000000000 +0100
  7412. +++ busybox-1.24.1/archival/libipkg/nv_pair_list.c 2015-10-31 19:00:22.000000000 +0100
  7413. @@ -0,0 +1,98 @@
  7414. +/* nv_pair_list.c - the itsy package management system
  7415. +
  7416. + Carl D. Worth
  7417. +
  7418. + Copyright (C) 2001 University of Southern California
  7419. +
  7420. + This program is free software; you can redistribute it and/or
  7421. + modify it under the terms of the GNU General Public License as
  7422. + published by the Free Software Foundation; either version 2, or (at
  7423. + your option) any later version.
  7424. +
  7425. + This program is distributed in the hope that it will be useful, but
  7426. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7427. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7428. + General Public License for more details.
  7429. +*/
  7430. +
  7431. +#include "ipkg.h"
  7432. +
  7433. +#include "nv_pair.h"
  7434. +#include "void_list.h"
  7435. +#include "nv_pair_list.h"
  7436. +
  7437. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
  7438. +{
  7439. + return void_list_elt_init((void_list_elt_t *) elt, data);
  7440. +}
  7441. +
  7442. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
  7443. +{
  7444. + void_list_elt_deinit((void_list_elt_t *) elt);
  7445. +}
  7446. +
  7447. +int nv_pair_list_init(nv_pair_list_t *list)
  7448. +{
  7449. + return void_list_init((void_list_t *) list);
  7450. +}
  7451. +
  7452. +void nv_pair_list_deinit(nv_pair_list_t *list)
  7453. +{
  7454. + nv_pair_list_elt_t *iter;
  7455. + nv_pair_t *nv_pair;
  7456. +
  7457. + for (iter = list->head; iter; iter = iter->next) {
  7458. + nv_pair = iter->data;
  7459. + nv_pair_deinit(nv_pair);
  7460. +
  7461. + /* malloced in nv_pair_list_append */
  7462. + free(nv_pair);
  7463. + iter->data = NULL;
  7464. + }
  7465. + void_list_deinit((void_list_t *) list);
  7466. +}
  7467. +
  7468. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list, const char *name, const char *value)
  7469. +{
  7470. + int err;
  7471. +
  7472. + /* freed in nv_pair_list_deinit */
  7473. + nv_pair_t *nv_pair = malloc(sizeof(nv_pair_t));
  7474. +
  7475. + if (nv_pair == NULL) {
  7476. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7477. + return NULL;
  7478. + }
  7479. + nv_pair_init(nv_pair, name, value);
  7480. +
  7481. + err = void_list_append((void_list_t *) list, nv_pair);
  7482. + if (err) {
  7483. + return NULL;
  7484. + }
  7485. +
  7486. + return nv_pair;
  7487. +}
  7488. +
  7489. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data)
  7490. +{
  7491. + return void_list_push((void_list_t *) list, data);
  7492. +}
  7493. +
  7494. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list)
  7495. +{
  7496. + return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  7497. +}
  7498. +
  7499. +char *nv_pair_list_find(nv_pair_list_t *list, char *name)
  7500. +{
  7501. + nv_pair_list_elt_t *iter;
  7502. + nv_pair_t *nv_pair;
  7503. +
  7504. + for (iter = list->head; iter; iter = iter->next) {
  7505. + nv_pair = iter->data;
  7506. + if (strcmp(nv_pair->name, name) == 0) {
  7507. + return nv_pair->value;
  7508. + }
  7509. + }
  7510. + return NULL;
  7511. +}
  7512. diff -Nur busybox-1.24.1.orig/archival/libipkg/nv_pair_list.h busybox-1.24.1/archival/libipkg/nv_pair_list.h
  7513. --- busybox-1.24.1.orig/archival/libipkg/nv_pair_list.h 1970-01-01 01:00:00.000000000 +0100
  7514. +++ busybox-1.24.1/archival/libipkg/nv_pair_list.h 2015-10-31 19:00:22.000000000 +0100
  7515. @@ -0,0 +1,60 @@
  7516. +/* nv_pair_list.h - the itsy package management system
  7517. +
  7518. + Carl D. Worth
  7519. +
  7520. + Copyright (C) 2001 University of Southern California
  7521. +
  7522. + This program is free software; you can redistribute it and/or
  7523. + modify it under the terms of the GNU General Public License as
  7524. + published by the Free Software Foundation; either version 2, or (at
  7525. + your option) any later version.
  7526. +
  7527. + This program is distributed in the hope that it will be useful, but
  7528. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7529. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7530. + General Public License for more details.
  7531. +*/
  7532. +
  7533. +#ifndef NV_PAIR_LIST_H
  7534. +#define NV_PAIR_LIST_H
  7535. +
  7536. +#include "nv_pair.h"
  7537. +#include "void_list.h"
  7538. +
  7539. +typedef struct nv_pair_list_elt nv_pair_list_elt_t;
  7540. +struct nv_pair_list_elt
  7541. +{
  7542. + nv_pair_list_elt_t *next;
  7543. + nv_pair_t *data;
  7544. +};
  7545. +
  7546. +typedef struct nv_pair_list nv_pair_list_t;
  7547. +struct nv_pair_list
  7548. +{
  7549. + nv_pair_list_elt_t pre_head;
  7550. + nv_pair_list_elt_t *head;
  7551. + nv_pair_list_elt_t *tail;
  7552. +};
  7553. +
  7554. +static inline int nv_pair_list_empty(nv_pair_list_t *list)
  7555. +{
  7556. + if (list->head == NULL)
  7557. + return 1;
  7558. + else
  7559. + return 0;
  7560. +}
  7561. +
  7562. +int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
  7563. +void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
  7564. +
  7565. +int nv_pair_list_init(nv_pair_list_t *list);
  7566. +void nv_pair_list_deinit(nv_pair_list_t *list);
  7567. +
  7568. +nv_pair_t *nv_pair_list_append(nv_pair_list_t *list,
  7569. + const char *name, const char *value);
  7570. +int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
  7571. +nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
  7572. +char *nv_pair_list_find(nv_pair_list_t *list, char *name);
  7573. +
  7574. +#endif
  7575. +
  7576. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg.c busybox-1.24.1/archival/libipkg/pkg.c
  7577. --- busybox-1.24.1.orig/archival/libipkg/pkg.c 1970-01-01 01:00:00.000000000 +0100
  7578. +++ busybox-1.24.1/archival/libipkg/pkg.c 2015-10-31 19:00:22.000000000 +0100
  7579. @@ -0,0 +1,1757 @@
  7580. +/* pkg.c - the itsy package management system
  7581. +
  7582. + Carl D. Worth
  7583. +
  7584. + Copyright (C) 2001 University of Southern California
  7585. +
  7586. + This program is free software; you can redistribute it and/or
  7587. + modify it under the terms of the GNU General Public License as
  7588. + published by the Free Software Foundation; either version 2, or (at
  7589. + your option) any later version.
  7590. +
  7591. + This program is distributed in the hope that it will be useful, but
  7592. + WITHOUT ANY WARRANTY; without even the implied warranty of
  7593. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  7594. + General Public License for more details.
  7595. +*/
  7596. +
  7597. +#include "ipkg.h"
  7598. +#include <ctype.h>
  7599. +#include <string.h>
  7600. +#include <errno.h>
  7601. +
  7602. +#include "pkg.h"
  7603. +
  7604. +#include "pkg_parse.h"
  7605. +#include "pkg_extract.h"
  7606. +#include "ipkg_message.h"
  7607. +#include "ipkg_utils.h"
  7608. +
  7609. +#include "sprintf_alloc.h"
  7610. +#include "file_util.h"
  7611. +#include "str_util.h"
  7612. +#include "xsystem.h"
  7613. +#include "ipkg_conf.h"
  7614. +
  7615. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname);
  7616. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_);
  7617. +
  7618. +typedef struct enum_map enum_map_t;
  7619. +struct enum_map
  7620. +{
  7621. + int value;
  7622. + const char *str;
  7623. +};
  7624. +
  7625. +static const enum_map_t pkg_state_want_map[] = {
  7626. + { SW_UNKNOWN, "unknown"},
  7627. + { SW_INSTALL, "install"},
  7628. + { SW_DEINSTALL, "deinstall"},
  7629. + { SW_PURGE, "purge"}
  7630. +};
  7631. +
  7632. +static const enum_map_t pkg_state_flag_map[] = {
  7633. + { SF_OK, "ok"},
  7634. + { SF_REINSTREQ, "reinstreq"},
  7635. + { SF_HOLD, "hold"},
  7636. + { SF_REPLACE, "replace"},
  7637. + { SF_NOPRUNE, "noprune"},
  7638. + { SF_PREFER, "prefer"},
  7639. + { SF_OBSOLETE, "obsolete"},
  7640. + { SF_USER, "user"},
  7641. +};
  7642. +
  7643. +static const enum_map_t pkg_state_status_map[] = {
  7644. + { SS_NOT_INSTALLED, "not-installed" },
  7645. + { SS_UNPACKED, "unpacked" },
  7646. + { SS_HALF_CONFIGURED, "half-configured" },
  7647. + { SS_INSTALLED, "installed" },
  7648. + { SS_HALF_INSTALLED, "half-installed" },
  7649. + { SS_CONFIG_FILES, "config-files" },
  7650. + { SS_POST_INST_FAILED, "post-inst-failed" },
  7651. + { SS_REMOVAL_FAILED, "removal-failed" }
  7652. +};
  7653. +
  7654. +static int verrevcmp(const char *val, const char *ref);
  7655. +
  7656. +
  7657. +pkg_t *pkg_new(void)
  7658. +{
  7659. + pkg_t *pkg;
  7660. +
  7661. + pkg = malloc(sizeof(pkg_t));
  7662. + if (pkg == NULL) {
  7663. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7664. + return NULL;
  7665. + }
  7666. +
  7667. + pkg_init(pkg);
  7668. +
  7669. + return pkg;
  7670. +}
  7671. +
  7672. +int pkg_init(pkg_t *pkg)
  7673. +{
  7674. + memset(pkg, 0, sizeof(pkg_t));
  7675. + pkg->name = NULL;
  7676. + pkg->epoch = 0;
  7677. + pkg->version = NULL;
  7678. + pkg->revision = NULL;
  7679. + pkg->familiar_revision = NULL;
  7680. + pkg->dest = NULL;
  7681. + pkg->src = NULL;
  7682. + pkg->architecture = NULL;
  7683. + pkg->maintainer = NULL;
  7684. + pkg->section = NULL;
  7685. + pkg->description = NULL;
  7686. + pkg->state_want = SW_UNKNOWN;
  7687. + pkg->state_flag = SF_OK;
  7688. + pkg->state_status = SS_NOT_INSTALLED;
  7689. + pkg->depends_str = NULL;
  7690. + pkg->provides_str = NULL;
  7691. + pkg->depends_count = 0;
  7692. + pkg->depends = NULL;
  7693. + pkg->suggests_str = NULL;
  7694. + pkg->recommends_str = NULL;
  7695. + pkg->suggests_count = 0;
  7696. + pkg->recommends_count = 0;
  7697. +
  7698. + /* Abhaya: added init for conflicts fields */
  7699. + pkg->conflicts = NULL;
  7700. + pkg->conflicts_count = 0;
  7701. +
  7702. + /* added for replaces. Jamey 7/23/2002 */
  7703. + pkg->replaces = NULL;
  7704. + pkg->replaces_count = 0;
  7705. +
  7706. + pkg->pre_depends_count = 0;
  7707. + pkg->pre_depends_str = NULL;
  7708. + pkg->provides_count = 0;
  7709. + pkg->provides = NULL;
  7710. + pkg->filename = NULL;
  7711. + pkg->local_filename = NULL;
  7712. + pkg->tmp_unpack_dir = NULL;
  7713. + pkg->md5sum = NULL;
  7714. + pkg->size = NULL;
  7715. + pkg->installed_size = NULL;
  7716. + pkg->priority = NULL;
  7717. + pkg->source = NULL;
  7718. + conffile_list_init(&pkg->conffiles);
  7719. + pkg->installed_files = NULL;
  7720. + pkg->installed_files_ref_cnt = 0;
  7721. + pkg->essential = 0;
  7722. + pkg->provided_by_hand = 0;
  7723. +
  7724. + return 0;
  7725. +}
  7726. +
  7727. +void pkg_deinit(pkg_t *pkg)
  7728. +{
  7729. + free(pkg->name);
  7730. + pkg->name = NULL;
  7731. + pkg->epoch = 0;
  7732. + free(pkg->version);
  7733. + pkg->version = NULL;
  7734. + /* revision and familiar_revision share storage with version, so
  7735. + don't free */
  7736. + pkg->revision = NULL;
  7737. + pkg->familiar_revision = NULL;
  7738. + /* owned by ipkg_conf_t */
  7739. + pkg->dest = NULL;
  7740. + /* owned by ipkg_conf_t */
  7741. + pkg->src = NULL;
  7742. + free(pkg->architecture);
  7743. + pkg->architecture = NULL;
  7744. + free(pkg->maintainer);
  7745. + pkg->maintainer = NULL;
  7746. + free(pkg->section);
  7747. + pkg->section = NULL;
  7748. + free(pkg->description);
  7749. + pkg->description = NULL;
  7750. + pkg->state_want = SW_UNKNOWN;
  7751. + pkg->state_flag = SF_OK;
  7752. + pkg->state_status = SS_NOT_INSTALLED;
  7753. + free(pkg->depends_str);
  7754. + pkg->depends_str = NULL;
  7755. + free(pkg->provides_str);
  7756. + pkg->provides_str = NULL;
  7757. + pkg->depends_count = 0;
  7758. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
  7759. + pkg->pre_depends_count = 0;
  7760. + free(pkg->pre_depends_str);
  7761. + pkg->pre_depends_str = NULL;
  7762. + pkg->provides_count = 0;
  7763. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
  7764. + /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
  7765. + free(pkg->filename);
  7766. + pkg->filename = NULL;
  7767. + free(pkg->local_filename);
  7768. + pkg->local_filename = NULL;
  7769. + /* CLEANUP: It'd be nice to pullin the cleanup function from
  7770. + ipkg_install.c here. See comment in
  7771. + ipkg_install.c:cleanup_temporary_files */
  7772. + free(pkg->tmp_unpack_dir);
  7773. + pkg->tmp_unpack_dir = NULL;
  7774. + free(pkg->md5sum);
  7775. + pkg->md5sum = NULL;
  7776. + free(pkg->size);
  7777. + pkg->size = NULL;
  7778. + free(pkg->installed_size);
  7779. + pkg->installed_size = NULL;
  7780. + free(pkg->priority);
  7781. + pkg->priority = NULL;
  7782. + free(pkg->source);
  7783. + pkg->source = NULL;
  7784. + conffile_list_deinit(&pkg->conffiles);
  7785. + /* XXX: QUESTION: Is forcing this to 1 correct? I suppose so,
  7786. + since if they are calling deinit, they should know. Maybe do an
  7787. + assertion here instead? */
  7788. + pkg->installed_files_ref_cnt = 1;
  7789. + pkg_free_installed_files(pkg);
  7790. + pkg->essential = 0;
  7791. +}
  7792. +
  7793. +int pkg_init_from_file(pkg_t *pkg, const char *filename)
  7794. +{
  7795. + int err;
  7796. + char **raw;
  7797. + FILE *control_file;
  7798. +
  7799. + err = pkg_init(pkg);
  7800. + if (err) { return err; }
  7801. +
  7802. + pkg->local_filename = strdup(filename);
  7803. +
  7804. + control_file = tmpfile();
  7805. + err = pkg_extract_control_file_to_stream(pkg, control_file);
  7806. + if (err) { return err; }
  7807. +
  7808. + rewind(control_file);
  7809. + raw = read_raw_pkgs_from_stream(control_file);
  7810. + pkg_parse_raw(pkg, &raw, NULL, NULL);
  7811. +
  7812. + fclose(control_file);
  7813. +
  7814. + return 0;
  7815. +}
  7816. +
  7817. +/* Merge any new information in newpkg into oldpkg */
  7818. +/* XXX: CLEANUP: This function shouldn't actually modify anything in
  7819. + newpkg, but should leave it usable. This rework is so that
  7820. + pkg_hash_insert doesn't clobber the pkg that you pass into it. */
  7821. +/*
  7822. + * uh, i thought that i had originally written this so that it took
  7823. + * two pkgs and returned a new one? we can do that again... -sma
  7824. + */
  7825. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
  7826. +{
  7827. + if (oldpkg == newpkg) {
  7828. + return 0;
  7829. + }
  7830. +
  7831. + if (!oldpkg->src)
  7832. + oldpkg->src = newpkg->src;
  7833. + if (!oldpkg->dest)
  7834. + oldpkg->dest = newpkg->dest;
  7835. + if (!oldpkg->architecture)
  7836. + oldpkg->architecture = str_dup_safe(newpkg->architecture);
  7837. + if (!oldpkg->arch_priority)
  7838. + oldpkg->arch_priority = newpkg->arch_priority;
  7839. + if (!oldpkg->section)
  7840. + oldpkg->section = str_dup_safe(newpkg->section);
  7841. + if(!oldpkg->maintainer)
  7842. + oldpkg->maintainer = str_dup_safe(newpkg->maintainer);
  7843. + if(!oldpkg->description)
  7844. + oldpkg->description = str_dup_safe(newpkg->description);
  7845. + if (set_status) {
  7846. + /* merge the state_flags from the new package */
  7847. + oldpkg->state_want = newpkg->state_want;
  7848. + oldpkg->state_status = newpkg->state_status;
  7849. + oldpkg->state_flag = newpkg->state_flag;
  7850. + } else {
  7851. + if (oldpkg->state_want == SW_UNKNOWN)
  7852. + oldpkg->state_want = newpkg->state_want;
  7853. + if (oldpkg->state_status == SS_NOT_INSTALLED)
  7854. + oldpkg->state_status = newpkg->state_status;
  7855. + oldpkg->state_flag |= newpkg->state_flag;
  7856. + }
  7857. +
  7858. + if (!oldpkg->depends_str && !oldpkg->pre_depends_str && !oldpkg->recommends_str && !oldpkg->suggests_str) {
  7859. + oldpkg->depends_str = newpkg->depends_str;
  7860. + newpkg->depends_str = NULL;
  7861. + oldpkg->depends_count = newpkg->depends_count;
  7862. + newpkg->depends_count = 0;
  7863. +
  7864. + oldpkg->depends = newpkg->depends;
  7865. + newpkg->depends = NULL;
  7866. +
  7867. + oldpkg->pre_depends_str = newpkg->pre_depends_str;
  7868. + newpkg->pre_depends_str = NULL;
  7869. + oldpkg->pre_depends_count = newpkg->pre_depends_count;
  7870. + newpkg->pre_depends_count = 0;
  7871. +
  7872. + oldpkg->recommends_str = newpkg->recommends_str;
  7873. + newpkg->recommends_str = NULL;
  7874. + oldpkg->recommends_count = newpkg->recommends_count;
  7875. + newpkg->recommends_count = 0;
  7876. +
  7877. + oldpkg->suggests_str = newpkg->suggests_str;
  7878. + newpkg->suggests_str = NULL;
  7879. + oldpkg->suggests_count = newpkg->suggests_count;
  7880. + newpkg->suggests_count = 0;
  7881. + }
  7882. +
  7883. + if (!oldpkg->provides_str) {
  7884. + oldpkg->provides_str = newpkg->provides_str;
  7885. + newpkg->provides_str = NULL;
  7886. + oldpkg->provides_count = newpkg->provides_count;
  7887. + newpkg->provides_count = 0;
  7888. +
  7889. + oldpkg->provides = newpkg->provides;
  7890. + newpkg->provides = NULL;
  7891. + }
  7892. +
  7893. + if (!oldpkg->conflicts_str) {
  7894. + oldpkg->conflicts_str = newpkg->conflicts_str;
  7895. + newpkg->conflicts_str = NULL;
  7896. + oldpkg->conflicts_count = newpkg->conflicts_count;
  7897. + newpkg->conflicts_count = 0;
  7898. +
  7899. + oldpkg->conflicts = newpkg->conflicts;
  7900. + newpkg->conflicts = NULL;
  7901. + }
  7902. +
  7903. + if (!oldpkg->replaces_str) {
  7904. + oldpkg->replaces_str = newpkg->replaces_str;
  7905. + newpkg->replaces_str = NULL;
  7906. + oldpkg->replaces_count = newpkg->replaces_count;
  7907. + newpkg->replaces_count = 0;
  7908. +
  7909. + oldpkg->replaces = newpkg->replaces;
  7910. + newpkg->replaces = NULL;
  7911. + }
  7912. +
  7913. + if (!oldpkg->filename)
  7914. + oldpkg->filename = str_dup_safe(newpkg->filename);
  7915. + if (0)
  7916. + fprintf(stdout, "pkg=%s old local_filename=%s new local_filename=%s\n",
  7917. + oldpkg->name, oldpkg->local_filename, newpkg->local_filename);
  7918. + if (!oldpkg->local_filename)
  7919. + oldpkg->local_filename = str_dup_safe(newpkg->local_filename);
  7920. + if (!oldpkg->tmp_unpack_dir)
  7921. + oldpkg->tmp_unpack_dir = str_dup_safe(newpkg->tmp_unpack_dir);
  7922. + if (!oldpkg->md5sum)
  7923. + oldpkg->md5sum = str_dup_safe(newpkg->md5sum);
  7924. + if (!oldpkg->size)
  7925. + oldpkg->size = str_dup_safe(newpkg->size);
  7926. + if (!oldpkg->installed_size)
  7927. + oldpkg->installed_size = str_dup_safe(newpkg->installed_size);
  7928. + if (!oldpkg->priority)
  7929. + oldpkg->priority = str_dup_safe(newpkg->priority);
  7930. + if (!oldpkg->source)
  7931. + oldpkg->source = str_dup_safe(newpkg->source);
  7932. + if (oldpkg->conffiles.head == NULL){
  7933. + oldpkg->conffiles = newpkg->conffiles;
  7934. + conffile_list_init(&newpkg->conffiles);
  7935. + }
  7936. + if (!oldpkg->installed_files){
  7937. + oldpkg->installed_files = newpkg->installed_files;
  7938. + oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt;
  7939. + newpkg->installed_files = NULL;
  7940. + }
  7941. + if (!oldpkg->essential)
  7942. + oldpkg->essential = newpkg->essential;
  7943. +
  7944. + return 0;
  7945. +}
  7946. +
  7947. +abstract_pkg_t *abstract_pkg_new(void)
  7948. +{
  7949. + abstract_pkg_t * ab_pkg;
  7950. +
  7951. + ab_pkg = malloc(sizeof(abstract_pkg_t));
  7952. +
  7953. + if (ab_pkg == NULL) {
  7954. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  7955. + return NULL;
  7956. + }
  7957. +
  7958. + if ( abstract_pkg_init(ab_pkg) < 0 )
  7959. + return NULL;
  7960. +
  7961. + return ab_pkg;
  7962. +}
  7963. +
  7964. +int abstract_pkg_init(abstract_pkg_t *ab_pkg)
  7965. +{
  7966. + memset(ab_pkg, 0, sizeof(abstract_pkg_t));
  7967. +
  7968. + ab_pkg->provided_by = abstract_pkg_vec_alloc();
  7969. + if (ab_pkg->provided_by==NULL){
  7970. + return -1;
  7971. + }
  7972. + ab_pkg->dependencies_checked = 0;
  7973. + ab_pkg->state_status = SS_NOT_INSTALLED;
  7974. +
  7975. + return 0;
  7976. +}
  7977. +
  7978. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg){
  7979. + char * temp_str;
  7980. + char **raw =NULL;
  7981. + char **raw_start=NULL;
  7982. +
  7983. + temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
  7984. + if (temp_str == NULL ){
  7985. + ipkg_message(conf, IPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
  7986. + return;
  7987. + }
  7988. + sprintf( temp_str,"%s/%s.control",pkg->dest->info_dir,pkg->name);
  7989. +
  7990. + raw = raw_start = read_raw_pkgs_from_file(temp_str);
  7991. + if (raw == NULL ){
  7992. + ipkg_message(conf, IPKG_ERROR, "Unable to open the control file in %s\n", __FUNCTION__);
  7993. + return;
  7994. + }
  7995. +
  7996. + while(*raw){
  7997. + if (!pkg_valorize_other_field(pkg, &raw ) == 0) {
  7998. + ipkg_message(conf, IPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name);
  7999. + }
  8000. + }
  8001. + raw = raw_start;
  8002. + while (*raw) {
  8003. + if (raw!=NULL)
  8004. + free(*raw++);
  8005. + }
  8006. +
  8007. + free(raw_start);
  8008. + free(temp_str);
  8009. +
  8010. + return ;
  8011. +
  8012. +}
  8013. +
  8014. +char * pkg_formatted_info(pkg_t *pkg )
  8015. +{
  8016. + char *line;
  8017. + char * buff;
  8018. +
  8019. + buff = malloc(8192);
  8020. + if (buff == NULL) {
  8021. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8022. + return NULL;
  8023. + }
  8024. +
  8025. + buff[0] = '\0';
  8026. +
  8027. + line = pkg_formatted_field(pkg, "Package");
  8028. + strncat(buff ,line, strlen(line));
  8029. + free(line);
  8030. +
  8031. + line = pkg_formatted_field(pkg, "Version");
  8032. + strncat(buff ,line, strlen(line));
  8033. + free(line);
  8034. +
  8035. + line = pkg_formatted_field(pkg, "Depends");
  8036. + strncat(buff ,line, strlen(line));
  8037. + free(line);
  8038. +
  8039. + line = pkg_formatted_field(pkg, "Recommends");
  8040. + strncat(buff ,line, strlen(line));
  8041. + free(line);
  8042. +
  8043. + line = pkg_formatted_field(pkg, "Suggests");
  8044. + strncat(buff ,line, strlen(line));
  8045. + free(line);
  8046. +
  8047. + line = pkg_formatted_field(pkg, "Provides");
  8048. + strncat(buff ,line, strlen(line));
  8049. + free(line);
  8050. +
  8051. + line = pkg_formatted_field(pkg, "Replaces");
  8052. + strncat(buff ,line, strlen(line));
  8053. + free(line);
  8054. +
  8055. + line = pkg_formatted_field(pkg, "Conflicts");
  8056. + strncat(buff ,line, strlen(line));
  8057. + free(line);
  8058. +
  8059. + line = pkg_formatted_field(pkg, "Status");
  8060. + strncat(buff ,line, strlen(line));
  8061. + free(line);
  8062. +
  8063. + line = pkg_formatted_field(pkg, "Section");
  8064. + strncat(buff ,line, strlen(line));
  8065. + free(line);
  8066. +
  8067. + line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
  8068. + strncat(buff ,line, strlen(line));
  8069. + free(line);
  8070. +
  8071. + line = pkg_formatted_field(pkg, "Architecture");
  8072. + strncat(buff ,line, strlen(line));
  8073. + free(line);
  8074. +
  8075. + line = pkg_formatted_field(pkg, "Maintainer");
  8076. + strncat(buff ,line, strlen(line));
  8077. + free(line);
  8078. +
  8079. + line = pkg_formatted_field(pkg, "MD5sum");
  8080. + strncat(buff ,line, strlen(line));
  8081. + free(line);
  8082. +
  8083. + line = pkg_formatted_field(pkg, "Size");
  8084. + strncat(buff ,line, strlen(line));
  8085. + free(line);
  8086. +
  8087. + line = pkg_formatted_field(pkg, "Filename");
  8088. + strncat(buff ,line, strlen(line));
  8089. + free(line);
  8090. +
  8091. + line = pkg_formatted_field(pkg, "Conffiles");
  8092. + strncat(buff ,line, strlen(line));
  8093. + free(line);
  8094. +
  8095. + line = pkg_formatted_field(pkg, "Source");
  8096. + strncat(buff ,line, strlen(line));
  8097. + free(line);
  8098. +
  8099. + line = pkg_formatted_field(pkg, "Description");
  8100. + strncat(buff ,line, strlen(line));
  8101. + free(line);
  8102. +
  8103. + line = pkg_formatted_field(pkg, "Installed-Time");
  8104. + strncat(buff ,line, strlen(line));
  8105. + free(line);
  8106. +
  8107. + return buff;
  8108. +}
  8109. +
  8110. +char * pkg_formatted_field(pkg_t *pkg, const char *field )
  8111. +{
  8112. + static size_t LINE_LEN = 128;
  8113. + char * temp = (char *)malloc(1);
  8114. + int len = 0;
  8115. + int flag_provide_false = 0;
  8116. +
  8117. +/*
  8118. + Pigi: After some discussion with Florian we decided to modify the full procedure in
  8119. + dynamic memory allocation. This should avoid any other segv in this area ( except for bugs )
  8120. +*/
  8121. +
  8122. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8123. + goto UNKNOWN_FMT_FIELD;
  8124. + }
  8125. +
  8126. + temp[0]='\0';
  8127. +
  8128. + switch (field[0])
  8129. + {
  8130. + case 'a':
  8131. + case 'A':
  8132. + if (strcasecmp(field, "Architecture") == 0) {
  8133. + /* Architecture */
  8134. + if (pkg->architecture) {
  8135. + temp = (char *)realloc(temp,strlen(pkg->architecture)+17);
  8136. + if ( temp == NULL ){
  8137. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8138. + return NULL;
  8139. + }
  8140. + temp[0]='\0';
  8141. + snprintf(temp, (strlen(pkg->architecture)+17), "Architecture: %s\n", pkg->architecture);
  8142. + }
  8143. + } else {
  8144. + goto UNKNOWN_FMT_FIELD;
  8145. + }
  8146. + break;
  8147. + case 'c':
  8148. + case 'C':
  8149. + if (strcasecmp(field, "Conffiles") == 0) {
  8150. + /* Conffiles */
  8151. + conffile_list_elt_t *iter;
  8152. + char confstr_[LINE_LEN];
  8153. +
  8154. + if (pkg->conffiles.head == NULL) {
  8155. + return temp;
  8156. + }
  8157. +
  8158. + len = 14 ;
  8159. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8160. + if (iter->data->name && iter->data->value) {
  8161. + len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
  8162. + }
  8163. + }
  8164. + temp = (char *)realloc(temp,len);
  8165. + if ( temp == NULL ){
  8166. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8167. + return NULL;
  8168. + }
  8169. + temp[0]='\0';
  8170. + strncpy(temp, "Conffiles:\n", 12);
  8171. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8172. + if (iter->data->name && iter->data->value) {
  8173. + snprintf(confstr_, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
  8174. + strncat(temp, confstr_, strlen(confstr_));
  8175. + }
  8176. + }
  8177. + } else if (strcasecmp(field, "Conflicts") == 0) {
  8178. + int i;
  8179. +
  8180. + if (pkg->conflicts_count) {
  8181. + char conflictstr[LINE_LEN];
  8182. + len = 14 ;
  8183. + for(i = 0; i < pkg->conflicts_count; i++) {
  8184. + len = len + (strlen(pkg->conflicts_str[i])+5);
  8185. + }
  8186. + temp = (char *)realloc(temp,len);
  8187. + if ( temp == NULL ){
  8188. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8189. + return NULL;
  8190. + }
  8191. + temp[0]='\0';
  8192. + strncpy(temp, "Conflicts:", 11);
  8193. + for(i = 0; i < pkg->conflicts_count; i++) {
  8194. + snprintf(conflictstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->conflicts_str[i]);
  8195. + strncat(temp, conflictstr, strlen(conflictstr));
  8196. + }
  8197. + strncat(temp, "\n", strlen("\n"));
  8198. + }
  8199. + } else {
  8200. + goto UNKNOWN_FMT_FIELD;
  8201. + }
  8202. + break;
  8203. + case 'd':
  8204. + case 'D':
  8205. + if (strcasecmp(field, "Depends") == 0) {
  8206. + /* Depends */
  8207. + int i;
  8208. +
  8209. + if (pkg->depends_count) {
  8210. + char depstr[LINE_LEN];
  8211. + len = 14 ;
  8212. + for(i = 0; i < pkg->depends_count; i++) {
  8213. + len = len + (strlen(pkg->depends_str[i])+4);
  8214. + }
  8215. + temp = (char *)realloc(temp,len);
  8216. + if ( temp == NULL ){
  8217. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8218. + return NULL;
  8219. + }
  8220. + temp[0]='\0';
  8221. + strncpy(temp, "Depends:", 10);
  8222. + for(i = 0; i < pkg->depends_count; i++) {
  8223. + snprintf(depstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->depends_str[i]);
  8224. + strncat(temp, depstr, strlen(depstr));
  8225. + }
  8226. + strncat(temp, "\n", strlen("\n"));
  8227. + }
  8228. + } else if (strcasecmp(field, "Description") == 0) {
  8229. + /* Description */
  8230. + if (pkg->description) {
  8231. + temp = (char *)realloc(temp,strlen(pkg->description)+16);
  8232. + if ( temp == NULL ){
  8233. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8234. + return NULL;
  8235. + }
  8236. + temp[0]='\0';
  8237. + snprintf(temp, (strlen(pkg->description)+16), "Description: %s\n", pkg->description);
  8238. + }
  8239. + } else {
  8240. + goto UNKNOWN_FMT_FIELD;
  8241. + }
  8242. + break;
  8243. + case 'e':
  8244. + case 'E': {
  8245. + /* Essential */
  8246. + if (pkg->essential) {
  8247. + temp = (char *)realloc(temp,16);
  8248. + if ( temp == NULL ){
  8249. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8250. + return NULL;
  8251. + }
  8252. + temp[0]='\0';
  8253. + snprintf(temp, (16), "Essential: yes\n");
  8254. + }
  8255. + }
  8256. + break;
  8257. + case 'f':
  8258. + case 'F': {
  8259. + /* Filename */
  8260. + if (pkg->filename) {
  8261. + temp = (char *)realloc(temp,strlen(pkg->filename)+12);
  8262. + if ( temp == NULL ){
  8263. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8264. + return NULL;
  8265. + }
  8266. + temp[0]='\0';
  8267. + snprintf(temp, (strlen(pkg->filename)+12), "Filename: %s\n", pkg->filename);
  8268. + }
  8269. + }
  8270. + break;
  8271. + case 'i':
  8272. + case 'I': {
  8273. + if (strcasecmp(field, "Installed-Size") == 0) {
  8274. + /* Installed-Size */
  8275. + temp = (char *)realloc(temp,strlen(pkg->installed_size)+17);
  8276. + if ( temp == NULL ){
  8277. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8278. + return NULL;
  8279. + }
  8280. + temp[0]='\0';
  8281. + snprintf(temp, (strlen(pkg->installed_size)+17), "Installed-Size: %s\n", pkg->installed_size);
  8282. + } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) {
  8283. + temp = (char *)realloc(temp,29);
  8284. + if ( temp == NULL ){
  8285. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8286. + return NULL;
  8287. + }
  8288. + temp[0]='\0';
  8289. + snprintf(temp, 29, "Installed-Time: %lu\n", pkg->installed_time);
  8290. + }
  8291. + }
  8292. + break;
  8293. + case 'm':
  8294. + case 'M': {
  8295. + /* Maintainer | MD5sum */
  8296. + if (strcasecmp(field, "Maintainer") == 0) {
  8297. + /* Maintainer */
  8298. + if (pkg->maintainer) {
  8299. + temp = (char *)realloc(temp,strlen(pkg->maintainer)+14);
  8300. + if ( temp == NULL ){
  8301. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8302. + return NULL;
  8303. + }
  8304. + temp[0]='\0';
  8305. + snprintf(temp, (strlen(pkg->maintainer)+14), "maintainer: %s\n", pkg->maintainer);
  8306. + }
  8307. + } else if (strcasecmp(field, "MD5sum") == 0) {
  8308. + /* MD5sum */
  8309. + if (pkg->md5sum) {
  8310. + temp = (char *)realloc(temp,strlen(pkg->md5sum)+11);
  8311. + if ( temp == NULL ){
  8312. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8313. + return NULL;
  8314. + }
  8315. + temp[0]='\0';
  8316. + snprintf(temp, (strlen(pkg->md5sum)+11), "MD5Sum: %s\n", pkg->md5sum);
  8317. + }
  8318. + } else {
  8319. + goto UNKNOWN_FMT_FIELD;
  8320. + }
  8321. + }
  8322. + break;
  8323. + case 'p':
  8324. + case 'P': {
  8325. + if (strcasecmp(field, "Package") == 0) {
  8326. + /* Package */
  8327. + temp = (char *)realloc(temp,strlen(pkg->name)+11);
  8328. + if ( temp == NULL ){
  8329. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8330. + return NULL;
  8331. + }
  8332. + temp[0]='\0';
  8333. + snprintf(temp, (strlen(pkg->name)+11), "Package: %s\n", pkg->name);
  8334. + } else if (strcasecmp(field, "Priority") == 0) {
  8335. + /* Priority */
  8336. + temp = (char *)realloc(temp,strlen(pkg->priority)+12);
  8337. + if ( temp == NULL ){
  8338. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8339. + return NULL;
  8340. + }
  8341. + temp[0]='\0';
  8342. + snprintf(temp, (strlen(pkg->priority)+12), "Priority: %s\n", pkg->priority);
  8343. + } else if (strcasecmp(field, "Provides") == 0) {
  8344. + /* Provides */
  8345. + int i;
  8346. +
  8347. + if (pkg->provides_count) {
  8348. + /* Here we check if the ipkg_internal_use_only is used, and we discard it.*/
  8349. + for ( i=0; i < pkg->provides_count; i++ ){
  8350. + if (strstr(pkg->provides_str[i],"ipkg_internal_use_only")!=NULL) {
  8351. + memset (pkg->provides_str[i],'\x0',strlen(pkg->provides_str[i])); /* Pigi clear my trick flag, just in case */
  8352. + flag_provide_false = 1;
  8353. + }
  8354. + }
  8355. + if ( !flag_provide_false || /* Pigi there is not my trick flag */
  8356. + ((flag_provide_false) && (pkg->provides_count > 1))){ /* Pigi There is, but we also have others Provides */
  8357. + char provstr[LINE_LEN];
  8358. + len = 15;
  8359. + for(i = 0; i < pkg->provides_count; i++) {
  8360. + len = len + (strlen(pkg->provides_str[i])+5);
  8361. + }
  8362. + temp = (char *)realloc(temp,len);
  8363. + if ( temp == NULL ){
  8364. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8365. + return NULL;
  8366. + }
  8367. + temp[0]='\0';
  8368. + strncpy(temp, "Provides:", 12);
  8369. + for(i = 0; i < pkg->provides_count; i++) {
  8370. + if (strlen(pkg->provides_str[i])>0){;
  8371. + snprintf(provstr, LINE_LEN, "%s %s", i == 1 ? "" : ",", pkg->provides_str[i]);
  8372. + strncat(temp, provstr, strlen(provstr));
  8373. + }
  8374. + }
  8375. + strncat(temp, "\n", strlen("\n"));
  8376. + }
  8377. + }
  8378. + } else {
  8379. + goto UNKNOWN_FMT_FIELD;
  8380. + }
  8381. + }
  8382. + break;
  8383. + case 'r':
  8384. + case 'R': {
  8385. + int i;
  8386. + /* Replaces | Recommends*/
  8387. + if (strcasecmp (field, "Replaces") == 0) {
  8388. + if (pkg->replaces_count) {
  8389. + char replstr[LINE_LEN];
  8390. + len = 14;
  8391. + for (i = 0; i < pkg->replaces_count; i++) {
  8392. + len = len + (strlen(pkg->replaces_str[i])+5);
  8393. + }
  8394. + temp = (char *)realloc(temp,len);
  8395. + if ( temp == NULL ){
  8396. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8397. + return NULL;
  8398. + }
  8399. + temp[0]='\0';
  8400. + strncpy(temp, "Replaces:", 12);
  8401. + for (i = 0; i < pkg->replaces_count; i++) {
  8402. + snprintf(replstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->replaces_str[i]);
  8403. + strncat(temp, replstr, strlen(replstr));
  8404. + }
  8405. + strncat(temp, "\n", strlen("\n"));
  8406. + }
  8407. + } else if (strcasecmp (field, "Recommends") == 0) {
  8408. + if (pkg->recommends_count) {
  8409. + char recstr[LINE_LEN];
  8410. + len = 15;
  8411. + for(i = 0; i < pkg->recommends_count; i++) {
  8412. + len = len + (strlen( pkg->recommends_str[i])+5);
  8413. + }
  8414. + temp = (char *)realloc(temp,len);
  8415. + if ( temp == NULL ){
  8416. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8417. + return NULL;
  8418. + }
  8419. + temp[0]='\0';
  8420. + strncpy(temp, "Recommends:", 13);
  8421. + for(i = 0; i < pkg->recommends_count; i++) {
  8422. + snprintf(recstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->recommends_str[i]);
  8423. + strncat(temp, recstr, strlen(recstr));
  8424. + }
  8425. + strncat(temp, "\n", strlen("\n"));
  8426. + }
  8427. + } else {
  8428. + goto UNKNOWN_FMT_FIELD;
  8429. + }
  8430. + }
  8431. + break;
  8432. + case 's':
  8433. + case 'S': {
  8434. + /* Section | Size | Source | Status | Suggests */
  8435. + if (strcasecmp(field, "Section") == 0) {
  8436. + /* Section */
  8437. + if (pkg->section) {
  8438. + temp = (char *)realloc(temp,strlen(pkg->section)+11);
  8439. + if ( temp == NULL ){
  8440. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8441. + return NULL;
  8442. + }
  8443. + temp[0]='\0';
  8444. + snprintf(temp, (strlen(pkg->section)+11), "Section: %s\n", pkg->section);
  8445. + }
  8446. + } else if (strcasecmp(field, "Size") == 0) {
  8447. + /* Size */
  8448. + if (pkg->size) {
  8449. + temp = (char *)realloc(temp,strlen(pkg->size)+8);
  8450. + if ( temp == NULL ){
  8451. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8452. + return NULL;
  8453. + }
  8454. + temp[0]='\0';
  8455. + snprintf(temp, (strlen(pkg->size)+8), "Size: %s\n", pkg->size);
  8456. + }
  8457. + } else if (strcasecmp(field, "Source") == 0) {
  8458. + /* Source */
  8459. + if (pkg->source) {
  8460. + temp = (char *)realloc(temp,strlen(pkg->source)+10);
  8461. + if ( temp == NULL ){
  8462. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8463. + return NULL;
  8464. + }
  8465. + temp[0]='\0';
  8466. + snprintf(temp, (strlen(pkg->source)+10), "Source: %s\n", pkg->source);
  8467. + }
  8468. + } else if (strcasecmp(field, "Status") == 0) {
  8469. + /* Status */
  8470. + /* Benjamin Pineau note: we should avoid direct usage of
  8471. + * strlen(arg) without keeping "arg" for later free()
  8472. + */
  8473. + char *pflag=pkg_state_flag_to_str(pkg->state_flag);
  8474. + char *pstat=pkg_state_status_to_str(pkg->state_status);
  8475. + char *pwant=pkg_state_want_to_str(pkg->state_want);
  8476. +
  8477. + size_t sum_of_sizes = (size_t) ( strlen(pwant)+ strlen(pflag)+ strlen(pstat) + 12 );
  8478. + temp = (char *)realloc(temp,sum_of_sizes);
  8479. + if ( temp == NULL ){
  8480. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8481. + return NULL;
  8482. + }
  8483. + temp[0]='\0';
  8484. + snprintf(temp, sum_of_sizes , "Status: %s %s %s\n", pwant, pflag, pstat);
  8485. + free(pflag);
  8486. + free(pwant);
  8487. + if(pstat) /* pfstat can be NULL if ENOMEM */
  8488. + free(pstat);
  8489. + } else if (strcasecmp(field, "Suggests") == 0) {
  8490. + if (pkg->suggests_count) {
  8491. + int i;
  8492. + char sugstr[LINE_LEN];
  8493. + len = 13;
  8494. + for(i = 0; i < pkg->suggests_count; i++) {
  8495. + len = len + (strlen(pkg->suggests_str[i])+5);
  8496. + }
  8497. + temp = (char *)realloc(temp,len);
  8498. + if ( temp == NULL ){
  8499. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8500. + return NULL;
  8501. + }
  8502. + temp[0]='\0';
  8503. + strncpy(temp, "Suggests:", 10);
  8504. + for(i = 0; i < pkg->suggests_count; i++) {
  8505. + snprintf(sugstr, LINE_LEN, "%s %s", i == 0 ? "" : ",", pkg->suggests_str[i]);
  8506. + strncat(temp, sugstr, strlen(sugstr));
  8507. + }
  8508. + strncat(temp, "\n", strlen("\n"));
  8509. + }
  8510. + } else {
  8511. + goto UNKNOWN_FMT_FIELD;
  8512. + }
  8513. + }
  8514. + break;
  8515. + case 'v':
  8516. + case 'V': {
  8517. + /* Version */
  8518. + char *version = pkg_version_str_alloc(pkg);
  8519. + temp = (char *)realloc(temp,strlen(version)+14);
  8520. + if ( temp == NULL ){
  8521. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8522. + return NULL;
  8523. + }
  8524. + temp[0]='\0';
  8525. + snprintf(temp, (strlen(version)+12), "Version: %s\n", version);
  8526. + free(version);
  8527. + }
  8528. + break;
  8529. + default:
  8530. + goto UNKNOWN_FMT_FIELD;
  8531. + }
  8532. +
  8533. + if ( strlen(temp)<2 ) {
  8534. + temp[0]='\0';
  8535. + }
  8536. + return temp;
  8537. +
  8538. + UNKNOWN_FMT_FIELD:
  8539. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field);
  8540. + if ( strlen(temp)<2 ) {
  8541. + temp[0]='\0';
  8542. + }
  8543. +
  8544. + return temp;
  8545. +}
  8546. +
  8547. +void pkg_print_info(pkg_t *pkg, FILE *file)
  8548. +{
  8549. + char * buff;
  8550. + if (pkg == NULL) {
  8551. + return;
  8552. + }
  8553. +
  8554. + buff = pkg_formatted_info(pkg);
  8555. + if ( buff == NULL )
  8556. + return;
  8557. + if (strlen(buff)>2){
  8558. + fwrite(buff, 1, strlen(buff), file);
  8559. + }
  8560. + free(buff);
  8561. +}
  8562. +
  8563. +void pkg_print_status(pkg_t * pkg, FILE * file)
  8564. +{
  8565. + if (pkg == NULL) {
  8566. + return;
  8567. + }
  8568. +
  8569. + /* XXX: QUESTION: Do we actually want more fields here? The
  8570. + original idea was to save space by installing only what was
  8571. + needed for actual computation, (package, version, status,
  8572. + essential, conffiles). The assumption is that all other fields
  8573. + can be found in th available file.
  8574. +
  8575. + But, someone proposed the idea to make it possible to
  8576. + reconstruct a .ipk from an installed package, (ie. for beaming
  8577. + from one handheld to another). So, maybe we actually want a few
  8578. + more fields here, (depends, suggests, etc.), so that that would
  8579. + be guaranteed to work even in the absence of more information
  8580. + from the available file.
  8581. +
  8582. + 28-MAR-03: kergoth and I discussed this yesterday. We think
  8583. + the essential info needs to be here for all installed packages
  8584. + because they may not appear in the Packages files on various
  8585. + feeds. Furthermore, one should be able to install from URL or
  8586. + local storage without requiring a Packages file from any feed.
  8587. + -Jamey
  8588. + */
  8589. + pkg_print_field(pkg, file, "Package");
  8590. + pkg_print_field(pkg, file, "Version");
  8591. + pkg_print_field(pkg, file, "Depends");
  8592. + pkg_print_field(pkg, file, "Recommends");
  8593. + pkg_print_field(pkg, file, "Suggests");
  8594. + pkg_print_field(pkg, file, "Provides");
  8595. + pkg_print_field(pkg, file, "Replaces");
  8596. + pkg_print_field(pkg, file, "Conflicts");
  8597. + pkg_print_field(pkg, file, "Status");
  8598. + pkg_print_field(pkg, file, "Essential"); /* @@@@ should be removed in future release. */
  8599. + pkg_print_field(pkg, file, "Architecture");
  8600. + pkg_print_field(pkg, file, "Conffiles");
  8601. + pkg_print_field(pkg, file, "Installed-Time");
  8602. + fputs("\n", file);
  8603. +}
  8604. +
  8605. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field)
  8606. +{
  8607. + char *buff;
  8608. + if (strlen(field) < PKG_MINIMUM_FIELD_NAME_LEN) {
  8609. + fprintf(stderr, "%s: ERROR: Unknown field name: %s\n",
  8610. + __FUNCTION__, field);
  8611. + }
  8612. + buff = pkg_formatted_field(pkg, field);
  8613. + if (strlen(buff)>2) {
  8614. + fprintf(file, "%s", buff);
  8615. + fflush(file);
  8616. + }
  8617. + free(buff);
  8618. + return;
  8619. +}
  8620. +
  8621. +/*
  8622. + * libdpkg - Debian packaging suite library routines
  8623. + * vercmp.c - comparison of version numbers
  8624. + *
  8625. + * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  8626. + */
  8627. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg)
  8628. +{
  8629. + int r;
  8630. +
  8631. + if (pkg->epoch > ref_pkg->epoch) {
  8632. + return 1;
  8633. + }
  8634. +
  8635. + if (pkg->epoch < ref_pkg->epoch) {
  8636. + return -1;
  8637. + }
  8638. +
  8639. + r = verrevcmp(pkg->version, ref_pkg->version);
  8640. + if (r) {
  8641. + return r;
  8642. + }
  8643. +
  8644. +#ifdef USE_DEBVERSION
  8645. + r = verrevcmp(pkg->revision, ref_pkg->revision);
  8646. + if (r) {
  8647. + return r;
  8648. + }
  8649. +
  8650. + r = verrevcmp(pkg->familiar_revision, ref_pkg->familiar_revision);
  8651. +#endif
  8652. +
  8653. + return r;
  8654. +}
  8655. +
  8656. +int verrevcmp(const char *val, const char *ref)
  8657. +{
  8658. + int vc, rc;
  8659. + long vl, rl;
  8660. + const char *vp, *rp;
  8661. + const char *vsep, *rsep;
  8662. +
  8663. + if (!val) val= "";
  8664. + if (!ref) ref= "";
  8665. + for (;;) {
  8666. + vp= val; while (*vp && !isdigit(*vp)) vp++;
  8667. + rp= ref; while (*rp && !isdigit(*rp)) rp++;
  8668. + for (;;) {
  8669. + vc= (val == vp) ? 0 : *val++;
  8670. + rc= (ref == rp) ? 0 : *ref++;
  8671. + if (!rc && !vc) break;
  8672. + if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
  8673. + if (rc && !isalpha(rc)) rc += 256;
  8674. + if (vc != rc) return vc - rc;
  8675. + }
  8676. + val= vp;
  8677. + ref= rp;
  8678. + vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10);
  8679. + rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10);
  8680. + if (vl != rl) return vl - rl;
  8681. +
  8682. + vc = *val;
  8683. + rc = *ref;
  8684. + vsep = strchr(".-", vc);
  8685. + rsep = strchr(".-", rc);
  8686. + if (vsep && !rsep) return -1;
  8687. + if (!vsep && rsep) return +1;
  8688. +
  8689. + if (!*val && !*ref) return 0;
  8690. + if (!*val) return -1;
  8691. + if (!*ref) return +1;
  8692. + }
  8693. +}
  8694. +
  8695. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op)
  8696. +{
  8697. + int r;
  8698. +
  8699. + r = pkg_compare_versions(it, ref);
  8700. +
  8701. + if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) {
  8702. + return r <= 0;
  8703. + }
  8704. +
  8705. + if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) {
  8706. + return r >= 0;
  8707. + }
  8708. +
  8709. + if (strcmp(op, "<<") == 0) {
  8710. + return r < 0;
  8711. + }
  8712. +
  8713. + if (strcmp(op, ">>") == 0) {
  8714. + return r > 0;
  8715. + }
  8716. +
  8717. + if (strcmp(op, "=") == 0) {
  8718. + return r == 0;
  8719. + }
  8720. +
  8721. + fprintf(stderr, "unknown operator: %s", op);
  8722. + return 0;
  8723. +}
  8724. +
  8725. +int pkg_name_version_and_architecture_compare(pkg_t *p1, pkg_t *p2)
  8726. +{
  8727. + const pkg_t *a = *(const pkg_t **)p1;
  8728. + const pkg_t *b = *(const pkg_t **)p2;
  8729. + int namecmp;
  8730. + int vercmp;
  8731. + if (!a->name || !b->name) {
  8732. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8733. + a, a->name, b, b->name);
  8734. + return 0;
  8735. + }
  8736. +
  8737. + namecmp = strcmp(a->name, b->name);
  8738. + if (namecmp)
  8739. + return namecmp;
  8740. + vercmp = pkg_compare_versions(a, b);
  8741. + if (vercmp)
  8742. + return vercmp;
  8743. + if (!a->arch_priority || !b->arch_priority) {
  8744. + fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n",
  8745. + a, a->arch_priority, b, b->arch_priority);
  8746. + return 0;
  8747. + }
  8748. + if (a->arch_priority > b->arch_priority)
  8749. + return 1;
  8750. + if (a->arch_priority < b->arch_priority)
  8751. + return -1;
  8752. + return 0;
  8753. +}
  8754. +
  8755. +int abstract_pkg_name_compare(abstract_pkg_t *p1, abstract_pkg_t *p2)
  8756. +{
  8757. + const abstract_pkg_t *a = *(const abstract_pkg_t **)p1;
  8758. + const abstract_pkg_t *b = *(const abstract_pkg_t **)p2;
  8759. + if (!a->name || !b->name) {
  8760. + fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n",
  8761. + a, a->name, b, b->name);
  8762. + return 0;
  8763. + }
  8764. + return strcmp(a->name, b->name);
  8765. +}
  8766. +
  8767. +
  8768. +char *pkg_version_str_alloc(pkg_t *pkg)
  8769. +{
  8770. + char *complete_version;
  8771. + char *epoch_str;
  8772. +#ifdef USE_DEBVERSION
  8773. + char *revision_str;
  8774. + char *familiar_revision_str;
  8775. +#endif
  8776. +
  8777. + if (pkg->epoch) {
  8778. + sprintf_alloc(&epoch_str, "%lu:", (unsigned long)pkg->epoch);
  8779. + } else {
  8780. + epoch_str = strdup("");
  8781. + }
  8782. +
  8783. +#ifdef USE_DEBVERSION
  8784. + if (pkg->revision && strlen(pkg->revision)) {
  8785. + sprintf_alloc(&revision_str, "-%s", pkg->revision);
  8786. + } else {
  8787. + revision_str = strdup("");
  8788. + }
  8789. +
  8790. + if (pkg->familiar_revision && strlen(pkg->familiar_revision)) {
  8791. + sprintf_alloc(&familiar_revision_str, "-fam%s", pkg->familiar_revision);
  8792. + } else {
  8793. + familiar_revision_str = strdup("");
  8794. + }
  8795. +#endif
  8796. +
  8797. +#ifdef USE_DEBVERSION
  8798. + sprintf_alloc(&complete_version, "%s%s%s%s",
  8799. + epoch_str, pkg->version, revision_str, familiar_revision_str);
  8800. +#else
  8801. + sprintf_alloc(&complete_version, "%s%s",
  8802. + epoch_str, pkg->version);
  8803. +#endif
  8804. +
  8805. + free(epoch_str);
  8806. +#ifdef USE_DEBVERSION
  8807. + free(revision_str);
  8808. + free(familiar_revision_str);
  8809. +#endif
  8810. +
  8811. + return complete_version;
  8812. +}
  8813. +
  8814. +str_list_t *pkg_get_installed_files(pkg_t *pkg)
  8815. +{
  8816. + int err;
  8817. + char *list_file_name = NULL;
  8818. + FILE *list_file = NULL;
  8819. + char *line;
  8820. + char *installed_file_name;
  8821. + int rootdirlen;
  8822. +
  8823. + pkg->installed_files_ref_cnt++;
  8824. +
  8825. + if (pkg->installed_files) {
  8826. + return pkg->installed_files;
  8827. + }
  8828. +
  8829. + pkg->installed_files = str_list_alloc();
  8830. + if (pkg->installed_files == NULL) {
  8831. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  8832. + return NULL;
  8833. + }
  8834. +
  8835. + /* For uninstalled packages, get the file list firectly from the package.
  8836. + For installed packages, look at the package.list file in the database.
  8837. + */
  8838. + if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
  8839. + if (pkg->local_filename == NULL) {
  8840. + return pkg->installed_files;
  8841. + }
  8842. + /* XXX: CLEANUP: Maybe rewrite this to avoid using a temporary
  8843. + file. In other words, change deb_extract so that it can
  8844. + simply return the file list as a char *[] rather than
  8845. + insisting on writing in to a FILE * as it does now. */
  8846. + list_file = tmpfile();
  8847. + err = pkg_extract_data_file_names_to_stream(pkg, list_file);
  8848. + if (err) {
  8849. + fclose(list_file);
  8850. + fprintf(stderr, "%s: Error extracting file list from %s: %s\n",
  8851. + __FUNCTION__, pkg->local_filename, strerror(err));
  8852. + return pkg->installed_files;
  8853. + }
  8854. + rewind(list_file);
  8855. + } else {
  8856. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8857. + pkg->dest->info_dir, pkg->name);
  8858. + if (! file_exists(list_file_name)) {
  8859. + free(list_file_name);
  8860. + return pkg->installed_files;
  8861. + }
  8862. +
  8863. + list_file = fopen(list_file_name, "r");
  8864. + if (list_file == NULL) {
  8865. + fprintf(stderr, "WARNING: Cannot open %s: %s\n",
  8866. + list_file_name, strerror(errno));
  8867. + free(list_file_name);
  8868. + return pkg->installed_files;
  8869. + }
  8870. + free(list_file_name);
  8871. + }
  8872. +
  8873. + rootdirlen = strlen( pkg->dest->root_dir );
  8874. + while (1) {
  8875. + char *file_name;
  8876. +
  8877. + line = file_read_line_alloc(list_file);
  8878. + if (line == NULL) {
  8879. + break;
  8880. + }
  8881. + str_chomp(line);
  8882. + file_name = line;
  8883. +
  8884. + /* Take pains to avoid uglies like "/./" in the middle of file_name. */
  8885. + if( strncmp( pkg->dest->root_dir,
  8886. + file_name,
  8887. + rootdirlen ) ) {
  8888. + if (*file_name == '.') {
  8889. + file_name++;
  8890. + }
  8891. + if (*file_name == '/') {
  8892. + file_name++;
  8893. + }
  8894. +
  8895. + /* Freed in pkg_free_installed_files */
  8896. + sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
  8897. + } else {
  8898. + // already contains root_dir as header -> ABSOLUTE
  8899. + sprintf_alloc(&installed_file_name, "%s", file_name);
  8900. + }
  8901. + str_list_append(pkg->installed_files, installed_file_name);
  8902. + free(line);
  8903. + }
  8904. +
  8905. + fclose(list_file);
  8906. +
  8907. + return pkg->installed_files;
  8908. +}
  8909. +
  8910. +/* XXX: CLEANUP: This function and it's counterpart,
  8911. + (pkg_get_installed_files), do not match our init/deinit naming
  8912. + convention. Nor the alloc/free convention. But, then again, neither
  8913. + of these conventions currrently fit the way these two functions
  8914. + work. */
  8915. +int pkg_free_installed_files(pkg_t *pkg)
  8916. +{
  8917. + str_list_elt_t *iter;
  8918. +
  8919. + pkg->installed_files_ref_cnt--;
  8920. + if (pkg->installed_files_ref_cnt > 0) {
  8921. + return 0;
  8922. + }
  8923. +
  8924. + if (pkg->installed_files) {
  8925. +
  8926. + for (iter = pkg->installed_files->head; iter; iter = iter->next) {
  8927. + /* malloced in pkg_get_installed_files */
  8928. + free (iter->data);
  8929. + iter->data = NULL;
  8930. + }
  8931. +
  8932. + str_list_deinit(pkg->installed_files);
  8933. + }
  8934. +
  8935. + pkg->installed_files = NULL;
  8936. +
  8937. + return 0;
  8938. +}
  8939. +
  8940. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg)
  8941. +{
  8942. + int err;
  8943. + char *list_file_name;
  8944. +
  8945. + //I don't think pkg_free_installed_files should be called here. Jamey
  8946. + //pkg_free_installed_files(pkg);
  8947. +
  8948. + sprintf_alloc(&list_file_name, "%s/%s.list",
  8949. + pkg->dest->info_dir, pkg->name);
  8950. + if (!conf->noaction) {
  8951. + err = unlink(list_file_name);
  8952. + free(list_file_name);
  8953. +
  8954. + if (err) {
  8955. + return errno;
  8956. + }
  8957. + }
  8958. + return 0;
  8959. +}
  8960. +
  8961. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
  8962. +{
  8963. + conffile_list_elt_t *iter;
  8964. + conffile_t *conffile;
  8965. +
  8966. + if (pkg == NULL) {
  8967. + return NULL;
  8968. + }
  8969. +
  8970. + for (iter = pkg->conffiles.head; iter; iter = iter->next) {
  8971. + conffile = iter->data;
  8972. +
  8973. + if (strcmp(conffile->name, file_name) == 0) {
  8974. + return conffile;
  8975. + }
  8976. + }
  8977. +
  8978. + return NULL;
  8979. +}
  8980. +
  8981. +int pkg_run_script(ipkg_conf_t *conf, pkg_t *pkg,
  8982. + const char *script, const char *args)
  8983. +{
  8984. + int err;
  8985. + char *path;
  8986. + char *cmd;
  8987. +
  8988. + /* XXX: FEATURE: When conf->offline_root is set, we should run the
  8989. + maintainer script within a chroot environment. */
  8990. +
  8991. + /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
  8992. + have scripts in pkg->tmp_unpack_dir. */
  8993. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  8994. + if (pkg->dest == NULL) {
  8995. + fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n",
  8996. + __FUNCTION__, pkg->name);
  8997. + return EINVAL;
  8998. + }
  8999. + sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script);
  9000. + } else {
  9001. + if (pkg->tmp_unpack_dir == NULL) {
  9002. + fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n",
  9003. + __FUNCTION__, pkg->name);
  9004. + return EINVAL;
  9005. + }
  9006. + sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script);
  9007. + }
  9008. +
  9009. + ipkg_message(conf, IPKG_INFO, "Running script %s\n", path);
  9010. + if (conf->noaction) return 0;
  9011. +
  9012. + /* XXX: CLEANUP: There must be a better way to handle maintainer
  9013. + scripts when running with offline_root mode and/or a dest other
  9014. + than '/'. I've been playing around with some clever chroot
  9015. + tricks and I might come up with something workable. */
  9016. + if (conf->offline_root) {
  9017. + setenv("IPKG_OFFLINE_ROOT", conf->offline_root, 1);
  9018. + }
  9019. +
  9020. + setenv("PKG_ROOT",
  9021. + pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1);
  9022. +
  9023. + if (! file_exists(path)) {
  9024. + free(path);
  9025. + return 0;
  9026. + }
  9027. +
  9028. + if (conf->offline_root) {
  9029. + fprintf(stderr, "(offline root mode: not running %s.%s)\n", pkg->name, script);
  9030. + free(path);
  9031. + return 0;
  9032. + }
  9033. +
  9034. + sprintf_alloc(&cmd, "%s %s", path, args);
  9035. + free(path);
  9036. +
  9037. + err = xsystem(cmd);
  9038. + free(cmd);
  9039. +
  9040. + if (err) {
  9041. + fprintf(stderr, "%s script returned status %d\n", script, err);
  9042. + return err;
  9043. + }
  9044. +
  9045. + return 0;
  9046. +}
  9047. +
  9048. +char *pkg_state_want_to_str(pkg_state_want_t sw)
  9049. +{
  9050. + int i;
  9051. +
  9052. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9053. + if (pkg_state_want_map[i].value == sw) {
  9054. + return strdup(pkg_state_want_map[i].str);
  9055. + }
  9056. + }
  9057. +
  9058. + fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n",
  9059. + __FUNCTION__, sw);
  9060. + return strdup("<STATE_WANT_UNKNOWN>");
  9061. +}
  9062. +
  9063. +pkg_state_want_t pkg_state_want_from_str(char *str)
  9064. +{
  9065. + int i;
  9066. +
  9067. + for (i=0; i < ARRAY_SIZE(pkg_state_want_map); i++) {
  9068. + if (strcmp(str, pkg_state_want_map[i].str) == 0) {
  9069. + return pkg_state_want_map[i].value;
  9070. + }
  9071. + }
  9072. +
  9073. + fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n",
  9074. + __FUNCTION__, str);
  9075. + return SW_UNKNOWN;
  9076. +}
  9077. +
  9078. +char *pkg_state_flag_to_str(pkg_state_flag_t sf)
  9079. +{
  9080. + int i;
  9081. + int len = 3; /* ok\000 is minimum */
  9082. + char *str = NULL;
  9083. +
  9084. + /* clear the temporary flags before converting to string */
  9085. + sf &= SF_NONVOLATILE_FLAGS;
  9086. +
  9087. + if (sf == 0) {
  9088. + return strdup("ok");
  9089. + } else {
  9090. +
  9091. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9092. + if (sf & pkg_state_flag_map[i].value) {
  9093. + len += strlen(pkg_state_flag_map[i].str) + 1;
  9094. + }
  9095. + }
  9096. + str = malloc(len);
  9097. + if ( str == NULL ) {
  9098. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9099. + return NULL;
  9100. + }
  9101. + str[0] = 0;
  9102. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9103. + if (sf & pkg_state_flag_map[i].value) {
  9104. + strcat(str, pkg_state_flag_map[i].str);
  9105. + strcat(str, ",");
  9106. + }
  9107. + }
  9108. + len = strlen(str);
  9109. + str[len-1] = 0; /* squash last comma */
  9110. + return str;
  9111. + }
  9112. +}
  9113. +
  9114. +pkg_state_flag_t pkg_state_flag_from_str(char *str)
  9115. +{
  9116. + int i;
  9117. + int sf = SF_OK;
  9118. +
  9119. + if (strcmp(str, "ok") == 0) {
  9120. + return SF_OK;
  9121. + }
  9122. + for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) {
  9123. + const char *sfname = pkg_state_flag_map[i].str;
  9124. + int sfname_len = strlen(sfname);
  9125. + if (strncmp(str, sfname, sfname_len) == 0) {
  9126. + sf |= pkg_state_flag_map[i].value;
  9127. + str += sfname_len;
  9128. + if (str[0] == ',') {
  9129. + str++;
  9130. + } else {
  9131. + break;
  9132. + }
  9133. + }
  9134. + }
  9135. +
  9136. + return sf;
  9137. +}
  9138. +
  9139. +char *pkg_state_status_to_str(pkg_state_status_t ss)
  9140. +{
  9141. + int i;
  9142. +
  9143. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9144. + if (pkg_state_status_map[i].value == ss) {
  9145. + return strdup(pkg_state_status_map[i].str);
  9146. + }
  9147. + }
  9148. +
  9149. + fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n",
  9150. + __FUNCTION__, ss);
  9151. + return strdup("<STATE_STATUS_UNKNOWN>");
  9152. +}
  9153. +
  9154. +pkg_state_status_t pkg_state_status_from_str(char *str)
  9155. +{
  9156. + int i;
  9157. +
  9158. + for (i=0; i < ARRAY_SIZE(pkg_state_status_map); i++) {
  9159. + if (strcmp(str, pkg_state_status_map[i].str) == 0) {
  9160. + return pkg_state_status_map[i].value;
  9161. + }
  9162. + }
  9163. +
  9164. + fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n",
  9165. + __FUNCTION__, str);
  9166. + return SS_NOT_INSTALLED;
  9167. +}
  9168. +
  9169. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg)
  9170. +{
  9171. + nv_pair_list_elt_t *l;
  9172. +
  9173. + if (!pkg->architecture)
  9174. + return 1;
  9175. +
  9176. + l = conf->arch_list.head;
  9177. +
  9178. + while (l) {
  9179. + nv_pair_t *nv = l->data;
  9180. + if (strcmp(nv->name, pkg->architecture) == 0) {
  9181. + ipkg_message(conf, IPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
  9182. + return 1;
  9183. + }
  9184. + l = l->next;
  9185. + }
  9186. +
  9187. + ipkg_message(conf, IPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
  9188. + return 0;
  9189. +}
  9190. +
  9191. +int pkg_get_arch_priority(ipkg_conf_t *conf, const char *archname)
  9192. +{
  9193. + nv_pair_list_elt_t *l;
  9194. +
  9195. + l = conf->arch_list.head;
  9196. +
  9197. + while (l) {
  9198. + nv_pair_t *nv = l->data;
  9199. + if (strcmp(nv->name, archname) == 0) {
  9200. + int priority = strtol(nv->value, NULL, 0);
  9201. + return priority;
  9202. + }
  9203. + l = l->next;
  9204. + }
  9205. + return 0;
  9206. +}
  9207. +
  9208. +int pkg_info_preinstall_check(ipkg_conf_t *conf)
  9209. +{
  9210. + int i;
  9211. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9212. + pkg_vec_t *available_pkgs = pkg_vec_alloc();
  9213. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9214. +
  9215. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n");
  9216. + pkg_hash_fetch_available(pkg_hash, available_pkgs);
  9217. + /* update arch_priority for each package */
  9218. + for (i = 0; i < available_pkgs->len; i++) {
  9219. + pkg_t *pkg = available_pkgs->pkgs[i];
  9220. + int arch_priority = 1;
  9221. + if (!pkg)
  9222. + continue;
  9223. + // ipkg_message(conf, IPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture);
  9224. + if (pkg->architecture)
  9225. + arch_priority = pkg_get_arch_priority(conf, pkg->architecture);
  9226. + else
  9227. + ipkg_message(conf, IPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name);
  9228. + // ipkg_message(conf, IPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority);
  9229. + pkg->arch_priority = arch_priority;
  9230. + }
  9231. +
  9232. + for (i = 0; i < available_pkgs->len; i++) {
  9233. + pkg_t *pkg = available_pkgs->pkgs[i];
  9234. + if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) {
  9235. + /* clear flags and want for any uninstallable package */
  9236. + ipkg_message(conf, IPKG_NOTICE, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n",
  9237. + pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want);
  9238. + pkg->state_want = SW_UNKNOWN;
  9239. + pkg->state_flag = 0;
  9240. + }
  9241. + }
  9242. + pkg_vec_free(available_pkgs);
  9243. +
  9244. + /* update the file owner data structure */
  9245. + ipkg_message(conf, IPKG_INFO, "pkg_info_preinstall_check: update file owner list\n");
  9246. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9247. + for (i = 0; i < installed_pkgs->len; i++) {
  9248. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9249. + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
  9250. + str_list_elt_t *iter;
  9251. + if (installed_files == NULL) {
  9252. + ipkg_message(conf, IPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
  9253. + break;
  9254. + }
  9255. + for (iter = installed_files->head; iter; iter = iter->next) {
  9256. + char *installed_file = iter->data;
  9257. + // ipkg_message(conf, IPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
  9258. + file_hash_set_file_owner(conf, installed_file, pkg);
  9259. + }
  9260. + }
  9261. + pkg_vec_free(installed_pkgs);
  9262. +
  9263. + return 0;
  9264. +}
  9265. +
  9266. +struct pkg_write_filelist_data {
  9267. + ipkg_conf_t *conf;
  9268. + pkg_t *pkg;
  9269. + FILE *stream;
  9270. +};
  9271. +
  9272. +void pkg_write_filelist_helper(const char *key, void *entry_, void *data_)
  9273. +{
  9274. + struct pkg_write_filelist_data *data = data_;
  9275. + pkg_t *entry = entry_;
  9276. + if (entry == data->pkg) {
  9277. + fprintf(data->stream, "%s\n", key);
  9278. + }
  9279. +}
  9280. +
  9281. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg)
  9282. +{
  9283. + struct pkg_write_filelist_data data;
  9284. + char *list_file_name = NULL;
  9285. + int err = 0;
  9286. +
  9287. + if (!pkg) {
  9288. + ipkg_message(conf, IPKG_ERROR, "Null pkg\n");
  9289. + return -EINVAL;
  9290. + }
  9291. + ipkg_message(conf, IPKG_INFO,
  9292. + " creating %s.list file\n", pkg->name);
  9293. + sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name);
  9294. + if (!list_file_name) {
  9295. + ipkg_message(conf, IPKG_ERROR, "Failed to alloc list_file_name\n");
  9296. + return -ENOMEM;
  9297. + }
  9298. + ipkg_message(conf, IPKG_INFO,
  9299. + " creating %s file for pkg %s\n", list_file_name, pkg->name);
  9300. + data.stream = fopen(list_file_name, "w");
  9301. + if (!data.stream) {
  9302. + ipkg_message(conf, IPKG_ERROR, "Could not open %s for writing: %s\n",
  9303. + list_file_name, strerror(errno));
  9304. + return errno;
  9305. + }
  9306. + data.pkg = pkg;
  9307. + data.conf = conf;
  9308. + hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data);
  9309. + fclose(data.stream);
  9310. + free(list_file_name);
  9311. +
  9312. + return err;
  9313. +}
  9314. +
  9315. +int pkg_write_changed_filelists(ipkg_conf_t *conf)
  9316. +{
  9317. + pkg_vec_t *installed_pkgs = pkg_vec_alloc();
  9318. + hash_table_t *pkg_hash = &conf->pkg_hash;
  9319. + int i;
  9320. + int err;
  9321. + if (conf->noaction)
  9322. + return 0;
  9323. +
  9324. + ipkg_message(conf, IPKG_INFO, "%s: saving changed filelists\n", __FUNCTION__);
  9325. + pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
  9326. + for (i = 0; i < installed_pkgs->len; i++) {
  9327. + pkg_t *pkg = installed_pkgs->pkgs[i];
  9328. + if (pkg->state_flag & SF_FILELIST_CHANGED) {
  9329. + ipkg_message(conf, IPKG_DEBUG, "Calling pkg_write_filelist for pkg=%s from %s\n", pkg->name, __FUNCTION__);
  9330. + err = pkg_write_filelist(conf, pkg);
  9331. + if (err)
  9332. + ipkg_message(conf, IPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
  9333. + }
  9334. + }
  9335. + return 0;
  9336. +}
  9337. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_depends.c busybox-1.24.1/archival/libipkg/pkg_depends.c
  9338. --- busybox-1.24.1.orig/archival/libipkg/pkg_depends.c 1970-01-01 01:00:00.000000000 +0100
  9339. +++ busybox-1.24.1/archival/libipkg/pkg_depends.c 2015-10-31 19:00:22.000000000 +0100
  9340. @@ -0,0 +1,1032 @@
  9341. +/* pkg_depends.c - the itsy package management system
  9342. +
  9343. + Steven M. Ayer
  9344. +
  9345. + Copyright (C) 2002 Compaq Computer Corporation
  9346. +
  9347. + This program is free software; you can redistribute it and/or
  9348. + modify it under the terms of the GNU General Public License as
  9349. + published by the Free Software Foundation; either version 2, or (at
  9350. + your option) any later version.
  9351. +
  9352. + This program is distributed in the hope that it will be useful, but
  9353. + WITHOUT ANY WARRANTY; without even the implied warranty of
  9354. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9355. + General Public License for more details.
  9356. +*/
  9357. +
  9358. +#include "ipkg.h"
  9359. +#include <errno.h>
  9360. +#include <ctype.h>
  9361. +
  9362. +#include "pkg.h"
  9363. +#include "ipkg_utils.h"
  9364. +#include "pkg_hash.h"
  9365. +#include "ipkg_message.h"
  9366. +#include "pkg_parse.h"
  9367. +#include "hash_table.h"
  9368. +
  9369. +static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str);
  9370. +static depend_t * depend_init(void);
  9371. +static void depend_deinit(depend_t *d);
  9372. +static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx);
  9373. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff);
  9374. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg);
  9375. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg);
  9376. +
  9377. +static int pkg_installed_and_constraint_satisfied(pkg_t *pkg, void *cdata)
  9378. +{
  9379. + depend_t *depend = (depend_t *)cdata;
  9380. + if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) && version_constraints_satisfied(depend, pkg))
  9381. + return 1;
  9382. + else
  9383. + return 0;
  9384. +}
  9385. +
  9386. +static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata)
  9387. +{
  9388. + depend_t *depend = (depend_t *)cdata;
  9389. +#if 0
  9390. + pkg_t * temp = pkg_new();
  9391. + int comparison;
  9392. + parseVersion(temp, depend->version);
  9393. + comparison = pkg_compare_versions(pkg, temp);
  9394. + free(temp);
  9395. +
  9396. + fprintf(stderr, "%s: pkg=%s pkg->version=%s constraint=%p type=%d version=%s comparison=%d satisfied=%d\n",
  9397. + __FUNCTION__, pkg->name, pkg->version,
  9398. + depend, depend->constraint, depend->version,
  9399. + comparison, version_constraints_satisfied(depend, pkg));
  9400. +#endif
  9401. + if (version_constraints_satisfied(depend, pkg))
  9402. + return 1;
  9403. + else
  9404. + return 0;
  9405. +}
  9406. +
  9407. +/* returns ndependences or negative error value */
  9408. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg,
  9409. + pkg_vec_t *unsatisfied, char *** unresolved)
  9410. +{
  9411. + pkg_t * satisfier_entry_pkg;
  9412. + register int i, j, k, l;
  9413. + int count, found;
  9414. + char ** the_lost;
  9415. + abstract_pkg_t * ab_pkg;
  9416. +
  9417. + /*
  9418. + * this is a setup to check for redundant/cyclic dependency checks,
  9419. + * which are marked at the abstract_pkg level
  9420. + */
  9421. + if (!(ab_pkg = pkg->parent)) {
  9422. + fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name);
  9423. + *unresolved = NULL;
  9424. + return 0;
  9425. + }
  9426. + if (ab_pkg->dependencies_checked) { /* avoid duplicate or cyclic checks */
  9427. + *unresolved = NULL;
  9428. + return 0;
  9429. + } else {
  9430. + ab_pkg->dependencies_checked = 1; /* mark it for subsequent visits */
  9431. + }
  9432. + /**/
  9433. +
  9434. + count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
  9435. + if (!count){
  9436. + *unresolved = NULL;
  9437. + return 0;
  9438. + }
  9439. +
  9440. + the_lost = NULL;
  9441. +
  9442. + /* foreach dependency */
  9443. + for (i = 0; i < count; i++) {
  9444. + compound_depend_t * compound_depend = &pkg->depends[i];
  9445. + depend_t ** possible_satisfiers = compound_depend->possibilities;;
  9446. + found = 0;
  9447. + satisfier_entry_pkg = NULL;
  9448. +
  9449. + if (compound_depend->type == GREEDY_DEPEND) {
  9450. + /* foreach possible satisfier */
  9451. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9452. + /* foreach provided_by, which includes the abstract_pkg itself */
  9453. + abstract_pkg_t *abpkg = possible_satisfiers[j]->pkg;
  9454. + abstract_pkg_vec_t *ab_provider_vec = abpkg->provided_by;
  9455. + int nposs = ab_provider_vec->len;
  9456. + abstract_pkg_t **ab_providers = ab_provider_vec->pkgs;
  9457. + for (l = 0; l < nposs; l++) {
  9458. + pkg_vec_t *test_vec = ab_providers[l]->pkgs;
  9459. + /* if no depends on this one, try the first package that Provides this one */
  9460. + if (!test_vec){ /* no pkg_vec hooked up to the abstract_pkg! (need another feed?) */
  9461. + continue;
  9462. + }
  9463. +
  9464. + /* cruise this possiblity's pkg_vec looking for an installed version */
  9465. + for (k = 0; k < test_vec->len; k++) {
  9466. + pkg_t *pkg_scout = test_vec->pkgs[k];
  9467. + /* not installed, and not already known about? */
  9468. + if ((pkg_scout->state_want != SW_INSTALL)
  9469. + && !pkg_scout->parent->dependencies_checked
  9470. + && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
  9471. + char ** newstuff = NULL;
  9472. + int rc;
  9473. + pkg_vec_t *tmp_vec = pkg_vec_alloc ();
  9474. + /* check for not-already-installed dependencies */
  9475. + rc = pkg_hash_fetch_unsatisfied_dependencies(conf,
  9476. + pkg_scout,
  9477. + tmp_vec,
  9478. + &newstuff);
  9479. + if (newstuff == NULL) {
  9480. + int ok = 1;
  9481. + for (i = 0; i < rc; i++) {
  9482. + pkg_t *p = tmp_vec->pkgs[i];
  9483. + if (p->state_want == SW_INSTALL)
  9484. + continue;
  9485. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name);
  9486. + ok = 0;
  9487. + break;
  9488. + }
  9489. + pkg_vec_free (tmp_vec);
  9490. + if (ok) {
  9491. + /* mark this one for installation */
  9492. + ipkg_message(conf, IPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name);
  9493. + pkg_vec_insert(unsatisfied, pkg_scout);
  9494. + }
  9495. + } else {
  9496. + ipkg_message(conf, IPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name);
  9497. + free (newstuff);
  9498. + }
  9499. + }
  9500. + }
  9501. + }
  9502. + }
  9503. +
  9504. + continue;
  9505. + }
  9506. +
  9507. + /* foreach possible satisfier, look for installed package */
  9508. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9509. + /* foreach provided_by, which includes the abstract_pkg itself */
  9510. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9511. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9512. + pkg_t *satisfying_pkg =
  9513. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9514. + pkg_installed_and_constraint_satisfied,
  9515. + dependence_to_satisfy, 1);
  9516. + /* Being that I can't test constraing in pkg_hash, I will test it here */
  9517. + if (satisfying_pkg != NULL) {
  9518. + if (!pkg_installed_and_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9519. + satisfying_pkg = NULL;
  9520. + }
  9521. + }
  9522. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg);
  9523. + if (satisfying_pkg != NULL) {
  9524. + found = 1;
  9525. + break;
  9526. + }
  9527. +
  9528. + }
  9529. + /* if nothing installed matches, then look for uninstalled satisfier */
  9530. + if (!found) {
  9531. + /* foreach possible satisfier, look for installed package */
  9532. + for (j = 0; j < compound_depend->possibility_count; j++) {
  9533. + /* foreach provided_by, which includes the abstract_pkg itself */
  9534. + depend_t *dependence_to_satisfy = possible_satisfiers[j];
  9535. + abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg;
  9536. + pkg_t *satisfying_pkg =
  9537. + pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg,
  9538. + pkg_constraint_satisfied,
  9539. + dependence_to_satisfy, 1);
  9540. + /* Being that I can't test constraing in pkg_hash, I will test it here too */
  9541. + if (satisfying_pkg != NULL) {
  9542. + if (!pkg_constraint_satisfied ( satisfying_pkg,dependence_to_satisfy)) {
  9543. + satisfying_pkg = NULL;
  9544. + }
  9545. + }
  9546. +
  9547. + /* user request overrides package recommendation */
  9548. + if (satisfying_pkg != NULL
  9549. + && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST)
  9550. + && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) {
  9551. + ipkg_message (conf, IPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n",
  9552. + pkg->name, satisfying_pkg->name);
  9553. + continue;
  9554. + }
  9555. +
  9556. + ipkg_message(conf, IPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg);
  9557. + if (satisfying_pkg != NULL) {
  9558. + satisfier_entry_pkg = satisfying_pkg;
  9559. + break;
  9560. + }
  9561. + }
  9562. + }
  9563. +
  9564. + /* we didn't find one, add something to the unsatisfied vector */
  9565. + if (!found) {
  9566. + if (!satisfier_entry_pkg) {
  9567. + /* failure to meet recommendations is not an error */
  9568. + if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST)
  9569. + the_lost = add_unresolved_dep(pkg, the_lost, i);
  9570. + else
  9571. + ipkg_message (conf, IPKG_NOTICE, "%s: unsatisfied recommendation for %s\n",
  9572. + pkg->name, compound_depend->possibilities[0]->pkg->name);
  9573. + }
  9574. + else {
  9575. + if (compound_depend->type == SUGGEST) {
  9576. + /* just mention it politely */
  9577. + ipkg_message (conf, IPKG_NOTICE, "package %s suggests installing %s\n",
  9578. + pkg->name, satisfier_entry_pkg->name);
  9579. + } else {
  9580. + char ** newstuff = NULL;
  9581. +
  9582. + if (satisfier_entry_pkg != pkg &&
  9583. + !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) {
  9584. + pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
  9585. + pkg_hash_fetch_unsatisfied_dependencies(conf,
  9586. + satisfier_entry_pkg,
  9587. + unsatisfied,
  9588. + &newstuff);
  9589. + the_lost = merge_unresolved(the_lost, newstuff);
  9590. + }
  9591. + }
  9592. + }
  9593. + }
  9594. + }
  9595. + *unresolved = the_lost;
  9596. +
  9597. + return unsatisfied->len;
  9598. +}
  9599. +
  9600. +/*checking for conflicts !in replaces
  9601. + If a packages conflicts with another but is also replacing it, I should not consider it a
  9602. + really conflicts
  9603. + returns 0 if conflicts <> replaces or 1 if conflicts == replaces
  9604. +*/
  9605. +int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg)
  9606. +{
  9607. + int i ;
  9608. + int replaces_count = pkg->replaces_count;
  9609. + abstract_pkg_t **replaces;
  9610. +
  9611. + if (pkg->replaces_count==0) // No replaces, it's surely a conflict
  9612. + return 0;
  9613. +
  9614. + replaces = pkg->replaces;
  9615. +
  9616. + for (i = 0; i < replaces_count; i++) {
  9617. + if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found
  9618. + ipkg_message(NULL, IPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name);
  9619. + return 1;
  9620. + }
  9621. + }
  9622. + return 0;
  9623. +
  9624. +}
  9625. +
  9626. +
  9627. +/* Abhaya: added support for conflicts */
  9628. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg)
  9629. +{
  9630. + pkg_vec_t * installed_conflicts, * test_vec;
  9631. + compound_depend_t * conflicts;
  9632. + depend_t ** possible_satisfiers;
  9633. + depend_t * possible_satisfier;
  9634. + register int i, j, k;
  9635. + int count;
  9636. + abstract_pkg_t * ab_pkg;
  9637. + pkg_t **pkg_scouts;
  9638. + pkg_t *pkg_scout;
  9639. +
  9640. + /*
  9641. + * this is a setup to check for redundant/cyclic dependency checks,
  9642. + * which are marked at the abstract_pkg level
  9643. + */
  9644. + if(!(ab_pkg = pkg->parent)){
  9645. + fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name);
  9646. + return (pkg_vec_t *)NULL;
  9647. + }
  9648. +
  9649. + conflicts = pkg->conflicts;
  9650. + if(!conflicts){
  9651. + return (pkg_vec_t *)NULL;
  9652. + }
  9653. + installed_conflicts = pkg_vec_alloc();
  9654. +
  9655. + count = pkg->conflicts_count;
  9656. +
  9657. +
  9658. +
  9659. + /* foreach conflict */
  9660. + for(i = 0; i < pkg->conflicts_count; i++){
  9661. +
  9662. + possible_satisfiers = conflicts->possibilities;
  9663. +
  9664. + /* foreach possible satisfier */
  9665. + for(j = 0; j < conflicts->possibility_count; j++){
  9666. + possible_satisfier = possible_satisfiers[j];
  9667. + if (!possible_satisfier)
  9668. + fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__);
  9669. + if (!possible_satisfier->pkg)
  9670. + fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__);
  9671. + test_vec = possible_satisfier->pkg->pkgs;
  9672. + if (test_vec) {
  9673. + /* pkg_vec found, it is an actual package conflict
  9674. + * cruise this possiblity's pkg_vec looking for an installed version */
  9675. + pkg_scouts = test_vec->pkgs;
  9676. + for(k = 0; k < test_vec->len; k++){
  9677. + pkg_scout = pkg_scouts[k];
  9678. + if (!pkg_scout) {
  9679. + fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__);
  9680. + continue;
  9681. + }
  9682. + if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) &&
  9683. + version_constraints_satisfied(possible_satisfier, pkg_scout) && !is_pkg_a_replaces(pkg_scout,pkg)){
  9684. + if (!is_pkg_in_pkg_vec(installed_conflicts, pkg_scout)){
  9685. + pkg_vec_insert(installed_conflicts, pkg_scout);
  9686. + }
  9687. + }
  9688. + }
  9689. + }
  9690. + }
  9691. + conflicts++;
  9692. + }
  9693. +
  9694. + if (installed_conflicts->len)
  9695. + return installed_conflicts;
  9696. + pkg_vec_free(installed_conflicts);
  9697. + return (pkg_vec_t *)NULL;
  9698. +}
  9699. +
  9700. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg)
  9701. +{
  9702. + pkg_t * temp;
  9703. + int comparison;
  9704. +
  9705. + if(depends->constraint == NONE)
  9706. + return 1;
  9707. +
  9708. + temp = pkg_new();
  9709. +
  9710. + parseVersion(temp, depends->version);
  9711. +
  9712. + comparison = pkg_compare_versions(pkg, temp);
  9713. +
  9714. + free(temp);
  9715. +
  9716. + if((depends->constraint == EARLIER) &&
  9717. + (comparison < 0))
  9718. + return 1;
  9719. + else if((depends->constraint == LATER) &&
  9720. + (comparison > 0))
  9721. + return 1;
  9722. + else if(comparison == 0)
  9723. + return 1;
  9724. + else if((depends->constraint == LATER_EQUAL) &&
  9725. + (comparison >= 0))
  9726. + return 1;
  9727. + else if((depends->constraint == EARLIER_EQUAL) &&
  9728. + (comparison <= 0))
  9729. + return 1;
  9730. +
  9731. + return 0;
  9732. +}
  9733. +
  9734. +int pkg_dependence_satisfiable(depend_t *depend)
  9735. +{
  9736. + abstract_pkg_t *apkg = depend->pkg;
  9737. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9738. + int n_providers = provider_apkgs->len;
  9739. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9740. + pkg_vec_t *pkg_vec;
  9741. + int n_pkgs ;
  9742. + int i;
  9743. + int j;
  9744. +
  9745. + for (i = 0; i < n_providers; i++) {
  9746. + abstract_pkg_t *papkg = apkgs[i];
  9747. + pkg_vec = papkg->pkgs;
  9748. + if (pkg_vec) {
  9749. + n_pkgs = pkg_vec->len;
  9750. + for (j = 0; j < n_pkgs; j++) {
  9751. + pkg_t *pkg = pkg_vec->pkgs[j];
  9752. + if (version_constraints_satisfied(depend, pkg)) {
  9753. + return 1;
  9754. + }
  9755. + }
  9756. + }
  9757. + }
  9758. + return 0;
  9759. +}
  9760. +
  9761. +int pkg_dependence_satisfied(depend_t *depend)
  9762. +{
  9763. + abstract_pkg_t *apkg = depend->pkg;
  9764. + abstract_pkg_vec_t *provider_apkgs = apkg->provided_by;
  9765. + int n_providers = provider_apkgs->len;
  9766. + abstract_pkg_t **apkgs = provider_apkgs->pkgs;
  9767. + int i;
  9768. + int n_pkgs;
  9769. + int j;
  9770. +
  9771. + for (i = 0; i < n_providers; i++) {
  9772. + abstract_pkg_t *papkg = apkgs[i];
  9773. + pkg_vec_t *pkg_vec = papkg->pkgs;
  9774. + if (pkg_vec) {
  9775. + n_pkgs = pkg_vec->len;
  9776. + for (j = 0; j < n_pkgs; j++) {
  9777. + pkg_t *pkg = pkg_vec->pkgs[j];
  9778. + if (version_constraints_satisfied(depend, pkg)) {
  9779. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED)
  9780. + return 1;
  9781. + }
  9782. + }
  9783. + }
  9784. + }
  9785. + return 0;
  9786. +}
  9787. +
  9788. +static int is_pkg_in_pkg_vec(pkg_vec_t * vec, pkg_t * pkg)
  9789. +{
  9790. + register int i;
  9791. + pkg_t ** pkgs = vec->pkgs;
  9792. +
  9793. + for(i = 0; i < vec->len; i++)
  9794. + if((strcmp(pkg->name, (*(pkgs + i))->name) == 0)
  9795. + && (pkg_compare_versions(pkg, *(pkgs + i)) == 0)
  9796. + && (strcmp(pkg->architecture, (*(pkgs + i))->architecture) == 0))
  9797. + return 1;
  9798. + return 0;
  9799. +}
  9800. +
  9801. +
  9802. +#ifdef DeadCode
  9803. +/**
  9804. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  9805. + * the same abstract package and 0 otherwise.
  9806. + */
  9807. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee)
  9808. +{
  9809. + abstract_pkg_t **provides = pkg->provides;
  9810. + int provides_count = pkg->provides_count;
  9811. + abstract_pkg_t **replacee_provides = replacee->provides;
  9812. + int replacee_provides_count = replacee->provides_count;
  9813. + int i, j;
  9814. + for (i = 0; i < provides_count; i++) {
  9815. + abstract_pkg_t *apkg = provides[i];
  9816. + for (j = 0; j < replacee_provides_count; j++) {
  9817. + abstract_pkg_t *replacee_apkg = replacee_provides[i];
  9818. + if (apkg == replacee_apkg)
  9819. + return 1;
  9820. + }
  9821. + }
  9822. + return 0;
  9823. +}
  9824. +#endif
  9825. +
  9826. +/**
  9827. + * pkg_provides_abstract returns 1 if pkg->provides contains providee
  9828. + * and 0 otherwise.
  9829. + */
  9830. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee)
  9831. +{
  9832. + abstract_pkg_t **provides = pkg->provides;
  9833. + int provides_count = pkg->provides_count;
  9834. + int i;
  9835. + for (i = 0; i < provides_count; i++) {
  9836. + if (provides[i] == providee)
  9837. + return 1;
  9838. + }
  9839. + return 0;
  9840. +}
  9841. +
  9842. +/**
  9843. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  9844. + * otherwise.
  9845. + */
  9846. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee)
  9847. +{
  9848. + abstract_pkg_t **replaces = pkg->replaces;
  9849. + int replaces_count = pkg->replaces_count;
  9850. + /* abstract_pkg_t **replacee_provides = pkg->provides;
  9851. + int replacee_provides_count = pkg->provides_count; */
  9852. + int i, j;
  9853. + for (i = 0; i < replaces_count; i++) {
  9854. + abstract_pkg_t *abstract_replacee = replaces[i];
  9855. + for (j = 0; j < replaces_count; j++) {
  9856. + /* ipkg_message(NULL, IPKG_DEBUG2, "Searching pkg-name %s repprovname %s absrepname %s \n",
  9857. + pkg->name,replacee->provides[j]->name, abstract_replacee->name); */
  9858. + if (replacee->provides[j] == abstract_replacee)
  9859. + return 1;
  9860. + }
  9861. + }
  9862. + return 0;
  9863. +}
  9864. +
  9865. +
  9866. +/**
  9867. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee and 0
  9868. + * otherwise.
  9869. + */
  9870. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflictee)
  9871. +{
  9872. + compound_depend_t *conflicts = pkg->conflicts;
  9873. + int conflicts_count = pkg->conflicts_count;
  9874. + int i, j;
  9875. + for (i = 0; i < conflicts_count; i++) {
  9876. + int possibility_count = conflicts[i].possibility_count;
  9877. + struct depend **possibilities = conflicts[i].possibilities;
  9878. + for (j = 0; j < possibility_count; j++) {
  9879. + if (possibilities[j]->pkg == conflictee) {
  9880. + return 1;
  9881. + }
  9882. + }
  9883. + }
  9884. + return 0;
  9885. +}
  9886. +
  9887. +/**
  9888. + * pkg_conflicts returns 1 if pkg->conflicts contains one of
  9889. + * conflictee's provides and 0 otherwise.
  9890. + */
  9891. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflictee)
  9892. +{
  9893. + compound_depend_t *conflicts = pkg->conflicts;
  9894. + int conflicts_count = pkg->conflicts_count;
  9895. + abstract_pkg_t **conflictee_provides = conflictee->provides;
  9896. + int conflictee_provides_count = conflictee->provides_count;
  9897. + int i, j, k;
  9898. + int possibility_count;
  9899. + struct depend **possibilities;
  9900. + abstract_pkg_t *possibility ;
  9901. +
  9902. + for (i = 0; i < conflicts_count; i++) {
  9903. + possibility_count = conflicts[i].possibility_count;
  9904. + possibilities = conflicts[i].possibilities;
  9905. + for (j = 0; j < possibility_count; j++) {
  9906. + possibility = possibilities[j]->pkg;
  9907. + for (k = 0; k < conflictee_provides_count; k++) {
  9908. + if (possibility == conflictee_provides[k]) {
  9909. + return 1;
  9910. + }
  9911. + }
  9912. + }
  9913. + }
  9914. + return 0;
  9915. +}
  9916. +
  9917. +static char ** merge_unresolved(char ** oldstuff, char ** newstuff)
  9918. +{
  9919. + int oldlen = 0, newlen = 0;
  9920. + char ** result;
  9921. + register int i, j;
  9922. +
  9923. + if(!newstuff)
  9924. + return oldstuff;
  9925. +
  9926. + while(oldstuff && oldstuff[oldlen]) oldlen++;
  9927. + while(newstuff && newstuff[newlen]) newlen++;
  9928. +
  9929. + result = (char **)realloc(oldstuff, sizeof(char *) * (oldlen + newlen + 1));
  9930. + if (result == NULL) {
  9931. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9932. + return NULL;
  9933. + }
  9934. +
  9935. + for(i = oldlen, j = 0; i < (oldlen + newlen); i++, j++)
  9936. + *(result + i) = *(newstuff + j);
  9937. +
  9938. + *(result + i) = NULL;
  9939. +
  9940. + return result;
  9941. +}
  9942. +
  9943. +/*
  9944. + * a kinda kludgy way to back out depends str from two different arrays (reg'l'r 'n pre)
  9945. + * this is null terminated, no count is carried around
  9946. + */
  9947. +char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx)
  9948. +{
  9949. + int count;
  9950. + char ** resized;
  9951. + char *depend_str = pkg_depend_str(pkg, ref_ndx);
  9952. +
  9953. + count = 0;
  9954. + while(the_lost && the_lost[count]) count++;
  9955. +
  9956. + count++; /* need one to hold the null */
  9957. + resized = (char **)realloc(the_lost, sizeof(char *) * (count + 1));
  9958. + if (resized == NULL) {
  9959. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  9960. + return NULL;
  9961. + }
  9962. + resized[count - 1] = strdup(depend_str);
  9963. + resized[count] = NULL;
  9964. +
  9965. + return resized;
  9966. +}
  9967. +
  9968. +void printDepends(pkg_t * pkg)
  9969. +{
  9970. + register int i, j;
  9971. + compound_depend_t * depend;
  9972. + int count;
  9973. +
  9974. + count = pkg->pre_depends_count + pkg->depends_count;
  9975. +
  9976. + depend = pkg->depends;
  9977. + if(!depend){
  9978. + fprintf(stderr, "Depends pointer is NULL\n");
  9979. + return;
  9980. + }
  9981. + for(i = 0; i < count; i++){
  9982. + fprintf(stderr, "%s has %d possibilities:\n",
  9983. + (depend->type == GREEDY_DEPEND) ? "Greedy-Depend" : ((depend->type == DEPEND) ? "Depend" : "Pre-Depend"),
  9984. + depend->possibility_count);
  9985. + for(j = 0; j < depend->possibility_count; j++)
  9986. + fprintf(stderr, "\t%s version %s (%d)\n",
  9987. + depend->possibilities[j]->pkg->name,
  9988. + depend->possibilities[j]->version,
  9989. + depend->possibilities[j]->constraint);
  9990. + depend++;
  9991. + }
  9992. +}
  9993. +
  9994. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  9995. +{
  9996. + register int i, j;
  9997. +
  9998. + /* every pkg provides itself */
  9999. + abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
  10000. +
  10001. + if (!pkg->provides_count)
  10002. + return 0;
  10003. +
  10004. + pkg->provides = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * (pkg->provides_count + 1));
  10005. + if (pkg->provides == NULL) {
  10006. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10007. + return -1 ;
  10008. + }
  10009. + pkg->provides[0] = ab_pkg;
  10010. +
  10011. + // if (strcmp(ab_pkg->name, pkg->name))
  10012. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10013. +
  10014. + for(i = 0; i < pkg->provides_count; i++){
  10015. + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, pkg->provides_str[i]);
  10016. +
  10017. + pkg->provides[i+1] = provided_abpkg;
  10018. +
  10019. + j = 0;
  10020. + abstract_pkg_vec_insert(provided_abpkg->provided_by, ab_pkg);
  10021. + }
  10022. + return 0;
  10023. +}
  10024. +
  10025. +/* Abhaya: added conflicts support */
  10026. +int buildConflicts(hash_table_t * hash, pkg_t * pkg)
  10027. +{
  10028. + register int i;
  10029. + compound_depend_t * conflicts;
  10030. +
  10031. + if (!pkg->conflicts_count)
  10032. + return 0;
  10033. +
  10034. + conflicts = pkg->conflicts = malloc(sizeof(compound_depend_t) *
  10035. + pkg->conflicts_count);
  10036. + if (conflicts == NULL) {
  10037. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10038. + return -1;
  10039. + }
  10040. + for (i = 0; i < pkg->conflicts_count; i++) {
  10041. + conflicts->type = CONFLICTS;
  10042. + parseDepends(conflicts, hash,
  10043. + pkg->conflicts_str[i]);
  10044. +#if 0
  10045. + for (j = 0; j < conflicts->possibility_count; j++) {
  10046. + depend_t *possibility = conflicts->possibilities[j];
  10047. + abstract_pkg_t *conflicting_apkg = possibility->pkg;
  10048. + pkg_add_conflict_pair(ab_pkg, conflicting_apkg);
  10049. + }
  10050. +#endif
  10051. + conflicts++;
  10052. + }
  10053. + return 0;
  10054. +}
  10055. +
  10056. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg)
  10057. +{
  10058. + register int i, j;
  10059. +
  10060. + if (!pkg->replaces_count)
  10061. + return 0;
  10062. +
  10063. + pkg->replaces = (abstract_pkg_t **)malloc(sizeof(abstract_pkg_t *) * pkg->replaces_count);
  10064. + if (pkg->replaces == NULL) {
  10065. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10066. + return -1;
  10067. + }
  10068. +
  10069. + // if (strcmp(ab_pkg->name, pkg->name))
  10070. + // fprintf(stderr, __FUNCTION__ ": ab_pkg=%s pkg=%s\n", ab_pkg->name, pkg->name);
  10071. +
  10072. + for(i = 0; i < pkg->replaces_count; i++){
  10073. + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]);
  10074. +
  10075. + pkg->replaces[i] = old_abpkg;
  10076. +
  10077. + j = 0;
  10078. + if (!old_abpkg->replaced_by)
  10079. + old_abpkg->replaced_by = abstract_pkg_vec_alloc();
  10080. + if ( old_abpkg->replaced_by == NULL ){
  10081. + return -1;
  10082. + }
  10083. + /* if a package pkg both replaces and conflicts old_abpkg,
  10084. + * then add it to the replaced_by vector so that old_abpkg
  10085. + * will be upgraded to ab_pkg automatically */
  10086. + if (pkg_conflicts_abstract(pkg, old_abpkg))
  10087. + abstract_pkg_vec_insert(old_abpkg->replaced_by, ab_pkg);
  10088. + }
  10089. + return 0;
  10090. +}
  10091. +
  10092. +int buildDepends(hash_table_t * hash, pkg_t * pkg)
  10093. +{
  10094. + int count;
  10095. + register int i;
  10096. + compound_depend_t * depends;
  10097. +
  10098. + if(!(count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count))
  10099. + return 0;
  10100. +
  10101. + if (0 && pkg->pre_depends_count)
  10102. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10103. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10104. + depends = pkg->depends = malloc(sizeof(compound_depend_t) * count);
  10105. + if (depends == NULL) {
  10106. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10107. + return -1;
  10108. + }
  10109. +
  10110. +
  10111. + for(i = 0; i < pkg->pre_depends_count; i++){
  10112. + parseDepends(depends, hash, pkg->pre_depends_str[i]);
  10113. + if (0 && pkg->pre_depends_count)
  10114. + fprintf(stderr, " pre_depends_str=%s depends=%p possibility_count=%x\n",
  10115. + pkg->pre_depends_str[i], depends, depends->possibility_count);
  10116. + depends->type = PREDEPEND;
  10117. + depends++;
  10118. + }
  10119. +
  10120. + for(i = 0; i < pkg->recommends_count; i++){
  10121. + parseDepends(depends, hash, pkg->recommends_str[i]);
  10122. + if (0 && pkg->recommends_count)
  10123. + fprintf(stderr, " recommends_str=%s depends=%p possibility_count=%x\n",
  10124. + pkg->recommends_str[i], depends, depends->possibility_count);
  10125. + depends->type = RECOMMEND;
  10126. + depends++;
  10127. + }
  10128. +
  10129. + for(i = 0; i < pkg->suggests_count; i++){
  10130. + parseDepends(depends, hash, pkg->suggests_str[i]);
  10131. + if (0 && pkg->suggests_count)
  10132. + fprintf(stderr, " suggests_str=%s depends=%p possibility_count=%x\n",
  10133. + pkg->suggests_str[i], depends, depends->possibility_count);
  10134. + depends->type = SUGGEST;
  10135. + depends++;
  10136. + }
  10137. +
  10138. + for(i = 0; i < pkg->depends_count; i++){
  10139. + parseDepends(depends, hash, pkg->depends_str[i]);
  10140. + if (0 && pkg->depends_count)
  10141. + fprintf(stderr, " depends_str=%s depends=%p possibility_count=%x\n",
  10142. + pkg->depends_str[i], depends, depends->possibility_count);
  10143. + depends++;
  10144. + }
  10145. + return 0;
  10146. +}
  10147. +
  10148. +/*
  10149. + * pkg_depend_string: returns the depends string specified by index_.
  10150. + * All 4 kinds of dependences: dependence, pre-dependence, recommend, and suggest are number starting from 0.
  10151. + * [0,npredepends) -> returns pre_depends_str[index_]
  10152. + * [npredepends,npredepends+nrecommends) -> returns recommends_str[index_]
  10153. + * [npredepends+nrecommends,npredepends+nrecommends+nsuggests) -> returns recommends_str[index_]
  10154. + * [npredepends+nrecommends+nsuggests,npredepends+nrecommends+nsuggests+ndepends) -> returns depends_str[index_]
  10155. + */
  10156. +char *pkg_depend_str(pkg_t *pkg, int index_)
  10157. +{
  10158. + if (index_ < pkg->pre_depends_count) {
  10159. + return pkg->pre_depends_str[index_];
  10160. + }
  10161. + index_ -= pkg->pre_depends_count;
  10162. +
  10163. + if (index_ < pkg->recommends_count) {
  10164. + return pkg->recommends_str[index_];
  10165. + }
  10166. + index_ -= pkg->recommends_count;
  10167. +
  10168. + if (index_ < pkg->suggests_count) {
  10169. + return pkg->suggests_str[index_];
  10170. + }
  10171. + index_ -= pkg->suggests_count;
  10172. +
  10173. + if (index_ < pkg->depends_count) {
  10174. + return pkg->depends_str[index_];
  10175. + }
  10176. + fprintf(stderr, "pkg_depend_str: index_ %d out of range for pkg=%s\n", index_, pkg->name);
  10177. + return NULL;
  10178. +}
  10179. +
  10180. +void freeDepends(pkg_t *pkg)
  10181. +{
  10182. + int i;
  10183. +
  10184. + if (pkg == NULL || pkg->depends == NULL) {
  10185. + return;
  10186. + }
  10187. +
  10188. + fprintf(stderr, "Freeing depends=%p\n", pkg->depends);
  10189. + for (i=0; i < pkg->depends->possibility_count; i++) {
  10190. + depend_deinit(pkg->depends->possibilities[i]);
  10191. + }
  10192. + free(pkg->depends->possibilities);
  10193. + free(pkg->depends);
  10194. + pkg->depends = NULL;
  10195. +}
  10196. +
  10197. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg)
  10198. +{
  10199. + compound_depend_t * depends;
  10200. + int count, othercount;
  10201. + register int i, j;
  10202. + abstract_pkg_t * ab_depend;
  10203. + abstract_pkg_t ** temp;
  10204. +
  10205. + count = pkg->pre_depends_count + pkg->depends_count;
  10206. + depends = pkg->depends;
  10207. +
  10208. + if (0 && pkg->pre_depends_count)
  10209. + fprintf(stderr, "pkg=%s pre_depends_count=%d depends_count=%d\n",
  10210. + pkg->name, pkg->pre_depends_count, pkg->depends_count);
  10211. + for (i = 0; i < count; i++) {
  10212. + if (0 && pkg->pre_depends_count)
  10213. + fprintf(stderr, " i=%d possibility_count=%x depends=%p\n", i, depends->possibility_count, depends);
  10214. + for (j = 0; j < depends->possibility_count; j++){
  10215. + ab_depend = depends->possibilities[j]->pkg;
  10216. + if(!ab_depend->depended_upon_by)
  10217. + ab_depend->depended_upon_by = (abstract_pkg_t **)calloc(1, sizeof(abstract_pkg_t *));
  10218. +
  10219. + temp = ab_depend->depended_upon_by;
  10220. + othercount = 1;
  10221. + while(*temp){
  10222. + temp++;
  10223. + othercount++;
  10224. + }
  10225. + *temp = ab_pkg;
  10226. +
  10227. + ab_depend->depended_upon_by = (abstract_pkg_t **)realloc(ab_depend->depended_upon_by,
  10228. + (othercount + 1) * sizeof(abstract_pkg_t *));
  10229. + /* the array may have moved */
  10230. + temp = ab_depend->depended_upon_by + othercount;
  10231. + *temp = NULL;
  10232. + }
  10233. + depends++;
  10234. + }
  10235. +}
  10236. +
  10237. +static depend_t * depend_init(void)
  10238. +{
  10239. + depend_t * d = (depend_t *)malloc(sizeof(depend_t));
  10240. + if ( d==NULL ){
  10241. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10242. + return NULL;
  10243. + }
  10244. + d->constraint = NONE;
  10245. + d->version = NULL;
  10246. + d->pkg = NULL;
  10247. +
  10248. + return d;
  10249. +}
  10250. +
  10251. +static void depend_deinit(depend_t *d)
  10252. +{
  10253. + free(d);
  10254. +}
  10255. +
  10256. +static int parseDepends(compound_depend_t *compound_depend,
  10257. + hash_table_t * hash, char * depend_str)
  10258. +{
  10259. + char * pkg_name, buffer[2048];
  10260. + int num_of_ors = 0;
  10261. + register int i;
  10262. + register char * src, * dest;
  10263. + depend_t ** possibilities;
  10264. +
  10265. + /* first count the number of ored possibilities for satisfying dependency */
  10266. + src = depend_str;
  10267. + while(*src)
  10268. + if(*src++ == '|')
  10269. + num_of_ors++;
  10270. +
  10271. + compound_depend->type = DEPEND;
  10272. +
  10273. + compound_depend->possibility_count = num_of_ors + 1;
  10274. + possibilities = (depend_t **)malloc(sizeof(depend_t *) * (num_of_ors + 1));
  10275. + if (!possibilities)
  10276. + return -ENOMEM;
  10277. + compound_depend->possibilities = possibilities;
  10278. +
  10279. + src = depend_str;
  10280. + for(i = 0; i < num_of_ors + 1; i++){
  10281. + possibilities[i] = depend_init();
  10282. + if (!possibilities[i])
  10283. + return -ENOMEM;
  10284. + /* gobble up just the name first */
  10285. + dest = buffer;
  10286. + while(*src &&
  10287. + !isspace(*src) &&
  10288. + (*src != '(') &&
  10289. + (*src != '*') &&
  10290. + (*src != '|'))
  10291. + *dest++ = *src++;
  10292. + *dest = '\0';
  10293. + pkg_name = trim_alloc(buffer);
  10294. + if (pkg_name == NULL )
  10295. + return -ENOMEM;
  10296. +
  10297. + /* now look at possible version info */
  10298. +
  10299. + /* skip to next chars */
  10300. + if(isspace(*src))
  10301. + while(*src && isspace(*src)) src++;
  10302. +
  10303. + /* extract constraint and version */
  10304. + if(*src == '('){
  10305. + src++;
  10306. + if(!strncmp(src, "<<", 2)){
  10307. + possibilities[i]->constraint = EARLIER;
  10308. + src += 2;
  10309. + }
  10310. + else if(!strncmp(src, "<=", 2)){
  10311. + possibilities[i]->constraint = EARLIER_EQUAL;
  10312. + src += 2;
  10313. + }
  10314. + else if(!strncmp(src, ">=", 2)){
  10315. + possibilities[i]->constraint = LATER_EQUAL;
  10316. + src += 2;
  10317. + }
  10318. + else if(!strncmp(src, ">>", 2)){
  10319. + possibilities[i]->constraint = LATER;
  10320. + src += 2;
  10321. + }
  10322. + else if(!strncmp(src, "=", 1)){
  10323. + possibilities[i]->constraint = EQUAL;
  10324. + src++;
  10325. + }
  10326. + /* should these be here to support deprecated designations; dpkg does */
  10327. + else if(!strncmp(src, "<", 1)){
  10328. + possibilities[i]->constraint = EARLIER_EQUAL;
  10329. + src++;
  10330. + }
  10331. + else if(!strncmp(src, ">", 1)){
  10332. + possibilities[i]->constraint = LATER_EQUAL;
  10333. + src++;
  10334. + }
  10335. +
  10336. + /* now we have any constraint, pass space to version string */
  10337. + while(isspace(*src)) src++;
  10338. +
  10339. + /* this would be the version string */
  10340. + dest = buffer;
  10341. + while(*src && *src != ')')
  10342. + *dest++ = *src++;
  10343. + *dest = '\0';
  10344. +
  10345. + possibilities[i]->version = trim_alloc(buffer);
  10346. + /* fprintf(stderr, "let's print the depends version string:");
  10347. + fprintf(stderr, "version %s\n", possibilities[i]->version);*/
  10348. + if (possibilities[i]->version == NULL )
  10349. + return -ENOMEM;
  10350. +
  10351. +
  10352. + }
  10353. + /* hook up the dependency to its abstract pkg */
  10354. + possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name);
  10355. +
  10356. + free(pkg_name);
  10357. +
  10358. + /* now get past the ) and any possible | chars */
  10359. + while(*src &&
  10360. + (isspace(*src) ||
  10361. + (*src == ')') ||
  10362. + (*src == '|')))
  10363. + src++;
  10364. + if (*src == '*')
  10365. + {
  10366. + compound_depend->type = GREEDY_DEPEND;
  10367. + src++;
  10368. + }
  10369. + }
  10370. +
  10371. + return 0;
  10372. +}
  10373. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_depends.h busybox-1.24.1/archival/libipkg/pkg_depends.h
  10374. --- busybox-1.24.1.orig/archival/libipkg/pkg_depends.h 1970-01-01 01:00:00.000000000 +0100
  10375. +++ busybox-1.24.1/archival/libipkg/pkg_depends.h 2015-10-31 19:00:22.000000000 +0100
  10376. @@ -0,0 +1,105 @@
  10377. +/* pkg_depends.h - the itsy package management system
  10378. +
  10379. + Steven M. Ayer
  10380. +
  10381. + Copyright (C) 2002 Compaq Computer Corporation
  10382. +
  10383. + This program is free software; you can redistribute it and/or
  10384. + modify it under the terms of the GNU General Public License as
  10385. + published by the Free Software Foundation; either version 2, or (at
  10386. + your option) any later version.
  10387. +
  10388. + This program is distributed in the hope that it will be useful, but
  10389. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10390. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10391. + General Public License for more details.
  10392. +*/
  10393. +
  10394. +#ifndef PKG_DEPENDS_H
  10395. +#define PKG_DEPENDS_H
  10396. +
  10397. +#include "pkg.h"
  10398. +#include "pkg_hash.h"
  10399. +
  10400. +enum depend_type {
  10401. + PREDEPEND,
  10402. + DEPEND,
  10403. + CONFLICTS,
  10404. + GREEDY_DEPEND,
  10405. + RECOMMEND,
  10406. + SUGGEST
  10407. +};
  10408. +typedef enum depend_type depend_type_t;
  10409. +
  10410. +enum version_constraint {
  10411. + NONE,
  10412. + EARLIER,
  10413. + EARLIER_EQUAL,
  10414. + EQUAL,
  10415. + LATER_EQUAL,
  10416. + LATER
  10417. +};
  10418. +typedef enum version_constraint version_constraint_t;
  10419. +
  10420. +struct depend{
  10421. + version_constraint_t constraint;
  10422. + char * version;
  10423. + abstract_pkg_t * pkg;
  10424. +};
  10425. +typedef struct depend depend_t;
  10426. +
  10427. +struct compound_depend{
  10428. + depend_type_t type;
  10429. + int possibility_count;
  10430. + struct depend ** possibilities;
  10431. +};
  10432. +typedef struct compound_depend compound_depend_t;
  10433. +
  10434. +#include "hash_table.h"
  10435. +
  10436. +int buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10437. +int buildConflicts(hash_table_t * hash, pkg_t * pkg);
  10438. +int buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg);
  10439. +int buildDepends(hash_table_t * hash, pkg_t * pkg);
  10440. +
  10441. +/**
  10442. + * pkg_has_common_provides returns 1 if pkg and replacee both provide
  10443. + * the same abstract package and 0 otherwise.
  10444. + */
  10445. +int pkg_has_common_provides(pkg_t *pkg, pkg_t *replacee);
  10446. +
  10447. +/**
  10448. + * pkg_provides returns 1 if pkg->provides contains providee and 0
  10449. + * otherwise.
  10450. + */
  10451. +int pkg_provides_abstract(pkg_t *pkg, abstract_pkg_t *providee);
  10452. +
  10453. +/**
  10454. + * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0
  10455. + * otherwise.
  10456. + */
  10457. +int pkg_replaces(pkg_t *pkg, pkg_t *replacee);
  10458. +
  10459. +/**
  10460. + * pkg_conflicts_abstract returns 1 if pkg->conflicts contains conflictee provides and 0
  10461. + * otherwise.
  10462. + */
  10463. +int pkg_conflicts_abstract(pkg_t *pkg, abstract_pkg_t *conflicts);
  10464. +
  10465. +/**
  10466. + * pkg_conflicts returns 1 if pkg->conflicts contains one of conflictee's provides and 0
  10467. + * otherwise.
  10468. + */
  10469. +int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts);
  10470. +
  10471. +char *pkg_depend_str(pkg_t *pkg, int index_);
  10472. +void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
  10473. +void freeDepends(pkg_t *pkg);
  10474. +void printDepends(pkg_t * pkg);
  10475. +int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
  10476. +int pkg_hash_fetch_unsatisfied_dependencies(ipkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved);
  10477. +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg);
  10478. +int pkg_dependence_satisfiable(depend_t *depend);
  10479. +int pkg_dependence_satisfied(depend_t *depend);
  10480. +
  10481. +#endif
  10482. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_dest.c busybox-1.24.1/archival/libipkg/pkg_dest.c
  10483. --- busybox-1.24.1.orig/archival/libipkg/pkg_dest.c 1970-01-01 01:00:00.000000000 +0100
  10484. +++ busybox-1.24.1/archival/libipkg/pkg_dest.c 2015-10-31 19:00:22.000000000 +0100
  10485. @@ -0,0 +1,92 @@
  10486. +/* pkg_dest.c - the itsy package management system
  10487. +
  10488. + Carl D. Worth
  10489. +
  10490. + Copyright (C) 2001 University of Southern California
  10491. +
  10492. + This program is free software; you can redistribute it and/or
  10493. + modify it under the terms of the GNU General Public License as
  10494. + published by the Free Software Foundation; either version 2, or (at
  10495. + your option) any later version.
  10496. +
  10497. + This program is distributed in the hope that it will be useful, but
  10498. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10499. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10500. + General Public License for more details.
  10501. +*/
  10502. +
  10503. +#include "ipkg.h"
  10504. +
  10505. +#include "pkg_dest.h"
  10506. +#include "file_util.h"
  10507. +#include "str_util.h"
  10508. +#include "sprintf_alloc.h"
  10509. +
  10510. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
  10511. +{
  10512. + dest->name = strdup(name);
  10513. +
  10514. + /* Guarantee that dest->root_dir ends with a '/' */
  10515. + if (str_ends_with(root_dir, "/")) {
  10516. + dest->root_dir = strdup(root_dir);
  10517. + } else {
  10518. + sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  10519. + }
  10520. + file_mkdir_hier(dest->root_dir, 0755);
  10521. +
  10522. + sprintf_alloc(&dest->ipkg_dir, "%s%s",
  10523. + dest->root_dir, IPKG_STATE_DIR_PREFIX);
  10524. + file_mkdir_hier(dest->ipkg_dir, 0755);
  10525. +
  10526. + if (str_starts_with (lists_dir, "/"))
  10527. + sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  10528. + else
  10529. + sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  10530. +
  10531. + file_mkdir_hier(dest->lists_dir, 0755);
  10532. +
  10533. + sprintf_alloc(&dest->info_dir, "%s/%s",
  10534. + dest->ipkg_dir, IPKG_INFO_DIR_SUFFIX);
  10535. + file_mkdir_hier(dest->info_dir, 0755);
  10536. +
  10537. + sprintf_alloc(&dest->status_file_name, "%s/%s",
  10538. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10539. +
  10540. + sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
  10541. + dest->ipkg_dir, IPKG_STATUS_FILE_SUFFIX);
  10542. +
  10543. + dest->status_file = NULL;
  10544. +
  10545. + return 0;
  10546. +}
  10547. +
  10548. +void pkg_dest_deinit(pkg_dest_t *dest)
  10549. +{
  10550. + free(dest->name);
  10551. + dest->name = NULL;
  10552. +
  10553. + free(dest->root_dir);
  10554. + dest->root_dir = NULL;
  10555. +
  10556. + free(dest->ipkg_dir);
  10557. + dest->ipkg_dir = NULL;
  10558. +
  10559. + free(dest->lists_dir);
  10560. + dest->lists_dir = NULL;
  10561. +
  10562. + free(dest->info_dir);
  10563. + dest->info_dir = NULL;
  10564. +
  10565. + free(dest->status_file_name);
  10566. + dest->status_file_name = NULL;
  10567. +
  10568. + free(dest->status_file_tmp_name);
  10569. + dest->status_file_tmp_name = NULL;
  10570. +
  10571. + if (dest->status_file) {
  10572. + fclose(dest->status_file);
  10573. + }
  10574. + dest->status_file = NULL;
  10575. +
  10576. + dest->root_dir = NULL;
  10577. +}
  10578. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_dest.h busybox-1.24.1/archival/libipkg/pkg_dest.h
  10579. --- busybox-1.24.1.orig/archival/libipkg/pkg_dest.h 1970-01-01 01:00:00.000000000 +0100
  10580. +++ busybox-1.24.1/archival/libipkg/pkg_dest.h 2015-10-31 19:00:22.000000000 +0100
  10581. @@ -0,0 +1,38 @@
  10582. +/* pkg_dest.h - the itsy package management system
  10583. +
  10584. + Carl D. Worth
  10585. +
  10586. + Copyright (C) 2001 University of Southern California
  10587. +
  10588. + This program is free software; you can redistribute it and/or
  10589. + modify it under the terms of the GNU General Public License as
  10590. + published by the Free Software Foundation; either version 2, or (at
  10591. + your option) any later version.
  10592. +
  10593. + This program is distributed in the hope that it will be useful, but
  10594. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10595. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10596. + General Public License for more details.
  10597. +*/
  10598. +
  10599. +#ifndef PKG_DEST_H
  10600. +#define PKG_DEST_H
  10601. +
  10602. +typedef struct pkg_dest pkg_dest_t;
  10603. +struct pkg_dest
  10604. +{
  10605. + char *name;
  10606. + char *root_dir;
  10607. + char *ipkg_dir;
  10608. + char *lists_dir;
  10609. + char *info_dir;
  10610. + char *status_file_name;
  10611. + char *status_file_tmp_name;
  10612. + FILE *status_file;
  10613. +};
  10614. +
  10615. +int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char *lists_dir);
  10616. +void pkg_dest_deinit(pkg_dest_t *dest);
  10617. +
  10618. +#endif
  10619. +
  10620. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_dest_list.c busybox-1.24.1/archival/libipkg/pkg_dest_list.c
  10621. --- busybox-1.24.1.orig/archival/libipkg/pkg_dest_list.c 1970-01-01 01:00:00.000000000 +0100
  10622. +++ busybox-1.24.1/archival/libipkg/pkg_dest_list.c 2015-10-31 19:00:22.000000000 +0100
  10623. @@ -0,0 +1,85 @@
  10624. +/* pkg_dest_list.c - the itsy package management system
  10625. +
  10626. + Carl D. Worth
  10627. +
  10628. + Copyright (C) 2001 University of Southern California
  10629. +
  10630. + This program is free software; you can redistribute it and/or
  10631. + modify it under the terms of the GNU General Public License as
  10632. + published by the Free Software Foundation; either version 2, or (at
  10633. + your option) any later version.
  10634. +
  10635. + This program is distributed in the hope that it will be useful, but
  10636. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10637. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10638. + General Public License for more details.
  10639. +*/
  10640. +
  10641. +#include "ipkg.h"
  10642. +
  10643. +#include "pkg_dest.h"
  10644. +#include "void_list.h"
  10645. +#include "pkg_dest_list.h"
  10646. +
  10647. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
  10648. +{
  10649. + return void_list_elt_init((void_list_elt_t *) elt, data);
  10650. +}
  10651. +
  10652. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
  10653. +{
  10654. + void_list_elt_deinit((void_list_elt_t *) elt);
  10655. +}
  10656. +
  10657. +int pkg_dest_list_init(pkg_dest_list_t *list)
  10658. +{
  10659. + return void_list_init((void_list_t *) list);
  10660. +}
  10661. +
  10662. +void pkg_dest_list_deinit(pkg_dest_list_t *list)
  10663. +{
  10664. + pkg_dest_list_elt_t *iter;
  10665. + pkg_dest_t *pkg_dest;
  10666. +
  10667. + for (iter = list->head; iter; iter = iter->next) {
  10668. + pkg_dest = iter->data;
  10669. + pkg_dest_deinit(pkg_dest);
  10670. +
  10671. + /* malloced in pkg_dest_list_append */
  10672. + free(pkg_dest);
  10673. + iter->data = NULL;
  10674. + }
  10675. + void_list_deinit((void_list_t *) list);
  10676. +}
  10677. +
  10678. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10679. + const char *root_dir,const char *lists_dir)
  10680. +{
  10681. + int err;
  10682. + pkg_dest_t *pkg_dest;
  10683. +
  10684. + /* freed in plg_dest_list_deinit */
  10685. + pkg_dest = malloc(sizeof(pkg_dest_t));
  10686. + if (pkg_dest == NULL) {
  10687. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  10688. + return NULL;
  10689. + }
  10690. +
  10691. + pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
  10692. + err = void_list_append((void_list_t *) list, pkg_dest);
  10693. + if (err) {
  10694. + return NULL;
  10695. + }
  10696. +
  10697. + return pkg_dest;
  10698. +}
  10699. +
  10700. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
  10701. +{
  10702. + return void_list_push((void_list_t *) list, data);
  10703. +}
  10704. +
  10705. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
  10706. +{
  10707. + return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
  10708. +}
  10709. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_dest_list.h busybox-1.24.1/archival/libipkg/pkg_dest_list.h
  10710. --- busybox-1.24.1.orig/archival/libipkg/pkg_dest_list.h 1970-01-01 01:00:00.000000000 +0100
  10711. +++ busybox-1.24.1/archival/libipkg/pkg_dest_list.h 2015-10-31 19:00:22.000000000 +0100
  10712. @@ -0,0 +1,50 @@
  10713. +/* pkg_dest_list.h - the itsy package management system
  10714. +
  10715. + Carl D. Worth
  10716. +
  10717. + Copyright (C) 2001 University of Southern California
  10718. +
  10719. + This program is free software; you can redistribute it and/or
  10720. + modify it under the terms of the GNU General Public License as
  10721. + published by the Free Software Foundation; either version 2, or (at
  10722. + your option) any later version.
  10723. +
  10724. + This program is distributed in the hope that it will be useful, but
  10725. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10726. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10727. + General Public License for more details.
  10728. +*/
  10729. +
  10730. +#ifndef PKG_DEST_LIST_H
  10731. +#define PKG_DEST_LIST_H
  10732. +
  10733. +#include "pkg_dest.h"
  10734. +
  10735. +typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
  10736. +struct pkg_dest_list_elt
  10737. +{
  10738. + pkg_dest_list_elt_t *next;
  10739. + pkg_dest_t *data;
  10740. +};
  10741. +
  10742. +typedef struct pkg_dest_list pkg_dest_list_t;
  10743. +struct pkg_dest_list
  10744. +{
  10745. + pkg_dest_list_elt_t pre_head;
  10746. + pkg_dest_list_elt_t *head;
  10747. + pkg_dest_list_elt_t *tail;
  10748. +};
  10749. +
  10750. +int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
  10751. +void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
  10752. +
  10753. +int pkg_dest_list_init(pkg_dest_list_t *list);
  10754. +void pkg_dest_list_deinit(pkg_dest_list_t *list);
  10755. +
  10756. +pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
  10757. + const char *root_dir,const char* lists_dir);
  10758. +int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data);
  10759. +pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list);
  10760. +
  10761. +#endif
  10762. +
  10763. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_extract.c busybox-1.24.1/archival/libipkg/pkg_extract.c
  10764. --- busybox-1.24.1.orig/archival/libipkg/pkg_extract.c 1970-01-01 01:00:00.000000000 +0100
  10765. +++ busybox-1.24.1/archival/libipkg/pkg_extract.c 2015-10-31 19:00:22.000000000 +0100
  10766. @@ -0,0 +1,255 @@
  10767. +/* pkg_extract.c - the itsy package management system
  10768. +
  10769. + Carl D. Worth
  10770. +
  10771. + Copyright (C) 2001 University of Southern California
  10772. +
  10773. + This program is free software; you can redistribute it and/or
  10774. + modify it under the terms of the GNU General Public License as
  10775. + published by the Free Software Foundation; either version 2, or (at
  10776. + your option) any later version.
  10777. +
  10778. + This program is distributed in the hope that it will be useful, but
  10779. + WITHOUT ANY WARRANTY; without even the implied warranty of
  10780. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10781. + General Public License for more details.
  10782. +*/
  10783. +
  10784. +#include "ipkg.h"
  10785. +#include <errno.h>
  10786. +#include <fcntl.h>
  10787. +#include <stdio.h>
  10788. +
  10789. +#include "pkg_extract.h"
  10790. +
  10791. +#include "libbb.h"
  10792. +#include "file_util.h"
  10793. +#include "sprintf_alloc.h"
  10794. +#include "bb_archive.h"
  10795. +
  10796. +#define IPKG_CONTROL_ARCHIVE "control.tar.gz"
  10797. +#define IPKG_DATA_ARCHIVE "data.tar.gz"
  10798. +#define IPKG_CONTROL_FILE "control"
  10799. +
  10800. +static void FAST_FUNC ipkg_data_extract_all_prefix(archive_handle_t *archive_handle)
  10801. +{
  10802. + char *name_ptr = archive_handle->file_header->name;
  10803. +
  10804. + /* Skip all leading "/" */
  10805. + while (*name_ptr == '/')
  10806. + name_ptr++;
  10807. + /* Skip all leading "./" and "../" */
  10808. + while (name_ptr[0] == '.') {
  10809. + if (name_ptr[1] == '.' && name_ptr[2] == '/')
  10810. + name_ptr++;
  10811. + if (name_ptr[1] != '/')
  10812. + break;
  10813. + name_ptr += 2;
  10814. + }
  10815. +
  10816. + if (name_ptr[0] != '\0') {
  10817. + archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
  10818. + data_extract_all(archive_handle);
  10819. + }
  10820. +}
  10821. +
  10822. +static void FAST_FUNC ipkg_data_extract_to_buffer(archive_handle_t *archive_handle)
  10823. +{
  10824. + unsigned size = archive_handle->file_header->size;
  10825. +
  10826. + archive_handle->dpkg__buffer = xzalloc(size + 1);
  10827. + xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
  10828. +}
  10829. +
  10830. +static void extract_ipkg_file_to_dir(pkg_t *pkg, const char *dir, const char *filename)
  10831. +{
  10832. + archive_handle_t *archive;
  10833. + char *path;
  10834. +
  10835. + sprintf_alloc(&path, "%s/", dir);
  10836. + archive = init_handle();
  10837. + archive->src_fd = xopen(pkg->local_filename, O_RDONLY);
  10838. + archive->filter = filter_accept_list;
  10839. + llist_add_to(&(archive->accept), (char *)filename);
  10840. + archive->dpkg__buffer = path;
  10841. + archive->action_data = ipkg_data_extract_all_prefix;
  10842. + archive->ah_flags |= ARCHIVE_UNLINK_OLD;
  10843. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10844. + close(archive->src_fd);
  10845. + free(archive->accept);
  10846. + free(archive);
  10847. + free(path);
  10848. +}
  10849. +
  10850. +static void FAST_FUNC data_extract_file_name_to_buffer(archive_handle_t *archive)
  10851. +{
  10852. + unsigned int size = strlen(archive->file_header->name) + 2;
  10853. +
  10854. + if (archive->dpkg__buffer == NULL) {
  10855. + archive->dpkg__buffer = xmalloc(size);
  10856. + strcpy(archive->dpkg__buffer, archive->file_header->name);
  10857. + } else {
  10858. + size += strlen(archive->dpkg__buffer);
  10859. + archive->dpkg__buffer = xrealloc(archive->dpkg__buffer, size);
  10860. + strcat(archive->dpkg__buffer, archive->file_header->name);
  10861. + }
  10862. + strcat(archive->dpkg__buffer, "\n");
  10863. + data_skip(archive);
  10864. +}
  10865. +
  10866. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream)
  10867. +{
  10868. + archive_handle_t *archive;
  10869. + char *name;
  10870. + const char *filename = IPKG_CONTROL_FILE;
  10871. +
  10872. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10873. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10874. + archive = init_handle();
  10875. + archive->src_fd = xopen(name, O_RDONLY);
  10876. + archive->filter = filter_accept_list;
  10877. + llist_add_to(&(archive->accept), (char *)filename);
  10878. + archive->action_data = ipkg_data_extract_to_buffer;
  10879. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10880. + close(archive->src_fd);
  10881. + fputs(archive->dpkg__buffer, stream);
  10882. + free(archive->dpkg__buffer);
  10883. + free(archive->accept);
  10884. + free(archive);
  10885. + free(name);
  10886. +
  10887. + return 0;
  10888. +}
  10889. +
  10890. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir)
  10891. +{
  10892. + return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  10893. +}
  10894. +
  10895. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg, const char *dir, const char *prefix)
  10896. +{
  10897. + archive_handle_t *archive;
  10898. + char *name;
  10899. + char *path;
  10900. +
  10901. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_CONTROL_ARCHIVE);
  10902. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_CONTROL_ARCHIVE);
  10903. + sprintf_alloc(&path, "%s/%s", dir, prefix);
  10904. + archive = init_handle();
  10905. + archive->src_fd = xopen(name, O_RDONLY);
  10906. + archive->filter = filter_accept_all;
  10907. + archive->dpkg__buffer = path;
  10908. + archive->action_data = ipkg_data_extract_all_prefix;
  10909. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10910. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10911. + close(archive->src_fd);
  10912. + free(archive);
  10913. + free(path);
  10914. + free(name);
  10915. +
  10916. + return 0;
  10917. +}
  10918. +
  10919. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
  10920. +{
  10921. + archive_handle_t *archive;
  10922. + char *name;
  10923. + char *path;
  10924. +
  10925. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  10926. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  10927. + sprintf_alloc(&path, "%s/", dir);
  10928. + archive = init_handle();
  10929. + archive->src_fd = xopen(name, O_RDONLY);
  10930. + archive->filter = filter_accept_all;
  10931. + archive->dpkg__buffer = path;
  10932. + archive->action_data = ipkg_data_extract_all_prefix;
  10933. + archive->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_RESTORE_DATE | ARCHIVE_UNLINK_OLD;
  10934. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  10935. + close(archive->src_fd);
  10936. + free(archive);
  10937. + free(path);
  10938. + free(name);
  10939. +
  10940. + return 0;
  10941. +}
  10942. +
  10943. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
  10944. +{
  10945. + int err=0;
  10946. + char *line, *data_file;
  10947. + FILE *file;
  10948. + FILE *tmp;
  10949. +
  10950. + file = fopen(file_name, "w");
  10951. + if (file == NULL) {
  10952. + fprintf(stderr, "%s: ERROR: Failed to open %s for writing.\n",
  10953. + __FUNCTION__, file_name);
  10954. + return EINVAL;
  10955. + }
  10956. +
  10957. + tmp = tmpfile();
  10958. + if (pkg->installed_files) {
  10959. + str_list_elt_t *elt;
  10960. + for (elt = pkg->installed_files->head; elt; elt = elt->next) {
  10961. + fprintf(file, "%s\n", elt->data);
  10962. + }
  10963. + } else {
  10964. + err = pkg_extract_data_file_names_to_stream(pkg, tmp);
  10965. + if (err) {
  10966. + fclose(file);
  10967. + fclose(tmp);
  10968. + return err;
  10969. + }
  10970. +
  10971. + /* Fixup data file names by removing the initial '.' */
  10972. + rewind(tmp);
  10973. + while (1) {
  10974. + line = file_read_line_alloc(tmp);
  10975. + if (line == NULL) {
  10976. + break;
  10977. + }
  10978. +
  10979. + data_file = line;
  10980. + if (*data_file == '.') {
  10981. + data_file++;
  10982. + }
  10983. +
  10984. + if (*data_file != '/') {
  10985. + fputs("/", file);
  10986. + }
  10987. +
  10988. + /* I have no idea why, but this is what dpkg does */
  10989. + if (strcmp(data_file, "/\n") == 0) {
  10990. + fputs("/.\n", file);
  10991. + } else {
  10992. + fputs(data_file, file);
  10993. + }
  10994. + }
  10995. + }
  10996. + fclose(tmp);
  10997. + fclose(file);
  10998. +
  10999. + return err;
  11000. +}
  11001. +
  11002. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
  11003. +{
  11004. + archive_handle_t *archive;
  11005. + char *name;
  11006. +
  11007. + extract_ipkg_file_to_dir(pkg, global_conf->tmp_dir, "./" IPKG_DATA_ARCHIVE);
  11008. + sprintf_alloc(&name, "%s/%s", global_conf->tmp_dir, IPKG_DATA_ARCHIVE);
  11009. + archive = init_handle();
  11010. + archive->src_fd = xopen(name, O_RDONLY);
  11011. + archive->filter = filter_accept_all;
  11012. + archive->action_data = data_extract_file_name_to_buffer;
  11013. + while( get_header_tar_gz(archive) == EXIT_SUCCESS );
  11014. + close(archive->src_fd);
  11015. + fputs(archive->dpkg__buffer, file);
  11016. + free(archive->dpkg__buffer);
  11017. + free(archive);
  11018. + free(name);
  11019. +
  11020. + return 0;
  11021. +}
  11022. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_extract.h busybox-1.24.1/archival/libipkg/pkg_extract.h
  11023. --- busybox-1.24.1.orig/archival/libipkg/pkg_extract.h 1970-01-01 01:00:00.000000000 +0100
  11024. +++ busybox-1.24.1/archival/libipkg/pkg_extract.h 2015-10-31 19:00:22.000000000 +0100
  11025. @@ -0,0 +1,32 @@
  11026. +/* pkg_extract.c - the itsy package management system
  11027. +
  11028. + Carl D. Worth
  11029. +
  11030. + Copyright (C) 2001 University of Southern California
  11031. +
  11032. + This program is free software; you can redistribute it and/or
  11033. + modify it under the terms of the GNU General Public License as
  11034. + published by the Free Software Foundation; either version 2, or (at
  11035. + your option) any later version.
  11036. +
  11037. + This program is distributed in the hope that it will be useful, but
  11038. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11039. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11040. + General Public License for more details.
  11041. +*/
  11042. +
  11043. +#ifndef PKG_EXTRACT_H
  11044. +#define PKG_EXTRACT_H
  11045. +
  11046. +#include "pkg.h"
  11047. +
  11048. +int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream);
  11049. +int pkg_extract_control_files_to_dir(pkg_t *pkg, const char *dir);
  11050. +int pkg_extract_control_files_to_dir_with_prefix(pkg_t *pkg,
  11051. + const char *dir,
  11052. + const char *prefix);
  11053. +int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir);
  11054. +int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name);
  11055. +int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file);
  11056. +
  11057. +#endif
  11058. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg.h busybox-1.24.1/archival/libipkg/pkg.h
  11059. --- busybox-1.24.1.orig/archival/libipkg/pkg.h 1970-01-01 01:00:00.000000000 +0100
  11060. +++ busybox-1.24.1/archival/libipkg/pkg.h 2015-10-31 19:00:22.000000000 +0100
  11061. @@ -0,0 +1,229 @@
  11062. +/* pkg.h - the itsy package management system
  11063. +
  11064. + Carl D. Worth
  11065. +
  11066. + Copyright (C) 2001 University of Southern California
  11067. +
  11068. + This program is free software; you can redistribute it and/or
  11069. + modify it under the terms of the GNU General Public License as
  11070. + published by the Free Software Foundation; either version 2, or (at
  11071. + your option) any later version.
  11072. +
  11073. + This program is distributed in the hope that it will be useful, but
  11074. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11075. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11076. + General Public License for more details.
  11077. +*/
  11078. +
  11079. +#ifndef PKG_H
  11080. +#define PKG_H
  11081. +
  11082. +#include <sys/types.h>
  11083. +#include <sys/stat.h>
  11084. +#include <unistd.h>
  11085. +
  11086. +#include "pkg_vec.h"
  11087. +#include "str_list.h"
  11088. +#include "pkg_src.h"
  11089. +#include "pkg_dest.h"
  11090. +#include "ipkg_conf.h"
  11091. +#include "conffile_list.h"
  11092. +
  11093. +struct ipkg_conf;
  11094. +
  11095. +/* I think "Size" is currently the shortest field name */
  11096. +#define PKG_MINIMUM_FIELD_NAME_LEN 4
  11097. +
  11098. +enum pkg_state_want
  11099. +{
  11100. + SW_UNKNOWN = 1,
  11101. + SW_INSTALL,
  11102. + SW_DEINSTALL,
  11103. + SW_PURGE,
  11104. + SW_LAST_STATE_WANT
  11105. +};
  11106. +typedef enum pkg_state_want pkg_state_want_t;
  11107. +
  11108. +enum pkg_state_flag
  11109. +{
  11110. + SF_OK = 0,
  11111. + SF_REINSTREQ = 1,
  11112. + SF_HOLD = 2, /* do not upgrade version */
  11113. + SF_REPLACE = 4, /* replace this package */
  11114. + SF_NOPRUNE = 8, /* do not remove obsolete files */
  11115. + SF_PREFER = 16, /* prefer this version */
  11116. + SF_OBSOLETE = 32, /* old package in upgrade pair */
  11117. + SF_MARKED = 64, /* temporary mark */
  11118. + SF_FILELIST_CHANGED = 128, /* needs filelist written */
  11119. + SF_USER = 256,
  11120. + SF_LAST_STATE_FLAG
  11121. +};
  11122. +typedef enum pkg_state_flag pkg_state_flag_t;
  11123. +#define SF_NONVOLATILE_FLAGS (SF_HOLD|SF_NOPRUNE|SF_PREFER|SF_OBSOLETE|SF_USER)
  11124. +
  11125. +enum pkg_state_status
  11126. +{
  11127. + SS_NOT_INSTALLED = 1,
  11128. + SS_UNPACKED,
  11129. + SS_HALF_CONFIGURED,
  11130. + SS_INSTALLED,
  11131. + SS_HALF_INSTALLED,
  11132. + SS_CONFIG_FILES,
  11133. + SS_POST_INST_FAILED,
  11134. + SS_REMOVAL_FAILED,
  11135. + SS_LAST_STATE_STATUS
  11136. +};
  11137. +typedef enum pkg_state_status pkg_state_status_t;
  11138. +
  11139. +struct abstract_pkg{
  11140. + char * name;
  11141. + int dependencies_checked;
  11142. + pkg_vec_t * pkgs;
  11143. + pkg_state_status_t state_status;
  11144. + pkg_state_flag_t state_flag;
  11145. + struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */
  11146. + abstract_pkg_vec_t * provided_by;
  11147. + abstract_pkg_vec_t * replaced_by;
  11148. +};
  11149. +
  11150. +#include "pkg_depends.h"
  11151. +
  11152. +/* XXX: CLEANUP: I'd like to clean up pkg_t in several ways:
  11153. +
  11154. + The 3 version fields should go into a single version struct. (This
  11155. + is especially important since, currently, pkg->version can easily
  11156. + be mistaken for pkg_verson_str_alloc(pkg) although they are very
  11157. + distinct. This has been the source of multiple bugs.
  11158. +
  11159. + The 3 state fields could possibly also go into their own struct.
  11160. +
  11161. + All fields which deal with lists of packages, (Depends,
  11162. + Pre-Depends, Provides, Suggests, Recommends, Enhances), should each
  11163. + be handled by a single struct in pkg_t
  11164. +
  11165. + All string fields for which there is a small set of possible
  11166. + values, (section, maintainer, architecture, maybe version?), that
  11167. + are reused among different packages -- for all such packages we
  11168. + should move from "char *"s to some atom datatype to share data
  11169. + storage and use less memory. We might even do reference counting,
  11170. + but probably not since most often we only create new pkg_t structs,
  11171. + we don't often free them. */
  11172. +struct pkg
  11173. +{
  11174. + char *name;
  11175. + unsigned long epoch;
  11176. + char *version;
  11177. + char *revision;
  11178. + char *familiar_revision;
  11179. + pkg_src_t *src;
  11180. + pkg_dest_t *dest;
  11181. + char *architecture;
  11182. + char *section;
  11183. + char *maintainer;
  11184. + char *description;
  11185. + pkg_state_want_t state_want;
  11186. + pkg_state_flag_t state_flag;
  11187. + pkg_state_status_t state_status;
  11188. + char **depends_str;
  11189. + int depends_count;
  11190. + char **pre_depends_str;
  11191. + int pre_depends_count;
  11192. + char **recommends_str;
  11193. + int recommends_count;
  11194. + char **suggests_str;
  11195. + int suggests_count;
  11196. + compound_depend_t * depends;
  11197. +
  11198. + /* Abhaya: new conflicts */
  11199. + char **conflicts_str;
  11200. + compound_depend_t * conflicts;
  11201. + int conflicts_count;
  11202. +
  11203. + char **replaces_str;
  11204. + int replaces_count;
  11205. + abstract_pkg_t ** replaces;
  11206. +
  11207. + char **provides_str;
  11208. + int provides_count;
  11209. + abstract_pkg_t ** provides;
  11210. +
  11211. + abstract_pkg_t *parent;
  11212. +
  11213. + pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */
  11214. +
  11215. + char *filename;
  11216. + char *local_filename;
  11217. + char *url;
  11218. + char *tmp_unpack_dir;
  11219. + char *md5sum;
  11220. + char *size;
  11221. + char *installed_size;
  11222. + char *priority;
  11223. + char *source;
  11224. + conffile_list_t conffiles;
  11225. + time_t installed_time;
  11226. + /* As pointer for lazy evaluation */
  11227. + str_list_t *installed_files;
  11228. + /* XXX: CLEANUP: I'd like to perhaps come up with a better
  11229. + mechanism to avoid the problem here, (which is that the
  11230. + installed_files list was being freed from an inner loop while
  11231. + still being used within an outer loop. */
  11232. + int installed_files_ref_cnt;
  11233. + int essential;
  11234. + int arch_priority;
  11235. +/* Adding this flag, to "force" ipkg to choose a "provided_by_hand" package, if there are multiple choice */
  11236. + int provided_by_hand;
  11237. +};
  11238. +
  11239. +pkg_t *pkg_new(void);
  11240. +int pkg_init(pkg_t *pkg);
  11241. +void pkg_deinit(pkg_t *pkg);
  11242. +int pkg_init_from_file(pkg_t *pkg, const char *filename);
  11243. +abstract_pkg_t *abstract_pkg_new(void);
  11244. +int abstract_pkg_init(abstract_pkg_t *ab_pkg);
  11245. +
  11246. +/*
  11247. + * merges fields from newpkg into oldpkg.
  11248. + * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero
  11249. + */
  11250. +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status);
  11251. +
  11252. +char *pkg_version_str_alloc(pkg_t *pkg);
  11253. +
  11254. +int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg);
  11255. +int pkg_name_version_and_architecture_compare(pkg_t *a, pkg_t *b);
  11256. +int abstract_pkg_name_compare(abstract_pkg_t *a, abstract_pkg_t *b);
  11257. +
  11258. +char * pkg_formatted_info(pkg_t *pkg );
  11259. +char * pkg_formatted_field(pkg_t *pkg, const char *field );
  11260. +
  11261. +void set_flags_from_control(ipkg_conf_t *conf, pkg_t *pkg);
  11262. +
  11263. +void pkg_print_info(pkg_t *pkg, FILE *file);
  11264. +void pkg_print_status(pkg_t * pkg, FILE * file);
  11265. +void pkg_print_field(pkg_t *pkg, FILE *file, const char *field);
  11266. +str_list_t *pkg_get_installed_files(pkg_t *pkg);
  11267. +int pkg_free_installed_files(pkg_t *pkg);
  11268. +int pkg_remove_installed_files_list(ipkg_conf_t *conf, pkg_t *pkg);
  11269. +conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
  11270. +int pkg_run_script(struct ipkg_conf *conf, pkg_t *pkg,
  11271. + const char *script, const char *args);
  11272. +
  11273. +/* enum mappings */
  11274. +char *pkg_state_want_to_str(pkg_state_want_t sw);
  11275. +pkg_state_want_t pkg_state_want_from_str(char *str);
  11276. +char *pkg_state_flag_to_str(pkg_state_flag_t sf);
  11277. +pkg_state_flag_t pkg_state_flag_from_str(char *str);
  11278. +char *pkg_state_status_to_str(pkg_state_status_t ss);
  11279. +pkg_state_status_t pkg_state_status_from_str(char *str);
  11280. +
  11281. +int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op);
  11282. +
  11283. +int pkg_arch_supported(ipkg_conf_t *conf, pkg_t *pkg);
  11284. +int pkg_info_preinstall_check(ipkg_conf_t *conf);
  11285. +int pkg_free_installed_files(pkg_t *pkg);
  11286. +
  11287. +int pkg_write_filelist(ipkg_conf_t *conf, pkg_t *pkg);
  11288. +int pkg_write_changed_filelists(ipkg_conf_t *conf);
  11289. +
  11290. +#endif
  11291. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_hash.c busybox-1.24.1/archival/libipkg/pkg_hash.c
  11292. --- busybox-1.24.1.orig/archival/libipkg/pkg_hash.c 1970-01-01 01:00:00.000000000 +0100
  11293. +++ busybox-1.24.1/archival/libipkg/pkg_hash.c 2015-10-31 19:00:22.000000000 +0100
  11294. @@ -0,0 +1,623 @@
  11295. +/* ipkg_hash.c - the itsy package management system
  11296. +
  11297. + Steven M. Ayer
  11298. +
  11299. + Copyright (C) 2002 Compaq Computer Corporation
  11300. +
  11301. + This program is free software; you can redistribute it and/or
  11302. + modify it under the terms of the GNU General Public License as
  11303. + published by the Free Software Foundation; either version 2, or (at
  11304. + your option) any later version.
  11305. +
  11306. + This program is distributed in the hope that it will be useful, but
  11307. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11308. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11309. + General Public License for more details.
  11310. +*/
  11311. +
  11312. +#include "ipkg.h"
  11313. +#include <errno.h>
  11314. +#include <ctype.h>
  11315. +#include <stdlib.h>
  11316. +#include <string.h>
  11317. +
  11318. +#include "hash_table.h"
  11319. +#include "pkg.h"
  11320. +#include "ipkg_message.h"
  11321. +#include "pkg_vec.h"
  11322. +#include "pkg_hash.h"
  11323. +#include "pkg_parse.h"
  11324. +#include "ipkg_utils.h"
  11325. +
  11326. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11327. +
  11328. +/*
  11329. + * this will talk to both feeds-lists files and installed status files
  11330. + * example api:
  11331. + *
  11332. + * hash_table_t hash;
  11333. + * pkg_hash_init(name, &hash, 1000);
  11334. + * pkg_hash_add_from_file(<feed filename>);
  11335. + *
  11336. + * the query function is just there as a shell to prove to me that this
  11337. + * sort of works, but isn't far from doing something useful
  11338. + *
  11339. + * -sma, 12/21/01
  11340. + * modified: CDW 3 Jan. 2002
  11341. + */
  11342. +
  11343. +
  11344. +
  11345. +int pkg_hash_init(const char *name, hash_table_t *hash, int len)
  11346. +{
  11347. + return hash_table_init(name, hash, len);
  11348. +}
  11349. +
  11350. +void pkg_hash_deinit(hash_table_t *hash)
  11351. +{
  11352. + hash_table_deinit(hash);
  11353. +}
  11354. +
  11355. +
  11356. +/* Find the default arch for a given package status file if none is given. */
  11357. +static char *pkg_get_default_arch(ipkg_conf_t *conf)
  11358. +{
  11359. + nv_pair_list_elt_t *l;
  11360. + const char *def_arch = HOST_CPU_STR; /* Default arch */
  11361. + int def_prio = 0; /* Other archs override this */
  11362. +
  11363. + l = conf->arch_list.head;
  11364. +
  11365. + while (l) {
  11366. + nv_pair_t *nv = l->data;
  11367. + int priority = strtol(nv->value, NULL, 0);
  11368. +
  11369. + /* Check if this arch has higher priority, and is valid */
  11370. + if ((priority > def_prio) &&
  11371. + (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
  11372. + /* Our new default */
  11373. + def_prio = priority;
  11374. + def_arch = nv->name;
  11375. + }
  11376. + l = l->next;
  11377. + }
  11378. +
  11379. + return strdup(def_arch);
  11380. +}
  11381. +
  11382. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11383. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
  11384. +{
  11385. + hash_table_t *hash = &conf->pkg_hash;
  11386. + char **raw;
  11387. + char **raw_start;
  11388. + pkg_t *pkg;
  11389. +
  11390. + raw = raw_start = read_raw_pkgs_from_file(file_name);
  11391. + if (!raw)
  11392. + return -ENOMEM;
  11393. +
  11394. + while(*raw){ /* don't worry, we'll increment raw in the parsing function */
  11395. + pkg = pkg_new();
  11396. + if (!pkg)
  11397. + return -ENOMEM;
  11398. +
  11399. + if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
  11400. + if (!pkg->architecture) {
  11401. + char *version_str = pkg_version_str_alloc(pkg);
  11402. + pkg->architecture = pkg_get_default_arch(conf);
  11403. + ipkg_message(conf, IPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
  11404. + pkg->name, version_str, pkg->architecture);
  11405. + free(version_str);
  11406. + }
  11407. + hash_insert_pkg(hash, pkg, is_status_file,conf);
  11408. + } else {
  11409. + free(pkg);
  11410. + }
  11411. + }
  11412. +
  11413. + /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
  11414. + memory after read_raw_pkgs_from_file */
  11415. + raw = raw_start;
  11416. + while (*raw) {
  11417. + free(*raw++);
  11418. + }
  11419. + free(raw_start);
  11420. + return 0;
  11421. +}
  11422. +
  11423. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
  11424. +{
  11425. + return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
  11426. +}
  11427. +
  11428. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
  11429. +{
  11430. + abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
  11431. + if (apkg)
  11432. + return NULL;
  11433. + return apkg->provided_by;
  11434. +}
  11435. +
  11436. +
  11437. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11438. + int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
  11439. +{
  11440. + int i;
  11441. + int nprovides = 0;
  11442. + int nmatching = 0;
  11443. + pkg_vec_t *matching_pkgs = pkg_vec_alloc();
  11444. + abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
  11445. + abstract_pkg_vec_t *provided_apkg_vec;
  11446. + abstract_pkg_t **provided_apkgs;
  11447. + abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
  11448. + pkg_t *latest_installed_parent = NULL;
  11449. + pkg_t *latest_matching = NULL;
  11450. + pkg_t *held_pkg = NULL;
  11451. + pkg_t *good_pkg_by_name = NULL;
  11452. +
  11453. + if (matching_apkgs == NULL || providers == NULL ||
  11454. + apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
  11455. + return NULL;
  11456. +
  11457. + ipkg_message(conf, IPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
  11458. +
  11459. + provided_apkg_vec = apkg->provided_by;
  11460. + nprovides = provided_apkg_vec->len;
  11461. + provided_apkgs = provided_apkg_vec->pkgs;
  11462. + if (nprovides > 1)
  11463. + ipkg_message(conf, IPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
  11464. +
  11465. + /* accumulate all the providers */
  11466. + for (i = 0; i < nprovides; i++) {
  11467. + abstract_pkg_t *provider_apkg = provided_apkgs[i];
  11468. + ipkg_message(conf, IPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
  11469. + abstract_pkg_vec_insert(providers, provider_apkg);
  11470. + }
  11471. + nprovides = providers->len;
  11472. +
  11473. + for (i = 0; i < nprovides; i++) {
  11474. + abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
  11475. + abstract_pkg_t *replacement_apkg = NULL;
  11476. + pkg_vec_t *vec;
  11477. +
  11478. + if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
  11479. + replacement_apkg = provider_apkg->replaced_by->pkgs[0];
  11480. + if (provider_apkg->replaced_by->len > 1) {
  11481. + ipkg_message(conf, IPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
  11482. + provider_apkg->name, replacement_apkg->name);
  11483. + }
  11484. + }
  11485. +
  11486. + if (replacement_apkg)
  11487. + ipkg_message(conf, IPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
  11488. + replacement_apkg->name, provider_apkg->name);
  11489. +
  11490. + if (replacement_apkg && (replacement_apkg != provider_apkg)) {
  11491. + if (abstract_pkg_vec_contains(providers, replacement_apkg))
  11492. + continue;
  11493. + else
  11494. + provider_apkg = replacement_apkg;
  11495. + }
  11496. +
  11497. + if (!(vec = provider_apkg->pkgs)) {
  11498. + ipkg_message(conf, IPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
  11499. + continue;
  11500. + }
  11501. +
  11502. +
  11503. + /* now check for supported architecture */
  11504. + {
  11505. + int max_count = 0;
  11506. + int j;
  11507. +
  11508. + /* count packages matching max arch priority and keep track of last one */
  11509. + for (j = 0; j < vec->len; j++) {
  11510. + pkg_t *maybe = vec->pkgs[j];
  11511. + ipkg_message(conf, IPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
  11512. + maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
  11513. + if (maybe->arch_priority > 0) {
  11514. + max_count++;
  11515. + abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
  11516. + pkg_vec_insert(matching_pkgs, maybe);
  11517. + }
  11518. + }
  11519. + }
  11520. + }
  11521. +
  11522. + if (matching_pkgs->len > 1)
  11523. + pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
  11524. + if (matching_apkgs->len > 1)
  11525. + abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
  11526. +
  11527. +/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
  11528. + needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
  11529. +/* The problem is what to do when there are more than a mathing package, with the same name and several version ?
  11530. + Until now I always got the latest, but that breaks the downgrade option.
  11531. + If I stop at the first one, I would probably miss the new ones
  11532. + Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
  11533. + or from a Packages feed.
  11534. + It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
  11535. +/*Pigi*/
  11536. +
  11537. + for (i = 0; i < matching_pkgs->len; i++) {
  11538. + pkg_t *matching = matching_pkgs->pkgs[i];
  11539. + if (constraint_fcn(matching, cdata)) { /* We found it */
  11540. + ipkg_message(conf, IPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
  11541. + good_pkg_by_name = matching;
  11542. + if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
  11543. + break;
  11544. + }
  11545. + }
  11546. +
  11547. +
  11548. + for (i = 0; i < matching_pkgs->len; i++) {
  11549. + pkg_t *matching = matching_pkgs->pkgs[i];
  11550. + latest_matching = matching;
  11551. + if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
  11552. + latest_installed_parent = matching;
  11553. + if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
  11554. + if (held_pkg)
  11555. + ipkg_message(conf, IPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
  11556. + held_pkg->name, matching->name);
  11557. + held_pkg = matching;
  11558. + }
  11559. + }
  11560. +
  11561. + if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
  11562. + ipkg_message(conf, IPKG_ERROR, "Package=%s, %d matching providers\n",
  11563. + apkg->name, matching_apkgs->len);
  11564. + for (i = 0; i < matching_apkgs->len; i++) {
  11565. + abstract_pkg_t *matching = matching_apkgs->pkgs[i];
  11566. + ipkg_message(conf, IPKG_ERROR, " %s\n", matching->name);
  11567. + }
  11568. + ipkg_message(conf, IPKG_ERROR, "Please select one with ipkg install or ipkg flag prefer\n");
  11569. + }
  11570. +
  11571. + if (matching_apkgs->len > 1 && conf->verbosity > 1) {
  11572. + ipkg_message(conf, IPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
  11573. + __FUNCTION__, apkg->name, matching_pkgs->len);
  11574. + for (i = 0; i < matching_pkgs->len; i++) {
  11575. + pkg_t *matching = matching_pkgs->pkgs[i];
  11576. + ipkg_message(conf, IPKG_INFO, " %s %s %s\n",
  11577. + matching->name, matching->version, matching->architecture);
  11578. + }
  11579. + }
  11580. +
  11581. + nmatching = matching_apkgs->len;
  11582. +
  11583. + pkg_vec_free(matching_pkgs);
  11584. + abstract_pkg_vec_free(matching_apkgs);
  11585. + abstract_pkg_vec_free(providers);
  11586. +
  11587. + if (good_pkg_by_name) { /* We found a good candidate, we will install it */
  11588. + return good_pkg_by_name;
  11589. + }
  11590. + if (held_pkg) {
  11591. + ipkg_message(conf, IPKG_INFO, " using held package %s\n", held_pkg->name);
  11592. + return held_pkg;
  11593. + }
  11594. + if (latest_installed_parent) {
  11595. + ipkg_message(conf, IPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
  11596. + return latest_installed_parent;
  11597. + }
  11598. + if (nmatching > 1) {
  11599. + ipkg_message(conf, IPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
  11600. + return NULL;
  11601. + }
  11602. + if (latest_matching) {
  11603. + ipkg_message(conf, IPKG_INFO, " using latest matching %s %s %s\n",
  11604. + latest_matching->name, latest_matching->version, latest_matching->architecture);
  11605. + return latest_matching;
  11606. + }
  11607. + return NULL;
  11608. +}
  11609. +
  11610. +static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
  11611. +{
  11612. + const char *name = (const char *)cdata;
  11613. + if (strcmp(pkg->name, name) == 0)
  11614. + return 1;
  11615. + else
  11616. + return 0;
  11617. +}
  11618. +
  11619. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name)
  11620. +{
  11621. + hash_table_t *hash = &conf->pkg_hash;
  11622. + abstract_pkg_t *apkg = NULL;
  11623. +
  11624. + if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
  11625. + return NULL;
  11626. +
  11627. + return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
  11628. +}
  11629. +
  11630. +
  11631. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11632. + const char *pkg_name,
  11633. + const char * version)
  11634. +{
  11635. + pkg_vec_t * vec;
  11636. + register int i;
  11637. + char *version_str = NULL;
  11638. +
  11639. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
  11640. + return NULL;
  11641. +
  11642. + for(i = 0; i < vec->len; i++) {
  11643. + version_str = pkg_version_str_alloc(vec->pkgs[i]);
  11644. + if(!strcmp(version_str, version)) {
  11645. + free(version_str);
  11646. + break;
  11647. + }
  11648. + free(version_str);
  11649. + }
  11650. +
  11651. + if(i == vec->len)
  11652. + return NULL;
  11653. +
  11654. + return vec->pkgs[i];
  11655. +}
  11656. +
  11657. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11658. + const char *pkg_name,
  11659. + pkg_dest_t *dest)
  11660. +{
  11661. + pkg_vec_t * vec;
  11662. + register int i;
  11663. +
  11664. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
  11665. + return NULL;
  11666. + }
  11667. +
  11668. + for(i = 0; i < vec->len; i++)
  11669. + if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
  11670. + return vec->pkgs[i];
  11671. + }
  11672. + return NULL;
  11673. +}
  11674. +
  11675. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11676. + const char *pkg_name)
  11677. +{
  11678. + pkg_vec_t * vec;
  11679. + register int i;
  11680. +
  11681. + if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
  11682. + return NULL;
  11683. + }
  11684. +
  11685. + for(i = 0; i < vec->len; i++)
  11686. + if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
  11687. + return vec->pkgs[i];
  11688. + }
  11689. +
  11690. + return NULL;
  11691. +}
  11692. +
  11693. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
  11694. +{
  11695. + abstract_pkg_t * ab_pkg;
  11696. +
  11697. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
  11698. + return NULL;
  11699. + }
  11700. +
  11701. + if (ab_pkg->pkgs) {
  11702. + return ab_pkg->pkgs;
  11703. + } else if (ab_pkg->provided_by) {
  11704. + abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
  11705. + if (abpkg != NULL){
  11706. + return abpkg->pkgs;
  11707. + } else {
  11708. + return ab_pkg->pkgs;
  11709. + }
  11710. + } else {
  11711. + return NULL;
  11712. + }
  11713. +}
  11714. +
  11715. +static int pkg_compare_names(const void *p1, const void *p2)
  11716. +{
  11717. + const pkg_t *pkg1 = *(const pkg_t **)p1;
  11718. + const pkg_t *pkg2 = *(const pkg_t **)p2;
  11719. + if (pkg1->name == NULL)
  11720. + return 1;
  11721. + if (pkg2->name == NULL)
  11722. + return -1;
  11723. + return(strcmp(pkg1->name, pkg2->name));
  11724. +}
  11725. +
  11726. +
  11727. +static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
  11728. +{
  11729. + int j;
  11730. + const char *name;
  11731. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11732. + pkg_vec_t *all = (pkg_vec_t *)data;
  11733. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11734. + name = pkg_name;
  11735. + if (pkg_vec) {
  11736. + for (j = 0; j < pkg_vec->len; j++) {
  11737. + pkg_t *pkg = pkg_vec->pkgs[j];
  11738. + pkg_vec_insert(all, pkg);
  11739. + }
  11740. + }
  11741. +}
  11742. +
  11743. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
  11744. +{
  11745. + hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
  11746. + qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
  11747. +}
  11748. +
  11749. +static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
  11750. +{
  11751. + const char *name;
  11752. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11753. + pkg_vec_t *all = (pkg_vec_t *)data;
  11754. + pkg_vec_t *pkg_vec = ab_pkg->pkgs;
  11755. + int j;
  11756. + name = pkg_name;
  11757. + if (pkg_vec) {
  11758. + for (j = 0; j < pkg_vec->len; j++) {
  11759. + pkg_t *pkg = pkg_vec->pkgs[j];
  11760. + if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
  11761. + pkg_vec_insert(all, pkg);
  11762. + }
  11763. + }
  11764. + }
  11765. +}
  11766. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
  11767. +{
  11768. + hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
  11769. + qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
  11770. +}
  11771. +
  11772. +static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
  11773. +{
  11774. + int i;
  11775. + pkg_t *pkg;
  11776. + const char *name;
  11777. + abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
  11778. + ipkg_conf_t *conf = (ipkg_conf_t *)data;
  11779. + abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
  11780. + name = pkg_name;
  11781. + fprintf(stdout, "%s\n", ab_pkg->name);
  11782. + i = 0;
  11783. + if (dependents != NULL)
  11784. + while (dependents [i] != NULL)
  11785. + printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
  11786. + dependents = ab_pkg->provided_by->pkgs;
  11787. + i = 0;
  11788. + if (dependents != NULL)
  11789. + while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
  11790. + printf ("\tprovided by - %s\n", dependents [i ++]->name);
  11791. + pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
  11792. + if (pkg) {
  11793. + i = 0;
  11794. + while (i < pkg->depends_count)
  11795. + printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
  11796. + }
  11797. +}
  11798. +void pkg_hash_dump(hash_table_t *hash, void *data)
  11799. +{
  11800. +
  11801. + printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
  11802. + hash_table_foreach(hash, pkg_hash_dump_helper, data);
  11803. + printf ("\n+=+%s+=+\n\n", __FUNCTION__);
  11804. +}
  11805. +
  11806. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11807. +{
  11808. + abstract_pkg_t * ab_pkg;
  11809. +
  11810. + if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
  11811. + ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
  11812. +
  11813. + return ab_pkg;
  11814. +}
  11815. +
  11816. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  11817. +{
  11818. + abstract_pkg_t * ab_pkg;
  11819. + int arch_priority;
  11820. +
  11821. + if(!pkg)
  11822. + return pkg;
  11823. +
  11824. + arch_priority = pkg->arch_priority;
  11825. +
  11826. + if (buildDepends(hash, pkg)<0){
  11827. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11828. + return NULL;
  11829. + }
  11830. + ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
  11831. +
  11832. + if (set_status) {
  11833. + if (pkg->state_status == SS_INSTALLED) {
  11834. + ab_pkg->state_status = SS_INSTALLED;
  11835. + } else if (pkg->state_status == SS_UNPACKED) {
  11836. + ab_pkg->state_status = SS_UNPACKED;
  11837. + }
  11838. + }
  11839. +
  11840. + if(!ab_pkg->pkgs)
  11841. + ab_pkg->pkgs = pkg_vec_alloc();
  11842. +
  11843. + /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
  11844. + pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
  11845. + pkg->parent = ab_pkg;
  11846. +
  11847. + if (buildProvides(hash, ab_pkg, pkg)<0){
  11848. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11849. + return NULL;
  11850. + }
  11851. + /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
  11852. + if (buildConflicts(hash, pkg)<0){
  11853. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11854. + return NULL;
  11855. + }
  11856. + if (buildReplaces(hash, ab_pkg, pkg)<0) {
  11857. + fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
  11858. + return NULL;
  11859. + }
  11860. +
  11861. + buildDependedUponBy(pkg, ab_pkg);
  11862. + return pkg;
  11863. +}
  11864. +
  11865. +/*
  11866. + * this will assume that we've already determined that
  11867. + * the abstract pkg doesn't exist, 'cause we should know these things...
  11868. + */
  11869. +static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
  11870. +{
  11871. + abstract_pkg_t * ab_pkg;
  11872. +
  11873. + ab_pkg = abstract_pkg_new();
  11874. + if (ab_pkg == NULL) { return NULL; }
  11875. +
  11876. + ab_pkg->name = strdup(pkg_name);
  11877. + hash_table_insert(hash, pkg_name, ab_pkg);
  11878. +
  11879. + return ab_pkg;
  11880. +}
  11881. +
  11882. +
  11883. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name)
  11884. +{
  11885. + hash_table_t *file_hash = &conf->file_hash;
  11886. +
  11887. + return hash_table_get(file_hash, file_name);
  11888. +}
  11889. +
  11890. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
  11891. +{
  11892. + hash_table_t *file_hash = &conf->file_hash;
  11893. + pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
  11894. + int file_name_len = strlen(file_name);
  11895. +
  11896. + if (file_name[file_name_len -1] == '/')
  11897. + return 0;
  11898. +
  11899. + if (conf->offline_root) {
  11900. + int len = strlen(conf->offline_root);
  11901. + if (strncmp(file_name, conf->offline_root, len) == 0) {
  11902. + file_name += len;
  11903. + }
  11904. + }
  11905. +
  11906. + // ipkg_message(conf, IPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
  11907. + hash_table_insert(file_hash, file_name, owning_pkg);
  11908. + if (old_owning_pkg) {
  11909. + str_list_remove_elt(old_owning_pkg->installed_files, file_name);
  11910. + /* mark this package to have its filelist written */
  11911. + old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11912. + owning_pkg->state_flag |= SF_FILELIST_CHANGED;
  11913. + }
  11914. + return 0;
  11915. +}
  11916. +
  11917. +
  11918. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_hash.h busybox-1.24.1/archival/libipkg/pkg_hash.h
  11919. --- busybox-1.24.1.orig/archival/libipkg/pkg_hash.h 1970-01-01 01:00:00.000000000 +0100
  11920. +++ busybox-1.24.1/archival/libipkg/pkg_hash.h 2015-10-31 19:00:22.000000000 +0100
  11921. @@ -0,0 +1,61 @@
  11922. +/* pkg_hash.h - the itsy package management system
  11923. +
  11924. + Steven M. Ayer
  11925. +
  11926. + Copyright (C) 2002 Compaq Computer Corporation
  11927. +
  11928. + This program is free software; you can redistribute it and/or
  11929. + modify it under the terms of the GNU General Public License as
  11930. + published by the Free Software Foundation; either version 2, or (at
  11931. + your option) any later version.
  11932. +
  11933. + This program is distributed in the hope that it will be useful, but
  11934. + WITHOUT ANY WARRANTY; without even the implied warranty of
  11935. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11936. + General Public License for more details.
  11937. +*/
  11938. +
  11939. +#ifndef PKG_HASH_H
  11940. +#define PKG_HASH_H
  11941. +
  11942. +#include "pkg.h"
  11943. +#include "pkg_vec.h"
  11944. +#include "hash_table.h"
  11945. +
  11946. +
  11947. +int pkg_hash_init(const char *name, hash_table_t *hash, int len);
  11948. +void pkg_hash_deinit(hash_table_t *hash);
  11949. +void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data);
  11950. +
  11951. +void pkg_hash_dump(hash_table_t *hash, void *data);
  11952. +void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available);
  11953. +
  11954. +int pkg_hash_add_from_file(ipkg_conf_t *conf, const char *file_name,
  11955. + pkg_src_t *src, pkg_dest_t *dest, int is_status_file);
  11956. +pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,ipkg_conf_t *conf);
  11957. +
  11958. +abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
  11959. +abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name);
  11960. +pkg_vec_t *pkg_hash_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11961. +void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed);
  11962. +pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
  11963. + const char *pkg_name,
  11964. + const char * version);
  11965. +abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name);
  11966. +pkg_t *pkg_hash_fetch_best_installation_candidate(ipkg_conf_t *conf, abstract_pkg_t *apkg,
  11967. + int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet);
  11968. +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(ipkg_conf_t *conf, const char *name);
  11969. +pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
  11970. + const char *pkg_name);
  11971. +pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
  11972. + const char *pkg_name,
  11973. + pkg_dest_t *dest);
  11974. +
  11975. +pkg_t *file_hash_get_file_owner(ipkg_conf_t *conf, const char *file_name);
  11976. +int file_hash_set_file_owner(ipkg_conf_t *conf, const char *file_name, pkg_t *pkg);
  11977. +
  11978. +/* XXX: shouldn't this go in pkg_vec.[ch]? */
  11979. +pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name);
  11980. +
  11981. +#endif
  11982. +
  11983. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_parse.c busybox-1.24.1/archival/libipkg/pkg_parse.c
  11984. --- busybox-1.24.1.orig/archival/libipkg/pkg_parse.c 1970-01-01 01:00:00.000000000 +0100
  11985. +++ busybox-1.24.1/archival/libipkg/pkg_parse.c 2015-10-31 19:00:22.000000000 +0100
  11986. @@ -0,0 +1,368 @@
  11987. +/* pkg_parse.c - the itsy package management system
  11988. +
  11989. + Steven M. Ayer
  11990. +
  11991. + Copyright (C) 2002 Compaq Computer Corporation
  11992. +
  11993. + This program is free software; you can redistribute it and/or
  11994. + modify it under the terms of the GNU General Public License as
  11995. + published by the Free Software Foundation; either version 2, or (at
  11996. + your option) any later version.
  11997. +
  11998. + This program is distributed in the hope that it will be useful, but
  11999. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12000. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12001. + General Public License for more details.
  12002. +*/
  12003. +
  12004. +#include "ipkg.h"
  12005. +#include <errno.h>
  12006. +#include <ctype.h>
  12007. +
  12008. +#include "pkg.h"
  12009. +#include "ipkg_utils.h"
  12010. +#include "pkg_parse.h"
  12011. +
  12012. +int alterProvidesLine(char *raw, char *temp);
  12013. +
  12014. +int isGenericFieldType(char * type, char * line)
  12015. +{
  12016. + if(!strncmp(line, type, strlen(type)))
  12017. + return 1;
  12018. + return 0;
  12019. +}
  12020. +
  12021. +char * parseGenericFieldType(char * type, char * raw)
  12022. +{
  12023. + char * field_value = raw + (strlen(type) + 1);
  12024. + return trim_alloc(field_value);
  12025. +}
  12026. +
  12027. +void parseStatus(pkg_t *pkg, char * raw)
  12028. +{
  12029. + char sw_str[64], sf_str[64], ss_str[64];
  12030. +
  12031. + sscanf(raw, "Status: %s %s %s", sw_str, sf_str, ss_str);
  12032. + pkg->state_want = pkg_state_want_from_str(sw_str);
  12033. + pkg->state_flag = pkg_state_flag_from_str(sf_str);
  12034. + pkg->state_status = pkg_state_status_from_str(ss_str);
  12035. +}
  12036. +
  12037. +char ** parseDependsString(char * raw, int * depends_count)
  12038. +{
  12039. + char ** depends = NULL;
  12040. + int line_count = 0;
  12041. + char buff[2048], * dest;
  12042. +
  12043. + while(raw && *raw && !isspace(*raw)) {
  12044. + raw++;
  12045. + }
  12046. +
  12047. + if(line_is_blank(raw)){
  12048. + *depends_count = line_count;
  12049. + return NULL;
  12050. + }
  12051. + while(raw && *raw){
  12052. + depends = (char **)realloc(depends, sizeof(char *) * (line_count + 1));
  12053. +
  12054. + while(isspace(*raw)) raw++;
  12055. +
  12056. + dest = buff;
  12057. + while((*raw != ',') && *raw)
  12058. + *dest++ = *raw++;
  12059. +
  12060. + *dest = '\0';
  12061. + depends[line_count] = trim_alloc(buff);
  12062. + if(depends[line_count] ==NULL)
  12063. + return NULL;
  12064. + line_count++;
  12065. + if(*raw == ',')
  12066. + raw++;
  12067. + }
  12068. + *depends_count = line_count;
  12069. + return depends;
  12070. +}
  12071. +
  12072. +void parseConffiles(pkg_t * pkg, char * raw)
  12073. +{
  12074. + char file_name[1048], md5sum[1048]; /* please tell me there aren't any longer that 1k */
  12075. +
  12076. + if(!strncmp(raw, "Conffiles:", 10))
  12077. + raw += strlen("Conffiles:");
  12078. +
  12079. + while(*raw && (sscanf(raw, "%s%s", file_name, md5sum) == 2)){
  12080. + conffile_list_append(&pkg->conffiles, file_name, md5sum);
  12081. + /* fprintf(stderr, "%s %s ", file_name, md5sum);*/
  12082. + while (*raw && isspace(*raw)) {
  12083. + raw++;
  12084. + }
  12085. + raw += strlen(file_name);
  12086. + while (*raw && isspace(*raw)) {
  12087. + raw++;
  12088. + }
  12089. + raw += strlen(md5sum);
  12090. + }
  12091. +}
  12092. +
  12093. +int parseVersion(pkg_t *pkg, char *raw)
  12094. +{
  12095. + char *colon, *eepochcolon;
  12096. +#ifdef USE_DEBVERSION
  12097. + char *hyphen;
  12098. +#endif
  12099. + unsigned long epoch;
  12100. +
  12101. + if (!*raw) {
  12102. + fprintf(stderr, "%s: ERROR: version string is empty", __FUNCTION__);
  12103. + return EINVAL;
  12104. + }
  12105. +
  12106. + if (strncmp(raw, "Version:", 8) == 0) {
  12107. + raw += 8;
  12108. + }
  12109. + while (*raw && isspace(*raw)) {
  12110. + raw++;
  12111. + }
  12112. +
  12113. + colon= strchr(raw,':');
  12114. + if (colon) {
  12115. + epoch= strtoul(raw,&eepochcolon,10);
  12116. + if (colon != eepochcolon) {
  12117. + fprintf(stderr, "%s: ERROR: epoch in version is not number", __FUNCTION__);
  12118. + return EINVAL;
  12119. + }
  12120. + if (!*++colon) {
  12121. + fprintf(stderr, "%s: ERROR: nothing after colon in version number", __FUNCTION__);
  12122. + return EINVAL;
  12123. + }
  12124. + raw= colon;
  12125. + pkg->epoch= epoch;
  12126. + } else {
  12127. + pkg->epoch= 0;
  12128. + }
  12129. +
  12130. + pkg->revision = (char *)"";
  12131. + pkg->familiar_revision = (char *)"";
  12132. +
  12133. + pkg->version= malloc(strlen(raw)+1);
  12134. + if ( pkg->version == NULL ) {
  12135. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12136. + return ENOMEM;
  12137. + }
  12138. + strcpy(pkg->version, raw);
  12139. +
  12140. +#ifdef USE_DEBVERSION
  12141. + hyphen= strrchr(pkg->version,'-');
  12142. +
  12143. + if (hyphen) {
  12144. + *hyphen++= 0;
  12145. + if (strncmp("fam", hyphen, 3) == 0) {
  12146. + pkg->familiar_revision=hyphen+3;
  12147. + hyphen= strrchr(pkg->version,'-');
  12148. + if (hyphen) {
  12149. + *hyphen++= 0;
  12150. + pkg->revision = hyphen;
  12151. + }
  12152. + } else {
  12153. + pkg->revision = hyphen;
  12154. + }
  12155. + }
  12156. +#endif
  12157. +
  12158. +/*
  12159. + fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n",
  12160. + pkg->epoch,
  12161. + pkg->version,
  12162. + pkg->revision,
  12163. + pkg->familiar_revision);
  12164. +*/
  12165. +
  12166. + return 0;
  12167. +}
  12168. +
  12169. +
  12170. +/* This code is needed to insert in first position the keyword for the aligning bug */
  12171. +
  12172. +int alterProvidesLine(char *raw, char *temp)
  12173. +{
  12174. +
  12175. +
  12176. + if (!*raw) {
  12177. + fprintf(stderr, "%s: ERROR: Provides string is empty", __FUNCTION__);
  12178. + return -EINVAL;
  12179. + }
  12180. +
  12181. + if ( temp == NULL ) {
  12182. + fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
  12183. + return -ENOMEM;
  12184. + }
  12185. +
  12186. + if (strncmp(raw, "Provides:", 9) == 0) {
  12187. + raw += 9;
  12188. + }
  12189. + while (*raw && isspace(*raw)) {
  12190. + raw++;
  12191. + }
  12192. +
  12193. + snprintf ( temp, 35, "Provides: ipkg_internal_use_only, "); /* First part of the line */
  12194. + while (*raw) {
  12195. + strncat( temp, raw++, 1);
  12196. + }
  12197. + return 0;
  12198. +
  12199. +}
  12200. +
  12201. +/* Some random thoughts from Carl:
  12202. +
  12203. + This function could be considerably simplified if we just kept
  12204. + an array of all the generic string-valued field names, and looped
  12205. + through those looking for a match. Also, these fields could perhaps
  12206. + be stored in the package as an array as well, (or, probably better,
  12207. + as an nv_pair_list_t).
  12208. +
  12209. + Fields which require special parsing or storage, (such as Depends:
  12210. + and Status:) could be handled as they are now.
  12211. +*/
  12212. +/* XXX: FEATURE: The Suggests: field needs to be changed from a string
  12213. + to a dependency list. And, since we already have
  12214. + Depends/Pre-Depends and need to add Conflicts, Recommends, and
  12215. + Enhances, perhaps we could generalize all of these and save some
  12216. + code duplication.
  12217. +*/
  12218. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
  12219. +{
  12220. + int reading_conffiles, reading_description;
  12221. + int pkg_false_provides=1;
  12222. + char ** lines;
  12223. + char * provide=NULL;
  12224. +
  12225. + pkg->src = src;
  12226. + pkg->dest = dest;
  12227. +
  12228. + reading_conffiles = reading_description = 0;
  12229. +
  12230. + for (lines = *raw; *lines; lines++) {
  12231. + /* fprintf(stderr, "PARSING %s\n", *lines);*/
  12232. + if(isGenericFieldType((char *)"Package:", *lines))
  12233. + pkg->name = parseGenericFieldType((char *)"Package", *lines);
  12234. + else if(isGenericFieldType((char *)"Architecture:", *lines))
  12235. + pkg->architecture = parseGenericFieldType((char *)"Architecture", *lines);
  12236. + else if(isGenericFieldType((char *)"Filename:", *lines))
  12237. + pkg->filename = parseGenericFieldType((char *)"Filename", *lines);
  12238. + else if(isGenericFieldType((char *)"Section:", *lines))
  12239. + pkg->section = parseGenericFieldType((char *)"Section", *lines);
  12240. + else if(isGenericFieldType((char *)"MD5sum:", *lines))
  12241. + pkg->md5sum = parseGenericFieldType((char *)"MD5sum", *lines);
  12242. + /* The old ipkg wrote out status files with the wrong case for MD5sum,
  12243. + let's parse it either way */
  12244. + else if(isGenericFieldType((char *)"MD5Sum:", *lines))
  12245. + pkg->md5sum = parseGenericFieldType((char *)"MD5Sum", *lines);
  12246. + else if(isGenericFieldType((char *)"Size:", *lines))
  12247. + pkg->size = parseGenericFieldType((char *)"Size", *lines);
  12248. + else if(isGenericFieldType((char *)"Source:", *lines))
  12249. + pkg->source = parseGenericFieldType((char *)"Source", *lines);
  12250. + else if(isGenericFieldType((char *)"Installed-Size:", *lines))
  12251. + pkg->installed_size = parseGenericFieldType((char *)"Installed-Size", *lines);
  12252. + else if(isGenericFieldType((char *)"Installed-Time:", *lines)) {
  12253. + char *time_str = parseGenericFieldType((char *)"Installed-Time", *lines);
  12254. + pkg->installed_time = strtoul(time_str, NULL, 0);
  12255. + } else if(isGenericFieldType((char *)"Priority:", *lines))
  12256. + pkg->priority = parseGenericFieldType((char *)"Priority", *lines);
  12257. + else if(isGenericFieldType((char *)"Essential:", *lines)) {
  12258. + char *essential_value;
  12259. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12260. + if (strcmp(essential_value, "yes") == 0) {
  12261. + pkg->essential = 1;
  12262. + }
  12263. + free(essential_value);
  12264. + }
  12265. + else if(isGenericFieldType((char *)"Status", *lines))
  12266. + parseStatus(pkg, *lines);
  12267. + else if(isGenericFieldType((char *)"Version", *lines))
  12268. + parseVersion(pkg, *lines);
  12269. + else if(isGenericFieldType((char *)"Maintainer", *lines))
  12270. + pkg->maintainer = parseGenericFieldType((char *)"Maintainer", *lines);
  12271. + else if(isGenericFieldType((char *)"Conffiles", *lines)){
  12272. + parseConffiles(pkg, *lines);
  12273. + reading_conffiles = 1;
  12274. + }
  12275. + else if(isGenericFieldType((char *)"Description", *lines)) {
  12276. + pkg->description = parseGenericFieldType((char *)"Description", *lines);
  12277. + reading_conffiles = 0;
  12278. + reading_description = 1;
  12279. + }
  12280. +
  12281. + else if(isGenericFieldType((char *)"Provides", *lines)){
  12282. +/* Here we add the internal_use to align the off by one problem between provides_str and provides */
  12283. + provide = (char * ) malloc(strlen(*lines)+ 35 ); /* Preparing the space for the new ipkg_internal_use_only */
  12284. + if ( alterProvidesLine(*lines,provide) ){
  12285. + return EINVAL;
  12286. + }
  12287. + pkg->provides_str = parseDependsString( provide, &pkg->provides_count);
  12288. +/* Let's try to hack a bit here.
  12289. + The idea is that if a package has no Provides, we would add one generic, to permit the check of dependencies
  12290. + in alot of other places. We will remove it before writing down the status database */
  12291. + pkg_false_provides=0;
  12292. + free(provide);
  12293. + }
  12294. +
  12295. + else if(isGenericFieldType((char *)"Depends", *lines))
  12296. + pkg->depends_str = parseDependsString(*lines, &pkg->depends_count);
  12297. + else if(isGenericFieldType((char *)"Pre-Depends", *lines))
  12298. + pkg->pre_depends_str = parseDependsString(*lines, &pkg->pre_depends_count);
  12299. + else if(isGenericFieldType((char *)"Recommends", *lines))
  12300. + pkg->recommends_str = parseDependsString(*lines, &pkg->recommends_count);
  12301. + else if(isGenericFieldType((char *)"Suggests", *lines))
  12302. + pkg->suggests_str = parseDependsString(*lines, &pkg->suggests_count);
  12303. + /* Abhaya: support for conflicts */
  12304. + else if(isGenericFieldType((char *)"Conflicts", *lines))
  12305. + pkg->conflicts_str = parseDependsString(*lines, &pkg->conflicts_count);
  12306. + else if(isGenericFieldType((char *)"Replaces", *lines))
  12307. + pkg->replaces_str = parseDependsString(*lines, &pkg->replaces_count);
  12308. + else if(line_is_blank(*lines)) {
  12309. + lines++;
  12310. + break;
  12311. + }
  12312. + else if(**lines == ' '){
  12313. + if(reading_description) {
  12314. + /* we already know it's not blank, so the rest of description */
  12315. + pkg->description = realloc(pkg->description,
  12316. + strlen(pkg->description)
  12317. + + 1 + strlen(*lines) + 1);
  12318. + strcat(pkg->description, "\n");
  12319. + strcat(pkg->description, (*lines));
  12320. + }
  12321. + else if(reading_conffiles)
  12322. + parseConffiles(pkg, *lines);
  12323. + }
  12324. + }
  12325. + *raw = lines;
  12326. +/* If the ipk has not a Provides line, we insert our false line */
  12327. + if ( pkg_false_provides==1)
  12328. + pkg->provides_str = parseDependsString ((char *)"Provides: ipkg_internal_use_only ", &pkg->provides_count);
  12329. +
  12330. + if (pkg->name) {
  12331. + return 0;
  12332. + } else {
  12333. + return EINVAL;
  12334. + }
  12335. +}
  12336. +
  12337. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw)
  12338. +{
  12339. + char ** lines;
  12340. +
  12341. + for (lines = *raw; *lines; lines++) {
  12342. + if(isGenericFieldType((char *)"Essential:", *lines)) {
  12343. + char *essential_value;
  12344. + essential_value = parseGenericFieldType((char *)"Essential", *lines);
  12345. + if (strcmp(essential_value, "yes") == 0) {
  12346. + pkg->essential = 1;
  12347. + }
  12348. + free(essential_value);
  12349. + }
  12350. + }
  12351. + *raw = lines;
  12352. +
  12353. + return 0;
  12354. +}
  12355. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_parse.h busybox-1.24.1/archival/libipkg/pkg_parse.h
  12356. --- busybox-1.24.1.orig/archival/libipkg/pkg_parse.h 1970-01-01 01:00:00.000000000 +0100
  12357. +++ busybox-1.24.1/archival/libipkg/pkg_parse.h 2015-10-31 19:00:22.000000000 +0100
  12358. @@ -0,0 +1,31 @@
  12359. +/* pkg_parse.h - the itsy package management system
  12360. +
  12361. + Steven M. Ayer
  12362. +
  12363. + Copyright (C) 2002 Compaq Computer Corporation
  12364. +
  12365. + This program is free software; you can redistribute it and/or
  12366. + modify it under the terms of the GNU General Public License as
  12367. + published by the Free Software Foundation; either version 2, or (at
  12368. + your option) any later version.
  12369. +
  12370. + This program is distributed in the hope that it will be useful, but
  12371. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12372. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12373. + General Public License for more details.
  12374. +*/
  12375. +
  12376. +#ifndef PKG_PARSE_H
  12377. +#define PKG_PARSE_H
  12378. +
  12379. +int isGenericFieldType(char * type, char * line);
  12380. +char * parseGenericFieldType(char * type, char * raw);
  12381. +void parseStatus(pkg_t *pkg, char * raw);
  12382. +int parseVersion(pkg_t *pkg, char *raw);
  12383. +char ** parseDependsString(char * raw, int * depends_count);
  12384. +int parseVersion(pkg_t *pkg, char *raw);
  12385. +void parseConffiles(pkg_t * pkg, char * raw);
  12386. +int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest);
  12387. +int pkg_valorize_other_field(pkg_t *pkg, char ***raw);
  12388. +
  12389. +#endif
  12390. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_src.c busybox-1.24.1/archival/libipkg/pkg_src.c
  12391. --- busybox-1.24.1.orig/archival/libipkg/pkg_src.c 1970-01-01 01:00:00.000000000 +0100
  12392. +++ busybox-1.24.1/archival/libipkg/pkg_src.c 2015-10-31 19:00:22.000000000 +0100
  12393. @@ -0,0 +1,43 @@
  12394. +/* pkg_src.c - the itsy package management system
  12395. +
  12396. + Carl D. Worth
  12397. +
  12398. + Copyright (C) 2001 University of Southern California
  12399. +
  12400. + This program is free software; you can redistribute it and/or
  12401. + modify it under the terms of the GNU General Public License as
  12402. + published by the Free Software Foundation; either version 2, or (at
  12403. + your option) any later version.
  12404. +
  12405. + This program is distributed in the hope that it will be useful, but
  12406. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12407. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12408. + General Public License for more details.
  12409. +*/
  12410. +
  12411. +#include "ipkg.h"
  12412. +
  12413. +#include "pkg_src.h"
  12414. +#include "str_util.h"
  12415. +
  12416. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip)
  12417. +{
  12418. + src->gzip = gzip;
  12419. + src->name = str_dup_safe (name);
  12420. + src->value = str_dup_safe (base_url);
  12421. + if (extra_data)
  12422. + src->extra_data = str_dup_safe (extra_data);
  12423. + else
  12424. + src->extra_data = NULL;
  12425. + return 0;
  12426. +}
  12427. +
  12428. +void pkg_src_deinit(pkg_src_t *src)
  12429. +{
  12430. + free (src->name);
  12431. + free (src->value);
  12432. + if (src->extra_data)
  12433. + free (src->extra_data);
  12434. +}
  12435. +
  12436. +
  12437. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_src.h busybox-1.24.1/archival/libipkg/pkg_src.h
  12438. --- busybox-1.24.1.orig/archival/libipkg/pkg_src.h 1970-01-01 01:00:00.000000000 +0100
  12439. +++ busybox-1.24.1/archival/libipkg/pkg_src.h 2015-10-31 19:00:22.000000000 +0100
  12440. @@ -0,0 +1,34 @@
  12441. +/* pkg_src.h - the itsy package management system
  12442. +
  12443. + Carl D. Worth
  12444. +
  12445. + Copyright (C) 2001 University of Southern California
  12446. +
  12447. + This program is free software; you can redistribute it and/or
  12448. + modify it under the terms of the GNU General Public License as
  12449. + published by the Free Software Foundation; either version 2, or (at
  12450. + your option) any later version.
  12451. +
  12452. + This program is distributed in the hope that it will be useful, but
  12453. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12454. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12455. + General Public License for more details.
  12456. +*/
  12457. +
  12458. +#ifndef PKG_SRC_H
  12459. +#define PKG_SRC_H
  12460. +
  12461. +#include "nv_pair.h"
  12462. +
  12463. +typedef struct
  12464. +{
  12465. + char *name;
  12466. + char *value;
  12467. + char *extra_data;
  12468. + int gzip;
  12469. +} pkg_src_t;
  12470. +
  12471. +int pkg_src_init(pkg_src_t *src, const char *name, const char *base_url, const char *extra_data, int gzip);
  12472. +void pkg_src_deinit(pkg_src_t *src);
  12473. +
  12474. +#endif
  12475. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_src_list.c busybox-1.24.1/archival/libipkg/pkg_src_list.c
  12476. --- busybox-1.24.1.orig/archival/libipkg/pkg_src_list.c 1970-01-01 01:00:00.000000000 +0100
  12477. +++ busybox-1.24.1/archival/libipkg/pkg_src_list.c 2015-10-31 19:00:22.000000000 +0100
  12478. @@ -0,0 +1,75 @@
  12479. +/* pkg_src_list.c - the itsy package management system
  12480. +
  12481. + Carl D. Worth
  12482. +
  12483. + Copyright (C) 2001 University of Southern California
  12484. +
  12485. + This program is free software; you can redistribute it and/or
  12486. + modify it under the terms of the GNU General Public License as
  12487. + published by the Free Software Foundation; either version 2, or (at
  12488. + your option) any later version.
  12489. +
  12490. + This program is distributed in the hope that it will be useful, but
  12491. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12492. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12493. + General Public License for more details.
  12494. +*/
  12495. +
  12496. +#include "ipkg.h"
  12497. +
  12498. +#include "pkg_src_list.h"
  12499. +#include "void_list.h"
  12500. +
  12501. +int pkg_src_list_init(pkg_src_list_t *list)
  12502. +{
  12503. + return void_list_init((void_list_t *) list);
  12504. +}
  12505. +
  12506. +void pkg_src_list_deinit(pkg_src_list_t *list)
  12507. +{
  12508. + pkg_src_list_elt_t *iter;
  12509. + pkg_src_t *pkg_src;
  12510. +
  12511. + for (iter = list->head; iter; iter = iter->next) {
  12512. + pkg_src = iter->data;
  12513. + pkg_src_deinit(pkg_src);
  12514. +
  12515. + /* malloced in pkg_src_list_append */
  12516. + free(pkg_src);
  12517. + iter->data = NULL;
  12518. + }
  12519. + void_list_deinit((void_list_t *) list);
  12520. +}
  12521. +
  12522. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
  12523. + const char *name, const char *base_url, const char *extra_data,
  12524. + int gzip)
  12525. +{
  12526. + int err;
  12527. +
  12528. + /* freed in pkg_src_list_deinit */
  12529. + pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
  12530. +
  12531. + if (pkg_src == NULL) {
  12532. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12533. + return NULL;
  12534. + }
  12535. + pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
  12536. +
  12537. + err = void_list_append((void_list_t *) list, pkg_src);
  12538. + if (err) {
  12539. + return NULL;
  12540. + }
  12541. +
  12542. + return pkg_src;
  12543. +}
  12544. +
  12545. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
  12546. +{
  12547. + return void_list_push((void_list_t *) list, data);
  12548. +}
  12549. +
  12550. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
  12551. +{
  12552. + return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
  12553. +}
  12554. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_src_list.h busybox-1.24.1/archival/libipkg/pkg_src_list.h
  12555. --- busybox-1.24.1.orig/archival/libipkg/pkg_src_list.h 1970-01-01 01:00:00.000000000 +0100
  12556. +++ busybox-1.24.1/archival/libipkg/pkg_src_list.h 2015-10-31 19:00:22.000000000 +0100
  12557. @@ -0,0 +1,57 @@
  12558. +/* pkg_src_list.h - the itsy package management system
  12559. +
  12560. + Carl D. Worth
  12561. +
  12562. + Copyright (C) 2001 University of Southern California
  12563. +
  12564. + This program is free software; you can redistribute it and/or
  12565. + modify it under the terms of the GNU General Public License as
  12566. + published by the Free Software Foundation; either version 2, or (at
  12567. + your option) any later version.
  12568. +
  12569. + This program is distributed in the hope that it will be useful, but
  12570. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12571. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12572. + General Public License for more details.
  12573. +*/
  12574. +
  12575. +#ifndef PKG_SRC_LIST_H
  12576. +#define PKG_SRC_LIST_H
  12577. +
  12578. +#include "pkg_src.h"
  12579. +
  12580. +typedef struct pkg_src_list_elt pkg_src_list_elt_t;
  12581. +struct pkg_src_list_elt
  12582. +{
  12583. + pkg_src_list_elt_t *next;
  12584. + pkg_src_t *data;
  12585. +};
  12586. +
  12587. +typedef struct pkg_src_list pkg_src_list_t;
  12588. +struct pkg_src_list
  12589. +{
  12590. + pkg_src_list_elt_t pre_head;
  12591. + pkg_src_list_elt_t *head;
  12592. + pkg_src_list_elt_t *tail;
  12593. +};
  12594. +
  12595. +static inline int pkg_src_list_empty(pkg_src_list_t *list)
  12596. +{
  12597. + if (list->head == NULL)
  12598. + return 1;
  12599. + else
  12600. + return 0;
  12601. +}
  12602. +
  12603. +int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
  12604. +void pkg_src_list_elt_deinit(pkg_src_list_elt_t *elt);
  12605. +
  12606. +int pkg_src_list_init(pkg_src_list_t *list);
  12607. +void pkg_src_list_deinit(pkg_src_list_t *list);
  12608. +
  12609. +pkg_src_t *pkg_src_list_append(pkg_src_list_t *list, const char *name, const char *root_dir, const char *extra_data, int gzip);
  12610. +int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data);
  12611. +pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list);
  12612. +
  12613. +#endif
  12614. +
  12615. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_vec.c busybox-1.24.1/archival/libipkg/pkg_vec.c
  12616. --- busybox-1.24.1.orig/archival/libipkg/pkg_vec.c 1970-01-01 01:00:00.000000000 +0100
  12617. +++ busybox-1.24.1/archival/libipkg/pkg_vec.c 2015-10-31 19:00:22.000000000 +0100
  12618. @@ -0,0 +1,231 @@
  12619. +/* pkg_vec.c - the itsy package management system
  12620. +
  12621. + Steven M. Ayer
  12622. +
  12623. + Copyright (C) 2002 Compaq Computer Corporation
  12624. +
  12625. + This program is free software; you can redistribute it and/or
  12626. + modify it under the terms of the GNU General Public License as
  12627. + published by the Free Software Foundation; either version 2, or (at
  12628. + your option) any later version.
  12629. +
  12630. + This program is distributed in the hope that it will be useful, but
  12631. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12632. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12633. + General Public License for more details.
  12634. +*/
  12635. +
  12636. +#include <stdlib.h>
  12637. +#include <fnmatch.h>
  12638. +#include "libbb.h"
  12639. +#include "xregex.h"
  12640. +#include "ipkg.h"
  12641. +#include "pkg.h"
  12642. +
  12643. +pkg_vec_t * pkg_vec_alloc(void)
  12644. +{
  12645. + pkg_vec_t * vec = (pkg_vec_t *)malloc(sizeof(pkg_vec_t));
  12646. + if (!vec) {
  12647. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12648. + return NULL;
  12649. + }
  12650. + vec->pkgs = NULL;
  12651. + vec->len = 0;
  12652. +
  12653. + return vec;
  12654. +}
  12655. +
  12656. +void pkg_vec_free(pkg_vec_t *vec)
  12657. +{
  12658. + free(vec->pkgs);
  12659. + free(vec);
  12660. +}
  12661. +
  12662. +/*
  12663. + * assumption: all names in a vector are identical
  12664. + * assumption: all version strings are trimmed,
  12665. + * so identical versions have identical version strings,
  12666. + * implying identical packages; let's marry these
  12667. + */
  12668. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,ipkg_conf_t *conf)
  12669. +{
  12670. + int i;
  12671. + int found = 0;
  12672. +
  12673. + /* look for a duplicate pkg by name, version, and architecture */
  12674. + for (i = 0; i < vec->len; i++){
  12675. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n",
  12676. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture,
  12677. + vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture );
  12678. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12679. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12680. + && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) {
  12681. + found = 1;
  12682. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n",
  12683. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12684. + break;
  12685. + }
  12686. + }
  12687. +
  12688. + /* we didn't find one, add it */
  12689. + if (!found){
  12690. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n",
  12691. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12692. +
  12693. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12694. + vec->pkgs[vec->len] = pkg;
  12695. + vec->len++;
  12696. + return pkg;
  12697. + }
  12698. + /* update the one that we have */
  12699. + else {
  12700. + ipkg_message(conf, IPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s",
  12701. + __FUNCTION__, pkg->name, pkg->version, pkg->architecture);
  12702. + if (set_status) {
  12703. + /* this is from the status file, so need to merge with existing database */
  12704. + ipkg_message(conf, IPKG_DEBUG2, " with set_status\n");
  12705. + pkg_merge(vec->pkgs[i], pkg, set_status);
  12706. + /* XXX: CLEANUP: It's not so polite to free something here
  12707. + that was passed in from above. */
  12708. + pkg_deinit(pkg);
  12709. + free(pkg);
  12710. + } else {
  12711. + ipkg_message(conf, IPKG_DEBUG2, " WITHOUT set_status\n");
  12712. + /* just overwrite the old one */
  12713. + pkg_deinit(vec->pkgs[i]);
  12714. + free(vec->pkgs[i]);
  12715. + vec->pkgs[i] = pkg;
  12716. + }
  12717. + return vec->pkgs[i];
  12718. + }
  12719. +}
  12720. +
  12721. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
  12722. +{
  12723. + int i;
  12724. + int found = 0;
  12725. +
  12726. + /* look for a duplicate pkg by name, version, and architecture */
  12727. + for (i = 0; i < vec->len; i++)
  12728. + if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12729. + && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
  12730. + && (strcmp(pkg->architecture, vec->pkgs[i]->name) == 0)) {
  12731. + found = 1;
  12732. + break;
  12733. + }
  12734. +
  12735. + /* we didn't find one, add it */
  12736. + if(!found){
  12737. + vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
  12738. + *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
  12739. + vec->len++;
  12740. + }
  12741. +}
  12742. +
  12743. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg)
  12744. +{
  12745. + int i;
  12746. + for (i = 0; i < vec->len; i++)
  12747. + if (vec->pkgs[i] == apkg)
  12748. + return 1;
  12749. + return 0;
  12750. +}
  12751. +
  12752. +typedef int (*compare_fcn_t)(const void *, const void *);
  12753. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *))
  12754. +{
  12755. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12756. +}
  12757. +
  12758. +int pkg_vec_clear_marks(pkg_vec_t *vec)
  12759. +{
  12760. + int npkgs = vec->len;
  12761. + int i;
  12762. + for (i = 0; i < npkgs; i++) {
  12763. + pkg_t *pkg = vec->pkgs[i];
  12764. + pkg->state_flag &= ~SF_MARKED;
  12765. + }
  12766. + return 0;
  12767. +}
  12768. +
  12769. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern)
  12770. +{
  12771. + int matching_count = 0;
  12772. + pkg_t **pkgs = vec->pkgs;
  12773. + int npkgs = vec->len;
  12774. + int i;
  12775. + for (i = 0; i < npkgs; i++) {
  12776. + pkg_t *pkg = pkgs[i];
  12777. + if (fnmatch(pattern, pkg->name, 0)==0) {
  12778. + pkg->state_flag |= SF_MARKED;
  12779. + matching_count++;
  12780. + }
  12781. + }
  12782. + return matching_count;
  12783. +}
  12784. +
  12785. +
  12786. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
  12787. +{
  12788. + abstract_pkg_vec_t * vec ;
  12789. + vec = (abstract_pkg_vec_t *)malloc(sizeof(abstract_pkg_vec_t));
  12790. + if (!vec) {
  12791. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  12792. + return NULL;
  12793. + }
  12794. + vec->pkgs = NULL;
  12795. + vec->len = 0;
  12796. +
  12797. + return vec;
  12798. +}
  12799. +
  12800. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
  12801. +{
  12802. + free(vec->pkgs);
  12803. + free(vec);
  12804. +}
  12805. +
  12806. +/*
  12807. + * assumption: all names in a vector are unique
  12808. + */
  12809. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg)
  12810. +{
  12811. + int i;
  12812. +
  12813. + /* look for a duplicate pkg by name */
  12814. + for(i = 0; i < vec->len; i++)
  12815. + if (strcmp(pkg->name, vec->pkgs[i]->name) == 0)
  12816. + break;
  12817. +
  12818. + /* we didn't find one, add it */
  12819. + if(i == vec->len){
  12820. + vec->pkgs =
  12821. + (abstract_pkg_t **)
  12822. + realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *));
  12823. + vec->pkgs[vec->len] = pkg;
  12824. + vec->len++;
  12825. + }
  12826. +}
  12827. +
  12828. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i)
  12829. +{
  12830. + if (vec->len > i)
  12831. + return vec->pkgs[i];
  12832. + else
  12833. + return NULL;
  12834. +}
  12835. +
  12836. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg)
  12837. +{
  12838. + int i;
  12839. + for (i = 0; i < vec->len; i++)
  12840. + if (vec->pkgs[i] == apkg)
  12841. + return 1;
  12842. + return 0;
  12843. +}
  12844. +
  12845. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *))
  12846. +{
  12847. + qsort(vec->pkgs, vec->len, sizeof(pkg_t *), (compare_fcn_t)compar);
  12848. +}
  12849. +
  12850. diff -Nur busybox-1.24.1.orig/archival/libipkg/pkg_vec.h busybox-1.24.1/archival/libipkg/pkg_vec.h
  12851. --- busybox-1.24.1.orig/archival/libipkg/pkg_vec.h 1970-01-01 01:00:00.000000000 +0100
  12852. +++ busybox-1.24.1/archival/libipkg/pkg_vec.h 2015-10-31 19:00:22.000000000 +0100
  12853. @@ -0,0 +1,62 @@
  12854. +/* pkg_vec.h - the itsy package management system
  12855. +
  12856. + Steven M. Ayer
  12857. +
  12858. + Copyright (C) 2002 Compaq Computer Corporation
  12859. +
  12860. + This program is free software; you can redistribute it and/or
  12861. + modify it under the terms of the GNU General Public License as
  12862. + published by the Free Software Foundation; either version 2, or (at
  12863. + your option) any later version.
  12864. +
  12865. + This program is distributed in the hope that it will be useful, but
  12866. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12867. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12868. + General Public License for more details.
  12869. +*/
  12870. +
  12871. +#ifndef PKG_VEC_H
  12872. +#define PKG_VEC_H
  12873. +
  12874. +typedef struct pkg pkg_t;
  12875. +typedef struct abstract_pkg abstract_pkg_t;
  12876. +
  12877. +struct pkg_vec
  12878. +{
  12879. + pkg_t **pkgs;
  12880. + int len;
  12881. +};
  12882. +typedef struct pkg_vec pkg_vec_t;
  12883. +
  12884. +struct abstract_pkg_vec
  12885. +{
  12886. + abstract_pkg_t **pkgs;
  12887. + int len;
  12888. +};
  12889. +typedef struct abstract_pkg_vec abstract_pkg_vec_t;
  12890. +
  12891. +
  12892. +pkg_vec_t * pkg_vec_alloc(void);
  12893. +void pkg_vec_free(pkg_vec_t *vec);
  12894. +void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg);
  12895. +
  12896. +void pkg_vec_add(pkg_vec_t *vec, pkg_t *pkg);
  12897. +/* pkg_vec_insert_merge: might munge pkg.
  12898. +* returns the pkg that is in the pkg graph */
  12899. +pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, ipkg_conf_t *conf);
  12900. +/* this one never munges pkg */
  12901. +void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg);
  12902. +int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg);
  12903. +void pkg_vec_sort(pkg_vec_t *vec, int (*compar)(pkg_t *, pkg_t *));
  12904. +
  12905. +int pkg_vec_clear_marks(pkg_vec_t *vec);
  12906. +int pkg_vec_mark_if_matches(pkg_vec_t *vec, const char *pattern);
  12907. +
  12908. +abstract_pkg_vec_t * abstract_pkg_vec_alloc(void);
  12909. +void abstract_pkg_vec_free(abstract_pkg_vec_t *vec);
  12910. +void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg);
  12911. +abstract_pkg_t * abstract_pkg_vec_get(abstract_pkg_vec_t *vec, int i);
  12912. +int abstract_pkg_vec_contains(abstract_pkg_vec_t *vec, abstract_pkg_t *apkg);
  12913. +void abstract_pkg_vec_sort(pkg_vec_t *vec, int (*compar)(abstract_pkg_t *, abstract_pkg_t *));
  12914. +#endif
  12915. +
  12916. diff -Nur busybox-1.24.1.orig/archival/libipkg/sprintf_alloc.h busybox-1.24.1/archival/libipkg/sprintf_alloc.h
  12917. --- busybox-1.24.1.orig/archival/libipkg/sprintf_alloc.h 1970-01-01 01:00:00.000000000 +0100
  12918. +++ busybox-1.24.1/archival/libipkg/sprintf_alloc.h 2015-10-31 19:00:22.000000000 +0100
  12919. @@ -0,0 +1,25 @@
  12920. +/* sprintf_alloca.c -- like sprintf with memory allocation
  12921. +
  12922. + Carl D. Worth
  12923. +
  12924. + Copyright (C) 2001 University of Southern California
  12925. +
  12926. + This program is free software; you can redistribute it and/or modify
  12927. + it under the terms of the GNU General Public License as published by
  12928. + the Free Software Foundation; either version 2, or (at your option)
  12929. + any later version.
  12930. +
  12931. + This program is distributed in the hope that it will be useful,
  12932. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  12933. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12934. + GNU General Public License for more details.
  12935. +*/
  12936. +
  12937. +#ifndef SPRINTF_ALLOC_H
  12938. +#define SPRINTF_ALLOC_H
  12939. +
  12940. +#include "libbb.h"
  12941. +
  12942. +#define sprintf_alloc(str, fmt, args...) *str = xasprintf(fmt, ## args)
  12943. +
  12944. +#endif
  12945. diff -Nur busybox-1.24.1.orig/archival/libipkg/str_list.c busybox-1.24.1/archival/libipkg/str_list.c
  12946. --- busybox-1.24.1.orig/archival/libipkg/str_list.c 1970-01-01 01:00:00.000000000 +0100
  12947. +++ busybox-1.24.1/archival/libipkg/str_list.c 2015-10-31 19:00:22.000000000 +0100
  12948. @@ -0,0 +1,76 @@
  12949. +/* str_list.c - the itsy package management system
  12950. +
  12951. + Carl D. Worth
  12952. +
  12953. + Copyright (C) 2001 University of Southern California
  12954. +
  12955. + This program is free software; you can redistribute it and/or
  12956. + modify it under the terms of the GNU General Public License as
  12957. + published by the Free Software Foundation; either version 2, or (at
  12958. + your option) any later version.
  12959. +
  12960. + This program is distributed in the hope that it will be useful, but
  12961. + WITHOUT ANY WARRANTY; without even the implied warranty of
  12962. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12963. + General Public License for more details.
  12964. +*/
  12965. +
  12966. +#include "ipkg.h"
  12967. +
  12968. +#include "str_list.h"
  12969. +
  12970. +int str_list_elt_init(str_list_elt_t *elt, char *data)
  12971. +{
  12972. + return void_list_elt_init((void_list_elt_t *) elt, data);
  12973. +}
  12974. +
  12975. +void str_list_elt_deinit(str_list_elt_t *elt)
  12976. +{
  12977. + void_list_elt_deinit((void_list_elt_t *) elt);
  12978. +}
  12979. +
  12980. +str_list_t *str_list_alloc(void)
  12981. +{
  12982. + str_list_t *list = (str_list_t *)malloc(sizeof(str_list_t));
  12983. + if (list)
  12984. + str_list_init(list);
  12985. + return list;
  12986. +}
  12987. +
  12988. +int str_list_init(str_list_t *list)
  12989. +{
  12990. + return void_list_init((void_list_t *) list);
  12991. +}
  12992. +
  12993. +void str_list_deinit(str_list_t *list)
  12994. +{
  12995. + void_list_deinit((void_list_t *) list);
  12996. +}
  12997. +
  12998. +int str_list_append(str_list_t *list, char *data)
  12999. +{
  13000. + return void_list_append((void_list_t *) list, data);
  13001. +}
  13002. +
  13003. +int str_list_push(str_list_t *list, char *data)
  13004. +{
  13005. + return void_list_push((void_list_t *) list, data);
  13006. +}
  13007. +
  13008. +str_list_elt_t *str_list_pop(str_list_t *list)
  13009. +{
  13010. + return (str_list_elt_t *) void_list_pop((void_list_t *) list);
  13011. +}
  13012. +
  13013. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
  13014. +{
  13015. + return (str_list_elt_t *) void_list_remove((void_list_t *) list,
  13016. + (void_list_elt_t **) iter);
  13017. +}
  13018. +
  13019. +char *str_list_remove_elt(str_list_t *list, const char *target_str)
  13020. +{
  13021. + return (char *)void_list_remove_elt((void_list_t *) list,
  13022. + (void *)target_str,
  13023. + (void_list_cmp_t)strcmp);
  13024. +}
  13025. diff -Nur busybox-1.24.1.orig/archival/libipkg/str_list.h busybox-1.24.1/archival/libipkg/str_list.h
  13026. --- busybox-1.24.1.orig/archival/libipkg/str_list.h 1970-01-01 01:00:00.000000000 +0100
  13027. +++ busybox-1.24.1/archival/libipkg/str_list.h 2015-10-31 19:00:22.000000000 +0100
  13028. @@ -0,0 +1,51 @@
  13029. +/* str_list.h - the itsy package management system
  13030. +
  13031. + Carl D. Worth
  13032. +
  13033. + Copyright (C) 2001 University of Southern California
  13034. +
  13035. + This program is free software; you can redistribute it and/or
  13036. + modify it under the terms of the GNU General Public License as
  13037. + published by the Free Software Foundation; either version 2, or (at
  13038. + your option) any later version.
  13039. +
  13040. + This program is distributed in the hope that it will be useful, but
  13041. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13042. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13043. + General Public License for more details.
  13044. +*/
  13045. +
  13046. +#ifndef STR_LIST_H
  13047. +#define STR_LIST_H
  13048. +
  13049. +#include "void_list.h"
  13050. +
  13051. +typedef struct str_list_elt str_list_elt_t;
  13052. +struct str_list_elt
  13053. +{
  13054. + str_list_elt_t *next;
  13055. + char *data;
  13056. +};
  13057. +
  13058. +typedef struct xstr_list str_list_t;
  13059. +struct xstr_list
  13060. +{
  13061. + str_list_elt_t pre_head;
  13062. + str_list_elt_t *head;
  13063. + str_list_elt_t *tail;
  13064. +};
  13065. +
  13066. +int str_list_elt_init(str_list_elt_t *elt, char *data);
  13067. +void str_list_elt_deinit(str_list_elt_t *elt);
  13068. +
  13069. +str_list_t *str_list_alloc(void);
  13070. +int str_list_init(str_list_t *list);
  13071. +void str_list_deinit(str_list_t *list);
  13072. +
  13073. +int str_list_append(str_list_t *list, char *data);
  13074. +int str_list_push(str_list_t *list, char *data);
  13075. +str_list_elt_t *str_list_pop(str_list_t *list);
  13076. +str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
  13077. +char *str_list_remove_elt(str_list_t *list, const char *target_str);
  13078. +
  13079. +#endif
  13080. diff -Nur busybox-1.24.1.orig/archival/libipkg/str_util.c busybox-1.24.1/archival/libipkg/str_util.c
  13081. --- busybox-1.24.1.orig/archival/libipkg/str_util.c 1970-01-01 01:00:00.000000000 +0100
  13082. +++ busybox-1.24.1/archival/libipkg/str_util.c 2015-10-31 19:00:22.000000000 +0100
  13083. @@ -0,0 +1,69 @@
  13084. +/* str_utils.c - the itsy package management system
  13085. +
  13086. + Carl D. Worth
  13087. +
  13088. + Copyright (C) 2001 University of Southern California
  13089. +
  13090. + This program is free software; you can redistribute it and/or
  13091. + modify it under the terms of the GNU General Public License as
  13092. + published by the Free Software Foundation; either version 2, or (at
  13093. + your option) any later version.
  13094. +
  13095. + This program is distributed in the hope that it will be useful, but
  13096. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13097. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13098. + General Public License for more details.
  13099. +*/
  13100. +
  13101. +#include "ipkg.h"
  13102. +
  13103. +int str_starts_with(const char *str, const char *prefix);
  13104. +int str_ends_with(const char *str, const char *suffix);
  13105. +int str_chomp(char *str);
  13106. +int str_toupper(char *str);
  13107. +char *str_dup_safe(const char *str);
  13108. +
  13109. +int str_starts_with(const char *str, const char *prefix)
  13110. +{
  13111. + return (strncmp(str, prefix, strlen(prefix)) == 0);
  13112. +}
  13113. +
  13114. +int str_ends_with(const char *str, const char *suffix)
  13115. +{
  13116. + int suffix_len;
  13117. + int str_len;
  13118. +
  13119. + str_len = strlen(str);
  13120. + suffix_len = strlen(suffix);
  13121. +
  13122. + if (str_len < suffix_len) {
  13123. + return 0;
  13124. + }
  13125. +
  13126. + return (strcmp(str + str_len - suffix_len, suffix) == 0);
  13127. +}
  13128. +
  13129. +int str_chomp(char *str)
  13130. +{
  13131. + if (str[strlen(str) - 1] == '\n') {
  13132. + str[strlen(str) - 1] = '\0';
  13133. + return 1;
  13134. + }
  13135. + return 0;
  13136. +}
  13137. +
  13138. +int str_toupper(char *str)
  13139. +{
  13140. + while (*str) {
  13141. + *str = toupper(*str);
  13142. + str++;
  13143. + }
  13144. +
  13145. + return 0;
  13146. +}
  13147. +
  13148. +char *str_dup_safe(const char *str)
  13149. +{
  13150. + return str ? strdup(str) : NULL;
  13151. +}
  13152. +
  13153. diff -Nur busybox-1.24.1.orig/archival/libipkg/str_util.h busybox-1.24.1/archival/libipkg/str_util.h
  13154. --- busybox-1.24.1.orig/archival/libipkg/str_util.h 1970-01-01 01:00:00.000000000 +0100
  13155. +++ busybox-1.24.1/archival/libipkg/str_util.h 2015-10-31 19:00:22.000000000 +0100
  13156. @@ -0,0 +1,27 @@
  13157. +/* str_utils.h - the itsy package management system
  13158. +
  13159. + Carl D. Worth
  13160. +
  13161. + Copyright (C) 2001 University of Southern California
  13162. +
  13163. + This program is free software; you can redistribute it and/or
  13164. + modify it under the terms of the GNU General Public License as
  13165. + published by the Free Software Foundation; either version 2, or (at
  13166. + your option) any later version.
  13167. +
  13168. + This program is distributed in the hope that it will be useful, but
  13169. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13170. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13171. + General Public License for more details.
  13172. +*/
  13173. +
  13174. +#ifndef STR_UTILS_H
  13175. +#define STR_UTILS_H
  13176. +
  13177. +int str_starts_with(const char *str, const char *prefix);
  13178. +int str_ends_with(const char *str, const char *suffix);
  13179. +int str_chomp(char *str);
  13180. +int str_toupper(char *str);
  13181. +char *str_dup_safe(const char *str);
  13182. +
  13183. +#endif
  13184. diff -Nur busybox-1.24.1.orig/archival/libipkg/user.c busybox-1.24.1/archival/libipkg/user.c
  13185. --- busybox-1.24.1.orig/archival/libipkg/user.c 1970-01-01 01:00:00.000000000 +0100
  13186. +++ busybox-1.24.1/archival/libipkg/user.c 2015-10-31 19:00:22.000000000 +0100
  13187. @@ -0,0 +1,49 @@
  13188. +/* user.c - the itsy package management system
  13189. +
  13190. + Jamey Hicks
  13191. +
  13192. + Copyright (C) 2002 Hewlett Packard Company
  13193. + Copyright (C) 2001 University of Southern California
  13194. +
  13195. + This program is free software; you can redistribute it and/or
  13196. + modify it under the terms of the GNU General Public License as
  13197. + published by the Free Software Foundation; either version 2, or (at
  13198. + your option) any later version.
  13199. +
  13200. + This program is distributed in the hope that it will be useful, but
  13201. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13202. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13203. + General Public License for more details.
  13204. +*/
  13205. +
  13206. +#include <stdio.h>
  13207. +#include <stdarg.h>
  13208. +#include "libbb.h"
  13209. +#include "file_util.h"
  13210. +#include "str_util.h"
  13211. +#include "libipkg.h"
  13212. +
  13213. +char *get_user_response(const char *format, ...);
  13214. +static char *question = NULL;
  13215. +static int question_len = 255;
  13216. +
  13217. +char *get_user_response(const char *format, ...)
  13218. +{
  13219. + int len = question_len;
  13220. + va_list ap;
  13221. + char *response;
  13222. + va_start(ap, format);
  13223. +
  13224. + do {
  13225. + if (question == NULL || len > question_len) {
  13226. + question = realloc(question, len + 1);
  13227. + question_len = len;
  13228. + }
  13229. + len = vsnprintf(question,question_len,format,ap);
  13230. + } while (len > question_len);
  13231. + response = strdup(ipkg_cb_response(question));
  13232. + str_chomp(response);
  13233. + str_tolower(response);
  13234. +
  13235. + return response;
  13236. +}
  13237. diff -Nur busybox-1.24.1.orig/archival/libipkg/user.h busybox-1.24.1/archival/libipkg/user.h
  13238. --- busybox-1.24.1.orig/archival/libipkg/user.h 1970-01-01 01:00:00.000000000 +0100
  13239. +++ busybox-1.24.1/archival/libipkg/user.h 2015-10-31 19:00:22.000000000 +0100
  13240. @@ -0,0 +1,23 @@
  13241. +/* user.c - the itsy package management system
  13242. +
  13243. + Jamey Hicks
  13244. +
  13245. + Copyright (C) 2002 Hewlett Packard Company
  13246. + Copyright (C) 2001 University of Southern California
  13247. +
  13248. + This program is free software; you can redistribute it and/or
  13249. + modify it under the terms of the GNU General Public License as
  13250. + published by the Free Software Foundation; either version 2, or (at
  13251. + your option) any later version.
  13252. +
  13253. + This program is distributed in the hope that it will be useful, but
  13254. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13255. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13256. + General Public License for more details.
  13257. +*/
  13258. +
  13259. +#include <stdio.h>
  13260. +#include <stdarg.h>
  13261. +
  13262. +char *get_user_response(const char *format, ...);
  13263. +
  13264. diff -Nur busybox-1.24.1.orig/archival/libipkg/void_list.c busybox-1.24.1/archival/libipkg/void_list.c
  13265. --- busybox-1.24.1.orig/archival/libipkg/void_list.c 1970-01-01 01:00:00.000000000 +0100
  13266. +++ busybox-1.24.1/archival/libipkg/void_list.c 2015-10-31 19:00:22.000000000 +0100
  13267. @@ -0,0 +1,194 @@
  13268. +/* void_list.c - the itsy package management system
  13269. +
  13270. + Carl D. Worth
  13271. +
  13272. + Copyright (C) 2001 University of Southern California
  13273. +
  13274. + This program is free software; you can redistribute it and/or
  13275. + modify it under the terms of the GNU General Public License as
  13276. + published by the Free Software Foundation; either version 2, or (at
  13277. + your option) any later version.
  13278. +
  13279. + This program is distributed in the hope that it will be useful, but
  13280. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13282. + General Public License for more details.
  13283. +*/
  13284. +
  13285. +#include "ipkg.h"
  13286. +#include <errno.h>
  13287. +
  13288. +#include "void_list.h"
  13289. +
  13290. +int void_list_elt_init(void_list_elt_t *elt, void *data)
  13291. +{
  13292. + elt->next = NULL;
  13293. + elt->data = data;
  13294. +
  13295. + return 0;
  13296. +}
  13297. +
  13298. +void void_list_elt_deinit(void_list_elt_t *elt)
  13299. +{
  13300. + void_list_elt_init(elt, NULL);
  13301. +}
  13302. +
  13303. +int void_list_init(void_list_t *list)
  13304. +{
  13305. + void_list_elt_init(&list->pre_head, NULL);
  13306. + list->head = NULL;
  13307. + list->pre_head.next = list->head;
  13308. + list->tail = NULL;
  13309. +
  13310. + return 0;
  13311. +}
  13312. +
  13313. +void void_list_deinit(void_list_t *list)
  13314. +{
  13315. + void_list_elt_t *elt;
  13316. +
  13317. + while (list->head) {
  13318. + elt = void_list_pop(list);
  13319. + void_list_elt_deinit(elt);
  13320. + /* malloced in void_list_append */
  13321. + free(elt);
  13322. + }
  13323. +}
  13324. +
  13325. +int void_list_append(void_list_t *list, void *data)
  13326. +{
  13327. + void_list_elt_t *elt;
  13328. +
  13329. + /* freed in void_list_deinit */
  13330. + elt = malloc(sizeof(void_list_elt_t));
  13331. + if (elt == NULL) {
  13332. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13333. + return ENOMEM;
  13334. + }
  13335. +
  13336. + void_list_elt_init(elt, data);
  13337. +
  13338. + if (list->tail) {
  13339. + list->tail->next = elt;
  13340. + list->tail = elt;
  13341. + } else {
  13342. + list->head = elt;
  13343. + list->pre_head.next = list->head;
  13344. + list->tail = elt;
  13345. + }
  13346. +
  13347. + return 0;
  13348. +}
  13349. +
  13350. +int void_list_push(void_list_t *list, void *data)
  13351. +{
  13352. + void_list_elt_t *elt;
  13353. +
  13354. + elt = malloc(sizeof(void_list_elt_t));
  13355. + if (elt == NULL) {
  13356. + fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
  13357. + return ENOMEM;
  13358. + }
  13359. +
  13360. + void_list_elt_init(elt, data);
  13361. +
  13362. + elt->next = list->head;
  13363. + list->head->next = elt;
  13364. + if (list->tail == NULL) {
  13365. + list->tail = list->head;
  13366. + }
  13367. +
  13368. + return 0;
  13369. +}
  13370. +
  13371. +void_list_elt_t *void_list_pop(void_list_t *list)
  13372. +{
  13373. + void_list_elt_t *elt;
  13374. +
  13375. + elt = list->head;
  13376. +
  13377. + if (list->head) {
  13378. + list->head = list->head->next;
  13379. + list->pre_head.next = list->head;
  13380. + if (list->head == NULL) {
  13381. + list->tail = NULL;
  13382. + }
  13383. + }
  13384. +
  13385. + return elt;
  13386. +}
  13387. +
  13388. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
  13389. +{
  13390. + void_list_elt_t *prior;
  13391. + void_list_elt_t *old_elt;
  13392. + void *old_data;
  13393. +
  13394. + old_elt = *iter;
  13395. + old_data = old_elt->data;
  13396. +
  13397. + if (old_elt == list->head) {
  13398. + prior = &list->pre_head;
  13399. + void_list_pop(list);
  13400. + } else {
  13401. + for (prior = list->head; prior; prior = prior->next) {
  13402. + if (prior->next == old_elt) {
  13403. + break;
  13404. + }
  13405. + }
  13406. + if (prior == NULL || prior->next != old_elt) {
  13407. + fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
  13408. + return NULL;
  13409. + }
  13410. + prior->next = old_elt->next;
  13411. +
  13412. + if (old_elt == list->tail) {
  13413. + list->tail = prior;
  13414. + }
  13415. + }
  13416. +
  13417. + void_list_elt_deinit(old_elt);
  13418. + *iter = prior;
  13419. +
  13420. + return old_data;
  13421. +}
  13422. +
  13423. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13424. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
  13425. +{
  13426. + void_list_elt_t *prior;
  13427. + void_list_elt_t *old_elt = NULL;
  13428. + void *old_data = NULL;
  13429. +
  13430. + /* first element */
  13431. + if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
  13432. + old_elt = list->head;
  13433. + old_data = list->head->data;
  13434. + void_list_pop(list);
  13435. + } else {
  13436. + int found = 0;
  13437. + for (prior = list->head; prior && prior->next; prior = prior->next) {
  13438. + if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
  13439. + old_elt = prior->next;
  13440. + old_data = old_elt->data;
  13441. + found = 1;
  13442. + break;
  13443. + }
  13444. + }
  13445. + if (!found) {
  13446. + return NULL;
  13447. + }
  13448. + prior->next = old_elt->next;
  13449. +
  13450. + if (old_elt == list->tail) {
  13451. + list->tail = prior;
  13452. + }
  13453. + }
  13454. + if (old_elt)
  13455. + void_list_elt_deinit(old_elt);
  13456. +
  13457. + if (old_data)
  13458. + return old_data;
  13459. + else
  13460. + return NULL;
  13461. +}
  13462. diff -Nur busybox-1.24.1.orig/archival/libipkg/void_list.h busybox-1.24.1/archival/libipkg/void_list.h
  13463. --- busybox-1.24.1.orig/archival/libipkg/void_list.h 1970-01-01 01:00:00.000000000 +0100
  13464. +++ busybox-1.24.1/archival/libipkg/void_list.h 2015-10-31 19:00:22.000000000 +0100
  13465. @@ -0,0 +1,59 @@
  13466. +/* void_list.h - the itsy package management system
  13467. +
  13468. + Carl D. Worth
  13469. +
  13470. + Copyright (C) 2001 University of Southern California
  13471. +
  13472. + This program is free software; you can redistribute it and/or
  13473. + modify it under the terms of the GNU General Public License as
  13474. + published by the Free Software Foundation; either version 2, or (at
  13475. + your option) any later version.
  13476. +
  13477. + This program is distributed in the hope that it will be useful, but
  13478. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13479. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13480. + General Public License for more details.
  13481. +*/
  13482. +
  13483. +#ifndef VOID_LIST_H
  13484. +#define VOID_LIST_H
  13485. +
  13486. +typedef struct void_list_elt void_list_elt_t;
  13487. +struct void_list_elt
  13488. +{
  13489. + void_list_elt_t *next;
  13490. + void *data;
  13491. +};
  13492. +
  13493. +typedef struct void_list void_list_t;
  13494. +struct void_list
  13495. +{
  13496. + void_list_elt_t pre_head;
  13497. + void_list_elt_t *head;
  13498. + void_list_elt_t *tail;
  13499. +};
  13500. +
  13501. +static inline int void_list_empty(void_list_t *list)
  13502. +{
  13503. + if (list->head == NULL)
  13504. + return 1;
  13505. + else
  13506. + return 0;
  13507. +}
  13508. +
  13509. +int void_list_elt_init(void_list_elt_t *elt, void *data);
  13510. +void void_list_elt_deinit(void_list_elt_t *elt);
  13511. +
  13512. +int void_list_init(void_list_t *list);
  13513. +void void_list_deinit(void_list_t *list);
  13514. +
  13515. +int void_list_append(void_list_t *list, void *data);
  13516. +int void_list_push(void_list_t *list, void *data);
  13517. +void_list_elt_t *void_list_pop(void_list_t *list);
  13518. +
  13519. +void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
  13520. +/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
  13521. +typedef int (*void_list_cmp_t)(const void *, const void *);
  13522. +void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
  13523. +
  13524. +#endif
  13525. diff -Nur busybox-1.24.1.orig/archival/libipkg/xsystem.c busybox-1.24.1/archival/libipkg/xsystem.c
  13526. --- busybox-1.24.1.orig/archival/libipkg/xsystem.c 1970-01-01 01:00:00.000000000 +0100
  13527. +++ busybox-1.24.1/archival/libipkg/xsystem.c 2015-10-31 19:00:22.000000000 +0100
  13528. @@ -0,0 +1,64 @@
  13529. +/* xsystem.c - system(3) with error messages
  13530. +
  13531. + Carl D. Worth
  13532. +
  13533. + Copyright (C) 2001 University of Southern California
  13534. +
  13535. + This program is free software; you can redistribute it and/or
  13536. + modify it under the terms of the GNU General Public License as
  13537. + published by the Free Software Foundation; either version 2, or (at
  13538. + your option) any later version.
  13539. +
  13540. + This program is distributed in the hope that it will be useful, but
  13541. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13542. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13543. + General Public License for more details.
  13544. +*/
  13545. +
  13546. +#include "ipkg.h"
  13547. +#include <sys/wait.h>
  13548. +
  13549. +#include "xsystem.h"
  13550. +
  13551. +/* XXX: FEATURE: I shouldn't actually use system(3) at all. I don't
  13552. + really need the /bin/sh invocation which takes resources and
  13553. + introduces security problems. I should switch all of this to a sort
  13554. + of execl() or execv() interface/implementation.
  13555. +*/
  13556. +
  13557. +/* Like system(3), but with error messages printed if the fork fails
  13558. + or if the child process dies due to an uncaught signal. Also, the
  13559. + return value is a bit simpler:
  13560. +
  13561. + -1 if there was any problem
  13562. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13563. + as defined in <sys/wait.h>.
  13564. +*/
  13565. +int xsystem(const char *cmd)
  13566. +{
  13567. + int err;
  13568. +
  13569. + err = system(cmd);
  13570. +
  13571. + if (err == -1) {
  13572. + fprintf(stderr, "%s: ERROR: fork failed before execution: `%s'\n",
  13573. + __FUNCTION__, cmd);
  13574. + return -1;
  13575. + }
  13576. +
  13577. + if (WIFSIGNALED(err)) {
  13578. + fprintf(stderr, "%s: ERROR: Child process died due to signal %d: `%s'\n",
  13579. + __FUNCTION__, WTERMSIG(err), cmd);
  13580. + return -1;
  13581. + }
  13582. +
  13583. + if (WIFEXITED(err)) {
  13584. + /* Normal child exit */
  13585. + return WEXITSTATUS(err);
  13586. + }
  13587. +
  13588. + fprintf(stderr, "%s: ERROR: Received unintelligible return value from system: %d",
  13589. + __FUNCTION__, err);
  13590. + return -1;
  13591. +}
  13592. +
  13593. diff -Nur busybox-1.24.1.orig/archival/libipkg/xsystem.h busybox-1.24.1/archival/libipkg/xsystem.h
  13594. --- busybox-1.24.1.orig/archival/libipkg/xsystem.h 1970-01-01 01:00:00.000000000 +0100
  13595. +++ busybox-1.24.1/archival/libipkg/xsystem.h 2015-10-31 19:00:22.000000000 +0100
  13596. @@ -0,0 +1,34 @@
  13597. +/* xsystem.h - system(3) with error messages
  13598. +
  13599. + Carl D. Worth
  13600. +
  13601. + Copyright (C) 2001 University of Southern California
  13602. +
  13603. + This program is free software; you can redistribute it and/or
  13604. + modify it under the terms of the GNU General Public License as
  13605. + published by the Free Software Foundation; either version 2, or (at
  13606. + your option) any later version.
  13607. +
  13608. + This program is distributed in the hope that it will be useful, but
  13609. + WITHOUT ANY WARRANTY; without even the implied warranty of
  13610. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13611. + General Public License for more details.
  13612. +*/
  13613. +
  13614. +#ifndef XSYSTEM_H
  13615. +#define XSYSTEM_H
  13616. +
  13617. +#include <stdlib.h>
  13618. +
  13619. +/* Like system(3), but with error messages printed if the fork fails
  13620. + or if the child process dies due to an uncaught signal. Also, the
  13621. + return value is a bit simpler:
  13622. +
  13623. + -1 if there was any problem
  13624. + Otherwise, the 8-bit return value of the program ala WEXITSTATUS
  13625. + as defined in <sys/wait.h>.
  13626. +*/
  13627. +int xsystem(const char *cmd);
  13628. +
  13629. +#endif
  13630. +
  13631. diff -Nur busybox-1.24.1.orig/include/applets.src.h busybox-1.24.1/include/applets.src.h
  13632. --- busybox-1.24.1.orig/include/applets.src.h 2015-10-24 02:24:35.000000000 +0200
  13633. +++ busybox-1.24.1/include/applets.src.h 2015-10-31 19:00:22.000000000 +0100
  13634. @@ -193,6 +193,7 @@
  13635. IF_IPCALC(APPLET(ipcalc, BB_DIR_BIN, BB_SUID_DROP))
  13636. IF_IPCRM(APPLET(ipcrm, BB_DIR_USR_BIN, BB_SUID_DROP))
  13637. IF_IPCS(APPLET(ipcs, BB_DIR_USR_BIN, BB_SUID_DROP))
  13638. +IF_IPKG(APPLET(ipkg, BB_DIR_USR_BIN, BB_SUID_DROP))
  13639. IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
  13640. IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
  13641. IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
  13642. diff -Nur busybox-1.24.1.orig/include/bb_archive.h busybox-1.24.1/include/bb_archive.h
  13643. --- busybox-1.24.1.orig/include/bb_archive.h 2015-10-24 02:24:35.000000000 +0200
  13644. +++ busybox-1.24.1/include/bb_archive.h 2015-10-31 19:00:22.000000000 +0100
  13645. @@ -79,7 +79,6 @@
  13646. /* Archiver specific. Can make it a union if it ever gets big */
  13647. #define PAX_NEXT_FILE 0
  13648. #define PAX_GLOBAL 1
  13649. -#if ENABLE_TAR || ENABLE_DPKG || ENABLE_DPKG_DEB
  13650. smallint tar__end;
  13651. # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
  13652. char* tar__longname;
  13653. @@ -92,13 +91,12 @@
  13654. # if ENABLE_FEATURE_TAR_SELINUX
  13655. char* tar__sctx[2];
  13656. # endif
  13657. -#endif
  13658. #if ENABLE_CPIO || ENABLE_RPM2CPIO || ENABLE_RPM
  13659. uoff_t cpio__blocks;
  13660. struct hardlinks_t *cpio__hardlinks_to_create;
  13661. struct hardlinks_t *cpio__created_hardlinks;
  13662. #endif
  13663. -#if ENABLE_DPKG || ENABLE_DPKG_DEB
  13664. +#if ENABLE_DPKG || ENABLE_DPKG_DEB || ENABLE_IPKG
  13665. /* Temporary storage */
  13666. char *dpkg__buffer;
  13667. /* How to process any sub archive, e.g. get_header_tar_gz */
  13668. diff -Nur busybox-1.24.1.orig/include/usage.src.h busybox-1.24.1/include/usage.src.h
  13669. --- busybox-1.24.1.orig/include/usage.src.h 2015-07-13 04:18:47.000000000 +0200
  13670. +++ busybox-1.24.1/include/usage.src.h 2015-10-31 19:00:22.000000000 +0100
  13671. @@ -19,4 +19,80 @@
  13672. #define busybox_notes_usage \
  13673. "Hello world!\n"
  13674. +#define ipkg_trivial_usage \
  13675. + "[options]... sub-command [arguments]..."
  13676. +#define ipkg_full_usage \
  13677. + "ipkg is an utility to install, remove and manage .ipk packages.\n" \
  13678. + "\n" \
  13679. + "Sub-commands:\n" \
  13680. + "\nPackage Manipulation:\n" \
  13681. + "\tupdate Update list of available packages\n" \
  13682. + "\tupgrade Upgrade all installed packages to latest version\n" \
  13683. + "\tinstall <pkg> Download and install <pkg> (and dependencies)\n" \
  13684. + "\tinstall <file.ipk> Install package <file.ipk>\n" \
  13685. + "\tconfigure [<pkg>] Configure unpacked packages\n" \
  13686. + "\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n" \
  13687. + "\tflag <flag> <pkg> ... Flag package(s) <pkg>\n" \
  13688. + "\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n" \
  13689. + "\n" \
  13690. + "Informational Commands:\n" \
  13691. + "\tlist List available packages and descriptions\n" \
  13692. + "\tlist_installed List all and only the installed packages and description \n" \
  13693. + "\tfiles <pkg> List all files belonging to <pkg>\n" \
  13694. + "\tsearch <file|regexp> Search for a package providing <file>\n" \
  13695. + "\tinfo [pkg|regexp [<field>]] Display all/some info fields for <pkg> or all\n" \
  13696. + "\tstatus [pkg|regexp [<field>]] Display all/some status fields for <pkg> or all\n" \
  13697. + "\tdownload <pkg> Download <pkg> to current directory.\n" \
  13698. + "\tcompare_versions <v1> <op> <v2>\n" \
  13699. + "\t compare versions using <= < > >= = << >>\n" \
  13700. + "\tprint_architecture prints the architecture.\n" \
  13701. + "\tprint_installation_architecture\n" \
  13702. + "\twhatdepends [-A] [pkgname|pat]+\n" \
  13703. + "\twhatdependsrec [-A] [pkgname|pat]+\n" \
  13704. + "\twhatprovides [-A] [pkgname|pat]+\n" \
  13705. + "\twhatconflicts [-A] [pkgname|pat]+\n" \
  13706. + "\twhatreplaces [-A] [pkgname|pat]+\n" \
  13707. + "\t prints the installation architecture.\n" \
  13708. + "\n" \
  13709. + "\nOptions:\n" \
  13710. + "\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n" \
  13711. + "\t-V <level> Set verbosity level to <level>. If no value is\n" \
  13712. + "\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n" \
  13713. + "\t 0 errors only\n" \
  13714. + "\t 1 normal messages (default)\n" \
  13715. + "\t 2 informative messages\n" \
  13716. + "\t 3 debug output\n" \
  13717. + "\t-f <conf_file> Use <conf_file> as the ipkg configuration file\n" \
  13718. + "\t-conf <conf_file> Default configuration file location\n" \
  13719. + " is /etc/ipkg.conf\n" \
  13720. + "\t-d <dest_name> Use <dest_name> as the the root directory for\n" \
  13721. + "\t-dest <dest_name> package installation, removal, upgrading.\n" \
  13722. + " <dest_name> should be a defined dest name from\n" \
  13723. + " the configuration file, (but can also be a\n" \
  13724. + " directory name in a pinch).\n" \
  13725. + "\t-o <offline_root> Use <offline_root> as the root directory for\n" \
  13726. + "\t-offline <offline_root> offline installation of packages.\n" \
  13727. + "\t-verbose_wget more wget messages\n" \
  13728. + "\n" \
  13729. + "Force Options (use when ipkg is too smart for its own good):\n" \
  13730. + "\t-force-depends Make dependency checks warnings instead of errors\n" \
  13731. + "\t Install/remove package in spite of failed dependences\n" \
  13732. + "\t-force-defaults Use default options for questions asked by ipkg.\n" \
  13733. + " (no prompts). Note that this will not prevent\n" \
  13734. + " package installation scripts from prompting.\n" \
  13735. + "\t-force-reinstall Allow ipkg to reinstall a package.\n" \
  13736. + "\t-force-overwrite Allow ipkg to overwrite files from another package during an install.\n" \
  13737. + "\t-force-downgrade Allow ipkg to downgrade packages.\n" \
  13738. + "\t-force_space Install even if there does not seem to be enough space.\n" \
  13739. + "\t-noaction No action -- test only\n" \
  13740. + "\t-nodeps Do not follow dependences\n" \
  13741. + "\t-force-removal-of-dependent-packages\n" \
  13742. + "\t-recursive Allow ipkg to remove package and all that depend on it.\n" \
  13743. + "\t-test No action -- test only\n" \
  13744. + "\t-t Specify tmp-dir.\n" \
  13745. + "\t--tmp-dir Specify tmp-dir.\n" \
  13746. + "\n" \
  13747. + "\tregexp could be something like 'pkgname*' '*file*' or similar\n" \
  13748. + "\teg: ipkg info 'libstd*' or ipkg search '*libop*' or ipkg remove 'libncur*'\n"
  13749. +
  13750. #endif
  13751. diff -Nur busybox-1.24.1.orig/Makefile busybox-1.24.1/Makefile
  13752. --- busybox-1.24.1.orig/Makefile 2015-10-24 02:28:51.000000000 +0200
  13753. +++ busybox-1.24.1/Makefile 2015-10-31 19:00:22.000000000 +0100
  13754. @@ -466,6 +466,7 @@
  13755. libs-y := \
  13756. archival/ \
  13757. archival/libarchive/ \
  13758. + archival/libipkg/ \
  13759. console-tools/ \
  13760. coreutils/ \
  13761. coreutils/libcoreutils/ \