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 258564 2013-11-25 16:44:02Z hrs $ */
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 <stdio.h>
54#include <netconfig.h>
55#include <syslog.h>
56#include <string.h>
57#include <unistd.h>
58#include <stdlib.h>
59
60#include "rpcbind.h"
--- 93 unchanged lines hidden (view full) ---
154 * Returns NULL if there was some system error.
155 * Returns "" if the address was not bound, i.e the server crashed.
156 * Returns the merged address otherwise.
157 */
158char *
159mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr)
160{
161 struct fdlist *fdl;
162 char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL;
163
164 for (fdl = fdhead; fdl; fdl = fdl->next)
165 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
166 break;
167 if (fdl == NULL)
168 return (NULL);
169 if (check_bound(fdl, uaddr) == FALSE)
170 /* that server died */
171 return (nullstring);
172 /*
173 * If saddr is not NULL, the remote client may have included the
174 * address by which it contacted us. Use that for the "client" uaddr,
175 * otherwise use the info from the SVCXPRT.
176 */
177 if (saddr != NULL) {
178 c_uaddr = saddr;
179 } else {
180 c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt));
181 if (c_uaddr == NULL) {
182 syslog(LOG_ERR, "taddr2uaddr failed for %s",
183 fdl->nconf->nc_netid);
184 return (NULL);
185 }
--- 26 unchanged lines hidden (view full) ---
212 return (m_uaddr);
213}
214
215/*
216 * Returns a netconf structure from its internal list. This
217 * structure should not be freed.
218 */
219struct netconfig *
220rpcbind_get_conf(char *netid)
221{
222 struct fdlist *fdl;
223
224 for (fdl = fdhead; fdl; fdl = fdl->next)
225 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
226 break;
227 if (fdl == NULL)
228 return (NULL);
229 return (fdl->nconf);
230}
2/* $FreeBSD: head/usr.sbin/rpcbind/check_bound.c 258564 2013-11-25 16:44:02Z hrs $ */
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 <stdio.h>
54#include <netconfig.h>
55#include <syslog.h>
56#include <string.h>
57#include <unistd.h>
58#include <stdlib.h>
59
60#include "rpcbind.h"
--- 93 unchanged lines hidden (view full) ---
154 * Returns NULL if there was some system error.
155 * Returns "" if the address was not bound, i.e the server crashed.
156 * Returns the merged address otherwise.
157 */
158char *
159mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr)
160{
161 struct fdlist *fdl;
162 char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL;
163
164 for (fdl = fdhead; fdl; fdl = fdl->next)
165 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
166 break;
167 if (fdl == NULL)
168 return (NULL);
169 if (check_bound(fdl, uaddr) == FALSE)
170 /* that server died */
171 return (nullstring);
172 /*
173 * If saddr is not NULL, the remote client may have included the
174 * address by which it contacted us. Use that for the "client" uaddr,
175 * otherwise use the info from the SVCXPRT.
176 */
177 if (saddr != NULL) {
178 c_uaddr = saddr;
179 } else {
180 c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt));
181 if (c_uaddr == NULL) {
182 syslog(LOG_ERR, "taddr2uaddr failed for %s",
183 fdl->nconf->nc_netid);
184 return (NULL);
185 }
--- 26 unchanged lines hidden (view full) ---
212 return (m_uaddr);
213}
214
215/*
216 * Returns a netconf structure from its internal list. This
217 * structure should not be freed.
218 */
219struct netconfig *
220rpcbind_get_conf(char *netid)
221{
222 struct fdlist *fdl;
223
224 for (fdl = fdhead; fdl; fdl = fdl->next)
225 if (strcmp(fdl->nconf->nc_netid, netid) == 0)
226 break;
227 if (fdl == NULL)
228 return (NULL);
229 return (fdl->nconf);
230}