@@ -390,31 +390,34 @@ fn set_supplemental_gids_with_strategy(
390390
391391/// Change the root, set the user ID, and set the group IDs for this process.
392392fn set_context ( options : & Options ) -> UResult < ( ) > {
393- enter_chroot ( & options. newroot , options. skip_chdir ) ?;
394393 match & options. userspec {
395394 None | Some ( UserSpec :: NeitherGroupNorUser ) => {
396395 let strategy = Strategy :: Nothing ;
397396 set_supplemental_gids_with_strategy ( strategy, options. groups . as_ref ( ) ) ?;
397+ enter_chroot ( & options. newroot , options. skip_chdir ) ?;
398398 }
399399 Some ( UserSpec :: UserOnly ( user) ) => {
400400 let uid = name_to_uid ( user) ?;
401401 let gid = usr2gid ( user) . map_err ( |_| ChrootError :: NoGroupSpecified ( uid) ) ?;
402402 let strategy = Strategy :: FromUID ( uid, false ) ;
403403 set_supplemental_gids_with_strategy ( strategy, options. groups . as_ref ( ) ) ?;
404+ enter_chroot ( & options. newroot , options. skip_chdir ) ?;
404405 set_gid ( gid) . map_err ( |e| ChrootError :: SetGidFailed ( user. to_owned ( ) , e) ) ?;
405406 set_uid ( uid) . map_err ( |e| ChrootError :: SetUserFailed ( user. to_owned ( ) , e) ) ?;
406407 }
407408 Some ( UserSpec :: GroupOnly ( group) ) => {
408409 let gid = name_to_gid ( group) ?;
409410 let strategy = Strategy :: Nothing ;
410411 set_supplemental_gids_with_strategy ( strategy, options. groups . as_ref ( ) ) ?;
412+ enter_chroot ( & options. newroot , options. skip_chdir ) ?;
411413 set_gid ( gid) . map_err ( |e| ChrootError :: SetGidFailed ( group. to_owned ( ) , e) ) ?;
412414 }
413415 Some ( UserSpec :: UserAndGroup ( user, group) ) => {
414416 let uid = name_to_uid ( user) ?;
415417 let gid = name_to_gid ( group) ?;
416418 let strategy = Strategy :: FromUID ( uid, true ) ;
417419 set_supplemental_gids_with_strategy ( strategy, options. groups . as_ref ( ) ) ?;
420+ enter_chroot ( & options. newroot , options. skip_chdir ) ?;
418421 set_gid ( gid) . map_err ( |e| ChrootError :: SetGidFailed ( group. to_owned ( ) , e) ) ?;
419422 set_uid ( uid) . map_err ( |e| ChrootError :: SetUserFailed ( user. to_owned ( ) , e) ) ?;
420423 }
0 commit comments