-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathrepo.c
709 lines (632 loc) · 17.2 KB
/
repo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
/*-
* Copyright (c) 2012-2020 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <archive.h>
#include <archive_entry.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/rsa.h>
#include <openssl/ssl.h>
#include <openssl/pem.h>
#include "xbps_api_impl.h"
/**
* @file lib/repo.c
* @brief Repository functions
* @defgroup repo Repository functions
*/
char *
xbps_repo_path(struct xbps_handle *xhp, const char *url)
{
return xbps_repo_path_with_name(xhp, url, "repodata");
}
char *
xbps_repo_path_with_name(struct xbps_handle *xhp, const char *url, const char *name)
{
assert(xhp);
assert(url);
assert(strcmp(name, "repodata") == 0 || strcmp(name, "stagedata") == 0);
return xbps_xasprintf("%s/%s-%s",
url, xhp->target_arch ? xhp->target_arch : xhp->native_arch, name);
}
static xbps_dictionary_t
repo_get_dict(struct xbps_repo *repo)
{
struct archive_entry *entry;
int rv;
if (repo->ar == NULL)
return NULL;
rv = archive_read_next_header(repo->ar, &entry);
if (rv != ARCHIVE_OK) {
xbps_dbg_printf("%s: read_next_header %s\n", repo->uri,
archive_error_string(repo->ar));
return NULL;
}
return xbps_archive_get_dictionary(repo->ar, entry);
}
bool
xbps_repo_lock(struct xbps_handle *xhp, const char *repodir,
int *lockfd, char **lockfname)
{
char *repofile, *lockfile;
int fd, rv;
assert(repodir);
assert(lockfd);
assert(lockfname);
repofile = xbps_repo_path(xhp, repodir);
assert(repofile);
lockfile = xbps_xasprintf("%s.lock", repofile);
free(repofile);
for (;;) {
fd = open(lockfile, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0660);
rv = errno;
if (fd != -1)
break;
if (rv != EEXIST) {
xbps_dbg_printf("[repo] `%s' failed to "
"create lock file %s\n", lockfile, strerror(rv));
free(lockfile);
return false;
} else {
xbps_dbg_printf("[repo] `%s' lock file exists,"
"waiting for 1s...\n", lockfile);
sleep(1);
}
}
*lockfname = lockfile;
*lockfd = fd;
return true;
}
void
xbps_repo_unlock(int lockfd, char *lockfname)
{
if (lockfd != -1) {
close(lockfd);
}
if (lockfname) {
unlink(lockfname);
free(lockfname);
}
}
static bool
repo_open_local(struct xbps_repo *repo, const char *repofile)
{
struct stat st;
if (fstat(repo->fd, &st) == -1) {
xbps_dbg_printf("[repo] `%s' fstat repodata %s\n",
repofile, strerror(errno));
return false;
}
repo->ar = archive_read_new();
assert(repo->ar);
archive_read_support_filter_gzip(repo->ar);
archive_read_support_filter_bzip2(repo->ar);
archive_read_support_filter_xz(repo->ar);
archive_read_support_filter_lz4(repo->ar);
archive_read_support_filter_zstd(repo->ar);
archive_read_support_format_tar(repo->ar);
if (archive_read_open_fd(repo->ar, repo->fd, st.st_blksize) == ARCHIVE_FATAL) {
xbps_dbg_printf("[repo] `%s' failed to open repodata archive %s\n",
repofile, archive_error_string(repo->ar));
return false;
}
if ((repo->idx = repo_get_dict(repo)) == NULL) {
xbps_dbg_printf("[repo] `%s' failed to internalize "
" index on archive, removing file.\n", repofile);
/* broken archive, remove it */
(void)unlink(repofile);
return false;
}
xbps_dictionary_make_immutable(repo->idx);
repo->idxmeta = repo_get_dict(repo);
if (repo->idxmeta != NULL) {
repo->is_signed = true;
xbps_dictionary_make_immutable(repo->idxmeta);
}
/*
* We don't need the archive anymore, we are only
* interested in the proplib dictionaries.
*/
xbps_repo_close(repo);
return true;
}
static bool
repo_open_remote(struct xbps_repo *repo)
{
char *rpath;
bool rv;
rpath = xbps_repo_path(repo->xhp, repo->uri);
rv = xbps_repo_fetch_remote(repo, rpath);
free(rpath);
if (rv) {
xbps_dbg_printf("[repo] `%s' used remotely (kept in memory).\n", repo->uri);
if (repo->xhp->state_cb && xbps_repo_key_import(repo) != 0)
rv = false;
}
return rv;
}
static struct xbps_repo *
repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
{
struct xbps_repo *repo = NULL;
const char *arch;
char *repofile = NULL;
assert(xhp);
assert(url);
if (xhp->target_arch)
arch = xhp->target_arch;
else
arch = xhp->native_arch;
repo = calloc(1, sizeof(struct xbps_repo));
assert(repo);
repo->fd = -1;
repo->xhp = xhp;
repo->uri = url;
if (xbps_repository_is_remote(url)) {
/* remote repository */
char *rpath;
if ((rpath = xbps_get_remote_repo_string(url)) == NULL) {
goto out;
}
repofile = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir, rpath, arch, name);
free(rpath);
repo->is_remote = true;
} else {
/* local repository */
repofile = xbps_repo_path_with_name(xhp, url, name);
}
/*
* In memory repo sync.
*/
if (repo->is_remote && (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC)) {
if (repo_open_remote(repo)) {
free(repofile);
return repo;
}
goto out;
}
/*
* Open the repository archive.
*/
repo->fd = open(repofile, O_RDONLY|O_CLOEXEC);
if (repo->fd == -1) {
int rv = errno;
xbps_dbg_printf("[repo] `%s' open %s %s\n",
repofile, name, strerror(rv));
xbps_error_printf("%s: %s\n", strerror(rv), repofile);
goto out;
}
if (repo_open_local(repo, repofile)) {
free(repofile);
return repo;
}
out:
free(repofile);
xbps_repo_release(repo);
return NULL;
}
bool
xbps_repo_store(struct xbps_handle *xhp, const char *repo)
{
char *url = NULL;
assert(xhp);
assert(repo);
if (xhp->repositories == NULL) {
xhp->repositories = xbps_array_create();
assert(xhp->repositories);
}
/*
* If it's a local repo and path is relative, make it absolute.
*/
if (!xbps_repository_is_remote(repo)) {
if (repo[0] != '/' && repo[0] != '\0') {
if ((url = realpath(repo, NULL)) == NULL)
xbps_dbg_printf("[repo] %s: realpath %s\n", __func__, repo);
}
}
if (xbps_match_string_in_array(xhp->repositories, url ? url : repo)) {
xbps_dbg_printf("[repo] `%s' already stored\n", url ? url : repo);
if (url)
free(url);
return false;
}
if (xbps_array_add_cstring(xhp->repositories, url ? url : repo)) {
xbps_dbg_printf("[repo] `%s' stored successfully\n", url ? url : repo);
if (url)
free(url);
return true;
}
if (url)
free(url);
return false;
}
bool
xbps_repo_remove(struct xbps_handle *xhp, const char *repo)
{
char *url;
bool rv = false;
assert(xhp);
assert(repo);
if (xhp->repositories == NULL)
return false;
url = strdup(repo);
if (xbps_remove_string_from_array(xhp->repositories, repo)) {
if (url)
xbps_dbg_printf("[repo] `%s' removed\n", url);
rv = true;
}
free(url);
return rv;
}
struct xbps_repo *
xbps_repo_stage_open(struct xbps_handle *xhp, const char *url)
{
return repo_open_with_type(xhp, url, "stagedata");
}
struct xbps_repo *
xbps_repo_public_open(struct xbps_handle *xhp, const char *url) {
return repo_open_with_type(xhp, url, "repodata");
}
struct xbps_repo *
xbps_repo_open(struct xbps_handle *xhp, const char *url)
{
struct xbps_repo *repo = xbps_repo_public_open(xhp, url);
struct xbps_repo *stage = NULL;
xbps_dictionary_t idx;
const char *pkgname;
xbps_object_t keysym;
xbps_object_iterator_t iter;
/*
* Load and merge staging repository if the repository is local.
*/
if (repo && !repo->is_remote) {
stage = xbps_repo_stage_open(xhp, url);
if (stage == NULL)
return repo;
idx = xbps_dictionary_copy_mutable(repo->idx);
iter = xbps_dictionary_iterator(stage->idx);
while ((keysym = xbps_object_iterator_next(iter))) {
pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym);
xbps_dictionary_set(idx, pkgname,
xbps_dictionary_get_keysym(stage->idx, keysym));
}
xbps_object_iterator_release(iter);
xbps_object_release(repo->idx);
xbps_repo_release(stage);
repo->idx = idx;
return repo;
}
return repo;
}
void
xbps_repo_close(struct xbps_repo *repo)
{
if (!repo)
return;
if (repo->ar != NULL) {
archive_read_free(repo->ar);
repo->ar = NULL;
}
if (repo->fd != -1) {
close(repo->fd);
repo->fd = -1;
}
}
void
xbps_repo_release(struct xbps_repo *repo)
{
if (!repo)
return;
xbps_repo_close(repo);
if (repo->idx != NULL) {
xbps_object_release(repo->idx);
repo->idx = NULL;
}
if (repo->idxmeta != NULL) {
xbps_object_release(repo->idxmeta);
repo->idxmeta = NULL;
}
free(repo);
}
xbps_dictionary_t
xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg)
{
xbps_dictionary_t pkgd;
const char *pkgver;
char pkgname[XBPS_NAME_SIZE] = {0};
if (!repo || !repo->idx || !pkg) {
return NULL;
}
pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg);
if (!pkgd) {
return NULL;
}
if (xbps_dictionary_get(pkgd, "repository") && xbps_dictionary_get(pkgd, "pkgname")) {
return pkgd;
}
if (!xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri)) {
return NULL;
}
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
return NULL;
}
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
return NULL;
}
if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) {
return NULL;
}
xbps_dbg_printf("%s: found %s\n", __func__, pkgver);
return pkgd;
}
xbps_dictionary_t
xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
{
xbps_dictionary_t pkgd = NULL;
const char *pkgver;
char pkgname[XBPS_NAME_SIZE] = {0};
if (!repo || !repo->idx || !pkg) {
return NULL;
}
/* Try matching vpkg from configuration files */
if ((pkgd = xbps_find_virtualpkg_in_conf(repo->xhp, repo->idx, pkg))) {
goto add;
}
/* ... otherwise match a real pkg */
if ((pkgd = xbps_find_pkg_in_dict(repo->idx, pkg))) {
goto add;
}
return NULL;
add:
if (xbps_dictionary_get(pkgd, "repository") && xbps_dictionary_get(pkgd, "pkgname")) {
return pkgd;
}
if (!xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri)) {
return NULL;
}
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
return NULL;
}
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
return NULL;
}
if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) {
return NULL;
}
xbps_dbg_printf("%s: found %s\n", __func__, pkgver);
return pkgd;
}
static xbps_array_t
revdeps_match(struct xbps_repo *repo, xbps_dictionary_t tpkgd, const char *str)
{
xbps_dictionary_t pkgd;
xbps_array_t revdeps = NULL, pkgdeps, provides;
xbps_object_iterator_t iter;
xbps_object_t obj;
const char *pkgver = NULL, *tpkgver = NULL, *arch = NULL, *vpkg = NULL;
iter = xbps_dictionary_iterator(repo->idx);
assert(iter);
while ((obj = xbps_object_iterator_next(iter))) {
pkgd = xbps_dictionary_get_keysym(repo->idx, obj);
if (xbps_dictionary_equals(pkgd, tpkgd))
continue;
pkgdeps = xbps_dictionary_get(pkgd, "run_depends");
if (!xbps_array_count(pkgdeps))
continue;
/*
* Try to match passed in string.
*/
if (str) {
if (!xbps_match_pkgdep_in_array(pkgdeps, str))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &tpkgver);
/* match */
if (revdeps == NULL)
revdeps = xbps_array_create();
if (!xbps_match_string_in_array(revdeps, tpkgver))
xbps_array_add_cstring_nocopy(revdeps, tpkgver);
continue;
}
/*
* Try to match any virtual package.
*/
provides = xbps_dictionary_get(tpkgd, "provides");
for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
xbps_array_get_cstring_nocopy(provides, i, &vpkg);
if (!xbps_match_pkgdep_in_array(pkgdeps, vpkg))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver",
&tpkgver);
/* match */
if (revdeps == NULL)
revdeps = xbps_array_create();
if (!xbps_match_string_in_array(revdeps, tpkgver))
xbps_array_add_cstring_nocopy(revdeps, tpkgver);
}
/*
* Try to match by pkgver.
*/
xbps_dictionary_get_cstring_nocopy(tpkgd, "pkgver", &pkgver);
if (!xbps_match_pkgdep_in_array(pkgdeps, pkgver))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
if (!xbps_pkg_arch_match(repo->xhp, arch, NULL))
continue;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &tpkgver);
/* match */
if (revdeps == NULL)
revdeps = xbps_array_create();
if (!xbps_match_string_in_array(revdeps, tpkgver))
xbps_array_add_cstring_nocopy(revdeps, tpkgver);
}
xbps_object_iterator_release(iter);
return revdeps;
}
xbps_array_t
xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg)
{
xbps_array_t revdeps = NULL, vdeps = NULL;
xbps_dictionary_t pkgd;
const char *vpkg;
bool match = false;
if (repo->idx == NULL)
return NULL;
if (((pkgd = xbps_repo_get_pkg(repo, pkg)) == NULL) &&
((pkgd = xbps_repo_get_virtualpkg(repo, pkg)) == NULL)) {
errno = ENOENT;
return NULL;
}
/*
* If pkg is a virtual pkg let's match it instead of the real pkgver.
*/
if ((vdeps = xbps_dictionary_get(pkgd, "provides"))) {
for (unsigned int i = 0; i < xbps_array_count(vdeps); i++) {
char vpkgn[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(vdeps, i, &vpkg);
if (!xbps_pkg_name(vpkgn, XBPS_NAME_SIZE, vpkg)) {
abort();
}
if (strcmp(vpkgn, pkg) == 0) {
match = true;
break;
}
vpkg = NULL;
}
if (match)
revdeps = revdeps_match(repo, pkgd, vpkg);
}
if (!match)
revdeps = revdeps_match(repo, pkgd, NULL);
return revdeps;
}
int
xbps_repo_key_import(struct xbps_repo *repo)
{
xbps_dictionary_t repokeyd = NULL;
xbps_data_t pubkey = NULL;
uint16_t pubkey_size = 0;
const char *signedby = NULL;
char *hexfp = NULL;
char *p, *dbkeyd, *rkeyfile = NULL;
int import, rv = 0;
assert(repo);
/*
* If repository does not have required metadata plist, ignore it.
*/
if (!xbps_dictionary_count(repo->idxmeta)) {
xbps_dbg_printf("[repo] `%s' unsigned repository!\n", repo->uri);
return 0;
}
/*
* Check for required objects in index-meta:
* - signature-by (string)
* - public-key (data)
* - public-key-size (number)
*/
xbps_dictionary_get_cstring_nocopy(repo->idxmeta, "signature-by", &signedby);
xbps_dictionary_get_uint16(repo->idxmeta, "public-key-size", &pubkey_size);
pubkey = xbps_dictionary_get(repo->idxmeta, "public-key");
if (signedby == NULL || pubkey_size == 0 ||
xbps_object_type(pubkey) != XBPS_TYPE_DATA) {
xbps_dbg_printf("[repo] `%s': incomplete signed repository "
"(missing objs)\n", repo->uri);
rv = EINVAL;
goto out;
}
hexfp = xbps_pubkey2fp(pubkey);
if (hexfp == NULL) {
rv = EINVAL;
goto out;
}
/*
* Check if the public key is alredy stored.
*/
rkeyfile = xbps_xasprintf("%s/keys/%s.plist", repo->xhp->metadir, hexfp);
repokeyd = xbps_plist_dictionary_from_file(rkeyfile);
if (xbps_object_type(repokeyd) == XBPS_TYPE_DICTIONARY) {
xbps_dbg_printf("[repo] `%s' public key already stored.\n", repo->uri);
goto out;
}
/*
* Notify the client and take appropiate action to import
* the repository public key. Pass back the public key openssh fingerprint
* to the client.
*/
import = xbps_set_cb_state(repo->xhp, XBPS_STATE_REPO_KEY_IMPORT, 0,
hexfp, "`%s' repository has been RSA signed by \"%s\"",
repo->uri, signedby);
if (import <= 0) {
rv = EAGAIN;
goto out;
}
p = strdup(rkeyfile);
dbkeyd = dirname(p);
assert(dbkeyd);
if (access(dbkeyd, R_OK|W_OK) == -1) {
rv = errno;
if (rv == ENOENT)
rv = xbps_mkpath(dbkeyd, 0755);
if (rv != 0) {
rv = errno;
xbps_dbg_printf("[repo] `%s' cannot create %s: %s\n",
repo->uri, dbkeyd, strerror(errno));
free(p);
goto out;
}
}
free(p);
repokeyd = xbps_dictionary_create();
xbps_dictionary_set(repokeyd, "public-key", pubkey);
xbps_dictionary_set_uint16(repokeyd, "public-key-size", pubkey_size);
xbps_dictionary_set_cstring_nocopy(repokeyd, "signature-by", signedby);
if (!xbps_dictionary_externalize_to_file(repokeyd, rkeyfile)) {
rv = errno;
xbps_dbg_printf("[repo] `%s' failed to externalize %s: %s\n",
repo->uri, rkeyfile, strerror(rv));
}
out:
if (hexfp)
free(hexfp);
if (repokeyd)
xbps_object_release(repokeyd);
if (rkeyfile)
free(rkeyfile);
return rv;
}