1
0

230-drop_md5_support.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. --- a/libopkg/conffile.c
  2. +++ b/libopkg/conffile.c
  3. @@ -36,7 +36,7 @@ void conffile_deinit(conffile_t *conffil
  4. int conffile_has_been_modified(conffile_t *conffile)
  5. {
  6. - char *md5sum;
  7. + char *chksum;
  8. char *filename = conffile->name;
  9. char *root_filename;
  10. int ret = 1;
  11. @@ -48,16 +48,23 @@ int conffile_has_been_modified(conffile_
  12. root_filename = root_filename_alloc(filename);
  13. - md5sum = file_md5sum_alloc(root_filename);
  14. -
  15. - if (md5sum && (ret = strcmp(md5sum, conffile->value))) {
  16. - opkg_msg(INFO, "Conffile %s:\n\told md5=%s\n\tnew md5=%s\n",
  17. - conffile->name, md5sum, conffile->value);
  18. +#ifdef HAVE_MD5
  19. + if(conffile->value && strlen(conffile->value) > 33) {
  20. + chksum = file_sha256sum_alloc(root_filename);
  21. + } else {
  22. + chksum = file_md5sum_alloc(root_filename);
  23. + }
  24. +#else
  25. + chksum = file_sha256sum_alloc(root_filename);
  26. +#endif
  27. + if (chksum && (ret = strcmp(chksum, conffile->value))) {
  28. + opkg_msg(INFO, "Conffile %s:\n\told chk=%s\n\tnew chk=%s\n",
  29. + conffile->name, chksum, conffile->value);
  30. }
  31. free(root_filename);
  32. - if (md5sum)
  33. - free(md5sum);
  34. + if (chksum)
  35. + free(chksum);
  36. return ret;
  37. }
  38. --- a/libopkg/file_util.c
  39. +++ b/libopkg/file_util.c
  40. @@ -26,7 +26,9 @@
  41. #include "sprintf_alloc.h"
  42. #include "file_util.h"
  43. +#ifdef HAVE_MD5
  44. #include "md5.h"
  45. +#endif
  46. #include "libbb/libbb.h"
  47. #if defined HAVE_SHA256
  48. @@ -135,6 +137,7 @@ file_mkdir_hier(const char *path, long m
  49. return make_directory(path, mode, FILEUTILS_RECUR);
  50. }
  51. +#ifdef HAVE_MD5
  52. char *file_md5sum_alloc(const char *file_name)
  53. {
  54. static const int md5sum_bin_len = 16;
  55. @@ -180,6 +183,7 @@ char *file_md5sum_alloc(const char *file
  56. return md5sum_hex;
  57. }
  58. +#endif
  59. #ifdef HAVE_SHA256
  60. char *file_sha256sum_alloc(const char *file_name)
  61. --- a/libopkg/opkg_install.c
  62. +++ b/libopkg/opkg_install.c
  63. @@ -1082,7 +1082,7 @@ resolve_conffiles(pkg_t *pkg)
  64. conffile_list_elt_t *iter;
  65. conffile_t *cf;
  66. char *cf_backup;
  67. - char *md5sum;
  68. + char *chksum;
  69. if (conf->noaction) return 0;
  70. @@ -1093,7 +1093,7 @@ resolve_conffiles(pkg_t *pkg)
  71. /* Might need to initialize the md5sum for each conffile */
  72. if (cf->value == NULL) {
  73. - cf->value = file_md5sum_alloc(root_filename);
  74. + cf->value = file_sha256sum_alloc(root_filename);
  75. }
  76. if (!file_exists(root_filename)) {
  77. @@ -1105,8 +1105,16 @@ resolve_conffiles(pkg_t *pkg)
  78. if (file_exists(cf_backup)) {
  79. /* Let's compute md5 to test if files are changed */
  80. - md5sum = file_md5sum_alloc(cf_backup);
  81. - if (md5sum && cf->value && strcmp(cf->value,md5sum) != 0 ) {
  82. +#ifdef HAVE_MD5
  83. + if(cf->value && strlen(cf->value) > 33) {
  84. + chksum = file_sha256sum_alloc(cf_backup);
  85. + } else {
  86. + chksum = file_md5sum_alloc(cf_backup);
  87. + }
  88. +#else
  89. + chksum = file_sha256sum_alloc(cf_backup);
  90. +#endif
  91. + if (chksum && cf->value && strcmp(cf->value,chksum) != 0 ) {
  92. if (conf->force_maintainer) {
  93. opkg_msg(NOTICE, "Conffile %s using maintainer's setting.\n",
  94. cf_backup);
  95. @@ -1123,8 +1131,8 @@ resolve_conffiles(pkg_t *pkg)
  96. }
  97. }
  98. unlink(cf_backup);
  99. - if (md5sum)
  100. - free(md5sum);
  101. + if (chksum)
  102. + free(chksum);
  103. }
  104. free(cf_backup);
  105. @@ -1323,6 +1331,7 @@ opkg_install_pkg(pkg_t *pkg, int from_up
  106. }
  107. #endif
  108. +#ifdef HAVE_MD5
  109. /* Check for md5 values */
  110. if (pkg->md5sum)
  111. {
  112. @@ -1346,6 +1355,7 @@ opkg_install_pkg(pkg_t *pkg, int from_up
  113. if (file_md5)
  114. free(file_md5);
  115. }
  116. +#endif
  117. #ifdef HAVE_SHA256
  118. /* Check for sha256 value */
  119. --- a/libopkg/Makefile.am
  120. +++ b/libopkg/Makefile.am
  121. @@ -25,13 +25,16 @@ opkg_list_sources = conffile.c conffile.
  122. pkg_src.c pkg_src.h pkg_src_list.c pkg_src_list.h \
  123. str_list.c str_list.h void_list.c void_list.h \
  124. active_list.c active_list.h list.h
  125. -opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c md5.c md5.h \
  126. +opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c \
  127. parse_util.c parse_util.h \
  128. sprintf_alloc.c sprintf_alloc.h \
  129. xregex.c xregex.h xsystem.c xsystem.h
  130. if HAVE_PATHFINDER
  131. opkg_util_sources += opkg_pathfinder.c opkg_pathfinder.h
  132. endif
  133. +if HAVE_MD5
  134. +opkg_util_sources += md5.c md5.h
  135. +endif
  136. if HAVE_SHA256
  137. opkg_util_sources += sha256.c sha256.h
  138. endif
  139. --- a/configure.ac
  140. +++ b/configure.ac
  141. @@ -68,10 +68,19 @@ AC_ARG_ENABLE(sha256,
  142. (sha256.{c,h} are GPLv3 licensed) [[default=no]] ]),
  143. [want_sha256="$enableval"], [want_sha256="no"])
  144. +AC_ARG_ENABLE(md5,
  145. + AC_HELP_STRING([--enable-md5], [Enable md5sum check
  146. + (md5.{c,h} are GPLv3 licensed) [[default=no]] ]),
  147. + [want_md5="$enableval"], [want_md5="yes"])
  148. +
  149. if test "x$want_sha256" = "xyes"; then
  150. AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support])
  151. fi
  152. +if test "x$want_md5" = "xyes"; then
  153. + AC_DEFINE(HAVE_MD5, 1, [Define if you want md5 support])
  154. +fi
  155. AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes")
  156. +AM_CONDITIONAL(HAVE_MD5, test "x$want_md5" = "xyes")
  157. # check for openssl
  158. AC_ARG_ENABLE(openssl,
  159. --- a/libopkg/pkg_parse.c
  160. +++ b/libopkg/pkg_parse.c
  161. @@ -49,9 +49,9 @@ parse_status(pkg_t *pkg, const char *sst
  162. static void
  163. parse_conffiles(pkg_t *pkg, const char *cstr)
  164. {
  165. - char file_name[1024], md5sum[35];
  166. + char file_name[1024], md5sum[85];
  167. - if (sscanf(cstr, "%1023s %34s", file_name, md5sum) != 2) {
  168. + if (sscanf(cstr, "%1023s %84s", file_name, md5sum) != 2) {
  169. opkg_msg(ERROR, "Failed to parse Conffiles line for %s\n",
  170. pkg->name);
  171. return;