X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=wotsap.c;h=8996c9b2d11549ba8e9f7ff93177b8776db4e5e4;hb=c981a80699901eb3d513a4cc9355574a69016037;hp=8990787a135b9df43eabb13964d44bc3d5555ed0;hpb=d781cc7c24d81c7461a2a5a6bf5125c0e5982d57;p=onak.git
diff --git a/wotsap.c b/wotsap.c
index 8990787..8996c9b 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)
{
@@ -62,16 +62,17 @@ static struct ll *sortkeyll(struct ll *keys)
return newll;
}
-static void output_key(FILE *names, FILE *keys, uint64_t keyid)
+static void output_key(struct onak_dbctx *dbctx,
+ FILE *names, FILE *keys, uint64_t keyid)
{
- fprintf(names, "%s\n", config.dbbackend->keyid2uid(keyid));
+ fprintf(names, "%s\n", dbctx->keyid2uid(dbctx, keyid));
fprintf(keys, "%c%c%c%c", (int) (keyid >> 24) & 0xFF,
(int) (keyid >> 16) & 0xFF,
(int) (keyid >> 8) & 0xFF,
(int) (keyid ) & 0xFF);
}
-static void wotsap(uint64_t keyid, char *dir)
+static void wotsap(struct onak_dbctx *dbctx, uint64_t keyid, char *dir)
{
struct ll *pending, *sigll, *sigsave;
uint32_t curidx = 0;
@@ -83,12 +84,16 @@ static void wotsap(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);
@@ -97,7 +102,7 @@ static void wotsap(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");
@@ -109,45 +114,46 @@ static void wotsap(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);
- config.dbbackend->cached_getkeysigs(keyid);
+ dbctx->cached_getkeysigs(dbctx, keyid);
curkey = findinhash(keyid);
curkey->colour = ++curidx;
pending = lladd(NULL, curkey);
- output_key(names, keys, curkey->keyid);
+ output_key(dbctx, names, keys, curkey->keyid);
while (pending != NULL) {
curkey = (struct stats_key *) pending->object;
- sigll = config.dbbackend->cached_getkeysigs(curkey->keyid);
+ sigll = dbctx->cached_getkeysigs(dbctx, curkey->keyid);
sigsave = sigll = sortkeyll(sigll);
sigcount = 0;
while (sigll != NULL) {
addkey = (struct stats_key *) sigll->object;
if (addkey->colour == 0 && !addkey->revoked) {
- uid = config.dbbackend->keyid2uid(addkey->keyid);
+ uid = dbctx->keyid2uid(dbctx, addkey->keyid);
if (uid != NULL) {
/* Force it to be loaded so we know if it's revoked */
- config.dbbackend->cached_getkeysigs(addkey->keyid);
+ dbctx->cached_getkeysigs(dbctx,
+ addkey->keyid);
if (!addkey->revoked) {
addkey->colour = ++curidx;
pending = lladdend(pending, addkey);
- output_key(names, keys, addkey->keyid);
+ output_key(dbctx, names, keys,
+ addkey->keyid);
}
}
}
@@ -177,13 +183,16 @@ static void wotsap(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) {
@@ -199,11 +208,16 @@ int main(int argc, char *argv[])
readconfig(configfile);
initlogthing("wotsap", config.logfile);
- config.dbbackend->initdb(true);
- inithash();
- wotsap(config.dbbackend->getfullkeyid(keyid), dir ? dir : ".");
- destroyhash();
- config.dbbackend->cleanupdb();
+ dbctx = config.dbinit(config.backend, true);
+ if (dbctx != NULL) {
+ inithash();
+ wotsap(dbctx, keyid, dir ? dir : ".");
+ destroyhash();
+ dbctx->cleanupdb(dbctx);
+ } else {
+ fprintf(stderr, "Couldn't initialize key database.\n");
+ }
cleanuplogthing();
cleanupconfig();
+ free(configfile);
}