Commit f04a1d9c authored by Pontus Freyhult's avatar Pontus Freyhult

Parse options from environment variables if available.

Rev: ChangeLog:1.556
Rev: NEWS:1.104
Rev: src/client.c:1.144
Rev: src/client.h:1.51
Rev: src/lsh.c:1.168
Rev: src/lshg.c:1.18
parent 0707a5ee
2002-11-01 Pontus Skld <pont@soua.net>
* src/testsuite/Makefile.am (TS_SH): New test lsh-9-test.
* src/testsuite/lsh-9-test: Test for LSHFLAGS.
* src/client.h (client_options): New attribute, inhibit_actions.
Declaration of envp_parse.
* src/client.c (envp_parse): New function envp_parse.
(client_argp_parser): Honour inhibit_actions.
(init_client_options): Initialize inhibit_actions.
* src/lshg.c (main_argp_parser): Honour inhibit_actions.
(main): Use envp_parse.
* src/lsh.c (main_argp_parser): Honour inhibit_actions.
(main): Use envp_parse.
2002-10-23 Pontus Skld <pont@soua.net>
* src/client_x11.c (parse_display): Handle special case
......
......@@ -8,6 +8,10 @@ News for the 1.x.y release
terminates as soon as the authentication is finished (this of
course goes for environment variables too).
lsh and and lshg now parses options from LSHFLAGS and
LSHGFLAGS, these are parsed before and can be overridden by
the command line.
News for the 1.5 release
Implemented the server side of X11 forwarding. Try lshd
......
......@@ -567,6 +567,8 @@ init_client_options(struct client_options *self,
self->start_shell = 1;
self->remote_forward = 0;
self->inhibit_actions = 0;
object_queue_init(&self->actions);
}
......@@ -1127,6 +1129,60 @@ make_client_session(struct client_options *options)
}
/* Treat environment variables as sources for options */
void
envp_parse(const struct argp *argp,
const char** envp,
const char* name,
unsigned flags,
void *input)
{
CAST_SUBTYPE(client_options, options, input);
int nlen = strlen(name);
while (*envp)
{
if (!strncmp(*envp, name, nlen)) /* Matching environment entry */
{
char** sim_argv;
char* entry;
/* Make a copy we can modify */
entry = strdup(*envp+nlen); /* Skip variable name */
if (entry)
{
/* Extra space doesn't hurt */
sim_argv = malloc(sizeof(char*) * (strlen(entry)+2));
if (sim_argv)
{
int sim_argc = 1;
char *token = strtok(entry, " \n\t");
sim_argv[0] = "";
while (token) /* For all tokens in variable */
{
sim_argv[sim_argc++] = token;
token = strtok( NULL, " \n\t");
}
sim_argv[sim_argc] = NULL;
options->inhibit_actions = 1; /* Disable nnormal actions performed at end */
argp_parse(argp, sim_argc, sim_argv, flags | ARGP_PARSE_ARGV0, NULL, input);
options->inhibit_actions = 0; /* Reenable */
}
}
}
envp++;
}
}
/* Parse the argument for -R and -L */
int
client_parse_forward_arg(char *arg,
......@@ -1235,6 +1291,9 @@ client_argp_parser(int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_END:
if (options->inhibit_actions)
break;
if (!options->user)
{
argp_error(state, "No user name given. Use the -l option, or set LOGNAME in the environment.");
......
......@@ -162,6 +162,9 @@ make_client_x11_display(const char *display, struct lsh_string *fake);
; True if the client should detach when a session closes (useful for gateways)
(detach_end . int)
; Inhibit actions, used to not create actions from environment parsing.
(inhibit_actions . int)
(start_shell . int)
(remote_forward . int)
(actions struct object_queue)))
......@@ -176,7 +179,6 @@ init_client_options(struct client_options *options,
struct command *
client_add_action(struct client_options *options,
struct command *action);
int
client_parse_forward_arg(char *arg,
UINT32 *listen_port,
......@@ -190,4 +192,12 @@ extern struct command client_options2actions;
extern const struct argp client_argp;
void
envp_parse(const struct argp *argp,
const char** envp,
const char* name,
unsigned flags,
void *input);
#endif /* LSH_CLIENT_H_INCLUDED */
......@@ -825,6 +825,9 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_END:
if (self->super.inhibit_actions)
break;
if (!self->home)
{
argp_error(state, "No home directory. Please set HOME in the environment.");
......@@ -1065,7 +1068,7 @@ make_lsh_default_handler(int *status, struct exception_handler *parent,
}
int main(int argc, char **argv)
int main(int argc, char **argv, const char** envp)
{
struct lsh_options *options;
struct spki_context *spki;
......@@ -1091,6 +1094,7 @@ int main(int argc, char **argv)
if (!options)
return EXIT_FAILURE;
envp_parse(&main_argp, envp, "LSHFLAGS=", ARGP_IN_ORDER, options);
argp_parse(&main_argp, argc, argv, ARGP_IN_ORDER, NULL, options);
if (!options->super.random)
......
......@@ -199,6 +199,9 @@ main_argp_parser(int key, char *arg, struct argp_state *state)
break;
case ARGP_KEY_END:
if (self->super.inhibit_actions)
break;
if (!self->super.local_user)
{
argp_error(state, "You have to set LOGNAME in the environment.");
......@@ -295,7 +298,7 @@ make_lshg_exception_handler(struct exception_handler *parent,
}
int
main(int argc, char **argv)
main(int argc, char **argv, const char** envp)
{
struct lshg_options *options;
......@@ -316,7 +319,8 @@ main(int argc, char **argv)
NULL,
0),
&exit_code);
envp_parse(&main_argp, envp, "LSHGFLAGS=", ARGP_IN_ORDER, options);
argp_parse(&main_argp, argc, argv, ARGP_IN_ORDER, NULL, options);
{
......
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