Skip to content

Commit

Permalink
Merge pull request #108 from openSUSE/fate_319639_2
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 14dabca + f45461a commit 5ac58e9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
7 changes: 0 additions & 7 deletions file.c
Expand Up @@ -1895,13 +1895,6 @@ void file_write_install_inf(char *dir)
if(config.net.realhostname) {
file_write_str(f, key_hostname, config.net.realhostname);
}
else {
char buf[256];
if(!gethostname(buf, sizeof buf)) {
log_debug("hostname = \"%s\"\n", buf);
if(*buf && strcmp(buf, "(none)")) file_write_str(f, key_hostname, buf);
}
}

LXRC_WAIT

Expand Down
3 changes: 3 additions & 0 deletions install.c
Expand Up @@ -1113,6 +1113,9 @@ int inst_start_install()
if(inst_choose_source()) err = 1;
}

/* if the user specified a hostname, set it */
util_set_hostname(config.net.realhostname);

if(! err && config.rescue) {
/* get rid of repo */
url_umount(config.url.install);
Expand Down
6 changes: 6 additions & 0 deletions linuxrc.c
Expand Up @@ -383,6 +383,9 @@ void lxrc_change_root()
if(config.net.sshpassword) setenv("SSHPASSWORD", config.net.sshpassword, 1);
if(config.net.sshpassword_enc) setenv("SSHPASSWORDENC", config.net.sshpassword_enc, 1);

/* change hostname from 'install' to 'rescue' unless we've had something better */
if(!config.net.realhostname) util_set_hostname("rescue");

lxrc_run_console("/mounts/initrd/scripts/prepare_rescue");

LXRC_WAIT
Expand Down Expand Up @@ -773,6 +776,7 @@ void lxrc_init()
config.net.ipv6 = 1;
config.net.setup = NS_DHCP; /* unless we are told otherwise just go for dhcp */
config.net.nameservers = 1;
config.net.sethostname = 1; /* let wicked set hostname */

config.explode_win = 1;
config.color = 2;
Expand Down Expand Up @@ -855,6 +859,8 @@ void lxrc_init()
config.initrd_has_ldso = 1;
#endif

util_set_hostname("install");

// read config from initrd:
// - /linuxrc.config
// - /etc/linuxrc.d/*
Expand Down
31 changes: 31 additions & 0 deletions linuxrc_hostname.md
@@ -0,0 +1,31 @@
#hostname setting in installation/rescue system

There are 3 cases:

1. no hostname is set

2. hostname is set via dhcp (either from HOSTNAME or FQDN)

3. hostname is set via `hostname` boot option

linuxrc defaults to `install`, which may be overridden by dhcp (2) or user
(3). (3) takes precedence over (2).

##installation system

When yast is started, the value from (3) is passed to yast via
`/etc/install.inf::Hostname` and ends up in `/etc/hostname` of the installed system.

When linuxrc doesn't set `/etc/install.inf::Hostname` yast generates a
default `/etc/hostname` entry of the form `linux-XXXX` (+ `.suse` in sle12).
`XXXX` is some random part.

There is no `/etc/hostname` file in the installation environment.

##rescue system

linuxrc changes the hostname to `rescue`, which may be overridden by user (3).

This value is put into `/etc/hostname` of the rescue system. The value there may later
be overridden by dhcp (2).

2 changes: 1 addition & 1 deletion linuxrc_yast_interface.txt
Expand Up @@ -127,7 +127,7 @@ Device: %s
# else the entry is missing
ProxyURL: %s

# the hostname as set by dhcp or by 'hostname=foo' boot option
# the hostname as set by 'hostname=foo' boot option
# entry is missing if unset
Hostname: %s

Expand Down
14 changes: 14 additions & 0 deletions util.c
Expand Up @@ -5443,3 +5443,17 @@ char *util_get_caller(int skip)
return buf;
}


/*
* Convenience function:
* Set hostname and log this.
*/
void util_set_hostname(char *hostname)
{
if(!hostname) return;

sethostname(hostname, strlen(hostname));

log_info("set hostname: %s\n", hostname);
}

1 change: 1 addition & 0 deletions util.h
Expand Up @@ -155,3 +155,4 @@ void util_log(unsigned level, char *format, ...);
int util_run(char *cmd, unsigned log_stdout);
void util_perror(unsigned level, char *msg);
char *util_get_caller(int skip);
void util_set_hostname(char *hostname);

0 comments on commit 5ac58e9

Please sign in to comment.