xref: /openbsd-src/libexec/spamd/gdcopy.c (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*
2  * Copyright (c) 2013 Todd C. Miller <Todd.Miller@courtesan.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <sys/types.h>
18 #include <db.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <time.h>
23 
24 #include "grey.h"
25 
26 /* Fill in struct gdata from DBT, converting from obsolete format as needed. */
27 int
28 gdcopyin(const void *v, struct gdata *gd)
29 {
30 	const DBT *dbd = v;
31 	int rc = 0;
32 
33 	if (dbd->size == sizeof(struct gdata)) {
34 		/* Current grey data format. */
35 		memcpy(gd, dbd->data, sizeof(struct gdata));
36 	} else if (dbd->size == sizeof(struct ogdata)) {
37 		/* Backwards compat for obsolete grey data format. */
38 		struct ogdata ogd;
39 		memcpy(&ogd, dbd->data, sizeof(struct ogdata));
40 		gd->first = ogd.first;
41 		gd->pass = ogd.pass;
42 		gd->expire = ogd.expire;
43 		gd->bcount = ogd.bcount;
44 		gd->pcount = ogd.pcount;
45 	} else {
46 		/* Unsupported grey data format. */
47 		rc = -1;
48 	}
49 	return (rc);
50 }
51