sssd_krb5_locator_plugin.c revision 1193f20a8267e506d863b27c74870c86c085902b
/*
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2009 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#include <ctype.h>
#include "util/sss_krb5.h"
#include <krb5/locate_plugin.h>
#include "providers/krb5/krb5_common.h"
#define DEFAULT_KERBEROS_PORT 88
#define DEFAULT_KADMIN_PORT 749
#define DEFAULT_KPASSWD_PORT 464
#define BUFSIZE 512
#define PORT_STR_SIZE 7
#define SSSD_KRB5_LOCATOR_DEBUG "SSSD_KRB5_LOCATOR_DEBUG"
#define SSSD_KRB5_LOCATOR_DISABLE "SSSD_KRB5_LOCATOR_DISABLE"
#define DEBUG_KEY "[sssd_krb5_locator] "
#define PLUGIN_DEBUG(body) do { \
} \
} while(0)
struct sssd_ctx {
char *sssd_realm;
char *kdc_addr;
char *kpasswd_addr;
bool debug;
bool disabled;
};
void plugin_debug_fn(const char *format, ...)
{
char *s = NULL;
int ret;
if (ret < 0) {
/* ENOMEM */
return;
}
free(s);
}
enum locate_service_type svc)
{
int ret;
char *krb5info_name = NULL;
int fd = -1;
char *port_str;
long port;
char *endptr;
switch (svc) {
case locate_service_kdc:
break;
case locate_service_kpasswd:
break;
default:
return EINVAL;
}
if (krb5info_name == NULL) {
PLUGIN_DEBUG(("malloc failed.\n"));
return ENOMEM;
}
if (ret < 0) {
PLUGIN_DEBUG(("snprintf failed.\n"));
goto done;
}
if (fd == -1) {
PLUGIN_DEBUG(("open failed [%s][%d][%s].\n",
goto done;
}
errno = 0;
if (len == -1) {
goto done;
}
PLUGIN_DEBUG(("Content of krb5info file [%s] is [%d] or larger.\n",
krb5info_name, BUFSIZE));
}
port = 0;
} else {
*port_str = '\0';
++port_str;
errno = 0;
if (errno != 0) {
PLUGIN_DEBUG(("strtol failed on [%s]: [%d][%s], "
port = 0;
}
if (*endptr != '\0') {
PLUGIN_DEBUG(("Found additional characters [%s] in port number "
port = 0;
}
PLUGIN_DEBUG(("Illegal port number [%ld], assuming default.\n",
port));
port = 0;
}
} else {
PLUGIN_DEBUG(("Illegal port number [%s], assuming default.\n",
port_str));
port = 0;
}
}
switch (svc) {
case locate_service_kdc:
PLUGIN_DEBUG(("strdup failed.\n"));
goto done;
}
break;
case locate_service_kpasswd:
PLUGIN_DEBUG(("strdup failed.\n"));
goto done;
}
break;
default:
goto done;
}
ret = 0;
done:
return ret;
}
void **private_data)
{
const char *dummy;
} else {
PLUGIN_DEBUG(("sssd_krb5_locator_init called\n"));
}
} else {
PLUGIN_DEBUG(("SSSD KRB5 locator plugin is disabled.\n"));
}
*private_data = ctx;
return 0;
}
void sssd_krb5_locator_close(void *private_data)
{
if (private_data == NULL) return;
PLUGIN_DEBUG(("sssd_krb5_locator_close called\n"));
return;
}
enum locate_service_type svc,
const char *realm,
int socktype,
int family,
void *cbdata)
{
int ret;
char port_str[PORT_STR_SIZE];
PLUGIN_DEBUG(("Plugin disabled, nothing to do.\n"));
return KRB5_PLUGIN_NO_HANDLE;
}
PLUGIN_DEBUG(("strdup failed.\n"));
return KRB5_PLUGIN_NO_HANDLE;
}
PLUGIN_DEBUG(("get_krb5info failed.\n"));
return KRB5_PLUGIN_NO_HANDLE;
}
svc == locate_service_master_kdc) {
PLUGIN_DEBUG(("reading kpasswd address failed, "
"using kdc address.\n"));
ctx->kpasswd_port = 0;
}
}
}
PLUGIN_DEBUG(("sssd_realm[%s] requested realm[%s] family[%d] socktype[%d] "
switch (svc) {
case locate_service_kdc:
break;
break;
case locate_service_kadmin:
break;
case locate_service_kpasswd:
break;
case locate_service_krb524:
return KRB5_PLUGIN_NO_HANDLE;
default:
return KRB5_PLUGIN_NO_HANDLE;
}
switch (family) {
case AF_UNSPEC:
case AF_INET:
case AF_INET6:
break;
default:
return KRB5_PLUGIN_NO_HANDLE;
}
switch (socktype) {
case SOCK_STREAM:
case SOCK_DGRAM:
break;
default:
return KRB5_PLUGIN_NO_HANDLE;
}
return KRB5_PLUGIN_NO_HANDLE;
PLUGIN_DEBUG(("snprintf failed.\n"));
return KRB5_PLUGIN_NO_HANDLE;
}
if (ret != 0) {
gai_strerror(ret)));
if (ret == EAI_SYSTEM) {
}
return KRB5_PLUGIN_NO_HANDLE;
}
if (ret != 0) {
PLUGIN_DEBUG(("cbfunc failed\n"));
return ret;
} else {
}
} else {
}
return 0;
}
0, /* version */
};