Mercurial > dropbear
comparison common-algo.c @ 1316:2c9dac2d6707
merge 2016.74
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 21 Jul 2016 23:38:42 +0800 |
parents | 750ec4ec4cbe eed9376a4ad6 |
children | 06d52bcb8094 |
comparison
equal
deleted
inserted
replaced
1298:251c5f7a6e96 | 1316:2c9dac2d6707 |
---|---|
527 } | 527 } |
528 | 528 |
529 return NULL; | 529 return NULL; |
530 } | 530 } |
531 | 531 |
532 static void | |
533 try_add_algo(const char *algo_name, algo_type *algos, | |
534 const char *algo_desc, algo_type * new_algos, int *num_ret) | |
535 { | |
536 algo_type *match_algo = check_algo(algo_name, algos); | |
537 if (!match_algo) | |
538 { | |
539 dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", algo_name, algo_desc); | |
540 return; | |
541 } | |
542 | |
543 new_algos[*num_ret] = *match_algo; | |
544 (*num_ret)++; | |
545 } | |
546 | |
547 /* Checks a user provided comma-separated algorithm list for available | 532 /* Checks a user provided comma-separated algorithm list for available |
548 * options. Any that are not acceptable are removed in-place. Returns the | 533 * options. Any that are not acceptable are removed in-place. Returns the |
549 * number of valid algorithms. */ | 534 * number of valid algorithms. */ |
550 int | 535 int |
551 check_user_algos(const char* user_algo_list, algo_type * algos, | 536 check_user_algos(const char* user_algo_list, algo_type * algos, |
552 const char *algo_desc) | 537 const char *algo_desc) |
553 { | 538 { |
554 algo_type new_algos[MAX_PROPOSED_ALGO]; | 539 algo_type new_algos[MAX_PROPOSED_ALGO+1]; |
555 /* this has two passes. first we sweep through the given list of | |
556 * algorithms and mark them as usable=2 in the algo_type[] array... */ | |
557 int num_ret = 0; | |
558 char *work_list = m_strdup(user_algo_list); | 540 char *work_list = m_strdup(user_algo_list); |
559 char *last_name = work_list; | 541 char *start = work_list; |
560 char *c; | 542 char *c; |
561 for (c = work_list; *c; c++) | 543 int n; |
544 /* So we can iterate and look for null terminator */ | |
545 memset(new_algos, 0x0, sizeof(new_algos)); | |
546 for (c = work_list, n = 0; ; c++) | |
562 { | 547 { |
563 if (*c == ',') | 548 char oc = *c; |
564 { | 549 if (n >= MAX_PROPOSED_ALGO) { |
550 dropbear_exit("Too many algorithms '%s'", user_algo_list); | |
551 } | |
552 if (*c == ',' || *c == '\0') { | |
553 algo_type *match_algo = NULL; | |
565 *c = '\0'; | 554 *c = '\0'; |
566 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret); | 555 match_algo = check_algo(start, algos); |
556 if (match_algo) { | |
557 if (check_algo(start, new_algos)) { | |
558 TRACE(("Skip repeated algorithm '%s'", start)) | |
559 } else { | |
560 new_algos[n] = *match_algo; | |
561 n++; | |
562 } | |
563 } else { | |
564 dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", start, algo_desc); | |
565 } | |
567 c++; | 566 c++; |
568 last_name = c; | 567 start = c; |
569 } | 568 } |
570 } | 569 if (oc == '\0') { |
571 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret); | 570 break; |
571 } | |
572 } | |
572 m_free(work_list); | 573 m_free(work_list); |
573 | 574 /* n+1 to include a null terminator */ |
574 new_algos[num_ret].name = NULL; | 575 memcpy(algos, new_algos, sizeof(*new_algos) * (n+1)); |
575 | 576 return n; |
576 /* Copy one more as a blank delimiter */ | |
577 memcpy(algos, new_algos, sizeof(*new_algos) * (num_ret+1)); | |
578 return num_ret; | |
579 } | 577 } |
580 #endif /* DROPBEAR_USER_ALGO_LIST */ | 578 #endif /* DROPBEAR_USER_ALGO_LIST */ |