use krb5_set_error_message

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23280 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2008-06-23 03:26:18 +00:00
parent cec3f10ef0
commit d542833a1f
18 changed files with 195 additions and 182 deletions

View File

@@ -93,12 +93,12 @@ _krb5_xlock(krb5_context context, int fd, krb5_boolean exclusive,
ret = 0;
break;
case EAGAIN:
krb5_set_error_string(context, "timed out locking cache file %s",
filename);
krb5_set_error_message(context, ret, "timed out locking cache file %s",
filename);
break;
default:
krb5_set_error_string(context, "error locking cache file %s: %s",
filename, strerror(ret));
krb5_set_error_message(context, ret, "error locking cache file %s: %s",
filename, strerror(ret));
break;
}
return ret;
@@ -127,8 +127,9 @@ _krb5_xunlock(krb5_context context, int fd)
ret = 0;
break;
default:
krb5_set_error_string(context,
"Failed to unlock file: %s", strerror(ret));
krb5_set_error_message(context, ret,
"Failed to unlock file: %s",
strerror(ret));
break;
}
return ret;
@@ -143,7 +144,7 @@ write_storage(krb5_context context, krb5_storage *sp, int fd)
ret = krb5_storage_to_data(sp, &data);
if (ret) {
krb5_set_error_string(context, "malloc: out of memory");
krb5_set_error_message(context, ret, "malloc: out of memory");
return ret;
}
sret = write(fd, data.data, data.length);
@@ -151,7 +152,8 @@ write_storage(krb5_context context, krb5_storage *sp, int fd)
krb5_data_free(&data);
if (ret) {
ret = errno;
krb5_set_error_string(context, "Failed to write FILE credential data");
krb5_set_error_message(context, ret,
"Failed to write FILE credential data");
return ret;
}
return 0;
@@ -177,13 +179,15 @@ fcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
krb5_fcache *f;
f = malloc(sizeof(*f));
if(f == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
krb5_set_error_message(context, KRB5_CC_NOMEM,
"malloc: out of memory");
return KRB5_CC_NOMEM;
}
f->filename = strdup(res);
if(f->filename == NULL){
free(f);
krb5_set_error_string(context, "malloc: out of memory");
krb5_set_error_message(context, KRB5_CC_NOMEM,
"malloc: out of memory");
return KRB5_CC_NOMEM;
}
f->version = 0;
@@ -297,19 +301,21 @@ fcc_gen_new(krb5_context context, krb5_ccache *id)
f = malloc(sizeof(*f));
if(f == NULL) {
krb5_set_error_string(context, "malloc: out of memory");
krb5_set_error_message(context, KRB5_CC_NOMEM,
"malloc: out of memory");
return KRB5_CC_NOMEM;
}
asprintf (&file, "%sXXXXXX", KRB5_DEFAULT_CCFILE_ROOT);
if(file == NULL) {
free(f);
krb5_set_error_string(context, "malloc: out of memory");
krb5_set_error_message(context, KRB5_CC_NOMEM,
"malloc: out of memory");
return KRB5_CC_NOMEM;
}
fd = mkstemp(file);
if(fd < 0) {
int ret = errno;
krb5_set_error_string(context, "mkstemp %s", file);
krb5_set_error_message(context, ret, "mkstemp %s", file);
free(f);
free(file);
return ret;
@@ -362,8 +368,8 @@ fcc_open(krb5_context context,
fd = open(filename, flags, mode);
if(fd < 0) {
ret = errno;
krb5_set_error_string(context, "open(%s): %s", filename,
strerror(ret));
krb5_set_error_message(context, ret, "open(%s): %s", filename,
strerror(ret));
return ret;
}
@@ -423,8 +429,8 @@ fcc_initialize(krb5_context context,
if (close(fd) < 0)
if (ret == 0) {
ret = errno;
krb5_set_error_string (context, "close %s: %s",
FILENAME(id), strerror(ret));
krb5_set_error_message (context, ret, "close %s: %s",
FILENAME(id), strerror(ret));
}
return ret;
}
@@ -477,8 +483,8 @@ fcc_store_cred(krb5_context context,
if (close(fd) < 0) {
if (ret == 0) {
ret = errno;
krb5_set_error_string (context, "close %s: %s",
FILENAME(id), strerror(ret));
krb5_set_error_message (context, ret, "close %s: %s",
FILENAME(id), strerror(ret));
}
}
return ret;
@@ -509,25 +515,27 @@ init_fcc (krb5_context context,
ret = krb5_ret_int8(sp, &pvno);
if(ret != 0) {
if(ret == KRB5_CC_END) {
krb5_set_error_string(context, "Empty credential cache file: %s",
FILENAME(id));
ret = ENOENT;
krb5_set_error_message(context, ret,
"Empty credential cache file: %s",
FILENAME(id));
} else
krb5_set_error_string(context, "Error reading pvno in "
"cache file: %s", FILENAME(id));
krb5_set_error_message(context, ret, "Error reading pvno in "
"cache file: %s", FILENAME(id));
goto out;
}
if(pvno != 5) {
krb5_set_error_string(context, "Bad version number in credential "
"cache file: %s", FILENAME(id));
ret = KRB5_CCACHE_BADVNO;
krb5_set_error_message(context, ret, "Bad version number in "
"credential cache file: %s",
FILENAME(id));
goto out;
}
ret = krb5_ret_int8(sp, &tag); /* should not be host byte order */
if(ret != 0) {
krb5_set_error_string(context, "Error reading tag in "
"cache file: %s", FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret, "Error reading tag in "
"cache file: %s", FILENAME(id));
goto out;
}
FCACHE(id)->version = tag;
@@ -539,8 +547,9 @@ init_fcc (krb5_context context,
ret = krb5_ret_int16 (sp, &length);
if(ret) {
ret = KRB5_CC_FORMAT;
krb5_set_error_string(context, "Error reading tag length in "
"cache file: %s", FILENAME(id));
krb5_set_error_message(context, ret,
"Error reading tag length in "
"cache file: %s", FILENAME(id));
goto out;
}
while(length > 0) {
@@ -550,32 +559,32 @@ init_fcc (krb5_context context,
ret = krb5_ret_int16 (sp, &dtag);
if(ret) {
krb5_set_error_string(context, "Error reading dtag in "
"cache file: %s", FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret, "Error reading dtag in "
"cache file: %s", FILENAME(id));
goto out;
}
ret = krb5_ret_int16 (sp, &data_len);
if(ret) {
krb5_set_error_string(context, "Error reading dlength in "
"cache file: %s", FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret, "Error reading dlength in "
"cache file: %s", FILENAME(id));
goto out;
}
switch (dtag) {
case FCC_TAG_DELTATIME :
ret = krb5_ret_int32 (sp, &context->kdc_sec_offset);
if(ret) {
krb5_set_error_string(context, "Error reading kdc_sec in "
"cache file: %s", FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret, "Error reading kdc_sec in "
"cache file: %s", FILENAME(id));
goto out;
}
ret = krb5_ret_int32 (sp, &context->kdc_usec_offset);
if(ret) {
krb5_set_error_string(context, "Error reading kdc_usec in "
"cache file: %s", FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret, "Error reading kdc_usec in "
"cache file: %s", FILENAME(id));
goto out;
}
break;
@@ -583,10 +592,11 @@ init_fcc (krb5_context context,
for (i = 0; i < data_len; ++i) {
ret = krb5_ret_int8 (sp, &dummy);
if(ret) {
krb5_set_error_string(context, "Error reading unknown "
"tag in cache file: %s",
FILENAME(id));
ret = KRB5_CC_FORMAT;
krb5_set_error_message(context, ret,
"Error reading unknown "
"tag in cache file: %s",
FILENAME(id));
goto out;
}
}
@@ -602,9 +612,9 @@ init_fcc (krb5_context context,
break;
default :
ret = KRB5_CCACHE_BADVNO;
krb5_set_error_string(context, "Unknown version number (%d) in "
"credential cache file: %s",
(int)tag, FILENAME(id));
krb5_set_error_message(context, ret, "Unknown version number (%d) in "
"credential cache file: %s",
(int)tag, FILENAME(id));
goto out;
}
*ret_sp = sp;
@@ -655,7 +665,7 @@ fcc_get_first (krb5_context context,
*cursor = malloc(sizeof(struct fcc_cursor));
if (*cursor == NULL) {
krb5_set_error_string (context, "malloc: out of memory");
krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
return ENOMEM;
}
memset(*cursor, 0, sizeof(struct fcc_cursor));
@@ -775,7 +785,7 @@ fcc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor)
iter = calloc(1, sizeof(*iter));
if (iter == NULL) {
krb5_set_error_string(context, "malloc - out of memory");
krb5_set_error_message(context, ENOMEM, "malloc - out of memory");
return ENOMEM;
}
iter->first = 1;
@@ -828,10 +838,10 @@ fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
ret = rename(FILENAME(from), FILENAME(to));
if (ret && errno != EXDEV) {
ret = errno;
krb5_set_error_string(context,
"Rename of file from %s to %s failed: %s",
FILENAME(from), FILENAME(to),
strerror(ret));
krb5_set_error_message(context, ret,
"Rename of file from %s to %s failed: %s",
FILENAME(from), FILENAME(to),
strerror(ret));
return ret;
} else if (ret && errno == EXDEV) {
/* make a copy and delete the orignal */
@@ -854,17 +864,17 @@ fcc_move(krb5_context context, krb5_ccache from, krb5_ccache to)
sz2 = write(fd2, buf, sz1);
if (sz1 != sz2) {
ret = EIO;
krb5_set_error_string(context,
"Failed to write data from one file "
"credential cache to the other");
krb5_set_error_message(context, ret,
"Failed to write data from one file "
"credential cache to the other");
goto out2;
}
}
if (sz1 < 0) {
ret = EIO;
krb5_set_error_string(context,
"Failed to read data from one file "
"credential cache to the other");
krb5_set_error_message(context, ret,
"Failed to read data from one file "
"credential cache to the other");
goto out2;
}
out2: