@@ -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
11521181done :
11531182 if (dfd != -1 )
0 commit comments