Skip to content

Commit cb8e510

Browse files
committed
configure: Add check for O_DIRECTORY definition in fcntl.h
This is needed by sudoedit to avoid a potential issue on systems without O_DIRECTORY where the wrong version of the DIR_OPEN_FLAGS macro could be used.
1 parent ff0b6be commit cb8e510

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
*/
169169
#undef HAVE_DECL_NSIG
170170

171+
/* Define to 1 if you have the declaration of 'O_DIRECTORY', and to 0 if you
172+
don't. */
173+
#undef HAVE_DECL_O_DIRECTORY
174+
171175
/* Define to 1 if you have the declaration of 'passwdexpiredx', and to 0 if
172176
you don't. */
173177
#undef HAVE_DECL_PASSWDEXPIREDX

configure

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29511,6 +29511,21 @@ esac
2951129511
fi
2951229512

2951329513

29514+
ac_fn_check_decl "$LINENO" "O_DIRECTORY" "ac_cv_have_decl_O_DIRECTORY" "
29515+
$ac_includes_default
29516+
#include <fcntl.h>
29517+
29518+
" "$ac_c_undeclared_builtin_options" "CFLAGS"
29519+
if test "x$ac_cv_have_decl_O_DIRECTORY" = xyes
29520+
then :
29521+
ac_have_decl=1
29522+
else case e in #(
29523+
e) ac_have_decl=0 ;;
29524+
esac
29525+
fi
29526+
printf "%s\n" "#define HAVE_DECL_O_DIRECTORY $ac_have_decl" >>confdefs.h
29527+
29528+
2951429529
ac_fn_check_decl "$LINENO" "errno" "ac_cv_have_decl_errno" "
2951529530
$ac_includes_default
2951629531
#include <errno.h>

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3387,6 +3387,14 @@ AC_INCLUDES_DEFAULT
33873387
#include <signal.h>
33883388
])
33893389

3390+
dnl
3391+
dnl Check for O_DIRECTORY declaration in fcntl.h
3392+
dnl
3393+
AC_CHECK_DECLS([O_DIRECTORY], [], [], [
3394+
AC_INCLUDES_DEFAULT
3395+
#include <fcntl.h>
3396+
])
3397+
33903398
dnl
33913399
dnl Check for errno declaration in errno.h
33923400
dnl

include/sudo_compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
#endif
146146

147147
/* Older systems lack O_DIRECTORY. */
148-
#ifndef O_DIRECTORY
148+
#if defined(HAVE_DECL_O_DIRECTORY) && !HAVE_DECL_O_DIRECTORY
149149
# define O_DIRECTORY 0
150150
#endif
151151

src/sudo_edit.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
* Use O_SEARCH/O_PATH and/or O_DIRECTORY where possible.
2525
*/
2626
#if defined(O_SEARCH)
27-
# if defined(O_DIRECTORY)
27+
# if defined(HAVE_DECL_O_DIRECTORY) && HAVE_DECL_O_DIRECTORY
2828
# define DIR_OPEN_FLAGS (O_SEARCH|O_DIRECTORY)
2929
# else
3030
# define DIR_OPEN_FLAGS (O_SEARCH)
3131
# endif
3232
#elif defined(O_PATH)
33-
# if defined(O_DIRECTORY)
33+
# if defined(HAVE_DECL_O_DIRECTORY) && HAVE_DECL_O_DIRECTORY
3434
# define DIR_OPEN_FLAGS (O_PATH|O_DIRECTORY)
3535
# else
3636
# define DIR_OPEN_FLAGS (O_PATH)
3737
# endif
38-
#elif defined(O_DIRECTORY)
38+
#elif defined(HAVE_DECL_O_DIRECTORY) && HAVE_DECL_O_DIRECTORY
3939
# define DIR_OPEN_FLAGS (O_RDONLY|O_DIRECTORY)
4040
#else
4141
# define DIR_OPEN_FLAGS (O_RDONLY|O_NONBLOCK)

0 commit comments

Comments
 (0)