diff --git a/compile.sh b/compile.sh index 69376fc..5b0501a 100755 --- a/compile.sh +++ b/compile.sh @@ -1,2 +1,2 @@ -/home/jlcyr/apache2/bin/apxs -lpam -lpam_misc -c -i mod_absec.c +/home/jlcyr/apache2/bin/apxs -lpam -lpam_misc `mysql_config --cflags --libs` -c -i mod_absec.c /home/jlcyr/apache2/bin/apachectl restart diff --git a/mod_absec.c b/mod_absec.c index e2f1ccd..0044b99 100644 --- a/mod_absec.c +++ b/mod_absec.c @@ -61,6 +61,8 @@ #include #include +#include + //////////////////////////////////////////////////////////////// /* Check user autentication against unix user/pass */ static int check_autentication(request_rec *r) @@ -93,6 +95,47 @@ int converse(int n, const struct pam_message **msg, struct pam_conv conv = { converse, 0 }; //////////////////////////////////////////////////////////////// +// define PAM callback function +int mysql_lookup() +{ + MYSQL *conn; + MYSQL_RES *res; + MYSQL_ROW row; + + char *server = "localhost"; + char *user = "jlcyr"; + char *password = "password"; /* set me first */ + char *database = "absec"; + + conn = mysql_init(NULL); + + /* Connect to database */ + if (!mysql_real_connect(conn, server, + user, password, database, 0, NULL, 0)) { + fprintf(stderr, "%s\n", mysql_error(conn)); + return(1); + } + + /* send SQL query */ + if (mysql_query(conn, "show tables")) { + fprintf(stderr, "%s\n", mysql_error(conn)); + return(1); + } + + res = mysql_use_result(conn); + + /* output table name */ + printf("MySQL Tables in mysql database:\n"); + while ((row = mysql_fetch_row(res)) != NULL) + printf("%s \n", row[0]); + + /* close connection */ + mysql_free_result(res); + mysql_close(conn); + return(0); +} + +//////////////////////////////////////////////////////////////// /* Main routine - called after request processing */ static int absec_handler_last(request_rec *r) { @@ -103,7 +146,7 @@ static int absec_handler_last(request_rec *r) //////// /* http method validate the perm asked (r/w vs get/post,put) */ - ap_rprintf(r, "Before Method: %s
\r\n", r->method); + ap_rprintf(r, "After Method: %s
\r\n", r->method); int permmask = 0; if (strcmp(r->method,"GET")!=0) { @@ -127,9 +170,12 @@ static int absec_handler_first(request_rec *r) return DECLINED; } + //////// /* http method validate the perm asked (r/w vs get/post,put) */ ap_rprintf(r, "Before Method: %s
\r\n", r->method); + ap_rprintf(r, "Result mysql: %d
\r\n", mysql_lookup()); + int permmask = 0; if (strcmp(r->method,"GET")==0) permmask=0444; // r if (strcmp(r->method,"PUT")==0) permmask=0222; // w