sqlickrypt: add setpw command.
Allow changing a user's password.
This commit is contained in:
parent
f1c5196829
commit
85708c5810
1 changed files with 28 additions and 1 deletions
29
sqlickrypt.c
29
sqlickrypt.c
|
|
@ -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 @@ int setmail(char *uname, char *newmail) {
|
|||
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 @@ int main(int argc, char *argv[]) {
|
|||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue