comparison cli-authinteract.c @ 1121:bb3a03feb31f

Merge pull request #13 from gazoo74/fix-warnings Fix warnings
author Matt Johnston <matt@ucc.asn.au>
date Thu, 04 Jun 2015 22:25:28 +0800
parents 506e769ed6d1
children aaf576b27a10
comparison
equal deleted inserted replaced
1087:1e486f368ec3 1121:bb3a03feb31f
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;
65 } 65 }
66 66
67 void recv_msg_userauth_info_request() { 67 void recv_msg_userauth_info_request() {
68 68
69 unsigned char *name = NULL; 69 char *name = NULL;
70 unsigned char *instruction = NULL; 70 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) {
82 fprintf(stderr, "Login for %s@%s\n", cli_opts.username, 82 fprintf(stderr, "Login for %s@%s\n", cli_opts.username,
83 cli_opts.remotehost); 83 cli_opts.remotehost);
84 } 84 }
85 cli_ses.interact_request_received = 1; 85 cli_ses.interact_request_received = 1;
86 86
87 name = buf_getstring(ses.payload, NULL); 87 name = (char *)buf_getstring(ses.payload, NULL);
88 instruction = buf_getstring(ses.payload, NULL); 88 instruction = (char *)buf_getstring(ses.payload, NULL);
89 89
90 /* language tag */ 90 /* language tag */
91 buf_eatstring(ses.payload); 91 buf_eatstring(ses.payload);
92 92
93 num_prompts = buf_getint(ses.payload); 93 num_prompts = buf_getint(ses.payload);
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
147 CHECKCLEARTOWRITE(); 147 CHECKCLEARTOWRITE();
148 148
149 buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST); 149 buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST);
150 150
151 /* username */ 151 /* username */
152 buf_putstring(ses.writepayload, cli_opts.username, 152 buf_putstring(ses.writepayload, (const unsigned char *)cli_opts.username,
153 strlen(cli_opts.username)); 153 strlen(cli_opts.username));
154 154
155 /* service name */ 155 /* service name */
156 buf_putstring(ses.writepayload, SSH_SERVICE_CONNECTION, 156 buf_putstring(ses.writepayload, (const unsigned char *)SSH_SERVICE_CONNECTION,
157 SSH_SERVICE_CONNECTION_LEN); 157 SSH_SERVICE_CONNECTION_LEN);
158 158
159 /* method */ 159 /* method */
160 buf_putstring(ses.writepayload, AUTH_METHOD_INTERACT, 160 buf_putstring(ses.writepayload, (const unsigned char *)AUTH_METHOD_INTERACT,
161 AUTH_METHOD_INTERACT_LEN); 161 AUTH_METHOD_INTERACT_LEN);
162 162
163 /* empty language tag */ 163 /* empty language tag */
164 buf_putstring(ses.writepayload, "", 0); 164 buf_putstring(ses.writepayload, (const unsigned char *)"", 0);
165 165
166 /* empty submethods */ 166 /* empty submethods */
167 buf_putstring(ses.writepayload, "", 0); 167 buf_putstring(ses.writepayload, (const unsigned char *)"", 0);
168 168
169 encrypt_packet(); 169 encrypt_packet();
170 cli_ses.interact_request_received = 0; 170 cli_ses.interact_request_received = 0;
171 171
172 TRACE(("leave cli_auth_interactive")) 172 TRACE(("leave cli_auth_interactive"))