X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;ds=sidebyside;f=wotsap.c;h=0a9f9df543df48c4b0852c2716fd623ea389af7a;hb=c0fee41b459cc3822d890bac98882a6c9696c033;hp=ca66f8562b41530c0f3f78e8962fab69adf5e021;hpb=2e969db9d32b8fba8a22125fe5b66323b6d1f71e;p=onak.git
diff --git a/wotsap.c b/wotsap.c
index ca66f85..0a9f9df 100644
--- a/wotsap.c
+++ b/wotsap.c
@@ -19,8 +19,7 @@
* more details.
*
* You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program. If not, see .
*/
#include
@@ -29,11 +28,12 @@
#include
#include
+#include "build-config.h"
+
#include "hash.h"
#include "log.h"
#include "onak-conf.h"
#include "stats.h"
-#include "version.h"
static struct ll *sortkeyll(struct ll *keys)
{
@@ -84,12 +84,16 @@ static void wotsap(struct onak_dbctx *dbctx, uint64_t keyid, char *dir)
/* Length of dir + "/" + "signatures" + NUL */
tmppath = malloc(strlen(dir) + 12);
+ if (tmppath == NULL) {
+ fprintf(stderr, "Couldn't allocate memory for directory\n");
+ goto err;
+ }
sprintf(tmppath, "%s/WOTVERSION", dir);
file = fopen(tmppath, "w");
if (file == NULL) {
fprintf(stderr, "Couldn't open %s\n", tmppath);
- return;
+ goto err;
}
fprintf(file, "0.2\n");
fclose(file);
@@ -98,7 +102,7 @@ static void wotsap(struct onak_dbctx *dbctx, uint64_t keyid, char *dir)
file = fopen(tmppath, "w");
if (file == NULL) {
fprintf(stderr, "Couldn't open %s\n", tmppath);
- return;
+ goto err;
}
fprintf(file, "This is a Web of Trust archive.\n");
fprintf(file, "The file format is documented at:\n");
@@ -110,21 +114,20 @@ static void wotsap(struct onak_dbctx *dbctx, uint64_t keyid, char *dir)
names = fopen(tmppath, "w");
if (names == NULL) {
fprintf(stderr, "Couldn't open %s\n", tmppath);
- return;
+ goto err;
}
sprintf(tmppath, "%s/keys", dir);
keys = fopen(tmppath, "wb");
if (keys == NULL) {
fprintf(stderr, "Couldn't open %s\n", tmppath);
- return;
+ goto err;
}
sprintf(tmppath, "%s/signatures", dir);
sigs = fopen(tmppath, "wb");
if (sigs == NULL) {
fprintf(stderr, "Couldn't open %s\n", tmppath);
- return;
+ goto err;
}
- free(tmppath);
dbctx->cached_getkeysigs(dbctx, keyid);
curkey = findinhash(keyid);
@@ -180,18 +183,23 @@ static void wotsap(struct onak_dbctx *dbctx, uint64_t keyid, char *dir)
fclose(sigs);
fclose(keys);
fclose(names);
+err:
+ free(tmppath);
}
int main(int argc, char *argv[])
{
int optchar;
char *configfile = NULL, *dir = NULL;
- uint64_t keyid = 0x2DA8B985;
+ uint64_t keyid = 0x94FA372B2DA8B985;
struct onak_dbctx *dbctx;
while ((optchar = getopt(argc, argv, "c:")) != -1 ) {
switch (optchar) {
case 'c':
+ if (configfile != NULL) {
+ free(configfile);
+ }
configfile = strdup(optarg);
break;
}
@@ -206,8 +214,7 @@ int main(int argc, char *argv[])
dbctx = config.dbinit(config.backend, true);
if (dbctx != NULL) {
inithash();
- wotsap(dbctx, dbctx->getfullkeyid(dbctx, keyid),
- dir ? dir : ".");
+ wotsap(dbctx, keyid, dir ? dir : ".");
destroyhash();
dbctx->cleanupdb(dbctx);
} else {