Mercurial > hg > octave-jordi > gnulib-hg
annotate m4/fcntl_h.m4 @ 12180:2c71cf09ef7e
Avoid symlink attack in localcharset module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 18 Oct 2009 16:58:39 +0200 |
parents | 01c9ffd58a51 |
children | e8d2c6fc33ad |
rev | line source |
---|---|
12180
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
1 # serial 6 |
7225 | 2 # Configure fcntl.h. |
11007
f6cba5a556ce
many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents:
9299
diff
changeset
|
3 dnl Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. |
7225 | 4 dnl This file is free software; the Free Software Foundation |
5 dnl gives unlimited permission to copy and/or distribute it, | |
6 dnl with or without modifications, as long as this notice is preserved. | |
7 | |
8 dnl Written by Paul Eggert. | |
9 | |
10 AC_DEFUN([gl_FCNTL_H], | |
11 [ | |
11482 | 12 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) |
12180
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
13 AC_REQUIRE([gl_FCNTL_O_FLAGS]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
14 gl_CHECK_NEXT_HEADERS([fcntl.h]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
15 FCNTL_H='fcntl.h' |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
16 AC_SUBST([FCNTL_H]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
17 ]) |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
18 |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
19 # Test whether the flags O_NOATIME and O_NOFOLLOW actually work. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
20 # Define HAVE_WORKING_O_NOATIME to 1 if O_NOATIME works, or to 0 otherwise. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
21 # Define HAVE_WORKING_O_NOFOLLOW to 1 if O_NOFOLLOW works, or to 0 otherwise. |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
22 AC_DEFUN([gl_FCNTL_O_FLAGS], |
2c71cf09ef7e
Avoid symlink attack in localcharset module.
Bruno Haible <bruno@clisp.org>
parents:
12051
diff
changeset
|
23 [ |
11482 | 24 dnl Persuade glibc <fcntl.h> to define O_NOATIME and O_NOFOLLOW. |
11479
2e168b9fc9aa
Make fcntl module detect O_NOATIME, O_NOFOLLOW on GNU/Linux.
Ben Pfaff <blp@cs.stanford.edu>
parents:
11007
diff
changeset
|
25 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
11007
f6cba5a556ce
many *.m4 files: improve m4 quoting
Jim Meyering <meyering@redhat.com>
parents:
9299
diff
changeset
|
26 AC_CACHE_CHECK([for working fcntl.h], [gl_cv_header_working_fcntl_h], |
7225 | 27 [AC_RUN_IFELSE( |
28 [AC_LANG_PROGRAM( | |
29 [[#include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 #include <unistd.h> | |
32 #include <fcntl.h> | |
7408 | 33 #ifndef O_NOATIME |
34 #define O_NOATIME 0 | |
35 #endif | |
7225 | 36 #ifndef O_NOFOLLOW |
37 #define O_NOFOLLOW 0 | |
38 #endif | |
39 static int const constants[] = | |
40 { | |
41 O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC, O_APPEND, | |
42 O_NONBLOCK, O_SYNC, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY | |
43 }; | |
44 ]], | |
7408 | 45 [[ |
46 int status = !constants; | |
47 { | |
48 static char const sym[] = "conftest.sym"; | |
49 if (symlink (".", sym) != 0 | |
50 || close (open (sym, O_RDONLY | O_NOFOLLOW)) == 0) | |
51 status |= 32; | |
12051
01c9ffd58a51
link-follow: ensure correct result
Eric Blake <ebb9@byu.net>
parents:
12047
diff
changeset
|
52 unlink (sym); |
7408 | 53 } |
54 { | |
55 static char const file[] = "confdefs.h"; | |
56 int fd = open (file, O_RDONLY | O_NOATIME); | |
57 char c; | |
58 struct stat st0, st1; | |
59 if (fd < 0 | |
60 || fstat (fd, &st0) != 0 | |
61 || sleep (1) != 0 | |
62 || read (fd, &c, 1) != 1 | |
63 || close (fd) != 0 | |
64 || stat (file, &st1) != 0 | |
7687
7fcc949f763a
* m4/fcntl_h.m4 (gl_FCNTL_H): Test the atime, not the mtime.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7408
diff
changeset
|
65 || st0.st_atime != st1.st_atime) |
7408 | 66 status |= 64; |
67 } | |
68 return status;]])], | |
7225 | 69 [gl_cv_header_working_fcntl_h=yes], |
7408 | 70 [case $? in #( |
71 32) gl_cv_header_working_fcntl_h='no (bad O_NOFOLLOW)';; #( | |
72 64) gl_cv_header_working_fcntl_h='no (bad O_NOATIME)';; #( | |
73 96) gl_cv_header_working_fcntl_h='no (bad O_NOATIME, O_NOFOLLOW)';; #( | |
74 *) gl_cv_header_working_fcntl_h='no';; | |
75 esac], | |
7225 | 76 [gl_cv_header_working_fcntl_h=cross-compiling])]) |
77 | |
7408 | 78 case $gl_cv_header_working_fcntl_h in #( |
79 *O_NOATIME* | no | cross-compiling) ac_val=0;; #( | |
80 *) ac_val=1;; | |
81 esac | |
82 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOATIME], [$ac_val], | |
83 [Define to 1 if O_NOATIME works.]) | |
84 | |
85 case $gl_cv_header_working_fcntl_h in #( | |
86 *O_NOFOLLOW* | no | cross-compiling) ac_val=0;; #( | |
87 *) ac_val=1;; | |
88 esac | |
89 AC_DEFINE_UNQUOTED([HAVE_WORKING_O_NOFOLLOW], [$ac_val], | |
90 [Define to 1 if O_NOFOLLOW works.]) | |
7225 | 91 ]) |
9299 | 92 |
93 AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], | |
94 [ | |
95 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
96 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) | |
97 GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 | |
98 ]) | |
99 | |
100 AC_DEFUN([gl_FCNTL_H_DEFAULTS], | |
101 [ | |
12047
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
102 GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) |
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
103 GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT]) |
9299 | 104 dnl Assume proper GNU behavior unless another module says otherwise. |
12047
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
105 HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT]) |
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
106 REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) |
21ec8b9a3f27
openat: fix openat bugs on Solaris 9
Eric Blake <ebb9@byu.net>
parents:
11966
diff
changeset
|
107 REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT]) |
9299 | 108 ]) |