pull/13/head
Soner Tari 5 years ago
parent 304207e9e9
commit fb25c45c66

@ -381,47 +381,27 @@ static int WUNRES
privsep_server_update_atime(opts_t *opts, const dbkeys_t *keys)
{
log_dbg_printf("privsep_server_update_atime: ENTER\n");
// struct sqlite3_stmt *opts->update_user_atime_sql_stmt;
// sqlite3 *userdb;
// if (sqlite3_open("/var/db/duaf.db", &userdb)) {
// fprintf(stderr, "Error opening user db file: %s\n", sqlite3_errmsg(userdb));
// sqlite3_close(userdb);
// exit(EXIT_FAILURE);
// }
// int rc = sqlite3_prepare_v2(opts->userdb, "UPDATE ip2user SET atime = ?1 WHERE ip = ?2 AND user = ?3", 100, &update_user_atime_sql_stmt, NULL);
// if (rc) {
// log_err_level_printf(LOG_CRIT, "Error preparing update_user_atime_sql_stmt: %s\n", sqlite3_errmsg(opts->userdb));
// sqlite3_close(opts->userdb);
// return -1;
// }
time_t atime = time(NULL);
sqlite3_reset(opts->update_user_atime_sql_stmt);
sqlite3_bind_int(opts->update_user_atime_sql_stmt, 1, atime);
sqlite3_bind_text(opts->update_user_atime_sql_stmt, 2, keys->ip, -1, NULL);
// sqlite3_bind_text(update_user_atime_sql_stmt, 2, "192.168.16.2", -1, NULL);
sqlite3_bind_text(opts->update_user_atime_sql_stmt, 3, keys->user, -1, NULL);
// sqlite3_bind_text(update_user_atime_sql_stmt, 3, "soner", -1, NULL);
// int count = 0;
// while (count++ < 50) {
if (sqlite3_step(opts->update_user_atime_sql_stmt) == SQLITE_DONE) {
//#ifdef DEBUG_PROXY
// log_dbg_level_printf(LOG_DBG_MODE_FINEST, "privsep_server_update_atime: Updated atime of user %s=%lld\n", keys->user, atime);
log_err_level_printf(LOG_CRIT, "privsep_server_update_atime: Updated atime of user %s=%lld\n", "soner", atime);
//#endif /* DEBUG_PROXY */
int count = 0;
int rc;
do {
rc = sqlite3_step(opts->update_user_atime_sql_stmt);
usleep(100);
// Retry in case we cannot acquire db file or database: SQLITE_BUSY or SQLITE_LOCKED respectively
} while ((rc == SQLITE_BUSY || rc == SQLITE_LOCKED) && count++ < 5);
if (rc == SQLITE_DONE) {
log_err_level_printf(LOG_CRIT, "privsep_server_update_atime: Updated atime of user %s=%lld\n", "soner", (long long)atime);
} else {
log_err_level_printf(LOG_CRIT, "privsep_server_update_atime: Error updating user atime: %s\n", sqlite3_errmsg(opts->userdb));
//#ifdef DEBUG_PROXY
// log_dbg_level_printf(LOG_DBG_MODE_FINEST, "privsep_server_update_atime: Error updating user atime: %s\n", sqlite3_errmsg(opts->userdb));
//#endif /* DEBUG_PROXY */
// sqlite3_close(userdb);
// return -1;
}
sqlite3_reset(opts->update_user_atime_sql_stmt);
// usleep(100);
// }
// sqlite3_close(opts->userdb);
return 0;
}
@ -609,7 +589,6 @@ privsep_server_handle_req(opts_t *opts, int srvsock)
}
case PRIVSEP_REQ_UPDATE_ATIME: {
dbkeys_t *arg;
// int s;
log_dbg_printf("ENTER PRIVSEP_REQ_UPDATE_ATIME\n");
if (n != sizeof(char) + sizeof(dbkeys_t)) {
@ -641,7 +620,6 @@ privsep_server_handle_req(opts_t *opts, int srvsock)
memcpy(arg, req + 1, n - 1);
log_dbg_printf("Calling privsep_server_update_atime\n");
// arg = *(dbkeys_t**)(&req[1]);
if (privsep_server_update_atime(opts, arg) == -1) {
free(arg);
ans[0] = PRIVSEP_ANS_SYS_ERR;
@ -657,12 +635,10 @@ privsep_server_handle_req(opts_t *opts, int srvsock)
free(arg);
ans[0] = PRIVSEP_ANS_SUCCESS;
if (sys_sendmsgfd(srvsock, ans, 1, 0) == -1) {
// evutil_closesocket(s);
log_err_level_printf(LOG_CRIT, "Sending message failed child 2: %s (%i"
")\n", strerror(errno), errno);
return -1;
}
// evutil_closesocket(s);
return 0;
}
/* not reached */
@ -1115,13 +1091,10 @@ privsep_client_update_atime(int clisock, const dbkeys_t *dbkeys)
{
char ans[PRIVSEP_MAX_ANS_SIZE];
char req[1 + sizeof(dbkeys_t)];
// char req[1 + sizeof(dbkeys)];
int rv = -1;
ssize_t n;
req[0] = PRIVSEP_REQ_UPDATE_ATIME;
// *((const dbkeys_t **)&req[1]) = dbkeys;
// *((const dbkeys_t **)&req[1]) = memcpy(&req[1], dbkeys, sizeof(dbkeys_t));
memcpy(req + 1, dbkeys, sizeof(req) - 1);
if (sys_sendmsgfd(clisock, req, sizeof(req), -1) == -1) {

@ -52,8 +52,6 @@
#include <glob.h>
#endif /* HAVE_NETFILTER */
//#include <sqlite3.h>
/*
* Maximum size of data to buffer per connection direction before
* temporarily stopping to read data from the other end.
@ -1497,39 +1495,12 @@ pxy_conn_identify_user(UNUSED evutil_socket_t fd, UNUSED short what, void *arg)
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_identify_user: Conn user=%s, ctx->fd=%d\n", ctx->user, ctx->fd);
#endif /* DEBUG_PROXY */
// struct dbkeys *ipuser = malloc(sizeof(struct dbkeys));
// memset(ipuser, 0, sizeof(dbkeys_t));
// memcpy(ipuser->ip, ctx->srchost_str, strlen(ctx->srchost_str));
//// ipuser->ip = strdup(ctx->srchost_str);
// memcpy(ipuser->user, ctx->user, strlen(ctx->user));
//// ipuser->user = strdup(ctx->user);
//
//// sqlite3_finalize(ctx->thr->get_user_sql_stmt);
//// sqlite3_close(ctx->opts->userdb);
//
// if (privsep_client_update_atime(ctx->clisock, ipuser) == -1) {
//// sqlite3_reset(ctx->thr->update_user_atime_sql_stmt);
//// sqlite3_bind_int(ctx->thr->update_user_atime_sql_stmt, 1, ctx->atime);
//// sqlite3_bind_text(ctx->thr->update_user_atime_sql_stmt, 2, ctx->srchost_str, -1, NULL);
//// if (sqlite3_step(ctx->thr->update_user_atime_sql_stmt) == SQLITE_DONE) {
////#ifdef DEBUG_PROXY
//// log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_identify_user: Updated atime of user %s=%lld, ctx->fd=%d\n", ctx->user, ctx->atime, ctx->fd);
////#endif /* DEBUG_PROXY */
//// } else {
//// log_err_level_printf(LOG_CRIT, "Error updating user atime: %s\n", sqlite3_errmsg(ctx->thrmgr->userdb));
////#ifdef DEBUG_PROXY
//// log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_identify_user: Error updating user atime: %s, ctx->fd=%d\n", sqlite3_errmsg(ctx->thrmgr->userdb), ctx->fd);
////#endif /* DEBUG_PROXY */
// }
} else if (rc == SQLITE_DONE) {
#ifdef DEBUG_PROXY
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_identify_user: Conn has no user, ctx->fd=%d\n", ctx->fd);
#endif /* DEBUG_PROXY */
}
// sqlite3_finalize(stmt);
// sqlite3_close(db);
event_free(ctx->ev);
// Retry in case we cannot acquire db file or database: SQLITE_BUSY or SQLITE_LOCKED respectively
if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
@ -1645,15 +1616,6 @@ pxy_conn_setup(evutil_socket_t fd,
memcpy(&ctx->srcaddr, peeraddr, ctx->srcaddrlen);
}
// /* for SSL, defer dst connection setup to initial_readcb */
// if (ctx->spec->ssl) {
// ctx->ev = event_new(ctx->evbase, fd, EV_READ, ctx->protoctx->fd_readcb, ctx);
// if (!ctx->ev)
// goto memout;
// event_add(ctx->ev, NULL);
// } else {
// ctx->protoctx->fd_readcb(fd, 0, ctx);
// }
ctx->ev = event_new(ctx->evbase, -1, 0, pxy_conn_identify_user, ctx);
if (!ctx->ev)
goto memout;

@ -394,22 +394,6 @@ pxy_thrmgr_run(pxy_thrmgr_ctx_t *ctx)
}
memset(ctx->thr, 0, ctx->num_thr * sizeof(pxy_thr_ctx_t*));
// // https://www.sqlite.org/faq.html:
// // "Under Unix, you should not carry an open SQLite database across a fork() system call into the child process."
// if (sqlite3_open("/var/db/sslproxy/duaf.db", &ctx->db)) {
// log_err_level_printf(LOG_CRIT, "Error opening user db file: %s\n", sqlite3_errmsg(ctx->db));
// sqlite3_close(ctx->db);
// goto leave;
// }
// ctx->userdb = db;
// int rc = sqlite3_prepare_v2(ctx->userdb, "SELECT user FROM ip2user WHERE ip = ?1", 100, &ctx->get_user_sql_stmt, NULL);
// if (rc) {
// log_err_level_printf(LOG_CRIT, "Error preparing sql stmt: %s\n", sqlite3_errmsg(ctx->userdb));
// sqlite3_close(ctx->userdb);
// goto leave;
// }
for (idx = 0; idx < ctx->num_thr; idx++) {
if (!(ctx->thr[idx] = malloc(sizeof(pxy_thr_ctx_t)))) {
log_dbg_printf("Failed to allocate memory\n");
@ -444,11 +428,6 @@ pxy_thrmgr_run(pxy_thrmgr_ctx_t *ctx)
log_err_level_printf(LOG_CRIT, "Error preparing get_user_sql_stmt: %s\n", sqlite3_errmsg(ctx->opts->userdb));
goto leave;
}
// rc = sqlite3_prepare_v2(ctx->userdb, "UPDATE ip2user SET atime = ?1 WHERE ip = ?2", 100, &ctx->thr[idx]->update_user_atime_sql_stmt, NULL);
// if (rc) {
// log_err_level_printf(LOG_CRIT, "Error preparing update_user_atime_sql_stmt: %s\n", sqlite3_errmsg(ctx->userdb));
// goto leave;
// }
}
log_dbg_printf("Initialized %d connection handling threads\n",
@ -505,8 +484,6 @@ void
pxy_thrmgr_free(pxy_thrmgr_ctx_t *ctx)
{
pthread_mutex_destroy(&ctx->mutex);
// sqlite3_close(ctx->db);
// sqlite3_finalize(ctx->get_user_sql_stmt);
if (ctx->thr) {
for (int idx = 0; idx < ctx->num_thr; idx++) {
event_base_loopbreak(ctx->thr[idx]->evbase);

@ -38,7 +38,6 @@
#include <event2/event.h>
#include <event2/dns.h>
#include <pthread.h>
#include <sqlite3.h>
typedef struct pxy_conn_ctx pxy_conn_ctx_t;
typedef struct pxy_thrmgr_ctx pxy_thrmgr_ctx_t;
@ -65,7 +64,6 @@ typedef struct pxy_thr_ctx {
unsigned short stats_idx;
pxy_conn_ctx_t *conns;
struct sqlite3_stmt *get_user_sql_stmt;
// struct sqlite3_stmt *update_user_atime_sql_stmt;
} pxy_thr_ctx_t;
struct pxy_thrmgr_ctx {
@ -73,8 +71,6 @@ struct pxy_thrmgr_ctx {
opts_t *opts;
pxy_thr_ctx_t **thr;
pthread_mutex_t mutex;
// sqlite3 *userdb;
// struct sqlite3_stmt *get_user_sql_stmt;
long long unsigned int conn_count;
};

Loading…
Cancel
Save