Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no-pty-setowner option in authorized_keys #272

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int svr_pubkey_allows_agentfwd(void);
int svr_pubkey_allows_tcpfwd(void);
int svr_pubkey_allows_x11fwd(void);
int svr_pubkey_allows_pty(void);
int svr_pubkey_allows_pty_setowner(void);
int svr_pubkey_allows_local_tcpfwd(const char *host, unsigned int port);
void svr_pubkey_set_forced_command(struct ChanSess *chansess);
void svr_pubkey_options_cleanup(void);
Expand All @@ -56,6 +57,7 @@ int svr_add_pubkey_options(buffer *options_buf, int line_num, const char* filena
#define svr_pubkey_allows_tcpfwd() 1
#define svr_pubkey_allows_x11fwd() 1
#define svr_pubkey_allows_pty() 1
#define svr_pubkey_allows_pty_setowner() 1
static inline int svr_pubkey_allows_local_tcpfwd(const char *host, unsigned int port)
{ (void)host; (void)port; return 1; }

Expand Down Expand Up @@ -143,6 +145,7 @@ struct PubKeyOptions {
int no_agent_forwarding_flag;
int no_x11_forwarding_flag;
int no_pty_flag;
int no_pty_setowner_flag;
/* "command=" option. */
char * forced_command;
/* "permitopen=" option */
Expand Down
14 changes: 14 additions & 0 deletions src/svr-authpubkeyoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ int svr_pubkey_allows_pty() {
return 1;
}

/* Returns 1 if pubkey allows pty_setowner, 0 otherwise */
int svr_pubkey_allows_pty_setowner() {
if (ses.authstate.pubkey_options
&& ses.authstate.pubkey_options->no_pty_setowner_flag) {
return 0;
}
return 1;
}

/* Returns 1 if pubkey allows local tcp fowarding to the provided destination,
* 0 otherwise */
int svr_pubkey_allows_local_tcpfwd(const char *host, unsigned int port) {
Expand Down Expand Up @@ -198,6 +207,11 @@ int svr_add_pubkey_options(buffer *options_buf, int line_num, const char* filena
#endif
goto next_option;
}
if (match_option(options_buf, "no-pty-setowner") == DROPBEAR_SUCCESS) {
dropbear_log(LOG_WARNING, "Pty setowner disabled.");
ses.authstate.pubkey_options->no_pty_setowner_flag = 1;
goto next_option;
}
if (match_option(options_buf, "no-pty") == DROPBEAR_SUCCESS) {
dropbear_log(LOG_WARNING, "Pty allocation disabled.");
ses.authstate.pubkey_options->no_pty_flag = 1;
Expand Down
6 changes: 4 additions & 2 deletions src/svr-chansession.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ static void cleanupchansess(const struct Channel *channel) {
login_logout(li);
login_free_entry(li);

pty_release(chansess->tty);
if (svr_pubkey_allows_pty_setowner())
pty_release(chansess->tty);
m_free(chansess->tty);
}

Expand Down Expand Up @@ -614,7 +615,8 @@ static int sessionpty(struct ChanSess * chansess) {
pw = getpwnam(ses.authstate.pw_name);
if (!pw)
dropbear_exit("getpwnam failed after succeeding previously");
pty_setowner(pw, chansess->tty);
if (svr_pubkey_allows_pty_setowner())
pty_setowner(pw, chansess->tty);

/* Set up the rows/col counts */
sessionwinchange(chansess);
Expand Down