ldap_child.c revision 6ccda8691123bb27f5f2a88a0c80174af3e0fd0a
/*
SSSD
LDAP Backend Module -- prime ccache with TGT in a child process
Authors:
Jakub Hrozek <jhrozek@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 <unistd.h>
#include <popt.h>
#include "util/sss_krb5.h"
#include "util/child_common.h"
#include "providers/dp_backend.h"
#include "providers/krb5/krb5_common.h"
static krb5_context krb5_error_ctx;
static const char *__ldap_child_krb5_error_msg;
#define KRB5_SYSLOG(krb5_error) do { \
} while(0)
struct input_buffer {
const char *realm_str;
const char *princ_str;
char *keytab_name;
};
struct input_buffer *ibuf)
{
size_t p = 0;
/* realm_str size and length */
if (len) {
p += len;
}
/* princ_str size and length */
if (len) {
p += len;
}
/* keytab_name size and length */
if (len) {
p += len;
}
/* ticket lifetime */
/* UID and GID to run as */
return EOK;
}
{
int len;
size_t p = 0;
if(!r->buf) {
return ENOMEM;
}
"result [%d] krberr [%d] msgsize [%d] msg [%s]\n",
/* result */
/* krb5 error code */
/* message size */
/* message itself */
/* ticket expiration time */
return EOK;
}
static errno_t
{
/* Set the global error context */
if (debug_level & SSSDBG_TRACE_ALL) {
if (kerr) {
return EIO;
}
}
return EOK;
}
static int lc_verify_keytab_ex(const char *principal,
const char *keytab_name,
{
bool found;
char *kt_principal;
if (krberr) {
"Cannot read keytab [%s].\n", KEYTAB_CLEAN_NAME);
"Unable to create GSSAPI-encrypted LDAP "
"connection.",
return EIO;
}
found = false;
if (krberr) {
"Could not parse keytab entry\n");
return EIO;
}
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) {
return EIO;
}
if (!found) {
"Principal [%s] not found in keytab [%s]\n",
"Principal [%s] was not found. "
"Unable to create GSSAPI-encrypted LDAP connection.",
return EFAULT;
}
return EOK;
}
const char *realm_str,
const char *princ_str,
const char *keytab_name,
const krb5_deltat lifetime,
const char **ccname_out,
{
int fd;
char *ccname;
char *ccname_dummy;
char *realm_name = NULL;
char *full_princ = NULL;
char *default_realm = NULL;
int canonicalize = 0;
int kdc_time_offset_usec;
int ret;
char *ccname_file_dummy = NULL;
char *ccname_file;
goto done;
}
}
if (!realm_str) {
if (krberr) {
goto done;
}
if (!realm_name) {
goto done;
}
} else {
if (!realm_name) {
goto done;
}
}
if (princ_str) {
} else {
}
} else {
if (ret == -1) {
goto done;
}
if (ret) {
goto done;
}
}
if (!full_princ) {
goto done;
}
if (krberr) {
goto done;
}
if (keytab_name) {
} else {
}
if (krberr) {
"Failed to read keytab file [%s]: %s\n",
goto done;
}
/* Verify the keytab */
if (ret) {
"Unable to verify principal is present in the keytab\n");
goto done;
}
canonicalize = 1;
}
if (ccname_file == NULL) {
"talloc_asprintf failed: %s:[%d].\n",
goto done;
}
if (ccname_file_dummy == NULL) {
"talloc_asprintf failed: %s:[%d].\n",
goto done;
}
if (fd == -1) {
"mkstemp failed: %s:[%d].\n",
goto done;
}
/* We only care about creating a unique file name here, we don't
* need the fd
*/
if (krberr) {
"Failed to init credentials: %s\n",
"Failed to initialize credentials using keytab [%s]: %s. "
"Unable to create GSSAPI-encrypted LDAP connection.",
goto done;
}
goto done;
}
if (krberr) {
goto done;
}
/* Use updated principal if changed due to canonicalization. */
if (krberr) {
goto done;
}
if (krberr) {
goto done;
}
#ifdef HAVE_KRB5_GET_TIME_OFFSETS
if (krberr) {
kdc_time_offset = 0;
} else {
if (kdc_time_offset_usec > 0) {
}
}
#else
/* If we don't have this function, just assume no offset */
kdc_time_offset = 0;
#endif
if (ret == -1) {
goto done;
}
krberr = 0;
done:
if (ccname_file_dummy) {
if (ret == -1) {
}
}
return krberr;
}
const char *ccname,
{
int ret;
if (!r) return ENOMEM;
r->size = 0;
if (kerr == 0) {
} else {
"sss_krb5_get_error_message failed.\n");
return ENOMEM;
}
}
return ret;
}
*rsp = r;
return EOK;
}
{
char *keytab_name;
if (kerr != 0) {
return kerr;
}
&keytab_name, NULL);
if (kerr != 0) {
return kerr;
}
return 0;
}
{
int ret;
int kerr;
int opt;
int debug_fd = -1;
time_t expire_time = 0;
struct poptOption long_options[] = {
_("Debug level"), NULL},
_("Add debug timestamps"), NULL},
_("Show timestamps with microseconds"), NULL},
_("An open file descriptor for the debug logs"), NULL},
_("Send the debug output to stderr directly."), NULL }, \
};
/* Set debug level to invalid value so we can decide if -d 0 was used. */
switch(opt) {
default:
_exit(-1);
}
}
if (!debug_prg_name) {
debug_prg_name = "[sssd[ldap_child]]";
goto fail;
}
if (debug_fd != -1) {
}
}
goto fail;
}
goto fail;
}
goto fail;
}
errno = 0;
if (len == -1) {
goto fail;
}
goto fail;
}
goto fail;
}
if (kerr != 0) {
goto fail;
}
&ccname, &expire_time);
/* Do not return, must report failure */
}
goto fail;
}
errno = 0;
if (written == -1) {
goto fail;
}
goto fail;
}
_exit(0);
fail:
_exit(-1);
}