summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/krb5/keytab_keyfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/krb5/keytab_keyfile.c')
-rw-r--r--crypto/heimdal/lib/krb5/keytab_keyfile.c70
1 files changed, 52 insertions, 18 deletions
diff --git a/crypto/heimdal/lib/krb5/keytab_keyfile.c b/crypto/heimdal/lib/krb5/keytab_keyfile.c
index ffdf35c..2403412 100644
--- a/crypto/heimdal/lib/krb5/keytab_keyfile.c
+++ b/crypto/heimdal/lib/krb5/keytab_keyfile.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -33,7 +33,7 @@
#include "krb5_locl.h"
-RCSID("$Id: keytab_keyfile.c,v 1.9 2000/07/02 16:14:16 assar Exp $");
+RCSID("$Id: keytab_keyfile.c,v 1.11 2001/05/14 06:14:49 assar Exp $");
/* afs keyfile operations --------------------------------------- */
@@ -63,16 +63,23 @@ struct akf_data {
*/
static int
-get_cell_and_realm (struct akf_data *d)
+get_cell_and_realm (krb5_context context,
+ struct akf_data *d)
{
FILE *f;
char buf[BUFSIZ], *cp;
+ int ret;
f = fopen (AFS_SERVERTHISCELL, "r");
- if (f == NULL)
- return errno;
+ if (f == NULL) {
+ ret = errno;
+ krb5_set_error_string (context, "open %s: %s", AFS_SERVERTHISCELL,
+ strerror(ret));
+ return ret;
+ }
if (fgets (buf, sizeof(buf), f) == NULL) {
fclose (f);
+ krb5_set_error_string (context, "no cell in %s", AFS_SERVERTHISCELL);
return EINVAL;
}
if (buf[strlen(buf) - 1] == '\n')
@@ -80,13 +87,17 @@ get_cell_and_realm (struct akf_data *d)
fclose(f);
d->cell = strdup (buf);
- if (d->cell == NULL)
- return errno;
+ if (d->cell == NULL) {
+ krb5_set_error_string (context, "malloc: out of memory");
+ return ENOMEM;
+ }
f = fopen (AFS_SERVERMAGICKRBCONF, "r");
if (f != NULL) {
if (fgets (buf, sizeof(buf), f) == NULL) {
fclose (f);
+ krb5_set_error_string (context, "no realm in %s",
+ AFS_SERVERMAGICKRBCONF);
return EINVAL;
}
if (buf[strlen(buf)-1] == '\n')
@@ -100,7 +111,8 @@ get_cell_and_realm (struct akf_data *d)
d->realm = strdup (buf);
if (d->realm == NULL) {
free (d->cell);
- return errno;
+ krb5_set_error_string (context, "malloc: out of memory");
+ return ENOMEM;
}
return 0;
}
@@ -115,11 +127,13 @@ akf_resolve(krb5_context context, const char *name, krb5_keytab id)
int ret;
struct akf_data *d = malloc(sizeof (struct akf_data));
- if (d == NULL)
- return errno;
+ if (d == NULL) {
+ krb5_set_error_string (context, "malloc: out of memory");
+ return ENOMEM;
+ }
d->num_entries = 0;
- ret = get_cell_and_realm (d);
+ ret = get_cell_and_realm (context, d);
if (ret) {
free (d);
return ret;
@@ -129,6 +143,7 @@ akf_resolve(krb5_context context, const char *name, krb5_keytab id)
free (d->cell);
free (d->realm);
free (d);
+ krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
id->data = d;
@@ -180,14 +195,21 @@ akf_start_seq_get(krb5_context context,
struct akf_data *d = id->data;
c->fd = open (d->filename, O_RDONLY|O_BINARY, 0600);
- if (c->fd < 0)
- return errno;
+ if (c->fd < 0) {
+ ret = errno;
+ krb5_set_error_string(context, "open(%s): %s", d->filename,
+ strerror(ret));
+ return ret;
+ }
c->sp = krb5_storage_from_fd(c->fd);
ret = krb5_ret_int32(c->sp, &d->num_entries);
if(ret) {
krb5_storage_free(c->sp);
close(c->fd);
+ krb5_clear_error_string (context);
+ if(ret == KRB5_CC_END)
+ return KRB5_KT_NOTFOUND;
return ret;
}
@@ -228,6 +250,7 @@ akf_next_entry(krb5_context context,
entry->keyblock.keyvalue.data = malloc (8);
if (entry->keyblock.keyvalue.data == NULL) {
krb5_free_principal (context, entry->principal);
+ krb5_set_error_string (context, "malloc: out of memory");
ret = ENOMEM;
goto out;
}
@@ -268,8 +291,12 @@ akf_add_entry(krb5_context context,
if (fd < 0) {
fd = open (d->filename,
O_RDWR | O_BINARY | O_CREAT, 0600);
- if (fd < 0)
- return errno;
+ if (fd < 0) {
+ ret = errno;
+ krb5_set_error_string(context, "open(%s): %s", d->filename,
+ strerror(ret));
+ return ret;
+ }
created = 1;
}
@@ -282,15 +309,18 @@ akf_add_entry(krb5_context context,
sp = krb5_storage_from_fd(fd);
if(sp == NULL) {
close(fd);
+ krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
if (created)
len = 0;
else {
if((*sp->seek)(sp, 0, SEEK_SET) < 0) {
+ ret = errno;
krb5_storage_free(sp);
close(fd);
- return errno;
+ krb5_set_error_string (context, "seek: %s", strerror(ret));
+ return ret;
}
ret = krb5_ret_int32(sp, &len);
@@ -303,9 +333,11 @@ akf_add_entry(krb5_context context,
len++;
if((*sp->seek)(sp, 0, SEEK_SET) < 0) {
+ ret = errno;
krb5_storage_free(sp);
close(fd);
- return errno;
+ krb5_set_error_string (context, "seek: %s", strerror(ret));
+ return ret;
}
ret = krb5_store_int32(sp, len);
@@ -317,9 +349,11 @@ akf_add_entry(krb5_context context,
if((*sp->seek)(sp, (len - 1) * (8 + 4), SEEK_CUR) < 0) {
+ ret = errno;
krb5_storage_free(sp);
close(fd);
- return errno;
+ krb5_set_error_string (context, "seek: %s", strerror(ret));
+ return ret;
}
ret = krb5_store_int32(sp, entry->vno);
OpenPOWER on IntegriCloud