From 74f2c4aa18f231830c29cdbd278674628956d20d Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 19 Jun 2015 19:28:25 -0400 Subject: [PATCH] fix diet libc build breaks for e4crypt and fallocate Diet libc doesn't support syscall correctly, but it does have add_key() and keyctl() in libc (although glibc does not). So change e4crypt to use add_key() and keyctl() directly if they are available. Signed-off-by: Theodore Ts'o --- configure | 4 ++-- configure.in | 3 +++ lib/config.h.in | 12 ++++++++++++ lib/ext2fs/fallocate.c | 4 ++++ misc/e4crypt.c | 23 ++++++++++++++++++++--- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/configure b/configure index e571948..c9da791 100755 --- a/configure +++ b/configure @@ -12394,7 +12394,7 @@ fi done fi -for ac_header in dirent.h errno.h execinfo.h getopt.h malloc.h mntent.h paths.h semaphore.h setjmp.h signal.h stdarg.h stdint.h stdlib.h termios.h termio.h unistd.h utime.h attr/xattr.h linux/falloc.h linux/fd.h linux/major.h linux/loop.h net/if_dl.h netinet/in.h sys/acl.h sys/disklabel.h sys/disk.h sys/file.h sys/ioctl.h sys/mkdev.h sys/mman.h sys/mount.h sys/prctl.h sys/resource.h sys/select.h sys/socket.h sys/sockio.h sys/stat.h sys/syscall.h sys/sysctl.h sys/sysmacros.h sys/time.h sys/types.h sys/un.h sys/wait.h +for ac_header in dirent.h errno.h execinfo.h getopt.h malloc.h mntent.h paths.h semaphore.h setjmp.h signal.h stdarg.h stdint.h stdlib.h termios.h termio.h unistd.h utime.h attr/xattr.h linux/falloc.h linux/fd.h linux/major.h linux/loop.h net/if_dl.h netinet/in.h sys/acl.h sys/disklabel.h sys/disk.h sys/file.h sys/ioctl.h sys/key.h sys/mkdev.h sys/mman.h sys/mount.h sys/prctl.h sys/resource.h sys/select.h sys/socket.h sys/sockio.h sys/stat.h sys/syscall.h sys/sysctl.h sys/sysmacros.h sys/time.h sys/types.h sys/un.h sys/wait.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -13061,7 +13061,7 @@ if test "$ac_res" != no; then : fi fi -for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llistxattr llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime utimes valloc +for ac_func in __secure_getenv add_key backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 keyctl llistxattr llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite pread64 pwrite64 secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime utimes valloc do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index e75a84e..b5bbcce 100644 --- a/configure.in +++ b/configure.in @@ -923,6 +923,7 @@ AC_CHECK_HEADERS(m4_flatten([ sys/disk.h sys/file.h sys/ioctl.h + sys/key.h sys/mkdev.h sys/mman.h sys/mount.h @@ -1073,6 +1074,7 @@ fi dnl AC_CHECK_FUNCS(m4_flatten([ __secure_getenv + add_key backtrace blkid_probe_get_topology blkid_probe_enable_partitions @@ -1092,6 +1094,7 @@ AC_CHECK_FUNCS(m4_flatten([ getrlimit getrusage jrand48 + keyctl llistxattr llseek lseek64 diff --git a/lib/config.h.in b/lib/config.h.in index 3a122b2..8ac5093 100644 --- a/lib/config.h.in +++ b/lib/config.h.in @@ -45,6 +45,9 @@ language is requested. */ #undef ENABLE_NLS +/* Define to 1 if you have the `add_key' function. */ +#undef HAVE_ADD_KEY + /* Define to 1 if you have `alloca', as a function or macro. */ #undef HAVE_ALLOCA @@ -226,6 +229,9 @@ /* Define to 1 if you have the `jrand48' function. */ #undef HAVE_JRAND48 +/* Define to 1 if you have the `keyctl' function. */ +#undef HAVE_KEYCTL + /* Define if you have and nl_langinfo(CODESET). */ #undef HAVE_LANGINFO_CODESET @@ -349,6 +355,9 @@ /* Define to 1 if you have the `pread64' function. */ #undef HAVE_PREAD64 +/* Define to 1 if you have the header file. */ +#undef HAVE_PTHREAD_H + /* Define if the defines PTHREAD_MUTEX_RECURSIVE. */ #undef HAVE_PTHREAD_MUTEX_RECURSIVE @@ -479,6 +488,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_IOCTL_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_KEY_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MKDEV_H diff --git a/lib/ext2fs/fallocate.c b/lib/ext2fs/fallocate.c index 8b502d5..5ae3125 100644 --- a/lib/ext2fs/fallocate.c +++ b/lib/ext2fs/fallocate.c @@ -11,6 +11,10 @@ #include "config.h" +#if HAVE_SYS_TYPES_H +#include +#endif + #include "ext2_fs.h" #include "ext2fs.h" #define min(a, b) ((a) < (b) ? (a) : (b)) diff --git a/misc/e4crypt.c b/misc/e4crypt.c index c5b384a..c186eb8 100644 --- a/misc/e4crypt.c +++ b/misc/e4crypt.c @@ -38,7 +38,12 @@ #include #include #include -#include +#if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL) +#include +#endif +#ifdef HAVE_SYS_KEY_H +#include +#endif #include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fs.h" @@ -71,6 +76,7 @@ typedef __s32 key_serial_t; int options; +#ifndef HAVE_KEYCTL static long keyctl(int cmd, ...) { va_list va; @@ -84,6 +90,17 @@ static long keyctl(int cmd, ...) va_end(va); return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5); } +#endif + +#ifndef HAVE_ADD_KEY +key_serial_t add_key(const char *type, const char *description, + const void *payload, size_t plen, + key_serial_t keyring) +{ + return syscall(__NR_add_key, type, description, payload, + plen, keyring); +} +#endif static const char *hexchars = "0123456789abcdef"; static const size_t hexchars_size = 16; @@ -566,8 +583,8 @@ static void insert_key_into_keyring(const char *keyring, struct salt *salt) key.mode = EXT4_ENCRYPTION_MODE_AES_256_XTS; memcpy(key.raw, salt->key, EXT4_MAX_KEY_SIZE); key.size = EXT4_MAX_KEY_SIZE; - rc = syscall(__NR_add_key, EXT2FS_KEY_TYPE_LOGON, key_ref_full, - (void *)&key, sizeof(key), keyring_id); + rc = add_key(EXT2FS_KEY_TYPE_LOGON, key_ref_full, (void *)&key, + sizeof(key), keyring_id); if (rc == -1) { if (errno == EDQUOT) { printf("Error adding key to keyring; quota exceeded\n"); -- 1.8.3.1