[PATCH] telnet: busybox telnet autologin with -a -l user option picks incorrect username

Athira Rajeev atrajeev at linux.vnet.ibm.com
Thu Aug 17 10:01:11 UTC 2017


    busybox telnet autologin with -a -l user option picks incorrect username

    package: busybox
    version: tested with upstream

    1. Using telnet ( from telnet package ) , behaviour is:
     
     # in.telnetd -debug 23456 &
    
     # telnet -a -l user123 localhost 23456
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost (127.0.0.1).
    Escape character is '^]'.
    Password:

    The above will login with password of user <user123>

    2. Behaviour with busybox telnet :
    #busybox telnet -a -l user123 localhost 23456

    Entering character mode
    Escape character is '^]'.

    Password:
    Login incorrect

    login:

    Here login fails with password of <user123> . Since -a option is passed,
    busybox telnet picks username from $USER (  ENVIRON option ) and value from -l is overwritten.

    Implementation Details
    =======================

    A. With telnet ( from telnet package ):

    -a : sets autologin to 1
    -l username : sets autologin to 1 and assigns value of username to "user” variable.
    USER ( from ENVIRON option ) is considered only if "user" is not set.

    Code Snippet:
    if (autologin && user == NULL) {
            struct passwd *pw;

            user = getenv("USER");

    So -a -l <username> picks proper value from <username>

    B. With Busybox telnet:

    	if (1 & getopt32(argv, "al:", &G.autologin))
    		G.autologin = getenv("USER");
    	argv += optind;

    Here when both a and l option are present, return will be 0011 ( ie 3, since bit 0 and 1 will be set in getopt32 )
    and G.autologin will be finally set to getenv("USER") though initially it gets
    proper value from -l <user> during getopt32(argv, "al:", &G.autologin)

    In Summary incase of busybox telnet, passing -a and -l together leads to user value from  getenv("USER") and hence it fails.

    Adding patch which has the following change similar to telnet which:
    - Assigns from getenv("USER") only if G.autologin is NULL

    Signed-off-by: Athira Rajeev <atrajeev at linux.vnet.ibm.com <mailto:atrajeev at linux.vnet.ibm.com>>

diff --git a/networking/telnet.c b/networking/telnet.c
index e1c2595..d1b79a0 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -644,7 +644,8 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)

 #if ENABLE_FEATURE_TELNET_AUTOLOGIN
 	if (1 & getopt32(argv, "al:", &G.autologin))
-		G.autologin = getenv("USER");
+		if (G.autologin == NULL)
+			G.autologin = getenv("USER");
 	argv += optind;
 #else
 	argv++;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20170817/e19c8114/attachment.html>


More information about the busybox mailing list