comparison svr-chansession.c @ 566:b321aeb57c64

- set $SSH_ORIGINAL_COMMAND if a command is forced, and log it if LOG_COMMANDS is set
author Matt Johnston <matt@ucc.asn.au>
date Wed, 26 Aug 2009 14:09:22 +0000
parents 52d7301e46bd
children 893a9dd0b9dd
comparison
equal deleted inserted replaced
565:1929bbe3fa84 566:b321aeb57c64
576 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 576 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
577 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess, 577 static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
578 int iscmd, int issubsys) { 578 int iscmd, int issubsys) {
579 579
580 unsigned int cmdlen; 580 unsigned int cmdlen;
581 int is_forced;
581 int ret; 582 int ret;
582 583
583 TRACE(("enter sessioncommand")) 584 TRACE(("enter sessioncommand"))
584 585
585 if (chansess->cmd != NULL) { 586 if (chansess->cmd != NULL) {
586 /* Note that only one command can _succeed_. The client might try 587 /* Note that only one command can _succeed_. The client might try
587 * one command (which fails), then try another. Ie fallback 588 * one command (which fails), then try another. Ie fallback
588 * from sftp to scp */ 589 * from sftp to scp */
589 return DROPBEAR_FAILURE; 590 return DROPBEAR_FAILURE;
590 } 591 }
591
592 /* take public key option 'command' into account */
593 svr_pubkey_set_forced_command(chansess);
594 592
595 if (iscmd) { 593 if (iscmd) {
596 /* "exec" */ 594 /* "exec" */
597 if (chansess->cmd == NULL) { 595 if (chansess->cmd == NULL) {
598 chansess->cmd = buf_getstring(ses.payload, &cmdlen); 596 chansess->cmd = buf_getstring(ses.payload, &cmdlen);
614 m_free(chansess->cmd); 612 m_free(chansess->cmd);
615 return DROPBEAR_FAILURE; 613 return DROPBEAR_FAILURE;
616 } 614 }
617 } 615 }
618 } 616 }
617
618 /* take public key option 'command' into account */
619 svr_pubkey_set_forced_command(chansess);
619 620
620 #ifdef LOG_COMMANDS 621 #ifdef LOG_COMMANDS
621 if (chansess->cmd) { 622 if (chansess->cmd) {
622 dropbear_log(LOG_INFO, "user %s executing '%s'", 623 dropbear_log(LOG_INFO, "user %s executing '%s'",
623 ses.authstate.pw_name, chansess->cmd); 624 ses.authstate.pw_name, chansess->cmd);
881 addnewvar("PATH", DEFAULT_PATH); 882 addnewvar("PATH", DEFAULT_PATH);
882 if (chansess->term != NULL) { 883 if (chansess->term != NULL) {
883 addnewvar("TERM", chansess->term); 884 addnewvar("TERM", chansess->term);
884 } 885 }
885 886
887 printf("adding option %p %s\n", ses.authstate.pubkey_options,
888 ses.authstate.pubkey_options->original_command);
889
890 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
891 if (ses.authstate.pubkey_options &&
892 ses.authstate.pubkey_options->original_command) {
893 addnewvar("SSH_ORIGINAL_COMMAND",
894 ses.authstate.pubkey_options->original_command);
895 }
896 #endif
897
886 /* change directory */ 898 /* change directory */
887 if (chdir(ses.authstate.pw_dir) < 0) { 899 if (chdir(ses.authstate.pw_dir) < 0) {
888 dropbear_exit("error changing directory"); 900 dropbear_exit("error changing directory");
889 } 901 }
890 902