Skip to content

Commit

Permalink
New command 'auth' for password protection
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-naumov committed Aug 3, 2024
1 parent 4bb2079 commit 87e4c2a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct comm comms[RC_LAST + 1] =
{ "allpartial", NEED_DISPLAY|ARGS_1, {NULL} },
{ "altscreen", ARGS_01, {NULL} },
{ "at", ARGS_2|ARGS_ORMORE, {NULL} },
{ "auth", ARGS_1, {NULL} },
{ "autodetach", ARGS_1, {NULL} },
{ "autonuke", NEED_DISPLAY|ARGS_1, {NULL} },
{ "backtick", ARGS_1|ARGS_ORMORE, {NULL} },
Expand Down
8 changes: 8 additions & 0 deletions src/doc/screen.1
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,14 @@ attrcolor i "+b"
Make bright colored text also bold.
.RE
.TP
.BR "auth [ on | off ]"
.RS 0
.PP
This command enables/disables password protection for the
.I screen
session. It is off by default (authentication is disabled).
.RE
.TP
.BR "autodetach [ on | off ]"
.RS 0
.PP
Expand Down
3 changes: 3 additions & 0 deletions src/doc/screen.texinfo
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,9 @@ Enables support for the "alternate screen" terminal capability. @xref{Redisplay
Execute a command at other displays or windows. @xref{At}.
@item attrcolor @var{attrib} [@var{attribute/color-modifier}]
Map attributes to colors. @xref{Attrcolor}.
@item auth @var{state}
This command enables/disables password protection for the screen session.
It is off by default (authentication is disabled).
@item autodetach @var{state}
Automatically detach the session on SIGHUP. @xref{Detach}.
@item autonuke @var{state}
Expand Down
14 changes: 14 additions & 0 deletions src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -4296,6 +4296,17 @@ static void DoCommandAltscreen(struct action *act)
OutputMsg(0, "Will %sdo alternate screen switching", use_altscreen ? "" : "not ");
}


static void DoCommandAuth(struct action *act)
{
int msgok = display && !*rc_name;

(void)ParseSwitch(act, &do_auth);
if (msgok)
OutputMsg(0, "Authentication: %s" , do_auth ? "enabled" : "disabled");
}


static void DoCommandBacktick(struct action *act)
{
char **args = act->args;
Expand Down Expand Up @@ -5229,6 +5240,9 @@ void DoAction(struct action *act)
case RC_ALTSCREEN:
DoCommandAltscreen(act);
break;
case RC_AUTH:
DoCommandAuth(act);
break;
case RC_BACKTICK:
DoCommandBacktick(act);
break;
Expand Down
1 change: 1 addition & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static void SetTtyname(bool fatal, struct stat *st);
int nversion; /* numerical version, used for secondary DA */

/* the attacher */
bool do_auth = false;
struct passwd *ppp;
char *attach_tty;
int attach_fd = -1;
Expand Down
1 change: 1 addition & 0 deletions src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ extern bool adaptflag;
extern bool auto_detach;
extern bool cjkwidth;
extern bool default_startup;
extern bool do_auth;
extern bool hastruecolor;
extern bool iflag;
extern bool logtstamp_on;
Expand Down
10 changes: 8 additions & 2 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ void ReceiveMsg(void)
case MSG_ATTACH:
if (CreateTempDisplay(&m, recvfd, win))
break;
AskPassword(&m);
if (do_auth)
AskPassword(&m);
else
FinishAttach(&m);
break;
case MSG_ERROR:
{
Expand All @@ -854,7 +857,10 @@ void ReceiveMsg(void)
case MSG_POW_DETACH:
if (CreateTempDisplay(&m, recvfd, NULL))
break;
AskPassword(&m);
if (do_auth)
AskPassword(&m);
else
FinishAttach(&m);
break;
case MSG_QUERY:
{
Expand Down

0 comments on commit 87e4c2a

Please sign in to comment.