sss_krb5.c revision 768591607fc89d3a14fa00c9c8f78e83f3f6b565
/*
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2009-2010 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 <stdio.h>
#include <errno.h>
#include <talloc.h>
#include "config.h"
#include "util/sss_krb5.h"
const char *hostname,
const char *desired_realm,
const char *keytab_name,
char **_principal,
char **_primary,
char **_realm)
{
krb5_error_code kerr = 0;
int i = 0;
char *principal_string;
const char *realm_name;
int realm_len;
/**
* Priority of lookup:
* - foobar$@REALM (AD domain)
* - host/our.hostname@REALM
* - pick the first principal in the keytab
*/
if (!tmp_ctx) {
return ENOMEM;
}
if (kerr) {
goto done;
}
if (keytab_name != NULL) {
} else {
}
if (kerr) {
DEBUG(0, ("Failed to read keytab file: %s\n",
goto done;
}
if (!desired_realm) {
desired_realm = "*";
}
if (!hostname) {
hostname = "*";
}
do {
if (primary_patterns[i]) {
goto done;
}
} else {
}
if (realm_patterns[i]) {
goto done;
}
} else {
}
&client_princ);
if (kerr == 0) {
break;
}
if (client_princ != NULL) {
client_princ = NULL;
}
i++;
if (kerr == 0) {
if (_principal) {
if (kerr) {
goto done;
}
if (!*_principal) {
goto done;
}
}
if (_primary) {
if (kerr) {
goto done;
}
if (!*_primary) {
goto done;
}
}
if (_realm) {
&realm_len);
if (!*_realm) {
goto done;
}
}
} else {
}
done:
if (client_princ != NULL) {
client_princ = NULL;
}
return ret;
}
int sss_krb5_verify_keytab(const char *principal,
const char *realm_str,
const char *keytab_name)
{
int ret;
char *full_princ = NULL;
char *realm_name = NULL;
char *default_realm = NULL;
if (!tmp_ctx) {
return ENOMEM;
}
if (krberr) {
goto done;
}
if (keytab_name) {
} else {
}
if (krberr) {
DEBUG(0, ("Failed to read keytab file: %s\n",
goto done;
}
if (!realm_str) {
if (krberr) {
goto done;
}
if (!realm_name) {
goto done;
}
} else {
if (!realm_name) {
goto done;
}
}
if (principal) {
} else {
}
} else {
char hostname[512];
if (ret == -1) {
goto done;
}
}
if (!full_princ) {
goto done;
}
done:
return ret;
}
{
bool found;
char *kt_principal;
if (krberr) {
"Unable to create GSSAPI-encrypted LDAP connection.",
return EIO;
}
found = false;
found = true;
}
if (krberr) {
/* This should never happen. The API docs for this function
* specify only success for this function
*/
/* This is non-fatal, so we'll continue here */
}
if (found) {
break;
}
}
if (krberr) {
DEBUG(0, ("Could not close keytab.\n"));
return EIO;
}
if (!found) {
DEBUG(0, ("Principal [%s] not found in keytab [%s]\n",
"Principal [%s] was not found. "
"Unable to create GSSAPI-encrypted LDAP connection.",
return EFAULT;
}
return EOK;
}
/**
* We only have primary and instances stored separately, we need to
* join them to one string and compare that string.
*
* @param ctx kerberos context
* @param principal principal we want to match
* @param pattern_primary primary part of the principal we want to
* perform matching against. It is possible to use * wildcard
* at the beginning or at the end of the string. If NULL, it
* will act as "*"
* @param pattern_realm realm part of the principal we want to perform
* the matching against. If NULL, it will act as "*"
*/
const char *pattern_primary,
const char *pattern_realm)
{
char *primary_str = NULL;
int primary_str_len = 0;
int tmp_len;
int len_diff;
const char *realm_name;
int realm_len;
int mode = MODE_NORMAL;
bool ret = false;
if (!tmp_ctx) {
return false;
}
if (pattern_primary) {
mode = MODE_PREFIX;
} else if (pattern_primary[0] == '*') {
mode = MODE_POSTFIX;
}
&primary);
if ((mode == MODE_NORMAL &&
(mode == MODE_PREFIX &&
(mode == MODE_POSTFIX &&
goto done;
}
}
ret = true;
}
done:
return ret;
}
const char *pattern_primary,
const char *pattern_realm,
{
bool principal_found = false;
if (kerr != 0) {
return kerr;
}
if (principal_found) {
break;
}
if (kerr != 0) {
}
}
/* Close the keytab here. Even though we're using cursors, the file
* handle is stored in the krb5_keytab structure, and it gets
* overwritten by other keytab calls, creating a leak. */
if (kerr != 0) {
goto done;
}
if (!principal_found) {
goto done;
}
/* check if we got any errors from krb5_kt_next_entry */
goto done;
}
if (kerr != 0) {
goto done;
}
kerr = 0;
done:
if (kerr_d != 0) {
}
return kerr;
}
{
#ifdef HAVE_KRB5_GET_ERROR_MESSAGE
#else
int ret;
char *s = NULL;
int size = sizeof("Kerberos error [XXXXXXXXXXXX]");
if (s == NULL) {
return NULL;
}
return NULL;
}
return s;
#endif
}
{
#ifdef HAVE_KRB5_GET_ERROR_MESSAGE
#else
free(s);
#endif
return;
}
{
#else
return ENOMEM;
}
return 0;
#endif
}
{
#else
#endif
return;
}
{
#ifdef HAVE_KRB5_FREE_UNPARSED_NAME
#else
}
#endif
}
const char *client_princ_str, bool *result)
{
char *server_name = NULL;
*result = false;
return ENOMEM;
}
if (krberr) {
goto done;
}
if (krberr != 0) {
goto done;
}
if (server_name == NULL) {
goto done;
}
if (krberr != 0) {
goto done;
}
if (krberr != 0) {
goto done;
}
if (krberr != 0) {
krberr = 0;
goto done;
}
*result = true;
}
krberr = 0;
done:
if (client_principal != NULL) {
}
if (server_principal != NULL) {
}
}
return krberr;
}
void *data)
{
#else
return 0;
#endif
}
{
*use_fast = false;
*use_fast = true;
} else {
"please use never, try, or demand.\n");
return EINVAL;
}
return EOK;
#else
"Please remove option krb5_use_fast.\n");
return EINVAL;
#endif
}
const char *fast_ccache_name)
{
#else
return 0;
#endif
}
{
#else
return 0;
#endif
}
#ifndef HAVE_KRB5_UNPARSE_NAME_FLAGS
#ifndef REALM_SEP
#define REALM_SEP '@'
#endif
#ifndef COMPONENT_SEP
#define COMPONENT_SEP '/'
#endif
static int
{
int j;
char *q = dest;
if (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) {
}
switch (*cp) {
case REALM_SEP:
if (no_realm) {
*q++ = *cp;
break;
}
case COMPONENT_SEP:
case '\\':
*q++ = '\\';
*q++ = *cp;
break;
case '\t':
*q++ = '\\';
*q++ = 't';
break;
case '\n':
*q++ = '\\';
*q++ = 'n';
break;
case '\b':
*q++ = '\\';
*q++ = 'b';
break;
case '\0':
*q++ = '\\';
*q++ = '0';
break;
default:
*q++ = *cp;
}
}
return q - dest;
}
static int
{
int j;
if ((flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) == 0) {
*cp == COMPONENT_SEP ||
size++;
}
return size;
}
#endif /* HAVE_KRB5_UNPARSE_NAME_FLAGS */
{
#ifdef HAVE_KRB5_UNPARSE_NAME_FLAGS
#else
char *cp, *q;
int i;
int length;
unsigned int totalsize = 0;
char *default_realm = NULL;
krb5_error_code ret = 0;
return KRB5_PARSE_MALFORMED;
if (flags & KRB5_PRINCIPAL_UNPARSE_SHORT) {
/* omit realm if local realm */
if (ret != 0)
goto cleanup;
}
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
flags);
totalsize++;
}
for (i = 0; i < (int) nelem; i++) {
totalsize++;
}
if (nelem == 0)
totalsize++;
if (!*name) {
goto cleanup;
}
q = *name;
for (i = 0; i < (int) nelem; i++) {
q += sss_krb5_copy_component_quoting(q,
i),
flags);
*q++ = COMPONENT_SEP;
}
if (i > 0)
q--;
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
*q++ = REALM_SEP;
}
*q++ = '\0';
return ret;
#endif /* HAVE_KRB5_UNPARSE_NAME_FLAGS */
}
int canonicalize)
{
/* FIXME: The extra check for HAVE_KRB5_TICKET_TIMES is a workaround due to Heimdal
* defining krb5_get_init_creds_opt_set_canonicalize() with a different set of
* arguments. We should use a better configure check in the future.
*/
#if defined(HAVE_KRB5_GET_INIT_CREDS_OPT_SET_CANONICALIZE) && defined(HAVE_KRB5_TICKET_TIMES)
#else
#endif
}
{
}
#else
{
if (data) {
}
}
#endif
{
}
#else
{
}
#endif