yp_dblookup.c (16999) | yp_dblookup.c (19161) |
---|---|
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 $ | 32 * $Id: yp_dblookup.c,v 1.4 1996/07/07 19:04:33 wpaul Exp wpaul $ |
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 $"; | 50static const char rcsid[] = "$Id: yp_dblookup.c,v 1.4 1996/07/07 19:04:33 wpaul Exp wpaul $"; |
51#endif 52 53int ypdb_debug = 0; 54int yp_errno = YP_TRUE; 55 56#define PERM_SECURE (S_IRUSR|S_IWUSR) 57HASHINFO openinfo = { 58 4096, /* bsize */ --- 13 unchanged lines hidden (view full) --- 72 73static int numdbs = 0; 74 75struct dbent { 76 DB *dbp; 77 char *name; 78 char *key; 79 int size; | 51#endif 52 53int ypdb_debug = 0; 54int yp_errno = YP_TRUE; 55 56#define PERM_SECURE (S_IRUSR|S_IWUSR) 57HASHINFO openinfo = { 58 4096, /* bsize */ --- 13 unchanged lines hidden (view full) --- 72 73static int numdbs = 0; 74 75struct dbent { 76 DB *dbp; 77 char *name; 78 char *key; 79 int size; |
80 int flags; |
|
80}; 81 82static CIRCLEQ_HEAD(circlehead, circleq_entry) qhead; 83 84struct circleq_entry { 85 struct dbent *dbptr; 86 CIRCLEQ_ENTRY(circleq_entry) links; 87}; --- 100 unchanged lines hidden (view full) --- 188 CIRCLEQ_REMOVE(&qhead, qhead.cqh_first, links); 189 yp_free_qent(qptr); 190 } 191 numdbs = 0; 192 193 return; 194} 195 | 81}; 82 83static CIRCLEQ_HEAD(circlehead, circleq_entry) qhead; 84 85struct circleq_entry { 86 struct dbent *dbptr; 87 CIRCLEQ_ENTRY(circleq_entry) links; 88}; --- 100 unchanged lines hidden (view full) --- 189 CIRCLEQ_REMOVE(&qhead, qhead.cqh_first, links); 190 yp_free_qent(qptr); 191 } 192 numdbs = 0; 193 194 return; 195} 196 |
197static char *inter_string = "YP_INTERDOMAIN"; 198static char *secure_string = "YP_SECURE"; 199static int inter_sz = sizeof("YP_INTERDOMAIN") - 1; 200static int secure_sz = sizeof("YP_SECURE") - 1; |
|
196 | 201 |
202static int yp_setflags(dbp) 203 DB *dbp; 204{ 205 DBT key = { NULL, 0 }, data = { NULL, 0 }; 206 int flags = 0; 207 208 key.data = inter_string; 209 key.size = inter_sz; 210 211 if (!(dbp->get)(dbp, &key, &data, 0)) 212 flags |= YP_INTERDOMAIN; 213 214 key.data = secure_string; 215 key.size = secure_sz; 216 217 if (!(dbp->get)(dbp, &key, &data, 0)) 218 flags |= YP_SECURE; 219 220 return(flags); 221} 222 223int yp_testflag(map, domain, flag) 224 char *map; 225 char *domain; 226 int flag; 227{ 228 char buf[MAXPATHLEN + 2]; 229 register struct circleq_entry *qptr; 230 231 if (map == NULL || domain == NULL) 232 return(0); 233 234 strcpy(buf, domain); 235 strcat(buf, "/"); 236 strcat(buf, map); 237 238 for (qptr = qhead.cqh_first; qptr != (void *)&qhead; 239 qptr = qptr->links.cqe_next) { 240 if (!strcmp(qptr->dbptr->name, buf)) { 241 if (qptr->dbptr->flags & flag) 242 return(1); 243 else 244 return(0); 245 } 246 } 247 248 if (yp_open_db_cache(domain, map, NULL, 0) == NULL) 249 return(0); 250 251 if (qhead.cqh_first->dbptr->flags & flag) 252 return(1); 253 254 return(0); 255} 256 |
|
197/* 198 * Add a DB handle and database name to the cache. We only maintain 199 * fixed number of entries in the cache, so if we're asked to store 200 * a new entry when all our slots are already filled, we have to kick 201 * out the entry in the last slot to make room. 202 */ 203static int yp_cache_db(dbp, name, size) 204 DB *dbp; --- 17 unchanged lines hidden (view full) --- 222 return(1); 223 } 224 225 qptr->dbptr->dbp = dbp; 226 qptr->dbptr->name = strdup(name); 227 qptr->dbptr->size = size; 228 qptr->dbptr->key = NULL; 229 | 257/* 258 * Add a DB handle and database name to the cache. We only maintain 259 * fixed number of entries in the cache, so if we're asked to store 260 * a new entry when all our slots are already filled, we have to kick 261 * out the entry in the last slot to make room. 262 */ 263static int yp_cache_db(dbp, name, size) 264 DB *dbp; --- 17 unchanged lines hidden (view full) --- 282 return(1); 283 } 284 285 qptr->dbptr->dbp = dbp; 286 qptr->dbptr->name = strdup(name); 287 qptr->dbptr->size = size; 288 qptr->dbptr->key = NULL; 289 |
290 qptr->dbptr->flags = yp_setflags(dbp); 291 |
|
230 CIRCLEQ_INSERT_HEAD(&qhead, qptr, links); 231 numdbs++; 232 233 return(0); 234} 235 236/* 237 * Search the list for a database matching 'name.' If we find it, --- 360 unchanged lines hidden --- | 292 CIRCLEQ_INSERT_HEAD(&qhead, qptr, links); 293 numdbs++; 294 295 return(0); 296} 297 298/* 299 * Search the list for a database matching 'name.' If we find it, --- 360 unchanged lines hidden --- |