151210d5cSmillert /*
2*bf198cc6Smillert * Copyright (c) 2013 Todd C. Miller <millert@openbsd.org>
351210d5cSmillert *
451210d5cSmillert * Permission to use, copy, modify, and distribute this software for any
551210d5cSmillert * purpose with or without fee is hereby granted, provided that the above
651210d5cSmillert * copyright notice and this permission notice appear in all copies.
751210d5cSmillert *
851210d5cSmillert * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
951210d5cSmillert * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1051210d5cSmillert * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1151210d5cSmillert * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1251210d5cSmillert * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1351210d5cSmillert * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1451210d5cSmillert * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1551210d5cSmillert */
1651210d5cSmillert
1751210d5cSmillert #include <sys/types.h>
1851210d5cSmillert #include <db.h>
1951210d5cSmillert #include <string.h>
2051210d5cSmillert
2151210d5cSmillert #include "grey.h"
2251210d5cSmillert
2351210d5cSmillert /* Fill in struct gdata from DBT, converting from obsolete format as needed. */
2451210d5cSmillert int
gdcopyin(const void * v,struct gdata * gd)2551210d5cSmillert gdcopyin(const void *v, struct gdata *gd)
2651210d5cSmillert {
2751210d5cSmillert const DBT *dbd = v;
2851210d5cSmillert int rc = 0;
2951210d5cSmillert
3051210d5cSmillert if (dbd->size == sizeof(struct gdata)) {
3151210d5cSmillert /* Current grey data format. */
3251210d5cSmillert memcpy(gd, dbd->data, sizeof(struct gdata));
3351210d5cSmillert } else if (dbd->size == sizeof(struct ogdata)) {
3451210d5cSmillert /* Backwards compat for obsolete grey data format. */
3551210d5cSmillert struct ogdata ogd;
3651210d5cSmillert memcpy(&ogd, dbd->data, sizeof(struct ogdata));
3751210d5cSmillert gd->first = ogd.first;
3851210d5cSmillert gd->pass = ogd.pass;
3951210d5cSmillert gd->expire = ogd.expire;
4051210d5cSmillert gd->bcount = ogd.bcount;
4151210d5cSmillert gd->pcount = ogd.pcount;
4251210d5cSmillert } else {
4351210d5cSmillert /* Unsupported grey data format. */
4451210d5cSmillert rc = -1;
4551210d5cSmillert }
4651210d5cSmillert return (rc);
4751210d5cSmillert }
48