Mercurial > gftp.yaz
comparison lib/misc.c @ 61:42df9e4be8e0
2002-11-21 Brian Masney <masneyb@gftp.org>
* lib/misc.c lib/ssh.c lib/sshv2.c - improvements to the login
sequence for SSH connections
lib/sshv2.c - SSH transfers now works again
author | masneyb |
---|---|
date | Fri, 22 Nov 2002 15:47:07 +0000 |
parents | 618423504fe0 |
children | 41b71c4e5076 |
comparison
equal
deleted
inserted
replaced
60:8a9324fb63a4 | 61:42df9e4be8e0 |
---|---|
863 _("Running program %s\n"), tempstr); | 863 _("Running program %s\n"), tempstr); |
864 g_free (tempstr); | 864 g_free (tempstr); |
865 return (args); | 865 return (args); |
866 } | 866 } |
867 | 867 |
868 #define SSH_LOGIN_BUFSIZE 200 | |
869 #define SSH_ERROR_BADPASS -1 | |
870 #define SSH_ERROR_QUESTION -2 | |
868 | 871 |
869 char * | 872 char * |
870 ssh_start_login_sequence (gftp_request * request, int fd) | 873 ssh_start_login_sequence (gftp_request * request, int fd) |
871 { | 874 { |
875 char *tempstr, *pwstr, *key_pos, *tmppos; | |
872 size_t rem, len, diff, lastdiff; | 876 size_t rem, len, diff, lastdiff; |
873 int wrotepw, ok; | 877 int wrotepw, ok; |
874 char *tempstr, *pwstr; | |
875 ssize_t rd; | 878 ssize_t rd; |
876 | 879 |
877 rem = len = 100; | 880 rem = len = SSH_LOGIN_BUFSIZE; |
878 tempstr = g_malloc0 (len); | 881 key_pos = tempstr = g_malloc0 (len + 1); |
879 diff = lastdiff = 0; | 882 diff = lastdiff = 0; |
880 wrotepw = 0; | 883 wrotepw = 0; |
881 ok = 1; | 884 ok = 1; |
882 | 885 |
883 if (gftp_set_sockblocking (request, request->datafd, 1) == -1) | 886 if (gftp_set_sockblocking (request, fd, 1) == -1) |
884 return (NULL); | 887 return (NULL); |
885 | 888 |
886 pwstr = g_strconcat (request->password, "\n", NULL); | 889 pwstr = g_strconcat (request->password, "\n", NULL); |
887 | 890 |
888 errno = 0; | 891 errno = 0; |
889 while (1) | 892 while (1) |
890 { | 893 { |
891 if ((rd = gftp_read (request, tempstr + diff, rem -1, fd)) <= 0) | 894 if ((rd = gftp_read (request, tempstr + diff, rem - 1, fd)) <= 0) |
892 { | 895 { |
893 ok = 0; | 896 ok = 0; |
894 break; | 897 break; |
895 } | 898 } |
899 | |
896 tempstr[diff + rd] = '\0'; | 900 tempstr[diff + rd] = '\0'; |
897 rem -= rd; | 901 rem -= rd; |
898 diff += rd; | 902 diff += rd; |
899 if (rem <= 1) | 903 if (rem <= 1) |
900 { | 904 { |
901 tempstr = g_realloc (tempstr, len + 100); | 905 tempstr = g_realloc (tempstr, len + SSH_LOGIN_BUFSIZE); |
902 tempstr[diff] = '\0'; | 906 |
903 request->logging_function (gftp_logging_recv, request->user_data, | 907 request->logging_function (gftp_logging_recv, request->user_data, |
904 "%s", tempstr + lastdiff); | 908 "%s", tempstr + lastdiff); |
905 lastdiff = diff; | 909 lastdiff = diff; |
906 len += 100; | 910 len += SSH_LOGIN_BUFSIZE; |
907 rem = 100; | 911 rem = SSH_LOGIN_BUFSIZE; |
908 } | 912 } |
909 | 913 |
910 if (!wrotepw && | 914 if (diff > 11 && strcmp (tempstr + diff - 10, "password: ") == 0) |
911 strlen (tempstr) > 11 && strcmp (tempstr + strlen (tempstr) - 10, | 915 { |
912 "password: ") == 0) | 916 if (wrotepw) |
913 { | 917 { |
918 ok = SSH_ERROR_BADPASS; | |
919 break; | |
920 } | |
921 | |
914 wrotepw = 1; | 922 wrotepw = 1; |
915 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0) | 923 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0) |
916 { | 924 { |
917 ok = 0; | 925 ok = 0; |
918 break; | 926 break; |
919 } | 927 } |
920 } | 928 } |
921 | 929 else if ((tmppos = strstr (key_pos, "Enter passphrase for RSA key")) != NULL || |
922 else if (!wrotepw && | 930 ((tmppos = strstr (key_pos, "Enter passphrase for key '")) != NULL)) |
923 (strstr (tempstr, "Enter passphrase for RSA key") != NULL || | 931 { |
924 strstr (tempstr, "Enter passphrase for key '") != NULL)) | 932 key_pos = tmppos + 1; |
925 { | 933 if (wrotepw) |
934 { | |
935 ok = SSH_ERROR_BADPASS; | |
936 break; | |
937 } | |
938 | |
926 wrotepw = 1; | 939 wrotepw = 1; |
927 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0) | 940 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0) |
928 { | 941 { |
929 ok = 0; | 942 ok = 0; |
930 break; | 943 break; |
931 } | 944 } |
932 } | 945 } |
933 else if (strlen (tempstr) >= 5 && | 946 else if (diff >= 10 && strcmp (tempstr + diff - 10, "(yes/no)? ") == 0) |
934 strcmp (tempstr + strlen (tempstr) - 5, "xsftp") == 0) | 947 { |
948 ok = SSH_ERROR_QUESTION; | |
949 break; | |
950 } | |
951 else if (diff >= 5 && strcmp (tempstr + diff - 5, "xsftp") == 0) | |
935 break; | 952 break; |
936 } | 953 } |
937 | 954 |
938 g_free (pwstr); | 955 g_free (pwstr); |
939 tempstr[diff] = '\0'; | 956 |
940 request->logging_function (gftp_logging_recv, request->user_data, | 957 if (*(tempstr + lastdiff) != '\0') |
941 "%s\n", tempstr + lastdiff); | 958 request->logging_function (gftp_logging_recv, request->user_data, |
942 | 959 "%s\n", tempstr + lastdiff); |
943 if (!ok) | 960 |
944 { | 961 if (ok <= 0) |
962 { | |
963 if (ok == SSH_ERROR_BADPASS) | |
964 request->logging_function (gftp_logging_error, request->user_data, | |
965 _("Error: An incorrect password was entered\n")); | |
966 else if (ok == SSH_ERROR_QUESTION) | |
967 request->logging_function (gftp_logging_error, request->user_data, | |
968 _("Please connect to this host with the command line SSH utility and answer this question appropriately.\n")); | |
969 | |
945 g_free (tempstr); | 970 g_free (tempstr); |
946 return (NULL); | 971 return (NULL); |
947 } | 972 } |
948 | 973 |
949 return (tempstr); | 974 return (tempstr); |