Skip to content

Commit

Permalink
rc: pimp recovery stage
Browse files Browse the repository at this point in the history
o pwd_mkdb(8)'s `-p' likely only cares about /etc/passwd
o Regenerate for each phase, pkg(8) seems to like that
o Also restore a clobbered /etc/shells including our root shell
  • Loading branch information
fichtner committed Jun 30, 2015
1 parent c506c9f commit 7baccb7
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/etc/rc.recover
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ hast:*:845:845::0:0:HAST unprivileged user:/var/empty:/usr/sbin/nologin
nobody:*:65534:65534::0:0:Unprivileged user:/nonexistent:/usr/sbin/nologin
EOF;

$etc_shells = <<<EOF
# \$FreeBSD$
#
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/sh
/bin/csh
/bin/tcsh
/usr/local/etc/rc.initial
EOF;

function recover_ports()
{
$actions = array(
Expand Down Expand Up @@ -128,9 +141,18 @@ function recover_ports()
unlink($tempname);
}

function recover_rebuild()
{
passthru('/usr/sbin/pwd_mkdb -p /etc/master.passwd');
passthru('/usr/sbin/pwd_mkdb /etc/master.passwd');
}

/* first stage recovers the base system state */
file_put_contents('/etc/group', $etc_group);
file_put_contents('/etc/master.passwd', $etc_master_passwd);
file_put_contents('/etc/shells', $etc_shells);
recover_rebuild();

/* second stage recovers the ports system state */
recover_ports();

exec('/usr/sbin/pwd_mkdb -p /etc/master.passwd');
recover_rebuild();

0 comments on commit 7baccb7

Please sign in to comment.