4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
44 /* Use N2L version of DBM calls */
45 #include "shim_hooks.h"
55 static DBM
*cur_fdb
; /* will be passwd back up by ypset_current_map */
56 static enum { UNKNOWN
, SECURE
, PUBLIC
} current_map_access
= UNKNOWN
;
57 static char map_owner
[MAX_MASTER_NAME
+ 1];
59 extern unsigned int ypcheck_domain();
60 int check_secure_net_ti(struct netbuf
*caller
, char *ypname
);
63 * The retrieves the order number of a named map from the order number datum
64 * in the map data base.
67 ypget_map_order(char *map
, char *domain
, uint_t
*order
)
71 char toconvert
[MAX_ASCII_ORDER_NUMBER_LENGTH
+ 1];
75 if ((fdb
= ypset_current_map(map
, domain
, &error
)) != NULL
) {
76 key
.dptr
= yp_last_modified
;
77 key
.dsize
= yp_last_modified_sz
;
78 val
= dbm_fetch(fdb
, key
);
80 if (val
.dptr
!= NULL
) {
82 if (val
.dsize
> MAX_ASCII_ORDER_NUMBER_LENGTH
) {
87 * This is getting recopied here because val.dptr
88 * points to static memory owned by the dbm package,
89 * and we have no idea whether numeric characters
90 * follow the order number characters, nor whether
91 * the mess is null-terminated at all.
94 memcpy(toconvert
, val
.dptr
, val
.dsize
);
95 toconvert
[val
.dsize
] = '\0';
96 *order
= (unsigned long) atol(toconvert
);
108 * The retrieves the master server name of a named map from the master datum
109 * in the map data base.
112 ypget_map_master(char **owner
, DBM
*fdb
)
117 key
.dptr
= yp_master_name
;
118 key
.dsize
= yp_master_name_sz
;
119 val
= dbm_fetch(fdb
, key
);
121 if (val
.dptr
!= NULL
) {
123 if (val
.dsize
> MAX_MASTER_NAME
) {
128 * This is getting recopied here because val.dptr
129 * points to static memory owned by the dbm package.
131 memcpy(map_owner
, val
.dptr
, val
.dsize
);
132 map_owner
[val
.dsize
] = '\0';
141 * This makes a map into the current map, and calls dbminit on that map
142 * and returns the DBM pointer to the map. Procedures called by
143 * ypserv dispatch routine would use this pointer for successive
144 * ndbm operations. Returns an YP_xxxx error code in error if FALSE.
147 ypset_current_map(char *map
, char *domain
, uint_t
*error
)
149 char mapname
[MAXNAMLEN
+ 1];
152 /* Do not allow any path as a domain name or a map name. */
153 if (!map
|| ((lenm
= (int)strlen(map
)) == 0) || (lenm
> YPMAXMAP
) ||
154 !domain
|| ((lend
= (int)strlen(domain
)) == 0) ||
155 (lend
> YPMAXDOMAIN
) || (strchr(map
, '/') != NULL
) ||
156 (strchr(domain
, '/') != NULL
)) {
161 if (FALSE
== ypmkfilename(domain
, map
, mapname
))
164 if ((cur_fdb
) && (strcmp(mapname
, get_map_name(cur_fdb
)) == 0)) {
168 /* If there was a previous open map close it */
172 /* Set the map access as "unknown" as the new map has not been loaded */
173 current_map_access
= UNKNOWN
;
175 /* All the map locking is now handled inside the dbm_open shim */
176 if ((cur_fdb
= dbm_open(mapname
, O_RDWR
, 0644)) != NULL
) {
180 if (ypcheck_domain(domain
)) {
182 if (ypcheck_map_existence(mapname
)) {
196 * This checks to see if there is a current map, and, if there is, does a
197 * dbmclose on it and sets the current map name and its DBM ptr to null.
200 ypclr_current_map(void)
202 if (cur_fdb
!= NULL
) {
203 (void) dbm_close(cur_fdb
);
206 current_map_access
= UNKNOWN
;
210 * Checks to see if caller has permission to query the current map (as
211 * set by ypset_current_map()). Returns TRUE if access is granted and
212 * FALSE otherwise. If FALSE then sets *error to YP_xxxxxxxx.
215 yp_map_access(SVCXPRT
*transp
, uint_t
*error
, DBM
*fdb
)
217 char *ypname
= "ypserv";
222 nbuf
= svc_getrpccaller(transp
);
223 af
= ((struct sockaddr_storage
*)nbuf
->buf
)->ss_family
;
224 if (af
!= AF_INET
&& af
!= AF_INET6
)
227 if (!(check_secure_net_ti(nbuf
, ypname
))) {
232 /* XXX - I expect that this won't happen much */
233 if (current_map_access
== PUBLIC
) {
237 if (af
== AF_INET6
) {
238 port
= ntohs(((struct sockaddr_in6
*)nbuf
->buf
)->sin6_port
);
240 port
= ntohs(((struct sockaddr_in
*)nbuf
->buf
)->sin_port
);
242 if (port
< IPPORT_RESERVED
) {
246 if (current_map_access
== UNKNOWN
) {
250 key
.dptr
= yp_secure
;
251 key
.dsize
= yp_secure_sz
;
252 val
= dbm_fetch(fdb
, key
);
253 if (val
.dptr
== NULL
) {
254 current_map_access
= PUBLIC
;
257 current_map_access
= SECURE
;
260 /* current_map_access == SECURE and non-priviledged caller */