prototype 1 mysql au lieu de fstat
This commit is contained in:
+31
-12
@@ -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<br/>", 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<br/>", 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<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);
|
||||
@@ -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<br/>", r->args);
|
||||
ap_rprintf(r, "After GET Url: %s from %s \n<br/>", 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<br/>\r\n", r->method);
|
||||
ap_rprintf(r, "Result mysql: %d<br/>\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 <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);
|
||||
|
||||
Reference in New Issue
Block a user