summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-04-06 12:52:07 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-06 13:11:50 +0200
commit11d6e84b8e5dadf35d3a6b19ba980583a6ff3144 (patch)
tree9a6cb159f8395ee2ef78fc08467fc3915b28b21c /src/dbi.c
parent8015f85b04c30350acbea8ce939a98b1f4c51cd8 (diff)
#915 Avoid duplicate db entries in /create/imagev1.2.0
/create/image adds an entry to the database for the given partition image created when payload contains a "description" attribute. This insertion into the database is lacking a check for duplicates, which are not supported for the images table. Add a prior duplicate check before inserting. Exit with -1 code if an image with the same name is found.
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 3f97fee..df3cebe 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -135,6 +135,24 @@ int og_dbi_add_image(struct og_dbi *dbi, const struct og_image *image)
dbi_result result;
result = dbi_conn_queryf(dbi->conn,
+ "SELECT nombreca FROM imagenes WHERE nombreca = '%s'",
+ image->name);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ return -1;
+ }
+
+ if (dbi_result_next_row(result)) {
+ syslog(LOG_ERR, "image creation attempt with already used image name (%s:%d)\n",
+ __func__, __LINE__);
+ dbi_result_free(result);
+ return -1;
+ }
+ dbi_result_free(result);
+
+ result = dbi_conn_queryf(dbi->conn,
"INSERT INTO imagenes (nombreca, "
"descripcion, "
"idperfilsoft, "