comparison common-algo.c @ 683:63f8d6c469cf

ENABLE_USER_ALGO_LIST should work for the client
author Matt Johnston <matt@ucc.asn.au>
date Thu, 17 May 2012 00:26:12 +0800
parents 4edea9f363d0
children c37857676924
comparison
equal deleted inserted replaced
682:4edea9f363d0 683:63f8d6c469cf
295 ret_list = m_strdup(buf_getptr(b, b->len - b->pos)); 295 ret_list = m_strdup(buf_getptr(b, b->len - b->pos));
296 buf_free(b); 296 buf_free(b);
297 return ret_list; 297 return ret_list;
298 } 298 }
299 299
300 static int 300 static algo_type*
301 check_algo(const char* algo_name, algo_type *algos) 301 check_algo(const char* algo_name, algo_type *algos)
302 { 302 {
303 algo_type *a; 303 algo_type *a;
304 for (a = algos; a->name != NULL; a++) 304 for (a = algos; a->name != NULL; a++)
305 { 305 {
306 if (strcmp(a->name, algo_name) == 0) 306 if (strcmp(a->name, algo_name) == 0)
307 { 307 {
308 a->usable = 2; 308 return a;
309 return DROPBEAR_SUCCESS; 309 }
310 } 310 }
311 } 311
312 312 return NULL;
313 return DROPBEAR_FAILURE; 313 }
314 } 314
315
316 /* helper for check_user_algos */
317 static void 315 static void
318 try_add_algo(const char *algo_name, algo_type *algos, 316 try_add_algo(const char *algo_name, algo_type *algos,
319 const char *algo_desc, char ** out_list, int *num_ret) 317 const char *algo_desc, algo_type * new_algos, int *num_ret)
320 { 318 {
321 if (check_algo(algo_name, algos) == DROPBEAR_FAILURE) 319 algo_type *match_algo = check_algo(algo_name, algos);
320 if (!match_algo)
322 { 321 {
323 dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", algo_name, algo_desc); 322 dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", algo_name, algo_desc);
324 return; 323 return;
325 } 324 }
326 325
327 if (*num_ret != 0) 326 new_algos[*num_ret] = *match_algo;
328 {
329 **out_list = ',';
330 (*out_list)++;
331 }
332
333 *out_list += sprintf(*out_list, "%s", algo_name);
334 (*num_ret)++; 327 (*num_ret)++;
335 } 328 }
336 329
337 /* Checks a user provided comma-separated algorithm list for available 330 /* Checks a user provided comma-separated algorithm list for available
338 * options. Any that are not acceptable are removed in-place. Returns the 331 * options. Any that are not acceptable are removed in-place. Returns the
339 * number of valid algorithms. */ 332 * number of valid algorithms. */
340 int 333 int
341 check_user_algos(char* user_algo_list, algo_type * algos, 334 check_user_algos(const char* user_algo_list, algo_type * algos,
342 const char *algo_desc) 335 const char *algo_desc)
343 { 336 {
337 algo_type new_algos[MAX_PROPOSED_ALGO];
344 /* this has two passes. first we sweep through the given list of 338 /* this has two passes. first we sweep through the given list of
345 * algorithms and mark them as usable=2 in the algo_type[] array... */ 339 * algorithms and mark them as usable=2 in the algo_type[] array... */
346 int num_ret = 0; 340 int num_ret = 0;
347 char *work_list = m_strdup(user_algo_list); 341 char *work_list = m_strdup(user_algo_list);
348 char *last_name = work_list; 342 char *last_name = work_list;
349 char *out_list = user_algo_list;
350 char *c; 343 char *c;
351 for (c = work_list; *c; c++) 344 for (c = work_list; *c; c++)
352 { 345 {
353 if (*c == ',') 346 if (*c == ',')
354 { 347 {
355 *c = '\0'; 348 *c = '\0';
356 try_add_algo(last_name, algos, algo_desc, &out_list, &num_ret); 349 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret);
357 last_name = c++; 350 last_name = c++;
358 } 351 }
359 } 352 }
360 try_add_algo(last_name, algos, algo_desc, &out_list, &num_ret); 353 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret);
361 m_free(work_list); 354 m_free(work_list);
362 355
363 /* ...then we mark anything with usable==1 as usable=0, and 356 new_algos[num_ret].name = NULL;
364 * usable==2 as usable=1. */ 357
365 algo_type *a; 358 /* Copy one more as a blank delimiter */
366 for (a = algos; a->name != NULL; a++) 359 memcpy(algos, new_algos, sizeof(*new_algos) * (num_ret+1));
367 {
368 if (a->usable == 1)
369 {
370 a->usable = 0;
371 } else if (a->usable == 2)
372 {
373 a->usable = 1;
374 }
375 }
376 return num_ret; 360 return num_ret;
377 } 361 }
378 #endif // ENABLE_USER_ALGO_LIST 362 #endif // ENABLE_USER_ALGO_LIST