Skip to content

Commit a930899

Browse files
committed
configure: Add check for O_NOFOLLOW definition in fcntl.h
This lets us use O_NOFOLLOW without having to check whether it is defined first. The sudoedit code needs to know whether O_NOFOLLOW actually functions so use HAVE_DECL_O_NOFOLLOW there.
1 parent cb8e510 commit a930899

7 files changed

Lines changed: 36 additions & 12 deletions

File tree

config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@
172172
don't. */
173173
#undef HAVE_DECL_O_DIRECTORY
174174

175+
/* Define to 1 if you have the declaration of 'O_NOFOLLOW', and to 0 if you
176+
don't. */
177+
#undef HAVE_DECL_O_NOFOLLOW
178+
175179
/* Define to 1 if you have the declaration of 'passwdexpiredx', and to 0 if
176180
you don't. */
177181
#undef HAVE_DECL_PASSWDEXPIREDX

configure

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29526,6 +29526,21 @@ fi
2952629526
printf "%s\n" "#define HAVE_DECL_O_DIRECTORY $ac_have_decl" >>confdefs.h
2952729527

2952829528

29529+
ac_fn_check_decl "$LINENO" "O_NOFOLLOW" "ac_cv_have_decl_O_NOFOLLOW" "
29530+
$ac_includes_default
29531+
#include <fcntl.h>
29532+
29533+
" "$ac_c_undeclared_builtin_options" "CFLAGS"
29534+
if test "x$ac_cv_have_decl_O_NOFOLLOW" = xyes
29535+
then :
29536+
ac_have_decl=1
29537+
else case e in #(
29538+
e) ac_have_decl=0 ;;
29539+
esac
29540+
fi
29541+
printf "%s\n" "#define HAVE_DECL_O_NOFOLLOW $ac_have_decl" >>confdefs.h
29542+
29543+
2952929544
ac_fn_check_decl "$LINENO" "errno" "ac_cv_have_decl_errno" "
2953029545
$ac_includes_default
2953129546
#include <errno.h>

configure.ac

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,6 +3395,14 @@ AC_INCLUDES_DEFAULT
33953395
#include <fcntl.h>
33963396
])
33973397

3398+
dnl
3399+
dnl Check for O_NOFOLLOW declaration in fcntl.h
3400+
dnl
3401+
AC_CHECK_DECLS([O_NOFOLLOW], [], [], [
3402+
AC_INCLUDES_DEFAULT
3403+
#include <fcntl.h>
3404+
])
3405+
33983406
dnl
33993407
dnl Check for errno declaration in errno.h
34003408
dnl

include/sudo_compat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
# define O_DIRECTORY 0
150150
#endif
151151

152+
/* Older systems lack O_NOFOLLOW. */
153+
#if defined(HAVE_DECL_O_NOFOLLOW) && !HAVE_DECL_O_NOFOLLOW
154+
# define O_NOFOLLOW 0
155+
#endif
156+
152157
/*
153158
* BSD defines these in <sys/param.h> but we don't include that anymore.
154159
*/

lib/util/mkdir_parents.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
#include <sudo_debug.h>
4040
#include <sudo_util.h>
4141

42-
#ifndef O_NOFOLLOW
43-
# define O_NOFOLLOW 0
44-
#endif
45-
4642
/*
4743
* Returns true if fd is a directory, else false.
4844
* Warns on failure if not quiet.

logsrvd/logsrvd.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@
7070
#include <logsrvd.h>
7171
#include <hostcheck.h>
7272

73-
#ifndef O_NOFOLLOW
74-
# define O_NOFOLLOW 0
75-
#endif
76-
7773
/*
7874
* Sudo I/O audit server.
7975
*/

src/edit_open.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ dir_is_writable(int dfd, const struct sudo_cred *user_cred,
232232
}
233233
#endif /* HAVE_FACCESSAT && AT_EACCESS */
234234

235-
#ifdef O_NOFOLLOW
235+
#if defined(HAVE_DECL_O_NOFOLLOW) && HAVE_DECL_O_NOFOLLOW
236236
static int
237237
sudo_edit_openat_nofollow(int dfd, char *path, int oflags, mode_t mode)
238238
{
@@ -332,7 +332,7 @@ sudo_edit_openat_nofollow(int dfd, char *path, int oflags, mode_t mode)
332332

333333
debug_return_int(fd);
334334
}
335-
#endif /* O_NOFOLLOW */
335+
#endif /* HAVE_DECL_O_NOFOLLOW */
336336

337337
static int
338338
sudo_edit_open_nonwritable(char *path, int oflags, mode_t mode,
@@ -400,7 +400,7 @@ sudo_edit_open_nonwritable(char *path, int oflags, mode_t mode,
400400
debug_return_int(fd);
401401
}
402402

403-
#ifdef O_NOFOLLOW
403+
#if defined(HAVE_DECL_O_NOFOLLOW) && HAVE_DECL_O_NOFOLLOW
404404
int
405405
sudo_edit_open(char *path, int oflags, mode_t mode, unsigned int sflags,
406406
const struct sudo_cred *user_cred, const struct sudo_cred *cur_cred)
@@ -474,7 +474,7 @@ sudo_edit_open(char *path, int oflags, mode_t mode, unsigned int sflags,
474474

475475
debug_return_int(fd);
476476
}
477-
#endif /* O_NOFOLLOW */
477+
#endif /* HAVE_DECL_O_NOFOLLOW */
478478

479479
/*
480480
* Verify that the parent dir of a new file exists and is not writable

0 commit comments

Comments
 (0)