Deleted Added
full compact
yp_dblookup.c (19161) yp_dblookup.c (20818)
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 1995
3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: yp_dblookup.c,v 1.4 1996/07/07 19:04:33 wpaul Exp wpaul $
32 * $Id: yp_dblookup.c,v 1.2 1996/12/22 15:54:15 wpaul Exp $
33 *
34 */
35#include <stdio.h>
36#include <stdlib.h>
37#include <fcntl.h>
38#include <string.h>
39#include <limits.h>
40#include <unistd.h>
41#include <db.h>
42#include <sys/stat.h>
43#include <sys/param.h>
44#include <errno.h>
45#include <paths.h>
46#include <rpcsvc/yp.h>
47#include "yp_extern.h"
48
49#ifndef lint
33 *
34 */
35#include <stdio.h>
36#include <stdlib.h>
37#include <fcntl.h>
38#include <string.h>
39#include <limits.h>
40#include <unistd.h>
41#include <db.h>
42#include <sys/stat.h>
43#include <sys/param.h>
44#include <errno.h>
45#include <paths.h>
46#include <rpcsvc/yp.h>
47#include "yp_extern.h"
48
49#ifndef lint
50static const char rcsid[] = "$Id: yp_dblookup.c,v 1.4 1996/07/07 19:04:33 wpaul Exp wpaul $";
50static const char rcsid[] = "$Id: yp_dblookup.c,v 1.2 1996/12/22 15:54:15 wpaul Exp $";
51#endif
52
53int ypdb_debug = 0;
51#endif
52
53int ypdb_debug = 0;
54int yp_errno = YP_TRUE;
54enum ypstat yp_errno = YP_TRUE;
55
56#define PERM_SECURE (S_IRUSR|S_IWUSR)
57HASHINFO openinfo = {
58 4096, /* bsize */
59 32, /* ffactor */
60 256, /* nelem */
61 2048 * 512, /* cachesize */
62 NULL, /* hash */

--- 391 unchanged lines hidden (view full) ---

454 * to match against.
455 *
456 * - yp_first_record(): retrieve first key/data base in a database.
457 *
458 * - yp_next_record(): retrieve key/data pair that sequentially follows
459 * the supplied key value in the database.
460 */
461
55
56#define PERM_SECURE (S_IRUSR|S_IWUSR)
57HASHINFO openinfo = {
58 4096, /* bsize */
59 32, /* ffactor */
60 256, /* nelem */
61 2048 * 512, /* cachesize */
62 NULL, /* hash */

--- 391 unchanged lines hidden (view full) ---

454 * to match against.
455 *
456 * - yp_first_record(): retrieve first key/data base in a database.
457 *
458 * - yp_next_record(): retrieve key/data pair that sequentially follows
459 * the supplied key value in the database.
460 */
461
462#ifdef DB_CACHE
463int yp_get_record(dbp,key,data,allow)
464 DB *dbp;
465#else
462int yp_get_record(domain,map,key,data,allow)
463 const char *domain;
464 const char *map;
466int yp_get_record(domain,map,key,data,allow)
467 const char *domain;
468 const char *map;
469#endif
465 const DBT *key;
466 DBT *data;
467 int allow;
468{
470 const DBT *key;
471 DBT *data;
472 int allow;
473{
474#ifndef DB_CACHE
469 DB *dbp;
475 DB *dbp;
476#endif
470 int rval = 0;
471#ifndef DB_CACHE
472 static unsigned char buf[YPMAXRECORD];
473#endif
474
475 if (ypdb_debug)
477 int rval = 0;
478#ifndef DB_CACHE
479 static unsigned char buf[YPMAXRECORD];
480#endif
481
482 if (ypdb_debug)
476 yp_error("Looking up key [%.*s] in map [%s]",
477 key->size, key->data, map);
483 yp_error("Looking up key [%.*s]",
484 key->size, key->data);
478
479 /*
480 * Avoid passing back magic "YP_*" entries unless
481 * the caller specifically requested them by setting
482 * the 'allow' flag.
483 */
484 if (!allow && !strncmp(key->data, "YP_", 3))
485 return(YP_NOKEY);
486
485
486 /*
487 * Avoid passing back magic "YP_*" entries unless
488 * the caller specifically requested them by setting
489 * the 'allow' flag.
490 */
491 if (!allow && !strncmp(key->data, "YP_", 3))
492 return(YP_NOKEY);
493
487#ifdef DB_CACHE
488 if ((dbp = yp_open_db_cache(domain, map, NULL, 0)) == NULL) {
489#else
494#ifndef DB_CACHE
490 if ((dbp = yp_open_db(domain, map)) == NULL) {
495 if ((dbp = yp_open_db(domain, map)) == NULL) {
491#endif
492 return(yp_errno);
493 }
496 return(yp_errno);
497 }
498#endif
494
495 if ((rval = (dbp->get)(dbp, key, data, 0)) != 0) {
496#ifdef DB_CACHE
497 qhead.cqh_first->dbptr->size = 0;
498#else
499 (void)(dbp->close)(dbp);
500#endif
501 if (rval == 1)

--- 84 unchanged lines hidden (view full) ---

586 static DBT lkey = { NULL, 0 };
587 static DBT ldata = { NULL, 0 };
588 int rval;
589#ifndef DB_CACHE
590 static unsigned char keybuf[YPMAXRECORD];
591 static unsigned char datbuf[YPMAXRECORD];
592#endif
593
499
500 if ((rval = (dbp->get)(dbp, key, data, 0)) != 0) {
501#ifdef DB_CACHE
502 qhead.cqh_first->dbptr->size = 0;
503#else
504 (void)(dbp->close)(dbp);
505#endif
506 if (rval == 1)

--- 84 unchanged lines hidden (view full) ---

591 static DBT lkey = { NULL, 0 };
592 static DBT ldata = { NULL, 0 };
593 int rval;
594#ifndef DB_CACHE
595 static unsigned char keybuf[YPMAXRECORD];
596 static unsigned char datbuf[YPMAXRECORD];
597#endif
598
594 if (key == NULL || key->data == NULL) {
599 if (key == NULL || !key->size || key->data == NULL) {
595 rval = yp_first_record(dbp,key,data,allow);
596 if (rval == YP_NOKEY)
597 return(YP_NOMORE);
598 else
599 return(rval);
600 }
601
602 if (ypdb_debug)

--- 49 unchanged lines hidden (view full) ---

652 lkey.data = (void *)&keybuf;
653 lkey.size = key->size;
654 bcopy((char *)data->data, (char *)&datbuf, data->size);
655 data->data = (void *)&datbuf;
656#endif
657
658 return(YP_TRUE);
659}
600 rval = yp_first_record(dbp,key,data,allow);
601 if (rval == YP_NOKEY)
602 return(YP_NOMORE);
603 else
604 return(rval);
605 }
606
607 if (ypdb_debug)

--- 49 unchanged lines hidden (view full) ---

657 lkey.data = (void *)&keybuf;
658 lkey.size = key->size;
659 bcopy((char *)data->data, (char *)&datbuf, data->size);
660 data->data = (void *)&datbuf;
661#endif
662
663 return(YP_TRUE);
664}
665
666#ifdef DB_CACHE
667/*
668 * Database glue functions.
669 */
670
671static DB *yp_currmap_db = NULL;
672static int yp_allow_db = 0;
673
674ypstat yp_select_map(map, domain, key, allow)
675 char *map;
676 char *domain;
677 keydat *key;
678 int allow;
679{
680 yp_currmap_db = yp_open_db_cache(domain, map, key->keydat_val,
681 key->keydat_len);
682
683 yp_allow_db = allow;
684 return(yp_errno);
685}
686
687ypstat yp_getbykey(key, val)
688 keydat *key;
689 valdat *val;
690{
691 DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
692 ypstat rval;
693
694 db_key.data = key->keydat_val;
695 db_key.size = key->keydat_len;
696
697 rval = yp_get_record(yp_currmap_db,
698 &db_key, &db_val, yp_allow_db);
699
700 if (rval == YP_TRUE) {
701 val->valdat_val = db_val.data;
702 val->valdat_len = db_val.size;
703 }
704
705 return(rval);
706}
707
708ypstat yp_firstbykey(key, val)
709 keydat *key;
710 valdat *val;
711{
712 DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
713 ypstat rval;
714
715 rval = yp_first_record(yp_currmap_db, &db_key, &db_val, yp_allow_db);
716
717 if (rval == YP_TRUE) {
718 key->keydat_val = db_key.data;
719 key->keydat_len = db_key.size;
720 val->valdat_val = db_val.data;
721 val->valdat_len = db_val.size;
722 }
723
724 return(rval);
725}
726
727ypstat yp_nextbykey(key, val)
728 keydat *key;
729 valdat *val;
730{
731 DBT db_key = { NULL, 0 }, db_val = { NULL, 0 };
732 ypstat rval;
733
734 db_key.data = key->keydat_val;
735 db_key.size = key->keydat_len;
736
737 rval = yp_next_record(yp_currmap_db, &db_key, &db_val, 0, yp_allow_db);
738
739 if (rval == YP_TRUE) {
740 key->keydat_val = db_key.data;
741 key->keydat_len = db_key.size;
742 val->valdat_val = db_val.data;
743 val->valdat_len = db_val.size;
744 }
745
746 return(rval);
747}
748#endif