*/
#include "includes.h"
+#include "system/filesys.h"
+#include "librpc/gen_ndr/ndr_krb5pac.h"
+#include "../libcli/security/security.h"
#define NETSAMLOGON_TDB "netsamlogon_cache.tdb"
bool netsamlogon_cache_init(void)
{
- if (!netsamlogon_tdb) {
- netsamlogon_tdb = tdb_open_log(lock_path(NETSAMLOGON_TDB), 0,
- TDB_DEFAULT, O_RDWR | O_CREAT, 0600);
+ bool first_try = true;
+ const char *path = NULL;
+ int ret;
+ struct tdb_context *tdb;
+
+ if (netsamlogon_tdb) {
+ return true;
+ }
+
+ path = cache_path(NETSAMLOGON_TDB);
+again:
+ tdb = tdb_open_log(path, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
+ O_RDWR | O_CREAT, 0600);
+ if (tdb == NULL) {
+ DEBUG(0,("tdb_open_log('%s') - failed\n", path));
+ goto clear;
+ }
+
+ ret = tdb_check(tdb, NULL, NULL);
+ if (ret != 0) {
+ tdb_close(tdb);
+ DEBUG(0,("tdb_check('%s') - failed\n", path));
+ goto clear;
+ }
+
+ netsamlogon_tdb = tdb;
+ return true;
+
+clear:
+ if (!first_try) {
+ return false;
+ }
+ first_try = false;
+
+ DEBUG(0,("retry after CLEAR_IF_FIRST for '%s'\n", path));
+ tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
+ O_RDWR | O_CREAT, 0600);
+ if (tdb) {
+ tdb_close(tdb);
+ goto again;
}
+ DEBUG(0,("tdb_open_log(%s) with CLEAR_IF_FIRST - failed\n", path));
- return (netsamlogon_tdb != NULL);
+ return false;
}
Clear cache getpwnam and getgroups entries from the winbindd cache
***********************************************************************/
-void netsamlogon_clear_cached_user(struct netr_SamInfo3 *info3)
+void netsamlogon_clear_cached_user(const struct dom_sid *user_sid)
{
- DOM_SID user_sid;
- fstring keystr, tmp;
-
- if (!info3) {
- return;
- }
+ fstring keystr;
if (!netsamlogon_cache_init()) {
DEBUG(0,("netsamlogon_clear_cached_user: cannot open "
NETSAMLOGON_TDB));
return;
}
- sid_copy(&user_sid, info3->base.domain_sid);
- sid_append_rid(&user_sid, info3->base.rid);
/* Prepare key as DOMAIN-SID/USER-RID string */
- slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, &user_sid));
+ sid_to_fstring(keystr, user_sid);
DEBUG(10,("netsamlogon_clear_cached_user: SID [%s]\n", keystr));
bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
{
TDB_DATA data;
- fstring keystr, tmp;
+ fstring keystr;
bool result = false;
- DOM_SID user_sid;
+ struct dom_sid user_sid;
time_t t = time(NULL);
TALLOC_CTX *mem_ctx;
DATA_BLOB blob;
return false;
}
- sid_copy(&user_sid, info3->base.domain_sid);
- sid_append_rid(&user_sid, info3->base.rid);
+ sid_compose(&user_sid, info3->base.domain_sid, info3->base.rid);
/* Prepare key as DOMAIN-SID/USER-RID string */
- slprintf(keystr, sizeof(keystr), "%s", sid_to_fstring(tmp, &user_sid));
+ sid_to_fstring(keystr, &user_sid);
DEBUG(10,("netsamlogon_cache_store: SID [%s]\n", keystr));
free the user_info struct (malloc()'d memory)
***********************************************************************/
-struct netr_SamInfo3 *netsamlogon_cache_get(TALLOC_CTX *mem_ctx, const DOM_SID *user_sid)
+struct netr_SamInfo3 *netsamlogon_cache_get(TALLOC_CTX *mem_ctx, const struct dom_sid *user_sid)
{
struct netr_SamInfo3 *info3 = NULL;
TDB_DATA data;
#endif
}
-bool netsamlogon_cache_have(const DOM_SID *user_sid)
+bool netsamlogon_cache_have(const struct dom_sid *user_sid)
{
TALLOC_CTX *mem_ctx = talloc_init("netsamlogon_cache_have");
struct netr_SamInfo3 *info3 = NULL;