changeset 119:b1480488ce9d

sqlickrypt: add setpw command. Allow changing a user's password.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 28 Jul 2012 07:49:33 -0700
parents 56a756695740
children 54979d35611a
files sqlickrypt.c
diffstat 1 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sqlickrypt.c	Mon Jul 23 09:32:46 2012 -0700
+++ b/sqlickrypt.c	Sat Jul 28 07:49:33 2012 -0700
@@ -6,7 +6,7 @@
 #include <unistd.h>
 #include <crypt.h>
 
-#define DATABASE "/dgldir/dgamelaunch.db"
+#define DATABASE "/dgldir/dgamelaunch-X.db"
 #define IBUFSIZE 200
 
 /* General idea for return status:
@@ -154,6 +154,30 @@
   return 0;
 }
 
+int setpw(char *uname, char *newpw) {
+  char *setquery = "UPDATE dglusers SET password = ? WHERE username = ?;";
+  sqlite3 *db;
+  sqlite3_stmt *qstmt;
+  int status;
+  char *hash;
+
+  /* This is not a smart use of crypt, but it needs to be compatible with
+   * dgamelaunch. */
+  hash = crypt(newpw, newpw);
+  opendb(&db, &qstmt, setquery);
+  status = sqlite3_bind_text(qstmt, 2, uname, -1, SQLITE_TRANSIENT);
+  if (status)
+    cleanup(db, qstmt, 3);
+  status = sqlite3_bind_text(qstmt, 1, hash, -1, SQLITE_TRANSIENT);
+  if (status)
+    cleanup(db, qstmt, 3);
+  status = sqlite3_step(qstmt);
+  if (status != SQLITE_DONE)
+    cleanup(db, qstmt, 3);
+  cleanup(db, qstmt, 0);
+  return 0;
+}
+
 int main(int argc, char *argv[]) {
   char ibuf[IBUFSIZE], *uname, *line1, *line2;
   char *cptr; // Utility pointer
@@ -212,6 +236,9 @@
   else if (!strcmp(argv[1], "setmail")) {
     status = setmail(uname, line1);
   }
+  else if (!strcmp(argv[1], "setpw")) {
+    status = setpw(uname, line1);
+  }
   else
     status = 127;
   return status;