forked from pantavisor/pantavisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.c
426 lines (353 loc) · 12.6 KB
/
paths.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
/*
* Copyright (c) 2022 Pantacor Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdio.h>
#include <stddef.h>
#include "paths.h"
#include "utils/str.h"
#define MODULE_NAME "paths"
#define pv_log(level, msg, ...) vlog(MODULE_NAME, level, msg, ##__VA_ARGS__)
#include "log.h"
#define PV_PATH "%s"
#define PV_PATHF PV_PATH "/%s"
void pv_paths_pv_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), name);
}
#define PV_USRMETA_PATHF PV_PATH "/" USRMETA_DNAME "/%s"
#define PV_USRMETA_PLAT_PATHF PV_PATH "/user-meta.%s/%s"
void pv_paths_pv_usrmeta_key(char *buf, size_t size, const char *key)
{
SNPRINTF_WTRUNC(buf, size, PV_USRMETA_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), key);
}
void pv_paths_pv_usrmeta_plat_key(char *buf, size_t size, const char *plat,
const char *key)
{
SNPRINTF_WTRUNC(buf, size, PV_USRMETA_PLAT_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), plat, key);
}
#define PV_DEVMETA_PATHF PV_PATH "/" DEVMETA_DNAME "/%s"
#define PV_DEVMETA_PLAT_PATHF PV_PATH "/device-meta.%s/%s"
void pv_paths_pv_devmeta_key(char *buf, size_t size, const char *key)
{
SNPRINTF_WTRUNC(buf, size, PV_DEVMETA_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), key);
}
void pv_paths_pv_devmeta_plat_key(char *buf, size_t size, const char *plat,
const char *key)
{
SNPRINTF_WTRUNC(buf, size, PV_DEVMETA_PLAT_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), plat, key);
}
#define PV_LOGS_PATHF PV_PATH "/" LOGS_DNAME "/%s"
#define PV_LOGS_PLAT_PATHF PV_LOGS_PATHF "/%s"
#define PV_LOGS_FILE_PATHF PV_LOGS_PLAT_PATHF "/%s"
void pv_paths_pv_log(char *buf, size_t size, const char *rev)
{
SNPRINTF_WTRUNC(buf, size, PV_LOGS_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), rev);
}
void pv_paths_pv_log_plat(char *buf, size_t size, const char *rev,
const char *plat)
{
SNPRINTF_WTRUNC(buf, size, PV_LOGS_PLAT_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), rev, plat);
}
void pv_paths_pv_log_file(char *buf, size_t size, const char *rev,
const char *plat, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LOGS_FILE_PATHF,
pv_config_get_str(PV_SYSTEM_RUNDIR), rev, plat, name);
}
#define PV_STORAGE_PATHF "%s"
void pv_paths_storage(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT));
}
void pv_paths_storage_log(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_PATHF,
pv_config_get_str(PV_LOG_DIR));
}
void pv_paths_storage_usrmeta(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_PATHF,
pv_config_get_str(PV_CACHE_USRMETADIR));
}
void pv_paths_storage_devmeta(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_PATHF,
pv_config_get_str(PV_CACHE_DEVMETADIR));
}
void pv_paths_storage_dropbear(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_PATHF,
pv_config_get_str(PV_DROPBEAR_CACHE_DIR));
}
#define PV_STORAGE_FILE_PATHF "%s/%s"
void pv_paths_storage_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_FILE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), name);
}
#define PV_OBJECT_PATHF "%s/objects/%s"
void pv_paths_storage_object(char *buf, size_t size, const char *sha)
{
SNPRINTF_WTRUNC(buf, size, PV_OBJECT_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), sha);
}
#define PV_TRAILS_PATHF "%s/trails/%s"
#define PV_TRAILS_FILE_PATHF PV_TRAILS_PATHF "/%s"
#define PV_TRAILS_PLAT_FILE_PATHF PV_TRAILS_PATHF "/%s/%s"
#define PV_TRAILS_CONFIG_PATHF PV_TRAILS_PATHF "/_config/%s"
#define PV_TRAILS_PV_PATHF PV_TRAILS_PATHF "/.pv/%s"
#define PV_TRAILS_PVR_PATHF PV_TRAILS_PATHF "/.pvr/%s"
void pv_paths_storage_trail(char *buf, size_t size, const char *rev)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev);
}
void pv_paths_storage_trail_file(char *buf, size_t size, const char *rev,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_FILE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, name);
}
void pv_paths_storage_trail_plat_file(char *buf, size_t size, const char *rev,
const char *plat, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_PLAT_FILE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, plat,
name);
}
void pv_paths_storage_trail_config_file(char *buf, size_t size, const char *rev,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_CONFIG_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, name);
}
void pv_paths_storage_trail_pv_file(char *buf, size_t size, const char *rev,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_PV_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, name);
}
void pv_paths_storage_trail_pvr_file(char *buf, size_t size, const char *rev,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRAILS_PVR_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, name);
}
#define PV_CONFIG_PATHF "%s/config/%s"
void pv_paths_storage_config_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CONFIG_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), name);
}
#define PV_BOOT_PATHF "%s/boot/%s"
void pv_paths_storage_boot_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_BOOT_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), name);
}
#define PV_STORAGE_DISKS_PATHF "%s/disks/"
#define PV_STORAGE_DISKS_REV_PATHF "%s/disks/rev/%s"
#define PV_STORAGE_DISKS_PERM_FILE_PATHF "%s/disks/perm/%s/%s"
#define PV_STORAGE_DISKS_REV_FILE_PATHF "%s/disks/rev/%s/%s/%s"
void pv_paths_storage_disks(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_DISKS_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT));
}
void pv_paths_storage_disks_rev(char *buf, size_t size, const char *rev)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_DISKS_REV_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev);
}
void pv_paths_storage_disks_rev_file(char *buf, size_t size, const char *rev,
const char *plat, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_DISKS_REV_FILE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), rev, plat,
name);
}
void pv_paths_storage_disks_perm_file(char *buf, size_t size, const char *plat,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_DISKS_PERM_FILE_PATHF,
pv_config_get_str(PV_STORAGE_MNTPOINT), plat, name);
}
#define PV_STORAGE_CRYPT_PATHF "%s/pv/%s/%s"
#define PV_CRYPT_DISKS_PERM_FILE_PATHF PV_STORAGE_CRYPT_PATHF "/perm/%s/%s"
#define PV_CRYPT_DISKS_REV_FILE_PATHF PV_STORAGE_CRYPT_PATHF "/rev/%s/%s/%s"
#define PV_CRYPT_DISKS_BOOT_FILE_PATHF PV_STORAGE_CRYPT_PATHF "/boot/%s/%s"
void pv_paths_storage_mounted_disk_path(char *buf, size_t size,
const char *type, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_STORAGE_CRYPT_PATHF,
pv_config_get_str(PV_SYSTEM_MEDIADIR), type, name);
}
void pv_paths_crypt_disks_rev_file(char *buf, size_t size, const char *type,
const char *dname, const char *rev,
const char *plat, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CRYPT_DISKS_REV_FILE_PATHF,
pv_config_get_str(PV_SYSTEM_MEDIADIR), type, dname, rev,
plat, name);
}
void pv_paths_crypt_disks_perm_file(char *buf, size_t size, const char *type,
const char *dname, const char *plat,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CRYPT_DISKS_PERM_FILE_PATHF,
pv_config_get_str(PV_SYSTEM_MEDIADIR), type, dname,
plat, name);
}
void pv_paths_crypt_disks_boot_file(char *buf, size_t size, const char *type,
const char *dname, const char *plat,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CRYPT_DISKS_BOOT_FILE_PATHF,
pv_config_get_str(PV_SYSTEM_MEDIADIR), type, dname,
plat, name);
}
#define PV_ROOT_PATHF "%s"
#define PV_VOLUMES_PATHF "%s/%s"
#define PV_VOLUMES_PLAT_PATHF PV_VOLUMES_PATHF "/%s"
void pv_paths_root_file(char *buf, size_t size, const char *path)
{
SNPRINTF_WTRUNC(buf, size, PV_ROOT_PATHF, path);
}
void pv_paths_volumes_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_VOLUMES_PATHF,
pv_config_get_str(PV_DISK_VOLDIR), name);
}
void pv_paths_volumes_plat_file(char *buf, size_t size, const char *plat,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_VOLUMES_PLAT_PATHF,
pv_config_get_str(PV_DISK_VOLDIR), plat, name);
}
void pv_paths_exports(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_ROOT_PATHF,
pv_config_get_str(PV_DISK_EXPORTSDIR));
}
void pv_paths_writable(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_ROOT_PATHF,
pv_config_get_str(PV_DISK_WRITABLEDIR));
}
#define PV_LIB_PLUGIN_PATHF "%s/pv_%s.so"
#define PV_LIB_MODULES_PATHF "%s/modules/%s"
#define PV_LIB_CRYPT_PATHF "%s/pv/volmount/crypt/%s"
#define PV_LIB_VOLMOUNT_PATHF "%s/pv/volmount/%s/%s"
#define PV_LIB_HOOK_PATHF "%s/pv/hooks_lxc-mount.d/%s"
#define PV_LIB_HOOKS_EARLY_SPAWN_PATHF "%s/pv/hooks_early.spawn/%s"
#define PV_LIB_LXC_ROOTFS_MOUNT_PATHF "%s/lib/lxc/rootfs"
#define PV_LIB_LXC_LXCPATH_PATHF "%s/var/lib/lxc"
void pv_paths_lib_plugin(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_PLUGIN_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), name);
}
void pv_paths_lib_modules(char *buf, size_t size, const char *release)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_MODULES_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), release);
}
void pv_paths_lib_crypt(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_CRYPT_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), name);
}
void pv_paths_lib_volmount(char *buf, size_t size, const char *type,
const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_VOLMOUNT_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), type, name);
}
void pv_paths_lib_hook(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_HOOK_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), name);
}
void pv_paths_lib_hooks_early_spawn(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_HOOKS_EARLY_SPAWN_PATHF,
pv_config_get_str(PV_SYSTEM_LIBDIR), name);
}
void pv_paths_lib_lxc_rootfs_mount(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_LXC_ROOTFS_MOUNT_PATHF,
pv_config_get_str(PV_SYSTEM_USRDIR));
}
void pv_paths_lib_lxc_lxcpath(char *buf, size_t size)
{
SNPRINTF_WTRUNC(buf, size, PV_LIB_LXC_LXCPATH_PATHF,
pv_config_get_str(PV_SYSTEM_USRDIR));
}
#define PV_ETC_PATHF "%s/%s"
#define PV_ETC_POLICY_PATHF "%s/pantavisor/policies/%s.config"
#define PV_ETC_SSH_PATHF "%s/pantavisor/ssh/%s"
void pv_paths_etc_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_ETC_PATHF,
pv_config_get_str(PV_SYSTEM_ETCDIR), name);
}
void pv_paths_etc_policy_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_ETC_POLICY_PATHF,
pv_config_get_str(PV_SYSTEM_ETCDIR), name);
}
void pv_paths_etc_ssh_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_ETC_SSH_PATHF,
pv_config_get_str(PV_SYSTEM_ETCDIR), name);
}
#define PV_CONFIGS_PATHF "%s/%s"
void pv_paths_configs_file(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CONFIGS_PATHF,
pv_config_get_str(PV_SYSTEM_CONFDIR), name);
}
#define PV_CERT_PATHF "%s/%s"
void pv_paths_cert(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_CERT_PATHF,
pv_config_get_str(PV_LIBTHTTP_CERTSDIR), name);
}
#define PV_TRUST_CERTS_PATHF "%s/%s/%s.crt"
void pv_paths_secureboot_trust_crts(char *buf, size_t size, const char *name)
{
SNPRINTF_WTRUNC(buf, size, PV_TRUST_CERTS_PATHF,
pv_config_get_str(PV_SYSTEM_ETCDIR), PVS_TRUST_DNAME,
name);
}
#define PV_TMP_PATHF "%s.tmp"
void pv_paths_tmp(char *buf, size_t size, const char *path)
{
SNPRINTF_WTRUNC(buf, size, PV_TMP_PATHF, path);
}