# HG changeset patch # User John "Elwin" Edwards # Date 1343486973 25200 # Node ID b1480488ce9de8ebf793c15c4c1fb5bce3cdda3d # Parent 56a756695740d1226d6b3714bbe436f056cb19e1 sqlickrypt: add setpw command. Allow changing a user's password. diff -r 56a756695740 -r b1480488ce9d sqlickrypt.c --- 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 #include -#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;