Mercurial > hg > rlgwebd
comparison sqlickrypt.c @ 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 | c08717cb7793 |
children | 0a3ff1267c24 |
comparison
equal
deleted
inserted
replaced
118:56a756695740 | 119:b1480488ce9d |
---|---|
4 #include <ctype.h> | 4 #include <ctype.h> |
5 #include <sqlite3.h> | 5 #include <sqlite3.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 #include <crypt.h> | 7 #include <crypt.h> |
8 | 8 |
9 #define DATABASE "/dgldir/dgamelaunch.db" | 9 #define DATABASE "/dgldir/dgamelaunch-X.db" |
10 #define IBUFSIZE 200 | 10 #define IBUFSIZE 200 |
11 | 11 |
12 /* General idea for return status: | 12 /* General idea for return status: |
13 * 0: success | 13 * 0: success |
14 * 1: password check failed | 14 * 1: password check failed |
143 opendb(&db, &qstmt, setquery); | 143 opendb(&db, &qstmt, setquery); |
144 status = sqlite3_bind_text(qstmt, 2, uname, -1, SQLITE_TRANSIENT); | 144 status = sqlite3_bind_text(qstmt, 2, uname, -1, SQLITE_TRANSIENT); |
145 if (status) | 145 if (status) |
146 cleanup(db, qstmt, 3); | 146 cleanup(db, qstmt, 3); |
147 status = sqlite3_bind_text(qstmt, 1, newmail, -1, SQLITE_TRANSIENT); | 147 status = sqlite3_bind_text(qstmt, 1, newmail, -1, SQLITE_TRANSIENT); |
148 if (status) | |
149 cleanup(db, qstmt, 3); | |
150 status = sqlite3_step(qstmt); | |
151 if (status != SQLITE_DONE) | |
152 cleanup(db, qstmt, 3); | |
153 cleanup(db, qstmt, 0); | |
154 return 0; | |
155 } | |
156 | |
157 int setpw(char *uname, char *newpw) { | |
158 char *setquery = "UPDATE dglusers SET password = ? WHERE username = ?;"; | |
159 sqlite3 *db; | |
160 sqlite3_stmt *qstmt; | |
161 int status; | |
162 char *hash; | |
163 | |
164 /* This is not a smart use of crypt, but it needs to be compatible with | |
165 * dgamelaunch. */ | |
166 hash = crypt(newpw, newpw); | |
167 opendb(&db, &qstmt, setquery); | |
168 status = sqlite3_bind_text(qstmt, 2, uname, -1, SQLITE_TRANSIENT); | |
169 if (status) | |
170 cleanup(db, qstmt, 3); | |
171 status = sqlite3_bind_text(qstmt, 1, hash, -1, SQLITE_TRANSIENT); | |
148 if (status) | 172 if (status) |
149 cleanup(db, qstmt, 3); | 173 cleanup(db, qstmt, 3); |
150 status = sqlite3_step(qstmt); | 174 status = sqlite3_step(qstmt); |
151 if (status != SQLITE_DONE) | 175 if (status != SQLITE_DONE) |
152 cleanup(db, qstmt, 3); | 176 cleanup(db, qstmt, 3); |
210 status = getmail(uname); | 234 status = getmail(uname); |
211 } | 235 } |
212 else if (!strcmp(argv[1], "setmail")) { | 236 else if (!strcmp(argv[1], "setmail")) { |
213 status = setmail(uname, line1); | 237 status = setmail(uname, line1); |
214 } | 238 } |
239 else if (!strcmp(argv[1], "setpw")) { | |
240 status = setpw(uname, line1); | |
241 } | |
215 else | 242 else |
216 status = 127; | 243 status = 127; |
217 return status; | 244 return status; |
218 } | 245 } |