summaryrefslogtreecommitdiff
path: root/src/db_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/db_user.c')
-rw-r--r--src/db_user.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/db_user.c b/src/db_user.c
new file mode 100644
index 0000000..1a851c8
--- /dev/null
+++ b/src/db_user.c
@@ -0,0 +1,32 @@
+#include <accman.h>
+#include <mysql.h>
+
+void db_insert_user(struct user u)
+{
+ MYSQL *conn;
+ char mysql_query_str[1024];
+
+ conn = mysql_init(NULL);
+
+ if (!conn) {
+ printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
+ exit(EXIT_FAILURE);
+ }
+
+ if (!mysql_real_connect(conn, "localhost", "user", "password",
+ "mailserver", 0, NULL, 0)) {
+ printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(mysql_query_str, 1024,
+ "insert into virtual_users(domain_id, password, email) "
+ "values (1, '%s', '%s')", u.p, u.n);
+
+ if (mysql_query(conn, mysql_query_str)) {
+ printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
+ exit(1);
+ }
+
+ mysql_close(conn);
+}