From add7ee4770c7868dbe8a14a08be565be5db20617 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 22 Jun 2009 11:22:08 -0300 Subject: [PATCH] Close databases for every query to avoid concurrency. This allows to manipulate the database while proxy is running. This also solves the problem when a database exists but is empty. In this case, consider as if it does not exist. --- usermap.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/usermap.c b/usermap.c index ddd6b52..e2fa5bd 100644 --- a/usermap.c +++ b/usermap.c @@ -25,22 +25,24 @@ int usermap_perm (char *user) { - static DEPOT* allow_dp = NULL; - static DEPOT* deny_dp = NULL; + DEPOT* allow_dp = NULL; + DEPOT* deny_dp = NULL; char* allow = NULL; char* deny = NULL; - if (allow_dp == NULL) + int allow_users = 0; + allow_dp = dpopen ("/var/lib/popproxy/allow.db", DP_OREADER, 0); + deny_dp = dpopen ("/var/lib/popproxy/deny.db", DP_OREADER, 0); + if (allow_dp) { - allow_dp = dpopen ("/var/lib/popproxy/allow.db", DP_OREADER, 0); + allow = dpget (allow_dp, user, -1, 0, -1, NULL); + allow_users = dprnum (allow_dp); + dpclose (allow_dp); } - if (deny_dp == NULL) + if (deny_dp) { - deny_dp = dpopen ("/var/lib/popproxy/deny.db", DP_OREADER, 0); + deny = dpget (deny_dp, user, -1, 0, -1, NULL); + dpclose (deny_dp); } - if (allow_dp) - allow = dpget (allow_dp, user, -1, 0, -1, NULL); - if (deny_dp) - deny = dpget (deny_dp, user, -1, 0, -1, NULL); if (allow && deny) { free (allow); @@ -57,7 +59,7 @@ usermap_perm (char *user) free (deny); return ACCESS_DENY; } - if (!allow_dp) + if (allow_users == 0) return ACCESS_ALLOW; return ACCESS_DENY; } -- 2.20.1