PROGS = add lookup gpgwww onak
OBJS = armor.o parsekey.o keydb_$(DBTYPE).o merge.o keyid.o md5.o sha.o \
- getcgi.o keyindex.o mem.o stats.o ll.o hash.o onak-conf.o
+ getcgi.o keyindex.o mem.o stats.o ll.o hash.o onak-conf.o charfuncs.o
SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \
keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \
- gpgwww.c onak-conf.c
+ gpgwww.c onak-conf.c charfuncs.c
all: $(PROGS) testparse maxpath
$(CC) -o gpgwww gpgwww.o $(OBJS) $(LIBS)
lookup: lookup.o getcgi.o keyindex.o keydb_$(DBTYPE).o keyid.o sha.o \
- parsekey.o mem.o armor.o ll.o hash.o onak-conf.o
+ parsekey.o mem.o armor.o ll.o hash.o onak-conf.o charfuncs.o
$(CC) -o lookup lookup.o getcgi.o keyindex.o keydb_$(DBTYPE).o keyid.o \
- sha.o parsekey.o mem.o armor.o ll.o hash.o onak-conf.o $(LIBS)
+ sha.o parsekey.o mem.o armor.o ll.o hash.o onak-conf.o \
+ charfuncs.o $(LIBS)
add: add.o getcgi.o armor.o parsekey.o keydb_$(DBTYPE).o keyid.o sha.o mem.o \
- keyindex.o ll.o hash.o merge.o onak-conf.o
+ keyindex.o ll.o hash.o merge.o onak-conf.o charfuncs.o
$(CC) -o add add.o getcgi.o armor.o parsekey.o keydb_$(DBTYPE).o \
keyid.o sha.o mem.o keyindex.o ll.o hash.o merge.o onak-conf.o \
- $(LIBS)
+ charfuncs.o $(LIBS)
-onak: onak.o merge.o keyid.o sha.o armor.o parsekey.o ll.o \
+onak: onak.o merge.o keyid.o sha.o armor.o parsekey.o ll.o charfuncs.o \
keydb_$(DBTYPE).o mem.o keyindex.o hash.o getcgi.o onak-conf.o
- $(CC) $(LDFLAGS) -o onak onak.o merge.o keyid.o sha.o armor.o parsekey.o \
- keydb_$(DBTYPE).o mem.o keyindex.o ll.o hash.o getcgi.o \
- onak-conf.o $(LIBS)
-
+ $(CC) $(LDFLAGS) -o onak onak.o merge.o keyid.o sha.o armor.o \
+ parsekey.o keydb_$(DBTYPE).o mem.o keyindex.o ll.o hash.o \
+ getcgi.o charfuncs.o onak-conf.o $(LIBS)
clean:
rm -f $(PROGS) $(OBJS) Makefile.bak testparse maxpath *.core core \
#include <string.h>
#include "armor.h"
+#include "charfuncs.h"
#include "getcgi.h"
#include "keydb.h"
#include "keystructs.h"
#include "parsekey.h"
#include "merge.h"
-struct cgi_get_ctx {
- char *buffer;
- int offset;
-};
-
-
-int cgi_getchar(void *ctx, size_t count, unsigned char *c)
-{
- struct cgi_get_ctx *buf = NULL;
-
- buf = (struct cgi_get_ctx *) ctx;
-
- while (count-- > 0 && *c != 0) {
- *c = buf->buffer[buf->offset++];
- }
-
- return (*c == 0);
-}
-
int main(int argc, char *argv[])
{
struct openpgp_packet_list *packets = NULL;
struct openpgp_publickey *keys = NULL;
char **params = NULL;
- struct cgi_get_ctx ctx;
+ struct buffer_ctx ctx;
int i;
memset(&ctx, 0, sizeof(ctx));
for (i = 0; params != NULL && params[i] != NULL; i += 2) {
if (!strcmp(params[i], "keytext")) {
ctx.buffer = params[i+1];
+ ctx.size = strlen(ctx.buffer);
} else {
free(params[i+1]);
}
if (ctx.buffer == NULL) {
puts("Error: No keytext to add supplied.");
} else {
- dearmor_openpgp_stream(cgi_getchar,
+ dearmor_openpgp_stream(buffer_fetchchar,
&ctx,
&packets);
if (packets != NULL) {
--- /dev/null
+/*
+ * charfuncs.c - Routines for dealing with character streams.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2002 Project Purple
+ */
+
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+#include "charfuncs.h"
+
+/**
+ * buffer_fetchchar - Fetches a char from a buffer.
+ * @ctx: Our buffer context structure.
+ * @count: The number of characters to get from the buffer.
+ * @c: Where to put the characters retrieved.
+ */
+int buffer_fetchchar(void *ctx, size_t count, unsigned char *c)
+{
+ struct buffer_ctx *buf = NULL;
+ int i;
+
+ buf = (struct buffer_ctx *) ctx;
+ for (i = 0; i < count; i++) {
+ c[i] = buf->buffer[buf->offset++];
+ }
+
+ return (((buf->offset) == (buf->size)) ? 1 : 0);
+}
+
+/**
+ * buffer_putchar - Puts a char to a buffer.
+ * @ctx: Our buffer context structure.
+ * @count: The number of characters to put into the buffer.
+ * @c: The characters to add to the buffer.
+ *
+ * Adds characters to the buffer references by the buffer context. If we
+ * fill it then we double the size of the current buffer and then add the
+ * rest.
+ */
+int buffer_putchar(void *ctx, size_t count, unsigned char *c)
+{
+ struct buffer_ctx *buf = NULL;
+ size_t newsize = 0;
+ int i;
+
+ buf = (struct buffer_ctx *) ctx;
+
+ for (newsize = buf->size; newsize < (buf->offset + count);
+ newsize *= 2) ;
+
+ if (newsize != buf->size) {
+ buf->buffer = realloc(buf->buffer, newsize);
+ buf->size = newsize;
+ }
+
+ for (i = 0; i < count; i++) {
+ buf->buffer[buf->offset++] = c[i];
+ }
+
+ return 1;
+}
+
+/**
+ * file_fetchchar - Fetches a char from a file.
+ */
+int file_fetchchar(void *fd, size_t count, unsigned char *c)
+{
+ return !(read( *(int *) fd, c, count));
+}
+
+/**
+ * file_putchar - Puts a char to a file.
+ */
+int file_putchar(void *fd, size_t count, unsigned char *c)
+{
+ return !(write( *(int *) fd, c, count));
+}
--- /dev/null
+/*
+ * charfuncs.h - Routines for dealing with character streams.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2002 Project Purple
+ */
+
+#ifndef __CHARFUNCS_H__
+#define __CHARFUNCS_H__
+
+#include <stdlib.h>
+
+/**
+ * buffer_ctx - Shared with CGI buffer stuff...
+ * @buffer: The data buffer.
+ * @offset: Our current position in the buffer.
+ * @size: The size of the data buffer.
+ */
+struct buffer_ctx {
+ char *buffer;
+ int offset;
+ int size;
+};
+
+/**
+ * buffer_fetchchar - Fetches a char from a buffer.
+ * @ctx: Our buffer context structure.
+ * @count: The number of characters to get from the buffer.
+ * @c: Where to put the characters retrieved.
+ */
+int buffer_fetchchar(void *ctx, size_t count, unsigned char *c);
+
+/**
+ * buffer_putchar - Puts a char to a buffer.
+ * @ctx: Our buffer context structure.
+ * @count: The number of characters to put into the buffer.
+ * @c: The characters to add to the buffer.
+ *
+ * Adds characters to the buffer references by the buffer context. If we
+ * fill it then we double the size of the current buffer and then add the
+ * rest.
+ */
+int buffer_putchar(void *ctx, size_t count, unsigned char *c);
+
+/**
+ * file_fetchchar - Fetches a char from a file.
+ */
+int file_fetchchar(void *fd, size_t count, unsigned char *c);
+
+/**
+ * file_putchar - Puts a char to a file.
+ */
+int file_putchar(void *fd, size_t count, unsigned char *c);
+
+
+#endif /* __CHARFUNCS_H__ */
#include <string.h>
#include <unistd.h>
+#include "charfuncs.h"
#include "keydb.h"
#include "keyid.h"
#include "keyindex.h"
*/
static DB_ENV db2_env;
-/*
- * Shared with CGI buffer stuff...
- */
-struct db2_get_ctx {
- char *buffer;
- int offset;
- int size;
-};
-
-/**
- * keydb_fetchchar - Fetches a char from a buffer.
- */
-int keydb_fetchchar(void *ctx, int count, unsigned char *c)
-{
- struct db2_get_ctx *buf = NULL;
- int i;
-
- buf = (struct db2_get_ctx *) ctx;
- for (i = 0; i < count; i++) {
- c[i] = buf->buffer[buf->offset++];
- }
-
- return (((buf->offset) == (buf->size)) ? 1 : 0);
-}
-
-/**
- * keydb_putchar - Puts a char to a file.
- */
-static int keydb_putchar(void *fd, unsigned char c)
-{
-// return !(lo_write(dbconn, *(int *) fd, &c, sizeof(c)));
- return 1;
-}
-
DB *keydb(DBT *key)
{
/*
int ret;
DBT key, data;
char id[KEYDB_KEYID_BYTES];
- struct db2_get_ctx fetchbuf;
+ struct buffer_ctx fetchbuf;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
fetchbuf.buffer = data.data;
fetchbuf.offset = 0;
fetchbuf.size = data.size;
- read_openpgp_stream(keydb_fetchchar, &fetchbuf, &packets);
+ read_openpgp_stream(buffer_fetchchar, &fetchbuf, &packets);
parse_keys(packets, publickey);
}
#include <db.h>
+#include "charfuncs.h"
#include "keydb.h"
#include "keyid.h"
#include "keyindex.h"
*/
static DB *worddb = NULL;
-/**
- * db3_get_ctx - Shared with CGI buffer stuff...
- */
-struct db3_get_ctx {
- char *buffer;
- int offset;
- int size;
-};
-
-/**
- * keydb_fetchchar - Fetches a char from a file.
- */
-static int keydb_fetchchar(void *ctx, size_t count, unsigned char *c)
-{
- struct db3_get_ctx *buf = NULL;
- int i;
-
- buf = (struct db3_get_ctx *) ctx;
- for (i = 0; i < count; i++) {
- c[i] = buf->buffer[buf->offset++];
- }
-
- return (((buf->offset) == (buf->size)) ? 1 : 0);
-}
-
-/**
- * keydb_putchar - Puts a char to a file.
- */
-static int keydb_putchar(void *ctx, size_t count, unsigned char *c)
-{
- struct db3_get_ctx *buf = NULL;
- size_t newsize = 0;
- int i;
-
- buf = (struct db3_get_ctx *) ctx;
-
- for (newsize = buf->size; newsize < (buf->offset + count);
- newsize *= 2) ;
-
- if (newsize != buf->size) {
- buf->buffer = realloc(buf->buffer, newsize);
- buf->size = newsize;
- }
-
- for (i = 0; i < count; i++) {
- buf->buffer[buf->offset++] = c[i];
- }
-
- return 1;
-}
-
/**
* makewordlist - Takes a string and splits it into a set of unique words.
* @wordlist: The current word list.
DBT key, data;
int ret = 0;
int numkeys = 0;
- struct db3_get_ctx fetchbuf;
+ struct buffer_ctx fetchbuf;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
fetchbuf.buffer = data.data;
fetchbuf.offset = 0;
fetchbuf.size = data.size;
- read_openpgp_stream(keydb_fetchchar, &fetchbuf,
+ read_openpgp_stream(buffer_fetchchar, &fetchbuf,
&packets);
parse_keys(packets, publickey);
numkeys++;
struct openpgp_publickey *next = NULL;
int ret = 0;
int i = 0;
- struct db3_get_ctx storebuf;
+ struct buffer_ctx storebuf;
DBT key;
DBT data;
uint64_t keyid = 0;
storebuf.size = 8192;
storebuf.buffer = malloc(8192);
- write_openpgp_stream(keydb_putchar, &storebuf, packets);
+ write_openpgp_stream(buffer_putchar, &storebuf, packets);
/*
* Now we have the key data store it in the DB; the keyid is the key.
#include <string.h>
#include <unistd.h>
+#include "charfuncs.h"
#include "keydb.h"
#include "keyid.h"
#include "keystructs.h"
#include "onak-conf.h"
#include "parsekey.h"
-/**
- * keydb_fetchchar - Fetches a char from a file.
- */
-static int keydb_fetchchar(void *fd, size_t count, unsigned char *c)
-{
- return !(read( *(int *) fd, c, count));
-}
-
-/**
- * keydb_putchar - Puts a char to a file.
- */
-static int keydb_putchar(void *fd, size_t count, unsigned char *c)
-{
- return !(write( *(int *) fd, c, count));
-}
-
/**
* initdb - Initialize the key database.
*
fd = open(keyfile, O_RDONLY); // | O_SHLOCK);
if (fd > -1) {
- read_openpgp_stream(keydb_fetchchar, &fd, &packets);
+ read_openpgp_stream(file_fetchchar, &fd, &packets);
parse_keys(packets, publickey);
close(fd);
}
flatten_publickey(publickey, &packets, &list_end);
publickey -> next = next;
- write_openpgp_stream(keydb_putchar, &fd, packets);
+ write_openpgp_stream(file_putchar, &fd, packets);
close(fd);
}