diff --git a/mod_absec.c b/mod_absec.c
index 0044b99..e0303a4 100644
--- a/mod_absec.c
+++ b/mod_absec.c
@@ -96,7 +96,7 @@ struct pam_conv conv = { converse, 0 };
////////////////////////////////////////////////////////////////
// define PAM callback function
-int mysql_lookup()
+int mysql_lookup(request_rec *r, struct stat *fperm)
{
MYSQL *conn;
MYSQL_RES *res;
@@ -112,22 +112,40 @@ int mysql_lookup()
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
- fprintf(stderr, "%s\n", mysql_error(conn));
- return(1);
+ ap_rprintf(r, "%s\n
", mysql_error(conn));
+ return(0);
}
+ char query[64];
+ sprintf(query, "select * from urls where url='%s'", r->uri);
/* send SQL query */
- if (mysql_query(conn, "show tables")) {
- fprintf(stderr, "%s\n", mysql_error(conn));
- return(1);
+ //if (mysql_query(conn, "show tables")) {
+ if (mysql_query(conn, query)) {
+ ap_rprintf(r, "%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]);
+ ap_rprintf(r, "MySQL data:\n
");
+ int cnt = 0;
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ ap_rprintf(r, "%s %d %d %o \n
", row[0], atoi(row[1]), atoi(row[2]), atoi(row[3]));
+ fperm->st_uid = atoi(row[1]);
+ fperm->st_gid = atoi(row[2]);
+ fperm->st_mode = atoi(row[3]);
+ cnt = cnt + 1;
+ }
+
+ if (cnt==0) {
+ sprintf(query, "insert into urls (url, uid, gid, perms) values ('%s', 0, 0, 0)", r->uri);
+ if (mysql_query(conn, query)) {
+ ap_rprintf(r, "%s\n
", mysql_error(conn));
+ return(0);
+ }
+ ap_rprintf(r, "Aucune donnee\n
");
+ }
/* close connection */
mysql_free_result(res);
@@ -158,7 +176,7 @@ static int absec_handler_last(request_rec *r)
r->content_type = "text/html";
//ap_rprintf(r, "The sample page from mod_absec.c %s \n
", r->args);
ap_rprintf(r, "After GET Url: %s from %s \n
", r->filename, r->uri);
- return (OK);
+ return (DECLINED);
}
////////////////////////////////////////////////////////////////
@@ -174,7 +192,6 @@ static int absec_handler_first(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, "Result mysql: %d
\r\n", mysql_lookup());
int permmask = 0;
if (strcmp(r->method,"GET")==0) permmask=0444; // r
@@ -187,7 +204,9 @@ static int absec_handler_first(request_rec *r)
/* should include */
struct stat fperm;
int status;
- status = stat(r->filename, &fperm);
+ //status = stat(r->filename, &fperm);
+ status = mysql_lookup(r, &fperm);
+ //ap_rprintf(r, "Result mysql: %d
\r\n", );
if (status==-1) {
ap_rprintf(r, "stat erreur %d", errno);
return (OK);
diff --git a/todo.txt b/todo.txt
index 307bda6..4f6b22c 100644
--- a/todo.txt
+++ b/todo.txt
@@ -19,4 +19,5 @@ sudo apt-get install libxml2-dev libdb-dev
--disable-cgi \
--with-zlib \
--with-gettext \
- --with-gdbm
\ No newline at end of file
+ --with-gdbm
+