1 /* $NetBSD: lib.h,v 1.58 2009/08/16 21:10:15 joerg Exp $ */
3 /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
6 * FreeBSD install - a package for the installation and maintainance
7 * of non-core utilities.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
21 * Include and define various things wanted by the library routines.
25 #ifndef _INST_LIB_LIB_H_
26 #define _INST_LIB_LIB_H_
33 #include <sys/param.h>
42 #include <sys/queue.h>
69 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
84 #define OPSYS_NAME "NetBSD"
93 # define PATH_MAX MAXPATHLEN
95 # define PATH_MAX 1024
100 MaxPathSize
= PATH_MAX
103 /* The names of our "special" files */
104 #define CONTENTS_FNAME "+CONTENTS"
105 #define COMMENT_FNAME "+COMMENT"
106 #define DESC_FNAME "+DESC"
107 #define INSTALL_FNAME "+INSTALL"
108 #define DEINSTALL_FNAME "+DEINSTALL"
109 #define REQUIRED_BY_FNAME "+REQUIRED_BY"
110 #define REQUIRED_BY_FNAME_TMP "+REQUIRED_BY.tmp"
111 #define DISPLAY_FNAME "+DISPLAY"
112 #define MTREE_FNAME "+MTREE_DIRS"
113 #define BUILD_VERSION_FNAME "+BUILD_VERSION"
114 #define BUILD_INFO_FNAME "+BUILD_INFO"
115 #define INSTALLED_INFO_FNAME "+INSTALLED_INFO"
116 #define SIZE_PKG_FNAME "+SIZE_PKG"
117 #define SIZE_ALL_FNAME "+SIZE_ALL"
118 #define PRESERVE_FNAME "+PRESERVE"
119 #define VIEWS_FNAME "+VIEWS"
120 #define VIEWS_FNAME_TMP "+VIEWS.tmp"
121 #define DEPOT_FNAME "+DEPOT"
123 /* The names of special variables */
124 #define AUTOMATIC_VARNAME "automatic"
126 /* Prefix for extended PLIST cmd */
129 /* The name of the "prefix" environment variable given to scripts */
130 #define PKG_PREFIX_VNAME "PKG_PREFIX"
132 /* The name of the "destdir" environment variable given to scripts */
133 #define PKG_DESTDIR_VNAME "PKG_DESTDIR"
136 * The name of the "metadatadir" environment variable given to scripts.
137 * This variable holds the location of the +-files for this package.
139 #define PKG_METADATA_DIR_VNAME "PKG_METADATA_DIR"
142 * The name of the environment variable holding the location to the
143 * reference-counts database directory.
145 #define PKG_REFCOUNT_DBDIR_VNAME "PKG_REFCOUNT_DBDIR"
147 #define PKG_PATTERN_MAX MaxPathSize /* max length of pattern, including nul */
148 #define PKG_SUFFIX_MAX 10 /* max length of suffix, including nul */
156 /* Enumerated constants for plist entry types */
157 typedef enum pl_ent_t
{
165 PLIST_COMMENT
, /* 6 */
166 PLIST_IGNORE
, /* 7 */
168 PLIST_UNEXEC
, /* 9 */
170 PLIST_DISPLAY
, /* 11 */
171 PLIST_PKGDEP
, /* 12 */
172 PLIST_DIR_RM
, /* 13 */
173 PLIST_OPTION
, /* 14 */
174 PLIST_PKGCFL
, /* 15 */
175 PLIST_BLDDEP
, /* 16 */
176 PLIST_PKGDIR
/* 17 */
179 /* Enumerated constants for build info */
180 typedef enum bi_ent_t
{
182 BI_OS_VERSION
, /* 1 */
183 BI_MACHINE_ARCH
, /* 2 */
184 BI_IGNORE_RECOMMENDED
, /* 3 */
185 BI_USE_ABI_DEPENDS
, /* 4 */
187 BI_ENUM_COUNT
/* 6 */
191 typedef unsigned int Boolean
;
193 /* This structure describes a packing list entry */
194 typedef struct plist_t
{
195 struct plist_t
*prev
; /* previous entry */
196 struct plist_t
*next
; /* next entry */
197 char *name
; /* name of entry */
198 Boolean marked
; /* whether entry has been marked */
199 pl_ent_t type
; /* type of entry */
202 /* This structure describes a package's complete packing list */
203 typedef struct package_t
{
204 plist_t
*head
; /* head of list */
205 plist_t
*tail
; /* tail of list */
208 #define SYMLINK_HEADER "Symlink:"
209 #define CHECKSUM_HEADER "MD5:"
212 ChecksumHeaderLen
= 4, /* strlen(CHECKSUM_HEADER) */
213 SymlinkHeaderLen
= 8, /* strlen(SYMLINK_HEADER) */
215 LegibleChecksumLen
= 33
219 typedef struct _lfile_t
{
220 TAILQ_ENTRY(_lfile_t
) lf_link
;
223 TAILQ_HEAD(_lfile_head_t
, _lfile_t
);
224 typedef struct _lfile_head_t lfile_head_t
;
225 #define LFILE_ADD(lfhead,lfp,str) do { \
226 lfp = xmalloc(sizeof(lfile_t)); \
227 lfp->lf_name = str; \
228 TAILQ_INSERT_TAIL(lfhead,lfp,lf_link); \
231 /* List of packages */
232 typedef struct _lpkg_t
{
233 TAILQ_ENTRY(_lpkg_t
) lp_link
;
236 TAILQ_HEAD(_lpkg_head_t
, _lpkg_t
);
237 typedef struct _lpkg_head_t lpkg_head_t
;
239 struct pkg_vulnerabilities
{
241 char **vulnerability
;
242 char **classification
;
246 /* If URLlength()>0, then there is a ftp:// or http:// in the string,
247 * and this must be an URL. Hide this behind a more obvious name. */
248 #define IS_URL(str) (URLlength(str) > 0)
250 #define IS_STDIN(str) ((str) != NULL && !strcmp((str), "-"))
251 #define IS_FULLPATH(str) ((str) != NULL && (str)[0] == '/')
253 /* Conflict handling (conflicts.c) */
254 int some_installed_package_conflicts_with(const char *, const char *, char **, char **);
259 void show_version(void);
260 int fexec(const char *, ...);
261 int fexec_skipempty(const char *, ...);
262 int fcexec(const char *, const char *, ...);
263 int pfcexec(const char *, const char *, const char **);
265 /* variables file handling */
267 char *var_get(const char *, const char *);
268 char *var_get_memory(const char *, const char *);
269 int var_set(const char *, const char *, const char *);
270 int var_copy_list(const char *, const char **);
272 /* automatically installed as dependency */
274 Boolean
is_automatic_installed(const char *);
275 int mark_as_automatic_installed(const char *, int);
278 const char *basename_of(const char *);
279 const char *dirname_of(const char *);
280 const char *suffix_of(const char *);
281 int pkg_match(const char *, const char *);
282 int pkg_order(const char *, const char *, const char *);
283 int ispkgpattern(const char *);
284 int quick_pkg_match(const char *, const char *);
286 /* Iterator functions */
287 int iterate_pkg_generic_src(int (*)(const char *, void *), void *,
288 const char *(*)(void *),void *);
289 int iterate_local_pkg_dir(const char *, int, int, int (*)(const char *, void *),
291 int iterate_pkg_db(int (*)(const char *, void *), void *);
293 int add_installed_pkgs_by_basename(const char *, lpkg_head_t
*);
294 int add_installed_pkgs_by_pattern(const char *, lpkg_head_t
*);
295 char *find_best_matching_installed_pkg(const char *);
296 char *find_best_matching_file(const char *, const char *, int, int);
297 int match_installed_pkgs(const char *, int (*)(const char *, void *), void *);
298 int match_local_files(const char *, int, int, const char *, int (*cb
)(const char *, void *), void *);
301 Boolean
fexists(const char *);
302 Boolean
isdir(const char *);
303 Boolean
islinktodir(const char *);
304 Boolean
isemptydir(const char *);
305 Boolean
isemptyfile(const char *);
306 Boolean
isfile(const char *);
307 Boolean
isbrokenlink(const char *);
308 Boolean
isempty(const char *);
309 int URLlength(const char *);
310 Boolean
make_preserve_name(char *, size_t, const char *, const char *);
311 void remove_files(const char *, const char *);
312 int format_cmd(char *, size_t, const char *, const char *, const char *);
314 int recursive_remove(const char *, int);
316 void add_pkgdir(const char *, const char *, const char *);
317 void delete_pkgdir(const char *, const char *, const char *);
318 int has_pkgdir(const char *);
320 /* pkg_io.c: Local and remote archive handling */
322 struct archive_entry
;
324 struct archive
*open_archive(const char *);
325 struct archive
*find_archive(const char *, int);
326 void process_pkg_path(void);
327 struct url
*find_best_package(const char *, const char *, int);
330 plist_t
*new_plist_entry(void);
331 plist_t
*last_plist(package_t
*);
332 plist_t
*find_plist(package_t
*, pl_ent_t
);
333 char *find_plist_option(package_t
*, const char *);
334 void plist_delete(package_t
*, Boolean
, pl_ent_t
, char *);
335 void free_plist(package_t
*);
336 void mark_plist(package_t
*);
337 void csum_plist_entry(char *, plist_t
*);
338 void add_plist(package_t
*, pl_ent_t
, const char *);
339 void add_plist_top(package_t
*, pl_ent_t
, const char *);
340 void delete_plist(package_t
*, Boolean
, pl_ent_t
, char *);
341 void write_plist(package_t
*, FILE *, char *);
342 void stringify_plist(package_t
*, char **, size_t *, const char *);
343 void parse_plist(package_t
*, const char *);
344 void read_plist(package_t
*, FILE *);
345 void append_plist(package_t
*, FILE *);
346 int delete_package(Boolean
, package_t
*, Boolean
, const char *);
348 /* Package Database */
350 void pkgdb_close(void);
351 int pkgdb_store(const char *, const char *);
352 char *pkgdb_retrieve(const char *);
353 int pkgdb_dump(void);
354 int pkgdb_remove(const char *);
355 int pkgdb_remove_pkg(const char *);
356 char *pkgdb_refcount_dir(void);
357 char *_pkgdb_getPKGDB_FILE(char *, unsigned);
358 const char *_pkgdb_getPKGDB_DIR(void);
359 void _pkgdb_setPKGDB_DIR(const char *);
361 char *pkgdb_pkg_file(const char *, const char *);
363 /* List of packages functions */
364 lpkg_t
*alloc_lpkg(const char *);
365 lpkg_t
*find_on_queue(lpkg_head_t
*, const char *);
366 void free_lpkg(lpkg_t
*);
368 /* Extract input if compressed to NUL terminated buffer (not counted) */
369 int decompress_buffer(const char *, size_t, char **, size_t *);
371 /* Parse NUL terminated inputed, argument is strlen of the input */
372 struct pkg_vulnerabilities
*parse_pkg_vulnerabilities(const char *, size_t, int);
373 /* Read pkg_vulnerabilities from file */
374 struct pkg_vulnerabilities
*read_pkg_vulnerabilities(const char *, int, int);
375 void free_pkg_vulnerabilities(struct pkg_vulnerabilities
*);
376 int audit_package(struct pkg_vulnerabilities
*, const char *, const char *,
379 /* Parse configuration file */
380 void pkg_install_config(void);
381 /* Print configuration variable */
382 void pkg_install_show_variable(const char *);
384 /* Package signature creation and validation */
385 int pkg_verify_signature(struct archive
**, struct archive_entry
**, char **);
386 int pkg_full_signature_check(struct archive
**);
388 void pkg_sign_x509(const char *, const char *, const char *, const char *);
391 void pkg_sign_gpg(const char *, const char *);
394 /* PKCS7 signing/verification */
395 int easy_pkcs7_verify(const char *, size_t, const char *, size_t,
397 int easy_pkcs7_sign(const char *, size_t, char **, size_t *, const char *,
401 int inline_gpg_verify(const char *, size_t, const char *);
402 int detached_gpg_verify(const char *, size_t, const char *, size_t,
404 int detached_gpg_sign(const char *, size_t, char **, size_t *, const char *,
407 /* License handling */
408 int add_licenses(const char *);
409 int acceptable_license(const char *);
410 int acceptable_pkg_license(const char *);
411 void load_license_lists(void);
413 /* Helper functions for memory allocation */
414 char *xstrdup(const char *);
415 void *xrealloc(void *, size_t);
416 void *xcalloc(size_t, size_t);
417 void *xmalloc(size_t);
418 char *xasprintf(const char *, ...);
421 extern Boolean Verbose
;
423 extern Boolean Force
;
424 extern const char *cert_chain_file
;
425 extern const char *certs_packages
;
426 extern const char *certs_pkg_vulnerabilities
;
427 extern const char *check_vulnerabilities
;
428 extern const char *config_file
;
429 extern const char *config_pkg_path
;
430 extern const char *do_license_check
;
431 extern const char *verified_installation
;
432 extern const char *gpg_cmd
;
433 extern const char *gpg_keyring_pkgvuln
;
434 extern const char *gpg_keyring_sign
;
435 extern const char *gpg_keyring_verify
;
436 extern const char *gpg_sign_as
;
437 extern char fetch_flags
[];
439 extern const char *pkg_vulnerabilities_dir
;
440 extern const char *pkg_vulnerabilities_file
;
441 extern const char *pkg_vulnerabilities_url
;
442 extern const char *ignore_advisories
;
443 extern const char tnf_vulnerability_base
[];
445 extern const char *acceptable_licenses
;
446 extern const char *default_acceptable_licenses
;
448 #endif /* _INST_LIB_LIB_H_ */