Skip to content

Commit

Permalink
Add use_raw_hostname to X11Parameters.
Browse files Browse the repository at this point in the history
Allow sites to use hostname as given by libc gethostname() instead of
the first domain used globally as hostname.

Bug 6532.

Co-authored-by: Nate Rini <nate@schedmd.com>
  • Loading branch information
wickberg and naterini committed Feb 27, 2019
1 parent 0a891c4 commit db14d94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -31,6 +31,7 @@ documents those changes that are of interest to users and administrators.
-- docs - change HTML title to include the page title or man page name.
-- X11 forwarding - fix an unnecessary error message when using the
local_xauthority X11Parameters option.
-- Add use_raw_hostname to X11Parameters.

* Changes in Slurm 18.08.5-2
============================
Expand Down
4 changes: 4 additions & 0 deletions doc/man/man5/slurm.conf.5
Expand Up @@ -4054,6 +4054,10 @@ If set, xauth data on the compute node will be placed in a temporary file
\fBXAUTHORITY\fR environment variable will be injected into the job's
environment (as well as any process captured by pam_slurm_adopt).
This can help avoid file locking contention on the user's home directory.
.TP 8
\fBuse_raw_hostname\fR
If set, xauth hostname will use the raw value of gethostname() instead
of the local part-only (as is used elsewhere within Slurm).
.RE

.LP
Expand Down
19 changes: 16 additions & 3 deletions src/slurmd/slurmstepd/x11_forwarding.c
Expand Up @@ -53,6 +53,7 @@
#include "src/common/macros.h"
#include "src/common/net.h"
#include "src/common/read_config.h"
#include "src/common/strlcpy.h"
#include "src/common/uid.h"
#include "src/common/x11_util.h"
#include "src/common/xmalloc.h"
Expand All @@ -76,6 +77,7 @@ static char *pub_format = "%s/.ssh/id_rsa.pub";

static bool local_xauthority = false;
static char *xauthority = NULL;
static char hostname[256] = {0};

static int x11_display = 0;

Expand Down Expand Up @@ -165,7 +167,7 @@ static void _shutdown_x11(int signal)
error("%s: problem unlinking xauthority file %s: %m",
__func__, xauthority);
} else
x11_delete_xauth(xauthority, conf->hostname, x11_display);
x11_delete_xauth(xauthority, hostname, x11_display);

xfree(xauthority);
}
Expand Down Expand Up @@ -300,6 +302,17 @@ extern int setup_x11_forward(stepd_step_rec_t *job, int *display,

xfree(home);

/*
* Slurm uses the shortened hostname by default (and discards any
* domain component), which can cause problems for some sites.
* So retrieve the raw value from gethostname() again.
*/
if (xstrcasestr(conf->x11_params, "use_raw_hostname")) {
if (gethostname(hostname, sizeof(hostname)))
fatal("%s: gethostname failed: %m", __func__);
} else
strlcpy(hostname, conf->hostname, sizeof(hostname));

/*
* If hostbased failed or was unavailable, try publickey instead.
*/
Expand All @@ -323,13 +336,13 @@ extern int setup_x11_forward(stepd_step_rec_t *job, int *display,

x11_display = port - X11_TCP_PORT_OFFSET;
if (x11_set_xauth(xauthority, job->x11_magic_cookie,
conf->hostname, x11_display)) {
hostname, x11_display)) {
error("%s: failed to run xauth", __func__);
goto shutdown;
}

info("X11 forwarding established on DISPLAY=%s:%d.0",
conf->hostname, x11_display);
hostname, x11_display);

/*
* Send keepalives every 60 seconds, and have the server
Expand Down

0 comments on commit db14d94

Please sign in to comment.