Mercurial > dropbear
comparison cli-authinteract.c @ 1104:5806c644469a
Turn get_response()'s return type and prompt argument into char *
author | Gaël PORTAY <gael.portay@gmail.com> |
---|---|
date | Sat, 02 May 2015 16:30:59 +0200 |
parents | c45d65392c1a |
children | 506e769ed6d1 |
comparison
equal
deleted
inserted
replaced
1103:303e27a78d2e | 1104:5806c644469a |
---|---|
29 #include "ssh.h" | 29 #include "ssh.h" |
30 #include "runopts.h" | 30 #include "runopts.h" |
31 | 31 |
32 #ifdef ENABLE_CLI_INTERACT_AUTH | 32 #ifdef ENABLE_CLI_INTERACT_AUTH |
33 | 33 |
34 static unsigned char* get_response(unsigned char* prompt) | 34 static char* get_response(char* prompt) |
35 { | 35 { |
36 FILE* tty = NULL; | 36 FILE* tty = NULL; |
37 unsigned char* response = NULL; | 37 char* response = NULL; |
38 /* not a password, but a reasonable limit */ | 38 /* not a password, but a reasonable limit */ |
39 char buf[DROPBEAR_MAX_CLI_PASS]; | 39 char buf[DROPBEAR_MAX_CLI_PASS]; |
40 char* ret = NULL; | 40 char* ret = NULL; |
41 | 41 |
42 fprintf(stderr, "%s", prompt); | 42 fprintf(stderr, "%s", prompt); |
48 } else { | 48 } else { |
49 ret = fgets(buf, sizeof(buf), stdin); | 49 ret = fgets(buf, sizeof(buf), stdin); |
50 } | 50 } |
51 | 51 |
52 if (ret == NULL) { | 52 if (ret == NULL) { |
53 response = (unsigned char*)m_strdup(""); | 53 response = m_strdup(""); |
54 } else { | 54 } else { |
55 unsigned int buflen = strlen(buf); | 55 unsigned int buflen = strlen(buf); |
56 /* fgets includes newlines */ | 56 /* fgets includes newlines */ |
57 if (buflen > 0 && buf[buflen-1] == '\n') | 57 if (buflen > 0 && buf[buflen-1] == '\n') |
58 buf[buflen-1] = '\0'; | 58 buf[buflen-1] = '\0'; |
59 response = (unsigned char*)m_strdup(buf); | 59 response = m_strdup(buf); |
60 } | 60 } |
61 | 61 |
62 m_burn(buf, sizeof(buf)); | 62 m_burn(buf, sizeof(buf)); |
63 | 63 |
64 return response; | 64 return response; |
69 unsigned char *name = NULL; | 69 unsigned char *name = NULL; |
70 unsigned char *instruction = NULL; | 70 unsigned char *instruction = NULL; |
71 unsigned int num_prompts = 0; | 71 unsigned int num_prompts = 0; |
72 unsigned int i; | 72 unsigned int i; |
73 | 73 |
74 unsigned char *prompt = NULL; | 74 char *prompt = NULL; |
75 unsigned int echo = 0; | 75 unsigned int echo = 0; |
76 unsigned char *response = NULL; | 76 char *response = NULL; |
77 | 77 |
78 TRACE(("enter recv_msg_recv_userauth_info_request")) | 78 TRACE(("enter recv_msg_recv_userauth_info_request")) |
79 | 79 |
80 /* Let the user know what password/host they are authing for */ | 80 /* Let the user know what password/host they are authing for */ |
81 if (!cli_ses.interact_request_received) { | 81 if (!cli_ses.interact_request_received) { |
113 } | 113 } |
114 m_free(instruction); | 114 m_free(instruction); |
115 | 115 |
116 for (i = 0; i < num_prompts; i++) { | 116 for (i = 0; i < num_prompts; i++) { |
117 unsigned int response_len = 0; | 117 unsigned int response_len = 0; |
118 prompt = buf_getstring(ses.payload, NULL); | 118 prompt = (char *)buf_getstring(ses.payload, NULL); |
119 cleantext(prompt); | 119 cleantext(prompt); |
120 | 120 |
121 echo = buf_getbool(ses.payload); | 121 echo = buf_getbool(ses.payload); |
122 | 122 |
123 if (!echo) { | 123 if (!echo) { |
124 unsigned char* p = getpass_or_cancel(prompt); | 124 char* p = getpass_or_cancel(prompt); |
125 response = m_strdup(p); | 125 response = m_strdup(p); |
126 m_burn(p, strlen(p)); | 126 m_burn(p, strlen(p)); |
127 } else { | 127 } else { |
128 response = get_response(prompt); | 128 response = get_response(prompt); |
129 } | 129 } |
130 | 130 |
131 response_len = strlen(response); | 131 response_len = strlen(response); |
132 buf_putstring(ses.writepayload, response, response_len); | 132 buf_putstring(ses.writepayload, (const unsigned char *)response, response_len); |
133 m_burn(response, response_len); | 133 m_burn(response, response_len); |
134 m_free(prompt); | 134 m_free(prompt); |
135 m_free(response); | 135 m_free(response); |
136 } | 136 } |
137 | 137 |