Skip to content

Commit

Permalink
Merge pull request #101 from openSUSE/fate_319639
Browse files Browse the repository at this point in the history
sanitize hostname handling (fate #319639)
  • Loading branch information
wfeldt committed May 17, 2016
2 parents fc4fd52 + 863bda5 commit b24450f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
3 changes: 3 additions & 0 deletions data/initrd/scripts/prepare_rescue
Expand Up @@ -38,6 +38,9 @@ cd /
# create machine id
a=`dd if=/dev/urandom bs=1 count=10 2>/dev/null | md5sum` ; echo ${a%% *} >/etc/machine-id

# preserve hostname
hostname >/etc/hostname

# bash >/dev/console 2>&1

rm -f /mounts/initrd/{*,.*}
Expand Down
1 change: 0 additions & 1 deletion data/rescue/rescue.file_list
Expand Up @@ -234,7 +234,6 @@ less:
netcfg:
/etc
r /etc/{diphosts,ftpusers,hosts.*}
e echo Rescue.local >etc/HOSTNAME

ntfs-3g:
/
Expand Down
19 changes: 6 additions & 13 deletions data/root/etc/inst_setup
Expand Up @@ -54,16 +54,9 @@ export YAST2_SSH=false
unset SSH_FAILED
stty sane 2>/dev/null

# set hostname and domainname
hostip_from_wicked >/tmp/hostips

hostname=$(awk ' /^Hostname:/ { print $2 }' < /etc/install.inf)
[ -n "$hostname" ] && hostname $hostname
hostname=`hostname`

domain=$(awk ' /^Domain:/ { print $2 }' < /etc/install.inf)
[ -z "$domain" ] && domain=local
domainname $domain
# get hostname & hostips
hostip_from_wicked /tmp/host_ips /tmp/host_name
host_name=`cat /tmp/host_name`

#
# a few files should be restored when installation has completed if we
Expand Down Expand Up @@ -186,7 +179,7 @@ function start_shell() {
bash -l
}

[ -f /tmp/hostips ] && cat /tmp/hostips
[ -f /tmp/host_ips ] && cat /tmp/host_ips

[ "$START_SHELL" ] && start_shell

Expand All @@ -197,7 +190,7 @@ if grep -qi "^VNC:.*1" /etc/install.inf ; then
if test "$ec" = "0" ; then
(
sleep 3
/usr/bin/slptool register "service:YaST.installation.suse:vnc://${hostname}:5901"
/usr/bin/slptool register "service:YaST.installation.suse:vnc://${host_name}:5901"
) &> /tmp/slptool_register.txt &
else
echo "slpd returned with exit code $ec, VNC will not be announced"
Expand All @@ -212,7 +205,7 @@ ec=
if [ "$YAST2_SSH" = "true" ] ; then
cat <<EOF
*** login using 'ssh -X root@${hostname}' ***
*** login using 'ssh -X root@${host_name}' ***
*** run '${yast}.ssh' to start the installation ***
EOF
Expand Down
53 changes: 50 additions & 3 deletions data/root/hostip_from_wicked
@@ -1,7 +1,45 @@
#! /usr/bin/perl

# helper script that
#
# (1) writes a list of assigned IP adresses to ARG1, and
#
# (2) writes the FQDN or, if not available, the first IP to ARG2
#
# The address in (2) should be something we can be reached by via network.
#
# usage:
#
# hostip_from_wicked ARG1 ARG2

$up = 0;

# 'wicked show all' is expected to look like this:
=comment
lo up
link: #1, state up
type: loopback
config: compat:suse:/etc/sysconfig/network/ifcfg-lo
leases: ipv4 static granted
leases: ipv6 static granted
addr: ipv4 127.0.0.1/8 [static]
addr: ipv6 ::1/128 [static]
ens7 up
link: #2, state up, mtu 1500
type: ethernet, hwaddr 52:54:00:05:0a:2c
config: compat:suse:/etc/sysconfig/network/ifcfg-ens7
eth1 up
link: #3, state up, mtu 1500
type: ethernet, hwaddr 52:54:00:d7:57:86
config: compat:suse:/etc/sysconfig/network/ifcfg-eth1
leases: ipv4 dhcp granted
leases: ipv6 dhcp requesting
addr: ipv4 10.230.34.112/18 [dhcp]
route: ipv4 default via 10.230.63.254
=cut

for (`wicked show all 2>/dev/null`) {
chomp;
if(/^(\S+)\s*(\S+)/) {
Expand All @@ -18,9 +56,18 @@ for (`wicked show all 2>/dev/null`) {
}

if(@addr) {
system "hostname $addr[0]";
chomp ($host = `hostname -f 2>/dev/null`);
$host = $addr[0] if $host !~ /\./;

print "IP addresses:\n";
print " $_\n" for @addr;
if($ARGV[0] && open $f, ">$ARGV[0]") {
print $f "IP addresses:\n";
print $f " $_\n" for @addr;
close $f;
}

if($ARGV[1] && open $f, ">$ARGV[1]") {
print $f "$host\n";
close $f;
}
}

0 comments on commit b24450f

Please sign in to comment.