X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libopkg%2Fconffile.c;h=434edf6eda4fbf19aec44f7ad4da0493feb7256a;hb=9239b2d2a5856b363fc8770710fecacde9f05a92;hp=d74ee60ee45534210071bc6882cd39e386ccd1f3;hpb=edf1b1964b565726a0b0f730b109e4491c7929b9;p=oweals%2Fopkg-lede.git diff --git a/libopkg/conffile.c b/libopkg/conffile.c index d74ee60..434edf6 100644 --- a/libopkg/conffile.c +++ b/libopkg/conffile.c @@ -15,50 +15,58 @@ General Public License for more details. */ -#include +#include #include -#include "includes.h" #include "opkg_message.h" - #include "conffile.h" #include "file_util.h" #include "sprintf_alloc.h" +#include "opkg_conf.h" -int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum) +int conffile_init(conffile_t * conffile, const char *file_name, + const char *md5sum) { - return nv_pair_init(conffile, file_name, md5sum); + return nv_pair_init(conffile, file_name, md5sum); } -void conffile_deinit(conffile_t *conffile) +void conffile_deinit(conffile_t * conffile) { - nv_pair_deinit(conffile); + nv_pair_deinit(conffile); } -int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile) +int conffile_has_been_modified(conffile_t * conffile) { - char *md5sum; - char *filename = conffile->name; - char *root_filename; - int ret = 1; - - if (conffile->value == NULL) { - opkg_message(conf, OPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name); - return 1; - } - - root_filename = root_filename_alloc(conf, filename); - - md5sum = file_md5sum_alloc(root_filename); - - if (md5sum && (ret = strcmp(md5sum, conffile->value))) { - opkg_message(conf, OPKG_NOTICE, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__, - conffile->name, md5sum, conffile->value); - } - - free(root_filename); - if (md5sum) - free(md5sum); - - return ret; + char *chksum; + char *filename = conffile->name; + char *root_filename; + int ret = 1; + + if (conffile->value == NULL) { + opkg_msg(NOTICE, "Conffile %s has no md5sum.\n", + conffile->name); + return 1; + } + + root_filename = root_filename_alloc(filename); + +#ifdef HAVE_MD5 + if (conffile->value && strlen(conffile->value) > 33) { + chksum = file_sha256sum_alloc(root_filename); + } else { + chksum = file_md5sum_alloc(root_filename); + } +#else + chksum = file_sha256sum_alloc(root_filename); +#endif + if (chksum && (ret = strcmp(chksum, conffile->value))) { + opkg_msg(INFO, "Conffile %s:\n\told chk=%s\n\tnew chk=%s\n", + conffile->name, chksum, conffile->value); + } + + free(root_filename); + if (chksum) + free(chksum); + + return ret; }