xref: /openbsd/libexec/spamd/gdcopy.c (revision 274d7c50)
1 /*
2  * Copyright (c) 2013 Todd C. Miller <millert@openbsd.org>
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 <string.h>
20 
21 #include "grey.h"
22 
23 /* Fill in struct gdata from DBT, converting from obsolete format as needed. */
24 int
25 gdcopyin(const void *v, struct gdata *gd)
26 {
27 	const DBT *dbd = v;
28 	int rc = 0;
29 
30 	if (dbd->size == sizeof(struct gdata)) {
31 		/* Current grey data format. */
32 		memcpy(gd, dbd->data, sizeof(struct gdata));
33 	} else if (dbd->size == sizeof(struct ogdata)) {
34 		/* Backwards compat for obsolete grey data format. */
35 		struct ogdata ogd;
36 		memcpy(&ogd, dbd->data, sizeof(struct ogdata));
37 		gd->first = ogd.first;
38 		gd->pass = ogd.pass;
39 		gd->expire = ogd.expire;
40 		gd->bcount = ogd.bcount;
41 		gd->pcount = ogd.pcount;
42 	} else {
43 		/* Unsupported grey data format. */
44 		rc = -1;
45 	}
46 	return (rc);
47 }
48