From 1c20ff1a6da5543187e1e85e58258fcbd565ccb3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Sep 2004 17:14:52 +0000 Subject: [PATCH] Use utimes() and futimes() instead of utime() in touch(), emulating as needed. Not all systems are able to support setting the times of an fd so touch() takes both an fd and a file name as arguments. --- Makefile.in | 2 +- aclocal.m4 | 24 ----- check.c | 5 +- compat.h | 8 ++ config.h.in | 34 ++++--- configure | 234 ++++++++++++++++++++++++++++++++------------ configure.in | 8 +- fileops.c | 33 +++---- sudo.h | 8 +- sudo_edit.c | 2 +- utime.c => utimes.c | 62 +++++++----- visudo.c | 2 +- 12 files changed, 268 insertions(+), 154 deletions(-) rename utime.c => utimes.c (57%) diff --git a/Makefile.in b/Makefile.in index 82ddd4190..0a0ac5a23 100644 --- a/Makefile.in +++ b/Makefile.in @@ -103,7 +103,7 @@ SRCS = alloc.c alloca.c check.c closefrom.c def_data.c defaults.c env.c err.c \ goodpath.c interfaces.c ldap.c lex.yy.c lsearch.c logging.c parse.c \ parse.lex parse.yacc set_perms.c sigaction.c snprintf.c strcasecmp.c \ strerror.c strlcat.c strlcpy.c sudo.c sudo_noexec.c sudo.tab.c \ - sudo_edit.c testsudoers.c tgetpass.c utime.c visudo.c zero_bytes.c \ + sudo_edit.c testsudoers.c tgetpass.c utimes.c visudo.c zero_bytes.c \ $(AUTH_SRCS) AUTH_SRCS = auth/afs.c auth/aix_auth.c auth/bsdauth.c auth/dce.c auth/fwtk.c \ diff --git a/aclocal.m4 b/aclocal.m4 index a418330ed..e6c29943e 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -210,30 +210,6 @@ dnl AC_DEFUN(SUDO_TYPE_INO_T, [SUDO_CHECK_TYPE(ino_t, unsigned int)]) -dnl -dnl check for POSIX utime() using struct utimbuf -dnl -AC_DEFUN(SUDO_FUNC_UTIME_POSIX, -[AC_MSG_CHECKING(for POSIX utime) -AC_CACHE_VAL(sudo_cv_func_utime_posix, -[rm -f conftestdata; > conftestdata -AC_TRY_RUN([#include -#include -#include -main() { -struct utimbuf ut; -ut.actime = ut.modtime = time(0); -utime("conftestdata", &ut); -exit(0); -}], sudo_cv_func_utime_posix=yes, sudo_cv_func_utime_posix=no, - sudo_cv_func_utime_posix=no) -rm -f core core.* *.core])dnl -AC_MSG_RESULT($sudo_cv_func_utime_posix) -if test $sudo_cv_func_utime_posix = yes; then - AC_DEFINE(HAVE_UTIME_POSIX, 1, [Define if you have a POSIX utime() (uses struct utimbuf).]) -fi -]) - dnl dnl check for working fnmatch(3) dnl diff --git a/check.c b/check.c index fed8bd081..a333e15d9 100644 --- a/check.c +++ b/check.c @@ -149,10 +149,11 @@ update_timestamp(timestampdir, timestampfile) char *timestampdir; char *timestampfile; { + time_t now = time(NULL); if (timestamp_uid != 0) set_perms(PERM_TIMESTAMP); - if (touch(timestampfile ? timestampfile : timestampdir, time(NULL)) == -1) { + if (touch(-1, timestampfile ? timestampfile : timestampdir, now) == -1) { if (timestampfile) { int fd = open(timestampfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); @@ -551,7 +552,7 @@ remove_timestamp(remove) remove = FALSE; } } - if (!remove && touch(ts, 0) == -1) + if (!remove && touch(-1, ts, 0) == -1) err(1, "can't reset %s to Epoch", ts); } diff --git a/compat.h b/compat.h index c7248f33f..8ce97a4f9 100644 --- a/compat.h +++ b/compat.h @@ -211,6 +211,14 @@ typedef struct sigaction sigaction_t; # define HAVE_DIRFD #endif +/* + * Define futimes() in terms of futimesat() if needed. + */ +#if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT) +# define futimes(_f, _p, _tv) futimesat(_f, NULL, _tv) +# define HAVE_FUTIMES +#endif + /* * If we lack getprogname(), emulate with __progname if possible. * Otherwise, add a prototype for use with our own getprogname.c. diff --git a/config.h.in b/config.h.in index d3f3e6798..6c6a49e96 100644 --- a/config.h.in +++ b/config.h.in @@ -71,16 +71,16 @@ /* Define if you use OSF DCE. */ #undef HAVE_DCE +/* Define to 1 if your `DIR' contains dd_fd. */ +#undef HAVE_DD_FD + /* Define to 1 if you have the header file, and it defines `DIR'. */ #undef HAVE_DIRENT_H -/* Define to 1 if you have the `dirfd' function (not macro). */ +/* Define if you have the `fnmatch' function or macro. */ #undef HAVE_DIRFD -/* Define to 1 if your `DIR' contains dd_fd. */ -#undef HAVE_DD_FD - /* Define to 1 if you have the `dispcrypt' function. */ #undef HAVE_DISPCRYPT @@ -102,6 +102,15 @@ /* Define to 1 if you have the `fstat' function. */ #undef HAVE_FSTAT +/* Define to 1 if you have the `futime' function. */ +#undef HAVE_FUTIME + +/* Define to 1 if you have the `futimes' function. */ +#undef HAVE_FUTIMES + +/* Define to 1 if you have the `futimesat' function. */ +#undef HAVE_FUTIMESAT + /* Define if you use the FWTK authsrv daemon. */ #undef HAVE_FWTK @@ -168,16 +177,16 @@ /* Define if you use Kerberos V. */ #undef HAVE_KERB5 -/* Define if you use LDAP. */ -#undef HAVE_LDAP - /* Define if your LDAP needs . (OpenLDAP does not) */ #undef HAVE_LBER_H -/* Define if your LDAP Supports URLs. (OpenLDAP does) */ +/* Define if you use LDAP. */ +#undef HAVE_LDAP + +/* Define to 1 if you have the `ldap_initialize' function. */ #undef HAVE_LDAP_INITIALIZE -/* Define if your LDAP Supports start_tls_s. (OpenLDAP does) */ +/* Define to 1 if you have the `ldap_start_tls_s' function. */ #undef HAVE_LDAP_START_TLS_S /* Define to 1 if you have the `lockf' function. */ @@ -339,15 +348,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H -/* Define to 1 if you have the `utime' function. */ -#undef HAVE_UTIME +/* Define to 1 if you have the `utimes' function. */ +#undef HAVE_UTIMES /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H -/* Define if you have a POSIX utime() (uses struct utimbuf). */ -#undef HAVE_UTIME_POSIX - /* Define to 1 if you have the `vasprintf' function. */ #undef HAVE_VASPRINTF diff --git a/configure b/configure index feea98102..9cfad54ae 100755 --- a/configure +++ b/configure @@ -3118,7 +3118,8 @@ fi; # Check whether --with-ldap-conf-file or --without-ldap-conf-file was given. if test "${with_ldap_conf_file+set}" = set; then withval="$with_ldap_conf_file" - cat >>confdefs.h <<_ACEOF + +cat >>confdefs.h <<_ACEOF #define _PATH_LDAP_CONF "$with_ldap_conf_file" _ACEOF @@ -5456,7 +5457,7 @@ ia64-*-hpux*) ;; *-*-irix6*) # Find out which ABI we are using. - echo '#line 5459 "configure"' > conftest.$ac_ext + echo '#line 5460 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -6617,7 +6618,7 @@ fi # Provide some information about the compiler. -echo "$as_me:6620:" \ +echo "$as_me:6621:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -7626,11 +7627,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7629: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7630: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7633: \$? = $ac_status" >&5 + echo "$as_me:7634: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -7858,11 +7859,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7861: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7862: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:7865: \$? = $ac_status" >&5 + echo "$as_me:7866: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -7925,11 +7926,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:7928: $lt_compile\"" >&5) + (eval echo "\"\$as_me:7929: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:7932: \$? = $ac_status" >&5 + echo "$as_me:7933: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -9905,7 +9906,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:12143: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:12146: \$? = $ac_status" >&5 + echo "$as_me:12147: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -12206,11 +12207,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:12209: $lt_compile\"" >&5) + (eval echo "\"\$as_me:12210: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:12213: \$? = $ac_status" >&5 + echo "$as_me:12214: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -13410,7 +13411,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:14334: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:14337: \$? = $ac_status" >&5 + echo "$as_me:14338: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -14397,11 +14398,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14400: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14401: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:14404: \$? = $ac_status" >&5 + echo "$as_me:14405: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -16309,11 +16310,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16312: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16313: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16316: \$? = $ac_status" >&5 + echo "$as_me:16317: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -16541,11 +16542,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16544: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16545: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:16548: \$? = $ac_status" >&5 + echo "$as_me:16549: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings @@ -16608,11 +16609,11 @@ else -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:16611: $lt_compile\"" >&5) + (eval echo "\"\$as_me:16612: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:16615: \$? = $ac_status" >&5 + echo "$as_me:16616: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -18588,7 +18589,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5 @@ -25977,14 +25978,15 @@ if test `eval echo '${'$as_ac_var'}'` = yes; then cat >>confdefs.h <<_ACEOF #define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF - echo "$as_me:$LINENO: checking for POSIX utime" >&5 -echo $ECHO_N "checking for POSIX utime... $ECHO_C" >&6 -if test "${sudo_cv_func_utime_posix+set}" = set; then + + +for ac_func in futimes futimesat +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then echo $ECHO_N "(cached) $ECHO_C" >&6 -else - rm -f conftestdata; > conftestdata -if test "$cross_compiling" = yes; then - sudo_cv_func_utime_posix=no else cat >conftest.$ac_ext <<_ACEOF #line $LINENO "configure" @@ -25993,52 +25995,159 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include -#include -#include -main() { -struct utimbuf ut; -ut.actime = ut.modtime = time(0); -utime("conftestdata", &ut); -exit(0); +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; } _ACEOF -rm -f conftest$ac_exeext +rm -f conftest.$ac_objext conftest$ac_exeext if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 (eval $ac_link) 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; }; then - sudo_cv_func_utime_posix=yes + eval "$as_ac_var=yes" else - echo "$as_me: program exited with status $ac_status" >&5 -echo "$as_me: failed program was:" >&5 + echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -( exit $ac_status ) -sudo_cv_func_utime_posix=no +eval "$as_ac_var=no" fi -rm -f core core.* *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext fi -rm -f core core.* *.core +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + break fi -echo "$as_me:$LINENO: result: $sudo_cv_func_utime_posix" >&5 -echo "${ECHO_T}$sudo_cv_func_utime_posix" >&6 -if test $sudo_cv_func_utime_posix = yes; then +done -cat >>confdefs.h <<\_ACEOF -#define HAVE_UTIME_POSIX 1 +else + +for ac_func in futime +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} _ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF -else - LIBOBJS="$LIBOBJS utime.$ac_objext" +fi +done + LIBOBJS="$LIBOBJS utimes.$ac_objext" fi done @@ -29700,7 +29809,8 @@ sed 's/^/| /' conftest.$ac_ext >&5 echo "$as_me:$LINENO: result: yes" >&5 echo "${ECHO_T}yes" >&6 - cat >>confdefs.h <<\_ACEOF + +cat >>confdefs.h <<\_ACEOF #define HAVE_LBER_H 1 _ACEOF diff --git a/configure.in b/configure.in index bff371fef..77fa87c13 100644 --- a/configure.in +++ b/configure.in @@ -515,7 +515,7 @@ AC_ARG_WITH(ignore-dot, [ --with-ignore-dot ignore '.' in the PATH], ;; esac]) if test "$ignore_dot" = "on"; then - AC_DEFINE(IGNORE_DOT_PATH, 1, [Define if you want to ignore '.' and empty \$PATH elements]) + AC_DEFINE(IGNORE_DOT_PATH, 1, [Define if you want to ignore '.' and empty PATH elements]) AC_MSG_RESULT(yes) else AC_MSG_RESULT(no) @@ -916,7 +916,7 @@ AC_ARG_WITH(ldap, [ --with-ldap[[=DIR]] enable LDAP support], ;; esac]) AC_ARG_WITH(ldap-conf-file, [ --with-ldap-conf-file path to LDAP configuration file], -[AC_DEFINE_UNQUOTED(_PATH_LDAP_CONF, "$with_ldap_conf_file")]) +[AC_DEFINE_UNQUOTED(_PATH_LDAP_CONF, "$with_ldap_conf_file", [Path to the ldap.conf file])]) AC_ARG_WITH(pc-insults, [ --with-pc-insults replace politically incorrect insults with less offensive ones], [case $with_pc_insults in @@ -1704,7 +1704,7 @@ AC_CHECK_FUNCS(lockf flock, [break]) AC_CHECK_FUNCS(waitpid wait3, [break]) AC_CHECK_FUNCS(innetgr _innetgr, [AC_CHECK_FUNCS(getdomainname) [break]]) AC_CHECK_FUNCS(lsearch, , [AC_CHECK_LIB(compat, lsearch, AC_CHECK_HEADER(search.h, AC_DEFINE(HAVE_LSEARCH) [LIBS="${LIBS} -lcompat"], AC_LIBOBJ(lsearch), -), AC_LIBOBJ(lsearch))]) -AC_CHECK_FUNCS(utime, [SUDO_FUNC_UTIME_POSIX], [AC_LIBOBJ(utime)]) +AC_CHECK_FUNCS(utimes, [AC_CHECK_FUNCS(futimes futimesat, [break])], [AC_CHECK_FUNCS(futime) AC_LIBOBJ(utimes)]) SUDO_FUNC_FNMATCH(AC_DEFINE(HAVE_FNMATCH, 1, [Define if you have the `fnmatch' function.]), AC_LIBOBJ(fnmatch)) SUDO_FUNC_ISBLANK AC_REPLACE_FUNCS(strerror strcasecmp sigaction strlcpy strlcat closefrom) @@ -2115,7 +2115,7 @@ if test -n "$with_ldap"; then AC_TRY_LINK([#include #include ], [(void)ldap_init(0, 0)], [AC_MSG_RESULT([no])], [ AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_LBER_H)]) + AC_DEFINE(HAVE_LBER_H, 1, [Define to 1 if your LDAP needs . (OpenLDAP does not)])]) AC_CHECK_FUNCS(ldap_initialize ldap_start_tls_s) diff --git a/fileops.c b/fileops.c index 797bda3e8..4ce877fe5 100644 --- a/fileops.c +++ b/fileops.c @@ -22,6 +22,7 @@ #include #include +#include #ifdef HAVE_FLOCK # include #endif /* HAVE_FLOCK */ @@ -31,13 +32,6 @@ #endif /* HAVE_UNISTD_H */ #include #include -#ifdef HAVE_UTIME -# ifdef HAVE_UTIME_H -# include -# endif /* HAVE_UTIME_H */ -#else -# include "emul/utime.h" -#endif /* HAVE_UTIME */ #include "sudo.h" @@ -46,26 +40,25 @@ static const char rcsid[] = "$Sudo$"; #endif /* lint */ /* - * Update the access and modify times on a file. + * Update the access and modify times on an fd or file. */ int -touch(path, when) +touch(fd, path, when) + int fd; char *path; time_t when; { -#ifdef HAVE_UTIME_POSIX - struct utimbuf ut, *utp; + struct timeval times[2]; - ut.actime = ut.modtime = when; - utp = &ut; -#else - /* BSD <= 4.3 has no struct utimbuf */ - time_t utp[2]; + times[0].tv_sec = times[1].tv_sec = when; + times[0].tv_usec = times[1].tv_usec = 0; - utp[0] = utp[1] = when; -#endif /* HAVE_UTIME_POSIX */ - - return(utime(path, utp)); +#if defined(HAVE_FUTIME) || defined(HAVE_FUTIMES) + if (fd != -1) + return(futimes(fd, times)); + else +#endif + return(utimes(path, times)); } /* diff --git a/sudo.h b/sudo.h index 2f7e68c3e..098702995 100644 --- a/sudo.h +++ b/sudo.h @@ -172,6 +172,12 @@ void closefrom __P((int)); #ifndef HAVE_GETCWD char *getcwd __P((char *, size_t size)); #endif +#ifndef HAVE_UTIMES +int utimes __P((const char *, const struct timeval *)); +#endif +#ifdef HAVE_FUTIME +int futimes __P((int, const struct timeval *)); +#endif #ifndef HAVE_SNPRINTF int snprintf __P((char *, size_t, const char *, ...)); #endif @@ -223,7 +229,7 @@ void dump_defaults __P((void)); void dump_auth_methods __P((void)); void init_envtables __P((void)); int lock_file __P((int, int)); -int touch __P((char *, time_t)); +int touch __P((int, char *, time_t)); int user_is_exempt __P((void)); void set_fqdn __P((void)); int set_runaspw __P((char *)); diff --git a/sudo_edit.c b/sudo_edit.c index 25d00e573..a5fefc4d2 100644 --- a/sudo_edit.c +++ b/sudo_edit.c @@ -157,7 +157,7 @@ int sudo_edit(argc, argv) #else chown(tf[i].tfile, user_uid, user_gid); #endif - touch(tf[i].tfile, tf[i].omtime); + touch(tf[i].tfd, tf[i].tfile, tf[i].omtime); } if (argc == 1) return(1); /* no files readable, you lose */ diff --git a/utime.c b/utimes.c similarity index 57% rename from utime.c rename to utimes.c index cc785b1e2..e3ee8c3a1 100644 --- a/utime.c +++ b/utimes.c @@ -1,6 +1,5 @@ /* - * Copyright (c) 1996, 1998, 1999, 2001 - * Todd C. Miller . + * Copyright (c) 2004 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,43 +18,58 @@ * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ -#include "config.h" - #include #include +#include #include -#ifdef HAVE_UNISTD_H -# include -#endif /* HAVE_UNISTD_H */ +#ifdef HAVE_UTIME_H +# include +#else +# include +#endif -#include "compat.h" -#include "emul/utime.h" +#include "config.h" #ifndef lint static const char rcsid[] = "$Sudo$"; #endif /* lint */ - +#ifndef HAVE_UTIMES /* - * Emulate utime(3) via utimes(2). - * utime(3) sets the access and mod times of the named file. + * Emulate utimes() via utime() */ int -utime(file, tvp) +utimes(file, times) const char *file; - const struct utimbuf *utp; + const struct timeval *times; { - if (upt) { - struct timeval tv[2]; + if (times != NULL) { + struct utimbuf utb; - tv[0].tv_sec = ut.actime; - tv[0].tv_usec = 0; + utb.actime = (time_t)times[0].tv_sec; + utb.modtime = (time_t)times[1].tv_sec; + return(utime(file, &utb)); + } else + return(utime(file, NULL)); +} +#endif /* !HAVE_UTIMES */ - tv[1].tv_sec = ut.modtime; - tv[1].tv_usec = 0; +#ifdef HAVE_FUTIME +/* + * Emulate futimes() via futime() + */ +int +futimes(fd, times) + int fd; + const struct timeval *times; +{ + if (times != NULL) { + struct utimbuf utb; - return(utimes(file, tv); - } else { - return(utimes(file, NULL); - } + utb.actime = (time_t)times[0].tv_sec; + utb.modtime = (time_t)times[1].tv_sec; + return(futime(fd, &utb)); + } else + return(futime(fd, NULL)); } +#endif /* HAVE_FUTIME */ diff --git a/visudo.c b/visudo.c index 25efc5a77..e2c8eebab 100644 --- a/visudo.c +++ b/visudo.c @@ -220,8 +220,8 @@ main(argc, argv) write(stmp_fd, buf, 1); } + (void) touch(stmp_fd, stmp, sudoers_sb.st_mtime); (void) close(stmp_fd); - (void) touch(stmp, sudoers_sb.st_mtime); /* Parse sudoers to pull in editor and env_editor conf values. */ if ((yyin = fopen(stmp, "r"))) { -- 2.40.0