summaryrefslogtreecommitdiff
path: root/src/krb5_plugin
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2010-03-04 12:44:21 +0100
committerStephen Gallagher <sgallagh@redhat.com>2010-03-11 09:22:41 -0500
commit03e7e62d439a2ef21f3c1c074a593a15606a0e1e (patch)
tree2c2bc856f9d3821c08687368f07866acc077b5e8 /src/krb5_plugin
parent29752834fbf3a19e4e117668abfce4e4c7c48ee4 (diff)
downloadsssd-03e7e62d439a2ef21f3c1c074a593a15606a0e1e.tar.gz
sssd-03e7e62d439a2ef21f3c1c074a593a15606a0e1e.tar.bz2
sssd-03e7e62d439a2ef21f3c1c074a593a15606a0e1e.zip
Write the IP address of the KDC to the kdcinfo file
Diffstat (limited to 'src/krb5_plugin')
-rw-r--r--src/krb5_plugin/sssd_krb5_locator_plugin.c81
1 files changed, 42 insertions, 39 deletions
diff --git a/src/krb5_plugin/sssd_krb5_locator_plugin.c b/src/krb5_plugin/sssd_krb5_locator_plugin.c
index 5e797333..8f32a31b 100644
--- a/src/krb5_plugin/sssd_krb5_locator_plugin.c
+++ b/src/krb5_plugin/sssd_krb5_locator_plugin.c
@@ -45,7 +45,7 @@
struct sssd_ctx {
char *sssd_realm;
- struct addrinfo *sssd_kdc_addrinfo;
+ char *kdc_addr;
bool debug;
};
@@ -122,14 +122,10 @@ static int get_kdcinfo(const char *realm, struct sssd_ctx *ctx)
}
PLUGIN_DEBUG(("Found kdcinfo [%s].\n", buf));
- ret = getaddrinfo((char *) buf, "kerberos", NULL, &ctx->sssd_kdc_addrinfo);
- if (ret != 0) {
- PLUGIN_DEBUG(("getaddrinfo failed [%d][%s].\n", ret,
- gai_strerror(ret)));
- if (ret == EAI_SYSTEM) {
- PLUGIN_DEBUG(("getaddrinfo failed [%d][%s].\n", errno,
- strerror(errno)));
- }
+ ctx->kdc_addr = strdup((char *) buf);
+ if (ctx->kdc_addr == NULL) {
+ PLUGIN_DEBUG(("strdup failed.\n"));
+ ret = ENOMEM;
goto done;
}
@@ -140,8 +136,6 @@ static int get_kdcinfo(const char *realm, struct sssd_ctx *ctx)
goto done;
}
-
-
done:
free(kdcinfo_name);
return ret;
@@ -178,7 +172,7 @@ void sssd_krb5_locator_close(void *private_data)
ctx = (struct sssd_ctx *) private_data;
PLUGIN_DEBUG(("sssd_krb5_locator_close called\n"));
- freeaddrinfo(ctx->sssd_kdc_addrinfo);
+ free(ctx->kdc_addr);
free(ctx->sssd_realm);
free(ctx);
private_data = NULL;
@@ -197,14 +191,15 @@ krb5_error_code sssd_krb5_locator_lookup(void *private_data,
int ret;
struct addrinfo *ai;
struct sssd_ctx *ctx;
- char hostip[NI_MAXHOST];
+ struct addrinfo ai_hints;
+ const char *service = NULL;
if (private_data == NULL) return KRB5_PLUGIN_NO_HANDLE;
ctx = (struct sssd_ctx *) private_data;
if (ctx->sssd_realm == NULL || strcmp(ctx->sssd_realm, realm) != 0) {
- freeaddrinfo(ctx->sssd_kdc_addrinfo);
- ctx->sssd_kdc_addrinfo = NULL;
+ free(ctx->kdc_addr);
+ ctx->kdc_addr = NULL;
free(ctx->sssd_realm);
ctx->sssd_realm = NULL;
ret = get_kdcinfo(realm, ctx);
@@ -221,10 +216,15 @@ krb5_error_code sssd_krb5_locator_lookup(void *private_data,
switch (svc) {
case locate_service_kdc:
case locate_service_master_kdc:
+ service = "kerberos";
+ break;
case locate_service_kadmin:
+ service = "kerberos-adm";
break;
- case locate_service_krb524:
case locate_service_kpasswd:
+ service = "kpasswd";
+ break;
+ case locate_service_krb524:
return KRB5_PLUGIN_NO_HANDLE;
default:
return EINVAL;
@@ -250,32 +250,35 @@ krb5_error_code sssd_krb5_locator_lookup(void *private_data,
if (strcmp(realm, ctx->sssd_realm) != 0)
return KRB5_PLUGIN_NO_HANDLE;
- for (ai = ctx->sssd_kdc_addrinfo; ai != NULL; ai = ai->ai_next) {
- ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, hostip, NI_MAXHOST,
- NULL, 0, NI_NUMERICHOST);
- if (ret != 0) {
- PLUGIN_DEBUG(("getnameinfo failed [%d][%s].\n", ret,
- gai_strerror(ret)));
- if (ret == EAI_SYSTEM) {
- PLUGIN_DEBUG(("getnameinfo failed [%d][%s].\n", errno,
- strerror(errno)));
- }
+ memset(&ai_hints, 0, sizeof(struct addrinfo));
+ ai_hints.ai_flags = AI_NUMERICHOST;
+ ai_hints.ai_socktype = socktype;
+ ret = getaddrinfo(ctx->kdc_addr, service, &ai_hints, &ai);
+ if (ret != 0) {
+ PLUGIN_DEBUG(("getaddrinfo failed [%d][%s].\n", ret,
+ gai_strerror(ret)));
+ if (ret == EAI_SYSTEM) {
+ PLUGIN_DEBUG(("getaddrinfo failed [%d][%s].\n", errno,
+ strerror(errno)));
}
- PLUGIN_DEBUG(("addr[%s] family[%d] socktype[%d] - ", hostip,
- ai->ai_family, ai->ai_socktype));
-
- if ((family == AF_UNSPEC || ai->ai_family == family) &&
- ai->ai_socktype == socktype) {
-
- ret = cbfunc(cbdata, socktype, ai->ai_addr);
- if (ret != 0) {
- PLUGIN_DEBUG(("\ncbfunc failed\n"));
- } else {
- PLUGIN_DEBUG(("used\n"));
- }
+ return EFAULT;
+ }
+
+ PLUGIN_DEBUG(("addr[%s] family[%d] socktype[%d]\n", ctx->kdc_addr,
+ ai->ai_family, ai->ai_socktype));
+
+ if ((family == AF_UNSPEC || ai->ai_family == family) &&
+ ai->ai_socktype == socktype) {
+
+ ret = cbfunc(cbdata, socktype, ai->ai_addr);
+ if (ret != 0) {
+ PLUGIN_DEBUG(("cbfunc failed\n"));
+ return ret;
} else {
- PLUGIN_DEBUG((" NOT used\n"));
+ PLUGIN_DEBUG(("[%s] used\n", ctx->kdc_addr));
}
+ } else {
+ PLUGIN_DEBUG(("[%s] NOT used\n", ctx->kdc_addr));
}
return 0;