Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitize hostname handling (fate #319639) #101

Merged
merged 3 commits into from May 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 2>/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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostip_from_wicked prints hostname including \n at the end. Isn't it a problem (e.g.) here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, shell swallows white space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehm, ok. So why do you explicitly append it? I'm just curios, not blocker for me ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea; the code is not by me. If you say it's not necessary, I'm fine with another line.

) &> /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
13 changes: 12 additions & 1 deletion data/root/hostip_from_wicked
@@ -1,5 +1,13 @@
#! /usr/bin/perl

# helper script that
#
# (1) writes a list of assigned IP adresses to STDOUT, and
#
# (2) writes the FQDN or, if not available, the first IP to STDERR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning value through STDERR seems a bit obscure to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but I documented it...

If you think this a serious problem, I could go and rewrite the script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this is about implementing new feature and not about a hotfix I'd go for more clean implementation.

#
# The address in (2) should be something we can be reached by via network.

Copy link
Member

@mvidner mvidner May 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the docs!

I would also add a sample wicked output, so that the parser loop makes more sense to the future maintainer:

# wicked show all
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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough; added

$up = 0;

for (`wicked show all 2>/dev/null`) {
Expand All @@ -18,7 +26,10 @@ 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 STDERR "$host\n";

print "IP addresses:\n";
print " $_\n" for @addr;
Expand Down