Deleted Added
sdiff udiff text old ( 258564 ) new ( 293229 )
full compact
1/* $NetBSD: check_bound.c,v 1.2 2000/06/22 08:09:26 fvdl Exp $ */
2/* $FreeBSD: head/usr.sbin/rpcbind/check_bound.c 293229 2016-01-06 00:00:11Z asomers $ */
3
4/*-
5 * Copyright (c) 2009, Sun Microsystems, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * - Redistributions of source code must retain the above copyright notice,

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

45 * Checks to see whether the program is still bound to the
46 * claimed address and returns the universal merged address
47 *
48 */
49
50#include <sys/types.h>
51#include <sys/socket.h>
52#include <rpc/rpc.h>
53#include <rpc/svc_dg.h>
54#include <stdio.h>
55#include <netconfig.h>
56#include <syslog.h>
57#include <string.h>
58#include <unistd.h>
59#include <stdlib.h>
60
61#include "rpcbind.h"

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

155 * Returns NULL if there was some system error.
156 * Returns "" if the address was not bound, i.e the server crashed.
157 * Returns the merged address otherwise.
158 */
159char *
160mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr)
161{
162 struct fdlist *fdl;
163 struct svc_dg_data *dg_data;
164 char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL;
165
166 for (fdl = fdhead; fdl; fdl = fdl->next)
167 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
168 break;
169 if (fdl == NULL)
170 return (NULL);
171 if (check_bound(fdl, uaddr) == FALSE)
172 /* that server died */
173 return (nullstring);
174 /*
175 * Try to determine the local address on which the client contacted us,
176 * so we can send a reply from the same address. If it's unknown, then
177 * try to determine which address the client used, and pick a nearby
178 * local address.
179 *
180 * If saddr is not NULL, the remote client may have included the
181 * address by which it contacted us. Use that for the "client" uaddr,
182 * otherwise use the info from the SVCXPRT.
183 */
184 dg_data = (struct svc_dg_data*)xprt->xp_p2;
185 if (dg_data != NULL && dg_data->su_srcaddr.buf != NULL) {
186 c_uaddr = taddr2uaddr(fdl->nconf, &dg_data->su_srcaddr);
187 }
188 else if (saddr != NULL) {
189 c_uaddr = saddr;
190 } else {
191 c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt));
192 if (c_uaddr == NULL) {
193 syslog(LOG_ERR, "taddr2uaddr failed for %s",
194 fdl->nconf->nc_netid);
195 return (NULL);
196 }

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

223 return (m_uaddr);
224}
225
226/*
227 * Returns a netconf structure from its internal list. This
228 * structure should not be freed.
229 */
230struct netconfig *
231rpcbind_get_conf(const char *netid)
232{
233 struct fdlist *fdl;
234
235 for (fdl = fdhead; fdl; fdl = fdl->next)
236 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
237 break;
238 if (fdl == NULL)
239 return (NULL);
240 return (fdl->nconf);
241}