archives.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * dpkg - main program for package management
  3. * archives.c - actions that process archive files, mainly unpack
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright (C) 2000 Wichert Akkerman <wakkerma@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with dpkg; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <config.h>
  23. #include <errno.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <utime.h>
  29. #include <assert.h>
  30. #include <time.h>
  31. #include <ctype.h>
  32. #include <fcntl.h>
  33. #include <sys/stat.h>
  34. #include <sys/types.h>
  35. #include <obstack.h>
  36. #define obstack_chunk_alloc m_malloc
  37. #define obstack_chunk_free free
  38. #include <dpkg.h>
  39. #include <dpkg-db.h>
  40. #include <tarfn.h>
  41. #include <myopt.h>
  42. #ifdef WITH_SELINUX
  43. #include <selinux/selinux.h>
  44. static int selinux_enabled=-1;
  45. static security_context_t scontext = NULL;
  46. #endif
  47. #include "filesdb.h"
  48. #include "main.h"
  49. #include "archives.h"
  50. /* We shouldn't need anymore than 10 conflictors */
  51. struct pkginfo *conflictor[20];
  52. int cflict_index = 0;
  53. /* snprintf(3) doesn't work if format contains %.<nnn>s and an argument has
  54. * invalid char for locale, then it returns -1.
  55. * ohshite() is ok, but fd_fd_copy(), which is used in tarobject() in this
  56. * file, is not ok, because
  57. * - fd_fd_copy() == buffer_copy_setup() [include/dpkg.h]
  58. * - buffer_copy_setup() uses varbufvprintf(&v, desc, al); [lib/mlib.c]
  59. * - varbufvpprintf() fails and memory exausted, because it call
  60. * fmt = "backend dpkg-deb during `%.255s'
  61. * arg may contain some invalid char, for example,
  62. * /usr/share/doc/console-tools/examples/unicode/\342\231\252\342\231\254
  63. * in console-tools.
  64. * In this case, if user uses some locale which doesn't support \342\231...,
  65. * vsnprintf() always return -1 and varbufextend() again and again
  66. * and memory exausted and die.
  67. *
  68. * So, we need to escape invalid char, probably as in
  69. * tar-1.13.19/lib/quotearg.c: quotearg_buffer_restyled()
  70. * but here I escape all 8bit chars, in order to be simple.
  71. * - ukai@debian.or.jp
  72. */
  73. static char *
  74. quote_filename(char *buf, int size, char *s)
  75. {
  76. char *r = buf;
  77. while (size > 0) {
  78. switch (*s) {
  79. case '\0':
  80. *buf = '\0';
  81. return r;
  82. case '\\':
  83. *buf++ = '\\';
  84. *buf++ = '\\';
  85. size -= 2;
  86. break;
  87. default:
  88. if (((*s)&0x80) == 0) {
  89. *buf++ = *s++;
  90. --size;
  91. } else {
  92. if (size > 4) {
  93. sprintf(buf, "\\%03o",
  94. *(unsigned char *)s);
  95. size -= 4;
  96. buf += 4;
  97. s++;
  98. } else {
  99. /* buffer full */
  100. *buf = '\0'; /* XXX */
  101. return s;
  102. }
  103. }
  104. }
  105. }
  106. *buf = '\0'; /* XXX */
  107. return r;
  108. }
  109. /* special routine to handle partial reads from the tarfile */
  110. static int safe_read(int fd, void *buf, int len)
  111. {
  112. int r, have= 0;
  113. char *p = (char *)buf;
  114. while (have < len) {
  115. if ((r= read(fd,p,len-have))==-1) {
  116. if (errno==EINTR || errno==EAGAIN) continue;
  117. return r;
  118. }
  119. if (r==0)
  120. break;
  121. have+= r;
  122. p+= r;
  123. }
  124. return have;
  125. }
  126. static struct obstack tar_obs;
  127. static int tarobs_init= 0;
  128. /* ensure the obstack is properly initialized */
  129. static void ensureobstackinit(void) {
  130. if (!tarobs_init) {
  131. obstack_init(&tar_obs);
  132. tarobs_init= 1;
  133. }
  134. }
  135. /* destroy the obstack */
  136. static void destroyobstack(void) {
  137. if (tarobs_init) {
  138. obstack_free(&tar_obs, 0);
  139. tarobs_init= 0;
  140. }
  141. }
  142. int filesavespackage(struct fileinlist *file, struct pkginfo *pkgtobesaved,
  143. struct pkginfo *pkgbeinginstalled) {
  144. struct pkginfo *divpkg, *thirdpkg;
  145. struct filepackages *packageslump;
  146. int i;
  147. debug(dbg_eachfiledetail,"filesavespackage file `%s' package %s",
  148. file->namenode->name,pkgtobesaved->name);
  149. /* A package can only be saved by a file or directory which is part
  150. * only of itself - it must be neither part of the new package being
  151. * installed nor part of any 3rd package (this is important so that
  152. * shared directories don't stop packages from disappearing).
  153. */
  154. /* If the file is a contended one and it's overridden by either
  155. * the package we're considering disappearing or the package
  156. * we're installing then they're not actually the same file, so
  157. * we can't disappear the package - it is saved by this file.
  158. */
  159. if (file->namenode->divert && file->namenode->divert->useinstead) {
  160. divpkg= file->namenode->divert->pkg;
  161. if (divpkg == pkgtobesaved || divpkg == pkgbeinginstalled) {
  162. debug(dbg_eachfiledetail,"filesavespackage ... diverted -- save!");
  163. return 1;
  164. }
  165. }
  166. /* Is the file in the package being installed ? If so then it can't save.
  167. */
  168. if (file->namenode->flags & fnnf_new_inarchive) {
  169. debug(dbg_eachfiledetail,"filesavespackage ... in new archive -- no save");
  170. return 0;
  171. }
  172. /* Look for a 3rd package which can take over the file (in case
  173. * it's a directory which is shared by many packages.
  174. */
  175. for (packageslump= file->namenode->packages;
  176. packageslump;
  177. packageslump= packageslump->more) {
  178. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  179. thirdpkg= packageslump->pkgs[i];
  180. debug(dbg_eachfiledetail, "filesavespackage ... also in %s",
  181. thirdpkg->name);
  182. /* Is this not the package being installed or the one being
  183. * checked for disappearance ?
  184. */
  185. if (thirdpkg == pkgbeinginstalled || thirdpkg == pkgtobesaved) continue;
  186. /* If !fileslistvalid then we've already disappeared this one, so
  187. * we shouldn't try to make it take over this shared directory.
  188. */
  189. debug(dbg_eachfiledetail,"filesavespackage ... is 3rd package");
  190. if (!thirdpkg->clientdata->fileslistvalid) {
  191. debug(dbg_eachfiledetail,
  192. _("process_archive ... already disappeared !"));
  193. continue;
  194. }
  195. /* We've found a package that can take this file. */
  196. debug(dbg_eachfiledetail, "filesavespackage ... taken -- no save");
  197. return 0;
  198. }
  199. }
  200. debug(dbg_eachfiledetail, "filesavespackage ... not taken -- save !");
  201. return 1;
  202. }
  203. void cu_pathname(int argc, void **argv) {
  204. ensure_pathname_nonexisting((char*)(argv[0]));
  205. }
  206. int tarfileread(void *ud, char *buf, int len) {
  207. struct tarcontext *tc= (struct tarcontext*)ud;
  208. int r;
  209. if ((r= safe_read(tc->backendpipe,buf,len)) == -1)
  210. ohshite(_("error reading from dpkg-deb pipe"));
  211. return r;
  212. }
  213. int fnameidlu;
  214. struct varbuf fnamevb;
  215. struct varbuf fnametmpvb;
  216. struct varbuf fnamenewvb;
  217. struct packageinlist *deconfigure= 0;
  218. static time_t currenttime;
  219. static int does_replace(struct pkginfo *newpigp,
  220. struct pkginfoperfile *newpifp,
  221. struct pkginfo *oldpigp) {
  222. struct dependency *dep;
  223. debug(dbg_depcon,"does_replace new=%s old=%s (%s)",newpigp->name,
  224. oldpigp->name,versiondescribe(&oldpigp->installed.version,
  225. vdew_always));
  226. for (dep= newpifp->depends; dep; dep= dep->next) {
  227. if (dep->type != dep_replaces || dep->list->ed != oldpigp) continue;
  228. debug(dbg_depcondetail,"does_replace ... found old, version %s",
  229. versiondescribe(&dep->list->version,vdew_always));
  230. if (!versionsatisfied(&oldpigp->installed,dep->list)) continue;
  231. debug(dbg_depcon,"does_replace ... yes");
  232. return 1;
  233. }
  234. debug(dbg_depcon,"does_replace ... no");
  235. return 0;
  236. }
  237. static void newtarobject_utime(const char *path, struct TarInfo *ti) {
  238. struct utimbuf utb;
  239. utb.actime= currenttime;
  240. utb.modtime= ti->ModTime;
  241. if (utime(path,&utb))
  242. ohshite(_("error setting timestamps of `%.255s'"),ti->Name);
  243. }
  244. static void newtarobject_allmodes(const char *path, struct TarInfo *ti, struct filestatoverride* statoverride) {
  245. if (chown(path,
  246. statoverride ? statoverride->uid : ti->UserID,
  247. statoverride ? statoverride->gid : ti->GroupID))
  248. ohshite(_("error setting ownership of `%.255s'"),ti->Name);
  249. if (chmod(path,(statoverride ? statoverride->mode : ti->Mode) & ~S_IFMT))
  250. ohshite(_("error setting permissions of `%.255s'"),ti->Name);
  251. newtarobject_utime(path,ti);
  252. }
  253. void setupfnamevbs(const char *filename) {
  254. fnamevb.used= fnameidlu;
  255. varbufaddstr(&fnamevb,filename);
  256. varbufaddc(&fnamevb,0);
  257. fnametmpvb.used= fnameidlu;
  258. varbufaddstr(&fnametmpvb,filename);
  259. varbufaddstr(&fnametmpvb,DPKGTEMPEXT);
  260. varbufaddc(&fnametmpvb,0);
  261. fnamenewvb.used= fnameidlu;
  262. varbufaddstr(&fnamenewvb,filename);
  263. varbufaddstr(&fnamenewvb,DPKGNEWEXT);
  264. varbufaddc(&fnamenewvb,0);
  265. debug(dbg_eachfiledetail, "setupvnamevbs main=`%s' tmp=`%s' new=`%s'",
  266. fnamevb.buf, fnametmpvb.buf, fnamenewvb.buf);
  267. }
  268. int unlinkorrmdir(const char *filename) {
  269. /* Returns 0 on success or -1 on failure, just like unlink & rmdir */
  270. int r, e;
  271. if (!rmdir(filename)) {
  272. debug(dbg_eachfiledetail,"unlinkorrmdir `%s' rmdir OK",filename);
  273. return 0;
  274. }
  275. if (errno != ENOTDIR) {
  276. e= errno;
  277. debug(dbg_eachfiledetail,"unlinkorrmdir `%s' rmdir %s",filename,strerror(e));
  278. errno= e; return -1;
  279. }
  280. r= unlink(filename); e= errno;
  281. debug(dbg_eachfiledetail,"unlinkorrmdir `%s' unlink %s",
  282. filename, r ? strerror(e) : "OK");
  283. errno= e; return r;
  284. }
  285. struct fileinlist *addfiletolist(struct tarcontext *tc,
  286. struct filenamenode *namenode) {
  287. struct fileinlist *nifd;
  288. nifd= obstack_alloc(&tar_obs, sizeof(struct fileinlist));
  289. nifd->namenode= namenode;
  290. nifd->next= 0; *tc->newfilesp= nifd; tc->newfilesp= &nifd->next;
  291. return nifd;
  292. }
  293. int tarobject(struct TarInfo *ti) {
  294. static struct varbuf conffderefn, hardlinkfn, symlinkfn;
  295. const char *usename;
  296. struct conffile *conff;
  297. struct tarcontext *tc= (struct tarcontext*)ti->UserData;
  298. int statr, fd, i, existingdirectory, keepexisting;
  299. size_t r;
  300. struct stat stab, stabtmp;
  301. char databuf[TARBLKSZ];
  302. struct fileinlist *nifd, **oldnifd;
  303. struct pkginfo *divpkg, *otherpkg;
  304. struct filepackages *packageslump;
  305. mode_t am;
  306. ensureobstackinit();
  307. /* Append to list of files.
  308. * The trailing / put on the end of names in tarfiles has already
  309. * been stripped by TarExtractor (lib/tarfn.c).
  310. */
  311. oldnifd= tc->newfilesp;
  312. nifd= addfiletolist(tc, findnamenode(ti->Name, 0));
  313. nifd->namenode->flags |= fnnf_new_inarchive;
  314. debug(dbg_eachfile,
  315. "tarobject ti->Name=`%s' Mode=%lo owner=%u.%u Type=%d(%c)"
  316. " ti->LinkName=`%s' namenode=`%s' flags=%o instead=`%s'",
  317. ti->Name, (long)ti->Mode, (unsigned)ti->UserID, (unsigned)ti->GroupID, ti->Type,
  318. ti->Type == '\0' ? '_' :
  319. ti->Type >= '0' && ti->Type <= '6' ? "-hlcbdp"[ti->Type - '0'] : '?',
  320. ti->LinkName,
  321. nifd->namenode->name, nifd->namenode->flags,
  322. nifd->namenode->divert && nifd->namenode->divert->useinstead
  323. ? nifd->namenode->divert->useinstead->name : "<none>");
  324. if (nifd->namenode->divert && nifd->namenode->divert->camefrom) {
  325. divpkg= nifd->namenode->divert->pkg;
  326. forcibleerr(fc_overwritediverted,
  327. _("trying to overwrite `%.250s', which is the "
  328. "diverted version of `%.250s'%.10s%.100s%.10s"),
  329. nifd->namenode->name,
  330. nifd->namenode->divert->camefrom->name,
  331. divpkg ? _(" (package: ") : "",
  332. divpkg ? divpkg->name : "",
  333. divpkg ? ")" : "");
  334. }
  335. usename= namenodetouse(nifd->namenode,tc->pkg)->name + 1; /* Skip the leading `/' */
  336. if (nifd->namenode->flags & fnnf_new_conff) {
  337. /* If it's a conffile we have to extract it next to the installed
  338. * version (ie, we do the usual link-following).
  339. */
  340. if (conffderef(tc->pkg, &conffderefn, usename))
  341. usename= conffderefn.buf;
  342. debug(dbg_conff,"tarobject fnnf_new_conff deref=`%s'",usename);
  343. }
  344. setupfnamevbs(usename);
  345. statr= lstat(fnamevb.buf,&stab);
  346. if (statr) {
  347. /* The lstat failed. */
  348. if (errno != ENOENT && errno != ENOTDIR)
  349. ohshite(_("unable to stat `%.255s' (which I was about to install)"),ti->Name);
  350. /* OK, so it doesn't exist.
  351. * However, it's possible that we were in the middle of some other
  352. * backup/restore operation and were rudely interrupted.
  353. * So, we see if we have .dpkg-tmp, and if so we restore it.
  354. */
  355. if (rename(fnametmpvb.buf,fnamevb.buf)) {
  356. if (errno != ENOENT && errno != ENOTDIR)
  357. ohshite(_("unable to clean up mess surrounding `%.255s' before "
  358. "installing another version"),ti->Name);
  359. debug(dbg_eachfiledetail,"tarobject nonexistent");
  360. } else {
  361. debug(dbg_eachfiledetail,"tarobject restored tmp to main");
  362. statr= lstat(fnamevb.buf,&stab);
  363. if (statr) ohshite(_("unable to stat restored `%.255s' before installing"
  364. " another version"), ti->Name);
  365. }
  366. } else {
  367. debug(dbg_eachfiledetail,"tarobject already exists");
  368. }
  369. /* Check to see if it's a directory or link to one and we don't need to
  370. * do anything. This has to be done now so that we don't die due to
  371. * a file overwriting conflict.
  372. */
  373. existingdirectory= 0;
  374. switch (ti->Type) {
  375. case SymbolicLink:
  376. /* If it's already an existing directory, do nothing. */
  377. if (!statr && S_ISDIR(stab.st_mode)) {
  378. debug(dbg_eachfiledetail,"tarobject SymbolicLink exists as directory");
  379. existingdirectory= 1;
  380. }
  381. break;
  382. case Directory:
  383. /* If it's already an existing directory, do nothing. */
  384. if (!stat(fnamevb.buf,&stabtmp) && S_ISDIR(stabtmp.st_mode)) {
  385. debug(dbg_eachfiledetail,"tarobject Directory exists");
  386. existingdirectory= 1;
  387. }
  388. break;
  389. case NormalFile0: case NormalFile1:
  390. case CharacterDevice: case BlockDevice: case FIFO:
  391. case HardLink:
  392. break;
  393. default:
  394. ohshit(_("archive contained object `%.255s' of unknown type 0x%x"),ti->Name,ti->Type);
  395. }
  396. keepexisting= 0;
  397. if (!existingdirectory) {
  398. for (packageslump= nifd->namenode->packages;
  399. packageslump;
  400. packageslump= packageslump->more) {
  401. for (i=0; i < PERFILEPACKAGESLUMP && packageslump->pkgs[i]; i++) {
  402. otherpkg= packageslump->pkgs[i];
  403. if (otherpkg == tc->pkg) continue;
  404. debug(dbg_eachfile, "tarobject ... found in %s",otherpkg->name);
  405. if (nifd->namenode->divert && nifd->namenode->divert->useinstead) {
  406. /* Right, so we may be diverting this file. This makes the conflict
  407. * OK iff one of us is the diverting package (we don't need to
  408. * check for both being the diverting package, obviously).
  409. */
  410. divpkg= nifd->namenode->divert->pkg;
  411. debug(dbg_eachfile, "tarobject ... diverted, divpkg=%s",
  412. divpkg ? divpkg->name : "<none>");
  413. if (otherpkg == divpkg || tc->pkg == divpkg) continue;
  414. }
  415. /* Nope ? Hmm, file conflict, perhaps. Check Replaces. */
  416. switch (otherpkg->clientdata->replacingfilesandsaid) {
  417. case 2:
  418. keepexisting= 1;
  419. case 1:
  420. continue;
  421. }
  422. /* Is the package with the conflicting file in the `config files
  423. * only' state ? If so it must be a config file and we can
  424. * silenty take it over.
  425. */
  426. if (otherpkg->status == stat_configfiles) continue;
  427. /* Perhaps we're removing a conflicting package ? */
  428. if (otherpkg->clientdata->istobe == itb_remove) continue;
  429. /* Is the file an obsolete conffile in the other package
  430. * and a conffile in the new package ? */
  431. if ((nifd->namenode->flags & fnnf_new_conff) &&
  432. !statr && S_ISREG(stab.st_mode)) {
  433. for (conff= otherpkg->installed.conffiles;
  434. conff;
  435. conff= conff->next) {
  436. if (!conff->obsolete)
  437. continue;
  438. if (stat(conff->name, &stabtmp))
  439. if (errno == ENOENT || errno == ENOTDIR || errno == ELOOP)
  440. continue;
  441. if (stabtmp.st_dev == stab.st_dev &&
  442. stabtmp.st_ino == stab.st_ino)
  443. break;
  444. }
  445. if (conff)
  446. debug(dbg_eachfiledetail,"tarobject other's obsolete conffile");
  447. /* processarc.c will have copied its hash already. */
  448. continue;
  449. }
  450. if (does_replace(tc->pkg,&tc->pkg->available,otherpkg)) {
  451. printf(_("Replacing files in old package %s ...\n"),otherpkg->name);
  452. otherpkg->clientdata->replacingfilesandsaid= 1;
  453. } else if (does_replace(otherpkg,&otherpkg->installed,tc->pkg)) {
  454. printf(_("Replaced by files in installed package %s ...\n"),
  455. otherpkg->name);
  456. otherpkg->clientdata->replacingfilesandsaid= 2;
  457. keepexisting = 1;
  458. } else {
  459. if (!statr && S_ISDIR(stab.st_mode)) {
  460. forcibleerr(fc_overwritedir, _("trying to overwrite directory `%.250s' "
  461. "in package %.250s with nondirectory"),
  462. nifd->namenode->name,otherpkg->name);
  463. } else {
  464. /* WTA: At this point we are replacing something without a Replaces.
  465. * if the new object is a directory and the previous object does not
  466. * exist assume it's also a directory and don't complain
  467. */
  468. if (! (statr && ti->Type==Directory))
  469. forcibleerr(fc_overwrite,
  470. _("trying to overwrite `%.250s', which is also in package %.250s"),
  471. nifd->namenode->name,otherpkg->name);
  472. }
  473. }
  474. }
  475. }
  476. }
  477. /* Now, at this stage we want to make sure neither of .dpkg-new and .dpkg-tmp
  478. * are hanging around.
  479. */
  480. ensure_pathname_nonexisting(fnamenewvb.buf);
  481. ensure_pathname_nonexisting(fnametmpvb.buf);
  482. if (existingdirectory) return 0;
  483. if (keepexisting) {
  484. obstack_free(&tar_obs, nifd);
  485. tc->newfilesp= oldnifd;
  486. *oldnifd = 0;
  487. /* We need to advance the tar file to the next object, so read the
  488. * file data and set it to oblivion.
  489. */
  490. if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) {
  491. char fnamebuf[256];
  492. fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name));
  493. r= ti->Size % TARBLKSZ;
  494. if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r);
  495. }
  496. return 0;
  497. }
  498. /* Now we start to do things that we need to be able to undo
  499. * if something goes wrong. Watch out for the CLEANUP comments to
  500. * keep an eye on what's installed on the disk at each point.
  501. */
  502. push_cleanup(cu_installnew,~ehflag_normaltidy, 0,0, 1,(void*)nifd);
  503. /* CLEANUP: Now we either have the old file on the disk, or not, in
  504. * its original filename.
  505. */
  506. #ifdef WITH_SELINUX
  507. /* Set selinux_enabled if it is not already set (singleton) */
  508. if (selinux_enabled < 0)
  509. selinux_enabled = (is_selinux_enabled() > 0);
  510. /* Since selinux is enabled, try and set the context */
  511. if (selinux_enabled > 0) {
  512. /*
  513. * well, we could use
  514. * void set_matchpathcon_printf(void (*f)(const char *fmt, ...));
  515. * to redirect the errors from the following bit, but that
  516. * seems too much effort.
  517. */
  518. /*
  519. * Do nothing if we can't figure out what the context is,
  520. * or if it has no context; in which case the default
  521. * context shall be applied.
  522. */
  523. if( ! ((matchpathcon(fnamevb.buf,
  524. (nifd->namenode->statoverride ?
  525. nifd->namenode->statoverride->mode : ti->Mode)
  526. & ~S_IFMT, &scontext) != 0) ||
  527. (strcmp(scontext, "<<none>>") == 0)))
  528. {
  529. if(setfscreatecon(scontext) < 0)
  530. perror("Error setting security context for file object:");
  531. }
  532. }
  533. #endif /* WITH_SELINUX */
  534. /* Extract whatever it is as .dpkg-new ... */
  535. switch (ti->Type) {
  536. case NormalFile0: case NormalFile1:
  537. /* We create the file with mode 0 to make sure nobody can do anything with
  538. * it until we apply the proper mode, which might be a statoverride.
  539. */
  540. fd= open(fnamenewvb.buf, (O_CREAT|O_EXCL|O_WRONLY), 0);
  541. if (fd < 0) ohshite(_("unable to create `%.255s'"),ti->Name);
  542. push_cleanup(cu_closefd,ehflag_bombout, 0,0, 1,&fd);
  543. debug(dbg_eachfiledetail,"tarobject NormalFile[01] open size=%lu",
  544. (unsigned long)ti->Size);
  545. { char fnamebuf[256];
  546. fd_fd_copy(tc->backendpipe, fd, ti->Size, _("backend dpkg-deb during `%.255s'"),quote_filename(fnamebuf,256,ti->Name));
  547. }
  548. r= ti->Size % TARBLKSZ;
  549. if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r);
  550. if (nifd->namenode->statoverride)
  551. debug(dbg_eachfile, "tarobject ... stat override, uid=%d, gid=%d, mode=%04o",
  552. nifd->namenode->statoverride->uid,
  553. nifd->namenode->statoverride->gid,
  554. nifd->namenode->statoverride->mode);
  555. if (fchown(fd,
  556. nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->UserID,
  557. nifd->namenode->statoverride ? nifd->namenode->statoverride->gid : ti->GroupID))
  558. ohshite(_("error setting ownership of `%.255s'"),ti->Name);
  559. am=(nifd->namenode->statoverride ? nifd->namenode->statoverride->mode : ti->Mode) & ~S_IFMT;
  560. if (fchmod(fd,am))
  561. ohshite(_("error setting permissions of `%.255s'"),ti->Name);
  562. pop_cleanup(ehflag_normaltidy); /* fd= open(fnamenewvb.buf) */
  563. if (close(fd))
  564. ohshite(_("error closing/writing `%.255s'"),ti->Name);
  565. newtarobject_utime(fnamenewvb.buf,ti);
  566. break;
  567. case FIFO:
  568. if (mkfifo(fnamenewvb.buf,0))
  569. ohshite(_("error creating pipe `%.255s'"),ti->Name);
  570. debug(dbg_eachfiledetail,"tarobject FIFO");
  571. newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
  572. break;
  573. case CharacterDevice:
  574. if (mknod(fnamenewvb.buf,S_IFCHR, ti->Device))
  575. ohshite(_("error creating device `%.255s'"),ti->Name);
  576. debug(dbg_eachfiledetail,"tarobject CharacterDevice");
  577. newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
  578. break;
  579. case BlockDevice:
  580. if (mknod(fnamenewvb.buf,S_IFBLK, ti->Device))
  581. ohshite(_("error creating device `%.255s'"),ti->Name);
  582. debug(dbg_eachfiledetail,"tarobject BlockDevice");
  583. newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
  584. break;
  585. case HardLink:
  586. varbufreset(&hardlinkfn);
  587. varbufaddstr(&hardlinkfn,instdir); varbufaddc(&hardlinkfn,'/');
  588. varbufaddstr(&hardlinkfn,ti->LinkName); varbufaddc(&hardlinkfn,0);
  589. if (link(hardlinkfn.buf,fnamenewvb.buf))
  590. ohshite(_("error creating hard link `%.255s'"),ti->Name);
  591. debug(dbg_eachfiledetail,"tarobject HardLink");
  592. newtarobject_allmodes(fnamenewvb.buf,ti, nifd->namenode->statoverride);
  593. break;
  594. case SymbolicLink:
  595. /* We've already cheched for an existing directory. */
  596. if (symlink(ti->LinkName,fnamenewvb.buf))
  597. ohshite(_("error creating symbolic link `%.255s'"),ti->Name);
  598. debug(dbg_eachfiledetail,"tarobject SymbolicLink creating");
  599. #ifdef HAVE_LCHOWN
  600. if (lchown(fnamenewvb.buf,
  601. nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->UserID,
  602. nifd->namenode->statoverride ? nifd->namenode->statoverride->gid : ti->GroupID))
  603. ohshite(_("error setting ownership of symlink `%.255s'"),ti->Name);
  604. #else
  605. if (chown(fnamenewvb.buf,
  606. nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->UserID,
  607. nifd->namenode->statoverride ? nifd->namenode->statoverride->gid : ti->GroupID))
  608. ohshite(_("error setting ownership of symlink `%.255s'"),ti->Name);
  609. #endif
  610. break;
  611. case Directory:
  612. /* We've already checked for an existing directory. */
  613. if (mkdir(fnamenewvb.buf,0))
  614. ohshite(_("error creating directory `%.255s'"),ti->Name);
  615. debug(dbg_eachfiledetail,"tarobject Directory creating");
  616. newtarobject_allmodes(fnamenewvb.buf,ti,nifd->namenode->statoverride);
  617. break;
  618. default:
  619. internerr("bad tar type, but already checked");
  620. }
  621. /* CLEANUP: Now we have extracted the new object in .dpkg-new (or,
  622. * if the file already exists as a directory and we were trying to extract
  623. * a directory or symlink, we returned earlier, so we don't need
  624. * to worry about that here).
  625. *
  626. * The old file is still in the original filename,
  627. */
  628. /* First, check to see if it's a conffile. If so we don't install
  629. * it now - we leave it in .dpkg-new for --configure to take care of
  630. */
  631. if (nifd->namenode->flags & fnnf_new_conff) {
  632. debug(dbg_conffdetail,"tarobject conffile extracted");
  633. nifd->namenode->flags |= fnnf_elide_other_lists;
  634. return 0;
  635. }
  636. /* Now we move the old file out of the way, the backup file will
  637. * be deleted later.
  638. */
  639. if (statr) { /* Don't try to back it up if it didn't exist. */
  640. debug(dbg_eachfiledetail,"tarobject new - no backup");
  641. } else {
  642. if (ti->Type == Directory || S_ISDIR(stab.st_mode)) {
  643. /* One of the two is a directory - can't do atomic install. */
  644. debug(dbg_eachfiledetail,"tarobject directory, nonatomic");
  645. nifd->namenode->flags |= fnnf_no_atomic_overwrite;
  646. if (rename(fnamevb.buf,fnametmpvb.buf))
  647. ohshite(_("unable to move aside `%.255s' to install new version"),ti->Name);
  648. } else if (S_ISLNK(stab.st_mode)) {
  649. /* We can't make a symlink with two hardlinks, so we'll have to copy it.
  650. * (Pretend that making a copy of a symlink is the same as linking to it.)
  651. */
  652. varbufreset(&symlinkfn);
  653. do {
  654. varbufextend(&symlinkfn);
  655. r= readlink(fnamevb.buf,symlinkfn.buf,symlinkfn.size);
  656. if (r<0) ohshite(_("unable to read link `%.255s'"),ti->Name);
  657. } while (r == symlinkfn.size);
  658. symlinkfn.used= r; varbufaddc(&symlinkfn,0);
  659. if (symlink(symlinkfn.buf,fnametmpvb.buf))
  660. ohshite(_("unable to make backup symlink for `%.255s'"),ti->Name);
  661. #ifdef HAVE_LCHOWN
  662. if (lchown(fnametmpvb.buf,stab.st_uid,stab.st_gid))
  663. ohshite(_("unable to chown backup symlink for `%.255s'"),ti->Name);
  664. #else
  665. if (chown(fnametmpvb.buf,stab.st_uid,stab.st_gid))
  666. ohshite(_("unable to chown backup symlink for `%.255s'"),ti->Name);
  667. #endif
  668. } else {
  669. debug(dbg_eachfiledetail,"tarobject nondirectory, `link' backup");
  670. if (link(fnamevb.buf,fnametmpvb.buf))
  671. ohshite(_("unable to make backup link of `%.255s' before installing new version"),
  672. ti->Name);
  673. }
  674. }
  675. /* CLEANUP: now the old file is in dpkg-tmp, and the new file is still
  676. * in dpkg-new.
  677. */
  678. #ifdef WITH_SELINUX
  679. /*
  680. * if selinux is enabled, try and set the default security context
  681. * for the renamed file
  682. */
  683. if (selinux_enabled > 0)
  684. if(scontext) {
  685. if(setfscreatecon(scontext) < 0)
  686. perror("Error setting security context for next file object:");
  687. freecon(scontext);
  688. }
  689. #endif /* WITH_SELINUX */
  690. if (rename(fnamenewvb.buf,fnamevb.buf))
  691. ohshite(_("unable to install new version of `%.255s'"),ti->Name);
  692. /* CLEANUP: now the new file is in the destination file, and the
  693. * old file is in dpkg-tmp to be cleaned up later. We now need
  694. * to take a different attitude to cleanup, because we need to
  695. * remove the new file.
  696. */
  697. nifd->namenode->flags |= fnnf_placed_on_disk;
  698. #ifdef WITH_SELINUX
  699. /*
  700. * if selinux is enabled, restore the default security context
  701. */
  702. if (selinux_enabled > 0)
  703. if(setfscreatecon(NULL) < 0)
  704. perror("Error restoring default security context:");
  705. #endif /* WITH_SELINUX */
  706. nifd->namenode->flags |= fnnf_elide_other_lists;
  707. debug(dbg_eachfiledetail,"tarobject done and installed");
  708. return 0;
  709. }
  710. static int try_remove_can(struct deppossi *pdep,
  711. struct pkginfo *fixbyrm,
  712. const char *why) {
  713. struct packageinlist *newdeconf;
  714. if (force_depends(pdep)) {
  715. fprintf(stderr, _("dpkg: warning - "
  716. "ignoring dependency problem with removal of %s:\n%s"),
  717. fixbyrm->name, why);
  718. return 1;
  719. } else if (f_autodeconf) {
  720. if (pdep->up->up->installed.essential) {
  721. if (fc_removeessential) {
  722. fprintf(stderr, _("dpkg: warning - considering deconfiguration of essential\n"
  723. " package %s, to enable removal of %s.\n"),
  724. pdep->up->up->name,fixbyrm->name);
  725. } else {
  726. fprintf(stderr, _("dpkg: no, %s is essential, will not deconfigure\n"
  727. " it in order to enable removal of %s.\n"),
  728. pdep->up->up->name,fixbyrm->name);
  729. return 0;
  730. }
  731. }
  732. pdep->up->up->clientdata->istobe= itb_deconfigure;
  733. newdeconf= malloc(sizeof(struct packageinlist));
  734. newdeconf->next= deconfigure;
  735. newdeconf->pkg= pdep->up->up;
  736. deconfigure= newdeconf;
  737. return 1;
  738. } else {
  739. fprintf(stderr, _("dpkg: no, cannot remove %s (--auto-deconfigure will help):\n%s"),
  740. fixbyrm->name, why);
  741. return 0;
  742. }
  743. }
  744. void check_conflict(struct dependency *dep, struct pkginfo *pkg,
  745. const char *pfilename) {
  746. struct pkginfo *fixbyrm;
  747. struct deppossi *pdep, flagdeppossi;
  748. struct varbuf conflictwhy, removalwhy;
  749. struct dependency *providecheck;
  750. varbufinit(&conflictwhy);
  751. varbufinit(&removalwhy);
  752. fixbyrm= 0;
  753. if (depisok(dep, &conflictwhy, &fixbyrm, 0)) {
  754. varbuffree(&conflictwhy);
  755. varbuffree(&removalwhy);
  756. return;
  757. }
  758. if (fixbyrm) {
  759. ensure_package_clientdata(fixbyrm);
  760. if (fixbyrm->clientdata->istobe == itb_installnew) {
  761. fixbyrm= dep->up;
  762. ensure_package_clientdata(fixbyrm);
  763. }
  764. if (((pkg->available.essential && fixbyrm->installed.essential) ||
  765. (((fixbyrm->want != want_install && fixbyrm->want != want_hold) ||
  766. does_replace(pkg,&pkg->available,fixbyrm)) &&
  767. (!fixbyrm->installed.essential || fc_removeessential)))) {
  768. assert(fixbyrm->clientdata->istobe == itb_normal || fixbyrm->clientdata->istobe == itb_deconfigure);
  769. fixbyrm->clientdata->istobe= itb_remove;
  770. fprintf(stderr, _("dpkg: considering removing %s in favour of %s ...\n"),
  771. fixbyrm->name, pkg->name);
  772. if (fixbyrm->status != stat_installed) {
  773. fprintf(stderr,
  774. _("%s is not properly installed - ignoring any dependencies on it.\n"),
  775. fixbyrm->name);
  776. pdep= 0;
  777. } else {
  778. for (pdep= fixbyrm->installed.depended;
  779. pdep;
  780. pdep= pdep->nextrev) {
  781. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends)
  782. continue;
  783. if (depisok(pdep->up, &removalwhy, 0,0)) continue;
  784. varbufaddc(&removalwhy,0);
  785. if (!try_remove_can(pdep,fixbyrm,removalwhy.buf))
  786. break;
  787. }
  788. if (!pdep) {
  789. /* If we haven't found a reason not to yet, let's look some more. */
  790. for (providecheck= fixbyrm->installed.depends;
  791. providecheck;
  792. providecheck= providecheck->next) {
  793. if (providecheck->type != dep_provides) continue;
  794. for (pdep= providecheck->list->ed->installed.depended;
  795. pdep;
  796. pdep= pdep->nextrev) {
  797. if (pdep->up->type != dep_depends && pdep->up->type != dep_predepends)
  798. continue;
  799. if (depisok(pdep->up, &removalwhy, 0,0)) continue;
  800. varbufaddc(&removalwhy,0);
  801. fprintf(stderr, _("dpkg"
  802. ": may have trouble removing %s, as it provides %s ...\n"),
  803. fixbyrm->name, providecheck->list->ed->name);
  804. if (!try_remove_can(pdep,fixbyrm,removalwhy.buf))
  805. goto break_from_both_loops_at_once;
  806. }
  807. }
  808. break_from_both_loops_at_once:;
  809. }
  810. }
  811. if (!pdep && skip_due_to_hold(fixbyrm)) {
  812. pdep= &flagdeppossi;
  813. }
  814. if (!pdep && (fixbyrm->eflag & eflagf_reinstreq)) {
  815. if (fc_removereinstreq) {
  816. fprintf(stderr, _("dpkg: package %s requires reinstallation, but will"
  817. " remove anyway as you request.\n"), fixbyrm->name);
  818. } else {
  819. fprintf(stderr, _("dpkg: package %s requires reinstallation, "
  820. "will not remove.\n"), fixbyrm->name);
  821. pdep= &flagdeppossi;
  822. }
  823. }
  824. if (!pdep) {
  825. /* if this gets triggered, it means a package has > 10 conflicts/replaces
  826. * pairs, which is the package's fault
  827. */
  828. assert(cflict_index < (int)sizeof(conflictor));
  829. /* This conflict is OK - we'll remove the conflictor. */
  830. conflictor[cflict_index++]= fixbyrm;
  831. varbuffree(&conflictwhy); varbuffree(&removalwhy);
  832. fprintf(stderr, _("dpkg: yes, will remove %s in favour of %s.\n"),
  833. fixbyrm->name, pkg->name);
  834. return;
  835. }
  836. fixbyrm->clientdata->istobe= itb_normal; /* put it back */
  837. }
  838. }
  839. varbufaddc(&conflictwhy,0);
  840. fprintf(stderr, _("dpkg: regarding %s containing %s:\n%s"),
  841. pfilename, pkg->name, conflictwhy.buf);
  842. if (!force_conflicts(dep->list))
  843. ohshit(_("conflicting packages - not installing %.250s"),pkg->name);
  844. fprintf(stderr, _("dpkg: warning - ignoring conflict, may proceed anyway !\n"));
  845. varbuffree(&conflictwhy);
  846. return;
  847. }
  848. void cu_cidir(int argc, void **argv) {
  849. char *cidir= (char*)argv[0];
  850. char *cidirrest= (char*)argv[1];
  851. cidirrest[-1]= 0;
  852. ensure_pathname_nonexisting(cidir);
  853. }
  854. void cu_fileslist(int argc, void **argv) {
  855. destroyobstack();
  856. }
  857. void archivefiles(const char *const *argv) {
  858. const char *volatile thisarg;
  859. const char *const *volatile argp;
  860. jmp_buf ejbuf;
  861. int pi[2], fc, nfiles, c, i, r;
  862. FILE *pf;
  863. static struct varbuf findoutput;
  864. const char **arglist;
  865. char *p;
  866. modstatdb_init(admindir,
  867. f_noact ? msdbrw_readonly
  868. : cipaction->arg == act_avail ? msdbrw_write
  869. : fc_nonroot ? msdbrw_write
  870. : msdbrw_needsuperuser);
  871. checkpath();
  872. if (f_recursive) {
  873. if (!*argv)
  874. badusage(_("--%s --recursive needs at least one path argument"),cipaction->olong);
  875. m_pipe(pi);
  876. if (!(fc= m_fork())) {
  877. const char *const *ap;
  878. char **narglist;
  879. int i;
  880. m_dup2(pi[1],1); close(pi[0]); close(pi[1]);
  881. for (i=0, ap=argv; *ap; ap++, i++);
  882. narglist= m_malloc(sizeof(char*)*(i+15));
  883. narglist[0]= strdup(FIND);
  884. for (i=1, ap=argv; *ap; ap++, i++) {
  885. if (strchr(FIND_EXPRSTARTCHARS,(*ap)[0])) {
  886. char *a;
  887. a= m_malloc(strlen(*ap)+10);
  888. strcpy(a,"./");
  889. strcat(a,*ap);
  890. narglist[i]= a;
  891. } else {
  892. narglist[i]= strdup(*ap);
  893. }
  894. }
  895. narglist[i++]= strdup("-follow"); /* When editing these, make sure that */
  896. narglist[i++]= strdup("-name"); /* arglist is mallocd big enough, above. */
  897. narglist[i++]= strdup(ARCHIVE_FILENAME_PATTERN);
  898. narglist[i++]= strdup("-type");
  899. narglist[i++]= strdup("f");
  900. narglist[i++]= strdup("-print0");
  901. narglist[i++]= 0;
  902. execvp(FIND, narglist);
  903. ohshite(_("failed to exec find for --recursive"));
  904. }
  905. close(pi[1]);
  906. nfiles= 0;
  907. pf= fdopen(pi[0],"r"); if (!pf) ohshite(_("failed to fdopen find's pipe"));
  908. varbufreset(&findoutput);
  909. while ((c= fgetc(pf)) != EOF) {
  910. varbufaddc(&findoutput,c);
  911. if (!c) nfiles++;
  912. }
  913. if (ferror(pf)) ohshite(_("error reading find's pipe"));
  914. if (fclose(pf)) ohshite(_("error closing find's pipe"));
  915. r= waitsubproc(fc,"find",PROCNOERR);
  916. if(!(r==0 || r==1))
  917. ohshit(_("find for --recursive returned unhandled error %i"),r);
  918. if (!nfiles)
  919. ohshit(_("searched, but found no packages (files matching *.deb)"));
  920. varbufaddc(&findoutput,0);
  921. varbufaddc(&findoutput,0);
  922. arglist= m_malloc(sizeof(char*)*(nfiles+1));
  923. p= findoutput.buf; i=0;
  924. while (*p) {
  925. arglist[i++]= p;
  926. while ((c= *p++) != 0);
  927. }
  928. arglist[i]= 0;
  929. argp= arglist;
  930. } else {
  931. if (!*argv) badusage(_("--%s needs at least one package archive file argument"),
  932. cipaction->olong);
  933. argp= argv;
  934. }
  935. currenttime= time(0);
  936. varbufinit(&fnamevb);
  937. varbufinit(&fnametmpvb);
  938. varbufinit(&fnamenewvb);
  939. varbufaddstr(&fnamevb,instdir); varbufaddc(&fnamevb,'/');
  940. varbufaddstr(&fnametmpvb,instdir); varbufaddc(&fnametmpvb,'/');
  941. varbufaddstr(&fnamenewvb,instdir); varbufaddc(&fnamenewvb,'/');
  942. fnameidlu= fnamevb.used;
  943. ensure_diversions();
  944. ensure_statoverrides();
  945. while ((thisarg= *argp++) != 0) {
  946. if (setjmp(ejbuf)) {
  947. error_unwind(ehflag_bombout);
  948. if (onerr_abort > 0) break;
  949. continue;
  950. }
  951. push_error_handler(&ejbuf,print_error_perpackage,thisarg);
  952. process_archive(thisarg);
  953. onerr_abort++;
  954. if (ferror(stdout)) werr("stdout");
  955. if (ferror(stderr)) werr("stderr");
  956. onerr_abort--;
  957. set_error_display(0,0);
  958. error_unwind(ehflag_normaltidy);
  959. }
  960. switch (cipaction->arg) {
  961. case act_install:
  962. case act_configure:
  963. case act_remove:
  964. case act_purge:
  965. process_queue();
  966. case act_unpack:
  967. case act_avail:
  968. break;
  969. default:
  970. internerr("unknown action");
  971. }
  972. modstatdb_shutdown();
  973. }
  974. int wanttoinstall(struct pkginfo *pkg, const struct versionrevision *ver, int saywhy) {
  975. /* Decide whether we want to install a new version of the package.
  976. * ver is the version we might want to install. If saywhy is 1 then
  977. * if we skip the package we say what we are doing (and, if we are
  978. * selecting a previously deselected package, say so and actually do
  979. * the select). want_install returns 0 if the package should be
  980. * skipped and 1 if it should be installed.
  981. *
  982. * ver may be 0, in which case saywhy must be 0 and want_install may
  983. * also return -1 to mean it doesn't know because it would depend on
  984. * the version number.
  985. */
  986. enum versiondisplayepochwhen needepochs;
  987. int r;
  988. if (pkg->want != want_install && pkg->want != want_hold) {
  989. if (f_alsoselect) {
  990. if (saywhy) {
  991. printf(_("Selecting previously deselected package %s.\n"),pkg->name);
  992. pkg->want= want_install;
  993. }
  994. return 1;
  995. } else {
  996. if (saywhy) printf(_("Skipping deselected package %s.\n"),pkg->name);
  997. return 0;
  998. }
  999. }
  1000. if (pkg->status != stat_installed) return 1;
  1001. if (!ver) return -1;
  1002. r= versioncompare(ver,&pkg->installed.version);
  1003. if (r > 0) {
  1004. return 1;
  1005. } else if (r == 0) {
  1006. if (f_skipsame && /* same version fully installed ? */
  1007. pkg->status == stat_installed && !(pkg->eflag &= eflagf_reinstreq)) {
  1008. if (saywhy) fprintf(stderr, _("Version %.250s of %.250s already installed, "
  1009. "skipping.\n"),
  1010. versiondescribe(&pkg->installed.version,vdew_never),
  1011. pkg->name);
  1012. return 0;
  1013. } else {
  1014. return 1;
  1015. }
  1016. } else {
  1017. needepochs= epochsdiffer(&pkg->available.version,&pkg->installed.version) ?
  1018. vdew_always : vdew_never;
  1019. if (fc_downgrade) {
  1020. if (saywhy) fprintf(stderr, _("%s - warning: downgrading %.250s "
  1021. "from %.250s to %.250s.\n"), DPKG, pkg->name,
  1022. versiondescribe(&pkg->installed.version,needepochs),
  1023. versiondescribe(&pkg->available.version,needepochs));
  1024. return 1;
  1025. } else {
  1026. if (saywhy) fprintf(stderr, _("Will not downgrade %.250s from version %.250s "
  1027. "to %.250s, skipping.\n"), pkg->name,
  1028. versiondescribe(&pkg->installed.version,needepochs),
  1029. versiondescribe(&pkg->available.version,needepochs));
  1030. return 0;
  1031. }
  1032. }
  1033. }
  1034. struct fileinlist *newconff_append(struct fileinlist ***newconffileslastp_io,
  1035. struct filenamenode *namenode) {
  1036. struct fileinlist *newconff;
  1037. newconff= m_malloc(sizeof(struct fileinlist));
  1038. newconff->next= 0;
  1039. newconff->namenode= namenode;
  1040. **newconffileslastp_io= newconff;
  1041. *newconffileslastp_io= &newconff->next;
  1042. return newconff;
  1043. }
  1044. /* vi: ts=8 sw=2
  1045. */