]> git.saurik.com Git - apple/network_cmds.git/blob - ypserv.tproj/ypserv_db.c
055b904605bc9d524912eb989a5b2236e1b62f75
[apple/network_cmds.git] / ypserv.tproj / ypserv_db.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* $OpenBSD: ypserv_db.c,v 1.13 1997/08/09 23:10:12 maja Exp $ */
24
25 /*
26 * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
27 * Copyright (c) 1996 Charles D. Cranor
28 * All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by Mats O Jansson
41 * and Charles D. Cranor.
42 * 4. The name of the author may not be used to endorse or promote products
43 * derived from this software without specific prior written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
46 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
49 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 */
57
58 #ifndef LINT
59 static char rcsid[] = "$OpenBSD: ypserv_db.c,v 1.13 1997/08/09 23:10:12 maja Exp $";
60 #endif
61
62 /*
63 * major revision/cleanup of Mats' version
64 * done by Chuck Cranor <chuck@ccrc.wustl.edu>
65 * Jan 1996.
66 */
67
68
69 #include <rpc/rpc.h>
70 #include <rpcsvc/yp.h>
71 #include <rpcsvc/ypclnt.h>
72 #include <sys/stat.h>
73 #include <sys/param.h>
74 #include <fcntl.h>
75 #include <string.h>
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <netdb.h>
79 #include <arpa/nameser.h>
80 #include <resolv.h>
81 #include <sys/types.h>
82 #include <sys/socket.h>
83 #include <sys/queue.h>
84 #include <netinet/in.h>
85 #include <arpa/inet.h>
86 #include <syslog.h>
87 #include <sys/errno.h>
88 #include "yplog.h"
89 #include "ypdb.h"
90 #include "ypdef.h"
91
92 LIST_HEAD(domainlist, opt_domain); /* LIST of domains */
93 LIST_HEAD(maplist, opt_map); /* LIST of maps (in a domain) */
94 CIRCLEQ_HEAD(mapq, opt_map); /* CIRCLEQ of maps (LRU) */
95
96 struct opt_map {
97 mapname map; /* map name (malloc'd) */
98 DBM *db; /* database */
99 struct opt_domain *dom; /* back ptr to our domain */
100 int host_lookup; /* host lookup */
101 int secure; /* secure map? */
102 CIRCLEQ_ENTRY(opt_map) mapsq; /* map queue pointers */
103 LIST_ENTRY(opt_map) mapsl; /* map list pointers */
104 };
105
106 struct opt_domain {
107 domainname domain; /* domain name (malloc'd) */
108 struct maplist dmaps; /* the domain's active maps */
109 LIST_ENTRY(opt_domain) domsl; /* global linked list of domains */
110 };
111
112
113 struct domainlist doms; /* global list of domains */
114 struct mapq maps; /* global queue of maps (LRU) */
115
116 extern int usedns;
117
118 /*
119 * ypdb_init: init the queues and lists
120 */
121
122 void
123 ypdb_init()
124
125 {
126 LIST_INIT(&doms);
127 CIRCLEQ_INIT(&maps);
128 }
129
130
131 /*
132 * yp_private:
133 * Check if key is a YP private key. Return TRUE if it is and
134 * ypprivate is FALSE.
135 */
136
137 int
138 yp_private(key,ypprivate)
139 datum key;
140 int ypprivate;
141 {
142 /* int result; */
143
144 if (ypprivate)
145 return (FALSE);
146
147 if (key.dsize == 0 || key.dptr == NULL)
148 return (FALSE);
149
150 if (key.dsize == YP_LAST_LEN &&
151 strncmp(key.dptr,YP_LAST_KEY,YP_LAST_LEN) == 0)
152 return(TRUE);
153 if (key.dsize == YP_INPUT_LEN &&
154 strncmp(key.dptr,YP_INPUT_KEY,YP_INPUT_LEN) == 0)
155 return(TRUE);
156 if (key.dsize == YP_OUTPUT_LEN &&
157 strncmp(key.dptr,YP_OUTPUT_KEY,YP_OUTPUT_LEN) == 0)
158 return(TRUE);
159 if (key.dsize == YP_MASTER_LEN &&
160 strncmp(key.dptr,YP_MASTER_KEY,YP_MASTER_LEN) == 0)
161 return(TRUE);
162 if (key.dsize == YP_DOMAIN_LEN &&
163 strncmp(key.dptr,YP_DOMAIN_KEY,YP_DOMAIN_LEN) == 0)
164 return(TRUE);
165 if (key.dsize == YP_INTERDOMAIN_LEN &&
166 strncmp(key.dptr,YP_INTERDOMAIN_KEY,YP_INTERDOMAIN_LEN) == 0)
167 return(TRUE);
168 if (key.dsize == YP_SECURE_LEN &&
169 strncmp(key.dptr,YP_SECURE_KEY,YP_SECURE_LEN) == 0)
170 return(TRUE);
171
172 return(FALSE);
173 }
174
175 /*
176 * Close least recent used map. This routine is called when we have
177 * no more file descripotors free, or we want to close all maps.
178 */
179
180 void
181 ypdb_close_last()
182 {
183 struct opt_map *last = maps.cqh_last;
184
185 if (last == (void*)&maps) {
186 yplog(" ypdb_close_last: LRU list is empty!");
187 return;
188 }
189
190 CIRCLEQ_REMOVE(&maps, last, mapsq); /* remove from LRU circleq */
191 LIST_REMOVE(last, mapsl); /* remove from domain list */
192
193 #ifdef DEBUG
194 yplog(" ypdb_close_last: closing map %s in domain %s [db=0x%x]",
195 last->map, last->dom->domain, last->db);
196 #endif
197
198 ypdb_close(last->db); /* close DB */
199 free(last->map); /* free map name */
200 free(last); /* free map */
201
202
203 }
204
205 /*
206 * Close all open maps.
207 */
208
209 void
210 ypdb_close_all()
211 {
212
213 #ifdef DEBUG
214 yplog(" ypdb_close_all(): start");
215 #endif
216 while (maps.cqh_first != (void *)&maps) {
217 ypdb_close_last();
218 }
219 #ifdef DEBUG
220 yplog(" ypdb_close_all(): done");
221 #endif
222 }
223
224 /*
225 * Close Database if Open/Close Optimization isn't turned on.
226 */
227
228 void
229 ypdb_close_db(db)
230 DBM *db;
231 {
232 #ifdef DEBUG
233 yplog(" ypdb_close_db(0x%x)", db);
234 #endif
235 #ifndef OPTDB
236 ypdb_close_all();
237 #endif
238 }
239
240 /*
241 * ypdb_open_db
242 */
243
244 DBM *
245 ypdb_open_db(domain, map, status, map_info)
246 domainname domain;
247 mapname map;
248 ypstat *status;
249 struct opt_map **map_info;
250 {
251 char map_path[MAXPATHLEN];
252 static char *domain_key = YP_INTERDOMAIN_KEY;
253 static char *secure_key = YP_SECURE_KEY;
254 /* struct stat finfo; */
255 DBM *db;
256 /* int fd; */
257 struct opt_domain *d = NULL;
258 struct opt_map *m = NULL;
259 datum k,v;
260 #ifdef OPTDB
261 int i;
262 #endif
263 /*
264 * check for preloaded domain, map
265 */
266
267 for (d = doms.lh_first ; d != NULL ; d = d->domsl.le_next) {
268 if (strcmp(domain, d->domain) == 0) break;
269 }
270
271 if (d) {
272 for (m = d->dmaps.lh_first ; m != NULL ; m = m->mapsl.le_next)
273 if (strcmp(map, m->map) == 0) break;
274 }
275
276 /*
277 * map found open?
278 */
279
280 if (m) {
281 #ifdef DEBUG
282 yplog(" ypdb_open_db: cached open: domain=%s, map=%s, db=0x%x",
283 domain, map, m->db);
284 #endif
285 CIRCLEQ_REMOVE(&maps, m, mapsq); /* adjust LRU queue */
286 CIRCLEQ_INSERT_HEAD(&maps, m, mapsq);
287 *status = YP_TRUE;
288 return(m->db);
289 }
290
291 /* Check for illegal charcaters */
292
293 if (strchr(domain, '/')) {
294 *status = YP_NODOM;
295 return (NULL);
296 }
297 if (strchr(map, '/')) {
298 *status = YP_NOMAP;
299 return (NULL);
300 }
301
302
303 /*
304 * open map
305 */
306 #ifdef OPTDB
307 i = 0;
308 while (i == 0) {
309 #endif
310 snprintf(map_path, sizeof(map_path), "%s/%s/%s", YP_DB_PATH,
311 domain, map);
312 db = ypdb_open(map_path, O_RDONLY, 0444);
313 #ifdef OPTDB
314 if (db == NULL) {
315 #ifdef DEBUG
316 yplog(" ypdb_open_db: errno %d (%s)",
317 errno,sys_errlist[errno]);
318 #endif
319 if ((errno == ENFILE) || (errno == EMFILE)) {
320 ypdb_close_last();
321 } else {
322 i = errno;
323 }
324 } else {
325 i = 4711;
326 }
327 };
328 #endif
329 *status = YP_NOMAP; /* see note below */
330 if (db == NULL) {
331 if (errno == ENOENT) {
332 #ifdef DEBUG
333 yplog(" ypdb_open_db: no map %s (domain=%s)",
334 map, domain);
335 #endif
336 return(NULL);
337 }
338 #ifdef DEBUG
339 yplog(" ypdb_open_db: ypdb_open FAILED: map %s (domain=%s)",
340 map, domain);
341 #endif
342 return(NULL);
343 }
344
345 /*
346 * note: status now YP_NOMAP
347 */
348
349 if (d == NULL) { /* allocate new domain? */
350 d = (struct opt_domain *) malloc(sizeof(*d));
351 if (d) d->domain = strdup(domain);
352 if (d == NULL || d->domain == NULL) {
353 yplog(" ypdb_open_db: MALLOC failed");
354 ypdb_close(db);
355 if (d) free(d);
356 return(NULL);
357 }
358 LIST_INIT(&d->dmaps);
359 LIST_INSERT_HEAD(&doms, d, domsl);
360 #ifdef DEBUG
361 yplog(" ypdb_open_db: NEW DOMAIN %s", domain);
362 #endif
363 }
364
365 /*
366 * m must be NULL since we couldn't find a map. allocate new one
367 */
368
369 m = (struct opt_map *) malloc(sizeof(*m));
370 if (m) {
371 m->map = strdup(map);
372 }
373 if (m == NULL || m->map == NULL) {
374 if (m) free(m);
375 yplog(" ypdb_open_db: MALLOC failed");
376 ypdb_close(db);
377 return(NULL);
378 }
379 m->db = db;
380 m->dom = d;
381 m->host_lookup = FALSE;
382 CIRCLEQ_INSERT_HEAD(&maps, m, mapsq);
383 LIST_INSERT_HEAD(&d->dmaps, m, mapsl);
384 if (strcmp(map, YP_HOSTNAME) == 0 || strcmp(map, YP_HOSTADDR) == 0) {
385 if (!usedns) {
386 k.dptr = domain_key;
387 k.dsize = YP_INTERDOMAIN_LEN;
388 v = ypdb_fetch(db,k);
389 if (v.dptr) m->host_lookup = TRUE;
390 } else {
391 m->host_lookup = TRUE;
392 }
393 }
394 m->secure = FALSE;
395 k.dptr = secure_key;
396 k.dsize = YP_SECURE_LEN;
397 v = ypdb_fetch(db,k);
398 if (v.dptr) m->secure = TRUE;
399 *status = YP_TRUE;
400 if (map_info) *map_info = m;
401 #ifdef DEBUG
402 yplog(" ypdb_open_db: NEW MAP domain=%s, map=%s, hl=%d, s=%d, db=0x%x",
403 domain, map, m->host_lookup, m->secure, m->db);
404 #endif
405 return(m->db);
406 }
407
408 #if 0
409 /*
410 * lookup host. Not needed for Rhapsody, lookupd does this stuff.
411 */
412
413 ypstat
414 lookup_host(nametable, host_lookup, db, keystr, result)
415 int nametable;
416 int host_lookup;
417 DBM *db;
418 char *keystr;
419 ypresp_val *result;
420 {
421 struct hostent *host;
422 struct in_addr *addr_name;
423 struct in_addr addr_addr;
424 static char val[BUFSIZ+1]; /* match libc */
425 static hostname[MAXHOSTNAMELEN];
426 char tmpbuf[MAXHOSTNAMELEN + 20];
427 char *v;
428 int l;
429 char *ptr;
430
431 if (!host_lookup) return(YP_NOKEY);
432
433 if ((_res.options & RES_INIT) == 0)
434 res_init();
435 bcopy("b", _res.lookups, sizeof("b"));
436
437 if (nametable) {
438 host = gethostbyname(keystr);
439 if (host == NULL || host->h_addrtype != AF_INET)
440 return(YP_NOKEY);
441 addr_name = (struct in_addr *) *host->h_addr_list;
442 v = val;
443 for (; host->h_addr_list[0] != NULL; host->h_addr_list++) {
444 addr_name = (struct in_addr *)host->h_addr_list[0];
445 snprintf(tmpbuf,sizeof(tmpbuf), "%s %s\n",
446 inet_ntoa(*addr_name), host->h_name);
447 if (v - val + strlen(tmpbuf) + 1 > sizeof(val))
448 break;
449 strcpy(v, tmpbuf);
450 v = v + strlen(tmpbuf);
451 }
452 result->val.valdat_val = val;
453 result->val.valdat_len = v - val;
454 return(YP_TRUE);
455 }
456
457 inet_aton(keystr, &addr_addr);
458 host = gethostbyaddr((char *) &addr_addr, sizeof(addr_addr), AF_INET);
459 if (host == NULL) return(YP_NOKEY);
460
461 strncpy((char *)hostname, host->h_name, sizeof(hostname) - 1);
462 hostname[sizeof(hostname) - 1] = '\0';
463 host = gethostbyname((char *)hostname);
464 if (host == NULL) return(YP_NOKEY);
465
466 l = 0;
467 for(; host->h_addr_list[0] != NULL; host->h_addr_list++)
468 if (!bcmp(host->h_addr_list[0], &addr_addr, sizeof(addr_addr)))
469 l++;
470 if (l == 0) {
471 yplog("lookup_host: address %s not listed for host %s\n",
472 inet_ntoa(addr_addr), hostname);
473 syslog(LOG_NOTICE,
474 "ypserv: address %s not listed for host %s\n",
475 inet_ntoa(addr_addr), hostname);
476 return(YP_NOKEY);
477 }
478
479 snprintf(val,sizeof(val),"%s %s",keystr,host->h_name);
480 l = strlen(val);
481 v = val + l;
482 while ((ptr = *(host->h_aliases)) != NULL) {
483 l = strlen(ptr);
484 if ((v - val) + l + 1 > BUFSIZ)
485 break;
486 strcpy(v, " ");
487 v += 1;
488 strcpy(v, ptr);
489 v += l;
490 host->h_aliases++;
491 }
492 result->val.valdat_val = val;
493 result->val.valdat_len = v - val;
494
495 return(YP_TRUE);
496 }
497 #endif
498
499 ypresp_val
500 ypdb_get_record(domain, map, key, ypprivate)
501 domainname domain;
502 mapname map;
503 keydat key;
504 int ypprivate;
505 {
506 static ypresp_val res;
507 /* static char keystr[YPMAXRECORD+1]; */
508 DBM *db;
509 datum k,v;
510 int host_lookup;
511 struct opt_map *map_info = NULL;
512
513 bzero((char *)&res, sizeof(res));
514
515 db = ypdb_open_db(domain, map, &res.stat, &map_info);
516 if (!db || res.stat < 0)
517 return(res);
518 if (map_info)
519 host_lookup = map_info->host_lookup;
520
521 k.dptr = key.keydat_val;
522 k.dsize = key.keydat_len;
523
524 if (yp_private(k,ypprivate)) {
525 res.stat = YP_NOKEY;
526 goto done;
527 }
528
529 v = ypdb_fetch(db, k);
530
531 /* lookupd does DNS resolution, not ypserv. */
532 if (v.dptr == NULL) {
533 res.stat = YP_NOKEY;
534 res.val.valdat_val = NULL;
535 res.val.valdat_len = 0;
536 } else {
537 res.val.valdat_val = v.dptr;
538 res.val.valdat_len = v.dsize;
539 }
540
541 done:
542 ypdb_close_db(db);
543 return(res);
544
545 }
546
547 ypresp_key_val
548 ypdb_get_first(domain, map, ypprivate)
549 domainname domain;
550 mapname map;
551 int ypprivate;
552 {
553 static ypresp_key_val res;
554 DBM *db;
555 datum k,v;
556
557 bzero((char *)&res, sizeof(res));
558
559 db = ypdb_open_db(domain, map, &res.stat, NULL);
560
561 if (res.stat >= 0) {
562
563 k = ypdb_firstkey(db);
564
565 while (yp_private(k,ypprivate)) {
566 k = ypdb_nextkey(db);
567 };
568
569 if (k.dptr == NULL) {
570 res.stat = YP_NOKEY;
571 } else {
572 res.key.keydat_val = k.dptr;
573 res.key.keydat_len = k.dsize;
574 v = ypdb_fetch(db,k);
575 if (v.dptr == NULL) {
576 res.stat = YP_NOKEY;
577 } else {
578 res.val.valdat_val = v.dptr;
579 res.val.valdat_len = v.dsize;
580 }
581 }
582 }
583
584 ypdb_close_db(db);
585
586 return (res);
587 }
588
589 ypresp_key_val
590 ypdb_get_next(domain, map, key, ypprivate)
591 domainname domain;
592 mapname map;
593 keydat key;
594 int ypprivate;
595 {
596 static ypresp_key_val res;
597 DBM *db;
598 datum k,v,n;
599
600 bzero((char *)&res, sizeof(res));
601
602 db = ypdb_open_db(domain, map, &res.stat, NULL);
603
604 if (res.stat >= 0) {
605
606 n.dptr = key.keydat_val;
607 n.dsize = key.keydat_len;
608 v.dptr = NULL;
609 v.dsize = 0;
610 k.dptr = NULL;
611 k.dsize = 0;
612
613 n = ypdb_setkey(db,n);
614
615 if (n.dptr != NULL) {
616 k = ypdb_nextkey(db);
617 } else {
618 k.dptr = NULL;
619 };
620
621 if (k.dptr != NULL) {
622 while (yp_private(k,ypprivate)) {
623 k = ypdb_nextkey(db);
624 };
625 };
626
627 if (k.dptr == NULL) {
628 res.stat = YP_NOMORE;
629 } else {
630 res.key.keydat_val = k.dptr;
631 res.key.keydat_len = k.dsize;
632 v = ypdb_fetch(db,k);
633 if (v.dptr == NULL) {
634 res.stat = YP_NOMORE;
635 } else {
636 res.val.valdat_val = v.dptr;
637 res.val.valdat_len = v.dsize;
638 }
639 }
640 }
641
642 ypdb_close_db(db);
643
644 return (res);
645 }
646
647 ypresp_order
648 ypdb_get_order(domain, map)
649 domainname domain;
650 mapname map;
651 {
652 static ypresp_order res;
653 static char *order_key = YP_LAST_KEY;
654 char order[MAX_LAST_LEN+1];
655 DBM *db;
656 datum k,v;
657
658 bzero((char *)&res, sizeof(res));
659
660 db = ypdb_open_db(domain, map, &res.stat, NULL);
661
662 if (res.stat >= 0) {
663
664 k.dptr = order_key;
665 k.dsize = YP_LAST_LEN;
666
667 v = ypdb_fetch(db,k);
668 if (v.dptr == NULL) {
669 res.stat = YP_NOKEY;
670 } else {
671 strncpy(order, v.dptr, v.dsize);
672 order[v.dsize] = '\0';
673 res.ordernum = (u_int32_t)atol(order);
674 }
675 }
676
677 ypdb_close_db(db);
678
679 return (res);
680 }
681
682 ypresp_master
683 ypdb_get_master(domain, map)
684 domainname domain;
685 mapname map;
686 {
687 static ypresp_master res;
688 static char *master_key = YP_MASTER_KEY;
689 static char master[MAX_MASTER_LEN+1];
690 DBM *db;
691 datum k,v;
692
693 bzero((char *)&res, sizeof(res));
694
695 db = ypdb_open_db(domain, map, &res.stat, NULL);
696
697 if (res.stat >= 0) {
698
699 k.dptr = master_key;
700 k.dsize = YP_MASTER_LEN;
701
702 v = ypdb_fetch(db,k);
703 if (v.dptr == NULL) {
704 res.stat = YP_NOKEY;
705 } else {
706 strncpy(master, v.dptr, v.dsize);
707 master[v.dsize] = '\0';
708 res.peer = (peername) &master;
709 }
710 }
711
712 ypdb_close_db(db);
713
714 return (res);
715 }
716
717 bool_t
718 ypdb_xdr_get_all(xdrs, req)
719 XDR *xdrs;
720 ypreq_nokey *req;
721 {
722 static ypresp_all resp;
723 DBM *db;
724 datum k,v;
725
726 bzero((char *)&resp, sizeof(resp));
727
728 /*
729 * open db, and advance past any private keys we may see
730 */
731
732 db = ypdb_open_db(req->domain, req->map,
733 &resp.ypresp_all_u.val.stat, NULL);
734 if (!db || resp.ypresp_all_u.val.stat < 0)
735 return(FALSE);
736 k = ypdb_firstkey(db);
737 while (yp_private(k,FALSE)) {
738 k = ypdb_nextkey(db);
739 };
740
741 while(1) {
742
743 if (k.dptr == NULL)
744 break;
745
746 v = ypdb_fetch(db,k);
747
748 if (v.dptr == NULL)
749 break;
750
751 resp.more = TRUE;
752 resp.ypresp_all_u.val.stat = YP_TRUE;
753 resp.ypresp_all_u.val.key.keydat_val = k.dptr;
754 resp.ypresp_all_u.val.key.keydat_len = k.dsize;
755 resp.ypresp_all_u.val.val.valdat_val = v.dptr;
756 resp.ypresp_all_u.val.val.valdat_len = v.dsize;
757
758 if (!xdr_ypresp_all(xdrs, &resp)) {
759 #ifdef DEBUG
760 yplog(" ypdb_xdr_get_all: xdr_ypresp_all failed");
761 #endif
762 return(FALSE);
763 }
764
765 /* advance past private keys */
766 k = ypdb_nextkey(db);
767 while (yp_private(k,FALSE)) {
768 k = ypdb_nextkey(db);
769 }
770 }
771
772 bzero((char *)&resp, sizeof(resp));
773 resp.ypresp_all_u.val.stat = YP_NOKEY;
774 resp.more = FALSE;
775
776 if (!xdr_ypresp_all(xdrs, &resp)) {
777 #ifdef DEBUG
778 yplog(" ypdb_xdr_get_all: final xdr_ypresp_all failed");
779 #endif
780 return(FALSE);
781 }
782
783 ypdb_close_db(db);
784
785 return (TRUE);
786 }
787
788 int
789 ypdb_secure(domain, map)
790 domainname domain;
791 mapname map;
792 {
793 static ypresp_val res;
794 DBM *db;
795 int secure;
796 struct opt_map *map_info = NULL;
797
798 bzero((char *)&res, sizeof(res));
799 secure = FALSE;
800
801 db = ypdb_open_db(domain, map, &res.stat, &map_info);
802 if (!db || res.stat < 0)
803 return(secure); /* ? */
804 if (map_info)
805 secure = map_info->secure;
806
807 ypdb_close_db(db);
808 return(secure);
809 }
810