[mw-devel] MW3 r1224 - trunk/src/webclient
arthur at sucs.org
arthur at sucs.org
Wed Oct 13 17:21:56 BST 2010
Author: arthur
Date: 2010-10-13 17:21:56 +0100 (Wed, 13 Oct 2010)
New Revision: 1224
Modified:
trunk/src/webclient/Makefile
trunk/src/webclient/mwpoll.c
Log:
add sucssite session mode by calling into postgres, requires appropriate permissions be set in postgres to query the session table
Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile 2010-10-10 20:12:43 UTC (rev 1223)
+++ trunk/src/webclient/Makefile 2010-10-13 16:21:56 UTC (rev 1224)
@@ -7,7 +7,7 @@
HOMEPATH := $(libdir)/mw
# cflags for standard 'cc' compiler
-CFLAGS= -Wall -pedantic --std=gnu99 -D_GNU_SOURCE -I..
+CFLAGS= -Wall -pedantic --std=gnu99 -D_GNU_SOURCE -I.. -I/usr/include/postgresql
#LDFLAGS+= -pie
# info strings, do not edit.
@@ -22,7 +22,7 @@
DEFS+= -DMSGDIR=\"$(MSGDIR)\"
### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g -lcrypt
+LDFLAGS+= -ggdb -g -lcrypt -lpq
CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all -std=c99
### Optimisation - uncomment for release & extra testing
Modified: trunk/src/webclient/mwpoll.c
===================================================================
--- trunk/src/webclient/mwpoll.c 2010-10-10 20:12:43 UTC (rev 1223)
+++ trunk/src/webclient/mwpoll.c 2010-10-13 16:21:56 UTC (rev 1224)
@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include <string.h>
#include <time.h>
+#include <libpq-fe.h>
#include <bb.h>
#include <talker_privs.h>
@@ -56,7 +57,11 @@
void usage(const char *name)
{
- printf("Usage: %s [-u username] [-c channel]\n", name);
+ printf("Usage: %s [-u username] [-c channel] [-ds]\n", name);
+ printf("-u username Select username\n");
+ printf("-c channel Initial channel to join\n");
+ printf("-d Debug (foreground) mode\n");
+ printf("-s Session mode for sucssite\n");
}
int main(int argc, char ** argv)
@@ -66,9 +71,10 @@
int32_t userposn;
int channel = 0;
int debug = 0;
+ int dbsession = 0;
username = strdup("Arthur2");
- while ((opt=getopt(argc,argv,"u:c:d"))!=-1) {
+ while ((opt=getopt(argc,argv,"u:c:ds"))!=-1) {
switch (opt) {
case 'u':
if (username) free(username);
@@ -80,6 +86,9 @@
case 'd':
debug++;
break;
+ case 's':
+ dbsession++;
+ break;
default:
usage(argv[0]);
return 1;
@@ -105,10 +114,48 @@
}
if ((p=strchr(buff,'\r'))!=NULL) *p=0;
if ((p=strchr(buff,'\n'))!=NULL) *p=0;
- strncpy(salt, me.passwd, 2);
- if (strcmp(crypt(buff,salt), me.passwd)!=0) {
- printf("Incorrect password\n");
- return 1;
+
+ if (dbsession) {
+ PGconn *dbconn;
+ PGresult *dbres;
+ dbconn = PQconnectdb("dbname=sucssite");
+ if (PQstatus(dbconn) != CONNECTION_OK) {
+ printf("DB Connect error\n");
+ PQfinish(dbconn);
+ return 1;
+ }
+ const char *vals[1];
+ vals[0] = buff;
+ dbres = PQexecParams(dbconn, "SELECT username from session where hash = $1", 1, NULL, vals, NULL, NULL, 0);
+ if (PQresultStatus(dbres) != PGRES_TUPLES_OK)
+ {
+ printf("SELECT failed: %s", PQerrorMessage(dbconn));
+ PQclear(dbres);
+ PQfinish(dbconn);
+ return 1;
+ }
+ if (PQntuples(dbres) < 1) {
+ printf("Session not found\n");
+ PQclear(dbres);
+ PQfinish(dbconn);
+ return 1;
+ }
+ char *who = PQgetvalue(dbres, 0, 0);
+ if (strcasecmp(who, username)!=0) {
+ printf("Username mismatch '%s' != '%s'\n", username, who);
+ PQclear(dbres);
+ PQfinish(dbconn);
+ return 1;
+ }
+
+ PQclear(dbres);
+ PQfinish(dbconn);
+ } else {
+ strncpy(salt, me.passwd, 2);
+ if (strcmp(crypt(buff,salt), me.passwd)!=0) {
+ printf("Incorrect password\n");
+ return 1;
+ }
}
}
More information about the mw-devel
mailing list