diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-08-18 13:43:08 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2018-08-18 13:43:08 -0400 |
commit | f3664a28a927c7a9a122af4d72a89114b26f39bd (patch) | |
tree | 9f9c98aa603a37bf51e1584fc3376394903bb7b6 | |
parent | d0eb997ee9f9889f184d0d52397b49a7f0dee009 (diff) | |
download | random-seed-f3664a28a927c7a9a122af4d72a89114b26f39bd.tar.xz random-seed-f3664a28a927c7a9a122af4d72a89114b26f39bd.zip |
Stuff.
-rw-r--r-- | Makefile.in | 19 | ||||
-rwxr-xr-x | autogen.sh | 6 | ||||
-rw-r--r-- | configure.ac | 55 | ||||
-rw-r--r-- | src/random-seed.c | 16 |
4 files changed, 76 insertions, 20 deletions
diff --git a/Makefile.in b/Makefile.in index 2c462ee..48b7bec 100644 --- a/Makefile.in +++ b/Makefile.in @@ -20,6 +20,7 @@ CFLAGS = @EXTRA_CFLAGS@ @CFLAGS@ override CFLAGS += -UNDEBUG -I$(abs_builddir) CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ VPATH := $(srcdir) SRC := src/id.c src/random-seed.c src/sha2.c src/util.c @@ -31,11 +32,17 @@ all: random-seed systemd/random-seed.service systemd/random-seed-save.service $(srcdir)/configure: $(srcdir)/aclocal.m4 $(srcdir)/autogen.sh $(srcdir)/configure.ac cd $(srcdir); ./autogen.sh -Makefile: $(srcdir)/configure Makefile.in - unset CFLAGS; $(srcdir)/configure +config.status: $(srcdir)/configure + $(SHELL) ./config.status --recheck + +Makefile: config.status Makefile.in + ./config.status + +config.h: config.status config.h.in + ./config.status random-seed: $(OBJ) - $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ + $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< @@ -48,11 +55,11 @@ src/sha2.o: src/sha2.c src/sha2.h src/id.o: src/id.c src/id.h src/sha2.h -systemd/random-seed.service systemd/random-seed-save.service: Makefile -.in: +%: %.in Makefile + mkdir -p $(@D) sed -e 's|@sbindir[@]|$(sbindir)|g' \ -e 's|@default_seed_path_dir[@]|$(default_seed_path_dir)|g' \ - $(srcdir)/$@.in > $@ + $< > $@ install: all install -D -m755 random-seed $(DESTDIR)$(sbindir)/random-seed @@ -3,8 +3,8 @@ set -e -autoheader & -aclocal -I m4 --install -autoconf +{ ${AUTOHEADER:-autoheader} && touch config.h; } & +${ACLOCAL:-aclocal} -I m4 --install && touch aclocal.m4 +${AUTOCONF:-autoconf} && touch configure wait diff --git a/configure.ac b/configure.ac index 5db95ac..485cc16 100644 --- a/configure.ac +++ b/configure.ac @@ -15,9 +15,9 @@ AS_IF([test "$ac_cv_prog_cc_c99" = no], CPPFLAGS="${CPPFLAGS+$CPPFLAGS }-D_GNU_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L" AC_ARG_ENABLE(debug, - AC_HELP_STRING(--enable-debug, [enable debug output [no]]), - [enable_debug=$enableval], - [enable_debug=no] + AC_HELP_STRING(--enable-debug, [enable debug output [no]]), + [enable_debug=$enableval], + [enable_debug=no] ) AS_CASE([$enable_debug], [yes], [AC_DEFINE(DEBUG, [], [enable debug output])], @@ -25,6 +25,48 @@ AS_CASE([$enable_debug], [AC_MSG_ERROR([invalid argument to --enable-debug])] ) +AC_ARG_WITH(udev, + AC_HELP_STRING(--with-udev, [enable libudev support [auto]]), + [with_udev=$withval], + [with_udev=auto] +) +AS_CASE([$with_udev], + [no], [], + [yes], [ PKG_CHECK_MODULES(LIBUDEV, libudev, [WITH_UDEV=1]) ], + [auto], [ PKG_CHECK_MODULES(LIBUDEV, libudev, [WITH_UDEV=1], []) ], + [AC_MSG_ERROR([invalid argument to --with-udev])] +) +AS_IF([test "$WITH_UDEV" = 1], [ + AC_DEFINE(HAVE_LIBUDEV, [], [enable libudev support]) + CFLAGS="${CFLAGS:+$CFLAGS }$LIBUDEV_CFLAGS" + LIBS="${LIBS:+$LIBS }$LIBUDEV_LIBS" +]) + +AC_ARG_WITH(util-linux, + AC_HELP_STRING(--with-util-linux, [enable util-linux support (libmount, libblkid) [auto]]), + [with_util_linux=$withval], + [with_util_linux=auto] +) +AS_CASE([$with_util_linux], + [no], [], + [yes], [ + PKG_CHECK_MODULES(LIBBLKID, blkid) + PKG_CHECK_MODULES(LIBMOUNT, mount) + WITH_UTIL_LINUX=1 + ], + [auto], [ + WITH_UTIL_LINUX=1 + PKG_CHECK_MODULES(LIBBLKID, blkid, [], [WITH_UTIL_LINUX=0]) + PKG_CHECK_MODULES(LIBMOUNT, mount, [], [WITH_UTIL_LINUX=0]) + ], + [AC_MSG_ERROR([invalid argument to --with-udev])] +) +AS_IF([test "$WITH_UTIL_LINUX" = 1], [ + AC_DEFINE(HAVE_UTIL_LINUX, [], [enable util-linux support]) + CFLAGS="${CFLAGS:+$CFLAGS }$LIBBLKID_CFLAGS $LIBMOUNT_CFLAGS" + LIBS="${LIBS:+$LIBS }$LIBBLKID_LIBS $LIBMOUNT_LIBS" +]) + AC_ARG_WITH([machine-id-path], AC_HELP_STRING(--with-machine-id-path, [manually specify machine-id location [/etc/machine-id, /var/lib/dbus/machine-id]]), [machine_id_path=$withval] @@ -40,9 +82,10 @@ AS_IF([test -n "$machine_id_path"], ) AC_ARG_WITH([default-seed-path], - AC_HELP_STRING(--with-default-seed-path, [default seed path if no command line argument [/var/lib/random-seed]]), - [default_seed_path=$withval], - [default_seed_path=/var/lib/random-seed]) + AC_HELP_STRING(--with-default-seed-path, [default seed path if no command line argument [/var/lib/random-seed]]), + [default_seed_path=$withval], + [default_seed_path=/var/lib/random-seed] +) AC_DEFINE_UNQUOTED(DEFAULT_SEED_PATH, "$default_seed_path", [default seed path]) default_seed_path_dir=${default_seed_path%/*} AC_SUBST(default_seed_path_dir) diff --git a/src/random-seed.c b/src/random-seed.c index 0ce1f8b..dd1c447 100644 --- a/src/random-seed.c +++ b/src/random-seed.c @@ -49,7 +49,7 @@ static inline void usage() { } static bool run_seed_file_cmd(const char *cmd, const unsigned char *salt, FILE *seed_file) { -#define HASH_ID_CMD(my_cmd, type, fn, hash_access, ...) \ +#define HASH_ID_CMD(my_cmd, type, fn, data_accessor, ...) \ do { \ if (!streq(cmd, my_cmd)) \ break; \ @@ -66,7 +66,7 @@ static bool run_seed_file_cmd(const char *cmd, const unsigned char *salt, FILE * fputs("error getting " my_cmd " hash\n", stderr); \ return false; \ } \ - hash(salt, fn ## _hash, hash_access fn ## _buf, sz); \ + hash(salt, fn ## _hash, data_accessor fn ## _buf, sz); \ unsigned char theirdigest[HASH_LEN]; \ if (hex2mem(theirdigest, HASH_LEN, arg) == 0) { \ fputs("error decoding hex hash\n", stderr); \ @@ -81,7 +81,7 @@ static bool run_seed_file_cmd(const char *cmd, const unsigned char *salt, FILE * HASH_ID_CMD("machine-id", char *, get_machine_id, ); HASH_ID_CMD("fs-id", fsid_t, get_fs_id, &, fileno(seed_file)); -#if defined(HAVE_UDEV) || defined(HAVE_UTIL_LINUX) +#if defined(HAVE_LIBUDEV) || defined(HAVE_UTIL_LINUX) HASH_ID_CMD("fs-uuid", char *, get_fs_uuid, fileno(seed_file)); #else if (streq(cmd, "fs-uuid")) { @@ -89,7 +89,7 @@ static bool run_seed_file_cmd(const char *cmd, const unsigned char *salt, FILE * return false; } #endif -#ifdef HAVE_UDEV +#ifdef HAVE_LIBUDEV HASH_ID_CMD("drive-id", char *, get_drive_id, fileno(seed_file)); #else if (streq(cmd, "drive-id")) { @@ -105,7 +105,7 @@ static bool load(FILE *seed_file) { bool credit_entropy = true; struct rand_pool_info_ rpi = { - .entropy_count = RAND_POOL_SIZE * 8, + .entropy_count = RAND_POOL_SIZE * CHAR_BIT, .buf_size = RAND_POOL_SIZE, .buf = { 0 } }; @@ -302,6 +302,12 @@ static bool save(const char *seed_path, unsigned char *random_buf) { } GET_HASH_STR(fsid_t, &, fs_id, seed_dir_fd); +#ifdef HAVE_LIBUDEV + GET_HASH_STR(char *, , drive_id, seed_dir_fd); +#endif +#if defined(HAVE_LIBUDEV) || defined(HAVE_UTIL_LINUX) + GET_HASH_STR(char *, , fs_uuid, seed_dir_fd); +#endif seed_fd = openat(seed_dir_fd, seed_name_new, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (seed_fd == -1) { |