Line data Source code
1 : /*-
2 : * Copyright (c) 2011-2014 Baptiste Daroussin <bapt@FreeBSD.org>
3 : * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions
8 : * are met:
9 : * 1. Redistributions of source code must retain the above copyright
10 : * notice, this list of conditions and the following disclaimer
11 : * in this position and unchanged.
12 : * 2. Redistributions in binary form must reproduce the above copyright
13 : * notice, this list of conditions and the following disclaimer in the
14 : * documentation and/or other materials provided with the distribution.
15 : *
16 : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
17 : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 : * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
20 : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 : */
27 :
28 : #ifndef _PKG_UTIL_H
29 : #define _PKG_UTIL_H
30 :
31 : #include <sys/types.h>
32 : #include <sys/sbuf.h>
33 : #include <sys/stat.h>
34 : #include <sys/param.h>
35 : #include <uthash.h>
36 : #include <ucl.h>
37 : #include <khash.h>
38 :
39 : #include <openssl/pem.h>
40 : #include <openssl/rsa.h>
41 :
42 : #define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
43 :
44 : #define ERROR_SQLITE(db, query) do { \
45 : pkg_emit_error("sqlite error while executing %s in file %s:%d: %s", (query), \
46 : __FILE__, __LINE__, sqlite3_errmsg(db)); \
47 : } while(0)
48 :
49 170 : KHASH_MAP_INIT_INT(hardlinks, int)
50 : typedef khash_t(hardlinks) hardlinks_t;
51 :
52 : struct dns_srvinfo {
53 : unsigned int type;
54 : unsigned int class;
55 : unsigned int ttl;
56 : unsigned int priority;
57 : unsigned int weight;
58 : unsigned int port;
59 : unsigned int finalweight;
60 : char host[MAXHOSTNAMELEN];
61 : struct dns_srvinfo *next;
62 : };
63 :
64 : struct rsa_key {
65 : pem_password_cb *pw_cb;
66 : char *path;
67 : RSA *key;
68 : };
69 :
70 :
71 : void sbuf_init(struct sbuf **);
72 : int sbuf_set(struct sbuf **, const char *);
73 : void sbuf_reset(struct sbuf *);
74 : void sbuf_free(struct sbuf *);
75 :
76 : int mkdirs(const char *path);
77 : int file_to_buffer(const char *, char **, off_t *);
78 : int file_to_bufferat(int, const char *, char **, off_t *);
79 : int format_exec_cmd(char **, const char *, const char *, const char *, char *,
80 : int argc, char **argv);
81 : int is_dir(const char *);
82 :
83 : int rsa_new(struct rsa_key **, pem_password_cb *, char *path);
84 : void rsa_free(struct rsa_key *);
85 : int rsa_sign(char *path, struct rsa_key *rsa, unsigned char **sigret, unsigned int *siglen);
86 : int rsa_verify(const char *path, const char *key,
87 : unsigned char *sig, unsigned int sig_len, int fd);
88 : int rsa_verify_cert(const char *path, unsigned char *cert,
89 : int certlen, unsigned char *sig, int sig_len, int fd);
90 :
91 : bool check_for_hardlink(hardlinks_t *hl, struct stat *st);
92 : bool is_valid_abi(const char *arch, bool emit_error);
93 :
94 : struct dns_srvinfo *
95 : dns_getsrvinfo(const char *zone);
96 :
97 : int set_nameserver(const char *nsname);
98 : void set_blocking(int fd);
99 : void set_nonblocking(int fd);
100 :
101 : int pkg_symlink_cksum(const char *path, const char *root, char *cksum);
102 : int pkg_symlink_cksumat(int fd, const char *path, const char *root,
103 : char *cksum);
104 :
105 : pid_t process_spawn_pipe(FILE *inout[2], const char *command);
106 :
107 : void *parse_mode(const char *str);
108 : int *text_diff(char *a, char *b);
109 : int merge_3way(char *pivot, char *v1, char *v2, struct sbuf *out);
110 : bool string_end_with(const char *path, const char *str);
111 :
112 : #endif
|