Be better at setting and clearing error string.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20215 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2007-02-09 21:59:53 +00:00
parent 24e5f936df
commit 7aaf3af6e4

View File

@@ -67,8 +67,11 @@ DB_lock(krb5_context context, HDB *db, int operation)
{ {
DB *d = (DB*)db->hdb_db; DB *d = (DB*)db->hdb_db;
int fd = (*d->fd)(d); int fd = (*d->fd)(d);
if(fd < 0) if(fd < 0) {
krb5_set_error_string(context,
"Can't lock database: %s", db->hdb_name);
return HDB_ERR_CANT_LOCK_DB; return HDB_ERR_CANT_LOCK_DB;
}
return hdb_lock(fd, operation); return hdb_lock(fd, operation);
} }
@@ -77,8 +80,11 @@ DB_unlock(krb5_context context, HDB *db)
{ {
DB *d = (DB*)db->hdb_db; DB *d = (DB*)db->hdb_db;
int fd = (*d->fd)(d); int fd = (*d->fd)(d);
if(fd < 0) if(fd < 0) {
krb5_set_error_string(context,
"Can't unlock database: %s", db->hdb_name);
return HDB_ERR_CANT_LOCK_DB; return HDB_ERR_CANT_LOCK_DB;
}
return hdb_unlock(fd); return hdb_unlock(fd);
} }
@@ -93,14 +99,22 @@ DB_seq(krb5_context context, HDB *db,
int code; int code;
code = db->hdb_lock(context, db, HDB_RLOCK); code = db->hdb_lock(context, db, HDB_RLOCK);
if(code == -1) if(code == -1) {
krb5_set_error_string(context, "Database %s in use", db->hdb_name);
return HDB_ERR_DB_INUSE; return HDB_ERR_DB_INUSE;
}
code = (*d->seq)(d, &key, &value, flag); code = (*d->seq)(d, &key, &value, flag);
db->hdb_unlock(context, db); /* XXX check value */ db->hdb_unlock(context, db); /* XXX check value */
if(code == -1) if(code == -1) {
return errno; code = errno;
if(code == 1) krb5_set_error_string(context, "Database %s seq error: %s",
db->hdb_name, strerror(code));
return code;
}
if(code == 1) {
krb5_clear_error_string(context);
return HDB_ERR_NOENTRY; return HDB_ERR_NOENTRY;
}
key_data.data = key.data; key_data.data = key.data;
key_data.length = key.size; key_data.length = key.size;
@@ -174,10 +188,16 @@ DB__get(krb5_context context, HDB *db, krb5_data key, krb5_data *reply)
return code; return code;
code = (*d->get)(d, &k, &v, 0); code = (*d->get)(d, &k, &v, 0);
db->hdb_unlock(context, db); db->hdb_unlock(context, db);
if(code < 0) if(code < 0) {
return errno; code = errno;
if(code == 1) krb5_set_error_string(context, "Database %s get error: %s",
db->hdb_name, strerror(code));
return code;
}
if(code == 1) {
krb5_clear_error_string(context);
return HDB_ERR_NOENTRY; return HDB_ERR_NOENTRY;
}
krb5_data_copy(reply, v.data, v.size); krb5_data_copy(reply, v.data, v.size);
return 0; return 0;
@@ -200,10 +220,16 @@ DB__put(krb5_context context, HDB *db, int replace,
return code; return code;
code = (*d->put)(d, &k, &v, replace ? 0 : R_NOOVERWRITE); code = (*d->put)(d, &k, &v, replace ? 0 : R_NOOVERWRITE);
db->hdb_unlock(context, db); db->hdb_unlock(context, db);
if(code < 0) if(code < 0) {
return errno; code = errno;
if(code == 1) krb5_set_error_string(context, "Database %s put error: %s",
db->hdb_name, strerror(code));
return code;
}
if(code == 1) {
krb5_clear_error_string(context);
return HDB_ERR_EXISTS; return HDB_ERR_EXISTS;
}
return 0; return 0;
} }
@@ -220,8 +246,12 @@ DB__del(krb5_context context, HDB *db, krb5_data key)
return code; return code;
code = (*d->del)(d, &k, 0); code = (*d->del)(d, &k, 0);
db->hdb_unlock(context, db); db->hdb_unlock(context, db);
if(code == 1) if(code == 1) {
return HDB_ERR_NOENTRY; code = errno;
krb5_set_error_string(context, "Database %s put error: %s",
db->hdb_name, strerror(code));
return code;
}
if(code < 0) if(code < 0)
return errno; return errno;
return 0; return 0;