annotate sqlickrypt.c @ 98:75a016c49076 beta4

Designate as beta4.
author John "Elwin" Edwards <elwin@sdf.org>
date Thu, 12 Jul 2012 07:57:50 -0700
parents f275d816e857
children c08717cb7793
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
1 #include <stdio.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
2 #include <stdlib.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
3 #include <string.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
4 #include <ctype.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
5 #include <sqlite3.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
6 #include <unistd.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
7 #include <crypt.h>
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
8
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
9 #define DATABASE "/dgldir/dgamelaunch.db"
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
10 #define IBUFSIZE 200
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
11
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
12 int check(char *uname, char *pw) {
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
13 char *pwhash, *comphash;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
14 char *query = "SELECT password FROM dglusers WHERE username=?;";
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
15 int status;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
16 sqlite3 *db;
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
17 sqlite3_stmt *qstmt;
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
18
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
19 status = sqlite3_open(DATABASE, &db);
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
20 if (status) {
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
21 sqlite3_close(db);
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
22 return 3;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
23 }
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
24 sqlite3_prepare_v2(db, query, -1, &qstmt, NULL);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
25 if (qstmt == NULL) {
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
26 sqlite3_close(db);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
27 return 3;
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
28 }
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
29 status = sqlite3_bind_text(qstmt, 1, uname, -1, SQLITE_TRANSIENT);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
30 if (status) {
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
31 sqlite3_finalize(qstmt);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
32 sqlite3_close(db);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
33 return 3;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
34 }
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
35 status = sqlite3_step(qstmt);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
36 if (status != SQLITE_ROW) {
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
37 sqlite3_finalize(qstmt);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
38 sqlite3_close(db);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
39 if (status == SQLITE_DONE)
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
40 return 2; /* User not found */
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
41 return 3;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
42 }
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
43 pwhash = strdup((char *) sqlite3_column_text(qstmt, 0));
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
44 /* Clean up */
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
45 sqlite3_finalize(qstmt);
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
46 sqlite3_close(db);
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
47
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
48 /* Check the password */
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
49 comphash = crypt(pw, pwhash);
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
50 if (!strcmp(pwhash, comphash))
24
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
51 status = 0;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
52 else
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
53 status = 1;
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
54 free(pwhash);
9d5da43c0e83 sqlickrypt.c: begin converting to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 18
diff changeset
55 return status;
17
d3e3d6b4016b rlgwebd: switch to dgamelaunch's SQLite database.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff changeset
56 }
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
57
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
58 int insertuser(char *uname, char *pw, char *email) {
25
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
59 char *checkquery = "SELECT * FROM dglusers WHERE username = ?;";
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
60 char *addquery = "INSERT INTO dglusers (username, password, email) VALUES (?, ?, ?);";
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
61 int status;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
62 sqlite3 *db;
25
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
63 sqlite3_stmt *qstmt;
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
64
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
65 status = sqlite3_open(DATABASE, &db);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
66 if (status) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
67 sqlite3_close(db);
25
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
68 return 3;
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
69 }
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
70 /* Check for existing account in the same transaction with creating it. */
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
71 status = sqlite3_exec(db, "BEGIN;", NULL, NULL, NULL);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
72 if (status) {
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
73 sqlite3_close(db);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
74 return 3;
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
75 }
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
76 sqlite3_prepare_v2(db, checkquery, -1, &qstmt, NULL);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
77 if (qstmt == NULL) {
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
78 sqlite3_close(db);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
79 return 3;
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
80 }
25
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
81 sqlite3_bind_text(qstmt, 1, uname, -1, SQLITE_TRANSIENT);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
82 status = sqlite3_step(qstmt);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
83 if (status != SQLITE_DONE) {
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
84 sqlite3_finalize(qstmt);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
85 sqlite3_close(db);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
86 if (status == SQLITE_ROW)
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
87 return 1; /* User already exists */
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
88 return 3;
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
89 }
25
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
90 /* The username doesn't exist yet, so create a new account. */
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
91 sqlite3_finalize(qstmt);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
92 sqlite3_prepare_v2(db, addquery, -1, &qstmt, NULL);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
93 if (qstmt == NULL) {
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
94 sqlite3_close(db);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
95 return 3;
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
96 }
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
97 sqlite3_bind_text(qstmt, 1, uname, -1, SQLITE_TRANSIENT);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
98 sqlite3_bind_text(qstmt, 2, strdup(crypt(pw, pw)), -1, free);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
99 sqlite3_bind_text(qstmt, 3, email, -1, SQLITE_TRANSIENT);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
100 status = sqlite3_step(qstmt);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
101 if (status != SQLITE_DONE) {
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
102 sqlite3_finalize(qstmt);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
103 sqlite3_close(db);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
104 return 3;
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
105 }
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
106 status = sqlite3_exec(db, "COMMIT;", NULL, NULL, NULL);
f275d816e857 sqlickrypt.c: finish switching to parametrized queries.
John "Elwin" Edwards <elwin@sdf.org>
parents: 24
diff changeset
107 sqlite3_finalize(qstmt);
18
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
108 sqlite3_close(db);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
109 return status;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
110 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
111
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
112 int main(int argc, char *argv[]) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
113 char ibuf[IBUFSIZE], *uname, *pw, *email;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
114 char *cptr; // Utility pointer
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
115 int status;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
116
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
117 /* Read in the username and password */
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
118 fgets(ibuf, IBUFSIZE, stdin);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
119 uname = ibuf;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
120 pw = strchr(uname, '\n');
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
121 if (pw == NULL)
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
122 exit(4); /* Truncated */
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
123 *pw = '\0';
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
124 pw++;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
125 fgets(pw, IBUFSIZE - (pw - ibuf), stdin);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
126 if (pw[strlen(pw) - 1] == '\n')
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
127 pw[strlen(pw) - 1] = '\0';
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
128 else
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
129 exit(4); /* Truncated */
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
130 if (argc > 1 && !strcmp(argv[1], "register")) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
131 email = pw + strlen(pw) + 1;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
132 fgets(email, IBUFSIZE - (email - ibuf), stdin);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
133 if (email[strlen(email) - 1] == '\n')
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
134 email[strlen(email) - 1] = '\0';
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
135 else
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
136 exit(4);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
137 for (cptr = email; *cptr != '\0'; cptr++) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
138 if (!isalnum(*cptr) && !strchr("@._-", *cptr)) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
139 exit(4);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
140 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
141 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
142 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
143 /* Sanitize the username, because it gets put into a query. */
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
144 for (cptr = uname; *cptr != '\0'; cptr++) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
145 if (!isalnum(*cptr)) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
146 exit(4);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
147 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
148 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
149 if (argc == 1 || !strcmp(argv[1], "check"))
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
150 status = check(uname, pw);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
151 else if (!strcmp(argv[1], "register")) {
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
152 status = insertuser(uname, pw, email);
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
153 }
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
154 else
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
155 status = 127;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
156 return status;
59ea628abb81 sqlickrypt.c: add the ability to register new users.
John "Elwin" Edwards <elwin@sdf.org>
parents: 17
diff changeset
157 }