Whamcloud - gitweb
fix diet libc build breaks for e4crypt and fallocate
authorTheodore Ts'o <tytso@mit.edu>
Fri, 19 Jun 2015 23:28:25 +0000 (19:28 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 19 Jun 2015 23:28:25 +0000 (19:28 -0400)
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 <tytso@mit.edu>
configure
configure.in
lib/config.h.in
lib/ext2fs/fallocate.c
misc/e4crypt.c

index e571948..c9da791 100755 (executable)
--- 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"
index e75a84e..b5bbcce 100644 (file)
@@ -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
index 3a122b2..8ac5093 100644 (file)
@@ -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
 
 /* 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 <langinfo.h> and nl_langinfo(CODESET). */
 #undef HAVE_LANGINFO_CODESET
 
 /* Define to 1 if you have the `pread64' function. */
 #undef HAVE_PREAD64
 
+/* Define to 1 if you have the <pthread.h> header file. */
+#undef HAVE_PTHREAD_H
+
 /* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
 #undef HAVE_PTHREAD_MUTEX_RECURSIVE
 
 /* Define to 1 if you have the <sys/ioctl.h> header file. */
 #undef HAVE_SYS_IOCTL_H
 
+/* Define to 1 if you have the <sys/key.h> header file. */
+#undef HAVE_SYS_KEY_H
+
 /* Define to 1 if you have the <sys/mkdev.h> header file. */
 #undef HAVE_SYS_MKDEV_H
 
index 8b502d5..5ae3125 100644 (file)
 
 #include "config.h"
 
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
 #include "ext2_fs.h"
 #include "ext2fs.h"
 #define min(a, b) ((a) < (b) ? (a) : (b))
index c5b384a..c186eb8 100644 (file)
 #include <termios.h>
 #include <unistd.h>
 #include <signal.h>
-#include <asm/unistd.h>
+#if !defined(HAVE_ADD_KEY) || !defined(HAVE_KEYCTL)
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYS_KEY_H
+#include <sys/key.h>
+#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");