From d4f921b6e3e471effc197c27ec265a1d18eb2c85 Mon Sep 17 00:00:00 2001 From: Jean-Luc Cyr Date: Tue, 3 Jul 2018 15:24:02 -0400 Subject: [PATCH 1/2] split before/after --- mod_absec.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mod_absec.c b/mod_absec.c index 6ca7fce..89bdbf4 100644 --- a/mod_absec.c +++ b/mod_absec.c @@ -86,10 +86,23 @@ static int check_autorization(request_rec *r) return 0; } +//////////////////////////////////////////////////////////////// +/* Main routine */ +static int absec_handler_last(request_rec *r) +{ + // Is this module really called? + if (strcmp(r->handler, "absec")) { + return DECLINED; + } + r->content_type = "text/html"; + //ap_rprintf(r, "The sample page from mod_absec.c %s \n
", r->args); + ap_rprintf(r, "After Url: %s from %s \n
", r->filename, r->uri); + return (OK); +} //////////////////////////////////////////////////////////////// /* Main routine */ -static int absec_handler(request_rec *r) +static int absec_handler_first(request_rec *r) { // Is this module really called? if (strcmp(r->handler, "absec")) { @@ -294,7 +307,8 @@ static int absec_handler(request_rec *r) static void absec_register_hooks(apr_pool_t *p) { //ap_hook_handler(absec_handler, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_handler(absec_handler, NULL, NULL, APR_HOOK_LAST); + ap_hook_handler(absec_handler_last, NULL, NULL, APR_HOOK_LAST); + ap_hook_handler(absec_handler_first, NULL, NULL, APR_HOOK_FIRST); } //////////////////////////////////////////////////////////////// From e2b3cda59f8c77ac036a78f012133e4acda625e2 Mon Sep 17 00:00:00 2001 From: Jean-Luc Cyr Date: Thu, 6 Sep 2018 10:14:12 -0400 Subject: [PATCH 2/2] added back mysql database perms from pam version --- mod_absec.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/mod_absec.c b/mod_absec.c index 89bdbf4..d43e184 100644 --- a/mod_absec.c +++ b/mod_absec.c @@ -21,20 +21,6 @@ ** ** $ apachectl restart ** -** you immediately can request the URL /absec and watch for the -** output of this module. This can be achieved for instance via: -** -** $ lynx -mime_header http://localhost/absec -** -** The output should be similar to the following one: -** -** HTTP/1.1 200 OK -** Date: Tue, 31 Mar 1998 14:42:22 GMT -** Server: Apache/1.3.4 (Unix) -** Connection: close -** Content-Type: text/html -** -** The sample page from mod_absec.c */ /* @@ -72,6 +58,8 @@ #include #include +#include + //////////////////////////////////////////////////////////////// /* Check user autentication against unix user/pass */ static int check_autentication(request_rec *r) @@ -87,6 +75,65 @@ static int check_autorization(request_rec *r) } //////////////////////////////////////////////////////////////// +// define PAM callback function +int mysql_lookup(request_rec *r, struct stat *fperm) +{ + 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)) { + ap_rprintf(r, "%s\n
", mysql_error(conn)); + return(0); + } + + char query[256]; + sprintf(query, "select * from urls where url='%s'", r->uri); + /* send SQL query */ + //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 */ + 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); + mysql_close(conn); + return(0); +} + +//////////////////////////////////////////////////////////////// /* Main routine */ static int absec_handler_last(request_rec *r) { @@ -123,7 +170,13 @@ 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); + } //ap_rprintf(r, "File perms %o, owner %d, group %d (status %d)
\r\n", fperm.st_mode, fperm.st_uid, fperm.st_gid, status); /* check if any permission (ogw) match method (get r, put/post w, delete x) */