Commit 55b04f97 authored by Niels Möller's avatar Niels Möller

* src/environ.h.in (USER_NAME_FROM_ENV): New macro, which consults

both $LOGNAME and $USER.
* src/client.c (init_client_options): Use it.
* src/srp-gen.c (make_srp_gen_options): Likewise.
* src/lshd.c (main_argp_parser): Likewise.
* src/lsh-writekey.c (main_argp_parser): Likewise.

Rev: src/client.c:1.165
Rev: src/environ.h.in:1.3
Rev: src/lsh-writekey.c:1.39
Rev: src/lshd.c:1.169
Rev: src/srp-gen.c:1.23
parent 95d759fd
......@@ -540,7 +540,8 @@ init_client_options(struct client_options *self,
self->port = NULL;
self->target = NULL;
self->local_user = self->user = getenv(ENV_LOGNAME);
USER_NAME_FROM_ENV(self->user);
self->local_user = self->user;
self->with_remote_peers = 0;
self->with_pty = -1;
......
......@@ -39,3 +39,12 @@
#define ENV_TZ "TZ"
#define ENV_USER "USER"
#define ENV_XAUTHORITY "XAUTHORITY"
/* To get the name of the logged in user, we need to check both
$LOGNAME (Sys V convention) and $USER (BSD convention). */
#define USER_NAME_FROM_ENV(s) do { \
(s) = getenv(ENV_LOGNAME); \
if (!(s)) \
(s) = getenv(ENV_USER); \
} while (0)
......@@ -199,7 +199,8 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
{
if (!self->label)
{
const char *name = getenv(ENV_LOGNAME);
const char *name;
USER_NAME_FROM_ENV(name);
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 300
#endif
......
......@@ -659,8 +659,8 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
else if (self->with_loginauthmode)
{
const char *name;
name = getenv(ENV_LOGNAME);
USER_NAME_FROM_ENV(name);
if (!name)
argp_failure(state, EXIT_FAILURE, 0,
"$LOGNAME not set in the environment.\n");
......
......@@ -97,7 +97,7 @@ make_srp_gen_options(struct exception_handler *e)
self->file = NULL;
self->dest = NULL;
self->name = getenv(ENV_LOGNAME);
USER_NAME_FROM_ENV(self->name);
self->passwd = NULL;
/* We use this only for generating the salt. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment