commit all files, will need cleanup later.
This commit is contained in:
+7
-120
@@ -58,100 +58,8 @@
|
||||
#include <shadow.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_misc.h>
|
||||
|
||||
#include <mysql.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
/* Check user autentication against unix user/pass */
|
||||
static int check_autentication(request_rec *r)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
/* Check check file perms */
|
||||
static int check_autorization(request_rec *r)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Global var for passing fake response to PAM callback
|
||||
struct pam_response *reply;
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// PAM response callback function
|
||||
int converse(int n, const struct pam_message **msg,
|
||||
struct pam_response **resp, void *data)
|
||||
{
|
||||
// Return globally set response
|
||||
*resp = reply;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// define PAM callback function
|
||||
struct pam_conv conv = { converse, 0 };
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// 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);
|
||||
}
|
||||
#include "absec_pam.h"
|
||||
#include "absec_mysql.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
/* Main routine - called after request processing */
|
||||
@@ -206,8 +114,8 @@ static int absec_handler_first(request_rec *r)
|
||||
/* should include <sys/stat.h> */
|
||||
struct stat fperm;
|
||||
int status;
|
||||
//status = stat(r->filename, &fperm);
|
||||
status = mysql_lookup(r, &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);
|
||||
@@ -264,23 +172,11 @@ static int absec_handler_first(request_rec *r)
|
||||
//ap_rprintf(r, "Headers Authorization: %s \n<br/>", auth64);
|
||||
//ap_rprintf(r, "User/Pass: %s/%s \n<br/>", user, pass);
|
||||
|
||||
////////
|
||||
// Connect to PAM to auth user
|
||||
pam_handle_t * pamh = NULL;
|
||||
int rret;
|
||||
|
||||
if((rret = pam_start("httpd", user/*pw->pw_name*/, &conv, &pamh)) != PAM_SUCCESS) {
|
||||
int pam_result = pam_check_user(user, pass);
|
||||
if ( (pam_result==PAM_ERROR_START) || (pam_result==PAM_ERROR_STOP) ) {
|
||||
return HTTP_INTERNAL_SERVER_ERROR;
|
||||
printf("Pam start failed\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Set the PAM callback function response (would call for password)
|
||||
reply = (struct pam_response *)malloc(sizeof(struct pam_response));
|
||||
reply[0].resp = strdup(pass); // password received in basic auth
|
||||
reply[0].resp_retcode = 0;
|
||||
|
||||
if((rret = pam_authenticate(pamh, 0)) != PAM_SUCCESS) {
|
||||
if (pam_result==PAM_ERROR_INVALID_CRED) {
|
||||
r->content_type = "text/html";
|
||||
apr_table_setn(r->err_headers_out,
|
||||
(PROXYREQ_PROXY == r->proxyreq) ? "Proxy-Authenticate"
|
||||
@@ -288,15 +184,6 @@ static int absec_handler_first(request_rec *r)
|
||||
apr_pstrcat(r->pool, "Basic realm=\"USER/PASS INVALIDE ", ap_auth_name(r),
|
||||
"\"", NULL));
|
||||
return HTTP_UNAUTHORIZED;
|
||||
printf("User auth failed\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(pam_end(pamh, rret) != PAM_SUCCESS) {
|
||||
//perror("pam_end");
|
||||
pamh = NULL;
|
||||
return HTTP_INTERNAL_SERVER_ERROR;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
////////
|
||||
|
||||
Reference in New Issue
Block a user