dpkg.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * dpkg.h - general header for Debian package handling
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2000,2001 Wichert Akkerman <wichert@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. #ifndef DPKG_H
  23. #define DPKG_H
  24. #include <setjmp.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <myopt.h>
  29. #include <dpkg-def.h>
  30. #ifdef HAVE_SYS_CDEFS_H
  31. #include <sys/cdefs.h>
  32. #endif
  33. #ifdef HAVE_STDDEF_H
  34. #include <stddef.h>
  35. #endif
  36. #ifdef PATH_MAX
  37. # define INTERPRETER_MAX PATH_MAX
  38. #else
  39. # define INTERPRETER_MAX 1024
  40. #endif
  41. #define ARCHIVEVERSION "2.0"
  42. #define SPLITVERSION "2.1"
  43. #define OLDARCHIVEVERSION "0.939000"
  44. #define SPLITPARTDEFMAX (450*1024)
  45. #define MAXFIELDNAME 200
  46. #define MAXCONFFILENAME 1000
  47. #define MAXDIVERTFILENAME 1024
  48. #define MAXCONTROLFILENAME 100
  49. #define BUILDCONTROLDIR "DEBIAN"
  50. #define EXTRACTCONTROLDIR BUILDCONTROLDIR
  51. #define DEBEXT ".deb"
  52. #define OLDDBEXT "-old"
  53. #define NEWDBEXT "-new"
  54. #define OLDOLDDEBDIR ".DEBIAN"
  55. #define OLDDEBDIR "DEBIAN"
  56. #define REMOVECONFFEXTS "~", ".bak", "%", \
  57. DPKGTEMPEXT, DPKGNEWEXT, DPKGOLDEXT, DPKGDISTEXT
  58. #ifndef ARCHBINFMT
  59. #define ARCHBINFMT
  60. #endif
  61. #define DPKG_VERSION_ARCH PACKAGE_VERSION " (" ARCHITECTURE ARCHBINFMT ")"
  62. #define NEWCONFFILEFLAG "newconffile"
  63. #define NONEXISTENTFLAG "nonexistent"
  64. #define DPKGTEMPEXT ".dpkg-tmp"
  65. #define DPKGNEWEXT ".dpkg-new"
  66. #define DPKGOLDEXT ".dpkg-old"
  67. #define DPKGDISTEXT ".dpkg-dist"
  68. #define CONTROLFILE "control"
  69. #define CONFFILESFILE "conffiles"
  70. #define PREINSTFILE "preinst"
  71. #define POSTINSTFILE "postinst"
  72. #define PRERMFILE "prerm"
  73. #define POSTRMFILE "postrm"
  74. #define LISTFILE "list"
  75. #define TRIGGERSCIFILE "triggers"
  76. #define STATUSFILE "status"
  77. #define AVAILFILE "available"
  78. #define LOCKFILE "lock"
  79. #define CMETHOPTFILE "cmethopt"
  80. #define METHLOCKFILE "methlock"
  81. #define DIVERSIONSFILE "diversions"
  82. #define STATOVERRIDEFILE "statoverride"
  83. #define UPDATESDIR "updates/"
  84. #define INFODIR "info/"
  85. #define PARTSDIR "parts/"
  86. #define TRIGGERSDIR "triggers/"
  87. #define TRIGGERSFILEFILE "File"
  88. #define TRIGGERSDEFERREDFILE "Unincorp"
  89. #define TRIGGERSLOCKFILE "Lock"
  90. #define CONTROLDIRTMP "tmp.ci/"
  91. #define IMPORTANTTMP "tmp.i"
  92. #define REASSEMBLETMP "reassemble" DEBEXT
  93. #define IMPORTANTMAXLEN 10
  94. #define IMPORTANTFMT "%04d" /* change => also change lib/database.c:cleanup_updates */
  95. #define MAXUPDATES 250
  96. #define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
  97. #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
  98. #define LOCALLIBDIR "/usr/local/lib/dpkg"
  99. #define METHODSDIR "methods"
  100. #define NOJOBCTRLSTOPENV "DPKG_NO_TSTP"
  101. #define SHELLENV "SHELL"
  102. #define DEFAULTSHELL "sh"
  103. #define PAGERENV "PAGER"
  104. #define DEFAULTPAGER "pager"
  105. #define IMETHODMAXLEN 50
  106. #define IOPTIONMAXLEN IMETHODMAXLEN
  107. #define METHODOPTIONSFILE "names"
  108. #define METHODSETUPSCRIPT "setup"
  109. #define METHODUPDATESCRIPT "update"
  110. #define METHODINSTALLSCRIPT "install"
  111. #define OPTIONSDESCPFX "desc."
  112. #define OPTIONINDEXMAXLEN 5
  113. #define PKGSCRIPTMAXARGS 10
  114. #define MD5HASHLEN 32
  115. #define MAXTRIGDIRECTIVE 256
  116. #define CONFFOPTCELLS /* int conffoptcells[2] {* 1= user edited *} \
  117. [2] {* 1= distributor edited *} = */ \
  118. /* dist not */ /* dist edited */ \
  119. /* user did not edit */ { cfo_keep, cfo_install }, \
  120. /* user did edit */ { cfo_keep, cfo_prompt_keep }
  121. #define ARCHIVE_FILENAME_PATTERN "*.deb"
  122. #define BACKEND "dpkg-deb"
  123. #define DPKGQUERY "dpkg-query"
  124. #define SPLITTER "dpkg-split"
  125. #define DSELECT "dselect"
  126. #define DPKG "dpkg"
  127. #define DEBSIGVERIFY "/usr/bin/debsig-verify"
  128. #define TAR "tar"
  129. #define GZIP "gzip"
  130. #define BZIP2 "bzip2"
  131. #define LZMA "lzma"
  132. #define RM "rm"
  133. #define FIND "find"
  134. #define SHELL "sh"
  135. #define DIFF "diff"
  136. #define SHELLENVIR "SHELL"
  137. #define FIND_EXPRSTARTCHARS "-(),!"
  138. #define TARBLKSZ 512
  139. extern const char thisname[]; /* defined separately in each program */
  140. extern const char printforhelp[];
  141. /*** from startup.c ***/
  142. #define standard_startup(ejbuf, argc, argv, prog, loadcfg, cmdinfos) do {\
  143. setlocale(LC_ALL, "");\
  144. bindtextdomain(PACKAGE, LOCALEDIR);\
  145. textdomain(PACKAGE);\
  146. if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
  147. error_unwind(ehflag_bombout); exit(2);\
  148. }\
  149. push_error_handler(ejbuf, print_error_fatal, NULL); \
  150. umask(022); /* Make sure all our status databases are readable. */\
  151. if (loadcfg)\
  152. loadcfgfile(prog, cmdinfos);\
  153. myopt(argv,cmdinfos);\
  154. } while (0)
  155. #define standard_shutdown(freemem) do {\
  156. set_error_display(NULL, NULL); \
  157. error_unwind(ehflag_normaltidy);\
  158. if (freemem)\
  159. nffreeall();\
  160. } while (0)
  161. /*** from ehandle.c ***/
  162. extern volatile int onerr_abort;
  163. typedef void error_printer(const char *emsg, const char *contextstring);
  164. void push_error_handler(jmp_buf *jbufp, error_printer *printerror,
  165. const char *contextstring);
  166. void set_error_display(error_printer *printerror, const char *contextstring);
  167. void print_error_fatal(const char *emsg, const char *contextstring);
  168. void error_unwind(int flagset);
  169. void push_cleanup(void (*f1)(int argc, void **argv), int flagmask1,
  170. void (*f2)(int argc, void **argv), int flagmask2,
  171. unsigned int nargs, ...);
  172. void push_checkpoint(int mask, int value);
  173. void pop_cleanup(int flagset);
  174. enum { ehflag_normaltidy=01, ehflag_bombout=02, ehflag_recursiveerror=04 };
  175. void do_internerr(const char *string, int line, const char *file) NONRETURNING;
  176. #define internerr(s) do_internerr(s,__LINE__,__FILE__)
  177. struct varbuf;
  178. void ohshit(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  179. void ohshitv(const char *fmt, va_list al) NONRETURNING;
  180. void ohshite(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  181. void ohshitvb(struct varbuf*) NONRETURNING;
  182. void badusage(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2);
  183. void werr(const char *what) NONRETURNING;
  184. void warningf(const char *fmt, ...) PRINTFFORMAT(1, 2);
  185. /*** log.c ***/
  186. extern const char *log_file;
  187. void log_message(const char *fmt, ...) PRINTFFORMAT(1, 2);
  188. /* FIXME: pipef and status_pipes should not be publicly exposed. */
  189. struct pipef {
  190. int fd;
  191. struct pipef *next;
  192. };
  193. extern struct pipef *status_pipes;
  194. void statusfd_send(const char *fmt, ...);
  195. /*** cleanup.c ***/
  196. void cu_closefile(int argc, void **argv);
  197. void cu_closepipe(int argc, void **argv);
  198. void cu_closedir(int argc, void **argv);
  199. void cu_closefd(int argc, void **argv);
  200. /*** lock.c ***/
  201. void lock_file(int *lockfd, const char *filename,
  202. const char *emsg, const char *emsg_eagain);
  203. void unlock_file(void);
  204. /*** from mlib.c ***/
  205. void setcloexec(int fd, const char* fn);
  206. void *m_malloc(size_t);
  207. void *m_realloc(void*, size_t);
  208. char *m_strdup(const char *str);
  209. int m_fork(void);
  210. void m_dup2(int oldfd, int newfd);
  211. void m_pipe(int fds[2]);
  212. #define PROCPIPE 1
  213. #define PROCWARN 2
  214. #define PROCNOERR 4
  215. int checksubprocerr(int status, const char *description, int flags);
  216. int waitsubproc(pid_t pid, const char *description, int flags);
  217. #define BUFFER_WRITE_BUF 0
  218. #define BUFFER_WRITE_VBUF 1
  219. #define BUFFER_WRITE_FD 2
  220. #define BUFFER_WRITE_NULL 3
  221. #define BUFFER_WRITE_STREAM 4
  222. #define BUFFER_WRITE_MD5 5
  223. #define BUFFER_READ_FD 0
  224. #define BUFFER_READ_STREAM 1
  225. #define BUFFER_WRITE_SETUP 1 << 16
  226. #define BUFFER_READ_SETUP 1 << 17
  227. #define BUFFER_WRITE_SHUTDOWN 1 << 18
  228. #define BUFFER_READ_SHUTDOWN 1 << 19
  229. typedef struct buffer_data *buffer_data_t;
  230. typedef off_t (*buffer_proc_t)(buffer_data_t data, void *buf, off_t size, const char *desc);
  231. typedef union buffer_arg {
  232. void *ptr;
  233. int i;
  234. } buffer_arg;
  235. struct buffer_data {
  236. buffer_proc_t proc;
  237. buffer_arg data;
  238. int type;
  239. };
  240. #if HAVE_C99
  241. # define fd_md5(fd, hash, limit, ...)\
  242. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  243. hash, BUFFER_WRITE_MD5, NULL, \
  244. limit, __VA_ARGS__)
  245. # define stream_md5(file, hash, limit, ...)\
  246. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  247. hash, BUFFER_WRITE_MD5, NULL, \
  248. limit, __VA_ARGS__)
  249. # define fd_fd_copy(fd1, fd2, limit, ...)\
  250. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  251. fd2, BUFFER_WRITE_FD, NULL, \
  252. limit, __VA_ARGS__)
  253. # define fd_buf_copy(fd, buf, limit, ...)\
  254. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  255. buf, BUFFER_WRITE_BUF, NULL, \
  256. limit, __VA_ARGS__)
  257. # define fd_vbuf_copy(fd, buf, limit, ...)\
  258. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  259. buf, BUFFER_WRITE_VBUF, NULL, \
  260. limit, __VA_ARGS__)
  261. # define fd_null_copy(fd, limit, ...) \
  262. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  263. if(errno != ESPIPE) ohshite(__VA_ARGS__); \
  264. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  265. NULL, BUFFER_WRITE_NULL, NULL, \
  266. limit, __VA_ARGS__);\
  267. }
  268. # define stream_null_copy(file, limit, ...) \
  269. if (fseek(file, limit, SEEK_CUR) == -1) { \
  270. if(errno != EBADF) ohshite(__VA_ARGS__); \
  271. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  272. NULL, BUFFER_WRITE_NULL, NULL, \
  273. limit, __VA_ARGS__);\
  274. }
  275. # define stream_fd_copy(file, fd, limit, ...)\
  276. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  277. fd, BUFFER_WRITE_FD, NULL, \
  278. limit, __VA_ARGS__)
  279. #else /* HAVE_C99 */
  280. # define fd_md5(fd, hash, limit, desc...)\
  281. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  282. hash, BUFFER_WRITE_MD5, NULL, \
  283. limit, desc)
  284. # define stream_md5(file, hash, limit, desc...)\
  285. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  286. hash, BUFFER_WRITE_MD5, NULL, \
  287. limit, desc)
  288. # define fd_fd_copy(fd1, fd2, limit, desc...)\
  289. buffer_copy_setup_IntInt(fd1, BUFFER_READ_FD, NULL, \
  290. fd2, BUFFER_WRITE_FD, NULL, \
  291. limit, desc)
  292. # define fd_buf_copy(fd, buf, limit, desc...)\
  293. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  294. buf, BUFFER_WRITE_BUF, NULL, \
  295. limit, desc)
  296. # define fd_vbuf_copy(fd, buf, limit, desc...)\
  297. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  298. buf, BUFFER_WRITE_VBUF, NULL, \
  299. limit, desc)
  300. # define fd_null_copy(fd, limit, desc...) \
  301. if (lseek(fd, limit, SEEK_CUR) == -1) { \
  302. if(errno != ESPIPE) ohshite(desc); \
  303. buffer_copy_setup_IntPtr(fd, BUFFER_READ_FD, NULL, \
  304. NULL, BUFFER_WRITE_NULL, NULL, \
  305. limit, desc);\
  306. }
  307. # define stream_null_copy(file, limit, desc...) \
  308. if (fseek(file, limit, SEEK_CUR) == -1) { \
  309. if(errno != EBADF) ohshite(desc); \
  310. buffer_copy_setup_PtrPtr(file, BUFFER_READ_STREAM, NULL, \
  311. NULL, BUFFER_WRITE_NULL, NULL, \
  312. limit, desc);\
  313. }
  314. # define stream_fd_copy(file, fd, limit, desc...)\
  315. buffer_copy_setup_PtrInt(file, BUFFER_READ_STREAM, NULL, \
  316. fd, BUFFER_WRITE_FD, NULL, \
  317. limit, desc)
  318. #endif /* HAVE_C99 */
  319. off_t buffer_copy_setup_PtrInt(void *p, int typeIn, void *procIn,
  320. int i, int typeOut, void *procOut,
  321. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  322. off_t buffer_copy_setup_PtrPtr(void *p1, int typeIn, void *procIn,
  323. void *p2, int typeOut, void *procOut,
  324. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  325. off_t buffer_copy_setup_IntPtr(int i, int typeIn, void *procIn,
  326. void *p, int typeOut, void *procOut,
  327. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  328. off_t buffer_copy_setup_IntInt(int i1, int typeIn, void *procIn,
  329. int i2, int typeOut, void *procOut,
  330. off_t limit, const char *desc, ...) PRINTFFORMAT(8, 9);
  331. off_t buffer_copy_setup(buffer_arg argIn, int typeIn, void *procIn,
  332. buffer_arg argOut, int typeOut, void *procOut,
  333. off_t limit, const char *desc);
  334. off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc);
  335. off_t buffer_read(buffer_data_t data, void *buf, off_t length, const char *desc);
  336. off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit, const char *desc);
  337. /*** from utils.c ***/
  338. int cisdigit(int c);
  339. int cisalpha(int c);
  340. int cisspace(int c);
  341. int fgets_checked(char *buf, size_t bufsz, FILE *f, const char *fn);
  342. int fgets_must(char *buf, size_t bufsz, FILE *f, const char *fn);
  343. /*** from compression.c ***/
  344. enum compress_type {
  345. compress_type_cat,
  346. compress_type_gzip,
  347. compress_type_bzip2,
  348. compress_type_lzma,
  349. };
  350. void decompress_cat(enum compress_type type, int fd_in, int fd_out,
  351. char *desc, ...) NONRETURNING PRINTFFORMAT(4, 5);
  352. void compress_cat(enum compress_type type, int fd_in, int fd_out,
  353. const char *compression, char *desc, ...)
  354. NONRETURNING PRINTFFORMAT(5, 6);
  355. /*** from compat.c ***/
  356. #ifndef HAVE_STRERROR
  357. const char *strerror(int);
  358. #endif
  359. #ifndef HAVE_STRSIGNAL
  360. const char *strsignal(int);
  361. #endif
  362. #ifndef HAVE_SCANDIR
  363. struct dirent;
  364. int scandir(const char *dir, struct dirent ***namelist,
  365. int (*select)(const struct dirent *),
  366. int (*compar)(const void*, const void*));
  367. #endif
  368. #ifndef HAVE_ALPHASORT
  369. struct dirent;
  370. int alphasort(const struct dirent *a, const struct dirent *b);
  371. #endif
  372. #ifndef HAVE_UNSETENV
  373. void unsetenv(const char *x);
  374. #endif
  375. /*** other compatibility functions ***/
  376. #ifndef offsetof
  377. #define offsetof(st, m) ((size_t)&((st *)NULL)->m)
  378. #endif
  379. #ifndef HAVE_STRTOUL
  380. #define strtoul strtol
  381. #endif
  382. #ifndef HAVE_VA_COPY
  383. #define va_copy(dest, src) (dest) = (src)
  384. #endif
  385. /* Define WCOREDUMP if we don't have it already - coredumps won't be
  386. * detected, though.
  387. */
  388. #ifndef WCOREDUMP
  389. #define WCOREDUMP(x) 0
  390. #endif
  391. /* Set BUILDOLDPKGFORMAT to 1 to build old-format archives by default.
  392. * */
  393. #ifndef BUILDOLDPKGFORMAT
  394. #define BUILDOLDPKGFORMAT 0
  395. #endif
  396. /* Take care of NLS matters. */
  397. #include <gettext.h>
  398. #if HAVE_LOCALE_H
  399. # include <locale.h>
  400. #endif
  401. /* Make gettext a little friendlier */
  402. #define _(String) gettext (String)
  403. #define N_(String) gettext_noop (String)
  404. #endif /* DPKG_H */