added back mysql database perms from pam version

This commit is contained in:
2018-09-06 10:14:12 -04:00
parent d4f921b6e3
commit e2b3cda59f
+68 -15
View File
@@ -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 <shadow.h>
#include <sys/stat.h>
#include <mysql.h>
////////////////////////////////////////////////////////////////
/* 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<br/>", 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<br/>", mysql_error(conn));
return(-1);
}
res = mysql_use_result(conn);
/* output table name */
ap_rprintf(r, "MySQL data:\n<br/>");
int cnt = 0;
while ((row = mysql_fetch_row(res)) != NULL) {
ap_rprintf(r, "%s %d %d %o \n<br/>", 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<br/>", mysql_error(conn));
return(0);
}
ap_rprintf(r, "Aucune donnee\n<br/>");
}
/* 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 <sys/stat.h> */
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<br/>\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)<br/>\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) */