opkg: improve download error reporting
[oweals/opkg-lede.git] / opkg_cmd.c
index 4e70eeb4ce61130337a9a749c52c672e83783feb..db04a4a680fbd8ace0e114bfa681febf8d01d9eb 100644 (file)
@@ -153,12 +153,11 @@ int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **arg
       
 
        result = (cmd->fun)(conf, argc, argv);
-        if ( result == 0 ) {
-           opkg_message(conf, OPKG_NOTICE, "Successfully terminated.\n");
-        } else {
-           opkg_message(conf, OPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
 
+        if ( result != 0 ) {
+           opkg_message(conf, OPKG_NOTICE, "An error ocurred, return value: %d.\n", result);
         }
+
         if ( error_list ) {
            reverse_error_list(&error_list);
 
@@ -266,6 +265,42 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                            list_file_name);
          }
          free(url);
+
+         /* download detached signitures to verify the package lists */
+         /* get the url for the sig file */
+         if (src->extra_data)  /* debian style? */
+             sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
+                           "Packages.sig");
+         else
+             sprintf_alloc(&url, "%s/%s", src->value, "Packages.sig");
+
+         /* create temporary dir for it */
+         char *tmp, *tmp_file_name;
+         tmp = strdup ("/tmp/opkg.XXXXXX");
+         if (mkdtemp (tmp) == NULL) {
+               perror ("mkdtemp");
+               failures++;
+               continue;
+         }
+         sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig");
+
+         err = opkg_download(conf, url, tmp_file_name);
+         if (err) {
+           failures++;
+               opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+         } else {
+           int err;
+           err = opkg_verify_file (list_file_name, tmp_file_name);
+           if (err == 0)
+               opkg_message (conf, OPKG_NOTICE, "Signature check passed\n");
+           else
+               opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
+         }
+         unlink (tmp_file_name);
+         unlink (tmp);
+         free (tmp_file_name);
+
+         free (url);
          free(list_file_name);
      }
      free(lists_dir);