1
/* Copyright (c) 2004 Thorsten Kukuk
2
This file is part of ypbind-mt.
3
Author: Thorsten Kukuk <kukuk@suse.de>
5
The ypbind-mt are free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License version 2
7
as published by the Free Software Foundation.
9
ypbind-mt is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with ypbind-mt; see the file COPYING. If not,
16
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA. */
19
#if defined(HAVE_CONFIG_H)
36
#define _(String) gettext (String)
39
/* Ask SLP server for ypserv service. */
48
MySLPSrvURLCallback (SLPHandle hslp __attribute__((unused)),
50
unsigned short lifetime __attribute__((unused)),
51
SLPError errcode, void *cookie)
53
struct slpcb *cb = (struct slpcb *) cookie;
55
if (errcode == SLP_OK)
57
if (cb->srvurl != NULL)
59
struct slpcb *cbt = malloc (sizeof (struct slpcb));
63
cbt->srvurl = cb->srvurl;
68
cb->srvurl = strdup (srvurl);
72
else if (errcode != SLP_LAST_CALL)
75
return SLP_FALSE; /* We don't wan't to be called again. */
79
query_slp (const char *domain)
81
struct slpcb *cb, callbackres = {NULL, 0, NULL};
86
err = SLPOpen ("en", SLP_FALSE, &hslp);
89
log_msg (LOG_ERR, _("Error opening SLP handle: %i."), err);
93
err = SLPFindSrvs (hslp, "ypserv", 0, 0,
94
MySLPSrvURLCallback, &callbackres);
96
/* err may contain an error code that occurred as the slp library
97
_prepared_ to make the call. */
98
if (err != SLP_OK || callbackres.err != SLP_OK)
100
log_msg (LOG_ERR, _("No service found with SLP."));
104
/* Now that we're done using slp, close the slp handle */
110
if (cb->srvurl != NULL)
112
char *hostp = strstr (cb->srvurl, "://");
115
if (!hostp || strlen(hostp) < strlen("://") + 1)
121
hostp += strlen ("://");
123
cp = strrchr (hostp, '/');
127
/* Remove any port specification (we should use it!). */
128
cp = strchr (hostp, ':');
132
if (add_server (domain, hostp, 0))
134
log_msg (LOG_INFO, "SLP: found server %s for domain %s.",