Skip to content

Commit 63ebe35

Browse files
committed
Automatically migrate lecture file path from name-based to uid-based.
GitHub issue #342. --HG-- branch : 1.9
1 parent 286c8dd commit 63ebe35

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@
758758
/* Define to 1 if you have the 'realpath' function. */
759759
#undef HAVE_REALPATH
760760

761+
/* Define to 1 if you have the 'renameat' function. */
762+
#undef HAVE_RENAMEAT
763+
761764
/* Define to 1 if you have the 'revoke' function. */
762765
#undef HAVE_REVOKE
763766

configure

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,13 +3439,14 @@ as_fn_append ac_header_c_list " sys/select.h sys_select_h HAVE_SYS_SELECT_H"
34393439
as_fn_append ac_header_c_list " sys/stropts.h sys_stropts_h HAVE_SYS_STROPTS_H"
34403440
as_fn_append ac_header_c_list " sys/sysmacros.h sys_sysmacros_h HAVE_SYS_SYSMACROS_H"
34413441
as_fn_append ac_header_c_list " sys/statvfs.h sys_statvfs_h HAVE_SYS_STATVFS_H"
3442+
as_fn_append ac_func_c_list " faccessat HAVE_FACCESSAT"
34423443
as_fn_append ac_func_c_list " fexecve HAVE_FEXECVE"
34433444
as_fn_append ac_func_c_list " fmemopen HAVE_FMEMOPEN"
34443445
as_fn_append ac_func_c_list " killpg HAVE_KILLPG"
34453446
as_fn_append ac_func_c_list " nl_langinfo HAVE_NL_LANGINFO"
3446-
as_fn_append ac_func_c_list " faccessat HAVE_FACCESSAT"
3447-
as_fn_append ac_func_c_list " wordexp HAVE_WORDEXP"
3447+
as_fn_append ac_func_c_list " renameat HAVE_RENAMEAT"
34483448
as_fn_append ac_func_c_list " strtoull HAVE_STRTOULL"
3449+
as_fn_append ac_func_c_list " wordexp HAVE_WORDEXP"
34493450
as_fn_append ac_func_c_list " seteuid HAVE_SETEUID"
34503451

34513452
# Auxiliary files required by this configure script.
@@ -22281,6 +22282,7 @@ done
2228122282

2228222283

2228322284

22285+
2228422286
for ac_func in execvpe
2228522287
do :
2228622288
ac_fn_c_check_func "$LINENO" "execvpe" "ac_cv_func_execvpe"

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ dnl Function checks
26602660
dnl
26612661
AC_FUNC_GETGROUPS
26622662
AC_FUNC_FSEEKO
2663-
AC_CHECK_FUNCS_ONCE([fexecve fmemopen killpg nl_langinfo faccessat wordexp strtoull])
2663+
AC_CHECK_FUNCS_ONCE([faccessat fexecve fmemopen killpg nl_langinfo renameat strtoull wordexp])
26642664
AC_CHECK_FUNCS([execvpe], [SUDO_APPEND_INTERCEPT_EXP(execvpe)])
26652665
AC_CHECK_FUNCS([pread], [
26662666
# pread/pwrite on 32-bit HP-UX 11.x may not support large files

plugins/sudoers/timestamp.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,35 @@ already_lectured(const struct sudoers_context *ctx)
11481148
goto done;
11491149

11501150
ret = fstatat(dfd, uidstr, &sb, AT_SYMLINK_NOFOLLOW) == 0;
1151+
if (!ret && errno == ENOENT && strchr(ctx->user.name, '/') == NULL) {
1152+
/* No uid-based lecture path, check for username-based path. */
1153+
ret = fstatat(dfd, ctx->user.name, &sb, AT_SYMLINK_NOFOLLOW) == 0;
1154+
if (ret) {
1155+
/* Migrate lecture file to uid-based path. */
1156+
#ifdef HAVE_RENAMEAT
1157+
if (renameat(dfd, ctx->user.name, dfd, uidstr) == -1) {
1158+
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
1159+
"%s: unable to rename %s/%s to %s/%s", __func__,
1160+
def_lecture_status_dir, ctx->user.name,
1161+
def_lecture_status_dir, uidstr);
1162+
}
1163+
#else
1164+
char from[PATH_MAX], to[PATH_MAX];
1165+
len = snprintf(from, sizeof(from), "%s/%s", def_lecture_status_dir,
1166+
ctx->user.name);
1167+
if (len < 0 || len >= ssizeof(from))
1168+
goto done;
1169+
len = snprintf(to, sizeof(to), "%s/%s", def_lecture_status_dir,
1170+
uidstr);
1171+
if (len < 0 || len >= ssizeof(to))
1172+
goto done;
1173+
if (rename(from, to) == -1) {
1174+
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
1175+
"%s: unable to rename %s to %s", __func__, from, to);
1176+
}
1177+
#endif
1178+
}
1179+
}
11511180

11521181
done:
11531182
if (dfd != -1)

0 commit comments

Comments
 (0)