4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #include <netconfig.h>
34 #include <sys/param.h>
37 #include <rpcsvc/yp_prot.h>
38 #include <rpcsvc/nis.h>
41 #include <sys/isa_defs.h> /* for ENDIAN defines */
43 #if defined(_LITTLE_ENDIAN)
47 static struct timeval TIMEOUT
= {25, 0};
50 extern bool secure_map
;
51 extern void logprintf(char *, ...);
53 /* delete the dbm file with name file */
58 char pag1
[MAXPATHLEN
];
59 char dir1
[MAXPATHLEN
];
66 if (unlink(pag1
) < 0) {
71 if (unlink(dir1
) < 0) {
78 /* xdr just the .pag file of a dbm file */
83 static struct pag res
;
95 if (!xdr_pag(xdrs
, &res
))
99 if (PAG
->status
== OK
) {
101 s
= (short *)PAG
->pag_u
.ok
.blkdat
;
103 for (i
= 1; i
<= s
[0]; i
++)
107 where
= (((off64_t
)PAG
->pag_u
.ok
.blkno
) * PBLKSIZ
);
108 (void) lseek64(db
->dbm_pagf
, where
, L_SET
);
113 if (write(db
->dbm_pagf
,
114 PAG
->pag_u
.ok
.blkdat
, PBLKSIZ
) < 0) {
118 } else if (PAG
->status
== GETDBM_ERROR
) {
119 (void) printf("clnt call getpag GETDBM_ERROR\n");
121 } else if (PAG
->status
== GETDBM_EOF
)
123 if (!xdr_bool(xdrs
, &more
))
127 if (!xdr_pag(xdrs
, &res
))
133 /* xdr just the .dir part of a dbm file */
138 static struct dir res
;
146 if (!xdr_dir(xdrs
, &res
))
150 if (DIR->status
== OK
) {
152 where
= (((off64_t
)DIR->dir_u
.ok
.blkno
) * DBLKSIZ
);
153 (void) lseek64(db
->dbm_dirf
, where
, L_SET
);
158 if (write(db
->dbm_dirf
,
159 DIR->dir_u
.ok
.blkdat
, DBLKSIZ
) < 0) {
163 } else if (DIR->status
== GETDBM_ERROR
) {
164 (void) printf("clnt call getdir GETDBM_ERROR\n");
166 } else if (DIR->status
== GETDBM_EOF
)
168 if (!xdr_bool(xdrs
, &more
))
172 if (!xdr_dir(xdrs
, &res
))
180 * xdr a dbm file from ypxfrd
181 * note that if the client or server do not support ndbm
182 * we may not use this optional protocol
186 xdr_myfyl(xdrs
, objp
)
190 if (!xdr_answer(xdrs
, (answer
*)objp
))
196 if (!xdr_pages(xdrs
))
206 ypxfrd_getdbm(tempmap
, master
, domain
, map
)
215 int recvsiz
= 24 * 1024;
216 struct netconfig
*nconf
;
218 struct netbuf
*svcaddr
;
219 struct t_bind
*tbind
;
220 char *netid
[] = { "tcp6", "tcp" };
221 int i
, lastnetid
= (sizeof (netid
)/sizeof (netid
[0])) - 1;
223 for (i
= 0; i
<= lastnetid
; i
++) {
224 if ((nconf
= getnetconfigent(netid
[i
])) == NULL
) {
227 logprintf("ypxfr: tcp transport not supported\n");
230 if ((fd
= t_open(nconf
->nc_device
, O_RDWR
, NULL
)) == -1) {
231 freenetconfigent(nconf
);
234 logprintf("ypxfr: TLI problems\n");
237 if (secure_map
== TRUE
) {
238 if (netdir_options(nconf
, ND_SET_RESERVEDPORT
, fd
,
241 freenetconfigent(nconf
);
245 "ypxfr: cannot bind to reserved port for %s\n%s\n",
246 netid
[i
], netdir_sperror());
251 /* LINTED pointer alignment */
252 if ((tbind
= (struct t_bind
*)t_alloc(fd
, T_BIND
, T_ADDR
)) ==
255 freenetconfigent(nconf
);
258 logprintf("ypxfr: TLI problems\n");
261 svcaddr
= &(tbind
->addr
);
262 if (rpcb_getaddr(YPXFRD
, 1, nconf
, svcaddr
, master
)
264 (void) t_free((char *)tbind
, T_BIND
);
266 freenetconfigent(nconf
);
269 logprintf("ypxfr: couldnot get %s address\n", master
);
272 if ((clnt
= __nis_clnt_create(fd
, nconf
, 0, svcaddr
, 0,
273 YPXFRD
, 1, recvsiz
, 0)) == 0) {
274 (void) t_free((char *)tbind
, T_BIND
);
276 freenetconfigent(nconf
);
280 "ypxfr (get_map) - TCP channel create failure");
283 (void) t_free((char *)tbind
, T_BIND
);
286 (void) CLNT_CONTROL(clnt
, CLSET_FD_CLOSE
, (char *)NULL
);
289 rmap
.domain
= domain
;
290 (void) memset((char *)&res
, 0, sizeof (res
));
291 db
= dbm_open(tempmap
, O_RDWR
+ O_CREAT
+ O_TRUNC
, 0777);
293 logprintf("dbm_open failed %s\n", tempmap
);
298 if (clnt_call(clnt
, getdbm
, xdr_hosereq
, (char *)&rmap
, xdr_myfyl
,
299 (char *)&res
, TIMEOUT
) != RPC_SUCCESS
) {
300 logprintf("clnt call to ypxfrd getdbm failed.\n");
301 clnt_perror(clnt
, "getdbm");
302 (void) dbm_deletefile(tempmap
);
306 logprintf("clnt call %s ypxfrd getdbm NOTOK %s %s code=%d\n",
307 master
, domain
, map
, res
);
308 (void) dbm_deletefile(tempmap
);