use krb5_set_error_message and krb5_enomem
This commit is contained in:
@@ -141,9 +141,9 @@ hdb_sqlite_prepare_stmt(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret != SQLITE_OK) {
|
if (ret != SQLITE_OK) {
|
||||||
|
krb5_set_error_message(context, EINVAL,
|
||||||
krb5_set_error_string(context, "Failed to prepare stmt %s: %s",
|
"Failed to prepare stmt %s: %s",
|
||||||
str, sqlite3_errmsg(db));
|
str, sqlite3_errmsg(db));
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +179,8 @@ hdb_sqlite_exec_stmt(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret != SQLITE_OK && error_code) {
|
if (ret != SQLITE_OK && error_code) {
|
||||||
krb5_set_error_string(context, "Execute %s: %s", statement,
|
krb5_set_error_message(context, error_code,
|
||||||
|
"Execute %s: %s", statement,
|
||||||
sqlite3_errmsg(database));
|
sqlite3_errmsg(database));
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
@@ -207,15 +208,15 @@ hdb_sqlite_open_database(krb5_context context, HDB *db, int flags)
|
|||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
if (hsdb->db) {
|
if (hsdb->db) {
|
||||||
krb5_set_error_string(context,
|
ret = ENOENT;
|
||||||
|
krb5_set_error_message(context, ret,
|
||||||
"Error opening sqlite database %s: %s",
|
"Error opening sqlite database %s: %s",
|
||||||
hsdb->db_file, sqlite3_errmsg(hsdb->db));
|
hsdb->db_file, sqlite3_errmsg(hsdb->db));
|
||||||
sqlite3_close(hsdb->db);
|
sqlite3_close(hsdb->db);
|
||||||
hsdb->db = NULL;
|
hsdb->db = NULL;
|
||||||
}
|
} else
|
||||||
else
|
ret = _krb5_enomem(context);
|
||||||
krb5_set_error_string(context, "out of memory");
|
return ret;
|
||||||
return ENOENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -352,8 +353,8 @@ hdb_sqlite_make_database(krb5_context context, HDB *db, const char *filename)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
if(hsdb->version != HDBSQLITE_VERSION) {
|
if(hsdb->version != HDBSQLITE_VERSION) {
|
||||||
krb5_set_error_string(context, "HDBSQLITE_VERSION mismatch");
|
|
||||||
ret = EINVAL;
|
ret = EINVAL;
|
||||||
|
krb5_set_error_message(context, ret, "HDBSQLITE_VERSION mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret) goto out;
|
if(ret) goto out;
|
||||||
@@ -406,10 +407,10 @@ hdb_sqlite_fetch(krb5_context context, HDB *db, krb5_const_principal principal,
|
|||||||
ret = HDB_ERR_NOENTRY;
|
ret = HDB_ERR_NOENTRY;
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
krb5_set_error_string(context,
|
ret = EINVAL;
|
||||||
|
krb5_set_error_message(context, ret,
|
||||||
"sqlite fetch failed: %d",
|
"sqlite fetch failed: %d",
|
||||||
sqlite_error);
|
sqlite_error);
|
||||||
ret = EINVAL;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -493,8 +494,10 @@ hdb_sqlite_store(krb5_context context, HDB *db, unsigned flags,
|
|||||||
ret = hdb_sqlite_exec_stmt(context, hsdb->db,
|
ret = hdb_sqlite_exec_stmt(context, hsdb->db,
|
||||||
"BEGIN IMMEDIATE TRANSACTION", EINVAL);
|
"BEGIN IMMEDIATE TRANSACTION", EINVAL);
|
||||||
if(ret != SQLITE_OK) {
|
if(ret != SQLITE_OK) {
|
||||||
krb5_set_error_string(context, "SQLite BEGIN TRANSACTION failed: %s",
|
ret = EINVAL;
|
||||||
sqlite3_errmsg(hsdb->db));
|
krb5_set_error_message(context, ret,
|
||||||
|
"SQLite BEGIN TRANSACTION failed: %s",
|
||||||
|
sqlite3_errmsg(hsdb->db));
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,7 +687,8 @@ hdb_sqlite_destroy(krb5_context context, HDB *db)
|
|||||||
static krb5_error_code
|
static krb5_error_code
|
||||||
hdb_sqlite_lock(krb5_context context, HDB *db, int operation)
|
hdb_sqlite_lock(krb5_context context, HDB *db, int operation)
|
||||||
{
|
{
|
||||||
krb5_set_error_string(context, "lock not implemented");
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
|
"lock not implemented");
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
return HDB_ERR_CANT_LOCK_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,7 +698,8 @@ hdb_sqlite_lock(krb5_context context, HDB *db, int operation)
|
|||||||
static krb5_error_code
|
static krb5_error_code
|
||||||
hdb_sqlite_unlock(krb5_context context, HDB *db)
|
hdb_sqlite_unlock(krb5_context context, HDB *db)
|
||||||
{
|
{
|
||||||
krb5_set_error_string(context, "unlock not implemented");
|
krb5_set_error_message(context, HDB_ERR_CANT_LOCK_DB,
|
||||||
|
"unlock not implemented");
|
||||||
return HDB_ERR_CANT_LOCK_DB;
|
return HDB_ERR_CANT_LOCK_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -798,7 +803,8 @@ hdb_sqlite_remove(krb5_context context, HDB *db,
|
|||||||
|
|
||||||
ret = hdb_sqlite_step(context, hsdb->db, remove);
|
ret = hdb_sqlite_step(context, hsdb->db, remove);
|
||||||
if (ret != SQLITE_DONE) {
|
if (ret != SQLITE_DONE) {
|
||||||
krb5_set_error_string(context,
|
ret = EINVAL;
|
||||||
|
krb5_set_error_message(context, ret,
|
||||||
"sqlite remove failed: %d",
|
"sqlite remove failed: %d",
|
||||||
ret);
|
ret);
|
||||||
} else
|
} else
|
||||||
@@ -827,17 +833,14 @@ hdb_sqlite_create(krb5_context context, HDB **db, const char *argument)
|
|||||||
hdb_sqlite_db *hsdb;
|
hdb_sqlite_db *hsdb;
|
||||||
|
|
||||||
*db = calloc(1, sizeof (**db));
|
*db = calloc(1, sizeof (**db));
|
||||||
if (*db == NULL) {
|
if (*db == NULL)
|
||||||
krb5_set_error_string(context, "calloc: out of memory");
|
return krb5_enomem(context);
|
||||||
return ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
hsdb = (hdb_sqlite_db*) calloc(1, sizeof (*hsdb));
|
hsdb = (hdb_sqlite_db*) calloc(1, sizeof (*hsdb));
|
||||||
if (hsdb == NULL) {
|
if (hsdb == NULL) {
|
||||||
free(*db);
|
free(*db);
|
||||||
*db = NULL;
|
*db = NULL;
|
||||||
krb5_set_error_string(context, "malloc: out of memory");
|
return krb5_enomem(context);
|
||||||
return ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*db)->hdb_db = hsdb;
|
(*db)->hdb_db = hsdb;
|
||||||
|
Reference in New Issue
Block a user