LCOV - code coverage report
Current view: top level - libpkg/private - pkg.h (source / functions) Hit Total Coverage
Test: cov.info Lines: 4 5 80.0 %
Date: 2015-08-15 Functions: 20 26 76.9 %

          Line data    Source code
       1             : /*-
       2             :  * Copyright (c) 2011-2015 Baptiste Daroussin <bapt@FreeBSD.org>
       3             :  * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
       4             :  * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
       5             :  * Copyright (c) 2013 Vsevolod Stakhov <vsevolod@FreeBSD.org>
       6             :  * All rights reserved.
       7             :  * 
       8             :  * Redistribution and use in source and binary forms, with or without
       9             :  * modification, are permitted provided that the following conditions
      10             :  * are met:
      11             :  * 1. Redistributions of source code must retain the above copyright
      12             :  *    notice, this list of conditions and the following disclaimer
      13             :  *    in this position and unchanged.
      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.
      17             :  * 
      18             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
      19             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      20             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      21             :  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
      22             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      23             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      24             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      25             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      26             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      27             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      28             :  */
      29             : 
      30             : #ifndef _PKG_PRIVATE_H
      31             : #define _PKG_PRIVATE_H
      32             : 
      33             : #include "bsd_compat.h"
      34             : 
      35             : #include <sys/param.h>
      36             : #include <sys/cdefs.h>
      37             : #include <sys/sbuf.h>
      38             : #include <sys/types.h>
      39             : 
      40             : #include <archive.h>
      41             : #include <sqlite3.h>
      42             : #include <stdbool.h>
      43             : #include <uthash.h>
      44             : #include <utlist.h>
      45             : #include <ucl.h>
      46             : 
      47             : #include "private/utils.h"
      48             : 
      49             : #define UCL_COUNT(obj) ((obj)?((obj)->len):0)
      50             : 
      51             : #define PKG_NUM_SCRIPTS 9
      52             : 
      53             : /*
      54             :  * Some compatibility checks
      55             :  */
      56             : #ifndef MAXLOGNAME
      57             : # ifdef LOGIN_NAME_MAX
      58             : # define MAXLOGNAME LOGIN_NAME_MAX
      59             : # else
      60             : # define MAXLOGNAME 64
      61             : # endif
      62             : #endif
      63             : #ifndef __unused
      64             : # ifdef __GNUC__
      65             : # define __unused __attribute__ ((__unused__))
      66             : # else
      67             : # define __unused
      68             : # endif
      69             : #endif
      70             : 
      71             : #if ARCHIVE_VERSION_NUMBER < 3000002
      72             : #define archive_write_add_filter_xz(a) archive_write_set_compression_xz(a)
      73             : #define archive_write_add_filter_bzip2(a) archive_write_set_compression_bzip2(a)
      74             : #define archive_write_add_filter_gzip(a) archive_write_set_compression_gzip(a)
      75             : #define archive_write_add_filter_none(a) archive_write_set_compression_none(a)
      76             : #define archive_read_support_filter_all(a) archive_read_support_compression_all(a)
      77             : #define archive_read_support_filter_none(a) archive_read_support_compression_none(a)
      78             : #define archive_read_free archive_read_finish
      79             : #define archive_write_free archive_write_finish
      80             : 
      81             : #ifndef UF_NOUNLINK
      82             : #define UF_NOUNLINK 0
      83             : #endif
      84             : 
      85             : #ifndef SF_NOUNLINK
      86             : #define SF_NOUNLINK 0
      87             : #endif
      88             : 
      89             : #endif
      90             : 
      91             : #define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM | \
      92             :                 ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_ACL | \
      93             :                 ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)
      94             : 
      95             : #define HASH_FREE(data, free_func) do {      \
      96             :         __typeof(data) hf1, hf2;                    \
      97             :         HASH_ITER(hh, data, hf1, hf2) {            \
      98             :                 HASH_DEL(data, hf1);               \
      99             :                 free_func(hf1);                    \
     100             :         }                                          \
     101             :         data = NULL;                               \
     102             : } while (0)
     103             : 
     104             : #define LL_FREE(head, free_func) do {   \
     105             :         __typeof(head) l1, l2;                 \
     106             :         LL_FOREACH_SAFE(head, l1, l2) {       \
     107             :                 LL_DELETE(head, l1);          \
     108             :                 free_func(l1);                \
     109             :         }                                     \
     110             :         head = NULL;                          \
     111             : } while (0)
     112             : 
     113             : #define HASH_NEXT(hash, data) do {            \
     114             :                 if (data == NULL)             \
     115             :                         data = hash;          \
     116             :                 else                          \
     117             :                         data = data->hh.next; \
     118             :                 if (data == NULL)             \
     119             :                         return (EPKG_END);    \
     120             :                 else                          \
     121             :                         return (EPKG_OK);     \
     122             :         } while (0)
     123             : 
     124             : #define kh_string_next(head, data) do {                  \
     125             :         khint_t k;                                       \
     126             :         if (head == NULL)                                \
     127             :                 return (EPKG_END);                       \
     128             :         if (data == NULL) {                              \
     129             :                 k = kh_begin(head);                      \
     130             :         } else {                                         \
     131             :                 k = kh_get_strings(head, (data));        \
     132             :                 k++;                                     \
     133             :         }                                                \
     134             :         while (k != kh_end(head) && !kh_exist(head, k))  \
     135             :                 k++;                                     \
     136             :         if (k == kh_end(head))                           \
     137             :                 return (EPKG_END);                       \
     138             :         data = kh_value(head, k);                        \
     139             :         return (EPKG_OK);                                \
     140             : } while (0)
     141             : 
     142             : #define kh_next(name, head, data, attrib) do {           \
     143             :         khint_t k;                                       \
     144             :         if (head == NULL)                                \
     145             :                 return (EPKG_END);                       \
     146             :         if (data == NULL) {                              \
     147             :                 k = kh_begin(head);                      \
     148             :         } else {                                         \
     149             :                 k = kh_get_##name(head, (data)->attrib); \
     150             :                 k++;                                     \
     151             :         }                                                \
     152             :         while (k != kh_end(head) && !kh_exist(head, k))  \
     153             :                 k++;                                     \
     154             :         if (k == kh_end(head)) {                         \
     155             :                 data = NULL;                             \
     156             :                 return (EPKG_END);                       \
     157             :         }                                                \
     158             :         data = kh_value(head, k);                        \
     159             :         return (EPKG_OK);                                \
     160             : } while (0)
     161             : 
     162             : #define kh_free(name, head, type, free_func) do {                       \
     163             :         if (head) {                                                     \
     164             :                 type *_todelete;                                        \
     165             :                 kh_foreach_value(head, _todelete, free_func(_todelete));\
     166             :                 kh_destroy_##name(head);                                \
     167             :                 head = NULL;                                            \
     168             :         }                                                               \
     169             : } while (0)
     170             : 
     171             : #define kh_contains(name, h, v) ((h)?(kh_get_##name(h, v) != kh_end(h)):false)
     172             : 
     173             : #define kh_each_value(h, vvar, code)                                                    \
     174             :         for (khint_t __i = kh_begin(h); h != NULL && __i != kh_end(h); __i++) {         \
     175             :                 if (!kh_exist(h, __i)) continue;                                        \
     176             :                 (vvar) = kh_val(h, __i);                                                \
     177             :                 code;                                                                   \
     178             :         }
     179             : 
     180             : #define kh_count(h) ((h)?((h)->size):0)
     181             : 
     182             : #define kh_add(name, h, val, k) do {            \
     183             :         int __ret;                              \
     184             :         khint_t __i;                            \
     185             :         if (!h) h = kh_init_##name();           \
     186             :         __i = kh_put_##name(h, k, &__ret);  \
     187             :         if (__ret != 0)                         \
     188             :                 kh_val(h, __i) = val;           \
     189             : } while (0)
     190             : 
     191             : 
     192             : extern int eventpipe;
     193             : extern int64_t debug_level;
     194             : extern bool developer_mode;
     195             : extern const char *pkg_rootdir;
     196             : 
     197             : struct pkg_repo_it;
     198             : struct pkg_repo;
     199             : 
     200         831 : KHASH_MAP_INIT_STR(pkg_deps, struct pkg_dep *);
     201         859 : KHASH_MAP_INIT_STR(pkg_files, struct pkg_file *);
     202          78 : KHASH_MAP_INIT_STR(pkg_dirs, struct pkg_dir *);
     203           0 : KHASH_MAP_INIT_STR(pkg_config_files, struct pkg_config_file *);
     204         385 : KHASH_MAP_INIT_STR(strings, char *);
     205             : 
     206             : struct pkg {
     207             :         bool             direct;
     208             :         bool             locked;
     209             :         bool             automatic;
     210             :         int64_t          id;
     211             :         struct sbuf     *scripts[PKG_NUM_SCRIPTS];
     212             :         char                    *name;
     213             :         char                    *origin;
     214             :         char                    *version;
     215             :         char                    *old_version;
     216             :         char                    *maintainer;
     217             :         char                    *www;
     218             :         char                    *arch;
     219             :         char                    *abi;
     220             :         char                    *uid;
     221             :         char                    *digest;
     222             :         char                    *old_digest;
     223             :         char                    *message;
     224             :         char                    *prefix;
     225             :         char                    *comment;
     226             :         char                    *desc;
     227             :         char                    *sum;
     228             :         char                    *repopath;
     229             :         char                    *reponame;
     230             :         char                    *repourl;
     231             :         char                    *reason;
     232             :         char                    *dep_formula;
     233             :         lic_t                    licenselogic;
     234             :         int64_t                  pkgsize;
     235             :         int64_t                  flatsize;
     236             :         int64_t                  old_flatsize;
     237             :         int64_t                  timestamp;
     238             :         kh_pkg_deps_t           *deps;
     239             :         kh_pkg_deps_t           *rdeps;
     240             :         struct pkg_strel        *categories;
     241             :         struct pkg_strel        *licenses;
     242             :         kh_pkg_files_t          *files;
     243             :         kh_pkg_dirs_t           *dirs;
     244             :         struct pkg_option       *options;
     245             :         kh_strings_t            *users;
     246             :         kh_strings_t            *groups;
     247             :         kh_strings_t            *shlibs_required;
     248             :         kh_strings_t            *shlibs_provided;
     249             :         struct pkg_conflict *conflicts;
     250             :         kh_strings_t            *provides;
     251             :         kh_strings_t            *requires;
     252             :         kh_pkg_config_files_t   *config_files;
     253             :         struct pkg_kv           *annotations;
     254             :         unsigned                        flags;
     255             :         int             rootfd;
     256             :         char            rootpath[MAXPATHLEN];
     257             :         char            **dir_to_del;
     258             :         size_t          dir_to_del_cap;
     259             :         size_t          dir_to_del_len;
     260             :         pkg_t            type;
     261             :         struct pkg_repo         *repo;
     262             : };
     263             : 
     264             : struct pkg_dep {
     265             :         char            *origin;
     266             :         char            *name;
     267             :         char            *version;
     268             :         char            *uid;
     269             :         bool             locked;
     270             : };
     271             : 
     272             : enum pkg_conflict_type {
     273             :         PKG_CONFLICT_ALL = 0,
     274             :         PKG_CONFLICT_REMOTE_LOCAL,
     275             :         PKG_CONFLICT_REMOTE_REMOTE,
     276             :         PKG_CONFLICT_LOCAL_LOCAL
     277             : };
     278             : 
     279             : struct pkg_conflict {
     280             :         char *uid;
     281             :         char *digest;
     282             :         enum pkg_conflict_type type;
     283             :         UT_hash_handle  hh;
     284             : };
     285             : 
     286             : struct pkg_file {
     287             :         char             path[MAXPATHLEN];
     288             :         int64_t          size;
     289             :         char            *sum;
     290             :         char             uname[MAXLOGNAME];
     291             :         char             gname[MAXLOGNAME];
     292             :         mode_t           perm;
     293             :         u_long           fflags;
     294             : };
     295             : 
     296             : struct pkg_dir {
     297             :         char             path[MAXPATHLEN];
     298             :         char             uname[MAXLOGNAME];
     299             :         char             gname[MAXLOGNAME];
     300             :         mode_t           perm;
     301             :         u_long           fflags;
     302             : };
     303             : 
     304             : struct pkg_option {
     305             :         char    *key;
     306             :         char    *value;
     307             :         char    *default_value;
     308             :         char    *description;
     309             :         UT_hash_handle  hh;
     310             : };
     311             : 
     312             : struct http_mirror {
     313             :         struct url *url;
     314             :         struct http_mirror *next;
     315             : };
     316             : 
     317             : struct pkg_repo_meta_key {
     318             :         char *pubkey;
     319             :         char *pubkey_type; /* TODO: should be enumeration */
     320             :         char *name;
     321             :         UT_hash_handle hh;
     322             : };
     323             : 
     324             : typedef enum pkg_checksum_type_e {
     325             :         PKG_HASH_TYPE_SHA256_BASE32 = 0,
     326             :         PKG_HASH_TYPE_SHA256_HEX,
     327             :         PKG_HASH_TYPE_BLAKE2_BASE32,
     328             :         PKG_HASH_TYPE_SHA256_RAW,
     329             :         PKG_HASH_TYPE_BLAKE2_RAW,
     330             :         PKG_HASH_TYPE_UNKNOWN
     331             : } pkg_checksum_type_t;
     332             : 
     333             : static const char repo_meta_file[] = "meta";
     334             : 
     335             : struct pkg_repo_meta {
     336             : 
     337             :         char *maintainer;
     338             :         char *source;
     339             : 
     340             :         pkg_formats packing_format;
     341             :         pkg_checksum_type_t digest_format;
     342             : 
     343             :         char *digests;
     344             :         char *digests_archive;
     345             :         char *manifests;
     346             :         char *manifests_archive;
     347             :         char *filesite;
     348             :         char *filesite_archive;
     349             :         char *conflicts;
     350             :         char *conflicts_archive;
     351             :         char *fulldb;
     352             :         char *fulldb_archive;
     353             : 
     354             :         char *source_identifier;
     355             :         int64_t revision;
     356             : 
     357             :         struct pkg_repo_meta_key *keys;
     358             : 
     359             :         time_t eol;
     360             : 
     361             :         int version;
     362             : };
     363             : 
     364             : struct pkg_repo_it_ops {
     365             :         int (*next)(struct pkg_repo_it *it, struct pkg **pkg_p, unsigned flags);
     366             :         void (*free)(struct pkg_repo_it *it);
     367             :         void (*reset)(struct pkg_repo_it *it);
     368             : };
     369             : 
     370             : struct pkg_repo_it {
     371             :         struct pkg_repo *repo;
     372             :         struct pkg_repo_it_ops *ops;
     373             :         int flags;
     374             :         void *data;
     375             : };
     376             : 
     377             : struct pkg_repo_ops {
     378             :         const char *type;
     379             :         /* Accessing repo */
     380             :         int (*init)(struct pkg_repo *);
     381             :         int (*access)(struct pkg_repo *, unsigned);
     382             :         int (*open)(struct pkg_repo *, unsigned);
     383             :         int (*create)(struct pkg_repo *);
     384             :         int (*close)(struct pkg_repo *, bool);
     385             : 
     386             :         /* Updating repo */
     387             :         int (*update)(struct pkg_repo *, bool);
     388             : 
     389             :         /* Query repo */
     390             :         struct pkg_repo_it * (*query)(struct pkg_repo *,
     391             :                                         const char *, match_t);
     392             :         struct pkg_repo_it * (*shlib_required)(struct pkg_repo *,
     393             :                                         const char *);
     394             :         struct pkg_repo_it * (*shlib_provided)(struct pkg_repo *,
     395             :                                         const char *);
     396             :         struct pkg_repo_it * (*required)(struct pkg_repo *,
     397             :                                         const char *);
     398             :         struct pkg_repo_it * (*provided)(struct pkg_repo *,
     399             :                                         const char *);
     400             :         struct pkg_repo_it * (*search)(struct pkg_repo *, const char *, match_t,
     401             :                                         pkgdb_field field, pkgdb_field sort);
     402             : 
     403             :         int64_t (*stat)(struct pkg_repo *, pkg_stats_t type);
     404             : 
     405             :         int (*ensure_loaded)(struct pkg_repo *repo, struct pkg *pkg, unsigned flags);
     406             : 
     407             :         /* Fetch package from repo */
     408             :         int (*get_cached_name)(struct pkg_repo *, struct pkg *,
     409             :                                         char *dest, size_t destlen);
     410             :         int (*fetch_pkg)(struct pkg_repo *, struct pkg *);
     411             :         int (*mirror_pkg)(struct pkg_repo *repo, struct pkg *pkg,
     412             :                 const char *destdir);
     413             : };
     414             : 
     415             : typedef enum _pkg_repo_flags {
     416             :         REPO_FLAGS_USE_IPV4 = (1U << 0),
     417             :         REPO_FLAGS_USE_IPV6 = (1U << 1)
     418             : } pkg_repo_flags;
     419             : 
     420             : struct pkg_repo {
     421             :         struct pkg_repo_ops *ops;
     422             : 
     423             :         char *name;
     424             :         char *url;
     425             :         char *pubkey;
     426             :         mirror_t mirror_type;
     427             :         union {
     428             :                 struct dns_srvinfo *srv;
     429             :                 struct http_mirror *http;
     430             :         };
     431             :         signature_t signature_type;
     432             :         char *fingerprints;
     433             :         FILE *ssh;
     434             : 
     435             :         struct fingerprint *trusted_fp;
     436             :         struct fingerprint *revoked_fp;
     437             : 
     438             :         struct {
     439             :                 int in;
     440             :                 int out;
     441             :                 pid_t pid;
     442             :         } sshio;
     443             : 
     444             :         struct pkg_repo_meta *meta;
     445             : 
     446             :         bool enable;
     447             :         UT_hash_handle hh;
     448             : 
     449             :         unsigned int priority;
     450             : 
     451             :         pkg_repo_flags flags;
     452             : 
     453             :         /* Opaque repository data */
     454             :         void *priv;
     455             : };
     456             : 
     457             : struct keyword {
     458             :         /* 64 is more than enough for this */
     459             :         char keyword[64];
     460             :         struct action *actions;
     461             :         UT_hash_handle hh;
     462             : };
     463             : 
     464             : struct plist {
     465             :         char last_file[MAXPATHLEN];
     466             :         const char *stage;
     467             :         char prefix[MAXPATHLEN];
     468             :         struct sbuf *pre_install_buf;
     469             :         struct sbuf *post_install_buf;
     470             :         struct sbuf *pre_deinstall_buf;
     471             :         struct sbuf *post_deinstall_buf;
     472             :         struct sbuf *pre_upgrade_buf;
     473             :         struct sbuf *post_upgrade_buf;
     474             :         struct pkg *pkg;
     475             :         char *uname;
     476             :         char *gname;
     477             :         const char *slash;
     478             :         char *pkgdep;
     479             :         bool ignore_next;
     480             :         int64_t flatsize;
     481             :         hardlinks_t *hardlinks;
     482             :         mode_t perm;
     483             :         struct {
     484             :                 char *buf;
     485             :                 char **patterns;
     486             :                 size_t len;
     487             :                 size_t cap;
     488             :         } post_patterns;
     489             :         struct keyword *keywords;
     490             : };
     491             : 
     492             : struct file_attr {
     493             :         char *owner;
     494             :         char *group;
     495             :         mode_t mode;
     496             :         u_long fflags;
     497             : };
     498             : 
     499             : struct action {
     500             :         int (*perform)(struct plist *, char *, struct file_attr *);
     501             :         struct action *next;
     502             : };
     503             : 
     504             : struct pkg_config_file {
     505             :         char path[MAXPATHLEN];
     506             :         char *content;
     507             : };
     508             : 
     509             : /* sql helpers */
     510             : 
     511             : typedef struct _sql_prstmt {
     512             :         sqlite3_stmt    *stmt;
     513             :         const char      *sql;
     514             :         const char      *argtypes;
     515             : } sql_prstmt;
     516             : 
     517             : #define STMT(x) (sql_prepared_statements[(x)].stmt)
     518             : #define SQL(x)  (sql_prepared_statements[(x)].sql)
     519             : 
     520             : /**
     521             :  * rc script actions
     522             :  */
     523             : typedef enum {
     524             :         PKG_RC_START = 0,
     525             :         PKG_RC_STOP
     526             : } pkg_rc_attr;
     527             : 
     528             : /**
     529             :  * Remove and unregister the package.
     530             :  * @param pkg An installed package to delete
     531             :  * @param db An opened pkgdb
     532             :  * @param force If set to one, the function will not fail if the package is
     533             :  * required by other packages.
     534             :  * @return An error code.
     535             :  */
     536             : int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags);
     537             : #define PKG_DELETE_FORCE (1<<0)
     538             : #define PKG_DELETE_UPGRADE (1<<1)
     539             : #define PKG_DELETE_NOSCRIPT (1<<2)
     540             : #define PKG_DELETE_CONFLICT (1<<3)
     541             : 
     542             : int pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
     543             :     time_t *t, ssize_t offset, int64_t size);
     544             : int pkg_repo_fetch_package(struct pkg *pkg);
     545             : int pkg_repo_mirror_package(struct pkg *pkg, const char *destdir);
     546             : FILE* pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo,
     547             :                 const char *filename, time_t *t, int *rc);
     548             : unsigned char *pkg_repo_fetch_remote_extract_mmap(struct pkg_repo *repo,
     549             :     const char *filename, time_t *t, int *rc, size_t *sz);
     550             : int pkg_repo_fetch_meta(struct pkg_repo *repo, time_t *t);
     551             : 
     552             : struct pkg_repo_meta *pkg_repo_meta_default(void);
     553             : int pkg_repo_meta_load(const char *file, struct pkg_repo_meta **target);
     554             : void pkg_repo_meta_free(struct pkg_repo_meta *meta);
     555             : ucl_object_t * pkg_repo_meta_to_ucl(struct pkg_repo_meta *meta);
     556             : bool pkg_repo_meta_is_special_file(const char *file, struct pkg_repo_meta *meta);
     557             : 
     558             : typedef enum {
     559             :         HASH_UNKNOWN,
     560             :         HASH_SHA256,
     561             :         HASH_BLAKE2
     562             : } hash_t;
     563             : 
     564             : struct fingerprint {
     565             :         hash_t type;
     566             :         char hash[BUFSIZ];
     567             :         UT_hash_handle hh;
     568             : };
     569             : int pkg_repo_load_fingerprints(struct pkg_repo *repo);
     570             : 
     571             : 
     572             : int pkg_start_stop_rc_scripts(struct pkg *, pkg_rc_attr attr);
     573             : 
     574             : int pkg_script_run(struct pkg *, pkg_script type);
     575             : 
     576             : int pkg_open2(struct pkg **p, struct archive **a, struct archive_entry **ae,
     577             :               const char *path, struct pkg_manifest_key *keys, int flags, int fd);
     578             : 
     579             : int pkg_validate(struct pkg *pkg);
     580             : 
     581             : void pkg_list_free(struct pkg *, pkg_list);
     582             : 
     583             : int pkg_strel_new(struct pkg_strel **, const char *val);
     584             : void pkg_strel_free(struct pkg_strel *);
     585             : 
     586             : int pkg_kv_new(struct pkg_kv **, const char *key, const char *val);
     587             : void pkg_kv_free(struct pkg_kv *);
     588             : 
     589             : int pkg_dep_new(struct pkg_dep **);
     590             : void pkg_dep_free(struct pkg_dep *);
     591             : 
     592             : int pkg_file_new(struct pkg_file **);
     593             : void pkg_file_free(struct pkg_file *);
     594             : 
     595             : int pkg_dir_new(struct pkg_dir **);
     596             : void pkg_dir_free(struct pkg_dir *);
     597             : 
     598             : int pkg_option_new(struct pkg_option **);
     599             : void pkg_option_free(struct pkg_option *);
     600             : 
     601             : int pkg_jobs_resolv(struct pkg_jobs *jobs);
     602             : 
     603             : int pkg_conflict_new(struct pkg_conflict **);
     604             : void pkg_conflict_free(struct pkg_conflict *);
     605             : 
     606             : int pkg_config_file_new(struct pkg_config_file **);
     607             : void pkg_config_file_free(struct pkg_config_file *);
     608             : 
     609             : struct packing;
     610             : 
     611             : int packing_init(struct packing **pack, const char *path, pkg_formats format,
     612             :     bool passmode);
     613             : int packing_append_file_attr(struct packing *pack, const char *filepath,
     614             :      const char *newpath, const char *uname, const char *gname, mode_t perm,
     615             :      u_long fflags);
     616             : int packing_append_buffer(struct packing *pack, const char *buffer,
     617             :                           const char *path, int size);
     618             : int packing_append_tree(struct packing *pack, const char *treepath,
     619             :                         const char *newroot);
     620             : void packing_finish(struct packing *pack);
     621             : pkg_formats packing_format_from_string(const char *str);
     622             : const char* packing_format_to_string(pkg_formats format);
     623             : 
     624             : int pkg_delete_files(struct pkg *pkg, unsigned force);
     625             : int pkg_delete_dirs(struct pkgdb *db, struct pkg *pkg, struct pkg *p);
     626             : 
     627             : /* pkgdb commands */
     628             : int sql_exec(sqlite3 *, const char *, ...);
     629             : int get_pragma(sqlite3 *, const char *sql, int64_t *res, bool silence);
     630             : int get_sql_string(sqlite3 *, const char *sql, char **res);
     631             : 
     632             : int pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int complete, int forced);
     633             : int pkgdb_update_shlibs_required(struct pkg *pkg, int64_t package_id, sqlite3 *s);
     634             : int pkgdb_update_shlibs_provided(struct pkg *pkg, int64_t package_id, sqlite3 *s);
     635             : int pkgdb_update_provides(struct pkg *pkg, int64_t package_id, sqlite3 *s);
     636             : int pkgdb_update_requires(struct pkg *pkg, int64_t package_id, sqlite3 *s);
     637             : int pkgdb_insert_annotations(struct pkg *pkg, int64_t package_id, sqlite3 *s);
     638             : int pkgdb_register_finale(struct pkgdb *db, int retcode);
     639             : int pkgdb_set_pkg_digest(struct pkgdb *db, struct pkg *pkg);
     640             : int pkgdb_is_dir_used(struct pkgdb *db, struct pkg *p, const char *dir, int64_t *res);
     641             : int pkgdb_file_set_cksum(struct pkgdb *db, struct pkg_file *file, const char *sha256);
     642             : 
     643             : 
     644             : int pkg_emit_manifest_sbuf(struct pkg*, struct sbuf *, short, char **);
     645             : int pkg_emit_filelist(struct pkg *, FILE *);
     646             : 
     647             : bool ucl_object_emit_sbuf(const ucl_object_t *obj, enum ucl_emitter emit_type,
     648             :     struct sbuf **buf);
     649             : bool ucl_object_emit_file(const ucl_object_t *obj, enum ucl_emitter emit_type,
     650             :     FILE *);
     651             : 
     652             : pkg_object* pkg_emit_object(struct pkg *pkg, short flags);
     653             : 
     654             : /* Hash is in format <version>:<typeid>:<hexhash> */
     655             : #define PKG_CHECKSUM_SHA256_LEN (SHA256_DIGEST_LENGTH * 2 + sizeof("100") * 2 + 2)
     656             : #define PKG_CHECKSUM_BLAKE2_LEN (BLAKE2B_OUTBYTES * 8 / 5 + sizeof("100") * 2 + 2)
     657             : #define PKG_CHECKSUM_CUR_VERSION 2
     658             : 
     659             : int pkg_checksum_generate(struct pkg *pkg, char *dest, size_t destlen,
     660             :         pkg_checksum_type_t type);
     661             : 
     662             : /*
     663             :  * Calculates checksum for any data.
     664             :  * Caller must free resulting hash after usage
     665             :  */
     666             : unsigned char * pkg_checksum_data(const unsigned char *in, size_t inlen,
     667             :         pkg_checksum_type_t type);
     668             : unsigned char *pkg_checksum_fd(int fd, pkg_checksum_type_t type);
     669             : unsigned char *pkg_checksum_file(const char *path, pkg_checksum_type_t type);
     670             : unsigned char *pkg_checksum_fileat(int fd, const char *path,
     671             :     pkg_checksum_type_t type);
     672             : unsigned char *pkg_checksum_symlink(const char *path, const char *root,
     673             :     pkg_checksum_type_t type);
     674             : unsigned char *pkg_checksum_symlinkat(int fd, const char *path,
     675             :     const char *root, pkg_checksum_type_t type);
     676             : bool pkg_checksum_validate_file(const char *path, const  char *sum);
     677             : bool pkg_checksum_validate_fileat(int fd, const char *path, const  char *sum);
     678             : 
     679             : bool pkg_checksum_is_valid(const char *cksum, size_t clen);
     680             : pkg_checksum_type_t pkg_checksum_get_type(const char *cksum, size_t clen);
     681             : pkg_checksum_type_t pkg_checksum_file_get_type(const char *cksum, size_t clen);
     682             : pkg_checksum_type_t pkg_checksum_type_from_string(const char *name);
     683             : const char* pkg_checksum_type_to_string(pkg_checksum_type_t type);
     684             : size_t pkg_checksum_type_size(pkg_checksum_type_t type);
     685             : int pkg_checksum_calculate(struct pkg *pkg, struct pkgdb *db);
     686             : char *pkg_checksum_generate_file(const char *path, pkg_checksum_type_t type);
     687             : char *pkg_checksum_generate_fileat(int fd, const char *path,
     688             :     pkg_checksum_type_t type);
     689             : 
     690             : int pkg_add_upgrade(struct pkgdb *db, const char *path, unsigned flags,
     691             :     struct pkg_manifest_key *keys, const char *location,
     692             :     struct pkg *rp, struct pkg *lp);
     693             : void pkg_delete_dir(struct pkg *pkg, struct pkg_dir *dir);
     694             : void pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force);
     695             : int pkg_open_root_fd(struct pkg *pkg);
     696             : void pkg_add_dir_to_del(struct pkg *pkg, const char *file, const char *dir);
     697             : struct plist *plist_new(struct pkg *p, const char *stage);
     698             : int plist_parse_line(struct plist *p, char *line);
     699             : void plist_free(struct plist *);
     700             : int pkg_appendscript(struct pkg *pkg, const char *cmd, pkg_script type);
     701             : 
     702             : int pkg_addscript(struct pkg *pkg, const char *data, pkg_script type);
     703             : int pkg_addfile(struct pkg *pkg, const char *path, const char *sha256,
     704             :     bool check_duplicates);
     705             : int pkg_addfile_attr(struct pkg *pkg, const char *path, const char *sha256,
     706             :     const char *uname, const char *gname, mode_t perm, u_long fflags,
     707             :     bool check_duplicates);
     708             : 
     709             : int pkg_adddir(struct pkg *pkg, const char *path, bool check_duplicates);
     710             : int pkg_adddir_attr(struct pkg *pkg, const char *path, const char *uname,
     711             :     const char *gname, mode_t perm, u_long fflags, bool check_duplicates);
     712             : 
     713             : int pkg_strel_add(struct pkg_strel **l, const char *name, const char *title);
     714             : int pkg_kv_add(struct pkg_kv **kv, const char *key, const char *value, const char *title);
     715             : const char *pkg_kv_get(struct pkg_kv *const*kv, const char *key);
     716             : int pkg_adduser(struct pkg *pkg, const char *name);
     717             : int pkg_addgroup(struct pkg *pkg, const char *group);
     718             : int pkg_addshlib_required(struct pkg *pkg, const char *name);
     719             : int pkg_addshlib_provided(struct pkg *pkg, const char *name);
     720             : int pkg_addconflict(struct pkg *pkg, const char *name);
     721             : int pkg_addprovide(struct pkg *pkg, const char *name);
     722             : int pkg_addrequire(struct pkg *pkg, const char *name);
     723             : int pkg_addconfig_file(struct pkg *pkg, const char *name, const char *buf);
     724             : 
     725             : int pkg_addoption(struct pkg *pkg, const char *name, const char *value);
     726             : int pkg_addoption_default(struct pkg *pkg, const char *key, const char *default_value);
     727             : int pkg_addoption_description(struct pkg *pkg, const char *key, const char *description);
     728             : 
     729             : int pkg_arch_to_legacy(const char *arch, char *dest, size_t sz);
     730             : bool pkg_is_config_file(struct pkg *p, const char *path, const struct pkg_file **file, struct pkg_config_file **cfile);
     731             : 
     732             : #endif

Generated by: LCOV version 1.10