compilation du module avec mysql
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
/home/jlcyr/apache2/bin/apxs -lpam -lpam_misc -c -i mod_absec.c
|
/home/jlcyr/apache2/bin/apxs -lpam -lpam_misc `mysql_config --cflags --libs` -c -i mod_absec.c
|
||||||
/home/jlcyr/apache2/bin/apachectl restart
|
/home/jlcyr/apache2/bin/apachectl restart
|
||||||
|
|||||||
+47
-1
@@ -61,6 +61,8 @@
|
|||||||
#include <security/pam_appl.h>
|
#include <security/pam_appl.h>
|
||||||
#include <security/pam_misc.h>
|
#include <security/pam_misc.h>
|
||||||
|
|
||||||
|
#include <mysql.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
/* Check user autentication against unix user/pass */
|
/* Check user autentication against unix user/pass */
|
||||||
static int check_autentication(request_rec *r)
|
static int check_autentication(request_rec *r)
|
||||||
@@ -93,6 +95,47 @@ int converse(int n, const struct pam_message **msg,
|
|||||||
struct pam_conv conv = { converse, 0 };
|
struct pam_conv conv = { converse, 0 };
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
// define PAM callback function
|
||||||
|
int mysql_lookup()
|
||||||
|
{
|
||||||
|
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)) {
|
||||||
|
fprintf(stderr, "%s\n", mysql_error(conn));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send SQL query */
|
||||||
|
if (mysql_query(conn, "show tables")) {
|
||||||
|
fprintf(stderr, "%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]);
|
||||||
|
|
||||||
|
/* close connection */
|
||||||
|
mysql_free_result(res);
|
||||||
|
mysql_close(conn);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
/* Main routine - called after request processing */
|
/* Main routine - called after request processing */
|
||||||
static int absec_handler_last(request_rec *r)
|
static int absec_handler_last(request_rec *r)
|
||||||
{
|
{
|
||||||
@@ -103,7 +146,7 @@ static int absec_handler_last(request_rec *r)
|
|||||||
|
|
||||||
////////
|
////////
|
||||||
/* http method validate the perm asked (r/w vs get/post,put) */
|
/* 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, "After Method: %s<br/>\r\n", r->method);
|
||||||
int permmask = 0;
|
int permmask = 0;
|
||||||
if (strcmp(r->method,"GET")!=0)
|
if (strcmp(r->method,"GET")!=0)
|
||||||
{
|
{
|
||||||
@@ -127,9 +170,12 @@ static int absec_handler_first(request_rec *r)
|
|||||||
return DECLINED;
|
return DECLINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////
|
////////
|
||||||
/* http method validate the perm asked (r/w vs get/post,put) */
|
/* 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, "Before Method: %s<br/>\r\n", r->method);
|
||||||
|
ap_rprintf(r, "Result mysql: %d<br/>\r\n", mysql_lookup());
|
||||||
|
|
||||||
int permmask = 0;
|
int permmask = 0;
|
||||||
if (strcmp(r->method,"GET")==0) permmask=0444; // r
|
if (strcmp(r->method,"GET")==0) permmask=0444; // r
|
||||||
if (strcmp(r->method,"PUT")==0) permmask=0222; // w
|
if (strcmp(r->method,"PUT")==0) permmask=0222; // w
|
||||||
|
|||||||
Reference in New Issue
Block a user