add some krb5_{set,clear}_error_string
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9937 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -46,8 +46,10 @@ krb5_rc_resolve(krb5_context context,
|
||||
const char *name)
|
||||
{
|
||||
id->name = strdup(name);
|
||||
if(id->name == NULL)
|
||||
if(id->name == NULL) {
|
||||
krb5_set_error_string (context, "malloc: out of memory");
|
||||
return KRB5_RC_MALLOC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -56,11 +58,16 @@ krb5_rc_resolve_type(krb5_context context,
|
||||
krb5_rcache *id,
|
||||
const char *type)
|
||||
{
|
||||
if(strcmp(type, "FILE"))
|
||||
if(strcmp(type, "FILE")) {
|
||||
krb5_set_error_string (context, "replay cache type %s not supported",
|
||||
type);
|
||||
return KRB5_RC_TYPE_NOTFOUND;
|
||||
}
|
||||
*id = calloc(1, sizeof(**id));
|
||||
if(*id == NULL)
|
||||
if(*id == NULL) {
|
||||
krb5_set_error_string (context, "malloc: out of memory");
|
||||
return KRB5_RC_MALLOC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -70,8 +77,11 @@ krb5_rc_resolve_full(krb5_context context,
|
||||
const char *string_name)
|
||||
{
|
||||
krb5_error_code ret;
|
||||
if(strncmp(string_name, "FILE:", 5))
|
||||
if(strncmp(string_name, "FILE:", 5)) {
|
||||
krb5_set_error_string (context, "replay cache type %s not supported",
|
||||
string_name);
|
||||
return KRB5_RC_TYPE_NOTFOUND;
|
||||
}
|
||||
ret = krb5_rc_resolve_type(context, id, "FILE");
|
||||
if(ret)
|
||||
return ret;
|
||||
@@ -110,8 +120,14 @@ krb5_rc_initialize(krb5_context context,
|
||||
{
|
||||
FILE *f = fopen(id->name, "w");
|
||||
struct rc_entry tmp;
|
||||
if(f == NULL)
|
||||
return errno;
|
||||
int ret;
|
||||
|
||||
if(f == NULL) {
|
||||
ret = errno;
|
||||
krb5_set_error_string (context, "open(%s): %s", id->name,
|
||||
strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
tmp.stamp = auth_lifespan;
|
||||
fwrite(&tmp, 1, sizeof(tmp), f);
|
||||
fclose(f);
|
||||
@@ -129,8 +145,14 @@ krb5_error_code
|
||||
krb5_rc_destroy(krb5_context context,
|
||||
krb5_rcache id)
|
||||
{
|
||||
if(remove(id->name) < 0)
|
||||
return errno;
|
||||
int ret;
|
||||
|
||||
if(remove(id->name) < 0) {
|
||||
ret = errno;
|
||||
krb5_set_error_string (context, "remove(%s): %s", id->name,
|
||||
strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
return krb5_rc_close(context, id);
|
||||
}
|
||||
|
||||
@@ -167,11 +189,17 @@ krb5_rc_store(krb5_context context,
|
||||
struct rc_entry ent, tmp;
|
||||
time_t t;
|
||||
FILE *f;
|
||||
int ret;
|
||||
|
||||
ent.stamp = time(NULL);
|
||||
checksum_authenticator(rep, ent.data);
|
||||
f = fopen(id->name, "r");
|
||||
if(f == NULL)
|
||||
return errno;
|
||||
if(f == NULL) {
|
||||
ret = errno;
|
||||
krb5_set_error_string (context, "open(%s): %s", id->name,
|
||||
strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
fread(&tmp, sizeof(ent), 1, f);
|
||||
t = ent.stamp - tmp.stamp;
|
||||
while(fread(&tmp, sizeof(ent), 1, f)){
|
||||
@@ -179,17 +207,23 @@ krb5_rc_store(krb5_context context,
|
||||
continue;
|
||||
if(memcmp(tmp.data, ent.data, sizeof(ent.data)) == 0){
|
||||
fclose(f);
|
||||
krb5_clear_error_string (context);
|
||||
return KRB5_RC_REPLAY;
|
||||
}
|
||||
}
|
||||
if(ferror(f)){
|
||||
ret = errno;
|
||||
fclose(f);
|
||||
return errno;
|
||||
krb5_set_error_string (context, "%s: %s", id->name, strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
fclose(f);
|
||||
f = fopen(id->name, "a");
|
||||
if(f == NULL)
|
||||
if(f == NULL) {
|
||||
krb5_set_error_string (context, "open(%s): %s", id->name,
|
||||
strerror(errno));
|
||||
return KRB5_RC_IO_UNKNOWN;
|
||||
}
|
||||
fwrite(&ent, 1, sizeof(ent), f);
|
||||
fclose(f);
|
||||
return 0;
|
||||
@@ -216,6 +250,7 @@ krb5_rc_get_lifespan(krb5_context context,
|
||||
*auth_lifespan = ent.stamp;
|
||||
return 0;
|
||||
}
|
||||
krb5_clear_error_string (context);
|
||||
return KRB5_RC_IO_UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -243,8 +278,11 @@ krb5_get_server_rcache(krb5_context context,
|
||||
|
||||
char *tmp = malloc(4 * piece->length + 1);
|
||||
char *name;
|
||||
if(tmp == NULL)
|
||||
|
||||
if(tmp == NULL) {
|
||||
krb5_set_error_string (context, "malloc: out of memory");
|
||||
return ENOMEM;
|
||||
}
|
||||
strvisx(tmp, piece->data, piece->length, VIS_WHITE | VIS_OCTAL);
|
||||
#ifdef HAVE_GETEUID
|
||||
asprintf(&name, "FILE:rc_%s_%u", tmp, geteuid());
|
||||
@@ -252,8 +290,10 @@ krb5_get_server_rcache(krb5_context context,
|
||||
asprintf(&name, "FILE:rc_%s", tmp);
|
||||
#endif
|
||||
free(tmp);
|
||||
if(name == NULL)
|
||||
if(name == NULL) {
|
||||
krb5_set_error_string (context, "malloc: out of memory");
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = krb5_rc_resolve_full(context, &rcache, name);
|
||||
free(name);
|
||||
|
Reference in New Issue
Block a user