1
0
mirror of https://github.com/dovecot/core.git synced 2026-10-23 22:08:58 +03:00

meson: Random

This commit is contained in:
Fred Morcos
2026-07-20 17:28:36 +02:00
committed by timo.sirainen
parent 8589748075
commit 8a0ee7dc91
3 changed files with 50 additions and 0 deletions

View File

@@ -121,6 +121,7 @@ subdir('meson' / 'defines')
subdir('meson' / 'endian')
subdir('meson' / 'libbsd')
subdir('meson' / 'libc')
subdir('meson' / 'random')
dovecot_moduledir = get_option('moduledir')
if dovecot_moduledir == ''

View File

@@ -10,3 +10,4 @@ option('hardening-sls', type: 'combo', choices: ['none', 'all', 'return', 'indir
option('hardening-stack-protector', type: 'combo', choices: ['off', 'auto', 'normal', 'strong'], value: 'auto', description: 'Add stack guards for buffer overflows')
option('libbsd', type: 'feature', value: 'disabled', description: 'Use libbsd for arc4random() and setproctitle()')
option('mem-align', type: 'integer', value: 8, min: 1, description: 'Set the memory alignment')
option('random-source', type: 'string', value : '/dev/urandom', description: 'Device file to use as random source')

48
meson/random/meson.build Normal file
View File

@@ -0,0 +1,48 @@
random_source = get_option('random-source')
have_getrandom = cc.has_function('getrandom', prefix: libc_prefix)
have_arc4random = cc.has_function('arc4random_buf', prefix: libc_prefix)
if not have_arc4random and ext_bsd.found()
have_arc4random = cc.has_function(
'arc4random_buf',
prefix: libc_prefix + '#include <bsd/stdlib.h>\n',
dependencies: ext_bsd,
)
endif
have_decl_getrandom = cc.has_header_symbol('sys/random.h', 'getrandom')
conf.set('HAVE_GETRANDOM', have_getrandom)
conf.set('HAVE_ARC4RANDOM', have_arc4random)
conf.set10('HAVE_DECL_GETRANDOM', have_decl_getrandom)
fs = import('fs')
if fs.exists(random_source) and \
fs.is_absolute(random_source) and \
fs.is_dir(random_source) == false and \
(fs.is_file(random_source) == false or fs.size(random_source) > 0)
conf.set_quoted('DEV_URANDOM_PATH', random_source)
else
error(f'Random source @random_source@ not usable')
endif
# Which generator randgen.c compiles in, following the same order it does. Anything else
# falls back to reading the device, so name that path by its own option value.
if get_option('fuzzing')
# Fuzzing builds seed the deterministic KISS PRNG unconditionally.
random_backend = 'kiss'
elif have_getrandom and have_decl_getrandom
random_backend = 'getrandom'
elif have_arc4random
random_backend = 'arc4random'
else
random_backend = random_source
endif
# DEBUG builds also compile in KISS, but only use it when DOVECOT_SRAND asks for it.
if development_extra_checks == 'yes' and not get_option('fuzzing')
random_backend += ' (or kiss, when DOVECOT_SRAND is set)'
endif
summary({'Random source' : random_backend}, section: 'Features')