mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +00:00
Add gmtime_r and localtime_r tests and compat if missing.
This commit is contained in:
parent
46d71c4360
commit
fa71679b5a
2
MANIFEST
2
MANIFEST
@ -205,12 +205,14 @@ lib/util/gettime.c
|
|||||||
lib/util/getusershell.c
|
lib/util/getusershell.c
|
||||||
lib/util/gidlist.c
|
lib/util/gidlist.c
|
||||||
lib/util/glob.c
|
lib/util/glob.c
|
||||||
|
lib/util/gmtime_r.c
|
||||||
lib/util/inet_ntop.c
|
lib/util/inet_ntop.c
|
||||||
lib/util/inet_pton.c
|
lib/util/inet_pton.c
|
||||||
lib/util/isblank.c
|
lib/util/isblank.c
|
||||||
lib/util/json.c
|
lib/util/json.c
|
||||||
lib/util/key_val.c
|
lib/util/key_val.c
|
||||||
lib/util/lbuf.c
|
lib/util/lbuf.c
|
||||||
|
lib/util/localtime_r.c
|
||||||
lib/util/locking.c
|
lib/util/locking.c
|
||||||
lib/util/logfac.c
|
lib/util/logfac.c
|
||||||
lib/util/logpri.c
|
lib/util/logpri.c
|
||||||
|
@ -408,6 +408,9 @@
|
|||||||
/* Define to 1 if you have the `glob' function. */
|
/* Define to 1 if you have the `glob' function. */
|
||||||
#undef HAVE_GLOB
|
#undef HAVE_GLOB
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `gmtime_r' function. */
|
||||||
|
#undef HAVE_GMTIME_R
|
||||||
|
|
||||||
/* Define to 1 if you have the `grantpt' function. */
|
/* Define to 1 if you have the `grantpt' function. */
|
||||||
#undef HAVE_GRANTPT
|
#undef HAVE_GRANTPT
|
||||||
|
|
||||||
@ -545,6 +548,9 @@
|
|||||||
/* Define to 1 if you have the <linux/random.h> header file. */
|
/* Define to 1 if you have the <linux/random.h> header file. */
|
||||||
#undef HAVE_LINUX_RANDOM_H
|
#undef HAVE_LINUX_RANDOM_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `localtime_r' function. */
|
||||||
|
#undef HAVE_LOCALTIME_R
|
||||||
|
|
||||||
/* Define to 1 if you have the `lockf' function. */
|
/* Define to 1 if you have the `lockf' function. */
|
||||||
#undef HAVE_LOCKF
|
#undef HAVE_LOCKF
|
||||||
|
|
||||||
|
52
configure
vendored
52
configure
vendored
@ -21107,6 +21107,58 @@ esac
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
for ac_func in localtime_r
|
||||||
|
do :
|
||||||
|
ac_fn_c_check_func "$LINENO" "localtime_r" "ac_cv_func_localtime_r"
|
||||||
|
if test "x$ac_cv_func_localtime_r" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_LOCALTIME_R 1" >>confdefs.h
|
||||||
|
|
||||||
|
else $as_nop
|
||||||
|
|
||||||
|
case " $LIBOBJS " in
|
||||||
|
*" localtime_r.$ac_objext "* ) ;;
|
||||||
|
*) LIBOBJS="$LIBOBJS localtime_r.$ac_objext"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
for _sym in sudo_localtime_r; do
|
||||||
|
COMPAT_EXP="${COMPAT_EXP}${_sym}
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
for ac_func in gmtime_r
|
||||||
|
do :
|
||||||
|
ac_fn_c_check_func "$LINENO" "gmtime_r" "ac_cv_func_gmtime_r"
|
||||||
|
if test "x$ac_cv_func_gmtime_r" = xyes
|
||||||
|
then :
|
||||||
|
printf "%s\n" "#define HAVE_GMTIME_R 1" >>confdefs.h
|
||||||
|
|
||||||
|
else $as_nop
|
||||||
|
|
||||||
|
case " $LIBOBJS " in
|
||||||
|
*" gmtime_r.$ac_objext "* ) ;;
|
||||||
|
*) LIBOBJS="$LIBOBJS gmtime_r.$ac_objext"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
for _sym in sudo_gmtime_r; do
|
||||||
|
COMPAT_EXP="${COMPAT_EXP}${_sym}
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
@ -2570,6 +2570,14 @@ AC_CHECK_FUNCS([cfmakeraw], [], [
|
|||||||
AC_LIBOBJ(cfmakeraw)
|
AC_LIBOBJ(cfmakeraw)
|
||||||
SUDO_APPEND_COMPAT_EXP(sudo_cfmakeraw)
|
SUDO_APPEND_COMPAT_EXP(sudo_cfmakeraw)
|
||||||
])
|
])
|
||||||
|
AC_CHECK_FUNCS([localtime_r], [], [
|
||||||
|
AC_LIBOBJ(localtime_r)
|
||||||
|
SUDO_APPEND_COMPAT_EXP(sudo_localtime_r)
|
||||||
|
])
|
||||||
|
AC_CHECK_FUNCS([gmtime_r], [], [
|
||||||
|
AC_LIBOBJ(gmtime_r)
|
||||||
|
SUDO_APPEND_COMPAT_EXP(sudo_gmtime_r)
|
||||||
|
])
|
||||||
AC_CHECK_FUNCS([getgrouplist], [], [
|
AC_CHECK_FUNCS([getgrouplist], [], [
|
||||||
case "$host_os" in
|
case "$host_os" in
|
||||||
aix*)
|
aix*)
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#ifndef SUDO_COMPAT_H
|
#ifndef SUDO_COMPAT_H
|
||||||
#define SUDO_COMPAT_H
|
#define SUDO_COMPAT_H
|
||||||
|
|
||||||
#include <sys/types.h> /* for gid_t, mode_t, size_t, ssize_t, uid_t */
|
#include <sys/types.h> /* for gid_t, mode_t, size_t, ssize_t, time_t, uid_t */
|
||||||
#if defined(__hpux) && !defined(__LP64__)
|
#if defined(__hpux) && !defined(__LP64__)
|
||||||
# include <unistd.h> /* for pread/pread64, and pwrite/pwrite64 */
|
# include <unistd.h> /* for pread/pread64, and pwrite/pwrite64 */
|
||||||
#endif
|
#endif
|
||||||
@ -401,6 +401,7 @@ struct passwd;
|
|||||||
struct stat;
|
struct stat;
|
||||||
struct timespec;
|
struct timespec;
|
||||||
struct termios;
|
struct termios;
|
||||||
|
struct tm;
|
||||||
|
|
||||||
#ifndef HAVE_CFMAKERAW
|
#ifndef HAVE_CFMAKERAW
|
||||||
sudo_dso_public void sudo_cfmakeraw(struct termios *term);
|
sudo_dso_public void sudo_cfmakeraw(struct termios *term);
|
||||||
@ -456,6 +457,16 @@ char *getusershell(void);
|
|||||||
void setusershell(void);
|
void setusershell(void);
|
||||||
void endusershell(void);
|
void endusershell(void);
|
||||||
#endif /* HAVE_GETUSERSHELL */
|
#endif /* HAVE_GETUSERSHELL */
|
||||||
|
#ifndef HAVE_GMTIME_R
|
||||||
|
sudo_dso_public struct tm *sudo_gmtime_r(const time_t *, struct tm *);
|
||||||
|
# undef gmtime_r
|
||||||
|
# define gmtime_r(_a, _b, _c, _d) sudo_gmtime_r((_a), (_b))
|
||||||
|
#endif /* HAVE_GMTIME_R */
|
||||||
|
#ifndef HAVE_LOCALTIME_R
|
||||||
|
sudo_dso_public struct tm *sudo_localtime_r(const time_t *, struct tm *);
|
||||||
|
# undef localtime_r
|
||||||
|
# define localtime_r(_a, _b, _c, _d) sudo_localtime_r((_a), (_b))
|
||||||
|
#endif /* HAVE_LOCALTIME_R */
|
||||||
#ifndef HAVE_UTIMENSAT
|
#ifndef HAVE_UTIMENSAT
|
||||||
sudo_dso_public int sudo_utimensat(int fd, const char *file, const struct timespec *times, int flag);
|
sudo_dso_public int sudo_utimensat(int fd, const char *file, const struct timespec *times, int flag);
|
||||||
# undef utimensat
|
# undef utimensat
|
||||||
|
49
lib/util/gmtime_r.c
Normal file
49
lib/util/gmtime_r.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: ISC
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||||
|
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_GMTIME_R
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "sudo_compat.h"
|
||||||
|
#include "sudo_util.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fake gmtime_r() that just stores the result.
|
||||||
|
* Still has the normal gmtime() side effects.
|
||||||
|
*/
|
||||||
|
struct tm *
|
||||||
|
sudo_gmtime_r(const time_t *timer, struct tm *result)
|
||||||
|
{
|
||||||
|
struct tm *tm;
|
||||||
|
|
||||||
|
if ((tm = gmtime(timer)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
memcpy(result, tm, sizeof(struct tm));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_GMTIME_T */
|
49
lib/util/localtime_r.c
Normal file
49
lib/util/localtime_r.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: ISC
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||||
|
* PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_LOCALTIME_R
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "sudo_compat.h"
|
||||||
|
#include "sudo_util.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fake localtime_r() that just stores the result.
|
||||||
|
* Still has the normal localtime() side effects.
|
||||||
|
*/
|
||||||
|
struct tm *
|
||||||
|
sudo_localtime_r(const time_t *timer, struct tm *result)
|
||||||
|
{
|
||||||
|
struct tm *tm;
|
||||||
|
|
||||||
|
if ((tm = localtime(timer)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
memcpy(result, tm, sizeof(struct tm));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif /* HAVE_LOCALTIME_T */
|
Loading…
x
Reference in New Issue
Block a user