conffile.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* conffile.c - the opkg package management system
  2. Carl D. Worth
  3. Copyright (C) 2001 University of Southern California
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "opkg_message.h"
  16. #include "conffile.h"
  17. #include "file_util.h"
  18. #include "sprintf_alloc.h"
  19. #include "opkg_conf.h"
  20. int conffile_init(conffile_t * conffile, const char *file_name,
  21. const char *md5sum)
  22. {
  23. return nv_pair_init(conffile, file_name, md5sum);
  24. }
  25. void conffile_deinit(conffile_t * conffile)
  26. {
  27. nv_pair_deinit(conffile);
  28. }
  29. int conffile_has_been_modified(conffile_t * conffile)
  30. {
  31. char *chksum;
  32. char *filename = conffile->name;
  33. char *root_filename;
  34. int ret = 1;
  35. if (conffile->value == NULL) {
  36. opkg_msg(NOTICE, "Conffile %s has no md5sum.\n",
  37. conffile->name);
  38. return 1;
  39. }
  40. root_filename = root_filename_alloc(filename);
  41. if (conffile->value && strlen(conffile->value) > 33) {
  42. chksum = file_sha256sum_alloc(root_filename);
  43. } else {
  44. chksum = file_md5sum_alloc(root_filename);
  45. }
  46. if (chksum && (ret = strcmp(chksum, conffile->value))) {
  47. opkg_msg(INFO, "Conffile %s:\n\told chk=%s\n\tnew chk=%s\n",
  48. conffile->name, chksum, conffile->value);
  49. }
  50. free(root_filename);
  51. if (chksum)
  52. free(chksum);
  53. return ret;
  54. }