From d18504ce2a2c53798d3b3547fc77d280c44afca5 Mon Sep 17 00:00:00 2001 From: Jean-Luc Cyr Date: Wed, 9 Jan 2019 12:08:25 -0500 Subject: [PATCH] finalisation decoupage options --- absec_auto.h | 2 +- absec_fs.c | 60 +++++------------------------------------------------------ absec_mysql.c | 4 ++-- compile.sh | 7 ++++--- mod_absec.c | 4 ++-- test_auto.c | 58 ++++++++++++++++++++++++++------------------------------- 6 files changed, 40 insertions(+), 95 deletions(-) diff --git a/absec_auto.h b/absec_auto.h index 17b06bc..8749937 100644 --- a/absec_auto.h +++ b/absec_auto.h @@ -13,4 +13,4 @@ #include "httpd.h" #include -int mysql_lookup(request_rec *r, struct stat *fperm); +int perms_lookup(request_rec *r, struct stat *fperm); diff --git a/absec_fs.c b/absec_fs.c index 64a851b..cf6dd4f 100644 --- a/absec_fs.c +++ b/absec_fs.c @@ -10,65 +10,15 @@ #include "absec_auto.h" -#include #include #include "httpd.h" //////////////////////////////////////////////////////////////// -// -int mysql_lookup(request_rec *r, struct stat *fperm) +// file system based permission lookup +int perms_lookup(request_rec *r, struct stat *fperm) { - MYSQL *conn; - MYSQL_RES *res; - MYSQL_ROW row; + int status; + status = stat(r->filename, fperm); - 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)) { - printf("%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)) { - printf("%s\n", mysql_error(conn)); - return(-1); - } - - res = mysql_use_result(conn); - - /* output table name */ - printf("MySQL data:\n
"); - int cnt = 0; - while ((row = mysql_fetch_row(res)) != NULL) { - printf("%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)) { - printf("%s\n", mysql_error(conn)); - return(0); - } - printf("Aucune donnee\n
"); - } - - /* close connection */ - mysql_free_result(res); - mysql_close(conn); - return(0); + return status; } diff --git a/absec_mysql.c b/absec_mysql.c index dc6d6f2..b6db31a 100644 --- a/absec_mysql.c +++ b/absec_mysql.c @@ -15,8 +15,8 @@ #include "httpd.h" //////////////////////////////////////////////////////////////// -// -int mysql_lookup(request_rec *r, struct stat *fperm) +// mysql based permission lookup +int perms_lookup(request_rec *r, struct stat *fperm) { MYSQL *conn; MYSQL_RES *res; diff --git a/compile.sh b/compile.sh index 24b6872..a15200e 100755 --- a/compile.sh +++ b/compile.sh @@ -1,8 +1,10 @@ #!/bin/bash ABSEC_AUTHEN_DEP="-lpam -lpam_misc " ABSEC_AUTHEN_FILE="absec_pam.o" +#could be absec_pam or absec_etc ABSEC_AUTO_DEP="`mysql_config --cflags --libs` " ABSEC_AUTO_FILE="absec_mysql.o" +#could be absec_fs or absec_mysql echo "----------------" echo "Cleaning projets" @@ -42,15 +44,14 @@ echo "Running test" echo "================" echo "Compiling filesystem module" -gcc absec_fs.c `mysql_config --cflags --libs` -I/usr/include/apache2 -I/usr/include/apr-1.0 -fPIC -c +gcc absec_fs.c -I/usr/include/apache2 -I/usr/include/apr-1.0 -fPIC -c echo "----------------" echo "Compiling auto test with filesystem (test_auto -labsec_fs)" -gcc test_auto.c absec_mysql.o `mysql_config --cflags --libs` -I/usr/include/apache2 -I/usr/include/apr-1.0 -o test_auto +gcc test_auto.c absec_fs.o -I/usr/include/apache2 -I/usr/include/apr-1.0 -o test_auto echo "Running test" ./test_auto - echo "================" echo "Compiling absec tools" echo "- absec_ls" diff --git a/mod_absec.c b/mod_absec.c index 621a6d8..fe501a6 100755 --- a/mod_absec.c +++ b/mod_absec.c @@ -123,8 +123,8 @@ static int absec_handler_first(request_rec *r) /* should include */ struct stat fperm; int status; - status = stat(r->filename, &fperm); - //status = mysql_lookup(r, &fperm); + //status = stat(r->filename, &fperm); + status = perms_lookup(r, &fperm); //ap_rprintf(r, "Result mysql: %d
\r\n", ); if (status==-1) { ap_rprintf(r, "stat erreur %d", errno); diff --git a/test_auto.c b/test_auto.c index 20a1252..c523794 100644 --- a/test_auto.c +++ b/test_auto.c @@ -1,8 +1,3 @@ - - -#include "absec_auto.h" -#include -#include ///// // // File : test_auto.c @@ -12,39 +7,38 @@ // Description: autorisation method test file // +#include "absec_auto.h" +#include +#include +#include "httpd.h" + +//////////////////////////////////////////////////////////////// int main() { - MYSQL *conn; - MYSQL_RES *res; - MYSQL_ROW row; - char *server = "localhost"; - char *user = "jlcyr"; - char *password = "password"; /* set me first */ - char *database = "absec"; + struct request_rec r; + struct stat fperm; - conn = mysql_init(NULL); + char* filename = "/var/www/html/absec/test.php"; + r.filename=malloc(strlen(filename)); + strcpy(r.filename, filename); + char* uri = "/absec/test.php"; + r.uri=malloc(strlen(uri)); + strcpy(r.uri, uri); - /* Connect to database */ - if (!mysql_real_connect(conn, server, - user, password, database, 0, NULL, 0)) { - fprintf(stderr, "%s\n", mysql_error(conn)); - exit(1); - } + printf("ABSEC auto perms for file %s or uri %s\r\n", r.filename, r.uri); - /* send SQL query */ - if (mysql_query(conn, "show tables")) { - fprintf(stderr, "%s\n", mysql_error(conn)); - exit(1); - } + perms_lookup(&r, &fperm); - res = mysql_use_result(conn); + printf("Perms: %o\r\n", fperm.st_mode); - /* output table name */ - printf("MySQL Tables in mysql database:\n"); - while ((row = mysql_fetch_row(res)) != NULL) - printf("%s \n", row[0]); + printf("Test completed\r\n"); + + return 0; - /* close connection */ - mysql_free_result(res); - mysql_close(conn); } +/* + printf("Retval: %d\r\n", retval); + if (retval == PAM_ERROR_START) printf("Error at start\r\n"); + if (retval == PAM_ERROR_INVALID_CRED) printf("Invalid user/pass\r\n"); + if (retval == PAM_OK) printf("OK\r\n"); +*/