1 /*
2  * dpkg - main program for package management
3  * main.h - external definitions for this program
4  *
5  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6  * Copyright © 2006, 2008-2016 Guillem Jover <guillem@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 published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This is distributed in the hope that it will be useful,
14  * but 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 License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef MAIN_H
23 #define MAIN_H
24 
25 #include <dpkg/debug.h>
26 #include <dpkg/pkg-list.h>
27 
28 #include "force.h"
29 
30 /* These two are defined in <dpkg/fsys.h>. */
31 struct fsys_namenode_list;
32 struct fsys_namenode;
33 
34 enum pkg_istobe {
35 	/** Package is to be left in a normal state. */
36 	PKG_ISTOBE_NORMAL,
37 	/** Package is to be removed. */
38 	PKG_ISTOBE_REMOVE,
39 	/** Package is to be installed, configured or triggered. */
40 	PKG_ISTOBE_INSTALLNEW,
41 	/** Package is to be deconfigured. */
42 	PKG_ISTOBE_DECONFIGURE,
43 	/** Package is to be checked for Pre-Depends satisfiability. */
44 	PKG_ISTOBE_PREINSTALL,
45 };
46 
47 enum pkg_cycle_color {
48 	PKG_CYCLE_WHITE,
49 	PKG_CYCLE_GRAY,
50 	PKG_CYCLE_BLACK,
51 };
52 
53 struct perpackagestate {
54   enum pkg_istobe istobe;
55 
56   /** Used during cycle detection. */
57   enum pkg_cycle_color color;
58 
59   bool enqueued;
60 
61   int replacingfilesandsaid;
62   int cmdline_seen;
63 
64   /** Non-NULL iff in trigproc.c:deferred. */
65   struct pkg_list *trigprocdeferred;
66 };
67 
68 enum action {
69 	act_unset,
70 
71 	act_unpack,
72 	act_configure,
73 	act_install,
74 	act_triggers,
75 	act_remove,
76 	act_purge,
77 	act_verify,
78 	act_commandfd,
79 
80 	act_status,
81 	act_listpackages,
82 	act_listfiles,
83 	act_searchfiles,
84 	act_controlpath,
85 	act_controllist,
86 	act_controlshow,
87 
88 	act_cmpversions,
89 
90 	act_arch_add,
91 	act_arch_remove,
92 	act_printarch,
93 	act_printforeignarches,
94 
95 	act_assertpredep,
96 	act_assertepoch,
97 	act_assertlongfilenames,
98 	act_assertmulticonrep,
99 	act_assertmultiarch,
100 	act_assertverprovides,
101 
102 	act_validate_pkgname,
103 	act_validate_trigname,
104 	act_validate_archname,
105 	act_validate_version,
106 
107 	act_audit,
108 	act_unpackchk,
109 	act_predeppackage,
110 
111 	act_getselections,
112 	act_setselections,
113 	act_clearselections,
114 
115 	act_avail,
116 	act_printavail,
117 	act_avclear,
118 	act_avreplace,
119 	act_avmerge,
120 	act_forgetold,
121 };
122 
123 extern const char *const statusstrings[];
124 
125 extern int f_pending, f_recursive, f_alsoselect, f_skipsame, f_noact;
126 extern int f_autodeconf, f_nodebsig;
127 extern int f_triggers;
128 
129 extern bool abort_processing;
130 extern int errabort;
131 extern const char *instdir;
132 extern struct pkg_list *ignoredependss;
133 
134 struct invoke_hook {
135 	struct invoke_hook *next;
136 	char *command;
137 };
138 
139 struct invoke_list {
140 	struct invoke_hook *head, **tail;
141 };
142 
143 /* from perpkgstate.c */
144 
145 void ensure_package_clientdata(struct pkginfo *pkg);
146 
147 /* from archives.c */
148 
149 int archivefiles(const char *const *argv);
150 void process_archive(const char *filename);
151 bool wanttoinstall(struct pkginfo *pkg);
152 
153 /* from update.c */
154 
155 int forgetold(const char *const *argv);
156 int updateavailable(const char *const *argv);
157 
158 /* from enquiry.c */
159 
160 int audit(const char *const *argv);
161 int unpackchk(const char *const *argv);
162 int assertepoch(const char *const *argv);
163 int assertpredep(const char *const *argv);
164 int assertlongfilenames(const char *const *argv);
165 int assertmulticonrep(const char *const *argv);
166 int assertmultiarch(const char *const *argv);
167 int assertverprovides(const char *const *argv);
168 int validate_pkgname(const char *const *argv);
169 int validate_trigname(const char *const *argv);
170 int validate_archname(const char *const *argv);
171 int validate_version(const char *const *argv);
172 int predeppackage(const char *const *argv);
173 int printarch(const char *const *argv);
174 int printinstarch(const char *const *argv);
175 int print_foreign_arches(const char *const *argv);
176 int cmpversions(const char *const *argv);
177 
178 /* from verify.c */
179 
180 bool verify_set_output(const char *name);
181 int verify(const char *const *argv);
182 
183 /* from select.c */
184 
185 int getselections(const char *const *argv);
186 int setselections(const char *const *argv);
187 int clearselections(const char *const *argv);
188 
189 /* from packages.c, remove.c and configure.c */
190 
191 void md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn);
192 void enqueue_package(struct pkginfo *pkg);
193 void enqueue_package_mark_seen(struct pkginfo *pkg);
194 void process_queue(void);
195 int packages(const char *const *argv);
196 void removal_bulk(struct pkginfo *pkg);
197 int conffderef(struct pkginfo *pkg, struct varbuf *result, const char *in);
198 
199 enum dep_check {
200   DEP_CHECK_HALT = 0,
201   DEP_CHECK_DEFER = 1,
202   DEP_CHECK_OK = 2,
203 };
204 
205 enum dep_check dependencies_ok(struct pkginfo *pkg, struct pkginfo *removing,
206                                struct varbuf *aemsgs);
207 enum dep_check breakses_ok(struct pkginfo *pkg, struct varbuf *aemsgs);
208 
209 void deferred_remove(struct pkginfo *pkg);
210 void deferred_configure(struct pkginfo *pkg);
211 
212 /*
213  * During the packages queue processing, the algorithm for deciding what to
214  * configure first is as follows:
215  *
216  * Loop through all packages doing a ‘try 1’ until we've been round and
217  * nothing has been done, then do ‘try 2’, and subsequent ones likewise.
218  * The incrementing of ‘dependtry’ is done by process_queue().
219  *
220  * Try 1:
221  *   Are all dependencies of this package done? If so, do it.
222  *   Are any of the dependencies missing or the wrong version?
223  *     If so, abort (unless --force-depends, in which case defer).
224  *   Will we need to configure a package we weren't given as an
225  *     argument? If so, abort ─ except if --force-configure-any,
226  *     in which case we add the package to the argument list.
227  *   If none of the above, defer the package.
228  *
229  * Try 2:
230  *   Find a cycle and break it (see above).
231  *   Do as for try 1.
232  *
233  * Try 3:
234  *   Start processing triggers if necessary.
235  *   Do as for try 2.
236  *
237  * Try 4:
238  *   Same as for try 3, but check trigger cycles even when deferring
239  *   processing due to unsatisfiable dependencies.
240  *
241  * Try 5 (only if --force-depends-version):
242  *   Same as for try 2, but don't mind version number in dependencies.
243  *
244  * Try 6 (only if --force-depends):
245  *   Do anyway.
246  */
247 enum dependtry {
248 	DEPEND_TRY_NORMAL = 1,
249 	DEPEND_TRY_CYCLES = 2,
250 	DEPEND_TRY_TRIGGERS = 3,
251 	DEPEND_TRY_TRIGGERS_CYCLES = 4,
252 	DEPEND_TRY_FORCE_DEPENDS_VERSION = 5,
253 	DEPEND_TRY_FORCE_DEPENDS = 6,
254 	DEPEND_TRY_LAST,
255 };
256 
257 extern enum dependtry dependtry;
258 extern int sincenothing;
259 
260 /* from cleanup.c (most of these are declared in archives.h) */
261 
262 void cu_prermremove(int argc, void **argv);
263 
264 /* from errors.c */
265 
266 void print_error_perpackage(const char *emsg, const void *data);
267 void print_error_perarchive(const char *emsg, const void *data);
268 int reportbroken_retexitstatus(int ret);
269 bool skip_due_to_hold(struct pkginfo *pkg);
270 
271 /* from help.c */
272 
273 struct stat;
274 
275 bool ignore_depends(struct pkginfo *pkg);
276 bool force_breaks(struct deppossi *possi);
277 bool force_depends(struct deppossi *possi);
278 bool force_conflicts(struct deppossi *possi);
279 void
280 conffile_mark_obsolete(struct pkginfo *pkg, struct fsys_namenode *namenode);
281 void pkg_conffiles_mark_old(struct pkginfo *pkg);
282 bool find_command(const char *prog);
283 void checkpath(void);
284 
285 struct fsys_namenode *
286 namenodetouse(struct fsys_namenode *namenode,
287               struct pkginfo *pkg, struct pkgbin *pkgbin);
288 
289 int maintscript_installed(struct pkginfo *pkg, const char *scriptname,
290                           const char *desc, ...) DPKG_ATTR_SENTINEL;
291 int maintscript_new(struct pkginfo *pkg,
292                     const char *scriptname, const char *desc,
293                     const char *cidir, char *cidirrest, ...)
294 	DPKG_ATTR_SENTINEL;
295 int maintscript_fallback(struct pkginfo *pkg,
296                          const char *scriptname, const char *desc,
297                          const char *cidir, char *cidirrest,
298                          const char *ifok, const char *iffallback);
299 
300 /* Callers wanting to run the postinst use these two as they want to postpone
301  * trigger incorporation until after updating the package status. The effect
302  * is that a package can trigger itself. */
303 int maintscript_postinst(struct pkginfo *pkg, ...) DPKG_ATTR_SENTINEL;
304 void post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status);
305 
306 void clear_istobes(void);
307 bool
308 dir_is_used_by_others(struct fsys_namenode *namenode, struct pkginfo *pkg);
309 bool
310 dir_is_used_by_pkg(struct fsys_namenode *namenode, struct pkginfo *pkg,
311                    struct fsys_namenode_list *list);
312 bool
313 dir_has_conffiles(struct fsys_namenode *namenode, struct pkginfo *pkg);
314 
315 void log_action(const char *action, struct pkginfo *pkg, struct pkgbin *pkgbin);
316 
317 /* From selinux.c */
318 
319 void dpkg_selabel_load(void);
320 void dpkg_selabel_set_context(const char *matchpath, const char *path, mode_t mode);
321 void dpkg_selabel_close(void);
322 
323 /* from trigproc.c */
324 
325 enum trigproc_type {
326 	/** Opportunistic deferred trigger processing. */
327 	TRIGPROC_TRY_DEFERRED,
328 	/** Opportunistic queued trigger processing. */
329 	TRIGPROC_TRY_QUEUED,
330 	/** Required trigger processing. */
331 	TRIGPROC_REQUIRED,
332 };
333 
334 void trigproc_install_hooks(void);
335 void trigproc_populate_deferred(void);
336 void trigproc_run_deferred(void);
337 void trigproc_reset_cycle(void);
338 
339 void trigproc(struct pkginfo *pkg, enum trigproc_type type);
340 
341 void trig_activate_packageprocessing(struct pkginfo *pkg);
342 
343 /* from depcon.c */
344 
345 enum which_pkgbin {
346   wpb_installed,
347   wpb_available,
348   wpb_by_istobe,
349 };
350 
351 struct deppossi_pkg_iterator;
352 
353 struct deppossi_pkg_iterator *
354 deppossi_pkg_iter_new(struct deppossi *possi, enum which_pkgbin wpb);
355 struct pkginfo *
356 deppossi_pkg_iter_next(struct deppossi_pkg_iterator *iter);
357 void
358 deppossi_pkg_iter_free(struct deppossi_pkg_iterator *iter);
359 
360 bool depisok(struct dependency *dep, struct varbuf *whynot,
361              struct pkginfo **fixbyrm, struct pkginfo **fixbytrigaw,
362              bool allowunconfigd);
363 struct cyclesofarlink;
364 bool findbreakcycle(struct pkginfo *pkg);
365 void describedepcon(struct varbuf *addto, struct dependency *dep);
366 
367 #endif /* MAIN_H */
368